Skip to content

Commit 2d81f58

Browse files
committed
test(plugin-dev): take the real module resolution out of the tenancy-posture clocked window
`dev-plugin-tenancy-posture.test.ts` left `@objectstack/organizations` unmocked so the real resolution failure would be the signal for branch entry. Five of its six cases therefore performed a real, uncached `node_modules` walk inside the per-test clocked window, which is the only thing in that window whose cost is a function of concurrent machine load. Under a parallel shard one case exceeded the 5000ms budget. Measured, since the first reading was wrong: the failing resolution is not cached (200 consecutive attempts, p50 1.157ms, none free) and is not served by the vitest main process (with that process blocked by ~45s of transforms the cases still ran in 2-12ms), so it is the worker's own resolver; under filesystem contention the same 200 attempts keep p50 at 0.839ms but take max from 8.0ms to 28.2ms. The package now gets the same throwing factory the other twelve get, which is what this file's own `#3060` block always claimed to achieve ("zero module resolution on the hot path"). The absence itself keeps its faithful witness: `dev-plugin-tenancy-failfast.test.ts` still reads the real, unmocked failure, and `no-framework-dependents.pin.test.ts` pins the ADR-0132 entitlement boundary that makes the package unresolvable here. Claude-Session: https://claude.ai/code/session_01AhQASwqJr2Z7XfGWUdvnbF Co-authored-by: Claude <noreply@anthropic.com>
1 parent e99a14c commit 2d81f58

1 file changed

Lines changed: 53 additions & 14 deletions

File tree

‎packages/plugins/plugin-dev/src/dev-plugin-tenancy-posture.test.ts‎

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,64 @@
2020
// service "is the wall up?" would be circular.
2121
//
2222
// ── What is observed, and why it is honest ──────────────────────────────────
23-
// `@objectstack/organizations` is open core since ADR-0132 and IS a member of
24-
// this workspace, but ADR-0132's entitlement boundary forbids any framework
25-
// package declaring it (`no-framework-dependents.pin.test.ts`), so it is
26-
// genuinely unresolvable from `plugin-dev`: the dynamic import genuinely fails
27-
// and the real catch branch runs. That makes the emitted warning a faithful
28-
// witness for "the multi-org branch was ENTERED": under the bug there is no
29-
// warning at all, because the `if` was never taken. The assertions therefore
30-
// key on branch ENTRY, not on a successfully mounted plugin — the latter is
31-
// unobservable in open-source CI, and pretending otherwise would need a fake
32-
// enterprise package, i.e. stubbing the very thing under test.
23+
// The assertions key on branch ENTRY, read off the warning the absent-package
24+
// path emits: under the bug there is no warning at all, because the `if` was
25+
// never taken. They deliberately do NOT key on a successfully mounted plugin —
26+
// that is unobservable in open-source CI, and pretending otherwise would need a
27+
// fake enterprise package, i.e. stubbing the very thing under test.
28+
//
29+
// `@objectstack/organizations` is SIMULATED absent here, by the same throwing
30+
// factory the twelve packages below get. That is a change: this file used to let
31+
// the REAL dynamic import fail, which it does — ADR-0132's entitlement boundary
32+
// forbids any framework package declaring the name
33+
// (`no-framework-dependents.pin.test.ts`), so it is genuinely unresolvable from
34+
// `plugin-dev`. What the real failure bought was honesty about the ABSENCE.
35+
// What it cost was a real, uncached module resolution inside the CLOCKED WINDOW
36+
// of five of the six cases below — and the absence is not this file's subject.
37+
// Its subject is WHICH KNOB decides branch entry.
38+
//
39+
// Measured on this tree, three readings, because the first guess was wrong:
40+
// • the failing resolution is NOT cached — 200 consecutive attempts from this
41+
// file's own runner, p50 1.157ms, max 8.037ms, none of them free;
42+
// • it is NOT served by the vitest main process, so it is not the transform
43+
// queue the `#3060` note below names: with that process blocked by ~45s of
44+
// real transforms these cases still ran in 2–12ms. The cost is the WORKER's
45+
// own resolver walking `node_modules` and raising ERR_MODULE_NOT_FOUND;
46+
// • that walk has a load-sensitive tail — the same 200 attempts under
47+
// filesystem contention keep p50 at 0.839ms but take max from 8.0ms to
48+
// 28.2ms.
49+
//
50+
// So each walled case drew from an unbounded, machine-load-dependent
51+
// distribution, and a 5000ms per-test budget bounded the DRAW rather than any
52+
// work this file is about. Under a parallel shard it timed out on a case that
53+
// asserts a back-compat env-var reading. Scaled repro, same command before and
54+
// after, timeout scaled down instead of load scaled up: with the per-test budget
55+
// at 25ms under filesystem contention, 10 runs of this file failed 6 times
56+
// before this change and 0 times after — and every one of those 10 timeouts
57+
// landed on a WALLED case, never on the single-org case, which runs three
58+
// `init()`s and resolves nothing. That control is what names the construct.
59+
//
60+
// ⛔ Nothing about the absence is given up by the SUITE, only by this file: the
61+
// real, unmocked resolution failure is still the signal in
62+
// `dev-plugin-tenancy-failfast.test.ts`, whose subject IS the absent-package
63+
// path, and the boundary that makes the package absent is pinned mechanically
64+
// by `no-framework-dependents.pin.test.ts`. A mock that stopped matching
65+
// reality would therefore redden there, not go unnoticed here.
3366

