Skip to content

Commit a0dbaa9

Browse files
committed
wip(runtime): lean fixture engines hold a Default Organization
Claude-Session: https://claude.ai/code/session_018EszgtA3V2KXBX5tf59Hi4 Co-authored-by: Claude <noreply@anthropic.com>
1 parent 0c5b9ee commit a0dbaa9

15 files changed

Lines changed: 101 additions & 0 deletions

‎packages/runtime/src/analytics-cube-measure-field-type-door.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { SqlDriver } from '@objectstack/driver-sql';
3131
import { AnalyticsServicePlugin } from '@objectstack/service-analytics';
3232

3333
import { createDispatcherPlugin } from './dispatcher-plugin.js';
34+
import { installDefaultOrganization } from './default-organization.testkit.js';
3435

3536
const OBJECT = 'os21044_route_ledger';
3637

@@ -152,6 +153,9 @@ for (const cell of CELLS) {
152153
await engine.init();
153154
engine.registry.registerObject(LEDGER as any);
154155
await engine.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(engine);
155159
for (const row of ROWS) await engine.insert(OBJECT, { ...row } as any);
156160

157161
for (const [face, caps] of [

‎packages/runtime/src/analytics-json-dimension-door.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import { AnalyticsServicePlugin, type AnalyticsService } from '@objectstack/serv
4747
import { DatasetSchema } from '@objectstack/spec/ui';
4848

4949
import { createDispatcherPlugin } from './dispatcher-plugin.js';
50+
import { installDefaultOrganization } from './default-organization.testkit.js';
5051

5152
// [#21061] The analytics domain refuses an anonymous caller first (ADR-0056 D2),
5253
// so this harness signs its caller in: an `auth` slot in the shape
@@ -167,6 +168,9 @@ for (const cell of CELLS) {
167168
await engine.init();
168169
engine.registry.registerObject(LEDGER as any);
169170
await engine.syncSchemas();
171+
// A real `single` install's Default Organization: the system writes below
172+
// derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
173+
await installDefaultOrganization(engine);
170174
for (const row of ROWS) await engine.insert(OBJECT, { ...row } as any);
171175

172176
// Count what reaches the engine for THIS object, on both bridges.

‎packages/runtime/src/analytics-query-window-validity.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import { SqlDriver } from '@objectstack/driver-sql';
4242
import { AnalyticsServicePlugin, type AnalyticsService } from '@objectstack/service-analytics';
4343

4444
import { createDispatcherPlugin } from './dispatcher-plugin.js';
45+
import { installDefaultOrganization } from './default-organization.testkit.js';
4546

4647
// [#21061] The analytics domain refuses an anonymous caller first (ADR-0056 D2),
4748
// so this harness signs its caller in: an `auth` slot in the shape
@@ -159,6 +160,9 @@ for (const cell of CELLS) {
159160
await engine.init();
160161
engine.registry.registerObject(DEAL as any);
161162
await engine.syncSchemas();
163+
// A real `single` install's Default Organization: the system writes below
164+
// derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
165+
await installDefaultOrganization(engine);
162166
for (const row of ROWS) await engine.insert(OBJECT, { ...row } as any);
163167

164168
// Count what reaches the engine for THIS object, on both bridges.
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/runtime',
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/runtime/src/dispatcher-unique-violation-wire-code.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { SysMetadataActivation } from '@objectstack/platform-objects/system';
4545
import { HttpDispatcher } from './http-dispatcher.js';
4646
import type { HttpProtocolContext } from './http-dispatcher.js';
4747
import { bindTestSecurityCatalog } from './security/security-catalog.testkit.js';
48+
import { installDefaultOrganization } from './default-organization.testkit.js';
4849

4950
const PREFIX = '/api/v1';
5051
/** `registry.registerObject` requires a package id (see the sibling real-stack tests). */
@@ -116,6 +117,9 @@ async function bootEngine(objects: readonly object[]): Promise<ObjectQL> {
116117
await engine.init();
117118
for (const o of objects) engine.registry.registerObject(o as any, TEST_PACKAGE_ID);
118119
await engine.syncSchemas();
120+
// A real `single` install's Default Organization: the system writes below
121+
// derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
122+
await installDefaultOrganization(engine);
119123
return engine;
120124
}
121125

‎packages/runtime/src/domains/data-conflict-caller-visibility.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import { RestServer } from '@objectstack/rest';
5151
import { declaredEnvelopeForThrow } from '@objectstack/plugin-hono-server';
5252
import { resolveThrownHttpError } from '@objectstack/types';
5353
import { HttpDispatcher } from '../http-dispatcher.js';
54+
import { installDefaultOrganization } from '../default-organization.testkit.js';
5455

5556
const PREFIX = '/api/v1';
5657
const DATA = `${PREFIX}/data`;
@@ -228,6 +229,9 @@ describe('[#23586] a 409 CONCURRENT_UPDATE reports only what the caller may read
228229
],
229230
} as never);
230231
await engine.syncSchemas();
232+
// A real `single` install's Default Organization: the system writes below
233+
// derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
234+
await installDefaultOrganization(engine);
231235

232236
const services: Record<string, unknown> = {
233237
manifest: { register: vi.fn() },

‎packages/runtime/src/domains/data-delete-expected-version.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import { ObjectStackProtocolImplementation } from '@objectstack/metadata-protoco
5050
import { RestServer, repeatedQueryParamMessage } from '@objectstack/rest';
5151
import { resolveThrownHttpError } from '@objectstack/types';
5252
import { HttpDispatcher } from '../http-dispatcher.js';
53+
import { installDefaultOrganization } from '../default-organization.testkit.js';
5354

5455
const PREFIX = '/api/v1';
5556
const DATA = `${PREFIX}/data`;
@@ -90,6 +91,9 @@ async function bootStore() {
9091
await engine.init();
9192
engine.registry.registerObject(TASK as any, TEST_PACKAGE_ID);
9293
await engine.syncSchemas();
94+
// A real `single` install's Default Organization: the system writes below
95+
// derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
96+
await installDefaultOrganization(engine);
9397
const protocol = new ObjectStackProtocolImplementation(engine as any);
9498
await protocol.createData({ object: 'task', data: { id: 'r1', name: 'first' } } as any);
9599
const row: any = await engine.findOne('task', { where: { id: 'r1' } });

‎packages/runtime/src/domains/data-update-expected-version.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import { ObjectStackProtocolImplementation } from '@objectstack/metadata-protoco
5252
import { RestServer } from '@objectstack/rest';
5353
import { resolveThrownHttpError } from '@objectstack/types';
5454
import { HttpDispatcher } from '../http-dispatcher.js';
55+
import { installDefaultOrganization } from '../default-organization.testkit.js';
5556

5657
const PREFIX = '/api/v1';
5758
const DATA = `${PREFIX}/data`;
@@ -96,6 +97,9 @@ async function bootStore() {
9697
await engine.init();
9798
engine.registry.registerObject(TASK as any, TEST_PACKAGE_ID);
9899
await engine.syncSchemas();
100+
// A real `single` install's Default Organization: the system writes below
101+
// derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
102+
await installDefaultOrganization(engine);
99103
const protocol = new ObjectStackProtocolImplementation(engine as any);
100104
await protocol.createData({ object: 'task', data: { id: 'r1', name: BEFORE } } as any);
101105
const row: any = await engine.findOne('task', { where: { id: 'r1' } });

‎packages/runtime/src/domains/data-write-request-gate.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ import { ObjectStackProtocolImplementation } from '@objectstack/metadata-protoco
8282
import { RestServer } from '@objectstack/rest';
8383
import { resolveThrownHttpError } from '@objectstack/types';
8484
import { HttpDispatcher } from '../http-dispatcher.js';
85+
import { installDefaultOrganization } from '../default-organization.testkit.js';
8586

8687
const PREFIX = '/api/v1';
8788
const DATA = `${PREFIX}/data`;
@@ -136,6 +137,9 @@ async function bootStore() {
136137
await engine.init();
137138
for (const object of OBJECTS) engine.registry.registerObject(object as any, TEST_PACKAGE_ID);
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
const protocol = new ObjectStackProtocolImplementation(engine as any);
140144
for (const object of OBJECTS) {
141145
await protocol.createData({ object: object.name, data: { id: 'r1', name: BEFORE } } as any);

‎packages/runtime/src/domains/share-links-internal-hash-probe.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { HttpDispatcher } from '../http-dispatcher.js';
3232
import type { DomainHandlerDeps } from '../domain-handler-registry.js';
3333
import type { HttpProtocolContext } from '../http-dispatcher.js';
3434
import { handleShareLinksRequest } from './share-links.js';
35+
import { installDefaultOrganization } from '../default-organization.testkit.js';
3536

3637
const SHARED = 'pin_doc';
3738
/** The system context, erased once here; the options bags that carry it stay typed. */
@@ -89,6 +90,9 @@ async function harness() {
8990
await engine.init();
9091
for (const o of [SysShareLink, TARGET]) engine.registry.registerObject(o as any, '@objectstack/runtime-test');
9192
await engine.syncSchemas();
93+
// A real `single` install's Default Organization: the system writes below
94+
// derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
95+
await installDefaultOrganization(engine);
9296
await engine.insert(SHARED, { id: RECORD, title: 'Shared doc' }, { context: { isSystem: true } } as any);
9397
const svc = new ShareLinkService({ engine: engine as any });
9498
const deps = makeDeps(engine, svc);

0 commit comments

Comments
 (0)