Skip to content

fix(qa): resolve constructed spawn paths in the tautology detector (#956) - #1002

Merged
admarble merged 8 commits into
mainfrom
feature/956-fix-qa-tautology-detector-still-flags-a-subprocess
Sep 8, 2026
Merged

admarble merged 8 commits into
mainfrom
feature/956-fix-qa-tautology-detector-still-flags-a-subprocess

Conversation

@admarble

@admarble admarble commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Teaches the tautology detector to resolve constructed spawn paths and to see through the indirection layers a purely textual scan cannot. The build-output heuristic recognized a spawn as production only when the source held a contiguous dist/, hooks/*.sh or scripts/** substring. Two idiomatic constructions leave no such substring:

const CLI  = path.resolve(__dirname, "tautology-detector-cli.ts");  // runtime global
const HOOK = join(REPO_ROOT, "hooks", "pre-tool.sh");               // split literals

Path expressions are now resolved to an absolute path (from the analyzed file's own location, never process.cwd()) and checked against the repository.

Four adjacent "one indirection layer" misses are fixed alongside, because the corpus classification would otherwise be unexplained noise (spec OQ-1): expression-bodied arrow helpers, dynamic destructured await import(), call-site argument binding into helper parameters, and — the last residual class — a suite handle instantiated in a beforeEach/beforeAll hook and driven in the blocks.

Corpus flags drop 132 → 25; repo-wide 600 → 201 across 288 test files.

Guardrails against over-permissiveness

Widening the exemption is the real risk, so each widening is bounded:

  • Resolved paths: must be inside the repo root, not under node_modules/, and name an executable extension. A mkdtempSync(...) sandbox, process.env.X, or an interpolated template resolves to null and is never production.
  • Hook-assigned handles: two gates, both load-bearing. The hook body must itself reach production, and the handle must be used in call position (client.callTool(...)), not merely read as a value. The second gate was added after measurement, not by design instinct — see below.

False-negative sweep (repo-wide, 288 test files): flagged 600 → 201; newly-clean = 399, newly-flagged = 0. Every legitimately-flagged block held its count exactly: the six file-content-legit gate files (8/4/4/3/3/2) and pre-tool-hook.integration.test.ts's harness-sanity block (1).

Why the call-shape gate exists

The first version of the hook rule gated only on "the hook body reaches production." Measured, it silenced pre-tool-hook.integration.test.ts:1529 — a harness sanity check (confirms jq is actually unavailable on the filtered PATH) that spawns only a system binary but reads a hook-assigned noJqPath string. Repo-wide newly-clean jumped to 408. Adding the call-shape gate restored that block to flagged and is pinned by a regression test.

AC verification

AC Description Status Evidence
AC-1 scripts/qa/tautology-detector-cli.test.ts scores 0 tautological ✅ -t "956 target" passes; row 6 → 0
AC-2 Genuinely tautological test with the same __dirname idiom still flagged ✅ -t "956 negative" passes; mutation-verified below
AC-3 #966 remainder in pre-tool-hook.integration.test.ts recognized ✅ -t "956 segments" asserts ≤ 1; row 4 → 1 (L1529 only)
AC-4 Corpus classification recorded ✅ 33-row table below; all classes inside the stated three-value enum; every subprocess-fp-fixed row reads after = 0
AC-5 Existing detector suite green ✅ 85 passed

Mutation records

Mutation-verified: AC-2 — removed the __dirname recognition (THIS_DIR_EXPRESSIONS branch in resolvePathExpression replaced with a dead if (false)); src/lib/test-tautology-detector.corpus.test.ts > 956 negative failed on the spawns the resolved CLI assertion; restored.

Mutation-verified: AC-4 — dropped the calledAsHandle call-shape gate on hook-assigned handles (replaced with if (true)); src/lib/test-tautology-detector.test.ts > still flags a block that only reads a value the hook computed failed; restored.

AC-4 — corpus classification (33 files)

File Before After Class
__tests__/cleanup-worktree-branch-resolution.integration.test.ts 12 0 subprocess-fp-fixed
__tests__/cleanup-worktree-checkout-guard.integration.test.ts 3 0 subprocess-fp-fixed
__tests__/integration/behavior-rule-qa-wiring.integration.test.ts 9 4 file-content-legit
__tests__/integration/behavior-rule-skill-sync.integration.test.ts 2 2 file-content-legit
__tests__/integration/behavior-rule-spec-wiring.integration.test.ts 8 8 file-content-legit
__tests__/integration/mcp-e2e.integration.test.ts 0 0 subprocess-fp-fixed
__tests__/integration/mcp-serve-multi-client.integration.test.ts 0 0 subprocess-fp-fixed
__tests__/integration/mcp-serve.integration.test.ts 6 0 subprocess-fp-fixed
__tests__/integration/qa-markdown-only-ci-snippet.integration.test.ts 4 4 file-content-legit
__tests__/integration/skill-sync.integration.test.ts 0 0 subprocess-fp-fixed
__tests__/integration/spec-marker-skill-sync.integration.test.ts 3 3 file-content-legit
__tests__/new-feature-checkout-guard.integration.test.ts 4 0 subprocess-fp-fixed
__tests__/new-feature-frozen-install.integration.test.ts 18 0 subprocess-fp-fixed
__tests__/plugin-staleness-warning.integration.test.ts 3 3 file-content-legit
__tests__/pre-tool-hook.integration.test.ts 4 1 harness-sanity-legit
scripts/qa/precheck-cli.integration.test.ts 2 0 subprocess-fp-fixed
scripts/qa/tautology-detector-cli.test.ts 6 0 subprocess-fp-fixed
scripts/spec/ground-check-cli.integration.test.ts 0 0 subprocess-fp-fixed
src/commands/__tests__/locks-cli.integration.test.ts 4 0 subprocess-fp-fixed
src/commands/cli.integration.test.ts 0 0 subprocess-fp-fixed
src/commands/doctor.integration.test.ts 0 0 subprocess-fp-fixed
src/commands/numeric-flags.integration.test.ts 0 0 subprocess-fp-fixed
src/commands/run-tui.integration.test.ts 0 0 subprocess-fp-fixed
src/commands/serve.integration.test.ts 0 0 subprocess-fp-fixed
src/commands/sync-source-invocation.integration.test.ts 1 0 subprocess-fp-fixed
src/lib/__tests__/merger-release-checkout-lock.integration.test.ts 0 0 subprocess-fp-fixed
src/lib/locks/checkout-lock.integration.test.ts 0 0 subprocess-fp-fixed
src/lib/locks/lock-manager.integration.test.ts 5 0 subprocess-fp-fixed
src/lib/test-tautology-detector.test.ts 0 0 subprocess-fp-fixed
src/lib/workflow/abort-logging.integration.test.ts 3 0 subprocess-fp-fixed
src/lib/workflow/phase-registry.integration.test.ts 0 0 subprocess-fp-fixed
src/lib/workflow/state-update-cli.test.ts 8 0 subprocess-fp-fixed
src/mcp/server-extended.test.ts 27 0 subprocess-fp-fixed

TOTALS before=132 after=25 files=33

Class definitions

Every row sits inside the three-value enum AC-4 specifies. The previous revision of this PR used a fourth class, deferred-fp, for src/mcp/server-extended.test.ts (27 → 21); that file is now 0 and the fourth class is gone.

Test plan

  • npx vitest run src/lib/test-tautology-detector.corpus.test.ts -t "956 target" → passes
  • … -t "956 negative" → passes
  • … -t "956 segments" → passes
  • npx vitest run src/lib/test-tautology-detector.test.ts → 85 passed
  • npm run build → clean
  • npm run lint → clean (0 warnings)
  • Repo-wide false-negative sweep → 0 newly flagged; all legit flags held
  • Full npm test — not run locally (see Known gaps)

Known gaps

  • Full suite not run locally. Three prior sessions on this issue were killed by the launcher's 30-minute ceiling running npm test, one losing the worktree. Targeted tests plus build/lint were run instead; CI is the backstop.

Refs #956

🤖 Generated with Claude Code

A+ pass (runner, 2026-09-07, commit 3d913f3)

Addresses the QA round-2 notes so this PR can reach READY_FOR_MERGE:

  • buildPathContext now has direct unit tests (test-tautology-detector.test.ts, describe buildPathContext (#956)): thisDir is anchored on the analyzed file; the repo root is found by walking up to .git (asserted against this checkout), falls back to the nearest package.json in a temp tree, and is null when neither exists; vars starts empty.
  • productionHandles reference-vs-call asymmetry documented at the use site (testBlockCallsProductionCode, step 3) with the QA's measurement — pre-existing on main; tightening to call shape moves the repo-wide flagged count 201 → 204 and newly flags a legitimate block (config-resolver.model-roles.test.ts:249) — so the next reader does not redo the analysis. Deliberately not changed (the naive fix regresses).

90/90 detector + corpus tests pass; typecheck clean.

…utology-detector-still-flags-a-subprocess

# Conflicts:
#	CHANGELOG.md
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.

1 participant