refactor(extension-core): stop exporting background helpers nothing imports - #229
Conversation
…mports The background split (#226) carved `background.ts` into purpose-shaped modules. Seven symbols that were file-private before the split picked up an `export` on the way out even though nothing outside their own module references them. Drop `export` from `hello.ts:sameDomainSet`, `DEFAULT_CAPABILITIES`, `effectiveCapabilities`, `DeclaredScope`, `declaredScope`; `badge.ts:syncBadge`; and `pending-records.ts:PendingRecordBase`. The sibling exports stay: badge.ts's four transitions are imported by socket.ts / server-hello.ts / approval.ts / boot.ts, and `PendingPairRecord` / `PendingScopeUpdateRecord` are imported by server-hello.ts. `PendingRecordBase` needs no `export` to stay reachable as the `extends` base of those two — the emitted `.d.ts` carries it unexported alongside `export {}`, so no TS4020. Also correct the pending-records.ts docblock, which claimed `PendingRecordBase` was "exported here because `background.ts` still constructs both record kinds": the constructor is `server-hello.ts`, not `background.ts`, and the export is not needed either way. The new tests/background-module-surface.test.ts guards both halves of each surface. Value exports are asserted through the ES module namespace; the type-only symbols are erased at runtime and this package's tsconfig includes only `src`, so `tsc -b` never reads `tests/` and a stray `export interface` would go uncaught — those are asserted against the module source text. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Sb9i5qyBwXYP8EkxdQfySu
|
Claude finished @chrischall's task in 1m 35s —— View job Review complete
SummaryThis PR drops I independently re-verified the PR's central claims rather than taking them at face value:
No correctness, convention, or test-coverage issues found. This is a mechanical, low-risk visibility narrowing with a well-targeted regression test that guards against re-widening (including the type-only exports that Note: I was unable to execute Verdict: pass |
|
✅ Auto-review verdict: pass — Mechanical, low-risk export-narrowing PR; all claims (no cross-file references, no barrel re-exports, accurate docblock, matching regression test) were independently verified via git grep and diff inspection. No correctness or convention issues found. |
…ally fail (#230) Closes #227 — the second nit, which #229 deliberately deferred. ## The test promised something it did not do `ALL_SCOPE_MAPS` carried this comment: > adding a thirteenth map without adding it to `clearAllSessionScopes` must fail here It was a hand-maintained literal, so a thirteenth map forgotten in `clearAllSessionScopes` would be forgotten *here* too. The suite stays green and the leak ships. **Proven before changing anything.** Added an uncleaned `mcpThirteenth` to `session-scope.ts`, omitted from `clearAllSessionScopes` and from the literal: ``` Tests 2 passed (2) ← the claim is false ``` After deriving the list from the module namespace, the same probe: ``` × empties every per-mcpId scope table × has exactly the scope tables it was last reviewed with AssertionError: mcpThirteenth survived teardown: expected 1 to be +0 ``` Probe removed, suite green again. ## Why this one matters more than a usual test nit A scope map surviving a WS teardown means **the next connection inherits the previous session's grant**. "No scope map is ever missed" is the entire guarantee this file exists for, and a hand-maintained list cannot make it — it fails in exactly the case it was written to catch. ## On the count assertion `toHaveLength(12)` stays, renamed and documented as what it actually is: a deliberate tripwire. The derived test catches a map teardown *forgets*; the count fires on any new scope map at all, cleaned or not, so adding one can't be an incidental edit. Bumping that number is the moment to ask whether the new table also needs seeding, redaction, or a popup surface. ## Verification ``` npm test 92 files, 1240 passed (1240) packages/extension-core npx tsc -b exit 0 packages/extension-chrome npx tsx build.ts built ``` 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Sb9i5qyBwXYP8EkxdQfySu
🤖 I have created a release *beep* *boop* --- ## [2.1.0](v2.0.0...v2.1.0) (2026-08-09) ### Features * **extension:** dial configured remote bridges alongside loopback ([#233](#233)) ([cc81e8a](cc81e8a)) * **server:** fall back to FETCHPROXY_WS_PORT for the concentrator port ([#231](#231)) ([c221262](c221262)) ### Bug Fixes * **extension:** give a refused hello its binding back, and show each bridge's own state ([#236](#236)) ([1f8da11](1f8da11)), closes [#234](#234) * **extension:** refuse download over a remote bridge ([#235](#235)) ([306d1f5](306d1f5)) ### Refactor * **extension-core:** split background.ts into purpose-shaped modules ([#226](#226)) ([db30f4d](db30f4d)), closes [#10](#10) * **extension-core:** stop exporting background helpers nothing imports ([#229](#229)) ([42c39a1](42c39a1)), closes [#227](#227) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Addresses the first nit from the #226 auto-review follow-ups (#227).
Nit 1 — seven symbols exported but referenced only within their own module — FIXED
Verified real before changing anything. A whole-tree
git grepoverorigin/main(tracked files only, sonode_modules/distare out of scope, docs are in) shows every one of the seven referenced only inside its own defining module. The apparent cross-file hits are false positives:declaredScope/DeclaredScopeintests/background.test.tsandserver-hello.tsare localconst declaredScope/const declaredScopeForHashidentifiers, not imports. Both barrels (src/background.ts,src/index.ts) were read directly — they re-exporthandleServerHello/HandleHelloDeps/HandleHelloResult,applyNeedsPairRecord/AnyPendingRecordand the session-scope symbols, and none of the seven.The sibling exports deliberately stay:
badge.ts's four transitions (setConnectionStatus,flashActivity,setPairPendingBadge,clearPairPendingBadge) are imported bysocket.ts/server-hello.ts/approval.ts/boot.ts, andPendingPairRecord/PendingScopeUpdateRecordare imported byserver-hello.ts. Only the over-exported symbols were narrowed.No TS4020.
PendingRecordBasedoes not needexportto remain reachable as theextendsbase of two exported interfaces. Confirmed from the emitted declaration rather than assumed:Docblock correction.
pending-records.tsasserted thatPendingRecordBasewas "exported here becausebackground.tsstill constructs both record kinds." Two things wrong with that: the constructor isserver-hello.ts(lines 139 and 214), notbackground.ts, and the export was not needed for it either way. Rewritten to say what is actually true.Regression guard
New
tests/background-module-surface.test.tspins all three surfaces. It guards both halves:Object.keys(module)).tsconfig.jsonsetsinclude: ["src/**/*"]—tsc -bnever readstests/, so a strayexport interfacecannot be caught by a type error either. Without the source-text half,DeclaredScopeandPendingRecordBasewould have had no automated guard at all.TDD — the guard was written first and run against the unfixed tree (
git stashof the threesrc/files, restored after):All four fail without the fix; all five pass with it.
Nit 2 —
session-scope-teardown.test.tsALL_SCOPE_MAPS— DEFERREDNot touched by this PR. Its checkbox stays unchecked on #227, which therefore stays open — no
Closes.Verification
Run in CI's order (
build-command: npm run build, thentest-command: npm test), all after the final edit:Refs #227