@@ -3,6 +3,7 @@ package git
33import (
44 "context"
55 "crypto/sha256"
6+ "errors"
67 "fmt"
78 "os"
89 "path/filepath"
@@ -75,3 +76,45 @@ func TestQuarantineCheckoutPreservesDirtyRepository(t *testing.T) {
7576 t .Fatalf ("dirty work changed: %q %v" , content , err )
7677 }
7778}
79+
80+ func TestQuarantineRemoteValidationAdmitsNetworkTransportsForReadOnlyObservation (t * testing.T ) {
81+ client , _ := mutationRepository (t )
82+ runFetchGit (t , client , "remote" , "add" , "origin" , "git@github.com:example/repository.git" )
83+ runner , err := NewMutationRunner ()
84+ if err != nil {
85+ t .Fatal (err )
86+ }
87+ _ , url , err := runner .validatedRemoteURL (context .Background (), client , "origin" )
88+ if err != nil {
89+ t .Fatalf ("read-only observation must admit the fetch URL: %v" , err )
90+ }
91+ if url != "git@github.com:example/repository.git" {
92+ t .Fatalf ("url=%q" , url )
93+ }
94+ if _ , err := runner .validatedPushURL (context .Background (), client , "origin" ); ! errors .Is (err , ErrNetworkMutationDisabled ) {
95+ t .Fatalf ("push URL must remain mutation-gated: %v" , err )
96+ }
97+ }
98+
99+ func TestQuarantineCheckoutNetworkRemoteFailsAtObservationNotAtTheMutationGate (t * testing.T ) {
100+ fixture := fastForwardFixture (t )
101+ runFetchGit (t , fixture .client , "remote" , "set-url" , "origin" , "ssh://127.0.0.1:1/repository.git" )
102+ head := stringsTrim (runFetchGit (t , fixture .client , "rev-parse" , "HEAD" ))
103+ workspaceRoot := filepath .Dir (fixture .client )
104+ stateRoot := t .TempDir ()
105+ quarantine := filepath .Join (stateRoot , "quarantine" , "checkouts" , "repo_fixture" , head )
106+ runner , err := NewMutationRunner ()
107+ if err != nil {
108+ t .Fatal (err )
109+ }
110+ _ , err = runner .QuarantineCheckout (
111+ context .Background (), workspaceRoot , fixture .client , stateRoot , quarantine ,
112+ head , "refs/heads/main" , fmt .Sprintf ("sha256:%x" , sha256 .Sum256 ([]byte ("x" ))),
113+ )
114+ if err == nil {
115+ t .Fatal ("an unreachable remote must fail the observation" )
116+ }
117+ if errors .Is (err , ErrNetworkMutationDisabled ) {
118+ t .Fatalf ("read-only remote observation must not hit the mutation gate: %v" , err )
119+ }
120+ }
0 commit comments