Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ThreadHandoff.test.ts

1,139 lines46.4 KB

1import { NodeHttpServer } from "@effect/platform-node";
2import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
3import * as NodeServices from "@effect/platform-node/NodeServices";
4import {
5 CommandId,
6 EnvironmentId,
7 linkOriginIsFenced,
8 MessageId,
9 OrchestratorMcpFailure,
10 type OrchestrationV2ThreadProjection,
11 type Project,
12 ProjectId,
13 ProviderInstanceId,
14 ThreadId,
15} from "@t3tools/contracts";
16import { expect, it } from "@effect/vitest";
17import * as Deferred from "effect/Deferred";
18import * as Fiber from "effect/Fiber";
19import * as Context from "effect/Context";
20import * as Queue from "effect/Queue";
21import * as Effect from "effect/Effect";
22import * as FileSystem from "effect/FileSystem";
23import * as Layer from "effect/Layer";
24import * as Option from "effect/Option";
25import * as Path from "effect/Path";
26import * as Ref from "effect/Ref";
27import * as Stream from "effect/Stream";
28import * as Tracer from "effect/Tracer";
29import { FetchHttpClient } from "effect/http";
30​
31import * as AssetSigner from "../../assets/AssetSigner.ts";
32import * as ServerSecretStore from "../../auth/ServerSecretStore.ts";
33import * as ServerConfig from "../../config.ts";
34import * as ServerEnvironment from "../../environment/ServerEnvironment.ts";
35import * as ServerHttp from "../../http.ts";
36import * as McpHttpServer from "../../mcp/McpHttpServer.ts";
37import * as EventSink from "../../orchestration-v2/EventSink.ts";
38import * as EventStore from "../../orchestration-v2/EventStore.ts";
39import * as CommandReceiptStore from "../../orchestration-v2/CommandReceiptStore.ts";
40import * as Orchestrator from "../../orchestration-v2/Orchestrator.ts";
41import * as ProjectionStore from "../../orchestration-v2/ProjectionStore.ts";
42import * as ProviderAdapterRegistry from "../../orchestration-v2/ProviderAdapterRegistry.ts";
43import * as ThreadImportService from "../../orchestration-v2/ThreadImportService.ts";
44import * as ThreadLaunch from "../../orchestration-v2/ThreadLaunchService.ts";
45import * as ThreadManagement from "../../orchestration-v2/ThreadManagementService.ts";
46import {
47 type CapturedTurn,
48 makeCapturingCodexAdapter,
49} from "../../orchestration-v2/testkit/CapturingCodexAdapter.ts";
50import * as ProviderReplayHarness from "../../orchestration-v2/testkit/ProviderReplayHarness.ts";
51import * as SqlitePersistence from "../../persistence/Sqlite.ts";
52import * as ManagedProjectFolders from "../../project/ManagedProjectFolders.ts";
53import * as ProjectService from "../../project/ProjectService.ts";
54import * as RepositoryIdentityResolver from "../../project/RepositoryIdentityResolver.ts";
55import * as DocumentText from "../../provider/DocumentText.ts";
56import * as ProviderRegistry from "../../provider/ProviderRegistry.ts";
57import * as ScheduledTaskService from "../../scheduledTasks/ScheduledTaskService.ts";
58import * as SecretRequests from "../../secrets/SecretRequests.ts";
59import * as ServerSettings from "../../serverSettings.ts";
60import * as SourceControlRepositoryService from "../../sourceControl/SourceControlRepositoryService.ts";
61import * as GitVcsDriver from "../../vcs/GitVcsDriver.ts";
62import * as VcsProcess from "../../vcs/VcsProcess.ts";
63import * as PeerForwarding from "../PeerForwarding.ts";
64import * as PeerLinks from "../PeerLinks.ts";
65import { descriptorOf, layerLinkingEnvironment, linkTo, servePeer } from "../PeerLinks.testkit.ts";
66import * as RemoteDelegation from "../RemoteDelegation.ts";
67import * as HandoffGit from "./HandoffGit.ts";
68import * as HandoffImport from "./HandoffImport.ts";
69import * as ThreadHandoff from "./ThreadHandoff.ts";
70import * as PeerLinkRequests from "../PeerLinkRequests.ts";
71​
72// A thread on the laptop moves to the box: both are real orchestrators, the
73// box behind its real /mcp, OAuth and upload route, the laptop linked to it,
74// and both with a real clone of the same repository. The thread arrives with
75// its conversation and its git work, and only one copy stays live.
76​
77const laptop = descriptorOf("environment-laptop", "Laptop");
78const box = descriptorOf("environment-box", "Box");
79const modelSelection = { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.4" };
80​
81const git = (cwd: string, args: ReadonlyArray<string>) =>
82 VcsProcess.VcsProcess.pipe(
83 Effect.flatMap((processes) =>
84 processes.run({
85 operation: "ThreadHandoff.test",
86 command: "git",
87 cwd,
88 args,
89 env: {
90 ...process.env,
91 GIT_AUTHOR_NAME: "Test",
92 GIT_AUTHOR_EMAIL: "test@example.com",
93 GIT_COMMITTER_NAME: "Test",
94 GIT_COMMITTER_EMAIL: "test@example.com",
95 },
96 }),
97 ),
98 Effect.map((result) => result.stdout),
99 Effect.orDie,
100 );
101​
102/** An origin and the laptop's and the box's clones of it. */
103const makeRepos = Effect.gen(function* () {
104 const fileSystem = yield* FileSystem.FileSystem;
105 const path = yield* Path.Path;
106 const root = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-thread-handoff-" });
107 const origin = path.join(root, "origin.git");
108 const seed = path.join(root, "seed");
109 yield* fileSystem.makeDirectory(seed);
110 yield* git(root, ["init", "--quiet", "--bare", "--initial-branch=main", origin]);
111 yield* git(seed, ["init", "--quiet", "--initial-branch=main"]);
112 yield* fileSystem.writeFileString(path.join(seed, "app.ts"), "export const version = 1;\n");
113 yield* git(seed, ["add", "."]);
114 yield* git(seed, ["commit", "--quiet", "-m", "start"]);
115 yield* git(seed, ["remote", "add", "origin", origin]);
116 yield* git(seed, ["push", "--quiet", "origin", "main"]);
117 const laptopRepo = path.join(root, "laptop");
118 const boxRepo = path.join(root, "box");
119 yield* git(root, ["clone", "--quiet", origin, laptopRepo]);
120 yield* git(root, ["clone", "--quiet", origin, boxRepo]);
121 // A local remote names no repository to match on, so each clone knows the origin by a
122 // forge address that git rewrites to the local one.
123 const forgeUrl = "https://github.com/acme/handoff-app.git";
124 for (const repo of [laptopRepo, boxRepo]) {
125 yield* git(repo, ["remote", "set-url", "origin", forgeUrl]);
126 yield* git(repo, ["config", `url.${origin}.insteadOf`, forgeUrl]);
127 }
128 return { root, laptopRepo, boxRepo };
129});
130​
131const projectAt = (id: string, workspaceRoot: string): Project => ({
132 id: ProjectId.make(id),
133 title: "app",
134 workspaceRoot,
135 // Blank, as a cold enrichment cache leaves it: both sides resolve the
136 // clones' shared origin themselves.
137 repositoryIdentity: null,
138 defaultModelSelection: null,
139 scripts: [],
140 createdAt: "2026-10-01T00:00:00.000Z",
141 updatedAt: "2026-10-01T00:00:00.000Z",
142 deletedAt: null,
143});
144​
145/** Projects whose repository identity is read from their real checkouts, as the service does. */
146const layerProjects = (projects: ReadonlyArray<Project>) =>
147 Layer.effect(
148 ProjectService.ProjectService,
149 Effect.gen(function* () {
150 const identities = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
151 return ProjectService.ProjectService.of({
152 getById: (id: ProjectId) =>
153 Effect.succeed(Option.fromNullishOr(projects.find((project) => project.id === id))),
154 snapshot: Effect.succeed({ projects, updatedAt: projects[0]!.updatedAt }),
155 listPage: () =>
156 Effect.forEach(projects, (project) =>
157 identities
158 .resolve(project.workspaceRoot)
159 .pipe(Effect.map((repositoryIdentity) => ({ ...project, repositoryIdentity }))),
160 ).pipe(Effect.map((listed) => ({ projects: listed, nextCursor: null }))),
161 } as unknown as ProjectService.ProjectService["Service"]);
162 }),
163 );
164​
165/** What each test runs on: a test HTTP server, git, and Node. */
166const layerTestHost = Layer.mergeAll(NodeHttpServer.layerTest, VcsProcess.layer).pipe(
167 Layer.provideMerge(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
168);
169​
170/** A real orchestrator on an in-memory database, with a capturing provider. */
171const layerOrchestration = (
172 name: string,
173 workspace: string,
174 captured: Ref.Ref<ReadonlyArray<CapturedTurn>>,
175 holdTurn?: Effect.Effect<void>,
176) => {
177 const layerDatabase = SqlitePersistence.layerMemory;
178 const layerStores = Layer.mergeAll(
179 layerDatabase,
180 EventStore.layer.pipe(Layer.provideMerge(layerDatabase)),
181 ProjectionStore.layer.pipe(Layer.provideMerge(layerDatabase)),
182 );
183 const layerOrchestrator = ProviderReplayHarness.layerWithRegistry(
184 {
185 name,
186 runtimePolicyOverride: {
187 cwd: workspace,
188 approvalPolicy: "never",
189 sandboxPolicy: { type: "readOnly", access: { type: "fullAccess" }, networkAccess: false },
190 },
191 },
192 ProviderAdapterRegistry.layerSingle(
193 makeCapturingCodexAdapter(captured, {
194 response: `${name} replied.`,
195 modelSelection,
196 ...(holdTurn === undefined ? {} : { holdTurn }),
197 }),
198 ),
199 { databaseLayer: layerDatabase },
200 );
201 return ThreadManagement.layer.pipe(
202 Layer.provide(CommandReceiptStore.layer.pipe(Layer.provide(layerDatabase))),
203 Layer.provideMerge(Layer.merge(layerOrchestrator, ServerSettings.layerTest())),
204 Layer.provideMerge(EventSink.layer.pipe(Layer.provide(layerStores))),
205 Layer.provideMerge(layerStores),
206 );
207};
208​
209const unusedServices = Layer.mergeAll(
210 Layer.mock(ProviderRegistry.ProviderRegistry)({ getProviders: Effect.succeed([]) }),
211 Layer.mock(ProviderAdapterRegistry.ProviderAdapterRegistryV2)({ list: () => Effect.succeed([]) }),
212 Layer.mock(ScheduledTaskService.ScheduledTaskService)({}),
213 Layer.mock(SecretRequests.SecretRequests)({}),
214 Layer.mock(ThreadLaunch.ThreadLaunchService)({}),
215 Layer.mock(ManagedProjectFolders.ManagedProjectFolders)({ namedProjectsRoot: "/p" }),
216 Layer.mock(SourceControlRepositoryService.SourceControlRepositoryService)({}),
217 Layer.mock(RemoteDelegation.RemoteDelegation)({}),
218 Layer.mock(PeerForwarding.PeerForwarding)({}),
219 Layer.mock(PeerLinkRequests.PeerLinkRequests)({}),
220 Layer.mock(PeerLinks.PeerLinks)({}),
221 // The box takes moves; it never starts one.
222 Layer.mock(ThreadHandoff.ThreadHandoff)({}),
223);
224​
225/** The box: its real tools on a real /mcp, with uploads, on its own repo. */
226const serveBox = (
227 boxRepo: string,
228 stateDir: string,
229 captured: Ref.Ref<ReadonlyArray<CapturedTurn>>,
230 projects: ReadonlyArray<Project> = [projectAt("project:box", boxRepo)],
231) =>
232 Effect.gen(function* () {
233 const core = yield* Layer.mergeAll(
234 ThreadImportService.layer.pipe(
235 Layer.provideMerge(layerOrchestration("box", boxRepo, captured)),
236 ),
237 VcsProcess.layer,
238 ).pipe(
239 Layer.provide(NodeCrypto.layer),
240 // Not merged out: uploads are signed, stored and read with the served peer's own.
241 Layer.provide(
242 ServerSecretStore.layer.pipe(
243 Layer.provideMerge(ServerConfig.layerTest(process.cwd(), stateDir)),
244 ),
245 ),
246 Layer.provideMerge(NodeServices.layer),
247 Layer.build,
248 );
249 const layerCore = Layer.succeedContext(core);
250 // One signer for the tool that signs an upload URL and the route that checks it.
251 const layerUploads = Layer.succeedContext(
252 yield* Layer.mergeAll(AssetSigner.layer, DocumentText.layer).pipe(
253 Layer.provide(
254 ServerSecretStore.layer.pipe(
255 Layer.provideMerge(ServerConfig.layerTest(process.cwd(), stateDir)),
256 ),
257 ),
258 Layer.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
259 Layer.build,
260 ),
261 );
262 const tools = Layer.mergeAll(
263 McpHttpServer.layerOrchestratorToolkit,
264 McpHttpServer.layerProjectRegistration,
265 McpHttpServer.layerAttachmentToolkit,
266 ).pipe(
267 Layer.provide(HandoffImport.layer.pipe(Layer.provide(HandoffGit.layer))),
268 Layer.provide(
269 layerProjects(projects).pipe(Layer.provideMerge(RepositoryIdentityResolver.layer)),
270 ),
271 Layer.provide(
272 Layer.mock(GitVcsDriver.GitVcsDriver)({
273 listWorktreePaths: () => Effect.succeed([]),
274 }),
275 ),
276 Layer.provide(unusedServices),
277 Layer.provide(layerCore),
278 Layer.provide(layerUploads),
279 Layer.provide(NodeCrypto.layer),
280 );
281 const served = yield* servePeer(box, tools, ServerHttp.layerAttachmentUploadRoute).pipe(
282 Effect.provide(Layer.merge(layerCore, layerUploads)),
283 );
284 return {
285 ...served,
286 orchestrator: Context.get(core, Orchestrator.OrchestratorV2),
287 settings: Context.get(core, ServerSettings.ServerSettingsService),
288 };
289 });
290​
291/** The laptop: a real orchestrator with a thread mid-conversation, linked to the box. */
292const makeLaptop = (
293 laptopRepo: string,
294 captured: Ref.Ref<ReadonlyArray<CapturedTurn>>,
295 holdTurn?: Effect.Effect<void>,
296 lostImportReplies?: Ref.Ref<number>,
297 pauseFirstPack?: Effect.Effect<void>,
298) =>
299 Effect.gen(function* () {
300 const linking = yield* layerLinkingEnvironment(laptop).pipe(Layer.build);
301 const core = yield* layerOrchestration("laptop", laptopRepo, captured, holdTurn).pipe(
302 Layer.provideMerge(
303 ServerSecretStore.layer.pipe(
304 Layer.provideMerge(
305 ServerConfig.layerTest(process.cwd(), { prefix: "t3-handoff-laptop-" }),
306 ),
307 ),
308 ),
309 Layer.provideMerge(NodeServices.layer),
310 Layer.build,
311 );
312 const forwarding =
313 lostImportReplies === undefined
314 ? PeerForwarding.layer
315 : Layer.effect(
316 PeerForwarding.PeerForwarding,
317 Effect.gen(function* () {
318 const peer = yield* PeerForwarding.PeerForwarding;
319 return PeerForwarding.PeerForwarding.of({
320 ...peer,
321 call: (scope, tool, environmentId, input) =>
322 peer.call(scope, tool, environmentId, input).pipe(
323 Effect.tap(() =>
324 tool.name === "t3_thread_import"
325 ? Ref.getAndUpdate(lostImportReplies, (count) =>
326 Math.max(0, count - 1),
327 ).pipe(
328 Effect.flatMap((count) =>
329 count > 0
330 ? Effect.fail(
331 new OrchestratorMcpFailure({
332 code: "orchestration_error",
333 message: "The linked environment stopped answering.",
334 }),
335 )
336 : Effect.void,
337 ),
338 )
339 : Effect.void,
340 ),
341 ),
342 });
343 }),
344 ).pipe(Layer.provide(PeerForwarding.layer));
345 const handoffGit =
346 pauseFirstPack === undefined
347 ? HandoffGit.layer
348 : Layer.effect(
349 HandoffGit.HandoffGit,
350 Effect.gen(function* () {
351 const git = yield* HandoffGit.HandoffGit;
352 const first = yield* Ref.make(true);
353 return HandoffGit.HandoffGit.of({
354 ...git,
355 pack: (input) =>
356 Ref.getAndSet(first, false).pipe(
357 Effect.flatMap((pause) => (pause ? pauseFirstPack : Effect.void)),
358 Effect.andThen(git.pack(input)),
359 ),
360 });
361 }),
362 ).pipe(Layer.provide(HandoffGit.layer));
363 const layerHere = ThreadHandoff.layer.pipe(
364 Layer.provideMerge(forwarding),
365 Layer.provide(handoffGit),
366 Layer.provide(
367 layerProjects([projectAt("project:laptop", laptopRepo)]).pipe(
368 Layer.provideMerge(RepositoryIdentityResolver.layer),
369 ),
370 ),
371 Layer.provide(
372 Layer.succeed(ServerEnvironment.ServerEnvironment, {
373 getEnvironmentId: Effect.succeed(laptop.environmentId),
374 getDescriptor: Effect.succeed(laptop),
375 }),
376 ),
377 Layer.provide(Layer.succeedContext(linking)),
378 Layer.provide(Layer.succeedContext(core)),
379 Layer.provide(VcsProcess.layer),
380 Layer.provide(NodeCrypto.layer),
381 // Uploads go to the box's own address, not the test server's.
382 Layer.provide(FetchHttpClient.layer),
383 Layer.provideMerge(NodeServices.layer),
384 Layer.fresh,
385 );
386 const here = yield* Layer.build(layerHere);
387 return {
388 links: Context.get(linking, PeerLinks.PeerLinks),
389 orchestrator: Context.get(core, Orchestrator.OrchestratorV2),
390 threads: Context.get(core, ThreadManagement.ThreadManagementService),
391 handoff: Context.get(here, ThreadHandoff.ThreadHandoff),
392 };
393 });
394​
395const threadId = ThreadId.make("thread:laptop-login");
396​
397/** The laptop's thread: one finished turn about the bug, on the laptop's checkout. */
398const createThread = (
399 laptopEnv: Effect.Success<ReturnType<typeof makeLaptop>>,
400 laptopRepo: string,
401) =>
402 laptopEnv.orchestrator.dispatch({
403 type: "thread.create",
404 createdBy: "user",
405 creationSource: "web",
406 commandId: CommandId.make("command:create:laptop-login"),
407 threadId,
408 projectId: ProjectId.make("project:laptop"),
409 title: "Flaky login test",
410 modelSelection,
411 runtimeMode: "full-access",
412 interactionMode: "default",
413 branch: null,
414 worktreePath: laptopRepo,
415 });
416​
417const seedThread = (laptopEnv: Effect.Success<ReturnType<typeof makeLaptop>>, laptopRepo: string) =>
418 Effect.gen(function* () {
419 yield* laptopEnv.orchestrator.dispatch({
420 type: "thread.create",
421 createdBy: "user",
422 creationSource: "web",
423 commandId: CommandId.make("command:create:laptop-login"),
424 threadId,
425 projectId: ProjectId.make("project:laptop"),
426 title: "Flaky login test",
427 modelSelection,
428 runtimeMode: "full-access",
429 interactionMode: "default",
430 branch: null,
431 worktreePath: laptopRepo,
432 });
433 yield* laptopEnv.orchestrator.dispatch({
434 type: "message.dispatch",
435 createdBy: "user",
436 creationSource: "web",
437 commandId: CommandId.make("command:send:laptop-login"),
438 threadId,
439 messageId: MessageId.make("message:laptop-login:1"),
440 text: "LAPTOP_QUESTION: why does the login test flake?",
441 attachments: [],
442 dispatchMode: { type: "start_immediately" },
443 });
444 yield* idle(laptopEnv.orchestrator, threadId);
445 });
446​
447/** The thread's projection once `done` holds, read after each of its events. */
448const until = (
449 orchestrator: Orchestrator.OrchestratorV2["Service"],
450 id: ThreadId,
451 done: (projection: OrchestrationV2ThreadProjection) => boolean,
452) =>
453 orchestrator.streamStoredEvents.pipe(
454 Stream.filter((stored) => stored.event.threadId === id),
455 Stream.mapEffect(() => orchestrator.getThreadProjection(id)),
456 Stream.filter(done),
457 Stream.runHead,
458 Effect.flatMap(Effect.fromOption),
459 Effect.orDie,
460 );
461​
462const idle = (orchestrator: Orchestrator.OrchestratorV2["Service"], id: ThreadId) =>
463 until(
464 orchestrator,
465 id,
466 (projection) =>
467 projection.runs.length > 0 &&
468 projection.runs.every(
469 (run) => !["queued", "starting", "running", "waiting", "preparing"].includes(run.status),
470 ),
471 );
472​
473it.live("finishes the original thread move after disconnecting during packaging", () =>
474 Effect.scoped(
475 Effect.gen(function* () {
476 const path = yield* Path.Path;
477 const { root, laptopRepo, boxRepo } = yield* makeRepos;
478 const turns = yield* Ref.make<ReadonlyArray<CapturedTurn>>([]);
479 const b = yield* serveBox(boxRepo, path.join(root, "box-state"), turns);
480 const packaging = yield* Deferred.make<void>();
481 const resume = yield* Deferred.make<void>();
482 const a = yield* makeLaptop(
483 laptopRepo,
484 turns,
485 undefined,
486 undefined,
487 Deferred.succeed(packaging, undefined).pipe(Effect.andThen(Deferred.await(resume))),
488 );
489 yield* linkTo(a.links, b, "full-access");
490 yield* seedThread(a, laptopRepo);
491​
492 const request = yield* a.handoff
493 .start({
494 threadId,
495 environmentId: box.environmentId,
496 projectId: ProjectId.make("project:box"),
497 })
498 .pipe(Effect.forkScoped);
499 yield* Deferred.await(packaging);
500 const source = yield* a.orchestrator.getThreadProjection(threadId);
501 // A WebSocket disconnect interrupts its outstanding request.
502 const disconnect = yield* Fiber.interrupt(request).pipe(
503 Effect.forkScoped({ startImmediately: true }),
504 );
505 yield* Deferred.succeed(resume, undefined);
506 yield* Fiber.join(disconnect);
507​
508 const after = yield* until(
509 a.orchestrator,
510 threadId,
511 ({ thread }) => thread.handoff?.state === "departed",
512 );
513 expect(after.thread.handoff?.handoffId).toBe(source.thread.handoff?.handoffId);
514 }),
515 ).pipe(Effect.provide(layerTestHost)),
516);
517​
518it.live.each([0, 2])(
519 "a thread moves with its conversation and work after %i lost import replies",
520 (lost) =>
521 Effect.scoped(
522 Effect.gen(function* () {
523 const fileSystem = yield* FileSystem.FileSystem;
524 const path = yield* Path.Path;
525 const { root, laptopRepo, boxRepo } = yield* makeRepos;
526 const boxTurns = yield* Ref.make<ReadonlyArray<CapturedTurn>>([]);
527 const laptopTurns = yield* Ref.make<ReadonlyArray<CapturedTurn>>([]);
528 const b = yield* serveBox(boxRepo, path.join(root, "box-state"), boxTurns);
529 const dropped = yield* Ref.make(lost);
530 const a = yield* makeLaptop(laptopRepo, laptopTurns, undefined, dropped);
531 yield* linkTo(a.links, b, "full-access");
532 yield* seedThread(a, laptopRepo);
533​
534 // The thread's work on the laptop: an unpushed commit, then uncommitted edits.
535 yield* git(laptopRepo, ["checkout", "--quiet", "-b", "fix/login"]);
536 yield* fileSystem.writeFileString(
537 path.join(laptopRepo, "app.ts"),
538 "export const version = 2;\n",
539 );
540 yield* git(laptopRepo, ["commit", "--quiet", "-am", "unpushed fix"]);
541 yield* fileSystem.writeFileString(
542 path.join(laptopRepo, "app.ts"),
543 "export const version = 3;\n",
544 );
545 yield* fileSystem.writeFileString(path.join(laptopRepo, "notes.md"), "# findings\n");
546​
547 expect(yield* a.handoff.options(threadId)).toEqual([
548 {
549 environmentId: box.environmentId,
550 label: "Box",
551 projectId: "project:box",
552 reason: null,
553 },
554 ]);
555 const start = a.handoff.start({ threadId, environmentId: box.environmentId });
556 if (lost > 0) {
557 yield* Effect.flip(start);
558 const before = yield* a.orchestrator.getThreadProjection(threadId);
559 expect(before.thread.handoff?.state).toBe("departing");
560 yield* a.handoff.settle(threadId);
561 } else {
562 yield* start;
563 }
564 const source = yield* a.orchestrator.getThreadProjection(threadId);
565 const moved = source.thread.handoff;
566 expect(moved?.state).toBe("departed");
567 if (moved?.state !== "departed") return;
568​
569 // On the box: the thread, its history, its first run with that context.
570 const there = yield* idle(b.orchestrator, moved.threadId);
571 expect(there.thread.historyOrigin).toBe("v1_import");
572 expect(there.messages.some((message) => message.text.includes("LAPTOP_QUESTION"))).toBe(
573 true,
574 );
575 const [firstTurn] = yield* Ref.get(boxTurns);
576 expect(firstTurn?.text).toContain("LAPTOP_QUESTION");
577 expect(firstTurn?.text).toContain("Continue where it left off.");
578 // ...in a new worktree on the branch, with the commit and the edits.
579 const worktree = there.thread.worktreePath!;
580 expect(there.thread.branch).toBe("fix/login");
581 expect((yield* git(worktree, ["log", "-1", "--format=%s"])).trim()).toBe("unpushed fix");
582 expect(yield* fileSystem.readFileString(path.join(worktree, "app.ts"))).toBe(
583 "export const version = 3;\n",
584 );
585 expect(yield* fileSystem.readFileString(path.join(worktree, "notes.md"))).toBe(
586 "# findings\n",
587 );
588​
589 // On the laptop: read-only, pointing at the box.
590 const here = yield* a.orchestrator.getThreadProjection(threadId);
591 expect(here.thread.handoff).toMatchObject({ state: "departed", threadId: moved.threadId });
592 const refused = yield* a.orchestrator
593 .dispatch({
594 type: "message.dispatch",
595 createdBy: "user",
596 creationSource: "web",
597 commandId: CommandId.make("command:send:after-move"),
598 threadId,
599 messageId: MessageId.make("message:after-move"),
600 text: "Still here?",
601 attachments: [],
602 dispatchMode: { type: "start_immediately" },
603 })
604 .pipe(Effect.flip);
605 expect(refused.message).toBe("This thread moved to Box. Continue it there.");
606 }),
607 ).pipe(Effect.provide(layerTestHost)),
608);
609​
610it.live("a thread on a branch ending in a nonbreaking space lands on that branch", () =>
611 Effect.scoped(
612 Effect.gen(function* () {
613 const path = yield* Path.Path;
614 const { root, laptopRepo, boxRepo } = yield* makeRepos;
615 const turns = yield* Ref.make<ReadonlyArray<CapturedTurn>>([]);
616 const b = yield* serveBox(boxRepo, path.join(root, "box-state"), turns);
617 const a = yield* makeLaptop(laptopRepo, turns);
618 yield* linkTo(a.links, b, "full-access");
619 yield* seedThread(a, laptopRepo);
620 const branch = "topic\u00a0";
621 yield* git(laptopRepo, ["checkout", "--quiet", "-b", branch]);
622​
623 yield* a.handoff.start({ threadId, environmentId: box.environmentId });
624 const moved = (yield* a.orchestrator.getThreadProjection(threadId)).thread.handoff;
625 if (moved?.state !== "departed") return expect.fail(`not departed: ${moved?.state}`);
626​
627 const there = yield* idle(b.orchestrator, moved.threadId);
628 expect(there.thread.branch).toBe(branch);
629 expect(yield* git(there.thread.worktreePath!, ["symbolic-ref", "--short", "HEAD"])).toBe(
630 `${branch}\n`,
631 );
632 }),
633 ).pipe(Effect.provide(layerTestHost)),
634);
635​
636it.live("a move offers every checkout there that has the thread's repository", () =>
637 Effect.scoped(
638 Effect.gen(function* () {
639 const path = yield* Path.Path;
640 const { root, laptopRepo, boxRepo } = yield* makeRepos;
641 const secondRepo = path.join(root, "box-second");
642 yield* git(root, ["clone", "--quiet", boxRepo, secondRepo]);
643 yield* git(secondRepo, [
644 "remote",
645 "set-url",
646 "origin",
647 "https://github.com/acme/handoff-app.git",
648 ]);
649 const turns = yield* Ref.make<ReadonlyArray<CapturedTurn>>([]);
650 const b = yield* serveBox(boxRepo, path.join(root, "box-state"), turns, [
651 projectAt("project:box", boxRepo),
652 projectAt("project:box-second", secondRepo),
653 ]);
654 const a = yield* makeLaptop(laptopRepo, turns);
655 yield* linkTo(a.links, b, "full-access");
656 yield* seedThread(a, laptopRepo);
657​
658 expect(yield* a.handoff.options(threadId)).toMatchObject([
659 {
660 environmentId: box.environmentId,
661 projectId: null,
662 projectSelectionRequired: true,
663 projectChoices: [
664 { id: "project:box", workspaceRoot: boxRepo },
665 { id: "project:box-second", workspaceRoot: secondRepo },
666 ],
667 },
668 ]);
669 }),
670 ).pipe(Effect.provide(layerTestHost)),
671);
672​
673it.live("a thread moved over a limited link stays fenced until its user there adopts it", () =>
674 Effect.scoped(
675 Effect.gen(function* () {
676 const path = yield* Path.Path;
677 const { root, laptopRepo, boxRepo } = yield* makeRepos;
678 const turns = yield* Ref.make<ReadonlyArray<CapturedTurn>>([]);
679 const b = yield* serveBox(boxRepo, path.join(root, "box-state"), turns);
680 const a = yield* makeLaptop(laptopRepo, turns);
681 yield* linkTo(a.links, b, "auto");
682 yield* seedThread(a, laptopRepo);
683 yield* git(laptopRepo, ["checkout", "--quiet", "-b", "fix/login"]);
684​
685 const moved = yield* a.handoff.start({ threadId, environmentId: box.environmentId });
686 if (moved.state !== "departed") return yield* Effect.die("not departed");
687 const origin = b.orchestrator
688 .getThreadProjection(moved.threadId)
689 .pipe(Effect.map((projection) => projection.thread.linkOrigin));
690 // The box cannot tell that a person accepted the move, so the link's fence holds.
691 const arrived = yield* origin;
692 // The thread ran in full access on the laptop; here it gets the most its link allows.
693 expect((yield* b.orchestrator.getThreadProjection(moved.threadId)).thread.runtimeMode).toBe(
694 "auto",
695 );
696 expect(arrived?.access).toBe("auto");
697 expect(arrived !== undefined && linkOriginIsFenced(arrived)).toBe(true);
698​
699 const adopt = b.orchestrator.dispatch({
700 type: "thread.link-origin.adopt",
701 commandId: CommandId.make("command:adopt"),
702 threadId: moved.threadId,
703 });
704 yield* adopt;
705 const adopted = yield* origin;
706 expect(adopted).toMatchObject({ access: "auto", adopted: true });
707 expect(adopted !== undefined && linkOriginIsFenced(adopted)).toBe(false);
708 }),
709 ).pipe(Effect.provide(layerTestHost)),
710);
711​
712it.live("a thread still held to a limited link cannot be moved on until it is adopted", () =>
713 Effect.scoped(
714 Effect.gen(function* () {
715 const path = yield* Path.Path;
716 const { root, laptopRepo, boxRepo } = yield* makeRepos;
717 const turns = yield* Ref.make<ReadonlyArray<CapturedTurn>>([]);
718 const b = yield* serveBox(boxRepo, path.join(root, "box-state"), turns);
719 const a = yield* makeLaptop(laptopRepo, turns);
720 // The link onward is broader than the one this thread came in over.
721 yield* linkTo(a.links, b, "full-access");
722 yield* a.orchestrator.dispatch({
723 type: "thread.create",
724 createdBy: "agent",
725 creationSource: "mcp",
726 commandId: CommandId.make("command:create:fenced"),
727 threadId,
728 projectId: ProjectId.make("project:laptop"),
729 title: "Came over a limited link",
730 modelSelection,
731 runtimeMode: "auto",
732 interactionMode: "default",
733 branch: null,
734 worktreePath: laptopRepo,
735 linkOrigin: { sessionId: "session-elsewhere", label: "Elsewhere", access: "auto" },
736 });
737​
738 const refused = yield* a.handoff
739 .start({ threadId, environmentId: box.environmentId })
740 .pipe(Effect.flip);
741 expect(refused.message).toContain("limited link");
742 expect((yield* a.orchestrator.getThreadProjection(threadId)).thread.handoff).toBeUndefined();
743​
744 yield* a.orchestrator.dispatch({
745 type: "thread.link-origin.adopt",
746 commandId: CommandId.make("command:adopt:fenced"),
747 threadId,
748 });
749 const moved = yield* a.handoff.start({ threadId, environmentId: box.environmentId });
750 expect(moved.state).toBe("departed");
751 }),
752 ).pipe(Effect.provide(layerTestHost)),
753);
754​
755it.live.each(["branch diverged", "worktree unavailable"] as const)(
756 "a move refused because the %s releases the source thread",
757 (reason) =>
758 Effect.scoped(
759 Effect.gen(function* () {
760 const fileSystem = yield* FileSystem.FileSystem;
761 const path = yield* Path.Path;
762 const { root, laptopRepo, boxRepo } = yield* makeRepos;
763 const turns = yield* Ref.make<ReadonlyArray<CapturedTurn>>([]);
764 const b = yield* serveBox(boxRepo, path.join(root, "box-state"), turns);
765 const a = yield* makeLaptop(laptopRepo, turns);
766 yield* linkTo(a.links, b, "full-access");
767 yield* seedThread(a, laptopRepo);
768 if (reason === "branch diverged") {
769 // The box has its own commit on the branch the laptop's thread is on.
770 yield* git(laptopRepo, ["checkout", "--quiet", "-b", "fix/login"]);
771 yield* fileSystem.writeFileString(
772 path.join(laptopRepo, "app.ts"),
773 "export const version = 2;\n",
774 );
775 yield* git(laptopRepo, ["commit", "--quiet", "-am", "laptop fix"]);
776 yield* git(boxRepo, ["checkout", "--quiet", "-b", "fix/login"]);
777 yield* fileSystem.writeFileString(path.join(boxRepo, "box.ts"), "export const b = 1;\n");
778 yield* git(boxRepo, ["add", "."]);
779 yield* git(boxRepo, ["commit", "--quiet", "-m", "box fix"]);
780 yield* git(boxRepo, ["checkout", "--quiet", "main"]);
781 } else {
782 const checkoutParent = path.join(root, "blocked-checkout");
783 yield* fileSystem.writeFileString(checkoutParent, "not a directory");
784 yield* b.settings.updateSettings({ worktreesDirectory: checkoutParent });
785 }
786​
787 const failed = yield* a.handoff
788 .start({ threadId, environmentId: box.environmentId })
789 .pipe(Effect.flip);
790 expect(failed.message).toContain(
791 reason === "branch diverged"
792 ? "commits the handed-off work lacks"
793 : "A checkout already sits where this one would go.",
794 );
795 const here = yield* a.orchestrator.getThreadProjection(threadId);
796 expect(here.thread.handoff).toMatchObject({ state: "failed" });
797 // Released: the thread takes turns here again.
798 yield* a.orchestrator.dispatch({
799 type: "message.dispatch",
800 createdBy: "user",
801 creationSource: "web",
802 commandId: CommandId.make("command:send:after-failure"),
803 threadId,
804 messageId: MessageId.make("message:after-failure"),
805 text: "Keep going here then.",
806 attachments: [],
807 dispatchMode: { type: "start_immediately" },
808 });
809 // Nothing was created on the box.
810 expect(
811 (yield* b.orchestrator.getShellSnapshot()).threads.filter((shell) =>
812 shell.title.includes("Flaky"),
813 ),
814 ).toEqual([]);
815 }),
816 ).pipe(Effect.provide(layerTestHost)),
817);
818​
819it.live(
820 "an agent's move waits for the user to accept and for its turn to end, and a message before then cancels it",
821 () =>
822 Effect.scoped(
823 Effect.gen(function* () {
824 const path = yield* Path.Path;
825 const { root, laptopRepo, boxRepo } = yield* makeRepos;
826 yield* git(boxRepo, ["remote", "remove", "origin"]);
827 const turns = yield* Ref.make<ReadonlyArray<CapturedTurn>>([]);
828 const b = yield* serveBox(boxRepo, path.join(root, "box-state"), turns);
829 // The laptop's turns stay open until the test lets one finish; each
830 // release lets exactly one waiting turn end.
831 const releases = yield* Queue.unbounded<void>();
832 const hold = Queue.take(releases);
833 const releaseTurn = Queue.offer(releases, undefined);
834 const a = yield* makeLaptop(laptopRepo, turns, hold);
835 yield* linkTo(a.links, b, "full-access");
836 yield* a.handoff.start_();
837 yield* createThread(a, laptopRepo);
838 expect(yield* a.handoff.options(threadId)).toMatchObject([
839 { environmentId: box.environmentId, projectId: null, projectSelectionRequired: true },
840 ]);
841 const send = (id: string, text: string) =>
842 a.orchestrator.dispatch({
843 type: "message.dispatch",
844 createdBy: "user",
845 creationSource: "web",
846 commandId: CommandId.make(`command:send:${id}`),
847 threadId,
848 messageId: MessageId.make(`message:${id}`),
849 text,
850 attachments: [],
851 dispatchMode: { type: "start_immediately" },
852 });
853 const handoffState = a.orchestrator
854 .getThreadProjection(threadId)
855 .pipe(Effect.map((projection) => projection.thread.handoff?.state ?? null));
856 // The agent only asks, with a card in its turn; the user answers it in a client.
857 const askToMove = a.handoff.propose(
858 {
859 environmentId: laptop.environmentId,
860 requestNamespace: "test",
861 thread: {
862 threadId,
863 providerSessionId: "session",
864 providerInstanceId: modelSelection.instanceId,
865 },
866 client: undefined,
867 capabilities: new Set(["orchestration"]),
868 issuedAt: 0,
869 },
870 {
871 environmentId: EnvironmentId.make("unlinked-suggestion"),
872 continuationPrompt: "SELF_HANDOFF_CONTINUE: run the e2e suite there.",
873 },
874 );
875 const cards = a.orchestrator
876 .getThreadProjection(threadId)
877 .pipe(
878 Effect.map((projection) =>
879 projection.turnItems.flatMap((item) =>
880 item.type === "handoff_request"
881 ? [{ id: item.id, status: item.handoffStatus }]
882 : [],
883 ),
884 ),
885 );
886 const openCard = cards.pipe(
887 Effect.map((all) => all.filter((card) => card.status === "pending")),
888 Effect.flatMap((open) =>
889 open.length === 1 ? Effect.succeed(open[0]!.id) : Effect.die("not one open card"),
890 ),
891 );
892 const accept = Effect.flatMap(openCard, (turnItemId) =>
893 a.handoff.start({
894 threadId,
895 environmentId: box.environmentId,
896 projectId: ProjectId.make("project:box"),
897 turnItemId,
898 }),
899 );
900 const runTurn = (id: string, text: string) =>
901 send(id, text).pipe(
902 Effect.andThen(
903 until(a.orchestrator, threadId, (projection) =>
904 projection.runs.some((run) => run.status === "running"),
905 ),
906 ),
907 );
908​
909 // Mid-turn, the agent asks to move: nothing moves yet.
910 yield* runTurn("turn-1", "Wrap up and move this to the box.");
911 expect(yield* askToMove).toMatchObject({ environmentId: "unlinked-suggestion" });
912 expect(yield* handoffState).toBe(null);
913 expect((yield* accept).state).toBe("pending");
914 expect((yield* cards).map((card) => card.status)).toEqual(["accepted"]);
915 const [accepted] = (yield* a.orchestrator.getThreadProjection(threadId)).turnItems.filter(
916 (item) => item.type === "handoff_request",
917 );
918 if (accepted?.runId == null || accepted.nodeId == null) {
919 return yield* Effect.die("The accepted card lost its run or node.");
920 }
921 const lateDecline = yield* Effect.flip(
922 a.orchestrator.dispatch({
923 type: "handoff_request.record",
924 commandId: CommandId.make("command:handoff:late-decline"),
925 threadId,
926 runId: accepted.runId,
927 nodeId: accepted.nodeId,
928 turnItemId: accepted.id,
929 handoffStatus: "declined",
930 }),
931 );
932 expect(lateDecline).toMatchObject({
933 cause: "This request to move the thread was already answered.",
934 });
935 // An agent the user works through steers the same turn before it ends:
936 // new instructions win.
937 yield* until(a.orchestrator, threadId, (projection) =>
938 projection.providerTurns.some((turn) => turn.status === "running"),
939 );
940 const running = (yield* a.orchestrator.getThreadProjection(threadId)).runs.find(
941 (run) => run.status === "running",
942 );
943 if (running === undefined) return yield* Effect.die("no running turn");
944 yield* a.orchestrator.dispatch({
945 type: "message.dispatch",
946 createdBy: "agent",
947 creationSource: "web",
948 commandId: CommandId.make("command:send:steer"),
949 threadId,
950 messageId: MessageId.make("message:steer"),
951 text: "Actually, stay here.",
952 attachments: [],
953 dispatchMode: { type: "steer_active", targetRunId: running.id },
954 });
955 yield* releaseTurn;
956 yield* until(
957 a.orchestrator,
958 threadId,
959 (projection) => projection.thread.handoff === undefined,
960 );
961 yield* idle(a.orchestrator, threadId);
962 expect(yield* handoffState).toBe(null);
963​
964 // A message queued behind the turn calls the move off too, and then gets its turn.
965 yield* runTurn("turn-queued", "Ask once more.");
966 yield* askToMove;
967 expect((yield* accept).state).toBe("pending");
968 yield* a.orchestrator.dispatch({
969 type: "message.dispatch",
970 createdBy: "user",
971 creationSource: "web",
972 commandId: CommandId.make("command:send:queued"),
973 threadId,
974 messageId: MessageId.make("message:queued"),
975 text: "Do this here instead.",
976 attachments: [],
977 dispatchMode: { type: "queue_after_active" },
978 });
979 yield* releaseTurn;
980 yield* until(
981 a.orchestrator,
982 threadId,
983 (projection) =>
984 projection.thread.handoff === undefined &&
985 projection.runs.some(
986 (run) => run.userMessageId === "message:queued" && run.status === "running",
987 ),
988 );
989 yield* releaseTurn;
990 yield* idle(a.orchestrator, threadId);
991​
992 // Declined, the thread stays and the card cannot be answered again. A newer ask
993 // replaces one still open.
994 yield* runTurn("turn-2", "Ask again.");
995 yield* askToMove;
996 const declined = yield* openCard;
997 yield* a.handoff.cancel({ threadId, turnItemId: declined });
998 const rejectedMove = yield* Effect.flip(
999 a.orchestrator.dispatch({
1000 type: "thread.handoff.update",
1001 commandId: CommandId.make("command:handoff:declined"),
1002 threadId,
1003 expected: null,
1004 handoff: {
1005 state: "pending",
1006 handoffId: "declined-move",
1007 environmentId: box.environmentId,
1008 label: "Box",
1009 projectId: ProjectId.make("project:box"),
1010 acceptedAt: "2026-01-01T00:00:00.000Z",
1011 },
1012 acceptRequestId: declined,
1013 }),
1014 );
1015 expect(rejectedMove).toMatchObject({
1016 cause: "This request to move the thread was already answered.",
1017 });
1018 expect(yield* handoffState).toBe(null);
1019 expect(
1020 yield* Effect.flip(a.handoff.cancel({ threadId, turnItemId: declined })),
1021 ).toMatchObject({ reason: "refused" });
1022 yield* askToMove;
1023 yield* askToMove;
1024 expect((yield* cards).map((card) => card.status)).toEqual([
1025 "accepted",
1026 "accepted",
1027 "declined",
1028 "cancelled",
1029 "pending",
1030 ]);
1031 // An unanswered ask moves nothing and holds nothing up: the thread still takes turns.
1032 yield* releaseTurn;
1033 yield* idle(a.orchestrator, threadId);
1034 expect(yield* handoffState).toBe(null);
1035 yield* runTurn("turn-3", "Now move it.");
1036 // Accepted with nothing after it: it moves once the turn ends.
1037 expect((yield* accept).state).toBe("pending");
1038 // Settling it while the turn still runs, as a restart's sweep does, leaves it waiting.
1039 yield* a.handoff.settle(threadId);
1040 expect(yield* handoffState).toBe("pending");
1041 yield* releaseTurn;
1042 yield* until(
1043 a.orchestrator,
1044 threadId,
1045 (projection) => projection.thread.handoff?.state === "departed",
1046 );
1047 const moved = (yield* a.orchestrator.getThreadProjection(threadId)).thread.handoff;
1048 if (moved?.state !== "departed") return yield* Effect.die("not departed");
1049 yield* idle(b.orchestrator, moved.threadId);
1050 // The box's first turn is the agent's own continuation.
1051 expect((yield* Ref.get(turns)).at(-1)?.text).toContain("SELF_HANDOFF_CONTINUE");
1052 }),
1053 ).pipe(Effect.provide(layerTestHost)),
1055​
1056it.live("a restart does not settle turns that ended before it", () =>
1057 Effect.scoped(
1058 Effect.gen(function* () {
1059 const { laptopRepo } = yield* makeRepos;
1060 const turns = yield* Ref.make<ReadonlyArray<CapturedTurn>>([]);
1061 const releases = yield* Queue.unbounded<void>();
1062 const a = yield* makeLaptop(laptopRepo, turns, Queue.take(releases));
1063 // History from before the restart: one finished turn, no move.
1064 yield* Queue.offer(releases, undefined);
1065 yield* seedThread(a, laptopRepo);
1066 // A finished turn writes two terminal run updates; both belong to the history.
1067 yield* a.orchestrator.streamStoredEvents.pipe(
1068 Stream.filter(
1069 (stored) =>
1070 stored.event.type === "run.updated" && stored.event.payload.status === "completed",
1071 ),
1072 Stream.take(2),
1073 Stream.runDrain,
1074 Effect.orDie,
1075 );
1076​
1077 let turnEnded = false;
1078 const settles = yield* Queue.unbounded<{ readonly afterNewTurn: boolean }>();
1079 const tracer = Tracer.make({
1080 span: (options) => {
1081 if (options.name === "ThreadHandoff.settle") {
1082 Queue.offerUnsafe(settles, { afterNewTurn: turnEnded });
1084 return new Tracer.NativeSpan(options);
1085 },
1086 });
1087 yield* a.handoff.start_().pipe(Effect.withTracer(tracer));
1088 yield* a.orchestrator.dispatch({
1089 type: "message.dispatch",
1090 createdBy: "user",
1091 creationSource: "web",
1092 commandId: CommandId.make("command:send:after-restart"),
1093 threadId,
1094 messageId: MessageId.make("message:after-restart"),
1095 text: "One more turn after the restart.",
1096 attachments: [],
1097 dispatchMode: { type: "start_immediately" },
1098 });
1099 yield* until(a.orchestrator, threadId, (projection) =>
1100 projection.runs.some((run) => run.status === "running"),
1101 );
1102 turnEnded = true;
1103 yield* Queue.offer(releases, undefined);
1104 yield* idle(a.orchestrator, threadId);
1105 // Only the turn that ended after start_ should be settled, not the replayed history.
1106 expect(yield* Queue.take(settles)).toEqual({ afterNewTurn: true });
1107 }),
1108 ).pipe(Effect.provide(layerTestHost)),
1110​
1111it.live("settling a thread with no move reads no runs or messages", () =>
1112 Effect.scoped(
1113 Effect.gen(function* () {
1114 const { laptopRepo } = yield* makeRepos;
1115 const turns = yield* Ref.make<ReadonlyArray<CapturedTurn>>([]);
1116 const releases = yield* Queue.unbounded<void>();
1117 const a = yield* makeLaptop(laptopRepo, turns, Queue.take(releases));
1118 yield* Queue.offer(releases, undefined);
1119 yield* seedThread(a, laptopRepo);
1120 expect((yield* a.orchestrator.getThreadProjection(threadId)).thread.handoff).toBe(undefined);
1121​
1122 const spans: Array<Tracer.NativeSpan> = [];
1123 const tracer = Tracer.make({
1124 span: (options) => {
1125 const span = new Tracer.NativeSpan(options);
1126 spans.push(span);
1127 return span;
1128 },
1129 });
1130 // Every turn that ends settles its thread; a thread with no move should only read its shell.
1131 yield* a.handoff.settle(threadId).pipe(Effect.withTracer(tracer));
1132 const queries = spans
1133 .map((span) => span.attributes.get("db.query.text"))
1134 .filter((query): query is string => typeof query === "string");
1135 expect(queries.length).toBeGreaterThan(0);
1136 expect(queries.filter((query) => /projection_(runs|messages)\b/.test(query))).toEqual([]);
1137 }),
1138 ).pipe(Effect.provide(layerTestHost)),