@@ -2715,6 +2715,106 @@ describe("OrchestratorMcpService provider resolution", () => { |
2715 | 2715 | }), |
2716 | 2716 | ); |
2717 | 2717 |
|
| 2718 | + it.effect("gives a worktree child in a project whose folder holds several repositories", () => |
| 2719 | + Effect.gen(function* () { |
| 2720 | + // A plain project folder: Git finds no repository at its root, only in a/ and b/. |
| 2721 | + const workspaceRoot = "/work/several-repos"; |
| 2722 | + const commands: Array<unknown> = []; |
| 2723 | + const task = { |
| 2724 | + id: taskId, |
| 2725 | + threadId: parentThreadId, |
| 2726 | + origin: "app_owned", |
| 2727 | + childThreadId, |
| 2728 | + providerInstanceId: codexInstanceId, |
| 2729 | + model: "gpt-5.4", |
| 2730 | + status: "running", |
| 2731 | + result: null, |
| 2732 | + }; |
| 2733 | + const dependencies = Layer.mergeAll( |
| 2734 | + NodeServices.layer, |
| 2735 | + NodeCrypto.layer, |
| 2736 | + Layer.mock(ThreadManagementService.ThreadManagementService)({ |
| 2737 | + hasReceipt: () => Effect.succeed(false), |
| 2738 | + getThreadRecords: (threadId) => |
| 2739 | + Effect.succeed( |
| 2740 | + threadId === parentThreadId |
| 2741 | + ? (() => { |
| 2742 | + const parent = parentProjection(commands.length > 0 ? [task] : []); |
| 2743 | + return { |
| 2744 | + ...parent, |
| 2745 | + thread: { ...parent.thread, worktreePath: null }, |
| 2746 | + } as OrchestrationV2ThreadProjection; |
| 2747 | + })() |
| 2748 | + : childProjection, |
| 2749 | + ), |
| 2750 | + dispatch: (command) => |
| 2751 | + Effect.sync(() => { |
| 2752 | + commands.push(command); |
| 2753 | + return { |
| 2754 | + sequence: 1, |
| 2755 | + storedEvents: [{ event: { type: "subagent.updated", payload: task } }], |
| 2756 | + } as never; |
| 2757 | + }), |
| 2758 | + }), |
| 2759 | + ServerSettings.layerTest(), |
| 2760 | + providerRegistryLayer([ |
| 2761 | + providerSnapshot({ |
| 2762 | + instanceId: codexInstanceId, |
| 2763 | + driver: ProviderDriverKind.make("codex"), |
| 2764 | + model: "gpt-5.4", |
| 2765 | + }), |
| 2766 | + ]), |
| 2767 | + adapterRegistryLayer([codexInstanceId]), |
| 2768 | + Layer.mock(ProjectService.ProjectService)({ |
| 2769 | + getById: () => |
| 2770 | + Effect.succeedSome({ id: projectId, title: "parent", workspaceRoot } as never), |
| 2771 | + }), |
| 2772 | + Layer.mock(SecretRequests.SecretRequests)({}), |
| 2773 | + Layer.mock(RemoteDelegation.RemoteDelegation)({}), |
| 2774 | + Layer.mock(ScheduledTaskService.ScheduledTaskService)({}), |
| 2775 | + ); |
| 2776 | + const notARepository = (cwd: string) => |
| 2777 | + new GitCommandError({ |
| 2778 | + operation: "GitVcsDriver.resolveCommit", |
| 2779 | + command: "git rev-parse --verify HEAD^{commit}", |
| 2780 | + cwd, |
| 2781 | + detail: "fatal: not a git repository (or any of the parent directories): .git", |
| 2782 | + }); |
| 2783 | + const layerService = OrchestratorMcpService.layer.pipe( |
| 2784 | + Layer.provide( |
| 2785 | + Layer.mock(ThreadLaunchService.ThreadLaunchService)({ |
| 2786 | + isNonGitProject: () => Effect.succeed(true), |
| 2787 | + }), |
| 2788 | + ), |
| 2789 | + Layer.provide( |
| 2790 | + Layer.mock(GitVcsDriver.GitVcsDriver)({ |
| 2791 | + resolveCommit: ({ cwd }) => Effect.fail(notARepository(cwd)), |
| 2792 | + }), |
| 2793 | + ), |
| 2794 | + Layer.provide(dependencies), |
| 2795 | + ); |
| 2796 | + yield* Effect.gen(function* () { |
| 2797 | + const service = yield* OrchestratorMcpService.OrchestratorMcpService; |
| 2798 | + const result = yield* service |
| 2799 | + .delegateTask(scope, { |
| 2800 | + task: "Add a line to a/README.md.", |
| 2801 | + isolation: "worktree", |
| 2802 | + mode: "async", |
| 2803 | + clientRequestId: "worktree-several-repos", |
| 2804 | + }) |
| 2805 | + .pipe(Effect.result); |
| 2806 | + assert.isTrue( |
| 2807 | + Result.isSuccess(result), |
| 2808 | + `worktree isolation was refused: ${Result.isFailure(result) ? result.failure.message : ""}`, |
| 2809 | + ); |
| 2810 | + assert.equal( |
| 2811 | + (commands[0] as { workspaceStrategy?: { type: string } }).workspaceStrategy?.type, |
| 2812 | + "worktree", |
| 2813 | + ); |
| 2814 | + }).pipe(Effect.provide(layerService)); |
| 2815 | + }), |
| 2816 | + ); |
| 2817 | + |
2718 | 2818 | it.effect("rejects delegation to a provider without a registered adapter", () => |
2719 | 2819 | Effect.gen(function* () { |
2720 | 2820 | const forkOnlyInstanceId = ProviderInstanceId.make("forkOnly"); |
|