@@ -80,6 +80,13 @@ const makeSuccessfulHandle = (stdout: string) =>
8080 getOutputFd : ( ) => Stream . empty ,
8181 } ) ;
8282
83+ const makeFailedHandle = ( stderr : string ) =>
84+ ChildProcessSpawner . makeHandle ( {
85+ ...makeNonRepositoryHandle ( ) ,
86+ exitCode : Effect . succeed ( ChildProcessSpawner . ExitCode ( 1 ) ) ,
87+ stderr : Stream . encodeText ( Stream . make ( stderr ) ) ,
88+ } ) ;
89+
8390const makeTmpDir = (
8491 prefix = "git-vcs-driver-test-" ,
8592) : Effect . Effect < string , PlatformError . PlatformError , FileSystem . FileSystem | Scope . Scope > =>
@@ -803,6 +810,88 @@ it.effect("retries a fetch that lost a ref update to another Git process", () =>
803810 } ) . pipe ( Effect . provide ( layerServerConfig . pipe ( Layer . provideMerge ( NodeServices . layer ) ) ) ) ,
804811) ;
805812
813+ describe ( "rejected git refs" , ( ) => {
814+ const remoteUrl = "https://user:[email protected] /org/secret-repo.git" ; 815+ const failedPush = `error: failed to push some refs to '${ remoteUrl } '` ;
816+ const leakedText = [
817+ "token-123" ,
818+ "secret-repo" ,
819+ "git.example.invalid" ,
820+ "private-branch" ,
821+ "workflow scope" ,
822+ ] ;
823+
824+ const failWith = ( stderr : string ) => {
825+ const spawner = ChildProcessSpawner . make ( ( ) => Effect . succeed ( makeFailedHandle ( stderr ) ) ) ;
826+ const layer = GitVcsDriver . layer . pipe (
827+ Layer . provide ( layerServerConfig ) ,
828+ Layer . provideMerge (
829+ Layer . merge (
830+ NodeServices . layer ,
831+ Layer . succeed ( ChildProcessSpawner . ChildProcessSpawner , spawner ) ,
832+ ) ,
833+ ) ,
834+ ) ;
835+ return Effect . gen ( function * ( ) {
836+ const driver = yield * GitVcsDriver . GitVcsDriver ;
837+ return yield * driver
838+ . execute ( {
839+ operation : "GitVcsDriver.test.rejectedRef" ,
840+ cwd : "/repo" ,
841+ args : [ "push" , "origin" , "HEAD" ] ,
842+ } )
843+ . pipe ( Effect . flip ) ;
844+ } ) . pipe ( Effect . provide ( layer ) ) ;
845+ } ;
846+
847+ it . effect . each ( [
848+ {
849+ label : "a ref the remote refused" ,
850+ stderr : [
851+ "remote: Unable to determine if workflow can be created; workflow scope may be required." ,
852+ `To ${ remoteUrl } ` ,
853+ " ! [remote rejected] private-branch -> private-branch (workflow scope may be required.)" ,
854+ failedPush ,
855+ ] ,
856+ reason : "push_rejected_by_remote" as const ,
857+ detail : "The remote rejected the push." ,
858+ } ,
859+ {
860+ label : "a non-fast-forward push" ,
861+ stderr : [
862+ `To ${ remoteUrl } ` ,
863+ " ! [rejected] private-branch -> private-branch (non-fast-forward)" ,
864+ failedPush ,
865+ ] ,
866+ reason : "push_rejected_non_fast_forward" as const ,
867+ detail : "Pull or rebase" ,
868+ } ,
869+ ] ) ( "names $label without quoting stderr" , ( { stderr, reason, detail } ) =>
870+ Effect . gen ( function * ( ) {
871+ const error = yield * failWith ( stderr . join ( "\n" ) ) ;
872+
873+ assert . deepInclude ( error , { reason } ) ;
874+ assert . include ( error . detail , detail ) ;
875+ for ( const text of leakedText ) assert . notInclude ( error . message , text ) ;
876+ } ) ,
877+ ) ;
878+
879+ // A fetch into a diverged local branch prints the same rejected line, but
880+ // never "failed to push some refs".
881+ it . effect ( "leaves a rejected fetch unclassified" , ( ) =>
882+ Effect . gen ( function * ( ) {
883+ const error = yield * failWith (
884+ [ `From ${ remoteUrl } ` , " ! [rejected] main -> side (non-fast-forward)" ] . join (
885+ "\n" ,
886+ ) ,
887+ ) ;
888+
889+ assert . equal ( error . reason , undefined ) ;
890+ assert . equal ( error . detail , "Git command exited with a non-zero status." ) ;
891+ } ) ,
892+ ) ;
893+ } ) ;
894+
806895it . layer ( layerTest ) ( "GitVcsDriver core integration" , ( it ) => {
807896 describe ( "structured errors" , ( ) => {
808897 it . effect ( "does not retain git arguments or stderr in command failures" , ( ) =>
@@ -1071,7 +1160,7 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
10711160 } ) ,
10721161 ) ;
10731162
1074- it . effect ( "does not read remote hook output as a git failure reason " , ( ) =>
1163+ it . effect ( "reads a hook-declined push from git's rejection line, not the hook's output " , ( ) =>
10751164 Effect . gen ( function * ( ) {
10761165 const parent = yield * makeTmpDir ( ) ;
10771166 const pathService = yield * Path . Path ;
@@ -1100,7 +1189,7 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
11001189 } )
11011190 . pipe ( Effect . flip ) ;
11021191
1103- assert . notProperty ( error , " reason" ) ;
1192+ assert . deepInclude ( error , { reason : "push_rejected_by_remote" } ) ;
11041193 assert . notInclude ( error . message , "(authentication_failed)" ) ;
11051194 } ) ,
11061195 ) ;
0 commit comments