Skip to content

Commit 8955995

Browse files
os-salesclaude
andauthored
test(cli): pay the cloud-connection transform at module load, out of the clocked window (#17659)
`optional-package.test.ts`'s end-to-end control — "resolves a real workspace package rather than mistaking it for absent" — called `loadOptionalPackage('@objectstack/cloud-connection')` inside vitest's default 5000ms `testTimeout`. With `packages/cloud-connection/dist` built it took 5005ms / 5043ms across two runs and timed out; the same import in plain node from `packages/cli` takes 856-1003ms on the same box. The gap is not import cost. Every workspace package here is a pnpm link whose realpath carries no `/node_modules/` segment, so vitest's default `server.deps.external` inlines it — `dist/` included — and the probe paid a cold whole-package source-graph transform inside the clock. Fix is the one `scripts/check-test-source-alias.mjs` prescribes in its clocked-window rule and that five sibling `packages/cli` test files already carry verbatim: a module-top side-effect import, so the transform is paid during collection, which vitest clocks against nothing. The timeout is NOT raised — the budget is the only thing currently reporting the cost. The assertion is untouched: the `it()` still calls `loadOptionalPackage()` on the real specifier and still asserts `state === 'loaded'`, so a genuinely absent or broken package still fails it. Claude-Session: https://claude.ai/code/session_01TSf4DV7ziu4V5j73e46b7c Co-authored-by: Claude <noreply@anthropic.com>
1 parent 5ddd5d3 commit 8955995

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

packages/cli/src/utils/optional-package.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,33 @@ import { pathToFileURL } from 'node:url';
3333

3434
import { loadOptionalPackage } from './optional-package.js';
3535

36+
// [#10126] Pay the first transform of this dist-resolved workspace dep at MODULE
37+
// LOAD. `@objectstack/cloud-connection` is reached below through
38+
// `loadOptionalPackage()`, which loads it dynamically from inside an `it()` body --
39+
// which vitest clocks, while collection is clocked against nothing. See
40+
// `scripts/check-test-source-alias.mjs` (the clocked-window rule) and #10115 /
41+
// PR #10120, where the same shape cost 30 ejected merge-queue builds in one night.
42+
//
43+
// [#17180] Why this file needed it too, measured with `packages/cloud-connection/dist`
44+
// BUILT: the probe below took 5005ms and 5043ms across two runs and blew the default
45+
// 5000ms `testTimeout`, against 856-1003ms for the same import in plain node from this
46+
// directory. The gap is not import cost -- every workspace package here is a pnpm link
47+
// whose realpath carries no `/node_modules/` segment, so vitest's default
48+
// `server.deps.external` inlines it, `dist/` included, and the probe was paying a cold
49+
// whole-package source-graph transform inside the clock. Paid here it is collection
50+
// work, which vitest clocks against nothing, and the call below becomes a module
51+
// registry lookup.
52+
//
53+
// The clocked-window rule could not see this one: its reader is a text scanner for a
54+
// literal `import(...)`/`require(...)` specifier, and here the specifier is an ordinary
55+
// string argument handed to `loadOptionalPackage()`, which imports a variable. That is
56+
// a gate gap, filed separately -- not something this file works around.
57+
//
58+
// This is a PRELOAD, not a substitute for the assertion: the `it()` below still calls
59+
// `loadOptionalPackage('@objectstack/cloud-connection')` and still asserts on the real
60+
// resolution, so a genuinely absent or broken package still fails it.
61+
import '@objectstack/cloud-connection';
62+
3663
/** A specifier nothing in this workspace resolves — genuinely not installed. */
3764
const NEVER_INSTALLED = '@objectstack/not-a-real-package-5644';
3865

0 commit comments

Comments
 (0)