@@ -318,6 +318,120 @@ async function verifyMonitorSignalScopeProjection({page, post, origin, width, pr
318318 console . log ( provider + " " + width + "px: monitor.create & monitor.update cards show applied, preserved_current (incl. PR filter & reopen), and retryable unverified scope" ) ;
319319}
320320
321+ async function goalTab ( page , label ) {
322+ const tab = page . getByRole ( "navigation" , { name : / G o a l v i e w | G o a l 视 图 / } )
323+ . getByRole ( "button" , { name : label } ) ;
324+ const goal = page . locator ( ".personal-goal-link:visible" ) . first ( ) ;
325+ const nav = page . locator ( ".personal-mobile-menu:visible" ) . first ( ) ;
326+ await tab . or ( goal ) . or ( nav ) . first ( ) . waitFor ( ) ;
327+ if ( ! await tab . isVisible ( ) ) {
328+ if ( await nav . isVisible ( ) ) await nav . click ( ) ;
329+ await goal . click ( ) ;
330+ }
331+ await tab . click ( ) ;
332+ }
333+
334+ async function verifyPendingDisplay ( { page, post, origin, width, provider, snapshot, fixture = "/__confirmation_fixture/display" } ) {
335+ await post ( fixture , { hold : true } ) ;
336+ const original = await snapshot ( ) ;
337+ const titles = width === 390
338+ ? [ "核对欠付项的责任人与跟进记录" , "保留交接文档中的原始验收证据" ]
339+ : [ "Review follow-up owners in the release checklist" , "Preserve evidence for the support handover after release" ] ;
340+ const operations = [ ] ;
341+ for ( let i = 0 ; i < titles . length ; i ++ ) {
342+ const [ created , preview ] = await post ( "/api/actions/preview" , {
343+ action_kind : "todo.create" , context : { kind : "goal" , goal_id : "goal-a" } ,
344+ normalized_parameters : { goal_id : "goal-a" , text : titles [ i ] } , summary : "Create task" ,
345+ idempotency_key : "display-confirmation-" + width + "-" + i ,
346+ } ) ;
347+ assert . equal ( created , 201 , JSON . stringify ( preview ) ) ;
348+ const id = preview . proposal . proposal_id ;
349+ const path = "/api/actions/" + id ;
350+ const [ , pending ] = await post ( path + "/apply" ) ;
351+ assert . equal ( pending . proposal . failure . error_code , "canonical_create_projection_pending" ) ;
352+ const createdStep = pending . proposal . checkpoint . steps . todo_created ;
353+ assert . equal ( createdStep . projection_delivery , "pending" ) ;
354+ operations . push ( { id, path, title : titles [ i ] , todo : createdStep . todo_id , receipt : createdStep . canonical_receipt . receipt_id } ) ;
355+ assert . equal ( ( await post ( path + "/cancel" ) ) [ 0 ] , 409 ) ;
356+ }
357+ const committed = await snapshot ( ) ;
358+ assert . equal ( committed . ids . length , original . ids . length + 2 ) ;
359+ assert . notEqual ( operations [ 0 ] . todo , operations [ 1 ] . todo ) ;
360+ await page . goto ( origin + "/chat/?goal=goal-a" ) ;
361+ await goalTab ( page , / ^ ( O v e r v i e w | 概 览 ) $ / ) ;
362+ await page . reload ( ) ;
363+ await goalTab ( page , / ^ ( O v e r v i e w | 概 览 ) $ / ) ;
364+ const overview = page . getByRole ( "region" , { name : / D i s p l a y u p d a t e s p e n d i n g | 展 示 待 更 新 / } ) ;
365+ await overview . waitFor ( ) ;
366+ for ( const { title} of operations ) await overview . getByRole ( "button" , { name : title , exact : true } ) . waitFor ( ) ;
367+ await page . screenshot ( { path : resolve ( output , provider + "-" + width + "-display-overview.png" ) } ) ;
368+ await goalTab ( page , / ^ ( C h a t | 对 话 ) $ / ) ;
369+ const cards = page . locator ( ".personal-proposal-row[data-action-kind='todo.create']" ) ;
370+ const card = title => cards . filter ( { hasText : title } ) ;
371+ // As with ordinary confirmations, these two persisted records have the
372+ // same action title. Both must remain selectable without first doing IO.
373+ for ( const { title} of operations ) await card ( title ) . waitFor ( ) ;
374+ await page . screenshot ( { path : resolve ( output , provider + "-" + width + "-display-chat.png" ) } ) ;
375+ const [ earlier , later ] = operations ;
376+ await card ( later . title ) . click ( ) ;
377+ const retry = page . getByRole ( "dialog" ) . getByRole ( "button" , { name : / ^ ( R e t r y o r i g i n a l o p e r a t i o n | 重 试 原 操 作 ) $ / } ) ;
378+ await retry . waitFor ( ) ;
379+ // Replace the upstream reply after apply ran. File finishes display, while
380+ // SQLite keeps it pending. Both temporarily lose the two readback routes.
381+ await post ( fixture , { hold : provider === "sqlite" , gateway_reply : later . id , hold_list : true , hold_detail : true } ) ;
382+ const gateway = page . waitForResponse ( response => response . url ( ) . endsWith ( later . path + "/apply" ) ) ;
383+ const unavailable = [ later . path , "/api/actions" ] . map ( path => page . waitForResponse ( response =>
384+ response . request ( ) . method ( ) === "GET" && new URL ( response . url ( ) ) . pathname === path && response . status ( ) === 503 ) ) ;
385+ await retry . click ( ) ;
386+ const [ reply ] = await Promise . all ( [ gateway , ...unavailable ] ) ;
387+ assert . equal ( reply . status ( ) , 502 ) ;
388+ assert . match ( reply . headers ( ) [ "content-type" ] , / ^ t e x t \/ h t m l \b / ) ;
389+ await retry . waitFor ( ) ;
390+ assert . ok ( await retry . isEnabled ( ) ) ;
391+ assert . equal ( await page . getByRole ( "dialog" ) . getByRole ( "button" , { name : / r e g e n e r a t e | 重 新 生 成 / i} ) . count ( ) , 0 ) ;
392+ await page . screenshot ( { path : resolve ( output , provider + "-" + width + "-gateway-recovery.png" ) } ) ;
393+ await post ( fixture , { hold : false , hold_list : false , hold_detail : false } ) ;
394+ function checkReceipt ( proposal , operation ) {
395+ assert . equal ( proposal . proposal_id , operation . id ) ;
396+ assert . equal ( proposal . receipt . receipt_id , operation . receipt ) ;
397+ assert . equal ( proposal . receipt . resource_ids . todo_id , operation . todo ) ;
398+ assert . equal ( proposal . receipt . projection_verified , true ) ;
399+ }
400+ async function recover ( operation ) {
401+ const outcome = page . waitForResponse ( response => response . url ( ) . endsWith ( operation . path + "/apply" ) ) ;
402+ await retry . click ( ) ;
403+ const response = await outcome ;
404+ assert . equal ( response . status ( ) , 200 ) ;
405+ checkReceipt ( ( await response . json ( ) ) . proposal , operation ) ;
406+ await page . keyboard . press ( "Escape" ) ;
407+ }
408+ const observed = ( await ( await fetch ( origin + later . path ) ) . json ( ) ) . proposal ;
409+ if ( provider === "sqlite" ) {
410+ assert . equal ( observed . failure . error_code , "canonical_create_projection_pending" ) ;
411+ assert . equal ( observed . checkpoint . steps . todo_created . canonical_receipt . receipt_id , later . receipt ) ;
412+ } else {
413+ checkReceipt ( observed , later ) ;
414+ }
415+ await recover ( later ) ;
416+ await goalTab ( page , / ^ ( O v e r v i e w | 概 览 ) $ / ) ;
417+ await overview . getByRole ( "button" , { name : earlier . title , exact : true } ) . click ( ) ;
418+ // A connection drop with the list unavailable still uses exact readback.
419+ await post ( fixture , { drop_reply : earlier . id , hold_list : true } ) ;
420+ const disconnected = page . waitForEvent ( "requestfailed" , {
421+ predicate : request => request . method ( ) === "POST" && request . url ( ) . endsWith ( earlier . path + "/apply" ) ,
422+ } ) ;
423+ await retry . click ( ) ;
424+ await disconnected ;
425+ await page . getByRole ( "dialog" ) . getByRole ( "button" , { name : / ^ ( V i e w u p d a t e d G o a l | 查 看 更 新 后 的 G o a l ) $ / } ) . waitFor ( ) ;
426+ const exact = await fetch ( origin + earlier . path ) ;
427+ checkReceipt ( ( await exact . json ( ) ) . proposal , earlier ) ;
428+ await post ( fixture , { hold_list : false } ) ;
429+ await page . keyboard . press ( "Escape" ) ;
430+ await overview . waitFor ( { state : "hidden" } ) ;
431+ assert . deepEqual ( await snapshot ( ) , committed ) ;
432+ console . log ( provider + " " + width + "px: HTML 502 and two failed reads keep the original retry; both receipts recovered" ) ;
433+ }
434+
321435async function verify ( provider , interruptedStep ) {
322436 const child = spawn ( resolveTestPython ( { repoRoot : root } ) ,
323437 [ "-u" , fileURLToPath ( new URL ( "todo-confirmation-http-fixture.py" , import . meta. url ) ) , provider , assetDir , interruptedStep ] ,
@@ -366,16 +480,7 @@ async function verify(provider, interruptedStep) {
366480 } ) ;
367481 await page . goto ( origin + "/chat/?goal=goal-a" ) ;
368482 async function openConfirmation ( ) {
369- const chat = page . getByRole ( "navigation" , { name : / G o a l v i e w | G o a l 视 图 / } )
370- . getByRole ( "button" , { name : / ^ ( C h a t | 对 话 ) $ / } ) ;
371- const goal = page . locator ( ".personal-goal-link:visible" ) . first ( ) ;
372- const nav = page . locator ( ".personal-mobile-menu:visible" ) . first ( ) ;
373- await chat . or ( goal ) . or ( nav ) . first ( ) . waitFor ( ) ;
374- if ( ! await chat . isVisible ( ) ) {
375- if ( await nav . isVisible ( ) ) await nav . click ( ) ;
376- await goal . click ( ) ;
377- }
378- await chat . click ( ) ;
483+ await goalTab ( page , / ^ ( C h a t | 对 话 ) $ / ) ;
379484 const card = page . locator ( ".personal-proposal-row" ) . filter ( { hasText : text } ) ;
380485 await card . first ( ) . click ( ) ;
381486 }
@@ -448,6 +553,7 @@ async function verify(provider, interruptedStep) {
448553 await page . screenshot ( { path : resolve ( output , capturePrefix + "-" + width + "-result.png" ) } ) ;
449554 console . log ( provider + " " + width + "px: " + interruptedStep + "; original proposal and one Todo write across reload" ) ;
450555 if ( ! beforeWrite ) {
556+ await verifyPendingDisplay ( { page, post, origin, width, provider, snapshot} ) ;
451557 await verifyMonitorSignalScopeProjection ( { page, post, origin, width, provider, snapshot} ) ;
452558 }
453559 } catch ( error ) {
@@ -471,6 +577,33 @@ async function verify(provider, interruptedStep) {
471577 assert . equal ( created , 201 ) ;
472578 assert . equal ( successor . proposal . regenerated_from , preview . proposal_id ) ;
473579 assert . notEqual ( successor . proposal . proposal_id , preview . proposal_id ) ;
580+ if ( interruptedStep === "todo_created" ) {
581+ const display = "/__confirmation_fixture/display" ;
582+ const [ previewCode , monitor ] = await post ( "/api/actions/preview" , {
583+ action_kind : "monitor.create" , context : { kind : "goal" , goal_id : "goal-a" } ,
584+ normalized_parameters : { goal_id : "goal-a" , agent_id : "agent-a" , target : "Review release readiness" ,
585+ target_key : "release-readiness" , cadence : "2h" , timezone : "UTC" , stop_condition : "watch_only" } ,
586+ summary : "Review release readiness" , idempotency_key : "monitor-display-recovery" ,
587+ } ) ;
588+ assert . equal ( previewCode , 201 ) ;
589+ const monitorPath = "/api/actions/" + monitor . proposal . proposal_id ;
590+ const original = await snapshot ( ) ;
591+ await post ( display , { hold : true } ) ;
592+ const [ , pending ] = await post ( monitorPath + "/apply" ) ;
593+ const saved = pending . proposal . checkpoint . steps . todo_created ;
594+ assert . equal ( pending . proposal . failure . error_code , "canonical_create_projection_pending" ) ;
595+ const committed = await snapshot ( ) ;
596+ assert . deepEqual ( committed . ids , [ ...original . ids , saved . todo_id ] . sort ( ) ) ;
597+ assert . equal ( ( await post ( monitorPath + "/cancel" ) ) [ 0 ] , 409 ) ;
598+ assert . deepEqual ( await snapshot ( ) , committed ) ;
599+ await post ( display , { hold : false } ) ;
600+ const [ applied , recovered ] = await post ( monitorPath + "/apply" ) ;
601+ assert . equal ( applied , 200 ) ;
602+ assert . equal ( recovered . proposal . receipt . resource_ids . todo_id , saved . todo_id ) ;
603+ assert . equal ( recovered . proposal . receipt . projection_verified , true ) ;
604+ assert . deepEqual ( await snapshot ( ) , committed ) ;
605+ console . log ( provider + ": the Monitor cancel returns 409 and the original confirmation recovers its display" ) ;
606+ }
474607 } finally {
475608 child . kill ( "SIGINT" ) ;
476609 await exited ;
0 commit comments