Skip to content

Commit f1111e1

Browse files
committed
wip(service-automation): fixtures hold a Default Organization, or model a pre-18 store
Claude-Session: https://claude.ai/code/session_018EszgtA3V2KXBX5tf59Hi4 Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3832d75 commit f1111e1

14 files changed

Lines changed: 116 additions & 2 deletions

‎packages/services/service-automation/src/builtin/get-record-id-projection.integration.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { SqlDriver } from '@objectstack/driver-sql';
3838
import { AutomationServicePlugin } from '../plugin.js';
3939
import { AutomationEngine } from '../engine.js';
4040
import { registerCrudNodes } from './crud-nodes.js';
41+
import { installDefaultOrganization } from '../default-organization.testkit.js';
4142

4243
const SYS = { isSystem: true } as const;
4344

@@ -80,6 +81,9 @@ describe('get_record answers the row id as output.id whatever its fields project
8081
ql.registerDriver(driver, true);
8182
ql.registry.registerObject(OBJECT as any, 'pin-get-record-id', 'pin-get-record-id');
8283
await ql.syncSchemas();
84+
// A real `single` install's Default Organization: the system writes below
85+
// derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
86+
await installDefaultOrganization(ql);
8387

8488
const row: any = await ql.insert(OBJECT.name, { title: 'alpha', status: 'open' }, { context: SYS });
8589
rowId = row.id;

‎packages/services/service-automation/src/builtin/get-record-stored-metadata-family.integration.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import { hashSpec } from '@objectstack/metadata-core';
4848
import { ObjectStackProtocolImplementation } from '@objectstack/metadata-protocol';
4949
import { AutomationServicePlugin } from '../plugin.js';
5050
import type { AutomationEngine } from '../engine.js';
51+
import { installDefaultOrganization } from '../default-organization.testkit.js';
5152

5253
const SYS = { isSystem: true } as const;
5354
const KEYED = /^hmac-sha256:[0-9a-f]{64}$/;
@@ -148,6 +149,9 @@ describe('flow get_record serves the stored-metadata family the way the data doo
148149
ql.registerDriver(driver, true);
149150
ql.registry.registerObject(COPY_OBJECT as any, 'pin-21519', 'pin-21519');
150151
await ql.syncSchemas();
152+
// A real `single` install's Default Organization: the system writes below
153+
// derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
154+
await installDefaultOrganization(ql);
151155

152156
const metadata = JSON.stringify(DS_BODY);
153157
await ql.insert('sys_metadata', {

‎packages/services/service-automation/src/builtin/get-record-stored-metadata-filter-refusal.integration.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import { hashSpec } from '@objectstack/metadata-core';
4848
import { ObjectStackProtocolImplementation } from '@objectstack/metadata-protocol';
4949
import { AutomationServicePlugin } from '../plugin.js';
5050
import type { AutomationEngine, NodeExecutor } from '../engine.js';
51+
import { installDefaultOrganization } from '../default-organization.testkit.js';
5152

5253
const SYS = { isSystem: true } as const;
5354
const KEYED = /^hmac-sha256:[0-9a-f]{64}$/;
@@ -152,6 +153,9 @@ describe("flow get_record refuses a filter that evaluates the stored-metadata fa
152153
ql.registerDriver(driver, true);
153154
ql.registry.registerObject(COPY_OBJECT as any, 'pin-21623', 'pin-21623');
154155
await ql.syncSchemas();
156+
// A real `single` install's Default Organization: the system writes below
157+
// derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
158+
await installDefaultOrganization(ql);
155159

156160
const metadata = JSON.stringify(DS_BODY);
157161
await ql.insert('sys_metadata', {

‎packages/services/service-automation/src/builtin/notify-zero-delivery-visibility.integration.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ import type { FlowRunSummary } from '@objectstack/spec/automation';
116116
import { AutomationEngine } from '../engine.js';
117117
import { registerNotifyNode } from './notify-node.js';
118118
import { formatRunSummaryLine } from '../run-summary.js';
119+
import { installDefaultOrganization } from '../default-organization.testkit.js';
119120

120121
/** The employer organization whose admin members are the intended recipients. */
121122
const ORG_EMPLOYER = 'org_employer_alpha';
@@ -299,6 +300,9 @@ async function boot(kind: DriverKind) {
299300
const PKG = '@objectstack/service-messaging';
300301
for (const o of FIXTURES) ql.registry.registerObject(o as any, PKG, PKG);
301302
await ql.syncSchemas();
303+
// A real `single` install's Default Organization: the system writes below
304+
// derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
305+
await installDefaultOrganization(ql);
302306
data = ql as unknown as IDataEngine;
303307
} else {
304308
data = inProcessEngine();

‎packages/services/service-automation/src/connector-pull.integration.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { AutomationServicePlugin } from './plugin.js';
3434
import type { EngineQueryOptions } from '@objectstack/spec/data';
3535
import type { IAutomationService } from '@objectstack/spec/contracts';
3636
import type { ConnectorPullProtocol } from './connector-pull.js';
37+
import { installDefaultOrganization } from './default-organization.testkit.js';
3738

3839
const CONTACT = {
3940
name: 'contact',
@@ -147,6 +148,9 @@ describe('[#20919] connector pull, end to end through a real rest connector', ()
147148
await ql.init();
148149
ql.registry.registerObject(CONTACT as any);
149150
await ql.syncSchemas();
151+
// A real `single` install's Default Organization: the system writes below
152+
// derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
153+
await installDefaultOrganization(ql);
150154

151155
const automation = new AutomationServicePlugin({ suspendedRunStore: 'memory' });
152156
kernel = new LiteKernel({ logger: { level: 'silent' } } as never);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* Give a lean test engine what every real `single` install has: an
5+
* organization object holding its Default Organization.
6+
*
7+
* ADR-0131 D1: a table the SQL driver creates carries its tenant column NOT
8+
* NULL. The engine stamps an organization-less system write with the derived
9+
* organization under `single` (D9) — but only where the composition registers
10+
* the organization object; a bare `ObjectQL` + `SqlDriver` registers none, so
11+
* the write reaches the database with no organization and is refused there.
12+
* A suite whose subject is not tenancy (claims, acks, idle cost, at-rest
13+
* shapes) calls this once its own objects are registered, so its system
14+
* writes land the way they do on a real install.
15+
*
16+
* The object mirrors the platform's: managed by better-auth, so it carries no
17+
* tenant column of its own.
18+
*/
19+
export const DEFAULT_ORGANIZATION_ID = 'org_default';
20+
21+
export async function installDefaultOrganization(engine: {
22+
registry: { registerObject(def: unknown, owner: string): unknown };
23+
getSchema(object: string): unknown;
24+
syncSchemas(): Promise<unknown>;
25+
getDriverForObject(object: string):
26+
| {
27+
create(object: string, data: Record<string, unknown>): Promise<unknown>;
28+
findOne(object: string, query: unknown): Promise<unknown>;
29+
}
30+
| undefined;
31+
}): Promise<void> {
32+
// Idempotent: a suite that syncs one engine more than once may call it each time.
33+
if (!engine.getSchema('sys_organization')) {
34+
engine.registry.registerObject(
35+
{ name: 'sys_organization', label: 'Organization', managedBy: 'better-auth', fields: { name: { type: 'text', label: 'Name' } } },
36+
'@objectstack/service-automation',
37+
);
38+
}
39+
await engine.syncSchemas();
40+
// Seeded through the driver: the organization is data at rest, not a write
41+
// the suite under test should observe (an audit or activity mirror would).
42+
const driver = engine.getDriverForObject('sys_organization')!;
43+
if (await driver.findOne('sys_organization', { where: { id: DEFAULT_ORGANIZATION_ID } })) return;
44+
await driver.create('sys_organization', { id: DEFAULT_ORGANIZATION_ID, name: 'Default' });
45+
}

‎packages/services/service-automation/src/flow-field-expression-scale.integration.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import { SqlDriver } from '@objectstack/driver-sql';
4444
import { AutomationServicePlugin } from './plugin.js';
4545
import type { AutomationEngine } from './engine.js';
4646
import { VALUE_SLOT_TEMPLATE_REFUSAL } from '@objectstack/spec/automation';
47+
import { installDefaultOrganization } from './default-organization.testkit.js';
4748

4849
function makeSqliteDriver() {
4950
return new SqlDriver({
@@ -114,6 +115,9 @@ describe('flow-computed money lands within its declared scale (#11060, oracle fo
114115
ql.registerDriver(driver, true);
115116
ql.registry.registerObject(quote as any, 'scale-test', 'scale-test');
116117
await ql.syncSchemas();
118+
// A real `single` install's Default Organization: the system writes below
119+
// derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
120+
await installDefaultOrganization(ql);
117121
}
118122

119123
const quoteByTitle = (title: string) =>

‎packages/services/service-automation/src/flow-metadata-save-arming.integration.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { SqlDriver } from '@objectstack/driver-sql';
3636
import type { AutomationContext } from '@objectstack/spec/contracts';
3737
import { AutomationServicePlugin } from './plugin.js';
3838
import type { AutomationEngine, FlowTrigger, FlowTriggerBinding } from './engine.js';
39+
import { installDefaultOrganization } from './default-organization.testkit.js';
3940

4041
/** The saved surface these tests drive: `ObjectStackProtocolImplementation`'s write doors. */
4142
interface MetadataWriteDoors {
@@ -133,6 +134,9 @@ describe('a flow saved through the metadata API is armed on the running engine (
133134
'qa-21725',
134135
);
135136
await ql.syncSchemas();
137+
// A real `single` install's Default Organization: the system writes below
138+
// derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
139+
await installDefaultOrganization(ql);
136140

137141
const rec = objectqlRecordTrigger(ql);
138142
automation.registerTrigger(rec.trigger);

‎packages/services/service-automation/src/paused-run-visibility.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ import { AutomationEngine } from './engine.js';
8080
import type { RunRecord, SuspendedRun, SuspendedRunStore } from './engine.js';
8181
import { InMemorySuspendedRunStore } from './suspended-run-store.js';
8282
import { AutomationServicePlugin } from './plugin.js';
83+
import { installDefaultOrganization } from './default-organization.testkit.js';
8384

8485
const silent = { info() {}, warn() {}, error() {}, debug() {}, child() { return silent; } } as never;
8586
const flush = () => new Promise<void>((r) => setTimeout(r, 0));
@@ -547,6 +548,9 @@ describe('#8050 cold boot over the same sqlite file (full stack)', () => {
547548
(ql as any).registry.registerObject(o.def as never, o.owner);
548549
}
549550
await ql.syncSchemas();
551+
// A real `single` install's Default Organization: the system writes below
552+
// derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
553+
await installDefaultOrganization(ql);
550554

551555
const automation = kernel.getService<AutomationEngine>('automation');
552556
automation.registerNodeExecutor(holdExecutor);

‎packages/services/service-automation/src/resume-gone-suspension-settle.test.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import type { RunRecord, SuspendedRun, SuspendedRunStore, SuspensionClaimOutcome
5353
import { InMemorySuspendedRunStore } from './suspended-run-store.js';
5454
import { AutomationServicePlugin } from './plugin.js';
5555
import { SysAutomationRun } from './sys-automation-run.object.js';
56+
import { installDefaultOrganization } from './default-organization.testkit.js';
5657

5758
const silent = { info() {}, warn() {}, error() {}, debug() {}, child() { return silent; } } as never;
5859
const SYSTEM = { isSystem: true } as never;
@@ -125,6 +126,9 @@ describe('a gone-for-good resume settles the run row (full stack, sqlite file)',
125126
await driver.connect();
126127
ql.registerDriver(driver, true);
127128
await ql.syncSchemas();
129+
// A real `single` install's Default Organization: the system writes below
130+
// derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
131+
await installDefaultOrganization(ql);
128132

129133
const automation = kernel.getService<AutomationEngine>('automation');
130134
return { kernel, ql, automation };
@@ -435,7 +439,11 @@ describe('the boot re-arm runs before a late-bound flow arrives (plugin boot ord
435439
} as never);
436440
await kernel.use(new AutomationServicePlugin());
437441
await kernel.bootstrap();
438-
return { kernel, ql: kernel.getService<ObjectQL>('objectql'), automation: kernel.getService<AutomationEngine>('automation') };
442+
const ql = kernel.getService<ObjectQL>('objectql');
443+
// A real `single` install's Default Organization: the run rows below
444+
// derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
445+
await installDefaultOrganization(ql);
446+
return { kernel, ql, automation: kernel.getService<AutomationEngine>('automation') };
439447
}
440448

441449
it('the re-armed resume finds the flow not bound yet, and the run stays parked and resumes once the boot completes', async () => {

0 commit comments

Comments
 (0)