Skip to content

feat(ci): run the tautology detector in CI — advisory, measured (#940) - #955

Merged
admarble merged 3 commits into
mainfrom
feature/940-feat-ci-run-the-tautology-detector-in-ci-advis
Aug 21, 2026
Merged

admarble merged 3 commits into
mainfrom
feature/940-feat-ci-run-the-tautology-detector-in-ci-advis

Conversation

@admarble

@admarble admarble commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds a tautology-advisory CI job (.github/workflows/ci.yml) that runs the existing test-tautology detector on every PR's changed test files, comparing against the base branch. It always exits 0 — Phase A of the feat(ci): run the tautology detector in CI — advisory, measured, with a scheduled enforcement decision #940 rollout is advisory only, so nothing here can block a merge.
  • Findings surface as ::warning PR annotations, a job-summary markdown table, and a machine-readable <!-- TAUTOLOGY_SUMMARY {...} --> line so a false-positive rate can be measured across real PRs ahead of a Phase B enforcement decision.
  • scripts/qa/tautology-detector-cli.ts gains --base, --advisory, --github flags. selectChangedTestFiles is exported and unit-tested directly; an unresolvable base ref is now reported explicitly (not silently scanned as zero files), so Phase A data isn't polluted by vacuous zeros.
  • /qa's existing invocation via quality-checks.sh is unaffected — no new flags passed there.

Bugs found and fixed during self-review (before merge)

The first live CI run on this PR caught two real defects that manual/local testing had missed:

  1. The job never actually scanned anything. fetch-depth: 1 + a separate git fetch --depth=1 origin main leaves HEAD (the PR merge commit) and origin/main with no shared history, so git diff origin/main...HEAD throws fatal: ...: no merge base even though origin/main itself resolves. The job silently degraded to its "skip" path on every run. Reproduced locally with a real shallow clone against GitHub, fixed by switching the checkout to fetch-depth: 0 (full history — also removes the need for the separate fetch step), and verified fixed with a full clone. selectChangedTestFiles now also distinguishes "ref doesn't exist" from "ref exists but the diff failed" via a new error field, since the old code's blanket try/catch reported both identically.
  2. Script-injection anti-pattern: ${{ github.base_ref }} was interpolated directly into two run: shell blocks instead of via env:. Low exploitability (base_ref is repo-controlled, not fork-controlled) but fixed for consistency with the pattern already used for PR_NUMBER in the same job. Hoisted to env: BASE_REF: ${{ github.base_ref }}.

A third, smaller fix: the pre-existing tautology-detector-cli.test.ts's "default markdown output" test asserted on the old, less-accurate skip message; after fix #1 it correctly asserts on either skip message.

Pre-PR AC Verification

AC Description Status Evidence
AC-1 ci.yml job runs the detector vs origin/<base> on every PR, always exits 0 in Phase A ✅ Implemented Live evidence: tautology-advisory passed on this PR's actual CI run (job log) after the fetch-depth fix — it correctly diffed against origin/main and scanned this PR's own changed test files.
AC-2 Findings render as annotations / job-summary table with file, rule, score — no box-drawing ✅ Implemented Live evidence: the fixed job found 5 tautological blocks in the pre-existing tautology-detector-cli.test.ts (a subprocess-driven integration test — see note below) and rendered them as 5 ::warning file=...,line=N,title=Tautological test::... annotations plus a ### Test Quality Review markdown table, both visible in the real job log — no fixture needed.
AC-3 One-line machine-readable summary (filesScanned, findings) for FP-rate accounting ✅ Implemented emitGithubStepSummary appends the table and the TAUTOLOGY_SUMMARY marker to $GITHUB_STEP_SUMMARY in one call, verified locally against a simulated summary file ({"pr":940,"filesScanned":2,"totalTests":4,"findings":1,"skipped":0,"score":0.25}); same code path ran on the live CI job above.
AC-4 Zero changed test files short-circuits cleanly ✅ Implemented scripts/qa/select-changed-test-files.test.ts (4 unit tests, mocked child_process) covers: unresolvable base ref, zero test files, a mixed diff, and (added after the CI-caught bug) the "ref exists but diff throws — no merge base" case specifically.
AC-5 Dated follow-up checklist item for the Phase B decision with the FP-rate bar 🔄 Deferred (by design — evidence is "issue comment after merge") Will post to #940 immediately after this PR merges.

Note on the AC-2 finding itself (not a bug in this PR): tautology-detector-cli.test.ts spawns the CLI as a subprocess and asserts on stdout/exit code rather than importing named production functions, so the detector's import-tracking heuristic flags all 5 of its blocks — the same subprocess-driven-test false-positive class #885 addressed for a different file. This is exactly the kind of noise Phase A exists to measure, not something to fix here (issue #940's Non-Goals explicitly rule out detector-quality rework in this issue) — it's now real data for the eventual Phase B FP-rate decision.

