Public: anyone can read this; the crew can change it.
src/kernel imports nothing outside src/kernel, held by a rule test with today's exceptions named #13650
Check · Review · Land · Live done — Landed and live in production.
This adds one new rule test, test/kernel-boundary.test.ts, that holds the kernel's first package boundary: a file in src/kernel/ may import only other kernel files and the runtime (node:, bun:). Each import that leaves the kernel today is listed in CROSSINGS as file -> specifier, with one line saying why.
shipped production is serving it deploy 59903fa
This adds one new rule test, test/kernel-boundary.test.ts, that holds the kernel's first package boundary: a file in src/kernel/ may import only other kernel files and the runtime (node:, bun:). Each import that leaves the kernel today is listed in CROSSINGS as file -> specifier, with one line saying why. 28 exceptions remain: 23 in vitals.ts, which reads every subsystem's state, and one each in full_disk.ts, guard.ts, outbound.ts, preflight.ts and worker_ask.ts. Removing them is later work.
How it works:
- Reading imports: Bun's own import scanner finds the static, dynamic and re-exported imports. A regex anchored at the start of a line adds the type-only imports, which Bun's scanner leaves out. Imports quoted inside comments and strings are not counted.
- New crossings fail: an import that leaves the kernel and is not in
CROSSINGSgets its own failing test, namedsrc/kernel/<file> -> <specifier>: not in CROSSINGS, so the check's summary names the file and the import. This covers a new kernel file as well as a new line in an old one. I checked it by adding a probe file tosrc/kernelthat imported../http/health.ts: the test went red, then I deleted the probe. - The list only shrinks: an entry in
CROSSINGSthat the code no longer makes also fails, so removed crossings have to come off the list. - Fixture test: a temporary kernel directory holds type-only, multi-line, re-exported, bare (side-effect), dynamic and bare-package imports, a sibling kernel import, and one inside a comment. The test checks that exactly the outside ones are reported.
- Speed: it only reads files and starts nothing; it runs in about 0.6 s. Its header says
@tree-scan, so every pull's fast tier runs it without a change toRULE_TESTS.
Only the test file changed; there is no change at runtime. bun scripts/gate.ts --fix, bun x tsc --noEmit, and the test files kernel-boundary, tree-scans and rule-tests-always all pass.
To try it: bun test test/kernel-boundary.test.ts. Then add import { health } from "../http/health.ts" to any file in src/kernel/ and run it again to see it fail.
🤖 Generated with Claude Code
Test-only change, no runtime or UI effect. It reads the kernel files, flags any import that leaves src/kernel and is not named in CROSSINGS, and fails on a stale entry. A fixture test covers multi-line, type-only, re-export, bare, dynamic and comment cases. The count in the pull (28) matches the 28 outside imports I counted in src/kernel. I could not run the test here: this checkout does not contain the file. Two next steps: (1) retire the 23 vitals.ts crossings by having subsystems hand the kernel their readings as plain data; (2) have the fixture assert the file -> specifier pairs, not only the specifiers.
This adds one new rule test,
test/kernel-boundary.test.ts, that holds the kernel's first package boundary: a file insrc/kernel/may import only other kernel files and the runtime (node:,bun:). Each import that leaves the kernel today is listed inCROSSINGSasfile -> specifier, with one line saying why. 28 exceptions remain: 23 invitals.ts, which reads every subsystem's state, and one each infull_disk.ts,guard.ts,outbound.ts,preflight.tsandworker_ask.ts. Removing them is later work.How it works:
CROSSINGSgets its own failing test, namedsrc/kernel/<file> -> <specifier>: not in CROSSINGS, so the check's summary names the file and the import. This covers a new kernel file as well as a new line in an old one. I checked it by adding a probe file tosrc/kernelthat imported../http/health.ts: the test went red, then I deleted the probe.CROSSINGSthat the code no longer makes also fails, so removed crossings have to come off the list.@tree-scan, so every pull's fast tier runs it without a change toRULE_TESTS.Only the test file changed; there is no change at runtime.
bun scripts/gate.ts --fix,bun x tsc --noEmit, and the test fileskernel-boundary,tree-scansandrule-tests-alwaysall pass.To try it:
bun test test/kernel-boundary.test.ts. Then addimport { health } from "../http/health.ts"to any file insrc/kernel/and run it again to see it fail.🤖 Generated with Claude Code
Closes #13646