Repository navigation
feat(cli): detect files pinned by contract tests (#445) - #466
Merged
Merged
Conversation
New detectContractPins(root, files) reports, per file, whether a test under the repo's *contract* test convention exercises it (value import that resolves to the file, or a run of the CLI command it implements), which tests pin it, the surfaces they assert (exit codes, --format json) and the semver guidance from core.adf. Repos with no contract-test convention get pinned: 'unknown'. summarizeContractPins folds several files into one answer for the preflight integration. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Summary
Adds
packages/cli/src/commands/contract-pins.ts, a new module that tells an agent before it edits whether a file's behaviour is pinned by a contract test. It reports which tests pin the file and what a change means for semver.detectContractPins(root, files) -> ContractPin[]: one result per file, as{ file, pinned: true|false|'unknown', by, surfaces, guidance, evidence }.summarizeContractPins(pins): folds several files into the singlecontractanswer from the issue. It istrueif any file is pinned,falseonly if every file is known not to be pinned, and'unknown'otherwise. Wiring it into preflight is a one-liner:contract: summarizeContractPins(detectContractPins(root, files)).How detection works:
*.test.*or*.spec.*files whose name or directory containscontract(node_modules,distand.claudeare skipped). With no such files, every file getspinned: 'unknown', never a guess. The file list comes fromgit ls-files --cached --others --exclude-standard. Outside a git work tree it falls back to a bounded directory walk.import: the contract test imports the file with a value import, through a relative specifier that resolves to it..jsspecifiers resolve to.tsfiles and directories resolve toindex.*.import typedoes not count. This is howevidence-contracts.test.tsexercisesadf-evidence.ts.cli: the file is undercommands/(adf-evidence.tsmaps toadf evidence) and the test runs that command through the CLI binary, either as an argument array whose first element isCLI_BINorbin.js, or as acharter <cmd>/bin.js <cmd>string passed straight toexec*/spawn*. A string that only mentions the command, such as thecharter adf metrics recalibratehint asserted in evidence-contracts, does not count. The tests cover that case.exit codes:EXIT_CODE.*,expect(exitCode)orexpect(r.status).--format json: a JSON format flag together withJSON.parse.breaking = major + migration note; additive = minorwhen pinned. There is distinct text for not pinned, unknown and outside-root files.Results on this repo:
adf-evidence.tsis pinned bypackages/cli/src/__tests__/integration/evidence-contracts.test.ts, with surfacesexit codesand--format json.packages/cli/src/index.tsis also pinned: the contract test imports theEXIT_CODEvalues from it, and those values are a real contract.false.Only new files are added. No existing code, JSON output or exit code changes.
Verified
pnpm exec vitest run packages/cli/src/__tests__/pinned-by-tests.test.ts: 15/15 passed. The tests cover this repo (the acceptance case, an absolute path, a hint string that is not an invocation, a file that isn't pinned) and fixtures (no convention givesunknown, CLI-invocation evidence with surfaces, acontracts/directory, a type-only import that doesn't pin, a non-test*.contract.ts, a file outside the root), plus the helpers and the summary.pnpm exec tsc --build tsconfig.build.json: ok.pnpm exec tsc --noEmit -p tsconfig.json: ok.node packages/cli/dist/bin.js adf evidence --auto-measure --ci --format text: PASS, with 1 warning (adf-migrate.ts at 792/792, already on main). The pre-commit hook passed too.pnpm exec vitest run, ran twice on a machine loaded by parallel worktrees:Not done
*contract*file convention, because adding a manifest key would mean editing.ai/*.adfconventions.adf-preflight.ts/adf-context.ts. That is left to the integration PR, as planned.false.pinned-by-tests.test.tsrather thancontract-pins.test.ts, so it doesn't match the convention itself.Closes #445
Part of #437
🤖 Generated with Claude Code