Sample
github.com/google/go-cmp v0.5.7: cmpopts.IgnoreFields
Verified sample for golang github.com/google/go-cmp v0.5.7: cmpopts.IgnoreFields. The contract ran on go 1.26 · linux debian/x64 · docker and passed.
sha256:8f2cbd97ad9da7073017c8328620f39674fbaf5a531de61bd9b1ad5d1e5977f8
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 1
- Signing keys that built it
- 1
Declared environment
linux 24 · ubuntu · glibc 2.39 x64 go
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a… |
2026-11-05 |
Case
HOW- Goal
- verify github.com/google/go-cmp/cmp/cmpopts.IgnoreFields in pkg:golang/github.com/google/go-cmp@v0.5.7
- Packages
- Symbols
-
- github.com/google/go-cmp/cmp/cmpopts.IgnoreFields
- Created
- 2026-11-05T21:43:28Z
Contract
- cmpopts.IgnoreFields ignores a single specified struct field during comparison
- cmpopts.IgnoreFields ignores multiple specified struct fields during comparison
- cmpopts.IgnoreFields detects differences when non-ignored fields differ
- cmpopts.IgnoreFields applies field ignoring when comparing slices of structs
- cmpopts.IgnoreFields ignores fields in nested structs when target struct type is specified
Files
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Source
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify github.com/google/go-cmp/cmp/cmpopts.IgnoreFields in pkg:golang/github.com/google/go-cmp@v0.5.7
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/google/go-cmp@v0.5.7
Demonstrate these symbols/APIs:
- github.com/google/go-cmp/cmp/cmpopts.IgnoreFields
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:0f229431e23bcbdcbb1fe533f59294c73c9505f8c740eaeaf0f16720dabb97fc","contract":["cmpopts.IgnoreFields ignores a single specified struct field during comparison","cmpopts.IgnoreFields ignores multiple specified struct fields during comparison","cmpopts.IgnoreFields detects differences when non-ignored fields differ","cmpopts.IgnoreFields applies field ignoring when comparing slices of structs","cmpopts.IgnoreFields ignores fields in nested structs when target struct type is specified"],"goal":"verify github.com/google/go-cmp/cmp/cmpopts.IgnoreFields in pkg:golang/github.com/google/go-cmp@v0.5.7","kind":"HOW","packages":["pkg:golang/github.com/google/go-cmp@v0.5.7"],"schemaVersion":1,"symbols":["github.com/google/go-cmp/cmp/cmpopts.IgnoreFields"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/google/go-cmp@v0.5.7"],"schemaVersion":1,"subject":"pkg:golang/github.com/google/go-cmp@v0.5.7","symbols":["github.com/google/go-cmp/cmp/cmpopts.IgnoreFields"],"verifierAdapter":"golang@1"}
module sample
go 1.22.0
require github.com/google/go-cmp v0.5.7
require golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
package main
import (
"fmt"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
)
// AuditRecord represents a structured record with metadata fields.
type AuditRecord struct {
ID int
Action string
Actor string
Timestamp string
Metadata RecordMetadata
}
// RecordMetadata holds nested details for an audit record.
type RecordMetadata struct {
TraceID string
Detail string
}
// CompareRecords compares two AuditRecord values while ignoring the specified fields.
func CompareRecords(a, b AuditRecord, ignored ...string) bool {
return cmp.Equal(a, b, cmpopts.IgnoreFields(AuditRecord{}, ignored...))
}
func main() {
r1 := AuditRecord{
ID: 1,
Action: "update",
Actor: "operator",
Timestamp: "2026-01-01T00:00:00Z",
}
r2 := AuditRecord{
ID: 1,
Action: "update",
Actor: "operator",
Timestamp: "2026-01-01T01:00:00Z",
}
fmt.Printf("Default equal: %v\n", cmp.Equal(r1, r2))
fmt.Printf("Ignoring Timestamp equal: %v\n", CompareRecords(r1, r2, "Timestamp"))
}
{
"schemaVersion": 1,
"goal": "verify github.com/google/go-cmp/cmp/cmpopts.IgnoreFields in pkg:golang/github.com/google/go-cmp@v0.5.7",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/google/go-cmp@v0.5.7"
],
"symbols": [
"github.com/google/go-cmp/cmp/cmpopts.IgnoreFields"
]
}
package main
import (
"fmt"
"os"
"strings"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
)
type auditEvent struct {
ID int
Action string
Actor string
Timestamp string
Payload eventPayload
}
type eventPayload struct {
CorrelationID string
Message string
}
func main() {
// 1. cmpopts.IgnoreFields ignores a single specified struct field during comparison
{
a := auditEvent{
ID: 1,
Action: "login",
Actor: "user-1",
Timestamp: "2026-09-01T00:00:00Z",
}
b := auditEvent{
ID: 1,
Action: "login",
Actor: "user-1",
Timestamp: "2026-09-01T12:00:00Z",
}
if cmp.Equal(a, b) {
fmt.Fprintln(os.Stderr, "FAIL: assertion 1 - expected inequality when Timestamp differs without IgnoreFields")
os.Exit(1)
}
if !cmp.Equal(a, b, cmpopts.IgnoreFields(auditEvent{}, "Timestamp")) {
fmt.Fprintln(os.Stderr, "FAIL: assertion 1 - expected equality when ignoring Timestamp")
os.Exit(1)
}
if diff := cmp.Diff(a, b, cmpopts.IgnoreFields(auditEvent{}, "Timestamp")); diff != "" {
fmt.Fprintf(os.Stderr, "FAIL: assertion 1 - expected empty diff when ignoring Timestamp, got:\n%s\n", diff)
os.Exit(1)
}
}
// 2. cmpopts.IgnoreFields ignores multiple specified struct fields during comparison
{
a := auditEvent{
ID: 100,
Action: "read",
Actor: "reader-a",
Timestamp: "2026-09-02T01:00:00Z",
}
b := auditEvent{
ID: 200,
Action: "read",
Actor: "reader-a",
Timestamp: "2026-09-02T02:00:00Z",
}
if !cmp.Equal(a, b, cmpopts.IgnoreFields(auditEvent{}, "ID", "Timestamp")) {
fmt.Fprintln(os.Stderr, "FAIL: assertion 2 - expected equality when ignoring ID and Timestamp")
os.Exit(1)
}
if diff := cmp.Diff(a, b, cmpopts.IgnoreFields(auditEvent{}, "ID", "Timestamp")); diff != "" {
fmt.Fprintf(os.Stderr, "FAIL: assertion 2 - expected empty diff when ignoring ID and Timestamp, got:\n%s\n", diff)
os.Exit(1)
}
}
// 3. cmpopts.IgnoreFields detects differences when non-ignored fields differ
{
a := auditEvent{
ID: 10,
Action: "create",
Actor: "admin",
Timestamp: "2026-09-03T00:00:00Z",
}
b := auditEvent{
ID: 10,
Action: "delete",
Actor: "admin",
Timestamp: "2026-09-03T10:00:00Z",
}
if cmp.Equal(a, b, cmpopts.IgnoreFields(auditEvent{}, "Timestamp")) {
fmt.Fprintln(os.Stderr, "FAIL: assertion 3 - expected inequality when non-ignored Action differs")
os.Exit(1)
}
diff := cmp.Diff(a, b, cmpopts.IgnoreFields(auditEvent{}, "Timestamp"))
if !strings.Contains(diff, "create") || !strings.Contains(diff, "delete") {
fmt.Fprintf(os.Stderr, "FAIL: assertion 3 - expected diff to contain Action values, got:\n%s\n", diff)
os.Exit(1)
}
}
// 4. cmpopts.IgnoreFields applies field ignoring when comparing slices of structs
{
listA := []auditEvent{
{ID: 1, Action: "sync", Timestamp: "10:00"},
{ID: 2, Action: "flush", Timestamp: "10:01"},
}
listB := []auditEvent{
{ID: 1, Action: "sync", Timestamp: "11:00"},
{ID: 2, Action: "flush", Timestamp: "11:01"},
}
if cmp.Equal(listA, listB) {
fmt.Fprintln(os.Stderr, "FAIL: assertion 4 - expected inequality for slices without IgnoreFields")
os.Exit(1)
}
if !cmp.Equal(listA, listB, cmpopts.IgnoreFields(auditEvent{}, "Timestamp")) {
fmt.Fprintln(os.Stderr, "FAIL: assertion 4 - expected equality for slices when ignoring Timestamp")
os.Exit(1)
}
}
// 5. cmpopts.IgnoreFields ignores fields in nested structs when target struct type is specified
{
a := auditEvent{
ID: 5,
Action: "dispatch",
Payload: eventPayload{
CorrelationID: "corr-111",
Message: "event processed",
},
}
b := auditEvent{
ID: 5,
Action: "dispatch",
Payload: eventPayload{
CorrelationID: "corr-222",
Message: "event processed",
},
}
if cmp.Equal(a, b) {
fmt.Fprintln(os.Stderr, "FAIL: assertion 5 - expected inequality when nested CorrelationID differs")
os.Exit(1)
}
if !cmp.Equal(a, b, cmpopts.IgnoreFields(eventPayload{}, "CorrelationID")) {
fmt.Fprintln(os.Stderr, "FAIL: assertion 5 - expected equality when ignoring nested CorrelationID")
os.Exit(1)
}
}
fmt.Println("PASS: cmpopts.IgnoreFields contract passed")
}
Origin Seeder
anonymous