@@ -2,6 +2,7 @@ import * as ProviderRegistry from "../../../provider/ProviderRegistry.ts";
22import { expect , it } from "@effect/vitest" ;
33import {
44 EnvironmentId ,
5+ GitCommandError ,
56 ProjectId ,
67 ProviderInstanceId ,
78 ProviderDriverKind ,
@@ -15,13 +16,17 @@ import {
1516import * as NodeCrypto from "@effect/platform-node/NodeCrypto" ;
1617import * as NodeServices from "@effect/platform-node/NodeServices" ;
1718import * as Cause from "effect/Cause" ;
19+ import * as Deferred from "effect/Deferred" ;
1820import * as Effect from "effect/Effect" ;
1921import * as Exit from "effect/Exit" ;
22+ import * as Fiber from "effect/Fiber" ;
2023import * as FileSystem from "effect/FileSystem" ;
2124import * as Path from "effect/Path" ;
2225import * as Layer from "effect/Layer" ;
2326import * as Option from "effect/Option" ;
2427import * as Stream from "effect/Stream" ;
28+ import { ChildProcessSpawner } from "effect/process" ;
29+ import * as TestClock from "effect/testing/TestClock" ;
2530
2631import * as DocumentText from "../../../provider/DocumentText.ts" ;
2732import { OrchestratorRuntimeModeAboveCeilingError } from "../../../orchestration-v2/Orchestrator.ts" ;
@@ -33,6 +38,8 @@ import * as Project from "../../../project/ProjectService.ts";
3338import * as ProjectCloneTracker from "../../../project/ProjectCloneTracker.ts" ;
3439import * as ManagedProjectFolders from "../../../project/ManagedProjectFolders.ts" ;
3540import * as PeerForwarding from "../../../peer/PeerForwarding.ts" ;
41+ import * as SourceControlProviderRegistry from "../../../sourceControl/SourceControlProviderRegistry.ts" ;
42+ import * as Repositories from "../../../sourceControl/SourceControlRepositoryService.ts" ;
3643import * as GitVcsDriver from "../../../vcs/GitVcsDriver.ts" ;
3744import * as VcsProcess from "../../../vcs/VcsProcess.ts" ;
3845import * as McpInvocationContext from "../../McpInvocationContext.ts" ;
@@ -689,6 +696,72 @@ it.effect("a client launches with the fallback for an exhausted default", () =>
689696 } ) ,
690697) ;
691698
699+ it . effect ( "an agent's clone is not cut off while git is still transferring" , ( ) =>
700+ Effect . gen ( function * ( ) {
701+ const fs = yield * FileSystem . FileSystem ;
702+ const path = yield * Path . Path ;
703+ const parent = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-mcp-clone-" } ) ;
704+ const destinationPath = path . join ( parent , "repo" ) ;
705+ const started = yield * Deferred . make < void > ( ) ;
706+ const transferred = yield * Deferred . make < void > ( ) ;
707+ const { dependencies } = clientLaunchHarness ( {
708+ runtimeModeCeiling : "full-access" ,
709+ launched : [ ] ,
710+ } ) ;
711+ const repositories = Repositories . layer . pipe (
712+ Layer . provide (
713+ Layer . mock ( SourceControlProviderRegistry . SourceControlProviderRegistry ) ( {
714+ resolveLink : ( ) => undefined ,
715+ } ) ,
716+ ) ,
717+ Layer . provide (
718+ Layer . mock ( GitVcsDriver . GitVcsDriver ) ( {
719+ // Like the real driver, the clone fails once it outlives the deadline it was given.
720+ execute : ( input ) =>
721+ Deferred . succeed ( started , undefined ) . pipe (
722+ Effect . andThen ( Deferred . await ( transferred ) ) ,
723+ Effect . as ( {
724+ exitCode : ChildProcessSpawner . ExitCode ( 0 ) ,
725+ stdout : "" ,
726+ stderr : "" ,
727+ stdoutTruncated : false ,
728+ stderrTruncated : false ,
729+ } ) ,
730+ Effect . timeoutOrElse ( {
731+ duration : input . timeoutMs ?? Infinity ,
732+ orElse : ( ) =>
733+ Effect . fail (
734+ new GitCommandError ( {
735+ operation : input . operation ,
736+ command : "git" ,
737+ cwd : input . cwd ,
738+ detail : "Git command timed out." ,
739+ } ) ,
740+ ) ,
741+ } ) ,
742+ ) ,
743+ } ) ,
744+ ) ,
745+ Layer . provideMerge ( dependencies ) ,
746+ ) ;
747+ const toolkit = yield * ProjectToolkit . pipe (
748+ Effect . provide (
749+ McpToolAccess . HandlersLayer . layer ( ProjectHandlers . layer ) . pipe ( Layer . provide ( repositories ) ) ,
750+ ) ,
751+ ) ;
752+
753+ const clone = yield * toolkit
754+ . handle ( "t3_project_clone" , { remoteUrl : "https://example.test/repo.git" , destinationPath } )
755+ . pipe ( Stream . unwrap , Stream . runCollect , Effect . provide ( repositories ) , Effect . forkChild ) ;
756+ yield * Deferred . await ( started ) ;
757+ // A large repository over a slow link; agents' MCP calls get a far longer budget.
758+ yield * TestClock . adjust ( "10 minutes" ) ;
759+ yield * Deferred . succeed ( transferred , undefined ) ;
760+
761+ expect ( ( yield * Fiber . join ( clone ) ) . at ( - 1 ) ?. result ) . toMatchObject ( { cwd : destinationPath } ) ;
762+ } ) . pipe ( Effect . provide ( NodeServices . layer ) ) ,
763+ ) ;
764+
692765it . effect ( "deleting a project through MCP also discards its clone record" , ( ) =>
693766 Effect . gen ( function * ( ) {
694767 const discarded : Array < ProjectId > = [ ] ;
0 commit comments