99 * child — so the ordering, the retained records and the refusals are the
1010 * production ones, with only the provider's own product replaced.
1111 */
12- import { describe , it } from "@executablemd/test-support/bdd" ;
12+ import { beforeEach , describe , it } from "@executablemd/test-support/bdd" ;
1313import { expect } from "@executablemd/test-support/expect" ;
14+ import { journalBeforeEach , useJournalStream } from "@executablemd/test-support/failure-journal" ;
1415import { InMemoryStream } from "@executablemd/durable-streams" ;
1516import type { DurableEvent } from "@executablemd/durable-streams" ;
1617import { ensure , scoped , spawn , until , withResolvers } from "effection" ;
@@ -51,6 +52,7 @@ import type { NativeLaunchOutcome, NativeLaunchRequest } from "@executablemd/run
5152import type { Json } from "../../core/src/types.ts" ;
5253
5354const ALPHABET = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
55+ const OWNER = "packages/agent/tests/agent-session-launch.test.ts" ;
5456
5557/** A synthetic GitHub token, format-realistic and assembled here. */
5658const CANARY = [ "ghp" , "_" , ALPHABET . slice ( 0 , 36 ) ] . join ( "" ) ;
@@ -367,7 +369,6 @@ interface Run {
367369function * runDoc ( doc : string , options : RunOptions = { } ) : Operation < Run > {
368370 const stub = options . stub ?? createLaunchStub ( ) ;
369371 const launcher : LauncherLog = { reserved : 0 , flushed : 0 , requests : [ ] , notices : [ ] , order : [ ] } ;
370- const stream = options . stream ?? new InMemoryStream ( ) ;
371372 const owned = options . dir === undefined ;
372373 const dir = options . dir ?? path . join ( os . tmpdir ( ) , `xmd-sl-${ randomUUID ( ) } ` ) ;
373374 yield * ensureDir ( dir ) ;
@@ -382,6 +383,7 @@ function* runDoc(doc: string, options: RunOptions = {}): Operation<Run> {
382383 }
383384 const docPath = path . join ( dir , "doc.md" ) ;
384385 yield * writeTextFile ( docPath , doc ) ;
386+ const stream = options . stream ?? ( yield * useJournalStream ( docPath ) ) ;
385387 // The document's own directory is the contextual cwd, so an authored
386388 // relative path resolves the way it would for someone running xmd there.
387389 yield * API . Env . around ( {
@@ -562,6 +564,7 @@ function retainedPhases(events: DurableEvent[]): string[] {
562564const LAUNCH = "<Session.Launch>\nYou are the implementor.\n</Session.Launch>\n" ;
563565
564566describe ( "Tier SL — native session launch" , ( ) => {
567+ beforeEach ( journalBeforeEach ( OWNER ) ) ;
565568 it ( "SL1: without a provider the launch fails, and nothing is reserved or spawned" , function * ( ) {
566569 const launcher : LauncherLog = { reserved : 0 , flushed : 0 , requests : [ ] , notices : [ ] , order : [ ] } ;
567570 const dir = path . join ( os . tmpdir ( ) , `xmd-sl-${ randomUUID ( ) } ` ) ;
@@ -576,7 +579,7 @@ describe("Tier SL — native session launch", () => {
576579 // Registered, but with no root provider: `prompt()` and `launch()` alike
577580 // fall through to the base handlers.
578581 yield * installAgentComponents ( ) ;
579- const execution = yield * execute ( { path : docPath , stream : new InMemoryStream ( ) } ) ;
582+ const execution = yield * execute ( { path : docPath , stream : yield * useJournalStream ( docPath ) } ) ;
580583 const subscription = yield * execution . output ;
581584 let next = yield * subscription . next ( ) ;
582585 while ( ! next . done ) {
@@ -620,7 +623,7 @@ describe("Tier SL — native session launch", () => {
620623 options : { defaultAgent : "stub-agent" , permissionMode : "deny-all" } ,
621624 } ,
622625 } ) ;
623- const execution = yield * execute ( { path : docPath , stream : new InMemoryStream ( ) } ) ;
626+ const execution = yield * execute ( { path : docPath , stream : yield * useJournalStream ( docPath ) } ) ;
624627 const subscription = yield * execution . output ;
625628 let next = yield * subscription . next ( ) ;
626629 while ( ! next . done ) {
@@ -937,6 +940,7 @@ describe("Tier SL — native session launch", () => {
937940 * managed to return.
938941 */
939942describe ( "Tier FS — the final public launch surface" , ( ) => {
943+ beforeEach ( journalBeforeEach ( OWNER ) ) ;
940944 it ( "FS1: middleware that returns a completion without delegating settles nothing" , function * ( ) {
941945 // The original exploit, on the surface that replaced it. The handler sees
942946 // the request, does not pass it on, and answers with a complete-looking
@@ -1448,6 +1452,7 @@ const OWED: MaterializationPlan = {
14481452} ;
14491453
14501454describe ( "Tier MR — retaining and replaying the materialization turn" , ( ) => {
1455+ beforeEach ( journalBeforeEach ( OWNER ) ) ;
14511456 function owing ( overrides : Partial < LaunchStub > = { } ) : LaunchStub {
14521457 return createLaunchStub ( { materialization : OWED , ...overrides } ) ;
14531458 }
@@ -1763,6 +1768,7 @@ const CONFIGURED_LAUNCH = [
17631768] . join ( "\n" ) ;
17641769
17651770describe ( "Tier SC — configured native launch" , ( ) => {
1771+ beforeEach ( journalBeforeEach ( OWNER ) ) ;
17661772 it ( "SC1: the routed use and the retained preparation carry the same two values" , function * ( ) {
17671773 const run = yield * runDoc ( CONFIGURED_LAUNCH , { declareSession : true } ) ;
17681774
@@ -1834,6 +1840,7 @@ describe("Tier SC — configured native launch", () => {
18341840 * that route rather than the element the launch was written inside.
18351841 */
18361842describe ( "Tier SC — the final routed Session decides a launch" , ( ) => {
1843+ beforeEach ( journalBeforeEach ( OWNER ) ) ;
18371844 it ( "SC20: narrowing the request to the raw session runs unconfigured" , function * ( ) {
18381845 const run = yield * runDoc ( CONFIGURED_LAUNCH , {
18391846 declareSession : true ,
@@ -1990,6 +1997,7 @@ describe("Tier SJ — configuration in a retained preparation", () => {
19901997 * these rows own is the durable sequence around it.
19911998 */
19921999describe ( "Tier SR — configured launch replay" , ( ) => {
2000+ beforeEach ( journalBeforeEach ( OWNER ) ) ;
19932001 it ( "SR1: a provider that cannot configure the conversation stops at the preparation" , function * ( ) {
19942002 const run = yield * runDoc ( CONFIGURED_LAUNCH , {
19952003 declareSession : true ,
0 commit comments