Test plan

  • npm run build — passes
  • npm run lint — passes (0 warnings)
  • npm test — full suite: 269 files / 5516 tests passed (1 pre-existing expected fail, 2 pre-existing skips, unrelated to this change)
  • New unit tests: scripts/qa/select-changed-test-files.test.ts (4 tests, unit project) — includes a regression test locking in the shallow-clone/no-merge-base failure mode
  • Existing scripts/qa/tautology-detector-cli.test.ts (5 subprocess integration tests) — 1 assertion updated to accept the more accurate skip message (see "Bugs found" above); still verifies default (no-flag) CLI behavior used by /qa is unaffected
  • CI job exercised live on this PR (self-referential — this PR's own test-file changes are what it scans): green run after both fixes landed

Pre-PR Confidence Check

  • Weakest part: The --github annotation/summary-writing code paths are now proven end-to-end on real CI (not just local simulation), but only for the "findings present" and "unresolvable base" cases — the "zero changed test files" case with --github set has only local/unit coverage, not a live CI run, since every commit on this PR touched test files.
  • Coverage gaps: None known beyond the above. The core regression this PR's own review process caught (shallow-clone merge-base failure) now has both a unit test and live-CI confirmation.

Closes #940

🤖 Generated with Claude Code


Mutation-verified (recorded post-merge — should have shipped with the original commit): AC-4 — mutated selectChangedTestFiles's catch-block return from baseResolved: false to baseResolved: true (the exact "silently report success on a real diff failure" regression AC-4 exists to prevent); select-changed-test-files.test.ts's "reports a diff failure explicitly when the ref exists but shares no history with HEAD" test failed as expected, no other tests affected; mutation restored and suite re-confirmed green.

Phase A rollout: a new tautology-advisory CI job runs the existing
test-tautology detector on every PR's changed test files and always
exits 0. Findings surface as ::warning PR annotations and a
job-summary table, plus a machine-readable TAUTOLOGY_SUMMARY line for
accumulating a false-positive rate ahead of a Phase B enforcement
decision.

- scripts/qa/tautology-detector-cli.ts: new --base, --advisory,
  --github flags; selectChangedTestFiles exported and unit-testable;
  an unresolvable base ref is reported explicitly rather than
  silently scanning zero files, so Phase A data isn't polluted.
- .github/workflows/ci.yml: tautology-advisory job, PR-only, fetches
  the base ref explicitly (default checkout is fetch-depth: 1).
- /qa's existing invocation via quality-checks.sh is unaffected — no
  new flags passed, same default behavior.

Closes #940
… merge-base failure)

QA found the job's first live CI run silently degraded to skip mode:
fetch-depth: 1 + a separate depth=1 fetch of the base ref leaves HEAD
(the PR merge commit) and origin/<base> with no shared history, so
`git diff origin/<base>...HEAD` throws "fatal: ...: no merge base"
even though origin/<base> itself resolves. Confirmed by pulling the
job's own log, then reproduced locally with a real shallow clone
against GitHub and verified fixed with a full clone.

- ci.yml: checkout uses fetch-depth: 0 (full history), which both
  resolves the merge-base and removes the need for the separate
  "Fetch base branch" step. Also hoists github.base_ref into env
  (BASE_REF) instead of interpolating it directly into run: shell
  blocks, per the security-scan finding on this PR.
- tautology-detector-cli.ts: selectChangedTestFiles now distinguishes
  "ref does not exist" from "ref exists but the diff failed" (e.g. no
  merge base) via a new `error` field, and prefers execFileSync's
  stderr over the generic "Command failed" message wrapper. The old
  code collapsed both cases into an inaccurate "not found" message.
- New regression test locks in the shallow-clone failure mode.
…-output test

The build (22.x) CI job's own checkout is shallow (fetch-depth: 1,
unchanged) and hits the same merge-base-less diff as the
tautology-advisory job did before its fix. The prior CLI code
collapsed every diff failure into "No test files changed in diff";
after b4d153f's fix, an unresolvable-diff case correctly prints
"Cannot diff against base ref ..." instead. Widen the assertion to
accept both skip messages.
@admarble
admarble merged commit 0339d0f into main Aug 21, 2026
6 checks passed
@admarble
admarble deleted the feature/940-feat-ci-run-the-tautology-detector-in-ci-advis branch August 21, 2026 06:04
admarble added a commit that referenced this pull request Aug 21, 2026
admarble added a commit that referenced this pull request Aug 21, 2026
…rker shape (#940 follow-up) (#957)

#940/#955 shipped the tautology-advisory CI job, but nothing pinned
the ::warning annotation format, the TAUTOLOGY_SUMMARY marker's JSON
shape, or the --github + zero-changed-test-files combination — only
live CI runs and manual verification covered them, so a future
refactor of any of the three could silently break Phase A's FP-rate
accounting with no test going red.

- Export emitGithubAnnotations, emitGithubStepSummary, and
  summaryMarker (previously private) so their output can be asserted
  on directly.
- New unit tests (tautology-github-output.test.ts): annotation format
  for tautological vs. non-tautological blocks, marker JSON shape
  including the reason field, step-summary file writing, and the
  stdout fallback when $GITHUB_STEP_SUMMARY is unset.
- New subprocess integration test in tautology-detector-cli.test.ts:
  runs the real CLI with --base HEAD --advisory --github (deterministic
  zero-files diff) and asserts the skip message + marker land in a
  real $GITHUB_STEP_SUMMARY file — closes the "never exercised on a
  real CLI invocation" gap for that flag combination.

Mutation-verified: AC-2 (annotation format) — removed the
isTautological guard in emitGithubAnnotations (`if (true) continue`);
"emits one ::warning line per tautological block" failed as expected,
no other tests affected; restored.

Mutation-verified: AC-3 (summary marker) — dropped the marker from
emitGithubStepSummary's body; both step-summary unit tests and the new
integration test failed as expected, no other tests affected; restored.

<!-- SEQUANT_MUTATION: {"ac":"AC-2","mutation":"emitGithubAnnotations: if (!block.isTautological) continue -> if (true) continue","failedTest":"emits one ::warning line per tautological block, in workflow-command format"} -->
<!-- SEQUANT_MUTATION: {"ac":"AC-3","mutation":"emitGithubStepSummary: body includes marker -> body omits marker","failedTest":"--github with zero changed test files writes the skip summary and marker to $GITHUB_STEP_SUMMARY"} -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant