test(B-0058): add Bun tests for alignment-clause audit tools#2107
Merged
Conversation
Adds test coverage for the two alignment tools shipped in PRs #2102-2105: - audit_clause_coverage.test.ts (26 tests): extractClauses regex logic, ALL_CLAUSES constant, audit() integration, main() CLI arg parsing + gate - audit_clause_drift.test.ts (8 tests): main() CLI arg parsing, no-drift baseline (HEAD vs HEAD), default base ref Exports extractClauses and ALL_CLAUSES from audit_clause_coverage.ts to enable direct unit testing of the core regex matching logic. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
Pull request overview
Adds Bun test coverage for the alignment-clause audit tooling under tools/alignment/, enabling direct unit testing of the clause-extraction logic and providing basic CLI/integration assertions for both the coverage auditor and drift detector.
Changes:
- Adds Bun tests for
audit_clause_coverage.ts(regex extraction,ALL_CLAUSES,audit()shape, andmain()exit codes). - Adds Bun tests for
audit_clause_drift.tscovering CLI exit codes and a no-drift baseline. - Exports
ALL_CLAUSESandextractClauses()fromaudit_clause_coverage.tsto support unit tests.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tools/alignment/audit_clause_drift.test.ts | New Bun tests for drift-detector CLI behavior and baseline no-drift assertions. |
| tools/alignment/audit_clause_coverage.ts | Exposes ALL_CLAUSES and extractClauses() for direct unit testing. |
| tools/alignment/audit_clause_coverage.test.ts | New Bun tests for clause extraction, audit result shape, and CLI exit codes. |
Comment on lines
+88
to
+89
| const result = audit(); | ||
| expect(result.schema).toBe("alignment-clause-coverage-v2"); |
Comment on lines
+140
to
+143
| describe("main() CLI", () => { | ||
| test("returns 0 with no args", () => { | ||
| expect(main([])).toBe(0); | ||
| }); |
Comment on lines
+11
to
+48
| describe("main() CLI", () => { | ||
| test("returns 0 with --help", () => { | ||
| expect(main(["--help"])).toBe(0); | ||
| }); | ||
|
|
||
| test("returns 2 for unknown arg", () => { | ||
| expect(main(["--bad-flag"])).toBe(2); | ||
| }); | ||
|
|
||
| test("returns 2 when --base has no value", () => { | ||
| expect(main(["--base"])).toBe(2); | ||
| }); | ||
|
|
||
| test("returns 2 when --head has no value", () => { | ||
| expect(main(["--head"])).toBe(2); | ||
| }); | ||
| }); | ||
|
|
||
| describe("no-drift baseline", () => { | ||
| test("HEAD vs HEAD shows zero drift", () => { | ||
| const code = main(["--base", "HEAD", "--head", "HEAD"]); | ||
| expect(code).toBe(0); | ||
| }); | ||
|
|
||
| test("HEAD vs HEAD with --json returns 0", () => { | ||
| const code = main(["--base", "HEAD", "--head", "HEAD", "--json"]); | ||
| expect(code).toBe(0); | ||
| }); | ||
|
|
||
| test("HEAD vs HEAD with --md returns 0", () => { | ||
| const code = main(["--base", "HEAD", "--head", "HEAD", "--md"]); | ||
| expect(code).toBe(0); | ||
| }); | ||
| }); | ||
|
|
||
| describe("default base ref", () => { | ||
| test("returns 0 with no args (defaults to main vs HEAD)", () => { | ||
| expect(main([])).toBe(0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
audit_clause_coverage.ts) and drift detector (audit_clause_drift.ts) shipped in PRs feat(B-0058): alignment-clause coverage audit tool #2102–feat(B-0058): extend clause coverage audit to backlog P0/P1 #2105extractClausesandALL_CLAUSESfromaudit_clause_coverage.tsto enable direct unit testing of the core regex matching logicexportkeywords addedWhat's tested
audit_clause_coverage.test.ts(26 tests):extractClausesregex: single clause, multiple clauses, deduplication, word boundaries, canonical ordering, no false positives on partial IDsALL_CLAUSESconstant: count (21), HC-1..HC-7, SD-1..SD-9, DIR-1..DIR-5audit()integration: result shape, surface discovery, field validation, zero-count consistency, uncited-clause subset, cited-clause validitymain()CLI: exit codes for--help,--json,--md, unknown args,--gate 0vs--gate 999audit_clause_drift.test.ts(8 tests):main()CLI: exit codes for--help, unknown args, missing valuesTest plan
bun test tools/alignment/audit_clause_coverage.test.ts— 26 pass, 0 failbun test tools/alignment/audit_clause_drift.test.ts— 8 pass, 0 faildotnet build -c Release— 0 warnings, 0 errorsB-0058 progress
This is a quality slice for B-0058 (AI ethics + safety research track). Prior slices landed the tools; this slice adds the test coverage that makes future extensions (glossary scanning, CI integration, candidate-failure log) safer to build.
🤖 Generated with Claude Code