@@ -17,7 +17,6 @@ import * as Exit from "effect/Exit";
1717import * as Fiber from "effect/Fiber" ;
1818import * as Layer from "effect/Layer" ;
1919import * as Option from "effect/Option" ;
20- import * as Path from "effect/Path" ;
2120import * as Schema from "effect/Schema" ;
2221
2322import * as GitWorkflowService from "../git/GitWorkflowService.ts" ;
@@ -104,7 +103,6 @@ interface HarnessOptions {
104103 readonly projectMissing ?: boolean ;
105104 readonly projectReadFails ?: boolean ;
106105 readonly existingBranchWorktreePath ?: string | null ;
107- readonly pathSemantics ?: "win32" | "posix" ;
108106 readonly createWorktreeFails ?: boolean ;
109107 readonly fetchRemoteFails ?: boolean ;
110108 readonly resolveRemoteFails ?: boolean ;
@@ -287,22 +285,7 @@ const makeHarness = (options: HarnessOptions = {}) => {
287285 }
288286 } ) ;
289287
290- // Optional deterministic Path semantics: providing this BEFORE the general
291- // mocks means the service resolves Path here rather than from NodeServices,
292- // so absolute-path validation is testable independently of the host OS.
293- const win32IsAbsolute = ( value : string ) => / ^ (?: [ a - z A - Z ] : [ \\ / ] | [ \\ / ] ) / . test ( value ) ;
294- const posixIsAbsolute = ( value : string ) => value . startsWith ( "/" ) ;
295- const layerService =
296- options . pathSemantics === undefined
297- ? WorktreeMcpService . layer
298- : WorktreeMcpService . layer . pipe (
299- Layer . provide (
300- Layer . succeed ( Path . Path , {
301- isAbsolute : options . pathSemantics === "win32" ? win32IsAbsolute : posixIsAbsolute ,
302- } as unknown as Path . Path ) ,
303- ) ,
304- ) ;
305- const layer = layerService . pipe (
288+ const layer = WorktreeMcpService . layer . pipe (
306289 Layer . provide (
307290 Layer . mergeAll (
308291 Layer . mock ( ThreadManagementService . ThreadManagementService ) ( {
@@ -386,6 +369,9 @@ const runStatus = (harness: ReturnType<typeof makeHarness>) =>
386369 return yield * service . status ( harness . scope ) ;
387370 } ) . pipe ( Effect . provide ( harness . layer ) ) ;
388371
372+ // Decodes tool arguments the way the MCP tool does before calling the service.
373+ const decodeHandoffInput = Schema . decodeUnknownEffect ( WorktreeMcpHandoffInput ) ;
374+
389375describe ( "t3_worktree_handoff" , ( ) => {
390376 it . effect ( "creates a worktree from the current branch and re-points the thread" , ( ) => {
391377 const harness = makeHarness ( ) ;
@@ -501,14 +487,13 @@ describe("t3_worktree_handoff", () => {
501487 } ) ;
502488 } ) ;
503489
504- it . effect ( "starts from origin and honors explicit baseRef and path " , ( ) => {
490+ it . effect ( "starts from origin and honors an explicit baseRef" , ( ) => {
505491 const harness = makeHarness ( ) ;
506492 return Effect . gen ( function * ( ) {
507493 const result = yield * runHandoff ( harness , {
508494 branch : "feature/from-origin" ,
509495 baseRef : "dev" ,
510496 startFromOrigin : true ,
511- path : "/custom/worktree/location" ,
512497 runSetupScript : false ,
513498 } ) ;
514499
@@ -526,11 +511,11 @@ describe("t3_worktree_handoff", () => {
526511 refName : "abc123" ,
527512 newRefName : "feature/from-origin" ,
528513 baseRefName : "dev" ,
529- path : "/custom/worktree/location" ,
514+ path : null ,
530515 } ) ;
531516 expect ( harness . localStatus ) . toHaveBeenCalled ( ) ;
532517 expect ( harness . runForThread ) . not . toHaveBeenCalled ( ) ;
533- expect ( result . worktreePath ) . toBe ( "/custom/worktree/location " ) ;
518+ expect ( result . worktreePath ) . toBe ( "/worktrees/project/feature/from-origin " ) ;
534519 expect ( result . startedFromOrigin ) . toBe ( true ) ;
535520 expect ( result . setupScript ) . toEqual ( { status : "skipped" } ) ;
536521 } ) ;
@@ -825,28 +810,16 @@ describe("t3_worktree_handoff", () => {
825810 } ) ;
826811 } ) ;
827812
828- it . effect ( "accepts a Windows drive path under win32 path semantics " , ( ) => {
829- const harness = makeHarness ( { pathSemantics : "win32" } ) ;
813+ it . effect ( "creates the worktree in the managed directory even when a call names a path " , ( ) => {
814+ const harness = makeHarness ( ) ;
830815 return Effect . gen ( function * ( ) {
831- const result = yield * runHandoff ( harness , {
832- branch : "feature/windows-path " ,
833- path : "C:\\worktrees\\custom " ,
816+ const input = yield * decodeHandoffInput ( {
817+ branch : "feature/elsewhere " ,
818+ path : "/home/user/.ssh/checkout " ,
834819 } ) ;
835- expect ( result . worktreePath ) . toBe ( "C:\\worktrees\\custom" ) ;
836- expect ( harness . createWorktree ) . toHaveBeenCalledWith (
837- expect . objectContaining ( { path : "C:\\worktrees\\custom" } ) ,
838- ) ;
839- } ) ;
840- } ) ;
841-
842- it . effect ( "rejects a Windows drive path under posix path semantics" , ( ) => {
843- const harness = makeHarness ( { pathSemantics : "posix" } ) ;
844- return Effect . gen ( function * ( ) {
845- const exit = yield * Effect . exit (
846- runHandoff ( harness , { branch : "feature/windows-path" , path : "C:\\worktrees\\custom" } ) ,
847- ) ;
848- expectTypedFailure ( exit , { _tag : "WorktreeMcpFailure" , code : "invalid_request" } ) ;
849- expect ( harness . createWorktree ) . not . toHaveBeenCalled ( ) ;
820+ const result = yield * runHandoff ( harness , input ) ;
821+ expect ( harness . createWorktree ) . toHaveBeenCalledWith ( expect . objectContaining ( { path : null } ) ) ;
822+ expect ( result . worktreePath ) . toBe ( "/worktrees/project/feature/elsewhere" ) ;
850823 } ) ;
851824 } ) ;
852825
@@ -914,17 +887,6 @@ describe("t3_worktree_handoff", () => {
914887 } ) ;
915888 } ) ;
916889
917- it . effect ( "rejects a relative path" , ( ) => {
918- const harness = makeHarness ( ) ;
919- return Effect . gen ( function * ( ) {
920- const exit = yield * Effect . exit (
921- runHandoff ( harness , { branch : "feature/relative-path" , path : "worktrees/nested" } ) ,
922- ) ;
923- expectTypedFailure ( exit , { _tag : "WorktreeMcpFailure" , code : "invalid_request" } ) ;
924- expect ( harness . createWorktree ) . not . toHaveBeenCalled ( ) ;
925- } ) ;
926- } ) ;
927-
928890 it . effect ( "fails when baseRef is omitted and HEAD is detached" , ( ) => {
929891 const harness = makeHarness ( { currentBranch : null } ) ;
930892 return Effect . gen ( function * ( ) {
@@ -1013,24 +975,6 @@ describe("t3_worktree_status", () => {
1013975describe ( "WorktreeMcpHandoffInput schema" , ( ) => {
1014976 const decode = Schema . decodeUnknownEffect ( WorktreeMcpHandoffInput ) ;
1015977
1016- it . effect ( "accepts POSIX, Windows drive, and UNC absolute paths" , ( ) =>
1017- Effect . gen ( function * ( ) {
1018- for ( const path of [ "/abs/posix" , "C:\\abs\\drive" , "C:/abs/drive" , "\\\\host\\share" ] ) {
1019- const decoded = yield * decode ( { branch : "feature/x" , path } ) ;
1020- expect ( decoded . path ) . toBe ( path ) ;
1021- }
1022- } ) ,
1023- ) ;
1024-
1025- it . effect ( "rejects relative paths" , ( ) =>
1026- Effect . gen ( function * ( ) {
1027- for ( const path of [ "worktrees/nested" , "./nested" , "../sibling" ] ) {
1028- const exit = yield * Effect . exit ( decode ( { branch : "feature/x" , path } ) ) ;
1029- expect ( Exit . isFailure ( exit ) , `path '${ path } ' should be rejected` ) . toBe ( true ) ;
1030- }
1031- } ) ,
1032- ) ;
1033-
1034978 it . effect ( "rejects a missing or blank branch" , ( ) =>
1035979 Effect . gen ( function * ( ) {
1036980 expect ( Exit . isFailure ( yield * Effect . exit ( decode ( { } ) ) ) ) . toBe ( true ) ;
0 commit comments