Skip to content

Commit 6a38035

Browse files
committed
wip(plugin-approvals): 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 da20f30 commit 6a38035

30 files changed

Lines changed: 218 additions & 0 deletions

‎packages/plugins/plugin-approvals/src/action-page-member.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 { ApprovalsServicePlugin } from './approvals-plugin.js';
3737
import type { ApprovalService } from './approval-service.js';
3838
import { renderResultPage } from './action-link-pages.js';
39+
import { installDefaultOrganization } from './default-organization.testkit.js';
3940

4041
const SYSTEM = { isSystem: true, positions: [], permissions: [] } as any;
4142
const SUBMITTER = { userId: 'u_submitter', positions: [], permissions: [] } as any;
@@ -128,6 +129,9 @@ async function bootStack(options: { rawApp: boolean }) {
128129
(objectql as any).registerDriver(driver, true);
129130
objectql.registry.registerObject(leaveRequest as any, 'approvals-test', 'approvals-test');
130131
await (objectql as any).syncSchemas();
132+
// A real `single` install's Default Organization: the system writes below
133+
// derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
134+
await installDefaultOrganization(objectql as any);
131135

132136
const svc = kernel.getService<ApprovalService>('approvals');
133137
let n = 0;

‎packages/plugins/plugin-approvals/src/action-slot-backfill.integration.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { SysApprovalRequest } from './sys-approval-request.object.js';
3636
import { SysApprovalAction } from './sys-approval-action.object.js';
3737
import { SysApprovalApprover } from './sys-approval-approver.object.js';
3838
import { SysApprovalDelegation } from './sys-approval-delegation.object.js';
39+
import { installDefaultOrganization } from './default-organization.testkit.js';
3940

4041
const SYSTEM = { isSystem: true, positions: [], permissions: [] } as any;
4142
const SUBMITTER = { userId: 'u_submitter', positions: [], permissions: [] } as any;
@@ -85,6 +86,9 @@ describe('the boot-time action-slot backfill (#21411)', () => {
8586
// Real DDL — including the `acted_as` column, so a write of it the schema
8687
// does not carry fails here rather than passing against a permissive fake.
8788
await engine.syncSchemas();
89+
// A real `single` install's Default Organization: the system writes below
90+
// derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
91+
await installDefaultOrganization(engine);
8892
svc = new ApprovalService({ engine: engine as any, logger: { warn: () => {} } as any });
8993
await engine.insert('crm_deal', { id: 'D1', title: 'Deal' }, { context: SYSTEM } as any);
9094
});

‎packages/plugins/plugin-approvals/src/actor-lookups-hold-ids.integration.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import { APPROVAL_REVISE_NODE_TYPE } from '@objectstack/spec/automation';
4646
import type { EngineQueryOptions } from '@objectstack/spec/data';
4747
import { ApprovalService } from './approval-service.js';
4848
import { ApprovalsServicePlugin } from './approvals-plugin.js';
49+
import { installDefaultOrganization } from './default-organization.testkit.js';
4950

5051
const SYSTEM = { isSystem: true, positions: [], permissions: [] } as any;
5152
const asUser = (userId: string, positions: string[] = []) =>
@@ -156,6 +157,9 @@ describe('ADR-0118 D1 — every sys_user lookup approvals writes holds an id or
156157
engine.registry.registerObject(def as any, 'approvals-test', 'approvals-test');
157158
}
158159
await engine.syncSchemas();
160+
// A real `single` install's Default Organization: the system writes below
161+
// derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
162+
await installDefaultOrganization(engine);
159163
for (const u of USERS) await engine.insert('sys_user', u, { context: SYSTEM } as any);
160164

161165
svc = new ApprovalService({

‎packages/plugins/plugin-approvals/src/admin-rescue-named-slate.integration.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { SqlDriver } from '@objectstack/driver-sql';
4545
import { bindSecurityCatalogReader, type SecurityCatalogEntry, type SecurityCatalogReader } from '@objectstack/core';
4646
import { ApprovalService } from './approval-service.js';
4747
import { ApprovalsServicePlugin } from './approvals-plugin.js';
48+
import { relaxEveryRegisteredTenantColumn } from './pre-18-tenant-column.testkit.js';
4849

4950
const SYSTEM = { isSystem: true, positions: [], permissions: [] } as any;
5051

@@ -185,6 +186,10 @@ describe('an empty admin_rescue slate opens on the organization\'s administrator
185186
];
186187
for (const def of defs) engine.registry.registerObject(def as any, 'approvals-test', 'approvals-test');
187188
await engine.syncSchemas();
189+
// The organization-less rows below (positions, holdings) exist only on a
190+
// store built before 18.x (ADR-0131 D1 makes a fresh tenant column NOT
191+
// NULL): this is that store.
192+
await relaxEveryRegisteredTenantColumn(engine);
188193
bindSecurityCatalogReader(engine, catalogServing([
189194
'organization_admin', 'organization_admin_no_bypass', 'admin_full_access',
190195
]));

‎packages/plugins/plugin-approvals/src/approval-list-display-labels.integration.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import { ApprovalService } from './approval-service.js';
5454
import { ApprovalsServicePlugin } from './approvals-plugin.js';
5555
import { SysApprovalRequest } from './sys-approval-request.object.js';
5656
import { SysApprovalAction } from './sys-approval-action.object.js';
57+
import { installDefaultOrganization } from './default-organization.testkit.js';
5758

5859
const SYSTEM = { isSystem: true, positions: [], permissions: [] } as any;
5960
const asUser = (userId: string, positions: string[] = []) =>
@@ -136,6 +137,9 @@ describe('#23889 — the approval lists read engine-written display columns', ()
136137
engine.registry.registerObject(def as any, 'approvals-test', 'approvals-test');
137138
}
138139
await engine.syncSchemas();
140+
// A real `single` install's Default Organization: the system writes below
141+
// derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
142+
await installDefaultOrganization(engine);
139143
for (const u of USERS) await engine.insert('sys_user', u, { context: SYSTEM } as any);
140144

141145
svc = new ApprovalService({

‎packages/plugins/plugin-approvals/src/approval-notification-body.integration.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ import { SqlDriver } from '@objectstack/driver-sql';
7676
import { APPROVAL_REVISE_NODE_TYPE } from '@objectstack/spec/automation';
7777
import { ApprovalService } from './approval-service.js';
7878
import { ApprovalsServicePlugin } from './approvals-plugin.js';
79+
import { relaxEveryRegisteredTenantColumn } from './pre-18-tenant-column.testkit.js';
7980

8081
const SYSTEM = { isSystem: true, positions: [], permissions: [] } as any;
8182
const asUser = (userId: string, positions: string[] = []) =>
@@ -211,6 +212,10 @@ describe('every approval notification carries its text in body', () => {
211212
engine.registry.registerObject(def as any, 'approvals-test', 'approvals-test');
212213
}
213214
await engine.syncSchemas();
215+
// The organization-less rows below (positions, holdings) exist only on a
216+
// store built before 18.x (ADR-0131 D1 makes a fresh tenant column NOT
217+
// NULL): this is that store.
218+
await relaxEveryRegisteredTenantColumn(engine);
214219
for (const u of USERS) await engine.insert('sys_user', u, { context: SYSTEM } as any);
215220

216221
svc = new ApprovalService({

‎packages/plugins/plugin-approvals/src/approval-requested-notification.integration.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import { ObjectQL } from '@objectstack/objectql';
4747
import { SqlDriver } from '@objectstack/driver-sql';
4848
import { ApprovalService } from './approval-service.js';
4949
import { ApprovalsServicePlugin } from './approvals-plugin.js';
50+
import { installDefaultOrganization } from './default-organization.testkit.js';
5051

5152
const SYSTEM = { isSystem: true, positions: [], permissions: [] } as any;
5253
const asUser = (userId: string) => ({ userId, positions: [], permissions: [] }) as any;
@@ -161,6 +162,9 @@ describe('opening an approval step tells each resolved approver, once (approval.
161162
engine.registry.registerObject(def as any, 'approvals-test', 'approvals-test');
162163
}
163164
await engine.syncSchemas();
165+
// A real `single` install's Default Organization: the system writes below
166+
// derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
167+
await installDefaultOrganization(engine);
164168
for (const u of USERS) await engine.insert('sys_user', u, { context: SYSTEM } as any);
165169
// `legal` is staffed by two people; `treasury` by nobody.
166170
for (const [id, user] of [['up_1', 'u_carol'], ['up_2', 'u_dan']]) {

‎packages/plugins/plugin-approvals/src/approval-token-internal-hash.integration.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { SysApprovalAction } from './sys-approval-action.object.js';
2222
import { SysApprovalApprover } from './sys-approval-approver.object.js';
2323
import { SysApprovalDelegation } from './sys-approval-delegation.object.js';
2424
import { SysApprovalToken } from './sys-approval-token.object.js';
25+
import { installDefaultOrganization } from './default-organization.testkit.js';
2526

2627
const SYSTEM = { isSystem: true, positions: [], permissions: [] } as any;
2728
const SUBMITTER = { userId: 'submitter', positions: [], permissions: [] } as any;
@@ -51,6 +52,9 @@ describe('[#21197] the approval token digest is internal, and the actionable lin
5152
engine.registry.registerObject(def as any, 'approvals-test', 'approvals-test');
5253
}
5354
await engine.syncSchemas();
55+
// A real `single` install's Default Organization: the system writes below
56+
// derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
57+
await installDefaultOrganization(engine);
5458
svc = new ApprovalService({
5559
engine: engine as any,
5660
automation: {
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/plugin-approvals',
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/plugins/plugin-approvals/src/display-label-backfill.integration.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import { SysApprovalRequest } from './sys-approval-request.object.js';
4747
import { SysApprovalAction } from './sys-approval-action.object.js';
4848
import { SysApprovalApprover } from './sys-approval-approver.object.js';
4949
import { SysApprovalDelegation } from './sys-approval-delegation.object.js';
50+
import { installDefaultOrganization } from './default-organization.testkit.js';
5051

5152
const SYSTEM = { isSystem: true, positions: [], permissions: [] } as any;
5253
const STAMP = '2026-09-01T09:00:00.000Z';
@@ -128,6 +129,9 @@ describe('#23889 — the boot-time display-label backfill', () => {
128129
engine.registry.registerObject(def as any, 'approvals-test', 'approvals-test');
129130
}
130131
await engine.syncSchemas();
132+
// A real `single` install's Default Organization: the system writes below
133+
// derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
134+
await installDefaultOrganization(engine);
131135
for (const u of [
132136
{ id: 'u_sub', name: 'Sam Submitter', email: 'sam@example.com' },
133137
{ id: 'u_alice', name: 'Alice', email: 'alice@example.com' },

0 commit comments

Comments
 (0)