@@ -35,7 +35,6 @@ import { until } from "effection";
3535import { join } from "node:path" ;
3636import { tmpdir } from "node:os" ;
3737import { DatabaseSync } from "node:sqlite" ;
38- import { API } from "@executablemd/runtime" ;
3938import { collect , execute , inlineSource , registerComponents } from "@executablemd/core" ;
4039import { executeInstalled } from "@executablemd/core/host" ;
4140import { durableCall , InMemoryStream } from "@executablemd/durable-streams" ;
@@ -837,12 +836,7 @@ function* useStubAgent(calls: AgentCalls): Operation<void> {
837836 * cases depend on is installed by the code that installs it in production
838837 * rather than by this suite.
839838 */
840- function productionHost (
841- root : string ,
842- calls : AgentCalls ,
843- events : string [ ] = [ ] ,
844- performed ?: string [ ] ,
845- ) : WorkflowHost {
839+ function productionHost ( root : string , calls : AgentCalls , events : string [ ] = [ ] ) : WorkflowHost {
846840 return {
847841 useRunHost ( ) : Operation < WorkflowExecutionTransitions > {
848842 return useWorkflowRunHost ( { root } ) ;
@@ -859,21 +853,6 @@ function productionHost(
859853 yield * ensure ( function * ( ) {
860854 events . push ( "released" ) ;
861855 } ) ;
862- if ( performed !== undefined ) {
863- // A pass-through observer around the ordinary Files boundary, so a
864- // case can count what a document execution actually performed there
865- // rather than inferring it from the rows a replay restored.
866- yield * API . Files . around ( {
867- * readTextFile ( [ input ] , next ) {
868- performed . push ( `read:${ input . path } ` ) ;
869- return yield * next ( input ) ;
870- } ,
871- * writeTextFile ( [ input ] , next ) {
872- performed . push ( `write:${ input . path } ` ) ;
873- return yield * next ( input ) ;
874- } ,
875- } ) ;
876- }
877856 return yield * withWorkflowWorkspace ( database , operation , {
878857 agent : ( ) => useStubAgent ( calls ) ,
879858 } ) ;
@@ -1054,6 +1033,24 @@ function journalled(path: string, type: string): number {
10541033 }
10551034}
10561035
1036+ /** The Workspace roots this run has published, and the one it stands on. */
1037+ function workspaceRootState ( path : string ) : { retained : number ; current : string } {
1038+ const database = new DatabaseSync ( path , { readOnly : true } ) ;
1039+ try {
1040+ const retained = Number (
1041+ database . prepare ( "SELECT COUNT(*) AS count FROM workspace_roots" ) . get ( ) ?. [ "count" ] ,
1042+ ) ;
1043+ const current = String (
1044+ database
1045+ . prepare ( "SELECT current_root_id FROM workspace_state WHERE singleton_id = 1" )
1046+ . get ( ) ?. [ "current_root_id" ] ,
1047+ ) ;
1048+ return { retained, current } ;
1049+ } finally {
1050+ database . close ( ) ;
1051+ }
1052+ }
1053+
10571054/** Every durable yield this run retained, in journal order, as type and name. */
10581055function orderedEffects ( path : string ) : { type : string ; name : string } [ ] {
10591056 const database = new DatabaseSync ( path , { readOnly : true } ) ;
@@ -1303,8 +1300,16 @@ describe("Tier CKX — a checkpoint a document asked for", () => {
13031300 * the real workflow `<Elicit>` follow outside it. The admission and every
13041301 * durable effect the admitted fragment performs belong to the owning document
13051302 * expansion's sequence, so a resume offers them in authored order and restores
1306- * each completed one without entering its provider again — which the existing
1307- * root-level checkpoint above does not discriminate.
1303+ * each completed one without another live execution or root publication —
1304+ * which the existing root-level checkpoint above does not discriminate.
1305+ *
1306+ * The once-only proof here is stability: the exact journal counts, the ordered
1307+ * durable subsequence, the Workspace root-publication count, and the
1308+ * authoritative current root are captured at suspension and must survive
1309+ * answer delivery and the completed resume unchanged. An `API.Files` call is
1310+ * deliberately not evidence — document re-expansion legitimately enters that
1311+ * boundary again before the durable `workspace_file` effect underneath
1312+ * restores, so a call count there sits above the live/restore decision.
13081313 */
13091314describe ( "Tier WGAC — generated effects in a bundled component resume through a later wait" , ( ) => {
13101315 /** One root declaring one bundled component, with the wait after both. */
@@ -1340,8 +1345,6 @@ decision: {decision.proceed}
13401345the retained note
13411346</File>
13421347` ,
1343- // What the fragment performs at the Files boundary, exactly once.
1344- live : ( call : string ) => call . startsWith ( "read:" ) && call . endsWith ( "notes.md" ) ,
13451348 nested : [ { operation : "read" , target : "notes.md" } ] ,
13461349 files : 3 ,
13471350 } ,
@@ -1351,7 +1354,6 @@ the retained note
13511354 component :
13521355 `<Evaluate source={"<File path=\\"proposed.md\\">a generated proposal</File>"} allow={["write"]} as="observed" />\n` ,
13531356 setup : "" ,
1354- live : ( call : string ) => call . startsWith ( "write:" ) && call . endsWith ( "proposed.md" ) ,
13551357 nested : [ { operation : "write" , target : "proposed.md" } ] ,
13561358 files : 2 ,
13571359 } ,
@@ -1367,12 +1369,11 @@ the retained note
13671369 yield * useRepositoryGit ( fixture . repository ) ;
13681370
13691371 const calls : AgentCalls = { prompts : [ ] } ;
1370- const performed : string [ ] = [ ] ;
13711372 const rendered : string [ ] = [ ] ;
13721373 const started = yield * invoke (
13731374 { ...REQUEST , action : "start" } ,
13741375 yield * startFor ( fixture ) ,
1375- productionHost ( store , calls , [ ] , performed ) ,
1376+ productionHost ( store , calls ) ,
13761377 pinnedBody ( rendered ) ,
13771378 ) ;
13781379 expect ( started . exitCode ) . toBe ( 2 ) ;
@@ -1383,8 +1384,9 @@ the retained note
13831384 const path = workflowRunPath ( store , runId ) ;
13841385
13851386 // The start settled suspended, with the nested effect and the later
1386- // parent effect committed ahead of the wait — and the fragment reached
1387- // the Files boundary exactly once.
1387+ // parent effect committed ahead of the wait. The journal counts and the
1388+ // Workspace root publications captured here are the once-only baseline
1389+ // everything after the suspension is held to.
13881390 const suspended = retained ( path ) ;
13891391 expect ( suspended . status ) . toBe ( "suspended" ) ;
13901392 expect ( suspended . requests ) . toHaveLength ( 1 ) ;
@@ -1395,7 +1397,7 @@ the retained note
13951397 [ EVALUATION_EFFECT ] : 1 ,
13961398 [ FILE_EFFECT ] : bundled . files ,
13971399 } ) ;
1398- expect ( performed . filter ( bundled . live ) ) . toHaveLength ( 1 ) ;
1400+ const rootsAtSuspension = workspaceRootState ( path ) ;
13991401
14001402 // The relevant ordered subsequence, exactly: the admission, the nested
14011403 // generated effect in authored order, the later parent effect, then the
@@ -1424,27 +1426,28 @@ the retained note
14241426 const suspensionId = suspended . requests [ 0 ] ?? "" ;
14251427 const delivered = yield * manage (
14261428 { action : "answer" , runId, suspensionId, value : { proceed : true } , secretDetection : true } ,
1427- productionHost ( store , calls , [ ] , performed ) ,
1429+ productionHost ( store , calls ) ,
14281430 ) ;
14291431 expect ( delivered . exitCode ) . toBe ( 0 ) ;
14301432 expect ( retained ( path ) ) . toEqual ( suspended ) ;
1431- expect ( performed . filter ( bundled . live ) ) . toHaveLength ( 1 ) ;
1433+ expect ( counts ( path ) ) . toEqual ( atSuspension ) ;
1434+ expect ( workspaceRootState ( path ) ) . toEqual ( rootsAtSuspension ) ;
14321435
1433- // The resume completes, restores every committed effect, and performs
1434- // the fragment's work no second time: one live call at the Files
1435- // boundary across both document executions .
1436+ // The resume completes and restores every committed effect: the same
1437+ // journal counts, the same ordered durable subsequence, the same root
1438+ // publications, and the same authoritative current root .
14361439 const resumed = yield * invoke (
14371440 { ...REQUEST , action : "resume" , target : runId } ,
14381441 undefined ,
1439- productionHost ( store , calls , [ ] , performed ) ,
1442+ productionHost ( store , calls ) ,
14401443 pinnedBody ( rendered ) ,
14411444 ) ;
14421445 expect ( resumed . exitCode ) . toBe ( 0 ) ;
14431446
14441447 const completed = retained ( path ) ;
14451448 expect ( completed . status ) . toBe ( "completed" ) ;
14461449 expect ( counts ( path ) ) . toEqual ( atSuspension ) ;
1447- expect ( performed . filter ( bundled . live ) ) . toHaveLength ( 1 ) ;
1450+ expect ( workspaceRootState ( path ) ) . toEqual ( rootsAtSuspension ) ;
14481451 expect (
14491452 orderedEffects ( path )
14501453 . filter ( ( effect ) => relevant . has ( effect . type ) )
0 commit comments