@@ -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 ) => / o n ` [ a - z 0 - 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
800843const SCENARIOS_DIR = resolve ( HERE , '../../../../../docs/qa/scenarios' ) ;
0 commit comments