Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion pkg/deploymentrecord/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (c *Client) PostOne(ctx context.Context, record *DeploymentRecord) error {

url := fmt.Sprintf("%s/orgs/%s/artifacts/metadata/deployment-record", c.baseURL, c.org)

body, err := json.Marshal(record)
body, err := buildRequestBody(record)
if err != nil {
return fmt.Errorf("failed to marshal record: %w", err)
}
Expand Down Expand Up @@ -398,6 +398,18 @@ func parseRateLimitDelay(resp *http.Response) time.Duration {
}
}

// buildRequestBody adds return_records=false to a deployment record request body
// which results in a minimal response payload.
func buildRequestBody(record *DeploymentRecord) ([]byte, error) {
return json.Marshal(struct {
DeploymentRecord
ReturnRecords bool `json:"return_records"`
}{
DeploymentRecord: *record,
ReturnRecords: false,
})
}

func waitForBackoff(ctx context.Context, attempt int) error {
if attempt > 0 {
backoff := time.Duration(math.Pow(2,
Expand Down
9 changes: 9 additions & 0 deletions pkg/deploymentrecord/client_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package deploymentrecord

import (
"bytes"
"context"
"errors"
"io"
"net/http"
"net/http/httptest"
"strconv"
Expand Down Expand Up @@ -593,6 +595,13 @@ func TestPostOneSendsCorrectRequest(t *testing.T) {
if got := r.Header.Get("Authorization"); got != "Bearer test-token" {
t.Errorf("Authorization = %s, want Bearer test-token", got)
}
body, err := io.ReadAll(r.Body)
if err != nil {
t.Fatal("unable to read request body")
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test failure message drops the underlying read error, which makes debugging intermittent test/server issues harder. Include err in the fatal message (or use t.Fatalf) so the failure has actionable context.

Suggested change
t.Fatal("unable to read request body")
t.Fatalf("unable to read request body: %v", err)

Copilot uses AI. Check for mistakes.
}
if !bytes.Contains(body, []byte("\"return_records\":false")) {
t.Error("expected '\"return_records\":false' in the request body")
}
Comment on lines +602 to +604
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a raw substring check on the request body can yield false positives (it doesn't validate JSON structure/typing). Consider unmarshalling the body and asserting return_records is a boolean false to make this test more robust.

Copilot uses AI. Check for mistakes.
w.WriteHeader(http.StatusOK)
}))
t.Cleanup(srv.Close)
Expand Down
Loading