3467
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
3568

36-
// #3060 — the same treatment the sibling suite uses: init() dynamically imports
69+
// #3060 — the same treatment the sibling suites use: init() dynamically imports
3770
// ~10 real workspace packages, whose vite transforms alone can blow the test
3871
// timeout under a parallel `pnpm test`. Each factory throws the shape an absent
3972
// package produces, so the graceful-degradation branches run for real with zero
40-
// module resolution on the hot path. `@objectstack/organizations` is
41-
// deliberately NOT listed: it is really absent, and its real failure is the
42-
// signal this file reads.
73+
// module resolution on the hot path.
74+
//
75+
// `@objectstack/organizations` is listed HERE TOO, and the header above is the
76+
// argument for why it may be: keeping it off this list left one real resolution
77+
// per walled case in the clocked window, which is the only thing in that window
78+
// whose cost is a function of what else the machine is doing. "Zero module
79+
// resolution on the hot path" is what this block has always claimed; now it is
80+
// true.
4381
vi.mock('@objectstack/objectql', () => { throw Object.assign(new Error("Cannot find package '@objectstack/objectql'"), { code: 'ERR_MODULE_NOT_FOUND' }); });
4482
vi.mock('@objectstack/runtime', () => { throw Object.assign(new Error("Cannot find package '@objectstack/runtime'"), { code: 'ERR_MODULE_NOT_FOUND' }); });
4583
vi.mock('@objectstack/driver-memory', () => { throw Object.assign(new Error("Cannot find package '@objectstack/driver-memory'"), { code: 'ERR_MODULE_NOT_FOUND' }); });
@@ -52,6 +90,7 @@ vi.mock('@objectstack/plugin-hono-server', () => { throw Object.assign(new Error
5290
vi.mock('@objectstack/rest', () => { throw Object.assign(new Error("Cannot find package '@objectstack/rest'"), { code: 'ERR_MODULE_NOT_FOUND' }); });
5391
vi.mock('@objectstack/setup', () => { throw Object.assign(new Error("Cannot find package '@objectstack/setup'"), { code: 'ERR_MODULE_NOT_FOUND' }); });
5492
vi.mock('@objectstack/account', () => { throw Object.assign(new Error("Cannot find package '@objectstack/account'"), { code: 'ERR_MODULE_NOT_FOUND' }); });
93+
vi.mock('@objectstack/organizations', () => { throw Object.assign(new Error("Cannot find package '@objectstack/organizations'"), { code: 'ERR_MODULE_NOT_FOUND' }); });
5594

5695
import { DevPlugin } from './dev-plugin';
5796

0 commit comments

Comments
 (0)