@@ -369,6 +369,59 @@ func TestReportCreateArtifactEmptyError(t *testing.T) {
369369 assert .Contains (t , err .Error (), "raw response" )
370370}
371371
372+ func TestReportExplicitCommitSkipsGit (t * testing.T ) {
373+ tempDir := t .TempDir ()
374+ artifactPath := filepath .Join (tempDir , "coverage.xml" )
375+ assert .NoError (t , os .WriteFile (artifactPath , []byte ("<coverage/>" ), 0o644 ))
376+
377+ var capturedCommit string
378+ httpClient := & mockHTTPClient {DoFunc : func (req * http.Request ) (* http.Response , error ) {
379+ body , _ := io .ReadAll (req .Body )
380+ _ = req .Body .Close ()
381+ if bytes .Contains (body , []byte ("ArtifactMetadataInput" )) {
382+ payload := `{"data":{"__type":{"inputFields":[]}}}`
383+ return httpResponse (200 , payload ), nil
384+ }
385+ if bytes .Contains (body , []byte ("createArtifact" )) {
386+ var q ReportQuery
387+ _ = json .Unmarshal (body , & q )
388+ capturedCommit = q .Variables .Input .CommitOID
389+ payload := `{"data":{"createArtifact":{"ok":true,"message":"ok","error":""}}}`
390+ return httpResponse (200 , payload ), nil
391+ }
392+ return httpResponse (400 , `{"error":"unexpected"}` ), nil
393+ }}
394+
395+ // Git client returns an error — simulates no git repo available
396+ git := adapters .NewMockGitClient ()
397+ git .SetError (errors .New ("not a git repository" ))
398+ env := adapters .NewMockEnvironment ()
399+ env .Set ("DEEPSOURCE_DSN" , "https://token@localhost:8080" )
400+
401+ svc := NewService (ServiceDeps {
402+ GitClient : git ,
403+ HTTPClient : httpClient ,
404+ FileSystem : adapters .NewOSFileSystem (),
405+ Environment : env ,
406+ Sentry : adapters .NewNoOpSentry (),
407+ Output : adapters .NewBufferOutput (),
408+ Workdir : func () (string , error ) { return tempDir , nil },
409+ })
410+
411+ result , err := svc .Report (context .Background (), Options {
412+ Analyzer : "test-coverage" ,
413+ Key : "python" ,
414+ ValueFile : artifactPath ,
415+ CommitOID : "deadbeef1234567890abcdef1234567890abcdef" ,
416+ })
417+
418+ assert .NoError (t , err )
419+ if assert .NotNil (t , result ) {
420+ assert .Equal (t , "ok" , result .Message )
421+ }
422+ assert .Equal (t , "deadbeef1234567890abcdef1234567890abcdef" , capturedCommit )
423+ }
424+
372425func TestCaptureSkipsUserErrors (t * testing.T ) {
373426 captured := false
374427 mockSentry := & captureSentry {onCapture : func (_ error ) { captured = true }}
0 commit comments