CodeSampleX

Sample

github.com/google/go-cmp v0.5.7: cmp.Equal

Verified sample for golang github.com/google/go-cmp v0.5.7: cmp.Equal. The contract ran on go 1.26 · linux debian/x64 · docker and passed.

sha256:b829e03598baf4ae5bd6b85b9d412f2673e74ad5d6c4ae435374219a48117ddc

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 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.Equal in pkg:golang/github.com/google/go-cmp@v0.5.7
Packages
Symbols
  • github.com/google/go-cmp/cmp.Equal
Created
2026-11-05T09:54:56Z

Contract

  1. cmp.Equal returns true for identical primitive, slice, and map values and false for differences
  2. cmp.Equal returns true for identical structs with exported fields and false for struct field differences
  3. cmp.Equal supports cmp.Comparer for custom equality predicates
  4. cmpopts.IgnoreFields excludes specified struct fields from comparison in cmp.Equal
  5. cmpopts.SortSlices compares unordered slices in cmp.Equal
  6. cmpopts.IgnoreUnexported and cmp.AllowUnexported handle structs with unexported fields in cmp.Equal
  7. cmp.Transformer applies value transformations before comparison in cmp.Equal
  8. cmpopts.EquateEmpty treats nil and empty slices or maps as equal in cmp.Equal

Files

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • spec.json
  • test/contract.go

Download the source artifact (tar.gz)

Source

