Skip to content

Commit 2fc0141

Browse files
committed
test(objectql): read "left unset" off the stored row, not the write answer, which now answers the unstored column null (#29538)
Claude-Session: https://claude.ai/code/session_01ADHkmQjPiXgNoSaEpqeGvY Co-authored-by: Claude <noreply@anthropic.com>
1 parent 1cb3f6a commit 2fc0141

5 files changed

Lines changed: 40 additions & 12 deletions

‎packages/objectql/src/engine-default-value-tokens.test.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,11 @@ describe('[#4560] the `current_user` defaultValue token is engine-owned', () =>
103103
// decision a column DEFAULT used to override, writing the literal string
104104
// `current_user` into a lookup('sys_user') column (#4560).
105105
const row: any = await engine.insert('tok_doc', { title: 'B' }, { context: { isSystem: true } } as any);
106-
expect(row.owner).toBeUndefined();
107-
expect(row.owner).not.toBe('current_user');
106+
// [#29538] The answer is the next read's record: a column nothing was
107+
// stored in reads `null`. "Unset" is the STORED row's own: no key at all.
108+
expect(row.owner).toBeNull();
109+
const stored = await engine.getDriverForObject('tok_doc')!.findOne('tok_doc', { where: { id: row.id } } as any);
110+
expect(stored).not.toHaveProperty('owner');
108111
});
109112

110113
it('an explicit null is treated as "not supplied" and still resolves the token (#2706)', async () => {

‎packages/objectql/src/engine-lookup-referential-integrity.test.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,11 @@ describe('[#4441] a lookup id that resolves to nothing is refused', () => {
370370
const row: any = await engine.insert(
371371
'ref_audit_note', { note: 'n', recorded_by: 'ps_does_not_exist' }, { context: userCtx } as any,
372372
);
373-
expect(row.recorded_by, 'stripped before the reference check, not refused by it').toBeUndefined();
373+
// [#29538] The answer reads the unstored column `null`, as the next read
374+
// does; the strip is the STORED row's own: no key at all.
375+
expect(row.recorded_by, 'stripped before the reference check, not refused by it').toBeNull();
376+
const stored = await engine.getDriverForObject('ref_audit_note')!.findOne('ref_audit_note', { where: { id: row.id } } as any);
377+
expect(stored, 'stripped before the reference check, not refused by it').not.toHaveProperty('recorded_by');
374378
});
375379

376380
it('…and the issue\'s own fields are NOT readonly, so they stay enforced', () => {

‎packages/objectql/src/engine-select-option-default.test.ts‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ function makeStubDriver() {
7272

7373
const sys = { context: { isSystem: true } } as any;
7474

75+
/** The row as the stub driver stored it — what the write persisted, before any engine shaping. */
76+
const storedRow = (engine: ObjectQL, object: string, id: unknown) =>
77+
engine.getDriverForObject(object)!.findOne(object, { where: { id } } as any);
78+
7579
describe('[#7246] the option marked `default: true` is the field default', () => {
7680
let engine: ObjectQL;
7781

@@ -132,7 +136,10 @@ describe('[#7246] the option marked `default: true` is the field default', () =>
132136
},
133137
} as any, 'test.issue7246');
134138
const row: any = await engine.insert('opt_unmarked', { title: 'D' }, sys);
135-
expect(row.status).toBeUndefined();
139+
// [#29538] The answer reads the unstored column `null`, as the next read
140+
// does; "left alone" is the STORED row's own: no key at all.
141+
expect(row.status).toBeNull();
142+
expect(await storedRow(engine, 'opt_unmarked', row.id)).not.toHaveProperty('status');
136143
});
137144
});
138145

@@ -348,8 +355,11 @@ describe('[#7246] the default follows the FIELD shape, not the option count', ()
348355
{ label: 'Quick', value: 'quick' },
349356
]) as any, 'test.issue7246');
350357
const row: any = await engine.insert('opt_valueless', {}, sys);
351-
expect(row.tags).toBeUndefined();
352-
expect(row.tags).not.toBeNull();
358+
// [#29538] The answer reads the unstored column `null`, as the next read
359+
// does; "left unset" (no value, not even a stored `null`) is the STORED
360+
// row's own: no key at all.
361+
expect(row.tags).toBeNull();
362+
expect(await storedRow(engine, 'opt_valueless', row.id)).not.toHaveProperty('tags');
353363
});
354364
});
355365

