Skip to content

test(B-0058): add Bun tests for alignment-clause audit tools#2107

Merged
AceHack merged 1 commit into
mainfrom
worktree-b-0058-alignment-audit-tests
May 8, 2026
Merged

test(B-0058): add Bun tests for alignment-clause audit tools#2107
AceHack merged 1 commit into
mainfrom
worktree-b-0058-alignment-audit-tests

Conversation

@AceHack
Copy link
Copy Markdown
Member

@AceHack AceHack commented May 8, 2026

Summary

What's tested

audit_clause_coverage.test.ts (26 tests):

  • extractClauses regex: single clause, multiple clauses, deduplication, word boundaries, canonical ordering, no false positives on partial IDs
  • ALL_CLAUSES constant: count (21), HC-1..HC-7, SD-1..SD-9, DIR-1..DIR-5
  • audit() integration: result shape, surface discovery, field validation, zero-count consistency, uncited-clause subset, cited-clause validity
  • main() CLI: exit codes for --help, --json, --md, unknown args, --gate 0 vs --gate 999

audit_clause_drift.test.ts (8 tests):

  • main() CLI: exit codes for --help, unknown args, missing values
  • No-drift baseline: HEAD vs HEAD in plain/json/md modes
  • Default base ref: no-args invocation defaults to main vs HEAD

Test plan

  • bun test tools/alignment/audit_clause_coverage.test.ts — 26 pass, 0 fail
  • bun test tools/alignment/audit_clause_drift.test.ts — 8 pass, 0 fail
  • dotnet build -c Release — 0 warnings, 0 errors

B-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

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>
Copilot AI review requested due to automatic review settings May 8, 2026 17:19
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@AceHack AceHack enabled auto-merge (squash) May 8, 2026 17:20
@AceHack AceHack merged commit ab4b51e into main May 8, 2026
27 checks passed
@AceHack AceHack deleted the worktree-b-0058-alignment-audit-tests branch May 8, 2026 17:22
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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, and main() exit codes).
  • Adds Bun tests for audit_clause_drift.ts covering CLI exit codes and a no-drift baseline.
  • Exports ALL_CLAUSES and extractClauses() from audit_clause_coverage.ts to 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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants