Skip to content

Commit 0e5e11c

Browse files
committed
wip(client,http-conformance,service-analytics): lean fixture engines hold a Default Organization
Claude-Session: https://claude.ai/code/session_018EszgtA3V2KXBX5tf59Hi4 Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6a38035 commit 0e5e11c

30 files changed

Lines changed: 251 additions & 1 deletion

‎packages/client/src/client.batch-transaction.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { createRestApiPlugin } from '@objectstack/runtime';
3535
import { ObjectStackClient } from './index';
3636
import type { IHttpServer } from '@objectstack/spec/contracts';
3737
import type { ServiceObject } from '@objectstack/spec/data';
38+
import { installDefaultOrganization } from './default-organization.testkit.js';
3839

3940
/**
4041
* ⚠️ [#18070] The authz objects every authenticated request in this file
@@ -210,6 +211,9 @@ describe('data.batchTransaction (live Hono, #1604)', () => {
210211
ql.registerObject(o.def, o.owner);
211212
await ql.syncObjectSchema(o.def.name);
212213
}
214+
// A real `single` install's Default Organization: the writes below derive
215+
// it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
216+
await installDefaultOrganization(ql);
213217

214218
const httpServer = kernel.getService<IHttpServer>('http.server');
215219
baseUrl = `http://localhost:${httpServer.getPort!()}`;

‎packages/client/src/client.hono.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { createRestApiPlugin } from '@objectstack/runtime';
77
import { ObjectStackClient } from './index';
88
import type { IHttpServer } from '@objectstack/spec/contracts';
99
import type { ServiceObject } from '@objectstack/spec/data';
10+
import { installDefaultOrganization } from './default-organization.testkit.js';
1011

1112
/**
1213
* ⚠️ [#18070] The authz objects every authenticated request in this file
@@ -233,6 +234,9 @@ describe('ObjectStackClient (with Hono Server)', () => {
233234
ql.registerObject(o.def, o.owner);
234235
await ql.syncObjectSchema(o.def.name);
235236
}
237+
// A real `single` install's Default Organization: the writes below derive
238+
// it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
239+
await installDefaultOrganization(ql);
236240

237241
// 5. Get Port from Service
238242
const httpServer = kernel.getService<IHttpServer>('http.server');
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/client',
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/qa/http-conformance/src/conformance.integration.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { HonoServerPlugin } from '@objectstack/plugin-hono-server';
2323
import { createDispatcherPlugin, createRestApiPlugin } from '@objectstack/runtime';
2424
import { NodeServerPlugin } from './node-plugin.js';
2525
import type { IHttpServer } from '@objectstack/spec/contracts';
26+
import { installDefaultOrganization } from './default-organization.testkit.js';
2627

2728
type AdapterCase = {
2829
label: 'node' | 'hono';
@@ -174,6 +175,9 @@ async function bootStack(makePlugin: () => any, opts: { withAnalytics?: boolean
174175
// a 404 OBJECT_NOT_FOUND — a routing-shaped symptom for a DDL-shaped cause.
175176
await ql.syncObjectSchema('task');
176177
for (const o of authzResolverObjects) ql.registry.registerObject(o.def as never, o.owner);
178+
// A real `single` install's Default Organization: the writes below derive
179+
// it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
180+
await installDefaultOrganization(ql);
177181

178182
const httpServer = kernel.getService<IHttpServer>('http.server');
179183
return { kernel, base: `http://127.0.0.1:${httpServer.getPort!()}` };
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/http-conformance',
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/qa/http-conformance/src/hono-approvals-act.conformance.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { ApprovalsServicePlugin } from '@objectstack/plugin-approvals';
4040
import type { ApprovalService } from '@objectstack/plugin-approvals';
4141
import { createHonoApp } from '@objectstack/hono';
4242
import type { IHttpServer } from '@objectstack/spec/contracts';
43+
import { installDefaultOrganization } from './default-organization.testkit.js';
4344

4445
const PREFIX = '/api/v1';
4546
const ACT_PATH = `${PREFIX}/approvals/act`;
@@ -103,6 +104,9 @@ async function bootKernel(opts: { selfHosted: boolean; approvals?: boolean }) {
103104
(objectql as any).registerDriver(driver, true);
104105
objectql.registry.registerObject(leaveRequest as any, 'approvals-act-test', 'approvals-act-test');
105106
await (objectql as any).syncSchemas();
107+
// A real `single` install's Default Organization: the writes below derive
108+
// it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
109+
await installDefaultOrganization(objectql as any);
106110

107111
let n = 0;
108112
/** A pending request with live action tokens for {@link APPROVER}. */

‎packages/qa/http-conformance/src/hono-body-refusal.conformance.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { SqliteWasmDriver } from '@objectstack/driver-sqlite-wasm';
4040
import { HttpDispatcher } from '@objectstack/runtime';
4141
import { HonoHttpServer } from '@objectstack/plugin-hono-server';
4242
import { createHonoApp } from '@objectstack/hono';
43+
import { installDefaultOrganization } from './default-organization.testkit.js';
4344

4445
const PREFIX = '/api/v1';
4546
const MEMBER = { userId: 'u_member', isSystem: false, systemPermissions: [] as string[] };
@@ -85,6 +86,9 @@ async function boot(auth?: Record<string, unknown>) {
8586
const ql = kernel.getService<ObjectQL>('objectql');
8687
ql.registerObject(TASK as any);
8788
await ql.syncObjectSchema(TASK.name);
89+
// A real `single` install's Default Organization: the writes below derive
90+
// it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
91+
await installDefaultOrganization(ql as any);
8892

8993
vi.spyOn(HttpDispatcher.prototype as any, 'timedResolveExecutionContext')
9094
.mockImplementation(async () => ({ ...MEMBER }));

‎packages/qa/http-conformance/src/hono-declared-envelope.conformance.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ import type { ObjectQL } from '@objectstack/objectql';
8383
import { SqliteWasmDriver } from '@objectstack/driver-sqlite-wasm';
8484
import { HttpDispatcher } from '@objectstack/runtime';
8585
import { createHonoApp } from '@objectstack/hono';
86+
import { installDefaultOrganization } from './default-organization.testkit.js';
8687

8788
const PREFIX = '/api/v1';
8889
const MEMBER = { userId: 'u_member', isSystem: false, systemPermissions: [] as string[] };
@@ -172,6 +173,9 @@ async function boot(auth?: Record<string, unknown>) {
172173
ql.registerObject(object as any);
173174
await ql.syncObjectSchema(object.name);
174175
}
176+
// A real `single` install's Default Organization: the writes below derive
177+
// it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
178+
await installDefaultOrganization(ql as any);
175179

176180
vi.spyOn(HttpDispatcher.prototype as any, 'timedResolveExecutionContext')
177181
.mockImplementation(async () => ({ ...MEMBER }));

‎packages/services/service-analytics/src/__tests__/analytics-faces-one-lowering.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ import { NativeSQLStrategy } from '../strategies/native-sql-strategy.js';
7272
import { ObjectQLStrategy } from '../strategies/objectql-strategy.js';
7373
import { NO_DATETIME_COLUMNS, normalizeAnalyticsFilterTree, type NormalizedFilterNode } from '../strategies/filter-normalizer.js';
7474
import { compileScopedFilterToSql } from '../read-scope-sql.js';
75+
import { installDefaultOrganization } from './default-organization.testkit.js';
7576

7677
const HERE = dirname(fileURLToPath(import.meta.url));
7778
const SRC = resolve(HERE, '..');
@@ -378,6 +379,9 @@ for (const cell of DB_CELLS) {
378379
await engine.init();
379380
engine.registry.registerObject(LEDGER as never);
380381
await engine.syncSchemas();
382+
// A real `single` install's Default Organization: the system writes below
383+
// derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
384+
await installDefaultOrganization(engine);
381385
for (const row of ROWS) await engine.insert(OBJECT, { ...row } as never);
382386
const realExecute = (engine as any).execute.bind(engine);
383387
(engine as any).execute = (sql: string, opts?: { object?: string }) => {
@@ -588,6 +592,9 @@ describe('[#5930 step 4] the temporal conformance matrix answers on every analyt
588592
},
589593
} as never);
590594
await engine.syncSchemas();
595+
// A real `single` install's Default Organization: the system writes below
596+
// derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
597+
await installDefaultOrganization(engine);
591598
for (const r of TEMPORAL_ROWS) await engine.insert(TEMPORAL, { id: r.id, [COLUMN.at]: r.at, [COLUMN.on]: r.on } as never);
592599
faces = await composeFaces(engine, [temporalCube]);
593600
});

‎packages/services/service-analytics/src/__tests__/api-exposure-door.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { DatasetSchema } from '@objectstack/spec/ui';
4141
import type { ExecutionContext } from '@objectstack/spec/kernel';
4242
import { AnalyticsServicePlugin } from '../plugin.js';
4343
import { AnalyticsService } from '../analytics-service.js';
44+
import { installDefaultOrganization } from './default-organization.testkit.js';
4445

4546
const HIDDEN = 'exposure_hidden';
4647
const NO_LIST = 'exposure_nolist';
@@ -246,6 +247,9 @@ describe.each(STRATEGIES)('the analytics door honours the generic-exit declarati
246247
engine.registry.registerObject(obj as any);
247248
}
248249
await engine.syncSchemas();
250+
// A real `single` install's Default Organization: the system writes below
251+
// derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
252+
await installDefaultOrganization(engine);
249253
for (const [object, rows] of Object.entries(ROWS)) {
250254
for (const row of rows) await engine.insert(object, { ...row } as any);
251255
}

0 commit comments

Comments
 (0)