Skip to content

Commit 5ea48bb

Browse files
committed
test(driver-sqlite-wasm): open the tenant audit with the real posture knob, not the deleted memo (#5262)
Regression from this branch's own driver-sql change, caught by CI (Test Core 2/3): `SqliteWasmDriver extends SqlDriver`, and this suite's tenant-audit test switched multi-tenant mode on by poking the private `_multiTenantMode` memo: (driver as any)._multiTenantMode = true; That memo is gone — `isMultiTenantMode()` now resolves the tenancy posture live — so the poke silently stopped doing anything, the gate read single-org, no warning was emitted, and the assertion failed with "expected [] to have a length of 1 but got +0". Reproduced locally against the pre-fix test before changing it. Fixed the way the sibling driver-sql suite already was: set the real `OS_TENANCY_POSTURE=isolated` and restore it in a `finally`. This is strictly better than what it replaces — the old poke reached into an implementation detail, so it began lying the moment that detail changed, which is exactly how it failed. Driving the documented knob cannot go quietly stale that way. Also strengthened the neighbouring `bypassTenantAudit` case in the same block, which was VACUOUS: it never set a posture, so the audit returned at the multi-tenant gate and `warnSpy` was empty regardless of the flag under test — it would have passed with the flag deleted. (Vacuous before this branch too; it simply never poked the memo the way its sibling did.) It now sets the posture, so the flag is the only thing that can keep the log quiet; verified by deleting the flag and watching it go red. Repo-wide grep confirms no third package pokes `_multiTenantMode`; the only remaining mentions are this branch's own comments and the tombstone assertion in sql-driver-tenant-audit-posture.test.ts. Full suites (not just the touched file): driver-sqlite-wasm 16 files / 232 tests passed; driver-sql 63 files (59 passed, 4 skipped) / 740 passed + 44 skipped. typecheck Done for both; eslint clean. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015W6nhsDrz6zWQc8je12a1t
1 parent dda8af0 commit 5ea48bb

1 file changed

Lines changed: 45 additions & 14 deletions

File tree

packages/plugins/driver-sqlite-wasm/src/sqlite-wasm-driver-tenant-scope.test.ts

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -287,27 +287,58 @@ describe('SqliteWasmDriver tenant scope (organization_id)', () => {
287287
(driver as any).logger = { warn: (msg: string, meta: any) => warnSpy.push({ msg, meta }) };
288288
// The tenant-audit warning only fires in multi-tenant mode (single-tenant
289289
// stacks now always have an organization_id column but no isolation).
290-
(driver as any)._multiTenantMode = true;
291-
await driver.initObjects(objects);
292-
293-
await driver.create('account', { id: 'x1', organization_id: 'org_a', name: 'X1' });
294-
await driver.create('account', { id: 'x2', organization_id: 'org_a', name: 'X2' });
295-
// Second create on same object:op should NOT add another warn (throttle).
296-
expect(warnSpy.filter(w => w.meta?.op === 'create')).toHaveLength(1);
290+
//
291+
// [#5262] Configured through the real knob rather than by poking the old
292+
// `_multiTenantMode` memo, which no longer exists: `SqliteWasmDriver
293+
// extends SqlDriver`, and that memo froze a process-level fact into a
294+
// per-instance verdict, so the gate now resolves the tenancy posture live
295+
// on every call. Setting the env exercises the same resolution a real
296+
// deployment does — and unlike the old poke it cannot silently stop
297+
// meaning anything, because a wrong posture makes the assertion fail
298+
// rather than quietly disabling the branch under test. Restored in the
299+
// `finally` below. Mirrors the same fix in driver-sql's suite.
300+
const priorPosture = process.env.OS_TENANCY_POSTURE;
301+
process.env.OS_TENANCY_POSTURE = 'isolated';
302+
try {
303+
await driver.initObjects(objects);
304+
305+
await driver.create('account', { id: 'x1', organization_id: 'org_a', name: 'X1' });
306+
await driver.create('account', { id: 'x2', organization_id: 'org_a', name: 'X2' });
307+
// Second create on same object:op should NOT add another warn (throttle).
308+
expect(warnSpy.filter(w => w.meta?.op === 'create')).toHaveLength(1);
309+
} finally {
310+
if (priorPosture === undefined) delete process.env.OS_TENANCY_POSTURE;
311+
else process.env.OS_TENANCY_POSTURE = priorPosture;
312+
}
297313
});
298314

299315
it('does not warn when bypassTenantAudit is set', async () => {
300316
await driver.disconnect();
301317
const warnSpy: any[] = [];
302318
driver = new SqliteWasmDriver({ filename: ':memory:' });
303319
(driver as any).logger = { warn: (msg: string, meta: any) => warnSpy.push({ msg, meta }) };
304-
await driver.initObjects(objects);
305-
await driver.create(
306-
'account',
307-
{ id: 'x1', organization_id: 'org_a', name: 'X1' },
308-
{ bypassTenantAudit: true } as any,
309-
);
310-
expect(warnSpy).toHaveLength(0);
320+
// [#5262] A walled posture is a PRECONDITION of this assertion, not
321+
// decoration. Without it the audit returns at the multi-tenant gate and
322+
// `warnSpy` is empty no matter what `bypassTenantAudit` does — the test
323+
// passed while proving nothing about the flag it names. (That was equally
324+
// true before this change, where the absent `_multiTenantMode` memo
325+
// resolved to single-org; the sibling test above happened to poke the memo
326+
// and this one never did.) With the posture set, the flag is the only
327+
// thing that can keep the log quiet.
328+
const priorPosture = process.env.OS_TENANCY_POSTURE;
329+
process.env.OS_TENANCY_POSTURE = 'isolated';
330+
try {
331+
await driver.initObjects(objects);
332+
await driver.create(
333+
'account',
334+
{ id: 'x1', organization_id: 'org_a', name: 'X1' },
335+
{ bypassTenantAudit: true } as any,
336+
);
337+
expect(warnSpy).toHaveLength(0);
338+
} finally {
339+
if (priorPosture === undefined) delete process.env.OS_TENANCY_POSTURE;
340+
else process.env.OS_TENANCY_POSTURE = priorPosture;
341+
}
311342
});
312343
});
313344
});

0 commit comments

Comments
 (0)