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

Automate a review finding as a lint or test: Duplicate import from views_store.ts; merge into one. #17004

Merged opened this

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

Merged

This adds a duplicate-import rule that fails the test run when a module is imported on two lines of the same kind in a file under src/, scripts/ or test/. What changed scripts/dup-imports.ts finds the duplicates, and test/dup-imports.test.ts runs the rule.

Notes

opened this

This adds a duplicate-import rule that fails the test run when a module is imported on two lines of the same kind in a file under src/, scripts/ or test/.

What changed

  • scripts/dup-imports.ts finds the duplicates, and test/dup-imports.test.ts runs the rule. Its repo-wide test fails with the rule name duplicate-import and both line numbers.
  • import type beside a value import, import * as and bare side-effect imports are left alone, since they can't be merged.
  • Files that already had duplicates are listed in scripts/dup-imports-allow.json. A new duplicate in any other file fails. A listed file that gets cleaned fails until you remove its entry, so the list only shrinks.
  • I merged main into the branch and regenerated that list. Main had moved on, so 253 files now have duplicates (317 import lines). The old list covered 132.
  • Merging main conflicted in src/spawn/host.ts and test/crew-interrupted-out.test.ts. I took main's version of both, which drops the earlier during wrapping of the spawn wake timer.

Checks before the push

  • The tests the check refused most often pass: the dead-code test, the during timing test and the runlist screen test. So do test/dup-imports.test.ts and test/crew-interrupted-out.test.ts.
  • bun x tsc --noEmit still reports errors in test/json-body-refusals.test.ts, test/render-xlsx.test.ts and test/scaffold.test.ts. None are in files this branch touches, and I didn't look into them.
  • bun scripts/gate.ts --fix changed nothing. I did not read the --explain output.

Left out

  • I did not merge the existing duplicates. Doing that across about 250 files is a separate change, and the allowlist makes it safe to do a few at a time.
  • The rule is a regex, not a parser, so an import … from written inside a template string or comment could be miscounted.
  • The change adds no page, action, route or MCP tool, so there is no terminal or how-to side to it.

Try it: bun test test/dup-imports.test.ts, or bun scripts/dup-imports.ts to run the check alone (exit 1 on a violation).

Closes #11516

5 earlier comments
commented

This adds a duplicate-import rule that fails the test run when a module is imported on two lines of the same kind in a file under src/, scripts/ or test/.

What changed

  • scripts/dup-imports.ts finds the duplicates, and test/dup-imports.test.ts runs the rule. Its repo-wide test fails with the rule name duplicate-import and both line numbers.
  • import type beside a value import, import * as and bare side-effect imports are left alone, since they can't be merged.
  • Files that already had duplicates are listed in scripts/dup-imports-allow.json. A new duplicate in any other file fails. A listed file that gets cleaned fails until you remove its entry, so the list only shrinks.
  • I merged main into the branch and regenerated that list. Main had moved on, so 253 files now have duplicates (317 import lines). The old list covered 132.
  • Merging main conflicted in src/spawn/host.ts and test/crew-interrupted-out.test.ts. I took main's version of both, which drops the earlier during wrapping of the spawn wake timer.

Checks before the push

  • The tests the check refused most often pass: the dead-code test, the during timing test and the runlist screen test. So do test/dup-imports.test.ts and test/crew-interrupted-out.test.ts.
  • bun x tsc --noEmit still reports errors in test/json-body-refusals.test.ts, test/render-xlsx.test.ts and test/scaffold.test.ts. None are in files this branch touches, and I didn't look into them.
  • bun scripts/gate.ts --fix changed nothing. I did not read the --explain output.

Left out

  • I did not merge the existing duplicates. Doing that across about 250 files is a separate change, and the allowlist makes it safe to do a few at a time.
  • The rule is a regex, not a parser, so an import … from written inside a template string or comment could be miscounted.
  • The change adds no page, action, route or MCP tool, so there is no terminal or how-to side to it.

Try it: bun test test/dup-imports.test.ts, or bun scripts/dup-imports.ts to run the check alone (exit 1 on a violation).

