Skip to content

Commit 49f6809

Browse files
os-zhuangclaude
andauthored
perf(dogfood): worker-shared plain-showcase boot — one boot per worker, not per file (#3705)
Measured before surgery: the gate's test BODIES are ~61s of aggregate compute while per-file setup (TS module graph ~3.5s + kernel boot ~4.1s + hooks) is ~800s — ~93% of the suite was booting the identical app over and over (63 boots per run). vitest.config.ts now defines two projects: shared-showcase runs 12 files that boot the IDENTICAL plain showcase stack with isolate:false, so a memoized helper (test/shared-showcase.ts) boots once per WORKER; isolated keeps vitest defaults for everything else. Eligibility was audited file by file, not assumed: candidates needed a plain bootStack(showcaseStack) call AND zero /meta writes, zero org/BU mutation, zero exact-count assertions over shared objects, zero process.env toggles. Two near-misses the grep audit alone would have shipped — action-params-contract and two-factor-lockout both flip boot-time env flags — stayed isolated. Verified: full suite green under the new config (367 tests, same 364 passed / 3 skipped as baseline — no state bleed), wall 216s -> 190s locally on 4 workers, boots 63 -> 54; --shard composes with projects (1/8 shard: 9 files, green); eslint clean. Not attempted, deliberately: the scope-depth pair (~30s of real test body) boots three custom-security worlds by design — one isDefault profile per boot IS the proof — and rewriting that for speed would change what the gate proves. Claude-Session: https://claude.ai/code/session_01ECTCrcCdZpCHw5zFSgcmGt Co-authored-by: Claude <noreply@anthropic.com>
1 parent 134ee9b commit 49f6809

15 files changed

Lines changed: 149 additions & 76 deletions

.changeset/dogfood-shared-boot.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
---
3+
4+
CI/test-only: dogfood suite splits into a `shared-showcase` vitest project (12 eligible files share one plain showcase boot per worker via `isolate: false`) and an `isolated` project keeping vitest defaults. Measured: ~93% of the gate's compute was per-file boot overhead. Releases nothing.

packages/qa/dogfood/test/form-self-auth.dogfood.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
// while staying least-privilege. Proven at the engine boundary (the same
1010
// middleware the HTTP form-submit route flows through).
1111

12-
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
13-
import showcaseStack from '@objectstack/example-showcase';
14-
import { bootStack, type VerifyStack } from '@objectstack/verify';
12+
import { describe, it, expect, beforeAll } from 'vitest';
13+
import { type VerifyStack } from '@objectstack/verify';
14+
import { getSharedShowcase } from './shared-showcase.js';
1515

1616
const idOf = (r: any) => r?.id ?? r?.record?.id ?? r?.data?.id ?? r;
1717

@@ -21,13 +21,11 @@ describe('ADR-0056 Option A — public-form grant (declaration-derived)', () =>
2121
let ql: any;
2222

2323
beforeAll(async () => {
24-
stack = await bootStack(showcaseStack);
24+
stack = await getSharedShowcase();
2525
await stack.signIn();
2626
ql = await stack.kernel.getServiceAsync('objectql');
2727
}, 60_000);
2828

29-
afterAll(async () => { await stack?.stop(); });
30-
3129
it('authorizes CREATE on exactly the declared object (no userId / no guest_portal)', async () => {
3230
const ctx = { publicFormGrant: { object: 'showcase_private_note' } };
3331
const r = await ql.insert('showcase_private_note', { title: 'from public form' }, { context: ctx });
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
//
3+
// Worker-scoped shared showcase stack for the `shared-showcase` vitest project.
4+
//
5+
// A plain `bootStack(showcaseStack)` costs ~7.8s per test file (~3.5s TS module
6+
// graph + ~4.1s kernel assembly, metadata parse, security/seed bootstrap) —
7+
// measured on a 4-vCPU class host. With the default isolated pool, each of the
8+
// files that boot the IDENTICAL plain showcase paid that price separately:
9+
// ~29 boots per suite run, ~25% of the whole gate's compute.
10+
//
11+
// The `shared-showcase` project runs with `isolate: false`, so files assigned
12+
// to the same worker share one module registry — this module's memoized boot
13+
// then runs once per WORKER (≤4 per run) instead of once per file. The suite
14+
// process tears the worker down at the end of the run; the stack is in-memory
15+
// SQLite, so no explicit stop() is needed (and shared files must NOT call
16+
// stack.stop() — that would kill the instance under the worker's later files).
17+
//
18+
// ELIGIBILITY — a file may use the shared stack ONLY if all of these hold:
19+
// 1. It boots `bootStack(showcaseStack)` or `bootStack(showcaseStack, {})` —
20+
// no custom security/plugins/automation/multiTenant options.
21+
// 2. It does not mutate shared global surfaces: no /meta writes, no
22+
// organization/business-unit creation, no permission-set metadata edits.
23+
// 3. Its assertions tolerate other files' rows existing in shared objects:
24+
// no exact-count / exhaustive-list assertions over data it didn't create.
25+
// Scope every list assertion to records the file itself created (unique
26+
// emails / name prefixes).
27+
// Anything else stays in the `isolated` project (plain vitest defaults).
28+
import showcaseStack from '@objectstack/example-showcase';
29+
import { bootStack, type VerifyStack } from '@objectstack/verify';
30+
31+
let booted: Promise<VerifyStack> | undefined;
32+
33+
/** Boot (once per worker) and return the shared plain-showcase stack. */
34+
export function getSharedShowcase(): Promise<VerifyStack> {
35+
booted ??= bootStack(showcaseStack).then(async (stack) => {
36+
// First sign-in provisions the dev admin; later files' own signIn() calls
37+
// are idempotent (~0.16s) and just mint fresh admin tokens.
38+
await stack.signIn();
39+
return stack;
40+
});
41+
return booted;
42+
}

packages/qa/dogfood/test/showcase-agent-intersection.dogfood.test.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
//
1919
// @proof: showcase-agent-intersection
2020

21-
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
22-
import showcaseStack from '@objectstack/example-showcase';
23-
import { bootStack, type VerifyStack } from '@objectstack/verify';
21+
import { describe, it, expect, beforeAll } from 'vitest';
22+
import { type VerifyStack } from '@objectstack/verify';
23+
import { getSharedShowcase } from './shared-showcase.js';
2424

2525
const SYS = { isSystem: true } as const;
2626

@@ -35,7 +35,7 @@ describe('showcase: ADR-0090 D10 agent intersection (served engine)', () => {
3535
(await ql.findOne('sys_user', { where: { email }, context: SYS }))?.id;
3636

3737
beforeAll(async () => {
38-
stack = await bootStack(showcaseStack);
38+
stack = await getSharedShowcase();
3939
await stack.signIn(); // admin (ensures bootstrap)
4040
ownerTok = await stack.signUp('int-owner@verify.test');
4141
await stack.signUp('int-agent@verify.test');
@@ -66,10 +66,6 @@ describe('showcase: ADR-0090 D10 agent intersection (served engine)', () => {
6666
expect(delsNoteId, "delegator's note id").toBeTruthy();
6767
}, 120_000);
6868

69-
afterAll(async () => {
70-
await stack?.stop();
71-
});
72-
7369
// Agent context as it reaches the engine middleware (auth layer resolved the
7470
// agent's own grants into `permissions`; the delegator's are reconstructed
7571
// from the DB by the D10 path).

packages/qa/dogfood/test/showcase-agent-scope-ceiling.dogfood.test.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
//
1919
// @proof: showcase-agent-scope-ceiling
2020

21-
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
22-
import showcaseStack from '@objectstack/example-showcase';
23-
import { bootStack, type VerifyStack } from '@objectstack/verify';
21+
import { describe, it, expect, beforeAll } from 'vitest';
22+
import { type VerifyStack } from '@objectstack/verify';
23+
import { getSharedShowcase } from './shared-showcase.js';
2424

2525
const SYS = { isSystem: true } as const;
2626
const idOf = (r: any): string => r?.id ?? r?.record?.id;
@@ -36,7 +36,7 @@ describe('showcase: ADR-0090 D10 agent scope ceiling (served engine)', () => {
3636
(await ql.findOne('sys_user', { where: { email }, context: SYS }))?.id;
3737

3838
beforeAll(async () => {
39-
stack = await bootStack(showcaseStack);
39+
stack = await getSharedShowcase();
4040
await stack.signIn(); // admin bootstrap
4141
aliceTok = await stack.signUp('scope-alice@verify.test');
4242
ql = await stack.kernel.getServiceAsync('objectql');
@@ -50,10 +50,6 @@ describe('showcase: ADR-0090 D10 agent scope ceiling (served engine)', () => {
5050
expect(noteId, 'note id resolved').toBeTruthy();
5151
}, 120_000);
5252

53-
afterAll(async () => {
54-
await stack?.stop();
55-
});
56-
5753
// The agent context exactly as the producer emits it: acting on behalf of
5854
// Alice, whose OWN grants are the scope-derived ceiling (no member baseline).
5955
const agentCtx = (ceiling: string) => ({

packages/qa/dogfood/test/showcase-anonymous-deny-surfaces.dogfood.test.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
// is what a fresh production deployment gets) and asserts every surface denies
1313
// an anonymous caller with 401 while an authenticated member is unaffected.
1414

15-
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
16-
import showcaseStack from '@objectstack/example-showcase';
17-
import { bootStack, type VerifyStack } from '@objectstack/verify';
15+
import { describe, it, expect, beforeAll } from 'vitest';
16+
import { type VerifyStack } from '@objectstack/verify';
17+
import { getSharedShowcase } from './shared-showcase.js';
1818

1919
const OBJ = '/data/showcase_private_note';
2020

@@ -23,13 +23,11 @@ describe('showcase: anonymous posture is uniform across surfaces (#2567)', () =>
2323
let memberToken: string;
2424

2525
beforeAll(async () => {
26-
stack = await bootStack(showcaseStack); // platform default (deny anonymous)
26+
stack = await getSharedShowcase(); // platform default (deny anonymous)
2727
await stack.signIn();
2828
memberToken = await stack.signUp('surfaces-member@verify.test');
2929
}, 60_000);
3030

31-
afterAll(async () => { await stack?.stop(); });
32-
3331
// ── /meta ──────────────────────────────────────────────────────────────
3432
it('anonymous GET /meta is denied (401)', async () => {
3533
const r = await stack.api('/meta', { method: 'GET' });
@@ -41,7 +39,6 @@ describe('showcase: anonymous posture is uniform across surfaces (#2567)', () =>
4139
expect(r.status, 'authenticated metadata read must clear the auth gate').not.toBe(401);
4240
});
4341

44-
4542
// ── /data (surface-level; raw-hono handler proven in plugin-hono-server) ──
4643
it('anonymous READ of the data surface is denied (401)', async () => {
4744
const r = await stack.api(OBJ, { method: 'GET' });

packages/qa/dogfood/test/showcase-anonymous-deny.dogfood.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
// Public forms survive the same default via the declaration-derived
1010
// publicFormGrant — see showcase-public-form.dogfood.test.ts.
1111

12-
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
13-
import showcaseStack from '@objectstack/example-showcase';
14-
import { bootStack, type VerifyStack } from '@objectstack/verify';
12+
import { describe, it, expect, beforeAll } from 'vitest';
13+
import { type VerifyStack } from '@objectstack/verify';
14+
import { getSharedShowcase } from './shared-showcase.js';
1515

1616
const OBJ = '/data/showcase_private_note';
1717

@@ -20,13 +20,11 @@ describe('showcase: anonymous default-deny (ADR-0056 D2)', () => {
2020
let memberToken: string;
2121

2222
beforeAll(async () => {
23-
stack = await bootStack(showcaseStack); // harness boots on the platform default (deny anonymous)
23+
stack = await getSharedShowcase(); // harness boots on the platform default (deny anonymous)
2424
await stack.signIn();
2525
memberToken = await stack.signUp('d2-member@verify.test'); // anonymous /auth call → proves control-plane is open
2626
}, 60_000);
2727

28-
afterAll(async () => { await stack?.stop(); });
29-
3028
it('control-plane is open for anonymous (sign-up succeeded without a token)', () => {
3129
expect(memberToken, 'anonymous /auth/sign-up returned a token').toBeTruthy();
3230
});

packages/qa/dogfood/test/showcase-declarative-rbac-seeding.dogfood.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,19 @@
77
//
88
// @proof: showcase-declarative-rbac-seeding
99

10-
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
11-
import showcaseStack from '@objectstack/example-showcase';
12-
import { bootStack, type VerifyStack } from '@objectstack/verify';
10+
import { describe, it, expect, beforeAll } from 'vitest';
11+
import { type VerifyStack } from '@objectstack/verify';
12+
import { getSharedShowcase } from './shared-showcase.js';
1313

1414
describe('showcase: declarative RBAC seeding (ADR-0057 D6 / #2077)', () => {
1515
let stack: VerifyStack;
1616
let ql: any;
1717

1818
beforeAll(async () => {
19-
stack = await bootStack(showcaseStack);
19+
stack = await getSharedShowcase();
2020
await stack.signIn();
2121
ql = await stack.kernel.getServiceAsync('objectql');
2222
}, 60_000);
23-
afterAll(async () => { await stack?.stop(); });
2423

2524
it('declared roles land in sys_position (was count = 0)', async () => {
2625
const roles = await ql.find('sys_position', { where: {}, context: { isSystem: true } });

packages/qa/dogfood/test/showcase-permission-zoo.dogfood.test.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
//
1111
// @proof: showcase-permission-zoo
1212

13-
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
14-
import showcaseStack from '@objectstack/example-showcase';
15-
import { bootStack, type VerifyStack } from '@objectstack/verify';
13+
import { describe, it, expect, beforeAll } from 'vitest';
14+
import { type VerifyStack } from '@objectstack/verify';
15+
import { getSharedShowcase } from './shared-showcase.js';
1616

1717
const SYS = { isSystem: true } as const;
1818

@@ -28,7 +28,7 @@ describe('showcase: ADR-0090 permission-model zoo', () => {
2828
(await ql.findOne('sys_user', { where: { email }, context: SYS }))?.id;
2929

3030
beforeAll(async () => {
31-
stack = await bootStack(showcaseStack);
31+
stack = await getSharedShowcase();
3232
adminTok = await stack.signIn();
3333
ownerTok = await stack.signUp('zoo-owner@verify.test');
3434
plainTok = await stack.signUp('zoo-plain@verify.test');
@@ -75,10 +75,6 @@ describe('showcase: ADR-0090 permission-model zoo', () => {
7575
expect(noteId, 'probe note id resolved').toBeTruthy();
7676
}, 120_000);
7777

78-
afterAll(async () => {
79-
await stack?.stop();
80-
});
81-
8278
// ── The app seed can plant the platform org tree ─────────────────────────
8379
it('seeds the sys_business_unit tree with explicit ids and parent links', async () => {
8480
const units = await ql.find('sys_business_unit', { where: {}, context: SYS });

packages/qa/dogfood/test/showcase-private-owd.dogfood.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
// `owner_id`. This is the canonical "declare one word, get owner isolation"
99
// capability — proven end-to-end through the real HTTP stack.
1010

11-
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
12-
import showcaseStack from '@objectstack/example-showcase';
13-
import { bootStack, type VerifyStack } from '@objectstack/verify';
11+
import { describe, it, expect, beforeAll } from 'vitest';
12+
import { type VerifyStack } from '@objectstack/verify';
13+
import { getSharedShowcase } from './shared-showcase.js';
1414

1515
const OBJ = '/data/showcase_private_note';
1616
const idOf = (b: any) => b?.id ?? b?.record?.id ?? b?.data?.id ?? b?.recordId;
@@ -23,7 +23,7 @@ describe('showcase: declarative private OWD (ADR-0056)', () => {
2323
let bNoteId: string;
2424

2525
beforeAll(async () => {
26-
stack = await bootStack(showcaseStack);
26+
stack = await getSharedShowcase();
2727
await stack.signIn(); // seed dev admin (first user)
2828
aToken = await stack.signUp('owd-alice@verify.test');
2929
bToken = await stack.signUp('owd-bob@verify.test');
@@ -41,8 +41,6 @@ describe('showcase: declarative private OWD (ADR-0056)', () => {
4141
expect(bNoteId, 'bob note id').toBeTruthy();
4242
}, 60_000);
4343

44-
afterAll(async () => { await stack?.stop(); });
45-
4644
it('owner_id is auto-stamped (no manual assignment, no predicate)', async () => {
4745
const ql: any = await stack.kernel.getServiceAsync('objectql');
4846
const row = await ql.findOne('showcase_private_note', { where: { id: aNoteId }, context: { isSystem: true } });

0 commit comments

Comments
 (0)