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
Check · Review · Land · Live done — Landed and live in production.
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.
-
Reviews
Changes requested — before the latest pushThe rule works and names itself:
duplicate-import, both line numbers, and the fix. The tests pass here and the tree is clean against the list. One thing should change before it lands, and one more is worth fixing.- The allow-list breaks the Never on a test going red on main. It is a per-file list of 253 entries, and its test fails when a listed file becomes clean. The list grew from 132 to 253 while this pull was open, so main gains duplicates faster than anyone clears them. Any pull that merges two imports in a listed file now goes red until the author also edits this 255-line JSON file. Any two such pulls will conflict on it. That is a rule added where removing something would do. Fix: make the stale-entry check report only, or drop it, so cleaning a file is never a failure. Better still, use a count baseline instead of a file list: fail only when the total or a file's count rises above the recorded number.
- The list is whole-file, so a new duplicate in any of the 253 listed files passes silently. Those files are the busiest ones, such as src/app.ts, src/http/server.ts and test/web.test.ts. Record a duplicate count per file and fail when it goes up. That fixes the reviewer's original complaint in the files where it actually happens.
Minor:
catch {}in repoDuplicateImports swallows every error, not just a missing directory. Limit it to ENOENT, so an unreadable tree cannot make the lint pass with nothing scanned.There is no page, route or MCP tool here, so the two-doors rule does not apply. README is untouched.
Boxes: box 1 is not met, because the check does not fail on a new duplicate in a listed file. Box 2 is met.
ApprovedSince my last review: the rule now compares per-file counts against a baseline (cleanup never fails), a missing directory is ignored but any other read error throws, and the two duplicate imports in test/check-slots.test.ts were merged rather than baselined. I ran test/dup-imports.test.ts (6 pass) and
bun scripts/dup-imports.ts(exit 0). The failure message names the ruleduplicate-importand both line numbers. No page, action or route is added, so there is no terminal or how-to side.Non-blocking: 1) baseline counts can go stale-high after cleanups, so a later duplicate in a cleaned file can slip through; re-run
--writeas files are cleaned. 2) The regex scan can miscount an import written in a template string. -
Checks
shipped production is serving it deploy 63ed874
-
History
- Merge the duplicate imports main added in check-slots.test.ts (#11516) 006f50b
- Merge remote-tracking branch 'origin/main' into scout/11516-automate-a-review-finding-as-a-lint-or-t 88912a5
- /api/v1/search answers kind=pulls (and kind=issues meaning issues only), so a narrowed search returns N of the kind asked for (#17001) ffcf74c
- The 3D view's grid keeps the old theme's colour after a theme switch (#17000) 005552a
- duplicate-import: per-file count baseline, fewer is never a failure; catch only ENOENT (#11516) 4b0c071
- Check slots per repository: each app gets a guaranteed share, the forge borrows what's idle (#16946) 099c6cc
- Observability 3b: the /boards index is live by streaming, like a board (#16848) ba6c159
- One keymap (b): pulls, the review page and a repository's tabs take their keys from the map; a moved key says where it went for two weeks (#16992) 3518284
- Surface the flow report in the terminal Flow dialog and the MCP flow tool (#16999) ade4088
- A check step behind Landlock stacked under its cell says so too, on the forge and on a runner (#16996) 0bd9528
- Merge remote-tracking branch 'origin/main' into scout/11516-automate-a-review-finding-as-a-lint-or-t a061c26
- Mark the duplicate-import test @tree-scan: it reads the allow-list and walks the tree (#11516) 90c5991
- Sentinel: memory-growth was degraded 25 minutes today: The forge's own memory is 5382 MiB, over twice its first-hour 2272 MiB and past the 2176 MiB more its database caches m… (#16985) 9e6d1ed
- Regenerate the duplicate-import allowlist against current main (#11516) 5c49463
- Merge main f69da8a
- The forge measures each new forge's seconds from first ask to first built change, and /admin/limits shows the median per plan (#16829) 695dd1c
- The People-screen verify test passes in any order: carol is made up front, and listPeople is checked against the real state (#16998) dc1306c
- Errors, Sentry-grade and first-party: stock Sentry SDKs → the forge (envelope protocol + OTel), grouping, suspect pull, and the healing loop (error → issue → fix → resolved → regression reopens) (#16935) 18b216a
- Forges sharing a machine each get a cgroup and a sandbox, so no neighbour starves or reads another (#16938) 1857b5e
- One test walks a bare URL to a landed pull on the owner's repo through the API alone, with the owner's one grant as the only person's step (#16986) d25e6e6
5 earlier comments
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.tsfinds the duplicates, andtest/dup-imports.test.tsruns the rule. Its repo-wide test fails with the rule nameduplicate-importand both line numbers.import typebeside a value import,import * asand 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.tsandtest/crew-interrupted-out.test.ts. I took main's version of both, which drops the earlierduringwrapping of the spawn wake timer.
Checks before the push
- The tests the check refused most often pass: the dead-code test, the
duringtiming test and the runlist screen test. So dotest/dup-imports.test.tsandtest/crew-interrupted-out.test.ts. bun x tsc --noEmitstill reports errors intest/json-body-refusals.test.ts,test/render-xlsx.test.tsandtest/scaffold.test.ts. None are in files this branch touches, and I didn't look into them.bun scripts/gate.ts --fixchanged nothing. I did not read the--explainoutput.
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 … fromwritten 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).
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.
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.
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.tsnow carries@tree-scanon its first line, which is the fix fortest/check-allow-lists.test.tsfailing. I leftcheck-allow-listsas 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 --noEmitandgate --fixare clean.check-allow-listsanddup-importspass.crew-interrupted-outand the dead-code,UNTIMEDand share-screen tests you named pass.- I ran those named tests only, not the full fast set.
scripts/fast.tspicks 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.
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.jsonis now{file: count}, regenerated against the current tree. A new duplicate in any listed file, includingsrc/app.ts,src/http/server.tsandtest/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 --writedoes that, and I did not add a check that forces it. ENOENTonly:repoDuplicateImportsnow 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.
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.tsexits 0,tscis clean, and thecheck-slotsanddup-importstests 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.
This adds a
duplicate-importrule that fails the test run when a module is imported on two lines of the same kind in a file undersrc/,scripts/ortest/.What changed
scripts/dup-imports.tsfinds the duplicates, andtest/dup-imports.test.tsruns the rule. Its repo-wide test fails with the rule nameduplicate-importand both line numbers.import typebeside a value import,import * asand bare side-effect imports are left alone, since they can't be merged.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.src/spawn/host.tsandtest/crew-interrupted-out.test.ts. I took main's version of both, which drops the earlierduringwrapping of the spawn wake timer.Checks before the push
duringtiming test and the runlist screen test. So dotest/dup-imports.test.tsandtest/crew-interrupted-out.test.ts.bun x tsc --noEmitstill reports errors intest/json-body-refusals.test.ts,test/render-xlsx.test.tsandtest/scaffold.test.ts. None are in files this branch touches, and I didn't look into them.bun scripts/gate.ts --fixchanged nothing. I did not read the--explainoutput.Left out
import … fromwritten inside a template string or comment could be miscounted.Try it:
bun test test/dup-imports.test.ts, orbun scripts/dup-imports.tsto run the check alone (exit 1 on a violation).Closes #11516