PROMPT.md
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.Equal 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.Equal

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.
csx.json
{"case":{"caseId":"case:sha256:dfa59f86f2b5b721a3dbe897a3d6186720ef3c58b5a0f442d8781693d68a51f5","contract":["cmp.Equal returns true for identical primitive, slice, and map values and false for differences","cmp.Equal returns true for identical structs with exported fields and false for struct field differences","cmp.Equal supports cmp.Comparer for custom equality predicates","cmpopts.IgnoreFields excludes specified struct fields from comparison in cmp.Equal","cmpopts.SortSlices compares unordered slices in cmp.Equal","cmpopts.IgnoreUnexported and cmp.AllowUnexported handle structs with unexported fields in cmp.Equal","cmp.Transformer applies value transformations before comparison in cmp.Equal","cmpopts.EquateEmpty treats nil and empty slices or maps as equal in cmp.Equal"],"goal":"verify github.com/google/go-cmp/cmp.Equal 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.Equal"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","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.Equal"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.22

require github.com/google/go-cmp v0.5.7

require golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect
go.sum
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=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/google/go-cmp/cmp.Equal 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.Equal"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"
	"strings"

	"github.com/google/go-cmp/cmp"
	"github.com/google/go-cmp/cmp/cmpopts"
)

type accountRecord struct {
	ID        int
	Handle    string
	UpdatedAt string
}

type privateHolder struct {
	Label  string
	hidden string
}

func main() {
	if err := runContractTests(); err != nil {
		fmt.Fprintf(os.Stderr, "Contract test failed: %v\n", err)
		os.Exit(1)
	}
	fmt.Println("All contract tests passed.")
}

func runContractTests() error {
	// 1. cmp.Equal returns true for identical primitive, slice, and map values and false for differences
	if !cmp.Equal(100, 100) {
		return fmt.Errorf("expected 100 == 100")
	}
	if cmp.Equal(100, 101) {
		return fmt.Errorf("expected 100 != 101")
	}
	if !cmp.Equal([]string{"first", "second"}, []string{"first", "second"}) {
		return fmt.Errorf("expected equal string slices")
	}
	if cmp.Equal([]string{"first", "second"}, []string{"second", "first"}) {
		return fmt.Errorf("expected ordered slices to differ by default")
	}
	if !cmp.Equal(map[string]int{"k1": 10, "k2": 20}, map[string]int{"k2": 20, "k1": 10}) {
		return fmt.Errorf("expected map key/value equality")
	}

	// 2. cmp.Equal returns true for identical structs with exported fields and false for struct field differences
	a1 := accountRecord{ID: 1, Handle: "user_one", UpdatedAt: "2026-01-01"}
	a2 := accountRecord{ID: 1, Handle: "user_one", UpdatedAt: "2026-01-01"}
	a3 := accountRecord{ID: 1, Handle: "user_two", UpdatedAt: "2026-01-01"}
	if !cmp.Equal(a1, a2) {
		return fmt.Errorf("expected identical structs to be equal")
	}
	if cmp.Equal(a1, a3) {
		return fmt.Errorf("expected structs with differing fields to be unequal")
	}

	// 3. cmp.Equal supports cmp.Comparer for custom equality predicates
	approxFloat := cmp.Comparer(func(x, y float64) bool {
		diff := x - y
		if diff < 0 {
			diff = -diff
		}
		return diff < 0.001
	})
	if !cmp.Equal(2.0001, 2.0002, approxFloat) {
		return fmt.Errorf("expected custom comparer to treat close floats as equal")
	}
	if cmp.Equal(2.0, 3.0, approxFloat) {
		return fmt.Errorf("expected custom comparer to treat distinct floats as unequal")
	}

	// 4. cmpopts.IgnoreFields excludes specified struct fields from comparison in cmp.Equal
	a4 := accountRecord{ID: 2, Handle: "user_three", UpdatedAt: "2026-01-01"}
	a5 := accountRecord{ID: 2, Handle: "user_three", UpdatedAt: "2026-06-15"}
	if cmp.Equal(a4, a5) {
		return fmt.Errorf("expected structs to differ without IgnoreFields")
	}
	if !cmp.Equal(a4, a5, cmpopts.IgnoreFields(accountRecord{}, "UpdatedAt")) {
		return fmt.Errorf("expected structs to match with UpdatedAt ignored")
	}

	// 5. cmpopts.SortSlices compares unordered slices in cmp.Equal
	s1 := []int{9, 3, 7, 1}
	s2 := []int{1, 3, 7, 9}
	lessInt := func(a, b int) bool { return a < b }
	if cmp.Equal(s1, s2) {
		return fmt.Errorf("expected unordered slices to differ by default")
	}
	if !cmp.Equal(s1, s2, cmpopts.SortSlices(lessInt)) {
		return fmt.Errorf("expected SortSlices to match elements regardless of order")
	}

	// 6. cmpopts.IgnoreUnexported and cmp.AllowUnexported handle structs with unexported fields in cmp.Equal
	p1 := privateHolder{Label: "item", hidden: "val-1"}
	p2 := privateHolder{Label: "item", hidden: "val-2"}
	if !cmp.Equal(p1, p2, cmpopts.IgnoreUnexported(privateHolder{})) {
		return fmt.Errorf("expected IgnoreUnexported to match structs differing only in unexported fields")
	}
	p3 := privateHolder{Label: "item", hidden: "val-1"}
	if !cmp.Equal(p1, p3, cmp.AllowUnexported(privateHolder{})) {
		return fmt.Errorf("expected AllowUnexported to match identical structs with unexported fields")
	}

	// 7. cmp.Transformer applies value transformations before comparison in cmp.Equal
	foldCase := cmp.Transformer("ToLower", strings.ToLower)
	if !cmp.Equal("SampleText", "sampletext", foldCase) {
		return fmt.Errorf("expected transformer to normalize casing")
	}

	// 8. cmpopts.EquateEmpty treats nil and empty slices or maps as equal in cmp.Equal
	var nilSlice []string
	emptySlice := []string{}
	if cmp.Equal(nilSlice, emptySlice) {
		return fmt.Errorf("expected nil slice and empty slice to differ by default")
	}
	if !cmp.Equal(nilSlice, emptySlice, cmpopts.EquateEmpty()) {
		return fmt.Errorf("expected EquateEmpty to treat nil and empty slice as equal")
	}

	return nil
}

Origin Seeder

anonymous