Skip to content

feat(ci): run the tautology detector in CI — advisory, measured, with a scheduled enforcement decision #940

Closed

Description

@admarble

Motivation

The behavior-rule (tautology) detector (src/lib/heuristics/behavior-rule-detector.ts) runs in exactly two places, both inside LLM-driven skill phases: /spec and /qa §6e (behavior_rule_survival_status). It is never executed in CI — ci.yml has no invocation. The standing incident note from #810 is blunt: "a failing tautology-detector is usually a REAL finding; that gate never fires in CI." So the one deterministic tool the repo owns for the tests-that-don't-bind defect class only runs when an LLM remembers to run it, inside phases that small diffs can skip entirely (Simple Fix mode omits §6d and more below the 100-line smallDiffThreshold).

The defect class it targets is the most common deterministic-catchable class in the recent gap-prompt audit (#842, #883, #799, #467 — tests passing without binding to behavior). Every catch converted into a deterministic gate ratchets work out of the manual second look permanently (the #834 pattern); this is the cheapest such conversion available because the detector already exists.

Proposal

Two-phase rollout, measurement before enforcement (the #922/#928 pattern — the citation-grounding gate was rejected on an 8:1 noise ratio; this detector must earn enforcement the same way).

Phase A — advisory + measured (this issue):

Phase B — enforce (follow-up issue, filed only if the measured FP rate clears a bar the maintainer sets, e.g. <20%):

  • The job fails on high-confidence findings; an inline @tautology-skip <reason> escape hatch already exists in the detector's vocabulary — but note the standing QA rule that skips must be justified, since @tautology-skip was previously used to defang a measured-metric AC.

Non-Goals

Tailored caveats

Acceptance Criteria

  • AC-1: A ci.yml job runs the behavior-rule detector over test files changed vs origin/<base> on every PR and always exits 0 in Phase A. Evidence: job visible and green on this PR itself, which modifies test files.
  • AC-2: Findings render as PR annotations or a job-summary table with file, rule, and score — labeled headers, no box-drawing. Evidence: screenshot or job-summary link on a PR with a deliberately tautological fixture test (fixture removed before merge).
  • AC-3: The job emits a one-line machine-readable summary (filesScanned, findings) to the job summary for FP-rate accounting. Evidence: job summary from AC-1's run.
  • AC-4: Zero changed test files short-circuits cleanly. Evidence: job log from a docs-only test PR or a unit test of the file-selection script.
  • AC-5: A dated follow-up checklist item exists in this issue for the Phase B decision with the FP-rate bar stated. Evidence: issue comment after merge.

Human decisions required

Context

From the 2026-08-13 strategy review. The #810 incident note is the direct motivation; #885 fixed the known FP class; #922/#928 is the measure-first precedent this rollout copies. Complements the mutation-verification gate (that one checks the human performed a red-phase check; this one mechanically screens for tests that cannot fail).

Activity

  1. admarble commented on Aug 21, 2026

    @admarble
    ContributorAuthor

    /spec Plan — #940

    Complexity: Standard (5 ACs, 3 directories: .github/workflows/, scripts/qa/, docs/features/)

    AC Quality Check

    All 5 ACs pass the linter (0 flagged). One naming defect worth fixing in the issue body: AC-1 and the Motivation say "behavior-rule detector (src/lib/heuristics/behavior-rule-detector.ts)", but that module detects behavior-rule ACs (#552) — it takes an AcceptanceCriterion, not a test file, and has no notion of a score. The tool the issue actually describes (tests that don't bind to production code, @tautology-skip, >50% blocking, the #885 FP fix, #810 note) is src/lib/test-tautology-detector.ts with the CLI wrapper scripts/qa/tautology-detector-cli.ts. Plan below targets the tautology detector; see Open Question 1.

    Scope Assessment

    Non-Goals: present (3 items: no enforcement, no detector rework, no full-corpus sweep).

    Metric Value Status
    Feature count 1 ✅
    AC items 5 ✅
    Directory spread 3 ✅

    Verdict: ✅ SCOPE_OK

    Acceptance Criteria

    AC-1: ci.yml job runs the detector over test files changed vs origin/<base> on every PR, always exit 0

    • Verification: Integration Test (CLI) + Manual (green job on the PR)
    • Scenario: Given a PR touching *.test.ts → When the tautology-advisory job runs → Then it diffs origin/${{ github.base_ref }}...HEAD, scans only those files, and the step exits 0 regardless of findings
    • Assumptions: CI checkout uses default fetch-depth: 1, so origin/<base> does not exist (that is exactly why the CLI header says "inert in CI by design"); the job must git fetch origin <base> explicitly. Exit-0 is a CLI flag (--advisory), not continue-on-error: — the latter shows a red ✗ on the step and hides real crashes (exit 2) behind the same mask.

    AC-2: Findings render as annotations / job-summary table with file, rule, score — labeled headers, no box-drawing

    • Verification: Manual (job summary on a PR with a throwaway tautological fixture test; fixture removed before merge)
    • Scenario: Given one changed test file with 2/5 tautological blocks → When the job runs → Then each block emits ::warning file=<path>,line=<n>,title=Tautological test::<description> — no production call and $GITHUB_STEP_SUMMARY gets a markdown table | File | Line | Test | Style | plus per-file score tautologicalCount/totalTests
    • Assumptions: formatTautologyResults() already emits markdown tables (no box-drawing) — reuse it for the summary body rather than writing a second renderer.

    AC-3: One-line machine-readable summary (filesScanned, findings) in the job summary

    • Verification: Integration Test (CLI --json/summary output) + Manual (job summary)
    • Scenario: Given any run → Then the summary's last line is <!-- TAUTOLOGY_SUMMARY {"pr":<n>,"filesScanned":N,"totalTests":N,"findings":N,"score":0.xx} --> — HTML-comment-wrapped so it is greppable from CI history (gh api .../jobs → summary) without cluttering the rendered table
    • Assumptions: pr comes from ${{ github.event.pull_request.number }}; score = findings/totalTests (0 when no tests).

    AC-4: Zero changed test files short-circuits cleanly

    • Verification: Unit Test (file-selection function) + Manual (docs-only PR log)
    • Scenario: Given diff contains no \.(test|spec)\.[jt]sx?$ paths → Then CLI prints No test files changed in diff, writes filesScanned:0, findings:0 summary line, exits 0. Also: Given origin/<base> unresolvable → Then exit 0 with an explicit Error: base ref not found line (today this path silently reports zero files — it must say it skipped, or the Phase A FP data is polluted with vacuous zeros).
    • Assumptions: getChangedTestFiles() is currently a private function — export it (or move selection into a testable helper) so the unit test binds to production code and the test itself isn't tautological.

    AC-5: Dated Phase B checklist item in this issue with the FP-rate bar

    • Verification: Manual (issue comment after merge)
    • Scenario: After merge, post: - [ ] 2026-09-18 (or after 20 PRs): compute FP rate from TAUTOLOGY_SUMMARY lines; if <20%, file Phase B enforcement issue; else tune/retire — include the exact gh one-liner that aggregates the summaries so the decision is mechanical.

    Implementation Plan

    Phase 1 — CLI becomes CI-capable (scripts/qa/tautology-detector-cli.ts)

    1. Add flags: --base <ref> (default: resolveDiffBase(cwd,"main") — unchanged local behavior), --advisory (force exit 0 for blocking; exit 2 on internal error stays — a crashed detector must not read as "clean"), --github (emit ::warning annotations + append to $GITHUB_STEP_SUMMARY when the env var is set).
    2. Extract selectChangedTestFiles(base: string, cwd: string): {files: string[]; baseResolved: boolean} and export it; make the "no base ref" case explicit in output (AC-4). Keep execFileSync array form (fix(observability): phase diff stats compare against the local base ref while worktrees branch from origin/<base> — phantom filesModified + base tip logged as the phase commit #878/fix(observability): remaining bare main...HEAD consumers after #878 — qa-cache diff hash, worktree-manager summaries, aider file-context, non-qa skill gates #890).
    3. Emit the TAUTOLOGY_SUMMARY line in both --json and summary outputs (AC-3). Reuse formatTautologyResults() for the human table (AC-2).
    4. Rewrite the header comment — it currently documents CI inertness as a design property (fix(qa): tautology detector scores subprocess-driven integration tests 100% tautological (cli.integration.test.ts, pre-existing) #885 AC-4); after this change that statement is false. Keep the /qa invocation in quality-checks.sh untouched (it still uses defaults).

    Phase 2 — CI job (.github/workflows/ci.yml)
    5. New job tautology-advisory, if: github.event_name == 'pull_request', steps: checkout → git fetch --no-tags origin ${{ github.base_ref }} → setup-node 22 → npm ci → npx tsx scripts/qa/tautology-detector-cli.ts --base origin/${{ github.base_ref }} --advisory --github. Pass PR_NUMBER=${{ github.event.pull_request.number }}. No globbing — file list comes from git, so scripts/dev/ (gitignored, #930) can never enter it.
    6. Do not add it to required checks; it's advisory.

    Phase 3 — tests + docs
    7. Extend scripts/qa/tautology-detector-cli.test.ts (already .test.ts with 60s timeout; subprocess tests under scripts/ flake per #842 — prefer a unit test of the exported selectChangedTestFiles against a temp git repo over another spawn). Cover: zero test files → skip line + exit 0; --advisory with a blocking fixture → exit 0; unresolvable base → explicit skip line. These are gate tests → each needs the Mutation-verified: marker in the PR body (CLAUDE.md / #939).
    8. docs/features/test-tautology-detector.md: add a "CI (Phase A, advisory)" section + the FP-rate aggregation one-liner. Update docs/internal/what-weve-built.md if it lists the #885 "inert in CI" fact.
    9. Post-merge: AC-5 comment on this issue (dated checklist + bar).

    Design Review

    1. Where does this logic belong? In the existing CLI wrapper, not a new script — /qa and CI should run the same binary so Phase A numbers measure the same detector /qa enforces. The YAML only wires flags.
    2. Simplest correct approach? Flags + a git fetch step. Rejected: fetch-depth: 0 (slower on every PR for one job; a targeted fetch of the base ref suffices); a separate scripts/ci/ runner (would fork the file-selection logic and drift from /qa); continue-on-error (masks exit-2 crashes).
    3. Existing pattern? validate-skills job (npx tsx scripts/lint-*.ts on Node 22, npm ci). Annotations follow GitHub workflow-command format, same as eslint's problem matcher output.
    4. Senior reviewer challenge? "Why not just git fetch in the existing build job and append one step?" — because the build job runs on push too and has a matrix; an advisory PR-only job is cheaper to reason about and to delete in Phase B if the data says retire. Also: "Is the @tautology-skip pragma counted as a finding or a skip?" — it's a skip today (skippedFiles); report it in the summary line as skipped:N so the FP analysis can see how often the hatch is used (the fix(test): cli.integration flag-surface tests assert on the not-initialized guard, so they fail on any locally init'd clone #883-class concern in the issue).

    Feature Quality Planning

    All standard checks pass. Notable items:

    • Silent-zero hazard: the current CLI returns [] on any git error, which in CI would log as a clean "nothing to scan" — the single most likely way Phase A produces garbage data. AC-4 scenario 2 covers it.
    • Fork PRs: GITHUB_STEP_SUMMARY and ::warning annotations work on forks with read-only GITHUB_TOKEN; no API writes needed. Good.
    • @tautology-skip observability: surface skipped-file count in the summary (see Design Review 4).

    Open Questions

    1. Issue names the wrong module. AC-1 says "behavior-rule detector"; the described tool is src/lib/test-tautology-detector.ts / scripts/qa/tautology-detector-cli.ts. — Recommendation: edit the issue body to name the tautology detector; plan proceeds on that reading. Impact if wrong: the behavior-rule detector cannot scan test files at all, so a literal AC-1 is unimplementable.
    2. Base for git fetch: github.base_ref only exists on pull_request events. — Recommendation: gate the job on pull_request (skip on push to main — nothing to diff). Impact: none; matches the "on PRs" wording.
    3. Summary line location: $GITHUB_STEP_SUMMARY (AC-3 says job summary) vs job log. — Recommendation: both; the summary is what gh api retrieves for the Phase B tally.

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: Single focused change to an existing CLI + one YAML job; the existing tautology-detector-cli.test.ts is the natural home for new tests, so testgen adds little. SCOPE_OK. /qa must check the mutation-verification markers for the gate tests (§6i) and that the CI job actually ran green on the PR (AC-1 evidence).

    Label Review

    Current: (none)
    Recommended: enhancement, ci, planned
    Reason: New CI job + CLI flags; not a bug. No UI, so no ui/test phase.
    Quality Loop: Won't auto-enable — SCOPE_OK, no complexity labels.

  2. added
    planned
    enhancement
    on Aug 21, 2026
  3. admarble commented on Aug 21, 2026

    @admarble
    ContributorAuthor

    Phase B decision — follow-up checklist

    PR #955 (merged) shipped Phase A: tautology-advisory runs the test-tautology detector on every PR, always exits 0, and emits <!-- TAUTOLOGY_SUMMARY {"pr":N,"filesScanned":N,"totalTests":N,"findings":N,"skipped":N,"score":0.xx} --> to the job summary.

    Aggregation command:

    gh run list --workflow=ci.yml --json databaseId -q '.[].databaseId' | \
      xargs -I{} gh api "/repos/{owner}/{repo}/actions/jobs/{}" 2>/dev/null | \
      grep -o '<!-- TAUTOLOGY_SUMMARY .* -->'

    Known FP data point already collected on PR #955 itself: the job flagged all 5 test blocks in scripts/qa/tautology-detector-cli.test.ts (a subprocess-driven integration test that spawns the CLI and asserts on stdout/exit code rather than importing named production functions) — the same false-positive class #885 addressed for a different file. Worth revisiting whether #885's fix should generalize to this shape, independent of the Phase B enforcement decision.

  4. admarble commented on Aug 21, 2026

    @admarble
    ContributorAuthor

    Filed #956 for the tautology-detector-cli.test.ts false-positive noted above — root cause is path.resolve(__dirname, ...)-built spawn paths evading #885's textual dist//scripts/ heuristic.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementplanned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions