feat: validate config files against published JSON Schema at runtime#2384
feat: validate config files against published JSON Schema at runtime#2384
Conversation
Replace the hand-written validateAwfFileConfig() implementation with ajv-based validation against the published awf-config.schema.json. This makes the JSON Schema the single source of truth for: 1. Runtime validation inside awf (this change) 2. External consumers like the gh-aw compiler (schema is downloadable as a release asset and from docs/awf-config.schema.json) 3. IDE autocomplete via $schema field Changes: - Move ajv from devDependencies to dependencies (runtime use) - Add src/schema-validator.ts: compiles schema once, formats ajv errors into human-readable messages matching the previous validator style - Add src/awf-config-schema.json: bundleable copy of the schema (imported at compile time, works with esbuild single-file bundle) - Update generate-schema.mjs to write both docs/ and src/ copies - Add sync test ensuring src/ and docs/ schemas stay aligned - Update one test assertion for new enum formatting The error messages are backward-compatible with the previous hand-written validator (all 113 config/schema tests pass unchanged except one enum format improvement: '"5m" or "1h"' → 'one of: 5m, 1h'). Closes #2374 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
| Metric | Base | PR | Delta |
|---|---|---|---|
| Lines | 85.90% | 85.82% | 📉 -0.08% |
| Statements | 85.88% | 85.70% | 📉 -0.18% |
| Functions | 88.00% | 88.18% | 📈 +0.18% |
| Branches | 80.06% | 78.55% | 📉 -1.51% |
📁 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/config-file.ts |
97.0% → 100.0% (+3.02%) | 96.6% → 98.0% (+1.42%) |
✨ New Files (1 files)
src/schema-validator.ts: 96.4% lines
Coverage comparison generated by scripts/ci/compare-coverage.ts
|
@copilot the schema needs to be versioned |
There was a problem hiding this comment.
Pull request overview
Introduces AJV-based runtime validation for AWF config files using the published awf-config.schema.json, aiming to make the JSON Schema the single source of truth for validation across AWF, external tooling, and IDEs.
Changes:
- Add
src/schema-validator.tsto compile and run AJV schema validation with human-readable error formatting. - Replace hand-written config validation in
src/config-file.tswith schema-based validation. - Generate and add a bundleable schema copy in
src/awf-config-schema.json, plus a test to keep it in sync withdocs/.
Show a summary per file
| File | Description |
|---|---|
| package.json | Moves ajv into runtime dependencies. |
| src/schema-validator.ts | New AJV-based validator + error formatting/deduplication. |
| src/config-file.ts | Delegates config validation to the schema validator. |
| src/awf-config-schema.json | Adds schema copy intended for runtime/bundling. |
| scripts/generate-schema.mjs | Writes schema output to src/ as well as docs/. |
| src/schema.test.ts | Adds sync-check ensuring src/ schema matches docs/ schema (minus $id). |
| src/config-file.test.ts | Updates expected enum error message format. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 7/7 changed files
- Comments generated: 2
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
| Metric | Base | PR | Delta |
|---|---|---|---|
| Lines | 85.90% | 85.80% | 📉 -0.10% |
| Statements | 85.88% | 85.68% | 📉 -0.20% |
| Functions | 88.00% | 88.18% | 📈 +0.18% |
| Branches | 80.06% | 78.51% | 📉 -1.55% |
📁 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/config-file.ts |
97.0% → 100.0% (+3.02%) | 96.6% → 98.0% (+1.42%) |
✨ New Files (1 files)
src/schema-validator.ts: 96.2% lines
Coverage comparison generated by scripts/ci/compare-coverage.ts
|
| Metric | Base | PR | Delta |
|---|---|---|---|
| Lines | 85.90% | 85.80% | 📉 -0.10% |
| Statements | 85.88% | 85.68% | 📉 -0.20% |
| Functions | 88.00% | 88.21% | 📈 +0.21% |
| Branches | 80.06% | 78.49% | 📉 -1.57% |
📁 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/config-file.ts |
97.0% → 100.0% (+3.02%) | 96.6% → 98.0% (+1.42%) |
✨ New Files (1 files)
src/schema-validator.ts: 94.8% lines
Coverage comparison generated by scripts/ci/compare-coverage.ts
|
Smoke Test Result:
Overall Status: PASS
|
Done in bafaae2. Following the same pattern as
|
|
@copilot all schema versions should be tied to a release tag. is there a way to do this in release.md? |
…asing.md Agent-Logs-Url: https://github.com/github/gh-aw-firewall/sessions/72cdaa37-37d8-4564-937b-e5f2ee8eafc1 Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Done in 4b4145e. Added a "JSON Schema versioning" section to
|
|
| Metric | Base | PR | Delta |
|---|---|---|---|
| Lines | 85.90% | 85.80% | 📉 -0.10% |
| Statements | 85.88% | 85.68% | 📉 -0.20% |
| Functions | 88.00% | 88.21% | 📈 +0.21% |
| Branches | 80.06% | 78.49% | 📉 -1.57% |
📁 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/config-file.ts |
97.0% → 100.0% (+3.02%) | 96.6% → 98.0% (+1.42%) |
✨ New Files (1 files)
src/schema-validator.ts: 94.9% lines
Coverage comparison generated by scripts/ci/compare-coverage.ts
- Add 18 unit tests covering all error formatting paths - Remove dead code: hasMinimumOne() and determineArticle() functions (all integer fields have minimum:1; no vowel-starting types reach the article logic after prior case handling) - Simplify isArrayOfStringsField() to a single boolean expression - Branch coverage for schema-validator.ts: 97.77% Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
| Metric | Base | PR | Delta |
|---|---|---|---|
| Lines | 85.90% | 85.83% | 📉 -0.07% |
| Statements | 85.88% | 85.71% | 📉 -0.17% |
| Functions | 88.00% | 88.15% | 📈 +0.15% |
| Branches | 80.06% | 78.67% | 📉 -1.39% |
📁 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/config-file.ts |
97.0% → 100.0% (+3.02%) | 96.6% → 98.0% (+1.42%) |
✨ New Files (1 files)
src/schema-validator.ts: 98.0% lines
Coverage comparison generated by scripts/ci/compare-coverage.ts
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
- Conditionally switch to azure.archive.ubuntu.com only if DNS resolves it - Falls back to default archive.ubuntu.com when BuildKit DNS can't reach the Azure mirror (common in Docker-in-Docker scenarios) - Improve apt_update_retry() to detect silent failures (apt returns 0 with 'Failed to fetch' warnings) and fall back to archive.ubuntu.com - Fixes persistent CI failures where BuildKit couldn't resolve azure.archive.ubuntu.com during container image builds Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
| Metric | Base | PR | Delta |
|---|---|---|---|
| Lines | 85.90% | 85.83% | 📉 -0.07% |
| Statements | 85.88% | 85.71% | 📉 -0.17% |
| Functions | 88.00% | 88.15% | 📈 +0.15% |
| Branches | 80.06% | 78.67% | 📉 -1.39% |
📁 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/config-file.ts |
97.0% → 100.0% (+3.02%) | 96.6% → 98.0% (+1.42%) |
✨ New Files (1 files)
src/schema-validator.ts: 98.0% lines
Coverage comparison generated by scripts/ci/compare-coverage.ts
🤖 Smoke Test Results
PR: feat: validate config files against published JSON Schema at runtime Overall: FAIL — smoke-data outputs were not populated by the pre-agent step.
|
|
Smoke Test Results:
|
This comment has been minimized.
This comment has been minimized.
Chroot Version Comparison Results
Overall: ❌ Not all tests passed — Python and Node.js versions differ between host and chroot environments.
|
🏗️ Build Test Suite Results
Overall: 8/8 ecosystems passed — ✅ PASS
|
This comment has been minimized.
This comment has been minimized.
Smoke Test Results
Overall: FAIL —
|
Smoke Test: Copilot BYOK (Offline) Mode
Running in BYOK offline mode ( Author:
|
|
feat: publish versioned schemas for JSONL audit/telemetry artifacts Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "registry.npmjs.org"See Network Configuration for more information.
|
Summary
Replace the hand-written
validateAwfFileConfig()with ajv-based validation against the publishedawf-config.schema.json. This makes the JSON Schema the single source of truth for:docs/awf-config.schema.json)$schemafieldChanges
package.jsonajvfrom devDependencies → dependenciessrc/schema-validator.tssrc/awf-config-schema.jsonscripts/generate-schema.mjssrc/alongsidedocs/src/config-file.tssrc/schema.test.tssrc/config-file.test.tsDesign decisions
ajv({ verbose: true })) to accessparentSchemafor rich error messagesfs.readFileSync)How gh-aw compiler uses this
The compiler can fetch the schema from:
https://github.com/github/gh-aw-firewall/releases/latest/download/awf-config.schema.jsonhttps://raw.githubusercontent.com/github/gh-aw-firewall/main/docs/awf-config.schema.jsonand validate configs client-side before passing them to awf.
Closes #2374