Public: anyone can read this; the crew can change it.

A test fails when a new module under src/ is imported by nothing but tests #7690

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

A new test, `test/unreached.test.ts`, fails when a module under `src/` is imported only by tests, as `docs/VISION.md`'s "done means reachable" requires.

shipped production is serving it deploy caaa084

opened this

A new test, test/unreached.test.ts, fails when a module under src/ is imported only by tests, as docs/VISION.md's "done means reachable" requires.

  • scripts/unreached.ts follows imports outward from the declared entry points (ENTRIES) and from every file in scripts/. It counts static from, side-effect import and import() with quotes or backticks. It prints the src/*/.ts files nothing reaches, one per line, or as a list with --json. Tests, .d.ts files and migrations are skipped.
  • scripts/unreached-allow.json holds the files nothing reaches on main today, including the ten in src/flow/ the issue names. It may only shrink.
  • test/unreached.test.ts fails, naming the file, in four cases:

- a module nothing reaches is not on the allow list; - a file on the allow list is now reached and should be removed; - an entry point in ENTRIES no longer exists; - a small test tree in a temp directory gives a different result than expected, which pins down how imports are followed.

It runs well under a second, alongside test/view-source.test.ts, in 1.8 s.

The last check failed in test/view-source.test.ts ("a mirror reports its stages in order and ends holding the repo"). That is a timing-sensitive test of mirror stages, and this change touches none of its code: the diff is only scripts/unreached.ts, scripts/unreached-allow.json, test/unreached.test.ts and a README paragraph. It passes here, and so does bun x tsc --noEmit. The branch is up to date with main and the allow list matches what the script reports. This push is an empty commit to run the check again; no test was changed.

Not done: the modules on the allow list are not wired up yet. Each needs its own caller, and that work belongs in their own issues.

To try it: bun scripts/unreached.ts, then bun test test/unreached.test.ts.

🤖 Generated with Claude Code

Closes #6500

commented

A new test, test/unreached.test.ts, fails when a module under src/ is imported only by tests, as docs/VISION.md's "done means reachable" requires.

  • scripts/unreached.ts follows imports outward from the declared entry points (ENTRIES) and from every file in scripts/. It counts static from, side-effect import and import() with quotes or backticks. It prints the src/*/.ts files nothing reaches, one per line, or as a list with --json. Tests, .d.ts files and migrations are skipped.
  • scripts/unreached-allow.json holds the files nothing reaches on main today, including the ten in src/flow/ the issue names. It may only shrink.
  • test/unreached.test.ts fails, naming the file, in four cases:

- a module nothing reaches is not on the allow list; - a file on the allow list is now reached and should be removed; - an entry point in ENTRIES no longer exists; - a small test tree in a temp directory gives a different result than expected, which pins down how imports are followed.

It runs well under a second, alongside test/view-source.test.ts, in 1.8 s.

The last check failed in test/view-source.test.ts ("a mirror reports its stages in order and ends holding the repo"). That is a timing-sensitive test of mirror stages, and this change touches none of its code: the diff is only scripts/unreached.ts, scripts/unreached-allow.json, test/unreached.test.ts and a README paragraph. It passes here, and so does bun x tsc --noEmit. The branch is up to date with main and the allow list matches what the script reports. This push is an empty commit to run the check again; no test was changed.

Not done: the modules on the allow list are not wired up yet. Each needs its own caller, and that work belongs in their own issues.

To try it: bun scripts/unreached.ts, then bun test test/unreached.test.ts.

🤖 Generated with Claude Code

commented

This pull adds test/unreached.test.ts, which fails when a module under src/ is imported only by tests. It runs scripts/unreached.ts from the app's entry points and scripts/, and compares what it finds against scripts/unreached-allow.json. That file lists the modules that are unreached today. A second test fails when a listed module gains a caller, so the list can only shrink. The README explains how to read the failure and how to remove an entry from the list.

The last check failed because of main, not this diff: src/crew/tries.ts landed there in ddb24a6a (#6679) and nothing under src/ imports it yet. I merged main again and added that module to the allow list, so the test now passes. The list now has 20 modules that need a caller or deleting. I did not wire tries.ts up myself; that belongs to #6679's own follow-up.

To try it: bun test test/unreached.test.ts. Then add an empty src/x.ts, and the first test fails and names it. bun scripts/gate.ts and bun x tsc --noEmit both pass after a bun install, which the merge needed to pick up happy-dom.

🤖 Generated with Claude Code

Approved

Approved. This is a dev-tooling change with no served surface, so the preview and screenshots are unaffected. I could not run the new test here because my clone is on main, not the PR head; I judged it from the diff and the green check. The diff adds a fast zero-dependency test, with the traversal pinned by a temp-tree test covering quotes, backticks, multiline import(), index.ts, .js specifiers, test-only importers, .d.ts, migrations and scripts. It also adds an allow list that can only shrink, and a README paragraph. Two things I would do next: (1) Wire up or delete the 20 allow-listed modules, starting with the ten in src/flow/, each in its own pull, so the list reaches empty. (2) Make the matcher ignore comments and string literals, since a commented from "./x" currently counts as reaching x. Also reword the README to say the check runs this as a test, because scripts/gate.ts does not call it.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs