Skip to content

Commit 69f08e7

Browse files
committed
test(objectql): the boundary-cut sweep pins a declared field's NOT NULL refusal as the validator's ValidationError with a cut cause
Claude-Session: https://claude.ai/code/session_01E1oXN1ZJ8NnZKKhzWeCZ6q Co-authored-by: Claude <noreply@anthropic.com>
1 parent ef7e1b7 commit 69f08e7

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

‎packages/objectql/src/driver-fault-boundary-redaction.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {
4545
} from '@objectstack/types';
4646
import { ObjectQL } from './engine.js';
4747
import { DuplicateRecordError } from './duplicate-record-error.js';
48+
import { NotNullRefusalError } from './not-null-refusal-error.js';
4849
import { SummaryRecomputeError } from './summary-errors.js';
4950
import { redactBoundStatement, redactPropagatedDriverFault } from '@objectstack/types';
5051

@@ -489,9 +490,20 @@ const DOORS: ReadonlyArray<readonly [string, Failing, (e: ObjectQL) => Promise<u
489490
/** One representative per dialect for the door sweep. */
490491
const DOOR_SHAPES = [SHAPES[1], SHAPES[6], SHAPES[11]];
491492

493+
/**
494+
* [#24768] The NOT NULL shapes, one per dialect. On a field the object declares
495+
* (`title` here) the insert and update doors refuse them as the record
496+
* validator's `ValidationError` (`NotNullRefusalError`) with the driver's error
497+
* on `cause`, so those door × shape pairs are pinned in their own block below
498+
* rather than by the sweep's same-prototype assertion.
499+
*/
500+
const NOT_NULL_SHAPES = [SHAPES[2], SHAPES[6], SHAPES[14]];
501+
const NOT_NULL_DOORS = new Set(['insert', 'insert (batch)', 'update by id', 'update by predicate']);
502+
492503
describe('[#21274] every engine door that reaches a driver exits through the cut', () => {
493504
for (const shape of DOOR_SHAPES) {
494505
for (const [door, failing, run] of DOORS) {
506+
if (NOT_NULL_SHAPES.includes(shape) && NOT_NULL_DOORS.has(door)) continue;
495507
it(`${door} — ${shape.id}`, async () => {
496508
const { engine, state } = await bootEngine(shape.make, failing);
497509
const error = await caught(run(engine));
@@ -527,6 +539,23 @@ describe('[#21274] every engine door that reaches a driver exits through the cut
527539
}
528540
}
529541

542+
for (const shape of NOT_NULL_SHAPES) {
543+
for (const [door, failing, run] of DOORS.filter(([name]) => NOT_NULL_DOORS.has(name))) {
544+
it(`${door}: a NOT NULL refusal on a declared field leaves as the validator's ValidationError, and a cut cause — ${shape.id}`, async () => {
545+
const { engine, state } = await bootEngine(shape.make, failing);
546+
const error = (await caught(run(engine))) as NotNullRefusalError;
547+
expectNoSentinel(error);
548+
expect(error).toBeInstanceOf(NotNullRefusalError);
549+
expect(error.code).toBe('VALIDATION_FAILED');
550+
expect(error.fields.map((f) => [f.field, f.code])).toEqual([['title', 'required']]);
551+
const cause = error.cause as Error & { code?: unknown };
552+
expect(Object.getPrototypeOf(cause)).toBe(Object.getPrototypeOf(state.lastRaw));
553+
expect(cause.code).toBe((state.lastRaw as Error & { code?: unknown }).code);
554+
expect(cause.message).toContain(shape.diagnostic);
555+
});
556+
}
557+
}
558+
530559
it('a middleware that logs what it caught sees the cut error too', async () => {
531560
const { engine } = await bootEngine(SHAPES[1].make, 'write');
532561
const seen: unknown[] = [];

0 commit comments

Comments
 (0)