Skip to content

Commit a89a1cc

Browse files
committed
test(runtime,metadata-protocol,objectql): pay the lint root's first load in a setup file, outside the clocked case
A served view read and an object publish load @objectstack/lint lazily; under vitest that first load is a cold transform paid inside whichever case makes the file's first such read. A traced full run of each suite found it inside a case in 9 runtime, 39 metadata-protocol and 18 objectql test files. Each package now imports the root in a setup file, which vitest runs before collection and no timeout clocks. objectql gains the anchored ^@objectstack/lint$ source alias, since it does not depend on lint itself. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ihL2gLghEqeDKTbDTC7Zd
1 parent 7dae3b3 commit a89a1cc

6 files changed

Lines changed: 142 additions & 2 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
//
3+
// Pay the first load of the `@objectstack/lint` package ROOT before a test
4+
// file is collected, never inside a clocked case. Wired as `setupFiles` in
5+
// `../vitest.config.ts`.
6+
//
7+
// ## Why
8+
//
9+
// The protocol loads the lint root lazily, on first use, in two places: a
10+
// served `view` read decorates its `_diagnostics` with the form-layout
11+
// warnings (`loadFormLayoutLint`, src/metadata-diagnostics.ts), and an object
12+
// publish runs its build probes (`runBuildProbes`, src/build-probes.ts). The
13+
// lazy shape is product design: the kernel boot path never reaches the root.
14+
// Under vitest the first of those loads is a cold transform of the lint
15+
// module graph, paid inside whichever case makes the file's first such read
16+
// or publish. Here the root resolves to `lint/dist/index.js` (no alias; the
17+
// package's row in `check:test-source-alias` lists it), and one run of the
18+
// whole suite traced that load inside a case in 39 test files. In those
19+
// cases it measured 714 ms p50 idle and 975 ms p50 (1241 ms max) with four
20+
// copies on four cores, against siblings in the tens of milliseconds and the
21+
// 5000 ms `testTimeout`.
22+
//
23+
// ## What it does
24+
//
25+
// It imports the root once, at module top. vitest runs a setup file before it
26+
// collects the test file, and neither `testTimeout` nor `hookTimeout` clocks
27+
// that. The setup file shares the test file's module graph, so the
28+
// protocol's later `import()` gets this instance back.
29+
//
30+
// A setup file rather than a per-file import, because 39 files need it and a
31+
// new test that first reaches a view read or an object publish needs it too,
32+
// without knowing it. The price is that every test file in the package
33+
// evaluates the lint root once during setup, including the files that never
34+
// reach it.
35+
import '@objectstack/lint';

‎packages/metadata-protocol/vitest.config.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
22

