CodeSampleX

Sample

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

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

sha256:c7206547134e6d3d74cae03ea3cd19b46673c3588c5153c0019c7150cdd6b2dd

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 go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 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-09-15

Case

HOW
Goal
verify github.com/google/go-cmp/cmp.Diff in pkg:golang/github.com/google/go-cmp@v0.6.0
Packages
Symbols
  • github.com/google/go-cmp/cmp.Diff
Environment
go 1.26
Created
2026-09-15T02:27:18Z

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 readable diffs detailing map modifications additions and deletions

Files

  • PROMPT.md
  • csx.json
  • diff.go
  • go.mod
  • go.sum
  • spec.json
  • test/contract_test.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.Diff in pkg:golang/github.com/google/go-cmp@v0.6.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/google/go-cmp@v0.6.0
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:036414808c292b0172f5879895a547f038ac5ba4ea990bf45058f32493a3b3df","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 readable diffs detailing map modifications additions and deletions"],"goal":"verify github.com/google/go-cmp/cmp.Diff in pkg:golang/github.com/google/go-cmp@v0.6.0","kind":"HOW","packages":["pkg:golang/github.com/google/go-cmp@v0.6.0"],"schemaVersion":1,"symbols":["github.com/google/go-cmp/cmp.Diff"]},"contractCommand":["go","test","./..."],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","libc":"glibc","libcVersion":"2.39","moduleSystem":"go.mod","os":"linux","osVersionBucket":"24","packageManager":"go","runtime":"go","runtimeVersion":"1.26","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/google/go-cmp@v0.6.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/google/go-cmp@v0.6.0","symbols":["github.com/google/go-cmp/cmp.Diff"],"verifierAdapter":"golang@1"}
diff.go
package sample

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

// UserProfile represents a user entity for comparison demonstrations.
type UserProfile struct {
	ID        int
	Username  string
	Roles     []string
	Metadata  map[string]string
	SecretKey string
}

// CompareProfiles compares two UserProfile values and returns the diff string.
// If ignoreSecret is true, SecretKey is excluded from the comparison.
func CompareProfiles(x, y UserProfile, ignoreSecret bool) string {
	var opts []cmp.Option
	if ignoreSecret {
		opts = append(opts, cmpopts.IgnoreFields(UserProfile{}, "SecretKey"))
	}
	return cmp.Diff(x, y, opts...)
}

// DiffValues wraps cmp.Diff with custom comparison options.
func DiffValues[T any](x, y T, opts ...cmp.Option) string {
	return cmp.Diff(x, y, opts...)
}
go.mod
module example.com/go-cmp-diff

go 1.24.0

require github.com/google/go-cmp v0.6.0
go.sum
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/google/go-cmp/cmp.Diff in pkg:golang/github.com/google/go-cmp@v0.6.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/google/go-cmp@v0.6.0"
  ],
  "symbols": [
    "github.com/google/go-cmp/cmp.Diff"
  ]
}
test/contract_test.go
package test

import (
	"strings"
	"testing"

	sample "example.com/go-cmp-diff"
	"github.com/google/go-cmp/cmp"
	"github.com/google/go-cmp/cmp/cmpopts"
)

func TestDiffContract(t *testing.T) {
	// 1. cmp.Diff returns an empty string when compared values are identical
	t.Run("returns empty string on equal values", func(t *testing.T) {
		a := sample.UserProfile{
			ID:       1,
			Username: "alice",
			Roles:    []string{"admin", "editor"},
			Metadata: map[string]string{"env": "prod"},
		}
		b := sample.UserProfile{
			ID:       1,
			Username: "alice",
			Roles:    []string{"admin", "editor"},
			Metadata: map[string]string{"env": "prod"},
		}

		diff := cmp.Diff(a, b)
		if diff != "" {
			t.Fatalf("expected empty diff for equal structs, got:\n%s", diff)
		}
	})

	// 2. cmp.Diff returns a non-empty diff string detailing differences when values differ
	t.Run("returns non-empty diff detailing differences on unequal values", func(t *testing.T) {
		a := sample.UserProfile{
			ID:       1,
			Username: "alice",
			Roles:    []string{"admin"},
		}
		b := sample.UserProfile{
			ID:       1,
			Username: "bob",
			Roles:    []string{"admin", "viewer"},
		}

		diff := cmp.Diff(a, b)
		if diff == "" {
			t.Fatal("expected non-empty diff for unequal structs, got empty string")
		}
		if !strings.Contains(diff, "alice") || !strings.Contains(diff, "bob") {
			t.Fatalf("expected diff to show username differences, got:\n%s", diff)
		}
	})

	// 3. cmp.Diff supports cmpopts.IgnoreFields to exclude specified struct fields from comparison
	t.Run("supports cmpopts.IgnoreFields to ignore struct fields", func(t *testing.T) {
		a := sample.UserProfile{
			ID:        1,
			Username:  "alice",
			SecretKey: "secret-token-a",
		}
		b := sample.UserProfile{
			ID:        1,
			Username:  "alice",
			SecretKey: "secret-token-b",
		}

		diffWithoutOption := cmp.Diff(a, b)
		if diffWithoutOption == "" {
			t.Fatal("expected diff when secret keys differ")
		}

		diffWithIgnore := sample.CompareProfiles(a, b, true)
		if diffWithIgnore != "" {
			t.Fatalf("expected empty diff when ignoring SecretKey, got:\n%s", diffWithIgnore)
		}
	})

	// 4. cmp.Diff supports cmpopts.SortSlices for order-independent slice comparison
	t.Run("supports cmpopts.SortSlices for order-independent comparison", func(t *testing.T) {
		sliceA := []string{"apple", "banana", "cherry"}
		sliceB := []string{"cherry", "apple", "banana"}

		diffUnsorted := cmp.Diff(sliceA, sliceB)
		if diffUnsorted == "" {
			t.Fatal("expected diff without sort option")
		}

		diffSorted := cmp.Diff(sliceA, sliceB, cmpopts.SortSlices(func(x, y string) bool {
			return x < y
		}))
		if diffSorted != "" {
			t.Fatalf("expected empty diff with SortSlices option, got:\n%s", diffSorted)
		}
	})

	// 5. cmp.Diff produces readable diffs detailing map modifications additions and deletions
	t.Run("produces diff for map additions, modifications, and deletions", func(t *testing.T) {
		mapA := map[string]int{"k1": 10, "k2": 20}
		mapB := map[string]int{"k1": 10, "k2": 25, "k3": 30}

		diff := cmp.Diff(mapA, mapB)
		if diff == "" {
			t.Fatal("expected diff for modified map")
		}
		if !strings.Contains(diff, "k2") || !strings.Contains(diff, "k3") {
			t.Fatalf("expected diff to mention changed keys, got:\n%s", diff)
		}
	})
}

Origin Seeder

anonymous