Skip to content

fix: load schema via require() for pkg/esbuild compat#2396

Merged
lpcox merged 6 commits into
mainfrom
fix/schema-pkg-compat
May 2, 2026
Merged

fix: load schema via require() for pkg/esbuild compat#2396
lpcox merged 6 commits into
mainfrom
fix/schema-pkg-compat

Conversation

@lpcox

@lpcox lpcox commented May 2, 2026

Copy link
Copy Markdown
Collaborator

Problem

The Release workflow (run #25241289459) failed at the Smoke test binary (x64) step with:

Error: Unable to locate awf-config-schema.json. Checked: /snapshot/gh-aw-firewall/dist/awf-config-schema.json, /snapshot/gh-aw-firewall/src/awf-config-schema.json

The schema-based config validation (PR #2384) used fs.readFileSync with __dirname paths to load the JSON Schema at runtime. This works fine for node dist/cli.js and the esbuild bundle, but fails in the pkg binary because the JSON file wasn't included in the snapshot filesystem.

Fix

Replace fs.readFileSync + loadSchema() with a simple require('./awf-config-schema.json'). Both bundlers handle this natively:

  • esbuild: inlines the JSON into the bundle
  • pkg: detects the require() and includes the file in the snapshot

Also adds dist/awf-config-schema.json to pkg.assets as belt-and-suspenders.

Verification

  • npm run build
  • npm run build:bundle
  • Bundle smoke test (config validation via esbuild bundle) ✅
  • All 114 schema/config tests pass ✅

Copilot AI review requested due to automatic review settings May 2, 2026 15:07
@lpcox lpcox requested a review from Mossaka as a code owner May 2, 2026 15:07
@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

⚠️ Coverage Regression Detected

This PR decreases test coverage. Please add tests to maintain coverage levels.

Overall Coverage

Metric Base PR Delta
Lines 85.74% 85.83% 📈 +0.09%
Statements 85.63% 85.71% 📈 +0.08%
Functions 88.15% 88.11% 📉 -0.04%
Branches 78.63% 78.69% 📈 +0.06%
📁 Per-file Coverage Changes (2 files)
File Lines (Before → After) Statements (Before → After)
src/docker-manager.ts 87.4% → 87.7% (+0.29%) 87.0% → 87.3% (+0.27%)
src/schema-validator.ts 98.0% → 100.0% (+1.97%) 98.0% → 100.0% (+1.97%)

Coverage comparison generated by scripts/ci/compare-coverage.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR changes runtime schema loading so config validation works inside packaged/bundled artifacts, especially the pkg binary that previously could not find awf-config-schema.json at runtime. It fits into the config-validation path added in PR #2384 by adjusting how the generated schema is loaded during CLI startup.

Changes:

  • Replace filesystem-based schema loading in schema-validator.ts with a literal require('./awf-config-schema.json').
  • Add dist/awf-config-schema.json to pkg.assets as an explicit packaged asset.
  • Update inline documentation to describe the new bundler/pkg loading behavior.
Show a summary per file
File Description
src/schema-validator.ts Switches schema loading from runtime file reads/fallback paths to a direct require() of the generated JSON schema.
package.json Adds the generated schema JSON under pkg.assets so the packaged binary can include it explicitly.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 1

Comment thread src/schema-validator.ts Outdated
The release binary failed because pkg couldn't find awf-config-schema.json
at runtime — the fs.readFileSync approach didn't work in pkg's snapshot
filesystem. Switch to require() which both esbuild (inlines into bundle)
and pkg (includes in snapshot via static analysis) handle natively.

Also add dist/awf-config-schema.json to pkg.assets as a fallback.

Fixes: Release workflow 'Smoke test binary (x64)' failure

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox lpcox force-pushed the fix/schema-pkg-compat branch from 0d107cd to 24b3cce Compare May 2, 2026 15:12
@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

⚠️ Coverage Regression Detected

This PR decreases test coverage. Please add tests to maintain coverage levels.

Overall Coverage

Metric Base PR Delta
Lines 85.74% 85.83% 📈 +0.09%
Statements 85.63% 85.71% 📈 +0.08%
Functions 88.15% 88.11% 📉 -0.04%
Branches 78.63% 78.69% 📈 +0.06%
📁 Per-file Coverage Changes (2 files)
File Lines (Before → After) Statements (Before → After)
src/docker-manager.ts 87.4% → 87.7% (+0.29%) 87.0% → 87.3% (+0.27%)
src/schema-validator.ts 98.0% → 100.0% (+1.97%) 98.0% → 100.0% (+1.97%)

Coverage comparison generated by scripts/ci/compare-coverage.ts

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment thread src/schema-validator.ts Fixed
Comment thread src/schema-validator.ts Fixed
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@lpcox

lpcox commented May 2, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot merge main

@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

⚠️ Coverage Regression Detected

This PR decreases test coverage. Please add tests to maintain coverage levels.

Overall Coverage

Metric Base PR Delta
Lines 85.74% 85.83% 📈 +0.09%
Statements 85.63% 85.71% 📈 +0.08%
Functions 88.15% 88.11% 📉 -0.04%
Branches 78.63% 78.69% 📈 +0.06%
📁 Per-file Coverage Changes (2 files)
File Lines (Before → After) Statements (Before → After)
src/docker-manager.ts 87.4% → 87.7% (+0.29%) 87.0% → 87.3% (+0.27%)
src/schema-validator.ts 98.0% → 100.0% (+1.97%) 98.0% → 100.0% (+1.97%)

Coverage comparison generated by scripts/ci/compare-coverage.ts

Comment thread src/schema-validator.ts Fixed
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Copilot AI commented May 2, 2026

Copy link
Copy Markdown
Contributor

@copilot merge main

The branch was already up to date with main (branched from the latest main commit). Also took this opportunity to properly fix the outstanding CodeQL alerts by replacing the unused import * as schemaJson + loadSchema() pattern with a clean import schemaJson from './awf-config-schema.json' that TypeScript actually uses — resolving both "Assignment to constant" and "Useless assignment to local variable" alerts. Merged in commit ca7b83c.

@github-actions

This comment has been minimized.

Copilot finished work on behalf of lpcox May 2, 2026 15:27
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

🔥 Smoke Test: Copilot BYOK — PASS

Test Result
GitHub MCP (merged PR: "feat: validate config files against published JSON Schema at runtime")
GitHub.com connectivity
File write/read (smoke-test-copilot-byok-25255268208.txt)
BYOK inference (agent → api-proxy → api.githubcopilot.com)

Running in BYOK offline mode (COPILOT_OFFLINE=true) via api-proxy → api.githubcopilot.com.

Overall: PASS | Author: @lpcox | Reviewer: @Mossaka

🔑 BYOK report filed by Smoke Copilot BYOK

@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

Smoke Test Results:

Overall Status: PASS

💥 [THE END] — Illustrated by Smoke Claude

@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

🤖 Smoke Test Results

Test Result
GitHub MCP connectivity ✅ PR list fetched successfully
GitHub.com HTTP connectivity ⚠️ Pre-step data unavailable (template vars not expanded)
File write/read ⚠️ Pre-step data unavailable (template vars not expanded)

PR: fix: load schema via require() for pkg/esbuild compat — author: @lpcox, reviewer: @Mossaka

Overall: PARTIAL — MCP ✅, pre-step outputs not injected into prompt.

📰 BREAKING: Report filed by Smoke Copilot

@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

Smoke Test

feat: validate config files against published JSON Schema at runtime
feat: publish versioned schemas for JSONL audit/telemetry artifacts
GitHub PR review ✅
Safeinputs GH CLI ❌
Playwright title ✅
Tavily search ❌
File + bash ✅
Discussion comment ✅
Build AWF ✅
Overall status: FAIL

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • registry.npmjs.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "registry.npmjs.org"

See Network Configuration for more information.

🔮 The oracle has spoken through Smoke Codex

@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

Chroot Version Comparison

Runtime Host Version Chroot Version Match?
Python Python 3.12.13 Python 3.12.3
Node.js v24.14.1 v20.20.2
Go go1.22.12 go1.22.12

Result: Not all tests passed. Python and Node.js versions differ between host and chroot.

Tested by Smoke Chroot

@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

🏗️ Build Test Suite Results

Ecosystem Project Build/Install Tests Status
Bun elysia 1/1 passed ✅ PASS
Bun hono 1/1 passed ✅ PASS
C++ fmt N/A ✅ PASS
C++ json N/A ✅ PASS
Deno oak N/A 1/1 passed ✅ PASS
Deno std N/A 1/1 passed ✅ PASS
.NET hello-world N/A ✅ PASS
.NET json-parse N/A ✅ PASS
Go color 1/1 passed ✅ PASS
Go env 1/1 passed ✅ PASS
Go uuid 1/1 passed ✅ PASS
Java gson 1/1 passed ✅ PASS
Java caffeine 1/1 passed ✅ PASS
Node.js clsx All passed ✅ PASS
Node.js execa All passed ✅ PASS
Node.js p-limit All passed ✅ PASS
Rust fd 1/1 passed ✅ PASS
Rust zoxide 1/1 passed ✅ PASS

Overall: 8/8 ecosystems passed — ✅ PASS

Generated by Build Test Suite for issue #2396 · ● 474.7K ·

@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

Smoke Test: Services Connectivity

Check Result
Redis PING ❌ Timeout (no response)
PostgreSQL pg_isready ❌ No response
PostgreSQL SELECT 1 ❌ No response

Overall: FAILhost.docker.internal is unreachable for both Redis (6379) and PostgreSQL (5432). Service containers may not be running or network routing is unavailable in this environment.

🔌 Service connectivity validated by Smoke Services

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants