Skip to content

Commit aca00a4

Browse files
committed
feat(scenarios): the confirm-first line asks the build to lock the change a gated action makes
Claude-Session: https://claude.ai/code/session_016WV4cypybwgoxE3ZMZy8kt Co-authored-by: Claude <noreply@anthropic.com>
1 parent 615d995 commit aca00a4

2 files changed

Lines changed: 67 additions & 1 deletion

File tree

‎packages/qa/scenarios/src/runner/prompts.ts‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,29 @@ function rowOwnership(card: Card): string[] {
420420
return lines;
421421
}
422422

423+
/**
424+
* What a confirm-gated agent action's line asks of the build. The gate
425+
* (`ai.requiresConfirmation`) guards the action's own door only, and it is not
426+
* widened to the raw data door (`update_record`), so without a lock an agent
427+
* that meets the gate can write the target state directly. The lock is the one
428+
* the objectstack-ai skill teaches (pitfall "Gating the action, not the
429+
* state"): the fields made not editable for the people who run the action,
430+
* written elevated by the action itself.
431+
*
432+
* Two limits keep it from denying a card's own operations: it is scoped to the
433+
* stage the action acts on (a field permission `when`), so the same people's
434+
* other changes to those fields still land (a team lead's resolve, refused by
435+
* validation, meets no lock before the ticket is resolved); and an action that
436+
* deletes its row locks nothing, since the same people's plain deletes are
437+
* applied operations on several cards.
438+
*/
439+
const CONFIRM_FIRST_LOCK =
440+
'confirm first; the confirmation guards this action’s own door only, so also lock the change it makes: ' +
441+
'if it changes fields of its row, make those fields not editable for each person who runs it, at the stage it acts on ' +
442+
'(a field permission `when` in their permission set), and have the action write them elevated, ' +
443+
'so a plain record update cannot make that change while those people’s other changes to the same fields still land; ' +
444+
'an action that deletes its row locks nothing, and those people keep their delete right';
445+
423446
/** The runner's contract, appended to every build prompt. */
424447
export function dataContract(card: Card): string {
425448
const lines: string[] = [];
@@ -461,7 +484,7 @@ export function dataContract(card: Card): string {
461484
if (card.run.agentActions?.length) {
462485
lines.push('');
463486
lines.push('Business actions an AI agent may call (expose each to AI; ask before acting where marked):');
464-
for (const a of card.run.agentActions) lines.push(`- \`${a.name}\` on \`${a.object}\`: ${a.summary}${a.confirm ? ' (confirm first)' : ''}`);
487+
for (const a of card.run.agentActions) lines.push(`- \`${a.name}\` on \`${a.object}\`: ${a.summary}${a.confirm ? ` (${CONFIRM_FIRST_LOCK})` : ''}`);
465488
}
466489
return lines.join('\n');
467490
}

‎packages/qa/scenarios/test/runner/units.test.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,49 @@ describe('namespace-relative cards', () => {
795795
});
796796
});
797797

798+
describe('the build contract asks for a stage-scoped field lock on a confirm-first action, and on no other action', () => {
799+
// The gate guards the action's own door only and is not widened to `update_record`, so the
800+
// line asks the build to lock the change itself. The fragments below are what the build reads.
801+
const LOCK = 'lock the change it makes';
802+
const STAGE = 'at the stage it acts on (a field permission `when` in their permission set)';
803+
const DELETE_EXEMPT = 'an action that deletes its row locks nothing, and those people keep their delete right';
804+
const actionLines = (contract: string): string[] => contract.split('\n').filter((l) => / on `[a-z0-9_]+`: /.test(l) && l.startsWith('- `'));
805+
806+
it('service_desk: the confirm-first `close_ticket` line carries the lock; `log_ticket`, `reply_to_customer` and `resolve_ticket` do not', () => {
807+
const desk = namespacedScenario(load(resolve(HERE, '../../../../../docs/qa/scenarios/service_desk.json'))).card;
808+
const lines = actionLines(dataContract(desk));
809+
expect(lines).toHaveLength(4);
810+
const close = lines.find((l) => l.includes('close_ticket` on '))!;
811+
expect(close).toContain(': Close a resolved ticket for good; irreversible. (confirm first; ');
812+
for (const fragment of [LOCK, STAGE, DELETE_EXEMPT]) expect(close).toContain(fragment);
813+
for (const plain of lines.filter((l) => l !== close)) {
814+
expect(plain).not.toContain('confirm first');
815+
expect(plain).not.toContain(LOCK);
816+
}
817+
});
818+
819+
it('every card: each confirm-gated action line asks for the lock, and each plain one asks for nothing', () => {
820+
const files = ['asset_lifecycle', 'crm_account_with_contacts', 'invoice_with_line_items', 'leave_balances', 'order_to_cash', 'project_with_tasks', 'requisition_to_receipt', 'service_desk', 'travel_expense'];
821+
let gated = 0;
822+
for (const f of files) {
823+
const card = namespacedScenario(load(resolve(HERE, `../../../../../docs/qa/scenarios/${f}.json`))).card;
824+
const lines = actionLines(dataContract(card));
825+
expect(lines, f).toHaveLength(card.run.agentActions!.length);
826+
card.run.agentActions!.forEach((a, i) => {
827+
if (a.confirm) {
828+
gated += 1;
829+
expect(lines[i], `${f} ${a.name}`).toContain(`(confirm first; `);
830+
expect(lines[i], `${f} ${a.name}`).toContain(LOCK);
831+
expect(lines[i], `${f} ${a.name}`).toContain(DELETE_EXEMPT);
832+
} else {
833+
expect(lines[i], `${f} ${a.name}`).not.toContain(LOCK);
834+
}
835+
});
836+
}
837+
expect(gated).toBe(9);
838+
});
839+
});
840+
798841
// ── The seed's load plan ────────────────────────────────────────────────────
799842

800843
const SCENARIOS_DIR = resolve(HERE, '../../../../../docs/qa/scenarios');

0 commit comments

Comments
 (0)