Skip to content

Commit f1e9159

Browse files
os-warrenclaude
andauthored
test(plugin-auth): load the batch-6 admin endpoint graphs at module top, not inside each clocked case (#15914)
`durability-swallow-repair.test.ts`'s batch-6 cases reached `runAdminCreateUser` / `runAdminImportUsers` through `await import(...)` written inside the `it()` body. vitest wraps test bodies in `withTimeout(...)` and has no timeout knob covering module loading, so the FIRST of each group of structurally identical siblings charged that module graph's cold transform-and-import to its own 10 000 ms `testTimeout` while the rest hit the warm module cache. Under a loaded CI shard the first sibling ran out of budget and reddened PRs that read no part of this code. Loading at module top removes the clock rather than widening it: `collectTests()` awaits `runner.importFile()` bare and only records the duration for reporters. This is the repo-wide convention already stated in AGENTS.md and enforced for cross-package specifiers by `check-test-source-alias`. No assertion changed. The file has no `vi.mock`/`vi.resetModules`, so every case already shared one module instance via the module cache; the only edit to a case body is the removal of its import line. Claude-Session: https://claude.ai/code/session_01XpTx2tbq3pZRYAdoGt6E6Y Co-authored-by: Claude <noreply@anthropic.com>
1 parent ea03c7c commit f1e9159

1 file changed

Lines changed: 27 additions & 7 deletions

File tree

packages/plugins/plugin-auth/src/durability-swallow-repair.test.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,33 @@ import { assertEngineFindOnePredicate, assertEngineUpdateDispatch } from '@objec
4545
import { AuthManager } from './auth-manager';
4646
import { AuthPlugin } from './auth-plugin';
4747
import type { PluginContext } from '@objectstack/core';
48+
// [#14998] The two admin endpoint module graphs are loaded HERE, at module top,
49+
// and NOT with an `await import(...)` inside each case — which is how batch 6's
50+
// seven cases used to reach them.
51+
//
52+
// Why that mattered: vitest wraps test bodies and hooks in `withTimeout(...)`,
53+
// and offers exactly three timeout knobs (`testTimeout`, `hookTimeout`,
54+
// `teardownTimeout`) — none of which covers module loading. So an
55+
// `await import()` written inside an `it()` charges that module graph's cold
56+
// transform-and-import to the CASE's budget. Of N structurally identical
57+
// siblings only the FIRST pays it; the rest hit the warm module cache. This
58+
// package's `vitest.config.ts` sets `testTimeout: 10_000`, and
59+
// `admin-import-users.ts` pulls in `@objectstack/rest` (`prepareImportRequest`,
60+
// `runImport`) — so under a loaded CI shard the first sibling's cold load ate
61+
// the 10 s and the case failed with `Test timed out in 10000ms`, reddening PRs
62+
// that touch nothing this file reads (#14998, #15603).
63+
//
64+
// Loading at module top is not a widened budget, it removes the clock: vitest's
65+
// `collectTests()` awaits `runner.importFile(filepath, 'collect')` bare and only
66+
// RECORDS the duration for reporters. This is the repo-wide convention —
67+
// AGENTS.md § Build & Test, "clocked windows measure behaviour, never loading",
68+
// enforced for cross-package specifiers by `pnpm check:test-source-alias`.
69+
//
70+
// No case body changed apart from dropping its import line: there is no
71+
// `vi.mock`/`vi.resetModules` in this file, so every case already shared one
72+
// module instance through the module cache. Coverage is identical.
73+
import { runAdminCreateUser } from './admin-user-endpoints.js';
74+
import { runAdminImportUsers } from './admin-import-users.js';
4875

4976
const SECRET = 'test-secret-at-least-32-chars-long';
5077

@@ -576,7 +603,6 @@ describe('#12981 batch 6 — the plugin-auth admin-audit swallows report instead
576603
it('a refused audit row is reported, and names the action that still succeeded', async () => {
577604
const logger = createLogger();
578605
const engine = createAuditEngine({ registered: true, refuseAudit: true });
579-
const { runAdminCreateUser } = await import('./admin-user-endpoints.js');
580606

581607
const res = await runAdminCreateUser(makeDeps(engine, logger) as never, createUserRequest(), ACTOR as never);
582608

@@ -603,7 +629,6 @@ describe('#12981 batch 6 — the plugin-auth admin-audit swallows report instead
603629
it('plugin-audit UNINSTALLED stays silent, and does not attempt the write', async () => {
604630
const logger = createLogger();
605631
const engine = createAuditEngine({ registered: false });
606-
const { runAdminCreateUser } = await import('./admin-user-endpoints.js');
607632

608633
const res = await runAdminCreateUser(makeDeps(engine, logger) as never, createUserRequest(), ACTOR as never);
609634

@@ -619,7 +644,6 @@ describe('#12981 batch 6 — the plugin-auth admin-audit swallows report instead
619644
it('a healthy audit write reports nothing on this channel', async () => {
620645
const logger = createLogger();
621646
const engine = createAuditEngine({ registered: true });
622-
const { runAdminCreateUser } = await import('./admin-user-endpoints.js');
623647

624648
const res = await runAdminCreateUser(makeDeps(engine, logger) as never, createUserRequest(), ACTOR as never);
625649

@@ -634,7 +658,6 @@ describe('#12981 batch 6 — the plugin-auth admin-audit swallows report instead
634658
// A lean host/mock: the probe is optional, and its absence must fail
635659
// toward the loud answer, never toward the silent one.
636660
const lean = { insert: engine.insert, update: engine.update, find: engine.find };
637-
const { runAdminCreateUser } = await import('./admin-user-endpoints.js');
638661

639662
const res = await runAdminCreateUser(makeDeps(lean as never, logger) as never, createUserRequest(), ACTOR as never);
640663

@@ -673,7 +696,6 @@ describe('#12981 batch 6 — the plugin-auth admin-audit swallows report instead
673696
it('a refused run-level row is reported, and says the per-row trail survived', async () => {
674697
const logger = createLogger();
675698
const engine = createAuditEngine({ registered: true, refuseAudit: true });
676-
const { runAdminImportUsers } = await import('./admin-import-users.js');
677699

678700
const res = await runAdminImportUsers(makeDeps(engine, logger) as never, importRequest(), ACTOR as never);
679701

@@ -693,7 +715,6 @@ describe('#12981 batch 6 — the plugin-auth admin-audit swallows report instead
693715
it('plugin-audit UNINSTALLED stays silent, and does not attempt the write', async () => {
694716
const logger = createLogger();
695717
const engine = createAuditEngine({ registered: false });
696-
const { runAdminImportUsers } = await import('./admin-import-users.js');
697718

698719
const res = await runAdminImportUsers(makeDeps(engine, logger) as never, importRequest(), ACTOR as never);
699720

@@ -706,7 +727,6 @@ describe('#12981 batch 6 — the plugin-auth admin-audit swallows report instead
706727
it('a healthy run reports nothing on this channel', async () => {
707728
const logger = createLogger();
708729
const engine = createAuditEngine({ registered: true });
709-
const { runAdminImportUsers } = await import('./admin-import-users.js');
710730

711731
const res = await runAdminImportUsers(makeDeps(engine, logger) as never, importRequest(), ACTOR as never);
712732

0 commit comments

Comments
 (0)