CodeSampleX

Sample

github.com/google/go-cmp v0.5.4: cmp.Diff

Verified sample for golang github.com/google/go-cmp v0.5.4: cmp.Diff. The contract ran on go 1.26 · linux debian/x64 · docker and passed: cmp.Diff returns an…

sha256:7b1c161843a2d8adb538d60ff5ba72ac007d7a75958292eff2976dbca18a6f2c

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-09-05

Case

HOW
Goal
verify pkg:golang/github.com/google/go-cmp@v0.5.4
Packages
Symbols
  • github.com/google/go-cmp/cmp.Diff
Created
2026-09-05T04:57:50Z

Contract

  1. cmp.Diff returns an empty string when compared values are identical
  2. cmp.Diff returns a non-empty diff string detailing differences when values differ
  3. cmp.Diff supports cmpopts.IgnoreFields to exclude specified struct fields from comparison
  4. cmp.Diff supports cmpopts.SortSlices for order-independent slice comparison
  5. cmp.Diff produces detailed diff output for map key additions modifications and deletions
  6. cmp.Diff respects custom cmp.Comparer options when computing differences

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 pkg:golang/github.com/google/go-cmp@v0.5.4
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/google/go-cmp@v0.5.4
Demonstrate these symbols/APIs:
  - github.com/google/go-cmp/cmp.Diff

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:b9d624f0cd665a70f466fa1e3024584905ae3313dd4bb6047ecdddc7f832e1b3","contract":["cmp.Diff returns an empty string when compared values are identical","cmp.Diff returns a non-empty diff string detailing differences when values differ","cmp.Diff supports cmpopts.IgnoreFields to exclude specified struct fields from comparison","cmp.Diff supports cmpopts.SortSlices for order-independent slice comparison","cmp.Diff produces detailed diff output for map key additions modifications and deletions","cmp.Diff respects custom cmp.Comparer options when computing differences"],"goal":"verify pkg:golang/github.com/google/go-cmp@v0.5.4","kind":"HOW","packages":["pkg:golang/github.com/google/go-cmp@v0.5.4"],"schemaVersion":1,"symbols":["github.com/google/go-cmp/cmp.Diff"]},"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.4"],"schemaVersion":1,"subject":"pkg:golang/github.com/google/go-cmp@v0.5.4","symbols":["github.com/google/go-cmp/cmp.Diff"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.22

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

require golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect
go.sum
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
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 pkg:golang/github.com/google/go-cmp@v0.5.4",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/google/go-cmp@v0.5.4"
  ],
  "symbols": [
    "github.com/google/go-cmp/cmp.Diff"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"math"
	"os"
	"strings"

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

type recordData struct {
	ID        int
	Tag       string
	Timestamp int64
}

type metricValue struct {
	Val float64
}

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 successfully.")
}

func runContractTests() error {
	// 1. cmp.Diff returns an empty string when compared values are identical
	diffInt := cmp.Diff(42, 42)
	if diffInt != "" {
		return fmt.Errorf("expected empty diff for equal ints, got: %s", diffInt)
	}
	sliceA := []string{"alpha", "beta"}
	sliceB := []string{"alpha", "beta"}
	if diff := cmp.Diff(sliceA, sliceB); diff != "" {
		return fmt.Errorf("expected empty diff for identical slices, got: %s", diff)
	}
	recA := recordData{ID: 10, Tag: "active", Timestamp: 1000}
	recB := recordData{ID: 10, Tag: "active", Timestamp: 1000}
	if diff := cmp.Diff(recA, recB); diff != "" {
		return fmt.Errorf("expected empty diff for identical records, got: %s", diff)
	}

	// 2. cmp.Diff returns a non-empty diff string detailing differences when values differ
	diffDiff := cmp.Diff("left-val", "right-val")
	if diffDiff == "" {
		return fmt.Errorf("expected non-empty diff for distinct strings")
	}
	if !strings.Contains(diffDiff, "left-val") || !strings.Contains(diffDiff, "right-val") {
		return fmt.Errorf("expected diff to show distinct values, got: %s", diffDiff)
	}

	// 3. cmp.Diff supports cmpopts.IgnoreFields to exclude specified struct fields from comparison
	rec1 := recordData{ID: 20, Tag: "cluster-1", Timestamp: 1000}
	rec2 := recordData{ID: 20, Tag: "cluster-1", Timestamp: 2000}
	if cmp.Diff(rec1, rec2) == "" {
		return fmt.Errorf("expected diff when Timestamp differs without IgnoreFields")
	}
	diffIgnored := cmp.Diff(rec1, rec2, cmpopts.IgnoreFields(recordData{}, "Timestamp"))
	if diffIgnored != "" {
		return fmt.Errorf("expected empty diff with Timestamp ignored, got: %s", diffIgnored)
	}

	// 4. cmp.Diff supports cmpopts.SortSlices for order-independent slice comparison
	s1 := []int{7, 1, 9, 3}
	s2 := []int{1, 3, 7, 9}
	if cmp.Diff(s1, s2) == "" {
		return fmt.Errorf("expected diff for differently ordered slices without SortSlices")
	}
	lessFunc := func(x, y int) bool { return x < y }
	diffSorted := cmp.Diff(s1, s2, cmpopts.SortSlices(lessFunc))
	if diffSorted != "" {
		return fmt.Errorf("expected empty diff with SortSlices, got: %s", diffSorted)
	}

	// 5. cmp.Diff produces detailed diff output for map key additions modifications and deletions
	map1 := map[string]int{"k1": 10, "k2": 20, "k3": 30}
	map2 := map[string]int{"k1": 10, "k2": 25, "k4": 40}
	diffMap := cmp.Diff(map1, map2)
	if diffMap == "" {
		return fmt.Errorf("expected non-empty diff for differing maps")
	}
	if !strings.Contains(diffMap, "k2") || !strings.Contains(diffMap, "k3") || !strings.Contains(diffMap, "k4") {
		return fmt.Errorf("expected diff to detail changed keys, got: %s", diffMap)
	}

	// 6. cmp.Diff respects custom cmp.Comparer options when computing differences
	m1 := metricValue{Val: 1.0002}
	m2 := metricValue{Val: 1.0005}
	if cmp.Diff(m1, m2) == "" {
		return fmt.Errorf("expected non-empty diff for distinct metric values without Comparer")
	}
	approxComp := cmp.Comparer(func(x, y metricValue) bool {
		return math.Abs(x.Val-y.Val) < 0.001
	})
	diffApprox := cmp.Diff(m1, m2, approxComp)
	if diffApprox != "" {
		return fmt.Errorf("expected empty diff with approx Comparer, got: %s", diffApprox)
	}

	return nil
}

Origin Seeder

anonymous