Repository navigation
fix(test-env): keep the storage instrument from going blind on Node 26 - #7785
Conversation
…6 (objectui#7271) From Node 26 the experimental Web Storage globals are on by default. Vitest's `populateGlobal` copies happy-dom's `Storage` class (its name is on Vitest's hardcoded key list) but NOT happy-dom's `localStorage`/`sessionStorage` (they are not), so in a happy-dom environment the class and the stores came from two different implementations and patching `Storage.prototype` observed nothing. `vitest.setup.base.ts` now states the rule positively - in a DOM environment every storage global is that environment's own `Storage` - and verifies it by identity, so a future divergence fails by name in every suite instead of quietly measuring a store nobody wrote to. `anonSeedScope-5746.enumeration.test.tsx` gains an environment guard that names this failure mode before the ledger is consulted. It does not replace S0: the counter-probe still has to hold on its own. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KbJQ1y1J12nZxYzFWhP8Q3
…alstorage-probe-node26
…ctui#7271)
Re-measured on this branch, not carried from the previous run:
* `Object.keys(localStorage)` on the pre-repair Node 26 store does NOT answer
`[]`. Measured, it answers the shim object literal's own six members,
`["length","clear","getItem","key","removeItem","setItem"]`. The effect the
comment described is real - a caller filtering own keys by a key prefix sees
nothing - but the value it named was wrong.
* The census the comment left open is now filled in. Over the 102
storage-touching suites on v26.7.0 with the old rule: 3 files red (12
tests), named; and two further suites that instrument `Storage.prototype`
stayed GREEN while the instrument was proven blind, which is what makes the
positive statement of the rule the right shape.
Comment-only; no executable line changes.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KbJQ1y1J12nZxYzFWhP8Q3
✅ Console Performance Budget
The eager closure is every chunk the entry reaches through static imports — what the browser fetches and parses before the app renders. The entry chunk on its own is a small fraction of it. 📦 Bundle Size Report
Size Limits
|
落地前检三条全过,已转 ready-for-review 并入队
① 契约复审Clause-② 申报 ② 载体一致
③ CI —— 逐项枚举,⛔ 不读聚合head
⛔ 没有读 入队
⇒ 等出队。合并后读 Generated by Claude Code |
Fixes #7271
Every number below was measured on this branch in this run, at
aac3322e0unless areading is explicitly labelled "before". Node 26.7.0 is a local toolchain download; the
container ships 20/21/22 only. CI stays pinned at 22.x — nothing here changes
ci.yml.Root cause, measured
Node 22.22.2 has no Web Storage globals at all (
typeof Storage,typeof localStorage,typeof sessionStorageallundefined;--experimental-webstorageturns them on). Node 26.7.0 has them by default:
Storageis a function whoseconstructor answers
Illegal constructor,sessionStorageis a live native store, andlocalStorageis a getter that warnslocalStorage is not available because --localstorage-file was not providedand answersundefined.Vitest's
populateGlobal(v4.1.10,dist/chunks/index.DC7d2Pf8.js) decides per key:"Storage"is on that list."localStorage"and"sessionStorage"are not — grepped inall three installed copies: 1 hit, 0 hits, 0 hits. So on Node 26, inside a happy-dom
environment, the class is copied from happy-dom while the two stores are left as Node's.
Measured with no setup file at all, happy-dom, v26.7.0:
instanceof globalThis.StoragelocalStorageundefined(Node's warning getter)sessionStorageStorage(Node's)A
Storage.prototypepatch therefore observes 0 writes there, against 2 on Node 22.The old shim in
vitest.setup.base.tsonly replaced a store that was missing or lackedclear/removeItem: that caughtlocalStorage(replaced with a plain object literal)and left
sessionStorageas Node's, which is the store the code under test writes.What changes
vitest.setup.base.tsstates the rule positively — in a DOM environment every storageglobal is that environment's own
Storage— discriminating happy-dom's class from Node'sby constructibility (
new Storage()throwsIllegal constructoron Node's; happy-dom'sdoes not), and then verifies it by identity so that a future divergence fails by name
in every suite instead of one suite quietly measuring a store nobody wrote to.
anonSeedScope-5746.enumeration.test.tsxgains an environment guard that names thisfailure mode before the ledger is consulted. It does not replace S0.
The property the repair had to preserve, and the proof it does
S0 is the file's counter-probe; the whole point of the card is that a repair which makes
S1..S6 green while disarming S0 is worse than the bug. Two deliberate blindings on the
repaired tree, both of which the two guards accept (
instanceofstill holds), bothwith the mutation confirmed on disk by blob hash and restored under a trap:
Storage.prototypepatch cannot reach)In both ablations neither guard fires and the failure is S0's own:
In the control the string
expected 0 to be greater than 0is absent. E1 also reproducesthe claim the code comment makes about a four-method liveness probe.
Readings on both Node versions, before and after
Same tree, one file swapped at a time, each swap confirmed by blob hash:
test environment: `sessionStorage` is not an instance …The third row is the honest one: the setup repair alone is what turns the suite green. The
test-file guard buys a named diagnosis at a later checkpoint, not the green.
Blast radius of
vitest.setup.base.tsThis file runs for every test in the repository, so the claim is not "it looks local". The
population is enumerated rather than sampled: the storage block branches on the
environment, not on the test file, and the farm has exactly two —
node(theunitproject) and
happy-dom(dom,dom-heavy,dist,apps/console). All four cells wereprobed directly, before and after:
instanceoftrue, prototype patch observes 2 writes,Object.keysshows entriesunit)sessionStoragewas Node's native store, now the same deterministic shimOn the Node version CI pins, both environments read identically before and after: on
Node 22 nothing exists to displace happy-dom's stores, so the block's replacing branch is
never taken either way.
Named population, run end to end: the 102 test files that reference
localStorage,sessionStorageorStorage(git grep -loverpackages/,apps/,examples/,scripts/; list in the report).aac3322e0, node 22 and node 26Lit control. A one-line mutation forcing that block down its replacing branch with the
plain-object shim, on node 22, turns 5 of the 102 files / 15 tests red — so the
before/after equality above is a live measurement, not a dark one. Broader sample on the
repaired tree, node 22:
vitest run --shard=1/8, 319 files / 3905 tests, all passed.The sibling, and the census
The sibling reported on the card,
packages/auth/src/__tests__/signOut-client-cache-purge-5198.test.tsxcase 5777, reproduces on Node 26 before (1 failed) and is green after — with no change
to that file, because the repair is in the shared environment. Carrying a second edit
into
packages/authwould have been redundant. A third suite nobody had reported,packages/auth/src/__tests__/sessionUserChangePurge-5664.test.tsx(4 tests), behaves thesame way.
Four suites instrument
Storage.prototypedirectly. Two of them stayed green on Node26 before the repair, while the instrument was proven blind — i.e. they were passing
vacuously, which is exactly the hazard this card is about. Adding a temporary counter-probe
to each made them fail there, and one of them fails its counter-probe on Node 22 as well.
Neither carries a counter-probe of its own, so nothing would have said so. That is filed
separately rather than repaired here; it is a different fix (add counter-probes) in two
packages this card does not reach.
What was not run locally
The full farm (2547 test files) was not run: one eighth of it holds the shared verify lock
for ~7.5 minutes on this box, so both a before and an after pass would have cost about two
hours of exclusive lock and starved the other agents. The narrowing is declared, not
silent: what ran is the enumerated environment matrix, the named 102-file population on
both Node versions before and after with a lit control, one eighth of the farm on the
repaired tree, and the gate family below. CI runs the farm exactly once regardless.
Gates, all green at
aac3322e0:check-changeset-presence(it names the empty frontmatteras the explicit exemption),
check-changeset-no-major,check:control-bytes,check:vi-mock-specifiers,check:vi-mock-inherit,type-check:vitest-setup,lint:coverage,type-check:coverage,pnpm --filter @object-ui/app-shell type-check(the edited test file confirmed present in
tsc --listFiles). ESLint was run scoped to thetwo edited files rather than repo-wide: 2 files linted per
--format json, 0 errors, 2pre-existing
no-explicit-anywarnings on untouched lines 37-38, and the config declaresno type-aware linting, so no untouched file's verdict can move.
Generated by Claude Code