@@ -28,6 +28,7 @@ import * as EnvironmentRegistry from "../connection/registry.ts";
2828import * as EnvironmentSupervisor from "../connection/supervisor.ts" ;
2929import type { WsRpcProtocolClient } from "../rpc/protocol.ts" ;
3030import type { RpcSession } from "../rpc/session.ts" ;
31+ import { createEnvironmentCatalogAtoms } from "./connections.ts" ;
3132import { createOrchestrationEnvironmentAtoms } from "./orchestration.ts" ;
3233import { v2Now , v2Project , v2ThreadShell } from "./orchestrationV2TestFixtures.ts" ;
3334
@@ -54,6 +55,7 @@ it("does not expose an archived snapshot failure message", () => {
5455 Cause . fail ( new Error ( "credential=secret-value" ) ) ,
5556 ) ,
5657 ) ,
58+ getConnectionStateAtom : ( ) => Atom . make ( AsyncResult . initial < SupervisorConnectionState > ( ) ) ,
5759 labelPrefix : "test:archived-thread-snapshots" ,
5860 } ) ;
5961 const registry = AtomRegistry . make ( ) ;
@@ -141,21 +143,33 @@ it.effect("keeps environment archives live and replaces stale data on reconnect"
141143 environmentId === envA ? a . supervisor : b . supervisor ,
142144 ) ,
143145 } as EnvironmentRegistry . EnvironmentRegistry [ "Service" ] ) ;
144- const atoms = createOrchestrationEnvironmentAtoms (
145- Atom . runtime (
146- Layer . merge (
147- Layer . succeed ( EnvironmentRegistry . EnvironmentRegistry , environments ) ,
148- FetchHttpClient . layer ,
149- ) ,
146+ const runtime = Atom . runtime (
147+ Layer . merge (
148+ Layer . succeed ( EnvironmentRegistry . EnvironmentRegistry , environments ) ,
149+ FetchHttpClient . layer ,
150150 ) ,
151151 ) ;
152+ const atoms = createOrchestrationEnvironmentAtoms ( runtime ) ;
153+ const catalog = createEnvironmentCatalogAtoms ( runtime ) ;
152154 const snapshots = createArchivedThreadSnapshotsAtomFamily ( {
153155 getSnapshotAtom : ( environmentId ) => atoms . archivedShell ( { environmentId, input : { } } ) ,
156+ getConnectionStateAtom : catalog . stateAtom ,
154157 labelPrefix : "test:archived-thread-snapshots" ,
155158 } ) ( makeArchivedThreadsEnvironmentKey ( [ envA , envB ] ) ) ;
156159 const registry = yield * Effect . acquireRelease ( Effect . sync ( AtomRegistry . make ) , ( registry ) =>
157160 Effect . sync ( ( ) => registry . dispose ( ) ) ,
158161 ) ;
162+ for ( const [ environmentId , phase ] of [
163+ [ envA , "connected" ] ,
164+ [ envB , "offline" ] ,
165+ ] as const ) {
166+ yield * AtomRegistry . toStream ( registry , catalog . stateAtom ( environmentId ) ) . pipe (
167+ Stream . filter ( ( result ) =>
168+ Option . exists ( AsyncResult . value ( result ) , ( state ) => state . phase === phase ) ,
169+ ) ,
170+ Stream . runHead ,
171+ ) ;
172+ }
159173 registry . mount ( snapshots ) ;
160174 expect ( registry . get ( snapshots ) . isLoading ) . toBe ( true ) ;
161175
0 commit comments