Skip to content

Commit c46708b

Browse files
committed
fix(plugin-sharing)!: the ownership-queue service refuses a failed member read when the caller asks, and the approver slate and the sharing-recipient recompute ask
expandMembers and isMember honour the contract's onFailedRead option. Under 'refuse' a failed sys_queue, sys_queue_member, team, position, sys_member or business-unit read rejects with a failure naming the queue, its organization and the read, never [] / a partial set / false; isMember still answers true when a read that succeeded reaches the user. The default 'nobody' answers as before, so the admission consumers (access path, claim, assignment pool) are unchanged. The activation-ledger read keeps "switched on" under both. The approver slate's queue arm (D6) and the sharing-rule recompute's queue recipient (D7: whole-rule pass, recipient-axis revoke, per-user pass, record pass) pass 'refuse': the node refuses with ApproverDirectoryUnreadableError, and each recompute's caller keeps the rule's grants and warns. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6CXqXpuVf14Mqo1pznh
1 parent 4a7f82f commit c46708b

6 files changed

Lines changed: 471 additions & 65 deletions

File tree

‎packages/plugins/plugin-approvals/src/approval-service.test.ts‎

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4176,7 +4176,7 @@ describe('ApprovalService — a queue approver routes to the queue\'s members (A
41764176
const req = await svc.openNodeRequest(queueInput('billing'), CTX) as any;
41774177

41784178
expect(req.pending_approvers).toEqual(['u7', 'u8']);
4179-
expect(asked).toEqual([['billing', 't1', { purpose: 'addressing' }]]);
4179+
expect(asked).toEqual([['billing', 't1', { purpose: 'addressing', onFailedRead: 'refuse' }]]);
41804180
expect(warnings.filter(([msg]) => String(msg).includes('expanded to nobody'))).toEqual([]);
41814181
// A member decides it under their own id.
41824182
const decided = await svc.decideNode(req.id, { decision: 'approve', actorId: 'u8' }, SYS);
@@ -4349,6 +4349,62 @@ describe('ApprovalService — a team, position or queue approver whose directory
43494349
});
43504350
});
43514351

4352+
// [ADR-0142 D2 as amended, D6; #29604] The queue arm asks the ownership-queue
4353+
// service for its refusal (`onFailedRead: 'refuse'`), beside the ADDRESSING
4354+
// purpose. The registered service (`@objectstack/plugin-sharing`) answers a
4355+
// failed member read with nobody unless asked, so before the arm asked, a
4356+
// queue whose team or position read failed added no slot and the node's
4357+
// `onEmptyApprovers` policy opened, rescued or approved on a slate missing its
4358+
// people. The double below gives the contract's two answers as that service
4359+
// does: a rejection naming the read under `'refuse'`, `[]` under `'nobody'`.
4360+
describe('ApprovalService — a queue approver asks the queue service to refuse a failed read, and the node refuses with it (ADR-0142 D6)', () => {
4361+
const POLICIES = ['admin_rescue', 'auto_approve', 'fail', 'fallback'] as const;
4362+
const READ = "[queue] queue 'billing' in organization 't1' does not answer its members, because a read behind it failed: "
4363+
+ "the members of team 't_night' could not be read: SQLITE_IOERR: disk I/O error.";
4364+
4365+
const withFailingQueue = () => {
4366+
const engine = makeFakeEngine();
4367+
const asked: unknown[] = [];
4368+
const warnings: any[] = [];
4369+
let n = 0;
4370+
const svc = new ApprovalService({
4371+
engine,
4372+
clock: { now: () => new Date(1757000000000 + (n++) * 1000) },
4373+
logger: { warn: (msg: any, meta: any) => warnings.push([msg, meta]) },
4374+
ownershipQueues: () => ({
4375+
expandMembers: async (name: string, org: string | null, options?: { purpose?: string; onFailedRead?: string }) => {
4376+
asked.push([name, org, options]);
4377+
if (options?.onFailedRead === 'refuse') throw new Error(READ);
4378+
return [];
4379+
},
4380+
}),
4381+
});
4382+
return { engine, svc, asked, warnings };
4383+
};
4384+
const node = (configExtra: Record<string, any>) => ({
4385+
...openInput([]),
4386+
config: { approvers: [{ type: 'queue' as const, value: 'billing' }], behavior: 'first_response' as const, lockRecord: false, ...configExtra },
4387+
});
4388+
4389+
for (const p of POLICIES) {
4390+
it(`a queue whose member read fails: onEmptyApprovers '${p}' opens nothing and approves nothing`, async () => {
4391+
const { engine, svc, asked, warnings } = withFailingQueue();
4392+
const refusal = await svc.openNodeRequest(node(
4393+
p === 'fallback' ? { onEmptyApprovers: p, fallbackApprovers: [{ type: 'user', value: 'u_backstop' }] } : { onEmptyApprovers: p },
4394+
), CTX).then(() => null, (e: unknown) => e);
4395+
4396+
expect(asked).toEqual([['billing', 't1', { purpose: 'addressing', onFailedRead: 'refuse' }]]);
4397+
expect(refusal).toBeInstanceOf(ApproverDirectoryUnreadableError);
4398+
expect(refusal).toMatchObject({ approverType: 'queue', approverValue: 'billing', retryable: true, failedRead: READ });
4399+
expect((refusal as Error).message).toMatch(/^APPROVER_DIRECTORY_UNREADABLE: approver 'queue:billing' could not be expanded in organization 't1'/);
4400+
expect(warnings.some(([msg]) => String(msg).includes("approver 'queue:billing' expanded to nobody"))).toBe(false);
4401+
expect(engine._tables['sys_approval_request'] ?? []).toEqual([]);
4402+
expect(engine._tables['sys_approval_approver'] ?? []).toEqual([]);
4403+
expect(engine._tables['sys_approval_action'] ?? []).toEqual([]);
4404+
});
4405+
}
4406+
});
4407+
43524408
// [ADR-0142 D6 as amended; ruling record 6599731698 on #29604, letter B] The
43534409
// ADR-0105 D9 cross-organization read filter is a read behind a `position` or
43544410
// `team` approver as much as the directory expansion is. When it fails, the

‎packages/plugins/plugin-approvals/src/approval-service.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3482,12 +3482,18 @@ export class ApprovalService implements IApprovalService {
34823482
* fail-open). The service resolves the name registry-first, then the
34833483
* organization's own `sys_queue` row, and answers `[]` for a name that
34843484
* resolves nowhere. With no service registered there is nothing to expand.
3485+
*
3486+
* [#29604] `onFailedRead: 'refuse'` (D2 as amended): a failed read behind the
3487+
* queue rejects instead of answering "nobody", and {@link resolveApproverSpec}'s
3488+
* catch turns that rejection into the node's {@link ApproverDirectoryUnreadableError},
3489+
* so the slate is never opened without the people who could not be read. An
3490+
* axis of its own beside `purpose`.
34853491
*/
34863492
private async expandQueueUsers(queueName: string, organizationId?: string | null): Promise<string[]> {
34873493
if (!queueName) return [];
34883494
const queues = this.queueSource();
34893495
if (!queues) return [];
3490-
return queues.expandMembers(queueName, organizationId ?? null, { purpose: 'addressing' });
3496+
return queues.expandMembers(queueName, organizationId ?? null, { purpose: 'addressing', onFailedRead: 'refuse' });
34913497
}
34923498

34933499
/**

0 commit comments

Comments
 (0)