Skip to content

feat(cli): rank first-test candidates by direct symbol evidence (#444) - #465

Merged
stackbilt-admin merged 1 commit into
mainfrom
feat/issue-444-first-test-ranking
Nov 28, 2026
Merged

stackbilt-admin merged 1 commit into
mainfrom
feat/issue-444-first-test-ranking

Conversation

@stackbilt-admin

Copy link
Copy Markdown
Member

Summary

Adds rankFirstTests(root, files, opts) in packages/cli/src/commands/test-rank.ts, which answers "what test should I run first?" for a seed file. It ranks by direct symbol evidence instead of import distance:

  1. symbol: the test imports one of the seed's exported symbols by name (aliases and import * as ns count too) from a module that reaches the seed, including through re-exports, or from the seed's own package name (@stackbilt/adf). Ordered by reference count. A test that imports the same name from an unrelated module does not count.
  2. import: the test imports the seed directly but uses none of its exported symbols.
  3. transitive: the test only reaches the seed through other modules (depth <= 3). Only 3 are listed; the rest go into collapsed: { count, maxDepth, note }.

Each candidate has { file, rank, tier, reason, refs?, depth, command }, where command is pnpm exec vitest run <repo-relative path>. If the seed is itself a test file, it ranks first. unknown is null when there is a direct answer. Otherwise it says what's missing: "only transitive candidates", "evidence ran out", or "seed file not found". opts.symbols limits the evidence to the named symbols, and opts.graph reuses a blast graph that's already built.

This is a new file. It reuses buildGraph and resolveSpecifier from @stackbilt/blast, which is unchanged and has no new dependencies. It changes no existing CLI output, JSON output or exit codes. Hooking it into preflight is left to the integration PR.

For seed packages/adf/src/manifest.ts on this repo, bundler.test.ts ranks first with "calls parseManifest (16), resolveModules (7)". With symbols: ['resolveModules'] the reason is "calls resolveModules (7)".

Verified

  • pnpm exec tsc --build tsconfig.build.json: clean
  • pnpm exec tsc --noEmit -p tsconfig.json: clean
  • pnpm exec vitest run packages/cli/src/__tests__/test-rank.test.ts: 9/9 pass. The fixture covers re-export, alias, namespace, bare package, name collision, the transitive cap, unknown and seed-is-test. Two tests run on this repo's real files and cover the acceptance criteria: bundler.test.ts ranks first, and no transitive candidate ranks above a direct one.
  • Speed on this repo (256 files): building the graph takes about 215 ms warm and about 500 ms cold. Ranking over the built graph takes about 50 ms. The whole node process takes about 1 s.
  • Full pnpm exec vitest run (run 1, machine loaded by parallel worktrees): the failures were the known Windows ones (bootstrap bootstrap: phases 6/7 collect warnings without printing them; absoluteAiDirArg misses Windows paths on POSIX #307, context-refresh, serve-context, github-commit-range), plus 5s timeouts in adf-vendor-doctor-score, adf-vendor-legacy, generated-context and integration/bootstrap-reset-cli. I re-ran those four files on their own and all 148 tests passed. A second full run had not finished when this PR was opened.
  • node packages/cli/dist/bin.js adf evidence --auto-measure --ci --format text: PASS. adf_migrate_loc is at 792/792 (already the case on main). The pre-commit hook passed.

Not done

  • No CLI flag or preflight wiring yet. That is left to the integration PR.
  • Symbol evidence comes from regex matching, not the type checker. Dynamic import() with destructuring and require bindings fall back to import distance.

Closes #444
Part of #437

🤖 Generated with Claude Code

Add rankFirstTests(root, files, opts) in packages/cli/src/commands/test-rank.ts.
Tests that import the seed's exported symbols by name (through re-exports or
the seed's package name) rank first by reference count, then direct importers,
then capped transitive importers with the rest collapsed. Each candidate has a
reason and a ready-to-run vitest command; `unknown` is set when direct
evidence runs out.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

2 participants