Skip to content

Commit 4517600

Browse files
committed
fix(objectql): an unresolvable lookup target fails open; forced test edits for the caller-read rule
Claude-Session: https://claude.ai/code/session_01ADHkmSZhbvtSoFM7YTkq6B Co-authored-by: Claude <noreply@anthropic.com>
1 parent 836064c commit 4517600

3 files changed

Lines changed: 27 additions & 6 deletions

File tree

‎packages/objectql/src/engine-predicate-related-master-detail-header.test.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ const LOOKUP_LINE_OBJECT = {
8787
label: 'Lookup line',
8888
fields: {
8989
invoice_ref: { name: 'invoice_ref', label: 'Invoice', type: 'lookup', reference: HEADER },
90+
memo: { name: 'memo', label: 'Memo', type: 'text' },
9091
},
9192
validations: [{
9293
name: 'no_refs_to_locked', type: 'script', severity: 'error',
@@ -368,10 +369,15 @@ describe('[#22892] a predicate rule reading its master through the master-detail
368369
});
369370

370371
it('a plain lookup traversal to the same object is unchanged: the header\'s stored state is judged, and no read door is asked', async () => {
371-
const err = await refusalOf(() => engine.insert(LOOKUP_LINE, { invoice_ref: 'h_other_locked' }, { context: ALICE } as any));
372+
// [#29029] A non-system write may no longer NAME a header the caller
373+
// cannot read through a lookup either, so the rows that already store
374+
// one are seeded and the write edits another column of them.
375+
storeFor(LOOKUP_LINE).set('ll_locked', { id: 'll_locked', invoice_ref: 'h_other_locked', memo: 'a' });
376+
storeFor(LOOKUP_LINE).set('ll_open', { id: 'll_open', invoice_ref: 'h_other_open', memo: 'a' });
377+
const err = await refusalOf(() => engine.update(LOOKUP_LINE, { memo: 'b' }, { where: { id: 'll_locked' }, context: ALICE } as any));
372378
expectRuleVerdict(answerOf(err, 'h_other_locked'));
373-
await engine.insert(LOOKUP_LINE, { invoice_ref: 'h_other_open' }, { context: ALICE } as any);
374-
expect([...storeFor(LOOKUP_LINE).values()].map((r) => r.invoice_ref)).toEqual(['h_other_open']);
379+
await engine.update(LOOKUP_LINE, { memo: 'b' }, { where: { id: 'll_open' }, context: ALICE } as any);
380+
expect([...storeFor(LOOKUP_LINE).values()].map((r) => [r.invoice_ref, r.memo])).toEqual([['h_other_locked', 'a'], ['h_other_open', 'b']]);
375381
expect(headerReads.length).toBeGreaterThan(0);
376382
expect(headerReads.filter((r) => !r.elevated)).toEqual([]);
377383
});

‎packages/objectql/src/engine-predicate-relationship.test.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,14 @@ describe('#18682 — engine-produced relationship bindings', () => {
138138
d.storeFor('crm_account').set('acc_empty', { id: 'acc_empty', name: 'E', secret: 's' });
139139
});
140140

141-
const relatedReads = () => d.calls.filter((c) => c.object === 'crm_account');
141+
// [#29029] The write's reference check asks the caller's read door for each
142+
// lookup value it names, projected to `id` alone: that read is the
143+
// reference check's, not a rule's related read, so it is not counted here.
144+
const isReferenceCheckRead = (c: { ast: any }) => {
145+
const fields = c.ast?.fields;
146+
return Array.isArray(fields) && fields.length === 1 && fields[0] === 'id';
147+
};
148+
const relatedReads = () => d.calls.filter((c) => c.object === 'crm_account' && !isReferenceCheckRead(c));
142149

143150
it('projects id plus only the fields the rules name — not the whole row', async () => {
144151
await engine.insert('crm_opportunity', { name: 'A', amount: 10, account: 'acc_d' }, { context: ACTING } as any);
@@ -488,7 +495,7 @@ describe('#18682 — engine-produced relationship bindings', () => {
488495
} as any, 'test-package');
489496
d.calls.length = 0;
490497
await engine.insert('plain', { name: 'A', account: 'acc_p' }, { context: ACTING } as any);
491-
expect(d.calls.filter((c) => c.object === 'crm_account')).toHaveLength(0);
498+
expect(relatedReads()).toHaveLength(0);
492499
});
493500
});
494501

‎packages/objectql/src/engine.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10555,7 +10555,15 @@ export class ObjectQL implements IObjectQLEngine {
1055510555
id: unknown,
1055610556
context: ExecutionContext | undefined,
1055710557
): Promise<boolean | null> {
10558-
const master = this.resolveObjectName(target);
10558+
// [#29029] An unresolvable target fails open here exactly as it does in
10559+
// {@link referenceExists}: an integrity check that cannot run invents no
10560+
// rejection.
10561+
let master: string;
10562+
try {
10563+
master = this.resolveObjectName(target);
10564+
} catch {
10565+
return null;
10566+
}
1055910567
if (!this._registry.getObject(master)) return null;
1056010568
const readable = await this.masterDetailHeadersCallerReads(master, [id], context);
1056110569
if (!readable.has(String(id))) return false;

0 commit comments

Comments
 (0)