@@ -3,6 +3,7 @@ package main
33import (
44 "context"
55 "encoding/json"
6+ "fmt"
67 "io"
78 "net/http"
89 "net/http/httptest"
@@ -585,12 +586,10 @@ func TestRunAgentFlow_SigningSuccess_SingleArtifact(t *testing.T) {
585586 }
586587 defer func () { createMetadataClientFunc = originalCreateClient }()
587588
588- // Mock OCI handler to return 1 successful upload
589+ // Mock OCI handler to return index digest
589590 originalOCIHandler := ociHandleUploadsFunc
590- ociHandleUploadsFunc = func (ctx context.Context , cfg * models.OCIConfig , workspace , agentType , version string ) ([]models.ArtifactUploadResult , error ) {
591- return []models.ArtifactUploadResult {
592- createSuccessfulUploadResult ("linux-tar" , "sha256:abc123" , "v1.2.3-linux-amd64" ),
593- }, nil
591+ ociHandleUploadsFunc = func (ctx context.Context , cfg * models.OCIConfig , workspace , version string ) (string , error ) {
592+ return "sha256:index123" , nil
594593 }
595594 defer func () { ociHandleUploadsFunc = originalOCIHandler }()
596595
@@ -604,14 +603,14 @@ func TestRunAgentFlow_SigningSuccess_SingleArtifact(t *testing.T) {
604603 assert .Equal (t , "/v1/signing/agent-metadata-action/sign" , r .URL .Path )
605604 assert .Equal (t , "Bearer test-token" , r .Header .Get ("Authorization" ))
606605
607- // Validate request body
606+ // Validate request body - should be signing the manifest index
608607 body , _ := io .ReadAll (r .Body )
609608 var signingReq models.SigningRequest
610609 json .Unmarshal (body , & signingReq )
611610 assert .Equal (t , "docker.io" , signingReq .Registry )
612611 assert .Equal (t , "newrelic/agents" , signingReq .Repository )
613- assert .Equal (t , "v1 .2.3-linux-amd64 " , signingReq .Tag )
614- assert .Equal (t , "sha256:abc123 " , signingReq .Digest )
612+ assert .Equal (t , "1 .2.3" , signingReq .Tag )
613+ assert .Equal (t , "sha256:index123 " , signingReq .Digest )
615614
616615 w .WriteHeader (http .StatusOK )
617616 w .Write ([]byte (`{"success": true}` ))
@@ -649,10 +648,9 @@ func TestRunAgentFlow_SigningSuccess_SingleArtifact(t *testing.T) {
649648 // Verify signing requests
650649 assert .Equal (t , 1 , requestCount , "Should have made 1 signing request" )
651650
652- // Verify logging
653- assert .Contains (t , outputStr , "Starting artifact signing for 1 artifacts" )
654- assert .Contains (t , outputStr , "Successfully signed artifact linux-tar" )
655- assert .Contains (t , outputStr , "Artifact signing complete: 1/1 signed successfully" )
651+ // Verify logging - now signing the manifest index
652+ assert .Contains (t , outputStr , "Starting manifest index signing" )
653+ assert .Contains (t , outputStr , "Successfully signed manifest index" )
656654 assert .NotContains (t , stderrStr , "::error::" )
657655}
658656
@@ -666,8 +664,9 @@ func TestRunAgentFlow_SigningDisabled_OCINotEnabled(t *testing.T) {
666664
667665 // Mock OCI handler should not be called since OCI is disabled
668666 originalOCIHandler := ociHandleUploadsFunc
669- ociHandleUploadsFunc = func (ctx context.Context , cfg * models.OCIConfig , workspace , agentType , version string ) ([]models.ArtifactUploadResult , error ) {
670- return []models.ArtifactUploadResult {}, nil
667+ ociHandleUploadsFunc = func (ctx context.Context , cfg * models.OCIConfig , workspace , version string ) (string , error ) {
668+ t .Fatal ("OCI handler should not be called when OCI is disabled" )
669+ return "" , nil
671670 }
672671 defer func () { ociHandleUploadsFunc = originalOCIHandler }()
673672
@@ -706,7 +705,7 @@ func TestRunAgentFlow_SigningDisabled_OCINotEnabled(t *testing.T) {
706705
707706 // Verify NO signing requests were made
708707 assert .Equal (t , 0 , requestCount , "Should have made 0 signing requests" )
709- assert .NotContains (t , outputStr , "Starting artifact signing" )
708+ assert .NotContains (t , outputStr , "Starting manifest index signing" )
710709 assert .NotContains (t , stderrStr , "::error::" )
711710}
712711
@@ -718,13 +717,10 @@ func TestRunAgentFlow_SigningSkipped_AllUploadsFailed(t *testing.T) {
718717 }
719718 defer func () { createMetadataClientFunc = originalCreateClient }()
720719
721- // Mock OCI handler to return only failed uploads
720+ // Mock OCI handler to return error (fail-fast behavior)
722721 originalOCIHandler := ociHandleUploadsFunc
723- ociHandleUploadsFunc = func (ctx context.Context , cfg * models.OCIConfig , workspace , agentType , version string ) ([]models.ArtifactUploadResult , error ) {
724- return []models.ArtifactUploadResult {
725- createFailedUploadResult ("linux-tar" ),
726- createFailedUploadResult ("windows-zip" ),
727- }, nil
722+ ociHandleUploadsFunc = func (ctx context.Context , cfg * models.OCIConfig , workspace , version string ) (string , error ) {
723+ return "" , fmt .Errorf ("artifact upload failed for linux-tar: upload error" )
728724 }
729725 defer func () { ociHandleUploadsFunc = originalOCIHandler }()
730726
@@ -756,17 +752,15 @@ func TestRunAgentFlow_SigningSkipped_AllUploadsFailed(t *testing.T) {
756752 mockClient := & mockMetadataClient {}
757753 err = runAgentFlow (ctx , mockClient , workspace , "java" , "1.2.3" )
758754
759- // Verify success (signing is skipped but flow continues)
760- require .NoError (t , err )
755+ // Verify error (fail-fast behavior)
756+ require .Error (t , err )
757+ assert .Contains (t , err .Error (), "binary upload failed" )
761758
762759 outputStr := getStdout ()
763760
764761 // Verify NO signing requests were made
765762 assert .Equal (t , 0 , requestCount , "Should have made 0 signing requests" )
766-
767- // Verify warning was logged
768- assert .Contains (t , outputStr , "OCI registry is enabled but no artifacts were successfully uploaded" )
769- assert .NotContains (t , outputStr , "Starting artifact signing" )
763+ assert .NotContains (t , outputStr , "Starting manifest index signing" )
770764}
771765
772766func TestRunAgentFlow_SigningError_ServiceFailure (t * testing.T ) {
@@ -777,12 +771,10 @@ func TestRunAgentFlow_SigningError_ServiceFailure(t *testing.T) {
777771 }
778772 defer func () { createMetadataClientFunc = originalCreateClient }()
779773
780- // Mock OCI handler to return 1 successful upload
774+ // Mock OCI handler to return index digest
781775 originalOCIHandler := ociHandleUploadsFunc
782- ociHandleUploadsFunc = func (ctx context.Context , cfg * models.OCIConfig , workspace , agentType , version string ) ([]models.ArtifactUploadResult , error ) {
783- return []models.ArtifactUploadResult {
784- createSuccessfulUploadResult ("linux-tar" , "sha256:abc123" , "v1.2.3-linux-amd64" ),
785- }, nil
776+ ociHandleUploadsFunc = func (ctx context.Context , cfg * models.OCIConfig , workspace , version string ) (string , error ) {
777+ return "sha256:index123" , nil
786778 }
787779 defer func () { ociHandleUploadsFunc = originalOCIHandler }()
788780
@@ -825,5 +817,5 @@ func TestRunAgentFlow_SigningError_ServiceFailure(t *testing.T) {
825817 assert .Equal (t , 3 , requestCount , "Should have made 3 signing requests (retries)" )
826818 assert .Contains (t , outputStr , "Signing attempt 1 failed" )
827819 assert .Contains (t , outputStr , "Signing attempt 2 failed" )
828- assert .Contains (t , outputStr , "Failed to sign artifact linux-tar after 3 attempts" )
820+ assert .Contains (t , outputStr , "Failed to sign manifest index after 3 attempts" )
829821}
0 commit comments