commented

This pull adds a duplicate-import lint. The failing check came from test/dup-imports.test.ts: it reads scripts/dup-imports-allow.json and walks the tree, but wasn't marked @tree-scan. That left it out of the tests every fast tier runs. I added the marker as the file's first line.

The allow-list test and the duplicate-import test both pass locally, and tsc --noEmit and gate --fix are clean. I didn't run the full suite; the forge runs it on this push. This commit changes only a test comment, so it has no terminal side or docs/features/ how-to (the commit line says No door).

The marker is in test/dup-imports.test.ts and the fix is pushed as 90c5991a0.

commented

Two failures here: the 2s check says it does not merge into main (conflicts in src/spawn/host.ts and test/crew-interrupted-out.test.ts), and the 10m check fails test/check-allow-lists.test.ts because test/dup-imports.test.ts reads scripts/dup-imports-allow.json but is not in every fast tier. Please rebase on main, resolve both conflicts, put the dup-imports test in the tiers the allow-list test expects (don't loosen check-allow-lists), and get one green check.

commented

I merged origin/main into the branch (not a rebase), and it merged cleanly, so there were no conflicts to resolve in src/spawn/host.ts or test/crew-interrupted-out.test.ts. It's pushed as a061c26f5. I haven't seen the forge's check on it yet.

  • Allow-list test: test/dup-imports.test.ts now carries @tree-scan on its first line, which is the fix for test/check-allow-lists.test.ts failing. I left check-allow-lists as it was. That marker went up in the previous push (90c5991a0). If the 10m check you saw ran before it, it was reading the old state.
  • Tests run locally after the merge:
    • tsc --noEmit and gate --fix are clean.
    • check-allow-lists and dup-imports pass.
    • crew-interrupted-out and the dead-code, UNTIMED and share-screen tests you named pass.
    • I ran those named tests only, not the full fast set. scripts/fast.ts picks 133 test files here and estimates about 10m42s, which is over its 5-minute budget, so the forge's check will be the first full run.
commented

The duplicate-import rule now compares duplicate counts per file against a recorded baseline. It fails only when a file has more duplicates than its recorded number. The new tests, tsc and gate.ts --fix pass. I didn't run the four tests the check named, because none of them touch this change.

  • Count baseline: scripts/dup-imports-allow.json is now {file: count}, regenerated against the current tree. A new duplicate in any listed file, including src/app.ts, src/http/server.ts and test/web.test.ts, fails. An unlisted file may have none.
  • Cleanup never fails: the stale-entry check is gone. Merging imports in a listed file needs no JSON edit, so cleanup pulls can't conflict on it. The recorded numbers can go stale-high, though. After a cleanup, a later duplicate in that file passes until someone re-baselines. bun scripts/dup-imports.ts --write does that, and I did not add a check that forces it.
  • ENOENT only: repoDuplicateImports now ignores a missing directory and rethrows any other read error. An unreadable tree can no longer pass with nothing scanned.
  • Tests: the old "cleaned file must leave the allowlist" test is replaced. The new ones cover a count above the baseline failing, a count at or below it passing, an unlisted file failing, a missing root scanning empty, and another read error throwing.

When a file has more duplicates than its baseline, the message names the later duplicates by position. That can point at a different line than the one you added.

commented

This push should clear the failing check, but I haven't seen the forge's run yet. The scan failed because main had added test/check-slots.test.ts with two duplicate imports. It reached the pull when I merged main.

  • Merged, not baselined: I folded ../src/actions/repos.ts (commitToBranch, createRepo) and ../src/core/repos.ts (getRepoById, Repo, writeCheckSlots) into one import each. A new file can't be listed in the baseline anyway, so the rule did what it should.
  • Passing here: bun scripts/dup-imports.ts exits 0, tsc is clean, and the check-slots and dup-imports tests pass.
  • Unchanged: the rule, the count baseline and the ENOENT handling are as in the last push.

Main keeps gaining duplicates, so any pull that adds a file with one will go red until the author merges the imports. That is intended: the rule is meant to catch it at that point.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs