@@ -712,6 +712,279 @@ it.layer(TestLayer)("GitVcsDriver core integration", (it) => {
712712 assert . notInclude ( error . message , secret ) ;
713713 assert . notProperty ( error , "args" ) ;
714714 assert . notProperty ( error , "stderr" ) ;
715+ assert . notProperty ( error , "reason" ) ;
716+ } ) ,
717+ ) ;
718+
719+ it . effect ( "names the branch conflict behind a failed worktree add" , ( ) =>
720+ Effect . gen ( function * ( ) {
721+ const parent = yield * makeTmpDir ( ) ;
722+ const pathService = yield * Path . Path ;
723+ const cwd = pathService . join ( parent , "repo" ) ;
724+ const fileSystem = yield * FileSystem . FileSystem ;
725+ yield * fileSystem . makeDirectory ( cwd ) ;
726+ const driver = yield * GitVcsDriver . GitVcsDriver ;
727+ yield * initRepoWithCommit ( cwd ) ;
728+ const firstWorktree = pathService . join ( parent , "first" ) ;
729+ yield * git ( cwd , [ "worktree" , "add" , firstWorktree , "-b" , "shared-branch" ] ) ;
730+
731+ const error = yield * driver
732+ . execute ( {
733+ operation : "GitVcsDriver.test.worktreeAddConflict" ,
734+ cwd,
735+ args : [ "worktree" , "add" , pathService . join ( parent , "second" ) , "shared-branch" ] ,
736+ env : { LC_ALL : "C" } ,
737+ } )
738+ . pipe ( Effect . flip ) ;
739+
740+ assert . deepInclude ( error , {
741+ _tag : "GitCommandError" ,
742+ operation : "GitVcsDriver.test.worktreeAddConflict" ,
743+ reason : "branch_checked_out_in_worktree" ,
744+ } ) ;
745+ assert . include ( error . message , "(branch_checked_out_in_worktree)" ) ;
746+ assert . notInclude ( error . message , firstWorktree ) ;
747+ } ) ,
748+ ) ;
749+
750+ it . effect ( "names a missing repository behind a failed command" , ( ) =>
751+ Effect . gen ( function * ( ) {
752+ const cwd = yield * makeTmpDir ( ) ;
753+ const driver = yield * GitVcsDriver . GitVcsDriver ;
754+
755+ const error = yield * driver
756+ . execute ( {
757+ operation : "GitVcsDriver.test.notARepository" ,
758+ cwd,
759+ args : [ "rev-parse" , "--abbrev-ref" , "HEAD" ] ,
760+ env : { LC_ALL : "C" } ,
761+ } )
762+ . pipe ( Effect . flip ) ;
763+
764+ assert . deepInclude ( error , {
765+ _tag : "GitCommandError" ,
766+ operation : "GitVcsDriver.test.notARepository" ,
767+ reason : "not_a_repository" ,
768+ } ) ;
769+ assert . include ( error . message , "(not_a_repository)" ) ;
770+ } ) ,
771+ ) ;
772+
773+ it . effect ( "appends the reason tag to a caller-supplied detail" , ( ) =>
774+ Effect . gen ( function * ( ) {
775+ const parent = yield * makeTmpDir ( ) ;
776+ const pathService = yield * Path . Path ;
777+ const cwd = pathService . join ( parent , "repo" ) ;
778+ const fileSystem = yield * FileSystem . FileSystem ;
779+ yield * fileSystem . makeDirectory ( cwd ) ;
780+ const driver = yield * GitVcsDriver . GitVcsDriver ;
781+ yield * initRepoWithCommit ( cwd ) ;
782+ yield * git ( cwd , [
783+ "worktree" ,
784+ "add" ,
785+ pathService . join ( parent , "taken" ) ,
786+ "-b" ,
787+ "taken-branch" ,
788+ ] ) ;
789+
790+ const error = yield * driver
791+ . createWorktree ( {
792+ cwd,
793+ refName : "taken-branch" ,
794+ path : pathService . join ( parent , "second" ) ,
795+ } )
796+ . pipe ( Effect . flip ) ;
797+
798+ assert . equal ( error . detail , "git worktree add failed" ) ;
799+ assert . include ( error . message , "git worktree add failed (branch_checked_out_in_worktree)" ) ;
800+ } ) ,
801+ ) ;
802+
803+ for ( const { label, sshMessage, expectedReason, expectedText } of [
804+ {
805+ label : "a refused key" ,
806+ sshMessage :
"[email protected] : Permission denied (publickey)." , 807+ expectedReason : "authentication_failed" as const ,
808+ expectedText : "(authentication_failed)" ,
809+ } ,
810+ {
811+ label : "a refused key among several methods" ,
812+ sshMessage :
"[email protected] : Permission denied (publickey,password)." , 813+ expectedReason : "authentication_failed" as const ,
814+ expectedText : "(authentication_failed)" ,
815+ } ,
816+ {
817+ label : "a refused keyboard-interactive attempt" ,
818+ sshMessage :
"[email protected] : Permission denied (keyboard-interactive)." , 819+ expectedReason : "authentication_failed" as const ,
820+ expectedText : "(authentication_failed)" ,
821+ } ,
822+ {
823+ label : "a rejected password" ,
824+ sshMessage : "Permission denied, please try again." ,
825+ expectedReason : "authentication_failed" as const ,
826+ expectedText : "(authentication_failed)" ,
827+ } ,
828+ {
829+ label : "an untrusted host key" ,
830+ sshMessage : "Host key verification failed." ,
831+ expectedReason : "host_key_unverified" as const ,
832+ expectedText : "(host_key_unverified)" ,
833+ } ,
834+ ] ) {
835+ it . effect ( `names ${ label } rather than an unreachable remote` , ( ) =>
836+ Effect . gen ( function * ( ) {
837+ const parent = yield * makeTmpDir ( ) ;
838+ const pathService = yield * Path . Path ;
839+ const cwd = pathService . join ( parent , "repo" ) ;
840+ const fileSystem = yield * FileSystem . FileSystem ;
841+ const driver = yield * GitVcsDriver . GitVcsDriver ;
842+ yield * fileSystem . makeDirectory ( cwd ) ;
843+ yield * initRepoWithCommit ( cwd ) ;
844+ yield * git ( cwd , [ "remote" , "add" , "origin" , "[email protected] :owner/repo.git" ] ) ; 845+ // Stands in for ssh, which prints its refusal unprefixed and leaves
846+ // git to add only a generic "could not read" line after it.
847+ const fakeSsh = pathService . join ( parent , "fake-ssh" ) ;
848+ yield * writeTextFile (
849+ parent ,
850+ "fake-ssh" ,
851+ `#!/bin/sh\necho "${ sshMessage } " >&2\nexit 255\n` ,
852+ ) ;
853+ yield * fileSystem . chmod ( fakeSsh , 0o755 ) ;
854+
855+ const error = yield * driver
856+ . execute ( {
857+ operation : "GitVcsDriver.test.sshRefusal" ,
858+ cwd,
859+ args : [ "fetch" , "origin" ] ,
860+ env : { LC_ALL : "C" , GIT_SSH_COMMAND : fakeSsh } ,
861+ } )
862+ . pipe ( Effect . flip ) ;
863+
864+ assert . deepInclude ( error , { reason : expectedReason } ) ;
865+ assert . include ( error . message , expectedText ) ;
866+ } ) ,
867+ ) ;
868+ }
869+
870+ it . effect ( "does not read a filesystem permission error as an ssh refusal" , ( ) =>
871+ Effect . gen ( function * ( ) {
872+ const parent = yield * makeTmpDir ( ) ;
873+ const pathService = yield * Path . Path ;
874+ const cwd = pathService . join ( parent , "repo" ) ;
875+ const fileSystem = yield * FileSystem . FileSystem ;
876+ const driver = yield * GitVcsDriver . GitVcsDriver ;
877+ yield * fileSystem . makeDirectory ( cwd ) ;
878+ yield * initRepoWithCommit ( cwd ) ;
879+ yield * git ( cwd , [ "remote" , "add" , "origin" , "[email protected] :owner/repo.git" ] ) ; 880+ const fakeSsh = pathService . join ( parent , "fake-ssh" ) ;
881+ yield * writeTextFile (
882+ parent ,
883+ "fake-ssh" ,
884+ '#!/bin/sh\necho "fatal: cannot open backup file: Permission denied (os error 13)" >&2\nexit 255\n' ,
885+ ) ;
886+ yield * fileSystem . chmod ( fakeSsh , 0o755 ) ;
887+
888+ const error = yield * driver
889+ . execute ( {
890+ operation : "GitVcsDriver.test.osPermission" ,
891+ cwd,
892+ args : [ "fetch" , "origin" ] ,
893+ env : { LC_ALL : "C" , GIT_SSH_COMMAND : fakeSsh } ,
894+ } )
895+ . pipe ( Effect . flip ) ;
896+
897+ assert . notInclude ( error . message , "(authentication_failed)" ) ;
898+ } ) ,
899+ ) ;
900+
901+ it . effect ( "does not read remote hook output as a git failure reason" , ( ) =>
902+ Effect . gen ( function * ( ) {
903+ const parent = yield * makeTmpDir ( ) ;
904+ const pathService = yield * Path . Path ;
905+ const remote = pathService . join ( parent , "origin.git" ) ;
906+ const cwd = pathService . join ( parent , "work" ) ;
907+ const fileSystem = yield * FileSystem . FileSystem ;
908+ const driver = yield * GitVcsDriver . GitVcsDriver ;
909+ yield * fileSystem . makeDirectory ( cwd ) ;
910+ yield * initRepoWithCommit ( cwd ) ;
911+ yield * git ( cwd , [ "init" , "--bare" , remote ] ) ;
912+ yield * git ( cwd , [ "remote" , "add" , "origin" , remote ] ) ;
913+ // Git prefixes everything the server says with `remote:`, so a remote
914+ // hook can put arbitrary text in front of the classifier.
915+ const preReceive = pathService . join ( remote , "hooks" , "pre-receive" ) ;
916+ yield * writeTextFile (
917+ remote ,
918+ "hooks/pre-receive" ,
919+ '#!/bin/sh\necho "authentication failed" >&2\nexit 1\n' ,
920+ ) ;
921+ yield * fileSystem . chmod ( preReceive , 0o755 ) ;
922+
923+ const error = yield * driver
924+ . execute ( {
925+ operation : "GitVcsDriver.test.remoteHookOutput" ,
926+ cwd,
927+ args : [ "push" , "origin" , "HEAD" ] ,
928+ env : { LC_ALL : "C" } ,
929+ } )
930+ . pipe ( Effect . flip ) ;
931+
932+ assert . notProperty ( error , "reason" ) ;
933+ assert . notInclude ( error . message , "(authentication_failed)" ) ;
934+ } ) ,
935+ ) ;
936+
937+ it . effect ( "does not read hook output as a git failure reason" , ( ) =>
938+ Effect . gen ( function * ( ) {
939+ const parent = yield * makeTmpDir ( ) ;
940+ const pathService = yield * Path . Path ;
941+ const remote = pathService . join ( parent , "origin.git" ) ;
942+ const cwd = pathService . join ( parent , "work" ) ;
943+ const fileSystem = yield * FileSystem . FileSystem ;
944+ const driver = yield * GitVcsDriver . GitVcsDriver ;
945+ yield * fileSystem . makeDirectory ( cwd ) ;
946+ yield * initRepoWithCommit ( cwd ) ;
947+ yield * git ( cwd , [ "init" , "--bare" , remote ] ) ;
948+ yield * git ( cwd , [ "remote" , "add" , "origin" , remote ] ) ;
949+ yield * writeTextFile (
950+ cwd ,
951+ ".git/hooks/pre-push" ,
952+ '#!/bin/sh\necho "authentication failed" >&2\nexit 1\n' ,
953+ ) ;
954+ yield * fileSystem . chmod ( pathService . join ( cwd , ".git/hooks/pre-push" ) , 0o755 ) ;
955+
956+ const error = yield * driver
957+ . execute ( {
958+ operation : "GitVcsDriver.test.hookOutput" ,
959+ cwd,
960+ args : [ "push" , "origin" , "HEAD" ] ,
961+ env : { LC_ALL : "C" } ,
962+ } )
963+ . pipe ( Effect . flip ) ;
964+
965+ assert . notProperty ( error , "reason" ) ;
966+ assert . notInclude ( error . message , "(authentication_failed)" ) ;
967+ } ) ,
968+ ) ;
969+
970+ it . effect ( "leaves a tag collision unclassified rather than calling it a path" , ( ) =>
971+ Effect . gen ( function * ( ) {
972+ const cwd = yield * makeTmpDir ( ) ;
973+ const driver = yield * GitVcsDriver . GitVcsDriver ;
974+ yield * initRepoWithCommit ( cwd ) ;
975+ yield * git ( cwd , [ "tag" , "v1" ] ) ;
976+
977+ const error = yield * driver
978+ . execute ( {
979+ operation : "GitVcsDriver.test.tagCollision" ,
980+ cwd,
981+ args : [ "tag" , "v1" ] ,
982+ env : { LC_ALL : "C" } ,
983+ } )
984+ . pipe ( Effect . flip ) ;
985+
986+ assert . notProperty ( error , "reason" ) ;
987+ assert . notInclude ( error . message , "(path_already_exists)" ) ;
715988 } ) ,
716989 ) ;
717990
0 commit comments