@@ -2,7 +2,6 @@ import assert from 'node:assert/strict';
22import { test } from 'vitest' ;
33import {
44 buildReplayDivergenceResume ,
5- evaluateReplayResumePreflight ,
65 stampPendingRecordAndHealWatermark ,
76} from '../session-replay-resume.ts' ;
87import type { SessionAction , SessionState } from '../../types.ts' ;
@@ -12,29 +11,6 @@ function action(overrides: Partial<SessionAction> = {}): SessionAction {
1211 return { ts : 0 , command : 'click' , positionals : [ 'label="Save"' ] , flags : { } , ...overrides } ;
1312}
1413
15- test ( 'generic .ad replay allows resuming from the first action' , ( ) => {
16- const actions : SessionAction [ ] = [ action ( { command : 'back' , positionals : [ ] } ) , action ( ) ] ;
17- assert . deepEqual ( evaluateReplayResumePreflight ( { from : 1 , actions } ) , { allowed : true } ) ;
18- } ) ;
19-
20- test ( 'generic .ad replay allows resuming after earlier actions' , ( ) => {
21- const actions : SessionAction [ ] = [
22- action ( { command : 'open' , positionals : [ 'Demo' ] } ) ,
23- action ( { command : 'click' , positionals : [ 'label="Continue"' ] } ) ,
24- action ( { command : 'click' , positionals : [ 'label="Save"' ] } ) ,
25- ] ;
26- assert . deepEqual ( evaluateReplayResumePreflight ( { from : 3 , actions } ) , { allowed : true } ) ;
27- } ) ;
28-
29- test ( 'repeated generic .ad action lines occupy distinct plan indices' , ( ) => {
30- const actions : SessionAction [ ] = [
31- action ( { command : 'click' , positionals : [ 'label="Item"' ] } ) ,
32- action ( { command : 'click' , positionals : [ 'label="Item"' ] } ) ,
33- action ( { command : 'click' , positionals : [ 'label="Item"' ] } ) ,
34- ] ;
35- assert . deepEqual ( evaluateReplayResumePreflight ( { from : 3 , actions } ) , { allowed : true } ) ;
36- } ) ;
37-
3814test ( 'buildReplayDivergenceResume reports a resumable generic .ad failure' , ( ) => {
3915 const actions : SessionAction [ ] = [
4016 action ( { command : 'open' , positionals : [ 'Demo' ] } ) ,
@@ -91,13 +67,11 @@ test('buildReplayDivergenceResume with repairHint record-and-heal on the LAST pl
9167} ) ;
9268// --- buildReplayDivergenceResume: `resume.alternateFrom` (#1262). The
9369// `caution`/`manual` dual-path's SECOND ordinal (`failedIndex + 1`), present
94- // ONLY when a `--from failedIndex + 1` request would actually be accepted —
95- // i.e. `evaluateReplayResumePreflight({ from: failedIndex + 1 })` passes,
96- // which additionally requires the DIVERGED step itself to be skip-safe. This
97- // closes the parity bug where the text renderer offered `--from N + 1` based
98- // on `N`'s preflight (which does not check step `N`'s own skip-safety). ---
70+ // ONLY when a `--from failedIndex + 1` request would actually be accepted.
71+ // Generic `.ad` plans contain no runtime variable producers or control
72+ // wrappers, so only the empty-tail session requirement can block it. ---
9973
100- test ( 'buildReplayDivergenceResume: caution mid-plan (skip-safe diverged step) carries alternateFrom = failedIndex + 1' , ( ) => {
74+ test ( 'buildReplayDivergenceResume: caution mid-plan carries alternateFrom = failedIndex + 1' , ( ) => {
10175 const actions : SessionAction [ ] = [
10276 action ( { command : 'open' } ) ,
10377 action ( { command : 'click' } ) ,
@@ -116,7 +90,7 @@ test('buildReplayDivergenceResume: caution mid-plan (skip-safe diverged step) ca
11690 assert . equal ( resume . alternateFrom , 3 ) ;
11791} ) ;
11892
119- test ( 'buildReplayDivergenceResume: manual last-step (skip-safe diverged step) carries alternateFrom = actions.length + 1' , ( ) => {
93+ test ( 'buildReplayDivergenceResume: manual last-step carries alternateFrom = actions.length + 1' , ( ) => {
12094 const actions : SessionAction [ ] = [ action ( { command : 'open' } ) , action ( { command : 'click' } ) ] ;
12195 const resume = buildReplayDivergenceResume ( {
12296 failedIndex : 2 ,
@@ -131,44 +105,6 @@ test('buildReplayDivergenceResume: manual last-step (skip-safe diverged step) ca
131105 assert . equal ( resume . alternateFrom , 3 ) ; // empty-tail ordinal
132106} ) ;
133107
134- test ( 'buildReplayDivergenceResume: caution whose diverged step is a runScript carries NO alternateFrom (mid-plan AND last-step)' , ( ) => {
135- // The `N + 1` alternate would skip the runScript (outputEnv producer) at
136- // step N, which `evaluateReplayResumePreflight({ from: N + 1 })` refuses —
137- // so alternateFrom is absent even though resuming AT N stays allowed.
138- const midPlan : SessionAction [ ] = [
139- action ( { command : 'open' } ) ,
140- action ( { command : '__maestroRunScript' , positionals : [ './setup.js' ] } ) ,
141- action ( { command : 'click' } ) ,
142- ] ;
143- const midPlanResume = buildReplayDivergenceResume ( {
144- failedIndex : 2 ,
145- actions : midPlan ,
146- planDigest : 'abc123' ,
147- repairHint : 'caution' ,
148- sessionExists : true ,
149- } ) ;
150- assert . equal ( midPlanResume . allowed , true ) ; // resuming AT 2 is fine
151- assert . equal ( midPlanResume . from , 2 ) ;
152- if ( ! midPlanResume . allowed ) return ;
153- assert . equal ( midPlanResume . alternateFrom , undefined ) ;
154-
155- const lastStep : SessionAction [ ] = [
156- action ( { command : 'open' } ) ,
157- action ( { command : '__maestroRunScript' , positionals : [ './setup.js' ] } ) ,
158- ] ;
159- const lastStepResume = buildReplayDivergenceResume ( {
160- failedIndex : 2 ,
161- actions : lastStep ,
162- planDigest : 'abc123' ,
163- repairHint : 'caution' ,
164- sessionExists : true ,
165- } ) ;
166- assert . equal ( lastStepResume . allowed , true ) ;
167- assert . equal ( lastStepResume . from , 2 ) ;
168- if ( ! lastStepResume . allowed ) return ;
169- assert . equal ( lastStepResume . alternateFrom , undefined ) ;
170- } ) ;
171-
172108test ( 'buildReplayDivergenceResume: record-and-heal and state-repair never carry alternateFrom (no separate recorded-action alternate)' , ( ) => {
173109 const actions : SessionAction [ ] = [
174110 action ( { command : 'open' } ) ,
@@ -381,34 +317,6 @@ test('stampPendingRecordAndHealWatermark does NOT stamp for a MID-PLAN caution/m
381317 }
382318} ) ;
383319
384- test ( 'stampPendingRecordAndHealWatermark does not stamp for a LAST-step caution/manual divergence when the N + 1 target is not itself preflight-safe' , ( ) => {
385- // failedIndex (3) IS the last step, but skipping it (to reach N + 1 = 4)
386- // requires also skipping step 2 (an outputEnv-producing maestro runScript),
387- // which cannot be proven safe — even though `resume.from` (unshifted, at
388- // N = 3 — resuming AT it, not skipping it) is independently fine.
389- const actions : SessionAction [ ] = [
390- action ( { command : 'open' } ) ,
391- action ( { command : '__maestroRunScript' , positionals : [ './setup.js' ] } ) ,
392- action ( { command : 'click' } ) ,
393- ] ;
394- const resume = buildReplayDivergenceResume ( {
395- failedIndex : 3 ,
396- actions,
397- planDigest : 'abc123' ,
398- repairHint : 'caution' ,
399- sessionExists : true ,
400- } ) ;
401- const session = sessionWithActions ( 2 ) ;
402- stampPendingRecordAndHealWatermark ( {
403- session,
404- resume,
405- repairHint : 'caution' ,
406- failedIndex : 3 ,
407- actions,
408- } ) ;
409- assert . equal ( session . pendingRecordAndHeal , undefined ) ;
410- } ) ;
411-
412320test ( 'stampPendingRecordAndHealWatermark never stamps for state-repair (not in the extended eligible set)' , ( ) => {
413321 const actions : SessionAction [ ] = [ action ( { command : 'open' } ) , action ( { command : 'click' } ) ] ;
414322 const resume = buildReplayDivergenceResume ( {
0 commit comments