2727 * the first test below asserts that precondition off the app's own flow rather
2828 * than trusting it, because adding a `fields` list to that step is precisely
2929 * the edit that would silently empty the day count again.
30+ *
31+ * ONE KERNEL PER FILE, CLEAN ROWS PER CASE. Booting a kernel inside each
32+ * async case put the boot under vitest's 5 s per-test default, and on a loaded
33+ * Test Core shard the first one was cut off at 5016 ms. So the kernel boots
34+ * once in `beforeAll`, under its own measured budget (below), and `beforeEach`
35+ * gives every case the table a fresh boot would: no `todo_task` rows (deleted
36+ * through the driver, so no hook observes the reset). Each case still passes
37+ * alone and in shuffled order.
3038 */
3139
32- import { describe , it , expect , afterEach } from 'vitest' ;
40+ import { describe , it , expect , beforeAll , beforeEach , afterAll } from 'vitest' ;
3341import { ObjectKernel } from '@objectstack/core' ;
3442import { ObjectQLPlugin } from '@objectstack/objectql' ;
3543import { SqliteWasmDriver } from '@objectstack/driver-sqlite-wasm' ;
@@ -38,13 +46,6 @@ import { OverdueEscalationFlow } from '../src/flows/index.js';
3846import { Task } from '../src/objects/task.object.js' ;
3947import { installDefaultOrganization } from './default-organization.testkit.js' ;
4048
41- const openDrivers : Array < { disconnect ?: ( ) => Promise < void > } > = [ ] ;
42- afterEach ( async ( ) => {
43- while ( openDrivers . length ) {
44- try { await openDrivers . pop ( ) ?. disconnect ?.( ) ; } catch { /* noop */ }
45- }
46- } ) ;
47-
4849/**
4950 * A node of the app's real flow, by id — searched at EVERY depth.
5051 *
@@ -95,7 +96,7 @@ function daysAgoIso(n: number): string {
9596}
9697
9798/** A real kernel with the app's real `todo_task` over in-process sqlite-wasm. */
98- async function bootTodoData ( ) : Promise < any > {
99+ async function bootTodoData ( ) : Promise < { data : any ; driver : any } > {
99100 const kernel = new ObjectKernel ( { logger : { level : 'silent' } } as any ) ;
100101 await kernel . use ( new ObjectQLPlugin ( ) ) ;
101102 await kernel . bootstrap ( ) ;
@@ -104,16 +105,38 @@ async function bootTodoData(): Promise<any> {
104105 const driver : any = new SqliteWasmDriver ( { filename : ':memory:' } ) ;
105106 await driver . connect ( ) ;
106107 objectql . registerDriver ( driver , true ) ;
107- openDrivers . push ( driver ) ;
108108 objectql . registry . registerObject ( Task , 'todo' , 'todo' ) ;
109109 await objectql . syncSchemas ( ) ;
110110 // A real `single` install's Default Organization: the system writes below
111111 // derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
112112 await installDefaultOrganization ( objectql ) ;
113113
114- return kernel . getService ( 'data' ) ;
114+ return { data : kernel . getService ( 'data' ) , driver } ;
115115}
116116
117+ /**
118+ * The boot budget is measured, not vitest's 10 s hook default. Locally one boot
119+ * (kernel, sqlite-wasm connect, schema sync, Default Organization) took
120+ * 150–250 ms cold and ~45 ms warm, and the case that paid it took 192–279 ms
121+ * idle and 466–693 ms with 8 CPU-bound processes beside the suite on 4 cores.
122+ * On a Test Core shard that case was cut off at 5016 ms (job 128575054246) and
123+ * the next one, booting its own kernel, took 3822 ms: the shard's slowdown has
124+ * reached ~20x the idle reading. 30 s is 6x the 5 s the shard already exceeded.
125+ */
126+ const BOOT_BUDGET_MS = 30_000 ;
127+
128+ let data : any ;
129+ let driver : any ;
130+ beforeAll ( async ( ) => { ( { data, driver } = await bootTodoData ( ) ) ; } , BOOT_BUDGET_MS ) ;
131+ afterAll ( async ( ) => { await driver ?. disconnect ?.( ) ; } ) ;
132+
133+ /** The table a fresh boot leaves: no task rows. */
134+ beforeEach ( async ( ) => {
135+ for ( const row of await driver . find ( 'todo_task' , { where : { } } ) ) {
136+ await driver . delete ( 'todo_task' , row . id ) ;
137+ }
138+ } ) ;
139+
117140const SYSTEM = { context : { isSystem : true } } ;
118141
119142describe ( '#18584 — the overdue escalation projection carries a day count' , ( ) => {
@@ -127,7 +150,6 @@ describe('#18584 — the overdue escalation projection carries a day count', ()
127150 } ) ;
128151
129152 it ( 'every `{{ currentTask.… }}` hole in the escalation body names a key the row carries' , async ( ) => {
130- const data = await bootTodoData ( ) ;
131153 const due = daysAgoIso ( 5 ) ;
132154 await data . insert ( 'todo_task' , {
133155 subject : 'Renew the domain' ,
@@ -163,7 +185,6 @@ describe('#18584 — the overdue escalation projection carries a day count', ()
163185 } ) ;
164186
165187 it ( '0 when the task is not overdue, and 0 when `due_date` is empty' , async ( ) => {
166- const data = await bootTodoData ( ) ;
167188 await data . insert ( 'todo_task' , {
168189 subject : 'Future task' , status : 'not_started' , priority : 'normal' ,
169190 due_date : daysAgoIso ( - 3 ) , owner : 'usr_test_owner' ,
0 commit comments