Skip to content

Commit 50c3929

Browse files
committed
test(plugin-auth): the anchor-parity NOT NULL case reads the engine's ValidationError (#24768)
The grant insert the fresh NOT NULL `organization_id` column refuses now leaves the engine as its own `ValidationError` naming the declared field (`required`), the driver's `SQLITE_CONSTRAINT_NOTNULL` on `cause`. The pin asserts all three, so the case still proves the column refused the row and stays distinct from the D9 refusal. Claude-Session: https://claude.ai/code/session_01E1oXN1ZJ8NnZKKhzWeCZ6q Co-authored-by: Claude <noreply@anthropic.com>
1 parent dbd9e9f commit 50c3929

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

‎packages/plugins/plugin-auth/src/last-admin-guard.anchor-parity.test.ts‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,20 @@ async function resolverStanding(engine: ObjectQL, userId: string, email?: string
162162
const ban = (engine: ObjectQL, id: string) => engine.update('sys_user', { id, banned: true }, SYSTEM);
163163

164164
/** The refusal envelope, or `undefined` when the write landed. */
165-
async function refusalOf(write: Promise<unknown>): Promise<{ code?: unknown; status?: unknown } | undefined> {
165+
async function refusalOf(
166+
write: Promise<unknown>,
167+
): Promise<{ code?: unknown; status?: unknown; fields?: unknown; causeCode?: unknown } | undefined> {
166168
try {
167169
await write;
168170
return undefined;
169171
} catch (err) {
170-
const e = err as { code?: unknown; status?: unknown };
171-
return { code: e.code, status: e.status };
172+
const e = err as { code?: unknown; status?: unknown; fields?: Array<{ field?: unknown; code?: unknown }>; cause?: { code?: unknown } };
173+
return {
174+
code: e.code,
175+
status: e.status,
176+
fields: e.fields?.map((f) => [f.field, f.code]),
177+
causeCode: e.cause?.code,
178+
};
172179
}
173180
}
174181

@@ -210,7 +217,12 @@ describe('[ADR-0131 D1/D9] where an organization-less admin_full_access grant ca
210217
expect(refusal?.code).toBe('ERR_SYSTEM_WRITE_ORGANIZATION_REQUIRED');
211218
expect(rows).toEqual([]);
212219
} else if (c.expected === 'refused-not-null') {
213-
expect(refusal?.code).toBe('SQLITE_CONSTRAINT_NOTNULL');
220+
// The COLUMN refused it: since #24768 the engine answers a NOT NULL
221+
// refusal on a declared field as its own `ValidationError`, the
222+
// driver's refusal on `cause`.
223+
expect(refusal?.code).toBe('VALIDATION_FAILED');
224+
expect(refusal?.fields).toEqual([['organization_id', 'required']]);
225+
expect(refusal?.causeCode).toBe('SQLITE_CONSTRAINT_NOTNULL');
214226
expect(rows).toEqual([]);
215227
} else if (c.expected === 'derived') {
216228
expect(refusal).toBeUndefined();

0 commit comments

Comments
 (0)