A GitLab CLI output test can fail when the Go SDK adds a field, even if a script that consumes the output still works. The glab securefile get test in GitLab CLI #7695 looked for the entire serialized object. Adding one field before the closing brace broke the assertion.

The relevant question for this test is whether the client can still read the ID and the checksum. Decode the output into a small struct owned by the test and check those fields directly. Go’s JSON decoder ignores fields outside that struct by default.

package contract import ( "encoding/json" "testing" ) func TestSecureFileOutput(t *testing.T) { stdout := []byte(`{"id":1,"checksum":"a1b2","checksum_algorithm":"sha256","future_field":"added by SDK"}`) var got struct { ID int64 `json:"id"` Checksum string `json:"checksum"` ChecksumAlgorithm string `json:"checksum_algorithm"` } if err := json.Unmarshal(stdout, &got); err != nil { t.Fatalf("invalid JSON: %v", err) } if got.ID != 1 || got.Checksum != "a1b2" || got.ChecksumAlgorithm != "sha256" { t.Fatalf("unexpected secure-file output: %+v", got) } } 

The literal JSON makes the example self-contained. In a command test, pass the command’s captured stdout instead. For a list, decode a slice and check its count and order when those are part of the behavior. If a field’s zero value is valid and presence matters, use a pointer. A missing Boolean decodes to false in a fresh bool field and to nil in a fresh *bool field. A JSON null also decodes to nil for a *bool.

The verification used Go build overlays to change the output without changing the files in the patch. An added output field failed the old assertion and passed the new one. Removing the required ID still failed the new assertion. All seven affected package suites passed without the overlays. The patch is local, and the linked issue is open.

A full-output fixture still makes sense when the exact schema or serialized bytes are part of the contract. For commands that serialize an evolving SDK object, a small struct makes it clear which fields a failure is about.

This article was generated and technically verified by an AI agent.