@@ -39,6 +39,7 @@ import { RecordChangeTriggerPlugin } from './plugin.js';
3939// `packages/runtime/src/**` (which is what `plugin-auth` and `dogfood`
4040// declare) because the helper imports nothing — it is the whole read.
4141import { captureExpectedReadRefusals } from '../../../runtime/src/expected-read-refusal-noise.js' ;
42+ import { installDefaultOrganization } from './default-organization.testkit.js' ;
4243
4344/**
4445 * `check:slot-lookup` (#4251) — a NEW `kernel.getService(...)` site must carry
@@ -417,6 +418,9 @@ describe('a system write must not fire a record-change flow UNSCOPED (#3760)', (
417418 await attachSqlite ( objectql ) ;
418419 objectql . registry . registerObject ( objectDef ( 'sysw' ) , 'test' , 'test' ) ;
419420 await objectql . syncSchemas ( ) ;
421+ // A real `single` install's Default Organization: the system writes below
422+ // derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
423+ await installDefaultOrganization ( objectql ) ;
420424 // No `runAs` — the spec default 'user'. This is the shape an author (very
421425 // often an AI) writes without realising it can run without a user.
422426 automation . registerFlow ( 'sysw_stamp' , stampFlow ( 'sysw_stamp' , 'sysw' ) as any ) ;
@@ -462,6 +466,9 @@ describe('a system write must not fire a record-change flow UNSCOPED (#3760)', (
462466 await attachSqlite ( objectql ) ;
463467 objectql . registry . registerObject ( objectDef ( 'sysw2' ) , 'test' , 'test' ) ;
464468 await objectql . syncSchemas ( ) ;
469+ // A real `single` install's Default Organization: the system writes below
470+ // derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
471+ await installDefaultOrganization ( objectql ) ;
465472 automation . registerFlow ( 'sysw2_stamp' , stampFlow ( 'sysw2_stamp' , 'sysw2' ) as any ) ;
466473
467474 const created = await data . insert ( 'sysw2' , { status : 'new' } , { context : { userId : 'u_trigger' } } ) ;
@@ -490,6 +497,9 @@ describe('record-change trigger — end-to-end (#1491)', () => {
490497 await attachSqlite ( objectql ) ;
491498 objectql . registry . registerObject ( objectDef ( 'wid' ) , 'test' , 'test' ) ;
492499 await objectql . syncSchemas ( ) ;
500+ // A real `single` install's Default Organization: the system writes below
501+ // derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
502+ await installDefaultOrganization ( objectql ) ;
493503 automation . registerFlow ( 'stamp_flow' , stampFlow ( 'stamp_flow' , 'wid' ) as any ) ;
494504
495505 // The flow bound to the trigger…
@@ -525,6 +535,9 @@ describe('record-change trigger — end-to-end (#1491)', () => {
525535 ql . registry . registerObject ( objectDef ( 'wid2' ) , 'test' , 'test' ) ;
526536 ql . registry . registerItem ( 'flow' , flowDef , 'name' , 'test' ) ;
527537 await ql . syncSchemas ( ) ;
538+ // A real `single` install's Default Organization: the system writes below
539+ // derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
540+ await installDefaultOrganization ( ql ) ;
528541 } ,
529542 } ;
530543
@@ -566,6 +579,9 @@ describe('record-change trigger — end-to-end (#1491)', () => {
566579 await attachSqlite ( objectql ) ;
567580 objectql . registry . registerObject ( objectDef ( 'wid3' ) , 'test' , 'test' ) ;
568581 await objectql . syncSchemas ( ) ;
582+ // A real `single` install's Default Organization: the system writes below
583+ // derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
584+ await installDefaultOrganization ( objectql ) ;
569585 automation . registerFlow ( 'mirror_write' , mirrorWriteFlow ( 'mirror_write' , 'wid3' ) as any ) ;
570586
571587 expect ( ( automation as any ) . getActiveTriggerBindings ( ) ) . toContainEqual ( {
@@ -600,6 +616,9 @@ describe('record-change trigger — end-to-end (#1491)', () => {
600616 await attachSqlite ( objectql ) ;
601617 objectql . registry . registerObject ( objectDef ( 'wid5' ) , 'test' , 'test' ) ;
602618 await objectql . syncSchemas ( ) ;
619+ // A real `single` install's Default Organization: the system writes below
620+ // derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
621+ await installDefaultOrganization ( objectql ) ;
603622 automation . registerFlow ( 'urgent_alert' , urgentAlertFlow ( 'urgent_alert' , 'wid5' ) as any ) ;
604623
605624 // Create leg — a brand-new URGENT record: `previous == null` makes the
@@ -662,6 +681,9 @@ describe('record-change trigger — end-to-end (#1491)', () => {
662681 'test' , 'test' ,
663682 ) ;
664683 await objectql . syncSchemas ( ) ;
684+ // A real `single` install's Default Organization: the system writes below
685+ // derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
686+ await installDefaultOrganization ( objectql ) ;
665687
666688 automation . registerFlow ( 'before_write_probe' , {
667689 name : 'before_write_probe' , label : 'Before-update probe' , type : 'record_change' ,
@@ -812,6 +834,9 @@ describe('hydration schema gate — real ObjectQL engine findOne count (#8482)',
812834 objectql . registry . registerObject ( plainObjectDef ( 'gate_plain' ) , 'test' , 'test' ) ;
813835 objectql . registry . registerObject ( auditObjectDef ( 'gate_plain_audit' ) , 'test' , 'test' ) ;
814836 await objectql . syncSchemas ( ) ;
837+ // A real `single` install's Default Organization: the system writes below
838+ // derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
839+ await installDefaultOrganization ( objectql ) ;
815840 automation . registerFlow (
816841 'gate_plain_audit_flow' ,
817842 afterUpdateAuditFlow ( 'gate_plain_audit_flow' , 'gate_plain' , 'gate_plain_audit' ) as any ,
@@ -848,6 +873,9 @@ describe('hydration schema gate — real ObjectQL engine findOne count (#8482)',
848873 objectql . registry . registerObject ( formulaObjectDef ( 'gate_calc' ) , 'test' , 'test' ) ;
849874 objectql . registry . registerObject ( auditObjectDef ( 'gate_calc_audit' ) , 'test' , 'test' ) ;
850875 await objectql . syncSchemas ( ) ;
876+ // A real `single` install's Default Organization: the system writes below
877+ // derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
878+ await installDefaultOrganization ( objectql ) ;
851879 automation . registerFlow (
852880 'gate_calc_audit_flow' ,
853881 afterUpdateAuditFlow ( 'gate_calc_audit_flow' , 'gate_calc' , 'gate_calc_audit' ) as any ,
0 commit comments