3-
// This config exists for exactly two settings; everything else stays on
3+
// This config exists for exactly three settings; everything else stays on
44
// vitest's defaults, deliberately — a key added here re-specifies behaviour
55
// for every test file in the package (packages/cli/vitest.config.ts's header
66
// records the incident that taught that).
@@ -16,6 +16,11 @@ export default defineConfig({
1616
// Mechanism + measured costs: examples/app-showcase/vitest.config.ts.
1717
// Enforced repo-wide by scripts/check-console-intercept-disarm.mjs.
1818
disableConsoleIntercept: true,
19+
// [#29627] The lint package root's first load is paid here, before a test
20+
// file is collected, never inside the case that makes the file's first
21+
// served view read or object publish. The module's header carries the
22+
// measurement and the price.
23+
setupFiles: ['./test/lint-root-preload.setup.ts'],
1924
},
2025
resolve: {
2126
alias: [
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
//
3+
// Pay the first load of the `@objectstack/lint` package ROOT before a test
4+
// file is collected, never inside a clocked case. Wired as `setupFiles` in
5+
// both projects of `../vitest.config.ts`.
6+
//
7+
// ## Why
8+
//
9+
// `@objectstack/metadata-protocol` loads the lint root lazily, on first use,
10+
// in two places: a served `view` read decorates its `_diagnostics` with the
11+
// form-layout warnings (`loadFormLayoutLint`, metadata-diagnostics.ts), and an
12+
// object publish runs its build probes (`runBuildProbes`, build-probes.ts).
13+
// The lazy shape is product design: the kernel boot path never reaches the
14+
// root. Under vitest the first of those loads is a cold transform of the lint
15+
// module graph, paid inside whichever case makes the file's first such read
16+
// or publish. One run of the whole suite traced that load inside a case in
17+
// 18 test files of this package. In those cases it measured 796 ms p50 idle
18+
// and 1169 ms p50 (2282 ms max) with four copies on four cores, against
19+
// siblings in the tens of milliseconds and the 5000 ms `testTimeout`.
20+
//
21+
// ## What it does
22+
//
23+
// It imports the root once, at module top. vitest runs a setup file before it
24+
// collects the test file, and neither `testTimeout` nor `hookTimeout` clocks
25+
// that. The setup file shares the test file's module graph, so the
26+
// protocol's later `import()` gets this instance back. This package does not
27+
// depend on `@objectstack/lint`, so the specifier resolves through the
28+
// anchored alias in `../vitest.config.ts`, which sends the protocol's own
29+
// `import()` to the same source file.
30+
//
31+
// A setup file rather than a per-file import, because 18 files need it and a
32+
// new test that first reaches a view read or an object publish needs it too,
33+
// without knowing it. The price is that every test file in the package
34+
// evaluates the lint root once during setup, including the files that never
35+
// reach it.
36+
import '@objectstack/lint';

‎packages/objectql/vitest.config.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,25 @@ runProjectCliOverridePreflight({
104104
parse: parseCLI,
105105
});
106106

107+
// [#29627] The lint package root's first load is paid in this setup file,
108+
// before a test file is collected, never inside the case that makes the
109+
// file's first served view read or object publish. Named in EACH project
110+
// below, like the per-project settings beside it. The module's header carries
111+
// the measurement and the price.
112+
const LINT_ROOT_PRELOAD = './test/lint-root-preload.setup.ts';
113+
107114
export default defineConfig({
115+
resolve: {
116+
alias: [
117+
// [#29627] The package root the preload above imports. This package does
118+
// not depend on `@objectstack/lint`; metadata-protocol does, and loads
119+
// the root lazily from its `dist/`. Anchored, so lint's published
120+
// subpaths are not swallowed by the file replacement, and pointed at
121+
// source, so the preload and the protocol's own `import()` resolve to
122+
// the same module, the lint rule in the checkout, never `dist/`.
123+
{ find: /^@objectstack\/lint$/, replacement: path.resolve(__dirname, '../lint/src/index.ts') },
124+
],
125+
},
108126
test: {
109127
// Each project re-declares the root block's test options: a ROOT-level
110128
// value is inert for a project run (measured on vitest 4.1.10, see
@@ -124,6 +142,7 @@ export default defineConfig({
124142
// block. A ROOT-level value is inert for a project run, so it is
125143
// declared here as well (scripts/check-console-intercept-disarm.mjs).
126144
disableConsoleIntercept: true,
145+
setupFiles: [LINT_ROOT_PRELOAD],
127146
},
128147
},
129148
{
@@ -139,6 +158,7 @@ export default defineConfig({
139158
// block. A ROOT-level value is inert for a project run, so it is
140159
// declared here as well (scripts/check-console-intercept-disarm.mjs).
141160
disableConsoleIntercept: true,
161+
setupFiles: [LINT_ROOT_PRELOAD],
142162
},
143163
},
144164
],
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
//
3+
// Pay the first load of the `@objectstack/lint` package ROOT before a test
4+
// file is collected, never inside a clocked case. Wired as `setupFiles` in
5+
// both projects of `../vitest.config.ts`.
6+
//
7+
// ## Why
8+
//
9+
// `@objectstack/metadata-protocol` loads the lint root lazily, on first use,
10+
// in two places: a served `view` read decorates its `_diagnostics` with the
11+
// form-layout warnings (`loadFormLayoutLint`, metadata-diagnostics.ts), and an
12+
// object publish runs its build probes (`runBuildProbes`, build-probes.ts).
13+
// The lazy shape is product design: the kernel boot path never reaches the
14+
// root. Under vitest the first of those loads is a cold transform of the lint
15+
// module graph, paid inside whichever case makes the file's first such read
16+
// or publish. One run of the whole suite traced that load inside a case in 9
17+
// test files of this package. Here the root resolves through the anchored
18+
// `^@objectstack/lint$` alias to lint's source, which costs less than the
19+
// built bundle the two sibling packages load, but it still lands in the case.
20+
//
21+
// ## What it does
22+
//
23+
// It imports the root once, at module top. vitest runs a setup file before it
24+
// collects the test file, and neither `testTimeout` nor `hookTimeout` clocks
25+
// that. The setup file shares the test file's module graph, so the
26+
// protocol's later `import()` gets this instance back.
27+
//
28+
// A setup file rather than a per-file import, because 9 files need it and a
29+
// new test that first reaches a view read or an object publish needs it too,
30+
// without knowing it. `meta-write-org-scope.test.ts` keeps its own module-top
31+
// import, which now finds the module already loaded. The price is that every
32+
// test file in the package evaluates the lint root once during setup,
33+
// including the files that never reach it.
34+
import '@objectstack/lint';

‎packages/runtime/vitest.config.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ runProjectCliOverridePreflight({
9898
parse: parseCLI,
9999
});
100100

101+
// [#29627] The lint package root's first load is paid in this setup file,
102+
// before a test file is collected, never inside the case that makes the
103+
// file's first served view read or object publish. Named in EACH project
104+
// below, like the per-project settings beside it. The module's header carries
105+
// the measurement and the price.
106+
const LINT_ROOT_PRELOAD = './test/lint-root-preload.setup.ts';
107+
101108
export default defineConfig({
102109
resolve: {
103110
// ARRAY form, not the object form: only the array form accepts a RegExp
@@ -154,7 +161,8 @@ export default defineConfig({
154161
{ find: /^@objectstack\/lint\/runtime$/, replacement: path.resolve(__dirname, '../lint/src/runtime.ts') },
155162
// [#29603] The package root: a served view read imports it lazily for the
156163
// form-layout warnings (metadata-protocol's `loadFormLayoutLint`), and
157-
// `meta-write-org-scope.test.ts` pays that load at module top. Both
164+
// `meta-write-org-scope.test.ts` pays that load at module top, as every
165+
// test file does through `LINT_ROOT_PRELOAD` (#29627). All of them
158166
// resolve here, so the read judges the lint rule in the checkout, never `dist/`.
159167
{ find: /^@objectstack\/lint$/, replacement: path.resolve(__dirname, '../lint/src/index.ts') },
160168
// The MCP bridge (`domains/mcp.ts`) reads "this field declares options"
@@ -272,6 +280,7 @@ export default defineConfig({
272280
// block. A ROOT-level value is inert for a project run, so it is
273281
// declared here as well (scripts/check-console-intercept-disarm.mjs).
274282
disableConsoleIntercept: true,
283+
setupFiles: [LINT_ROOT_PRELOAD],
275284
},
276285
},
277286
{
@@ -290,6 +299,7 @@ export default defineConfig({
290299
// block. A ROOT-level value is inert for a project run, so it is
291300
// declared here as well (scripts/check-console-intercept-disarm.mjs).
292301
disableConsoleIntercept: true,
302+
setupFiles: [LINT_ROOT_PRELOAD],
293303
},
294304
},
295305
],

0 commit comments

Comments
 (0)