Add a cyclomatic-complexity and CRAP-score CI gate - #3670
Open
tom2drum wants to merge 5 commits into
Open
Conversation
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add the four-ticket decomposition for the complexity/CRAP CI gate: complexity CLI (tracer bullet), CRAP + coverage/JSX, CI wiring, and threshold calibration. Amend the spec to drop the third-party service from the shipped tool and add focused mode + in-tool threshold config. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Introduce tools/code-complexity/: a CLI that computes per-function cyclomatic complexity by walking the TS/TSX AST (ts.createSourceFile, no type-checker), matching ESLint's complexity rule. It gates the raw complexity of functions a diff touches against a configurable cap, prints a table of all checked functions sorted by complexity, and exits non-zero on any violation. A focused mode scores every function in explicit file paths, bypassing diff-scoping. Wired to `pnpm test:code-complexity` via a compile-on-run wrapper (dist/ is git-ignored). Coverage, CRAP, and JSX handling arrive in later tickets. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Extend tools/code-complexity with the second, coverage-aware gate and make coverage self-service so the tool is usable in one command locally and in CI. - CRAP: AST-based JSX detection, per-function line coverage joined from a v8/istanbul coverage-final.json, CRAP = c²·(1−cov)³+c, second configurable threshold. Report gains COV/CRAP/BROKE columns sorted by CRAP descending. - Coverage sourcing, two axes mirroring vitest. Selection: full-repo (default), focused (paths), diff (--changed). Source: generated by running vitest scoped to the selection (default), --coverage-file to consume a prebuilt report (the CI path, skips vitest), or --no-coverage. Vitest output hidden unless --verbose; a no-test or failing run degrades gracefully. - The CRAP half applies to JSX-less logic files and to JSX components with a co-located vitest spec; visual-only components stay complexity-only. *.primed.spec.tsx are excluded from coverage runs (page mounts, no behavior), and vitest is skipped entirely when nothing in the selection needs coverage. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The vitest_tests PR run now emits coverage-final.json, and a diff-scoped post-step gates on it; under $GITHUB_ACTIONS the tool prints ::error annotations for offenders and writes the report table to the job summary. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
tom2drum
added a commit
that referenced
this pull request
Aug 27, 2026
Reverted once the gate's ::error annotations are confirmed on PR #3670. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
tom2drum
marked this pull request as ready for review
August 27, 2026 13:13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #3663
Adds a CI gate that flags code which is both complex and under-tested. A bespoke
tools/code-complexity/CLI computes per-function cyclomatic complexity from the TypeScript AST and joins it with per-function coverage to compute the CRAP score (c²·(1 − cov)³ + c), failing when a function a PR touches exceeds a configurable threshold — scoped to the diff so it never blocks on pre-existing debt.Spec:
.agents/tasks/3663-code-complexity-ci-gate/spec.mdThis is a spec-first draft: the branch will receive the task's work ticket by ticket, and the final description will be written when the PR is marked ready for review.