Skip to content

feat(qa): health-report.ts — one script prints the fundamentals baseline, --check fails a raised metric, advisory CI job, release-checklist line #1502

Closed

Description

@admarble

Epic: graph-2026-10-fundamentals Tier: mechanical Execution: sequant_run Blocked by: #1501

Problem

Every later node's AC reads a number, and today each number is produced by an ad-hoc script in a session scratchpad (fnlen.mjs, grep pipelines). Without a committed script and baseline, "the number went from A to B" is unverifiable and nothing stops it going back up. The repo already has the pattern: scripts/qa/tautology-detector-cli.ts plus the tautology-advisory CI job.

Metric definitions (§4 of the founding doc; the script implements exactly these):

Key Definition Value on main 96990da
functions.over400, functions.over200, functions.longest ESLint max-lines-per-function with skipBlankLines: true, skipComments: true over non-test src/**/*.ts(x), bin/**/*.ts; longest = {file, name, lines} 4, 12, batch-executor runIssueWithLogging 1,049
emptyCatch.total, emptyCatch.byFile TypeScript AST CatchClause whose block has zero statements, non-test src 119; batch-executor 25
childProcessMockFiles test files matching vi.mock(\s*["'](node:)?child_process 31
ghCallFilesOutsideProvider non-test files matching spawnSync(\s*"gh" excluding src/lib/workflow/platforms/github.ts 3 (4 sites)
proseGate.files, proseGate.lines test files containing the literal SKILL.md and toContain or toMatch 76, 30,461
testRatio28d.sum, testRatio28d.median, testRatio28d.commits over non-merge commits on main in the last 28 days: lines added to paths matching `.test.tsx?$ tests/
deprecatedWithoutRemoval @deprecated JSDoc tags in non-test src/bin not followed on the same line by remove in v\d+\.\d+ 18 (of 18)
harness.claudeMdLines, harness.skillLines, harness.skillFiles, harness.memoryFiles wc -l CLAUDE.md; sum and count of .claude/skills/*/SKILL.md; file count of $CLAUDE_PROJECT_MEMORY_DIR when set, else null 25, 15,542, 19, 253
adrWithoutActor **Status:** Accepted lines in docs/adr/0*.md not matching Accepted \(owner, \d{4}-\d{2}-\d{2}\) 11

--check compares every numeric key except testRatio28d.* and harness.memoryFiles against scripts/qa/health-baseline.json and exits 1 naming each key that rose; the two excluded keys are reported only (the ratio slides with its 28-day window and would read as "raised" on any later day; the memory count is local to one machine; D-6). --write-baseline rewrites the file (I-4: only in a PR that lowers a metric).

Acceptance Criteria

  • AC-1: --json prints every key above. Evidence: npx tsx scripts/qa/health-report.ts --json | jq -e '.functions.over200 >= 0 and .emptyCatch.total >= 0 and .childProcessMockFiles >= 0 and .ghCallFilesOutsideProvider >= 0 and .proseGate.files >= 0 and .testRatio28d.sum >= 0 and .deprecatedWithoutRemoval >= 0 and .harness.skillLines >= 0 and .adrWithoutActor >= 0' > /dev/null && echo ok → ok
  • AC-2: The committed baseline equals what the script prints on the PR's tree. Evidence: test -f scripts/qa/health-baseline.json && diff <(npx tsx scripts/qa/health-report.ts --json | jq -S 'del(.generatedAt, .commit, .harness.memoryFiles, .testRatio28d)') <(jq -S 'del(.generatedAt, .commit, .harness.memoryFiles, .testRatio28d)' scripts/qa/health-baseline.json) && echo same → same
  • AC-3: --check is a ratchet. Evidence: npx vitest run scripts/qa/health-report.test.ts → ≥ 4 passed, 0 failed (temp fixture tree: equal baseline → exit 0; one metric raised → exit 1 and stderr names the key; one metric lowered → exit 0 and stdout says ratchet available: <key>; --write-baseline rewrites the file and a following --check exits 0; the fixture tree is real files, no fs mock)
  • AC-4: An advisory CI job runs --check and cannot block a merge. Evidence: grep -A14 '^ health-advisory:' .github/workflows/ci.yml | grep -c 'continue-on-error: true' → 1
  • AC-5: The release checklist reads the report. Evidence: grep -c 'health-report' docs/internal/release-checklist.md → ≥ 1
  • AC-3 is classified as a gate test by isGateTestEvidence; the PR body carries its SEQUANT_MUTATION record (delete the raised-metric branch in the fixture → the "names the key" case fails; restore).
  • AC-6: The script finishes in CI time. Evidence: test -f scripts/qa/health-report.ts && /usr/bin/time -p npx tsx scripts/qa/health-report.ts --json > /dev/null 2> /tmp/hr-time.txt && awk '/^real/ {print ($2 < 90) ? "fast" : "slow"}' /tmp/hr-time.txt → fast

Prior fixes / producers

  • Prior scripts of this class: scripts/qa/tautology-detector-cli.ts (advisory job), scripts/qa/backtest-mutation-gate.ts. Neither computes these metrics; no prior fix.
  • Producers of the baseline file: this script only (I-4). Consumers: the ACs of F-03, F-04, F-06, F-07, F-08, F-09, F-11, F-12 and the health-advisory job.
  • Re-fix-per-file and duplicate groups are not recomputed; they come from accretion cadence and dups (D-C).

May touch

scripts/qa/health-report.ts (new), scripts/qa/health-report.test.ts (new), scripts/qa/health-baseline.json (new), .github/workflows/ci.yml (one appended job after tautology-advisory), package.json (one lint:health script line), docs/internal/release-checklist.md (one line), tsconfig.scripts.json only if the new file is not already covered.

Non-Goals

  • No metric is enforced in this node; the job is advisory (D-A). Blocking is a W2 decision.
  • No edits under plugin/, .claude/skills/, templates/skills/ (I-1).
  • No fix to any metric; this node only measures.
  • testRatio28d is reported, not gated (D-6).

Done when

npx tsx scripts/qa/health-report.ts --check exits 0 on main, the baseline file is committed, and the advisory job appears on the PR's checks.

Activity

  1. added
    graph-2026-10-fundamentals
    on Oct 18, 2026
  2. admarble commented on Oct 19, 2026

    @admarble
    ContributorAuthor

    Runner context, 2026-10-19, before launch (W0 of graph-2026-10-fundamentals; stop-at-PR). D-1..D-6 are answered on #1501 (D-1 alongside, so this runs beside consolidation W1, #1471 and #1474, whose files don't overlap).

    For every phase, and the qa phase by name: run the full suite at most once, in the foreground, under timeout, after a WIP commit. Each MCP-dispatched phase has a 30-minute wall. Prefer the targeted npx vitest run <files> for the ACs.
    CHANGELOG: add [Unreleased] lines, not changelog.d/ fragments. #1370 has not merged.
    Freeze: nothing under plugin/, .claude/skills/ or templates/skills/.

  3. admarble commented on Oct 19, 2026

    @admarble
    ContributorAuthor

    Complexity: Standard (6 ACs, 5 directories)

    AC Quality Check

    • All 6 ACs are single-line with Evidence: and parse.
    • AC-1 is satisfiable only on key presence (>= 0); it does not check functions.longest shape or harness.skillFiles/adrWithoutActor-style sub-keys. Fine as a floor; AC-2 pins the values.
    • AC-4 is non-vacuous today (grep -c gives 0: no health-advisory job). Note -A14 means continue-on-error: true must sit within 14 lines of the job header, so place it directly under runs-on/if, before steps.
    • AC-5 non-vacuous (0 matches in release-checklist.md today).
    • AC-3 mixes a count threshold (≥ 4 passed) with a 5-case behavior list; the list is the real bar (equal→0, raised→1 naming key, lowered→0 + ratchet available: <key>, write-baseline→check 0).
    • AC-2 excludes .testRatio28d and .harness.memoryFiles, matching --check. It does NOT exclude .commit/.generatedAt from the file (it deletes them in the diff) — fine.
    • AC-6 requires real < 90 s; ESLint over src/ is the cost driver (see risks).

    Scope Assessment

    Non-Goals: present (no enforcement, no plugin//.claude/skills//templates/skills/ edits, no metric fixes, testRatio28d report-only).

    Metric Value Status
    Feature count 1 (script + ratchet) ✅
    AC items 6 ✅
    Directory spread 5 (scripts/qa, .github/workflows, docs/internal, root package.json, CHANGELOG) ⚠️ borderline, all one-line appends

    Verdict: ✅ SCOPE_OK


    Acceptance Criteria

    AC-1: --json prints every key

    Verification: Integration Test (declared evidence: jq command)
    Scenario: Given the repo tree → When npx tsx scripts/qa/health-report.ts --json → Then JSON has all keys in the §4 table, plus generatedAt and commit.
    Assumptions: harness.memoryFiles is null when CLAUDE_PROJECT_MEMORY_DIR unset.

    AC-2: Committed baseline equals script output on the PR tree

    Verification: Integration Test (declared diff command)
    Scenario: Given baseline generated by --write-baseline after the last source change → When the diff command runs → Then same.
    Assumptions: Deterministic output (sorted byFile keys, stable longest tie-break). Baseline must be regenerated LAST, after any CHANGELOG/doc edits, because harness.* and adrWithoutActor read those trees (CLAUDE.md lines, skill lines). This PR must not touch .claude/skills, so skill counts are stable.

    AC-3: --check is a ratchet (gate test)

    Verification: Unit Test (scripts/qa/health-report.test.ts, ≥4 cases, real temp fixture tree, no fs mock)
    Scenario: equal → exit 0; raised key → exit 1, stderr names key; lowered → exit 0, stdout ratchet available: <key>; --write-baseline then --check → exit 0.
    Assumptions: Script takes a --root <dir> (and --baseline <file>) so tests run on a tiny fixture rather than the 1,000+-file repo.

    AC-4: Advisory CI job that cannot block

    Verification: Manual/grep (declared) + PR checks show health-advisory.
    Scenario: Given the appended job → When grep runs → Then 1.

    AC-5: Release checklist mentions health-report

    Verification: grep (declared). One line under "Build & Test".

    AC-6: Runs under 90 s

    Verification: Integration Test (declared timing command)
    Scenario: Then prints fast.


    Implementation Plan

    Phase 1: Script (scripts/qa/health-report.ts)

    1. Export pure collectMetrics(root, opts) and compare(current, baseline); thin main() parses --json | --check | --write-baseline | --root | --baseline. Follow tautology-detector-cli.ts structure.
    2. Metrics:
      • functions: use ESLint's Linter/ESLint API with an in-memory config (max-lines-per-function {max:1, skipBlankLines, skipComments}, TS parser from typescript-eslint) run twice thresholds 200/400 — better: one pass with max:1, parse the "N lines" from each message, then count >200/>400 and take the max. Files: non-test src/**/*.ts(x), bin/**/*.ts. Do NOT use the repo eslint.config.js (avoid coupling to the shared merge-point file).
      • emptyCatch: typescript compiler API CatchClause with block.statements.length === 0, non-test src; byFile sorted.
      • childProcessMockFiles / proseGate / ghCallFilesOutsideProvider / deprecatedWithoutRemoval / adrWithoutActor / harness: regex over file lists; exact regexes from the issue table.
      • testRatio28d: git log --no-merges --since=28.days --numstat once (single git call), per-commit sums, sum and median.
    3. Output key order fixed; arrays/objects sorted for AC-2 determinism.

    Phase 2: Ratchet + tests

    1. compare: numeric leaves except testRatio28d.* and harness.memoryFiles; for emptyCatch.byFile and functions.longest compare only scalars (total, lines) — report byFile diff informationally. Raised → stderr health: <key> rose A -> B, exit 1; lowered → stdout ratchet available: <key>.
    2. health-report.test.ts: build fixture tree with mkdtempSync (a long function, an empty catch, etc.), git init inside it for the ratio, call exported functions + one spawn for exit codes. Per-test timeout (ESLint startup): file name has no .integration., so the default 5 s applies — set explicit timeouts or name accordingly; confirm against the vitest project config.

    Phase 3: Wiring

    1. package.json: "lint:health": "npx tsx scripts/qa/health-report.ts --check", alphabetical among lint:* (after lint:constitution-dod). CI job health-advisory appended after tautology-advisory (checkout fetch-depth 0 — the ratio needs history; continue-on-error: true right under runs-on). One line in docs/internal/release-checklist.md. [Unreleased] CHANGELOG line (not changelog.d/).
    2. Generate baseline last: --write-baseline, then re-run AC-2.

    Design Review

    1. Where does this logic belong? scripts/qa/, same slot as tautology-detector-cli.ts; pure functions exported so tests don't spawn.
    2. Simplest correct approach? One script, one JSON file. Rejected: reusing the repo ESLint config (coupling to shared file); per-metric scripts (≥12 files).
    3. Existing pattern / re-patch count? advisory-CI-job pattern from tautology-advisory. No prior fixes for this metric class (git log -S on the script names finds nothing; issue states none). Not a re-patch.
    4. Reviewer challenge? "Why a hand-rolled ratchet vs. ESLint --max-warnings?" — metrics are cross-file counts and non-lint (git, ADRs, harness), so no.
    5. Producers/consumers: producer of baseline: this script only. Consumers: health-advisory job, release-checklist line, later F-03…F-12 ACs (chore(lint): end the 2026-01 "temporarily relaxed" rules, add knip as an advisory job with a numeric baseline #1503, docs: postmortem template, the D-5-approved incidents moved from memory into docs/incidents, ADR acceptance authority named and linted #1513 append to ci.yml/package.json/baseline). Keep the baseline flat-ish JSON and the CI job self-contained for easy appends.

    Feature Quality Planning

    Notable items:

    • Reproducibility of baseline values: issue values are on 96990daab; main is now 8d1895c36. Numbers may drift (e.g. empty-catch 119). AC-2 only requires equality with the PR tree, so regenerate rather than hand-copy; note any drift in the PR body.
    • testRatio28d on shallow clones: CI needs fetch-depth: 0; if history is shallow the ratio silently shrinks. Since it's report-only, acceptable, but emit commits so it's visible.
    • AC-6 time: type-aware ESLint is not needed (syntax-only rule), so parsing ~hundreds of files should be well under 90 s; measure on first run.
    • Gate-test mutation record (required for AC-3): delete the raised-metric branch in compare, confirm the "names the key" case fails, restore; record using Mutation-verified: AC-3 — … with failedTest as scripts/qa/health-report.test.ts > <describe> > <case> and the SEQUANT_MUTATION marker. Commit before mutating.
    • Worktree already exists at ~/Projects/worktrees/feature/1502-… (clean at 8d1895c); /exec will reuse it.
    • Freeze respected: no plugin/, .claude/skills/, templates/skills/ edits.

    Open Questions

    1. functions.longest equality — Recommendation: compare only longest.lines in --check; store file/name for info. Impact: if wrong, a rename of the longest function would false-alarm.
    2. --root/--baseline flags are not in the issue — Recommendation: add (needed for AC-3 fixture without fs mocks). Impact: otherwise tests must run on the real repo and be slow/fragile.

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: Single new script with a unit-tested ratchet (AC-3 declares a vitest evidence). testgen skipped: AC-3's test is itself the deliverable and the issue fully specifies its cases. No UI → no test. Runner context says stop-at-PR; run the full suite at most once, in the foreground under timeout, after a WIP commit.


    Label Review

    Current: graph-2026-10-fundamentals
    Recommended: + planned
    Quality Loop: Won't auto-enable (scope OK).

  4. added
    planned
    on Oct 19, 2026
  5. admarble commented on Oct 19, 2026

    @admarble
    ContributorAuthor

    QA Verdict: AC_MET_BUT_NOT_A_PLUS

    AC coverage: 6/6 met

    Gaps:

    • --check skips emptyCatch.byFile.* beyond the issue's stated exclusions (testRatio28d.*, harness.memoryFiles); undocumented deviation
    • Founding-doc table values do not reproduce at their stated commit and the PR body omits the drift note the spec quality plan asked for
    • scripts/ changed with no /verify evidence
    • Mutation record names one failing test but two fail; PR body lacks the human-readable Mutation-verified line
  6. admarble commented on Oct 19, 2026

    @admarble
    ContributorAuthor

    Execution Verification (runner, 2026-10-19), PR #1548 @ 8058510

    The runner re-ran every Evidence command verbatim in the worktree:

    • AC-1: ok
    • AC-2: same
    • AC-3: 7 passed, 0 failed
    • AC-4: 1
    • AC-5: 1
    • AC-6: fast (3.73 s)

    CI: test and health-advisory passed.

    Mutation (AC-3 gate test): deleted the raised-metric branch in compare. Two tests failed, "exits 1 and names the key" and "--write-baseline … --check exits 0", 2 of 7. Restored, tree clean. The record is in the PR body.

    Founding-doc drift: the runner re-ran the script on a detached 96990da checkout. emptyCatch.total = 120 (the table says 119) and proseGate.lines = 30,179 (the table says 30,461). Every other planning value reproduces.

    Open for the owner: emptyCatch.byFile.* is reported but not gated. The spec's plan, step 4, chose this. See the PR body's "Decisions to review".

  7. admarble commented on Oct 19, 2026

    @admarble
    ContributorAuthor

    Owner ruling, 2026-10-19: emptyCatch.byFile.* stays ungated in --check, as the spec chose. A catch that moves between files does not fail CI, but any rise in emptyCatch.total still does. This settles QA's repository_gap finding on PR #1548.

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

    graph-2026-10-fundamentalsplanned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions