|
101 | 101 | * same 501 instead of escaping to the route's own `500 EMAIL_SEND_FAILED`. |
102 | 102 | */ |
103 | 103 |
|
| 104 | +// [#21920] Pay the state route's `@objectstack/objectql` load at MODULE LOAD, |
| 105 | +// never inside a clocked window. |
| 106 | +// |
| 107 | +// The route reaches `legalNextStates` through a dynamic |
| 108 | +// `await import('@objectstack/objectql')` in `rest-server.ts`, kept dynamic on |
| 109 | +// purpose (a devDependency there: a host without the data engine degrades to |
| 110 | +// 501 rather than failing to load). This package's tests resolve that specifier |
| 111 | +// through `dist/`, so the first request to reach that line pays the vite |
| 112 | +// transform and evaluation of objectql's whole module graph, inside whichever |
| 113 | +// `it()` first gets PAST the gate with a schema: §0's multi-kernel case. Measured |
| 114 | +// on a 4-vCPU container, this file run alone, before this import existed: |
| 115 | +// |
| 116 | +// * idle: that case cost 3574-3661 ms of the 5000 ms `testTimeout`. Phase-timed, |
| 117 | +// the handler call is all of it (2.7-2.8 s in a stripped probe); wiring and |
| 118 | +// boot are under 1 ms each, and the cold KERNEL branch answering a 404 before |
| 119 | +// the load costs 1.5 ms. So it is the load, not a multi-kernel first-request |
| 120 | +// cost: under plain Node the same cold import is ~0.6 s on top of the core |
| 121 | +// and spec this server already loads, and a host whose engine IS objectql |
| 122 | +// has it loaded before any request. |
| 123 | +// * confined to one core beside two busy loops: `Test timed out in 5000ms` on |
| 124 | +// 3 of 3 runs, and the load, still in flight, then landed on §3's served |
| 125 | +// CONTROL (3714-4330 ms), the next case to reach the same line. |
| 126 | +// |
| 127 | +// A module-top import is paid during COLLECTION, which vitest clocks against |
| 128 | +// nothing (AGENTS.md § Build & Test; `scripts/check-test-source-alias.mjs` |
| 129 | +// carries the runner measurement). ⛔ Not a `beforeAll` with a budget, and not a |
| 130 | +// raised timeout: either only moves the window around the cost, and |
| 131 | +// `dev-plugin-security-enforcement-warning.test.ts` (plugin-dev) records such a |
| 132 | +// hook budget being exhausted on a heavier shard. The dynamic call in |
| 133 | +// `rest-server.ts` stays where it is; this only decides where the first load is |
| 134 | +// paid. §0's multi-kernel case pins it with a budget on its own work. |
| 135 | +import '@objectstack/objectql'; |
| 136 | + |
104 | 137 | import { describe, it, expect, vi } from 'vitest'; |
105 | 138 | import { |
106 | 139 | AUTHZ_STORE_UNAVAILABLE_CODE, |
@@ -299,9 +332,25 @@ describe('[#15405] §0 reachability of this consumer, measured', () => { |
299 | 332 | // and the route's own engine line is what decides. This is the |
300 | 333 | // precondition every case in §1–§4 depends on; without it they would |
301 | 334 | // all be measuring the gate. |
| 335 | + const started = performance.now(); |
302 | 336 | const seen = await driveStateOnKernelHost(providerHealthy); |
| 337 | + const ownWorkMs = performance.now() - started; |
303 | 338 | expect(seen.outcome).toBe('answered'); |
304 | 339 | expect(seen.status).toBe(200); |
| 340 | + // [#21920] PIN — this is the file's FIRST case to reach the route's |
| 341 | + // `import('@objectstack/objectql')`, so it is the one that pays that load |
| 342 | + // if it ever lands in a clocked window again (file head). Its own work, |
| 343 | + // measured on a 4-vCPU container: 3 ms idle, 12-16 ms with this file |
| 344 | + // confined to a third of one core, 3-23 ms confined to a fifth. The load |
| 345 | + // it must not carry: 3574-3661 ms with the file run alone, 893 and |
| 346 | + // 1723 ms in two whole-package runs (an earlier file had already cached |
| 347 | + // the transform). 500 ms sits about 20x above the first and below every |
| 348 | + // reading of the second, so the regression reads red on an IDLE box, |
| 349 | + // well before a loaded shard turns it into the 5000 ms timeout. |
| 350 | + expect( |
| 351 | + ownWorkMs, |
| 352 | + "this case paid a module load inside its clocked window: keep the module-top import of '@objectstack/objectql' at the file head", |
| 353 | + ).toBeLessThan(500); |
305 | 354 | }); |
306 | 355 | }); |
307 | 356 |
|
|
0 commit comments