Skip to content

Commit 584c26a

Browse files
committed
fix(plugin-approvals): the one-row detail lock read answers from the row it found
The one-row form asked exactly one id, so a non-empty answer is that row's; it no longer depends on the engine spelling the id back as asked. The batch form's docblock says why the join stays in-app, and the spec contract docblocks say "a record the line belongs to". Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufzeiHatzB4rRx1t4Php
1 parent cf433db commit 584c26a

3 files changed

Lines changed: 36 additions & 4 deletions

File tree

‎packages/plugins/plugin-approvals/src/lifecycle-hooks.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,10 @@ export async function detailRowHeldByLockingApproval(
540540
objectName: string,
541541
recordId: string,
542542
): Promise<boolean> {
543-
return (await detailRowsHeldByLockingApproval(engine, objectName, [recordId])).has(recordId);
543+
// Asked of exactly one id, a non-empty answer is that row's: the set's member
544+
// is the row's id as the engine spells it back, which need not be `recordId`'s
545+
// spelling, so membership is never compared.
546+
return (await detailRowsHeldByLockingApproval(engine, objectName, [recordId])).size > 0;
544547
}
545548

546549
/**
@@ -553,6 +556,12 @@ export async function detailRowHeldByLockingApproval(
553556
* and a row asked alone cannot disagree. An object with no `master_detail`
554557
* edge reads nothing.
555558
*
559+
* The join is not pushed down to the database: the judgement is made in-app
560+
* over each request's `node_config_json` snapshot and must be the write hook's
561+
* own ({@link lockingRequestsForRecords}), and the id list is bounded by the
562+
* door's 200-id cap (`APPROVAL_RECORD_LOCKS_MAX_RECORD_IDS`), so `1 + edges`
563+
* bounded reads is the whole cost.
564+
*
556565
* ⚠️ Like the one-row form, it answers for the rows, not for a caller, and the
557566
* FK read is SYSTEM.
558567
*/

‎packages/plugins/plugin-approvals/src/record-lock-read.integration.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import { SysApprovalAction } from './sys-approval-action.object.js';
4444
import { SysApprovalApprover } from './sys-approval-approver.object.js';
4545
import { SysApprovalDelegation } from './sys-approval-delegation.object.js';
4646
import { installDefaultOrganization } from './default-organization.testkit.js';
47+
import { detailRowHeldByLockingApproval, detailRowsHeldByLockingApproval } from './lifecycle-hooks.js';
4748

4849
/** Its approval node locks the record. */
4950
const HELD = 'held_sheet';
@@ -402,3 +403,25 @@ describe('a locked record\'s lines are locked with it — the record-lock read a
402403
expect(await rig.svc.getRecordLock(LINE, MISSING, asUser(READER))).toBeNull();
403404
});
404405
});
406+
407+
describe('the one-row detail read answers from the row it found, not from how the engine spells its id', () => {
408+
// A stand-in engine that answers the by-id read with the row's id spelled
409+
// differently from the asked one (a driver that normalizes case, or hands a
410+
// numeric id back as a number) — the master it names is held by a locking request.
411+
const engine = {
412+
getSchema: (name: string) => name === 'line'
413+
? { fields: { order: { name: 'order', type: 'master_detail', reference: 'order' } } }
414+
: undefined,
415+
find: async (name: string) => name === 'line'
416+
? [{ id: 'LINE-1', order: 'ord_1' }]
417+
: name === 'sys_approval_request'
418+
? [{ record_id: 'ord_1', status: 'pending', node_config_json: '{}' }]
419+
: [],
420+
} as any;
421+
422+
it('a held line asked by an id the engine spells back differently answers true', async () => {
423+
expect(await detailRowHeldByLockingApproval(engine, 'line', 'line-1')).toBe(true);
424+
// The batch form keeps answering with the ids as the engine spells them.
425+
expect([...await detailRowsHeldByLockingApproval(engine, 'line', ['line-1'])]).toEqual(['LINE-1']);
426+
});
427+
});

‎packages/spec/src/contracts/approval-service.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,8 +1112,8 @@ export interface IApprovalService {
11121112
* - **What is answered:** `locked` only. `true` when a pending request on the
11131113
* record comes from a node whose `lockRecord` is not `false` — the same
11141114
* judgement, off the same snapshot, the record-lock `beforeUpdate` hook
1115-
* enforces. Asked of a master-detail line, it also answers `true` while the
1116-
* record the line belongs to is so held — the detail-row lock's judgement,
1115+
* enforces. Asked of a master-detail line, it also answers `true` while
1116+
* a record the line belongs to is so held — the detail-row lock's judgement,
11171117
* which refuses the line's writes.
11181118
* ⛔ No request id, node, participants or `pending` flag: whether
11191119
* the caller may see the request is still `approvalsVisibleToReaders`'
@@ -1144,7 +1144,7 @@ export interface IApprovalService {
11441144
* can read the record, `null` when it cannot or when it does not exist,
11451145
* ⛔ never an entry that tells the two apart. The same judgement, off the
11461146
* same snapshot, the record-lock `beforeUpdate` hook enforces — and, for a
1147-
* master-detail line, the detail-row lock's: a line answers `true` while the
1147+
* master-detail line, the detail-row lock's: a line answers `true` while a
11481148
* record it belongs to is so held. A repeated id
11491149
* is answered at each of its positions. A caller refused the object's read
11501150
* outright is refused the same way for every id.

0 commit comments

Comments
 (0)