@@ -400,6 +410,8 @@ describe('[#7246] the lint heuristic and the engine agree BY CONSTRUCTION', () =
400410
},
401411
} as any, 'test.issue7246');
402412
const row: any = await engine.insert('opt_alias', {}, sys);
403-
expect(row.status).toBeUndefined();
413+
// [#29538] The answer reads the unstored column `null`; the STORED row has no key.
414+
expect(row.status).toBeNull();
415+
expect(await storedRow(engine, 'opt_alias', row.id)).not.toHaveProperty('status');
404416
});
405417
});

‎packages/objectql/src/engine-write-formula-hydration.test.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,12 @@ describe('#5504 — cost threshold: same gate the read path uses', () => {
557557
it('an object declaring NO formula evaluates nothing on write', async () => {
558558
const created = await rig.protocol.createData({ object: 'wf_plain', data: { name: 'nothing derived' } });
559559
expect(evaluate).not.toHaveBeenCalled();
560-
// …and the response carries exactly the stored keys — no phantom columns.
561-
expect(Object.keys(created.record as Rec).sort()).toEqual(['id', 'name']);
560+
// …and the response carries exactly the stored values — no phantom columns.
561+
// [#29538] Every other stored declared column is answered `null`, as the
562+
// next read answers it: the response IS that read's record.
563+
const record = created.record as Rec;
564+
expect(Object.keys(record).filter((k) => record[k] !== null).sort()).toEqual(['id', 'name']);
565+
expect(record).toStrictEqual(await rig.engine.findOne('wf_plain', { where: { id: record.id } }));
562566
});
563567

564568
it('an object declaring formulas evaluates once per formula field per row', async () => {

‎packages/objectql/src/protocol-save-notice-answer.test.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ const beforeSay = async (ctx: any) => {
109109
};
110110
const afterSay = async (ctx: any) => {
111111
const say = ctx.result?.say_after;
112-
if (say !== undefined) listenerOf(ctx)?.(say);
112+
// [#29538] `!= null`: the write result answers an unwritten declared column
113+
// `null`, as the next read does.
114+
if (say != null) listenerOf(ctx)?.(say);
113115
if (nestedSay !== undefined && ctx.event === 'afterInsert') {
114116
const nested = nestedSay;
115117
nestedSay = undefined;
@@ -136,15 +138,18 @@ async function boot(surface: 'envelope' | 'declarative' | 'member') {
136138
for (const e of ['beforeInsert', 'afterInsert', 'beforeDelete', 'afterDelete', 'beforeFind'] as const) {
137139
engine.registerHook(e, async (ctx: any) => {
138140
memberSeen.push({ event: e, type: typeof ctx.notice });
139-
const say = e === 'beforeInsert' ? ctx.input?.data?.say : e === 'afterInsert' ? ctx.result?.say_after : undefined;
141+
// [#29538] The write result answers an unwritten declared column
142+
// `null`, as the next read does: on the RESULT, `null` is "not said".
143+
const say = e === 'beforeInsert' ? ctx.input?.data?.say : e === 'afterInsert' ? (ctx.result?.say_after ?? undefined) : undefined;
140144
if (say !== undefined) ctx.notice(say);
141145
}, { object: DEAL.name });
142146
}
143147
const bound = bindHooksToEngine(engine, [
144148
{
145149
name: 'sn_deal_member', object: DEAL.name, events: ['beforeUpdate', 'afterUpdate'],
146150
handler: async (ctx: any) => {
147-
const say = ctx.event === 'beforeUpdate' ? ctx.input.say : ctx.result?.say_after;
151+
// [#29538] On the RESULT, `null` is "not said", as above.
152+
const say = ctx.event === 'beforeUpdate' ? ctx.input.say : (ctx.result?.say_after ?? undefined);
148153
if (say !== undefined) ctx.notice(say);
149154
},
150155
},

0 commit comments

Comments
 (0)