@@ -177,6 +177,9 @@ describe("ProviderCommandReactor", () => { |
177 | 177 | const baseDir = |
178 | 178 | input?.baseDir ?? NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3code-reactor-")); |
179 | 179 | createdBaseDirs.add(baseDir); |
| 180 | + const workspaceRoot = NodePath.join(baseDir, "provider-project"); |
| 181 | + const worktreeRoot = NodePath.join(baseDir, "provider-project-worktree"); |
| 182 | + NodeFS.mkdirSync(workspaceRoot, { recursive: true }); |
180 | 183 | const { stateDir } = deriveServerPathsSync(baseDir, undefined); |
181 | 184 | createdStateDirs.add(stateDir); |
182 | 185 | const runtimeEventPubSub = Effect.runSync(PubSub.unbounded<ProviderRuntimeEvent>()); |
@@ -290,7 +293,10 @@ describe("ProviderCommandReactor", () => { |
290 | 293 | const pruneWorktrees = vi.fn((_: { readonly cwd: string }) => Effect.void); |
291 | 294 | const createWorktree = vi.fn( |
292 | 295 | (input: { readonly refName: string; readonly path: string | null }) => |
293 | | - Effect.succeed({ worktree: { path: input.path ?? "", refName: input.refName } }), |
| 296 | + Effect.sync(() => { |
| 297 | + if (input.path) NodeFS.mkdirSync(input.path, { recursive: true }); |
| 298 | + return { worktree: { path: input.path ?? "", refName: input.refName } }; |
| 299 | + }), |
294 | 300 | ); |
295 | 301 | const refreshStatus = vi.fn((_: string) => |
296 | 302 | Effect.succeed({ |
@@ -461,7 +467,7 @@ describe("ProviderCommandReactor", () => { |
461 | 467 | commandId: CommandId.make("cmd-project-create"), |
462 | 468 | projectId: asProjectId("project-1"), |
463 | 469 | title: "Provider Project", |
464 | | - workspaceRoot: "/tmp/provider-project", |
| 470 | + workspaceRoot, |
465 | 471 | defaultModelSelection: modelSelection, |
466 | 472 | createdAt: now, |
467 | 473 | }), |
@@ -544,6 +550,8 @@ describe("ProviderCommandReactor", () => { |
544 | 550 | generateBranchName, |
545 | 551 | generateThreadTitle, |
546 | 552 | runtimeSessions, |
| 553 | + workspaceRoot, |
| 554 | + worktreeRoot, |
547 | 555 | stateDir, |
548 | 556 | drain, |
549 | 557 | runEffect, |
@@ -578,7 +586,7 @@ describe("ProviderCommandReactor", () => { |
578 | 586 | await waitFor(() => harness.sendTurn.mock.calls.length === 1); |
579 | 587 | expect(harness.startSession.mock.calls[0]?.[0]).toEqual(ThreadId.make("thread-1")); |
580 | 588 | expect(harness.startSession.mock.calls[0]?.[1]).toMatchObject({ |
581 | | - cwd: "/tmp/provider-project", |
| 589 | + cwd: harness.workspaceRoot, |
582 | 590 | modelSelection: { |
583 | 591 | instanceId: ProviderInstanceId.make("codex"), |
584 | 592 | model: "gpt-5-codex", |
@@ -593,6 +601,50 @@ describe("ProviderCommandReactor", () => { |
593 | 601 | expect(thread?.session?.runtimeMode).toBe("approval-required"); |
594 | 602 | }); |
595 | 603 |
|
| 604 | + it("reports a missing workspace before starting the provider", async () => { |
| 605 | + const harness = await createHarness(); |
| 606 | + const now = "2026-01-01T00:00:00.000Z"; |
| 607 | + NodeFS.rmSync(harness.workspaceRoot, { recursive: true }); |
| 608 | + |
| 609 | + await Effect.runPromise( |
| 610 | + harness.engine.dispatch({ |
| 611 | + type: "thread.turn.start", |
| 612 | + commandId: CommandId.make("cmd-turn-start-missing-workspace"), |
| 613 | + threadId: ThreadId.make("thread-1"), |
| 614 | + message: { |
| 615 | + messageId: asMessageId("user-message-missing-workspace"), |
| 616 | + role: "user", |
| 617 | + text: "continue in moved workspace", |
| 618 | + attachments: [], |
| 619 | + }, |
| 620 | + interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE, |
| 621 | + runtimeMode: "approval-required", |
| 622 | + createdAt: now, |
| 623 | + }), |
| 624 | + ); |
| 625 | + |
| 626 | + await waitFor(async () => { |
| 627 | + const readModel = await harness.readModel(); |
| 628 | + const thread = readModel.threads.find((entry) => entry.id === ThreadId.make("thread-1")); |
| 629 | + return thread?.session?.status === "error"; |
| 630 | + }); |
| 631 | + |
| 632 | + expect(harness.startSession).not.toHaveBeenCalled(); |
| 633 | + expect(harness.sendTurn).not.toHaveBeenCalled(); |
| 634 | + const readModel = await harness.readModel(); |
| 635 | + const thread = readModel.threads.find((entry) => entry.id === ThreadId.make("thread-1")); |
| 636 | + expect(thread?.session?.lastError).toBe( |
| 637 | + `This thread's workspace folder no longer exists: '${harness.workspaceRoot}'. Restore the folder before retrying.`, |
| 638 | + ); |
| 639 | + expect( |
| 640 | + thread?.activities.find((activity) => activity.kind === "provider.turn.start.failed"), |
| 641 | + ).toMatchObject({ |
| 642 | + payload: { |
| 643 | + detail: expect.stringContaining(harness.workspaceRoot), |
| 644 | + }, |
| 645 | + }); |
| 646 | + }); |
| 647 | + |
596 | 648 | effectIt.effect("retains a turn dispatched immediately after start until activation", () => |
597 | 649 | Effect.gen(function* () { |
598 | 650 | const activation = yield* Deferred.make<void>(); |
@@ -869,7 +921,7 @@ describe("ProviderCommandReactor", () => { |
869 | 921 |
|
870 | 922 | expect(harness.generateThreadTitle).toHaveBeenCalledTimes(1); |
871 | 923 | expect(harness.generateThreadTitle.mock.calls[0]?.[0]).toMatchObject({ |
872 | | - cwd: "/tmp/provider-project", |
| 924 | + cwd: harness.workspaceRoot, |
873 | 925 | previousTitle: "Investigate reconnect regressions", |
874 | 926 | message: [ |
875 | 927 | "USER:", |
@@ -1597,7 +1649,7 @@ describe("ProviderCommandReactor", () => { |
1597 | 1649 | commandId: CommandId.make("cmd-thread-branch"), |
1598 | 1650 | threadId: ThreadId.make("thread-1"), |
1599 | 1651 | branch: "t3code/1234abcd", |
1600 | | - worktreePath: "/tmp/provider-project-worktree", |
| 1652 | + worktreePath: harness.worktreeRoot, |
1601 | 1653 | }), |
1602 | 1654 | ); |
1603 | 1655 |
|
@@ -1639,7 +1691,7 @@ describe("ProviderCommandReactor", () => { |
1639 | 1691 | `Add a safer reconnect backoff. ${assistantQuoteText}`, |
1640 | 1692 | ); |
1641 | 1693 | expect(harness.generateBranchName.mock.calls[0]?.[0].message).not.toContain("t3-citation://"); |
1642 | | - expect(harness.refreshStatus.mock.calls[0]?.[0]).toBe("/tmp/provider-project-worktree"); |
| 1694 | + expect(harness.refreshStatus.mock.calls[0]?.[0]).toBe(harness.worktreeRoot); |
1643 | 1695 | const readModel = await harness.readModel(); |
1644 | 1696 | expect( |
1645 | 1697 | readModel.threads |
@@ -1681,9 +1733,9 @@ describe("ProviderCommandReactor", () => { |
1681 | 1733 | ); |
1682 | 1734 |
|
1683 | 1735 | await waitFor(() => harness.startSession.mock.calls.length === 1); |
1684 | | - expect(harness.pruneWorktrees).toHaveBeenCalledWith({ cwd: "/tmp/provider-project" }); |
| 1736 | + expect(harness.pruneWorktrees).toHaveBeenCalledWith({ cwd: harness.workspaceRoot }); |
1685 | 1737 | expect(harness.createWorktree).toHaveBeenCalledWith({ |
1686 | | - cwd: "/tmp/provider-project", |
| 1738 | + cwd: harness.workspaceRoot, |
1687 | 1739 | refName: "feature/restore", |
1688 | 1740 | path: worktreePath, |
1689 | 1741 | }); |
@@ -2182,15 +2234,16 @@ describe("ProviderCommandReactor", () => { |
2182 | 2234 | await waitFor(() => harness.startSession.mock.calls.length === 1); |
2183 | 2235 | await waitFor(() => harness.sendTurn.mock.calls.length === 1); |
2184 | 2236 | expect(harness.startSession.mock.calls[0]?.[1]).toMatchObject({ |
2185 | | - cwd: "/tmp/provider-project", |
| 2237 | + cwd: harness.workspaceRoot, |
2186 | 2238 | }); |
| 2239 | + NodeFS.mkdirSync(harness.worktreeRoot, { recursive: true }); |
2187 | 2240 |
|
2188 | 2241 | await Effect.runPromise( |
2189 | 2242 | harness.engine.dispatch({ |
2190 | 2243 | type: "thread.meta.update", |
2191 | 2244 | commandId: CommandId.make("cmd-thread-worktree-change"), |
2192 | 2245 | threadId: ThreadId.make("thread-1"), |
2193 | | - worktreePath: "/tmp/provider-project-worktree", |
| 2246 | + worktreePath: harness.worktreeRoot, |
2194 | 2247 | }), |
2195 | 2248 | ); |
2196 | 2249 |
|
@@ -2216,7 +2269,7 @@ describe("ProviderCommandReactor", () => { |
2216 | 2269 | expect(harness.stopSession.mock.calls.length).toBe(0); |
2217 | 2270 | expect(harness.startSession.mock.calls[1]?.[1]).toMatchObject({ |
2218 | 2271 | threadId: ThreadId.make("thread-1"), |
2219 | | - cwd: "/tmp/provider-project-worktree", |
| 2272 | + cwd: harness.worktreeRoot, |
2220 | 2273 | resumeCursor: { opaque: "resume-1" }, |
2221 | 2274 | modelSelection: { |
2222 | 2275 | instanceId: ProviderInstanceId.make("claudeAgent"), |
@@ -2961,7 +3014,7 @@ describe("ProviderCommandReactor", () => { |
2961 | 3014 | status: "ready", |
2962 | 3015 | runtimeMode: "approval-required", |
2963 | 3016 | threadId: ThreadId.make("thread-1"), |
2964 | | - cwd: "/tmp/provider-project", |
| 3017 | + cwd: harness.workspaceRoot, |
2965 | 3018 | resumeCursor: { opaque: "resume-without-instance" }, |
2966 | 3019 | createdAt: now, |
2967 | 3020 | updatedAt: now, |
|