CodeSampleX

Ejemplo

github.com/google/go-cmp v0.3.0: cmp.Option

Muestra verificada para golang github.com/google/go-cmp v0.3.0: cmp.Option. El contrato se ejecutó en go 1.26 · linux debian/x64 · docker y pasó.

sha256:4e16668081abcb26b302c6cd8c119706116a413e4200d7af3370be64c369dfdd

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado linux 24 · ubuntu · glibc 2.39 x64 go

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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-10-19

Caso

HOW
Objetivo
verify github.com/google/go-cmp/cmp.Option in pkg:golang/github.com/google/go-cmp@v0.3.0
Paquetes
Símbolos
  • github.com/google/go-cmp/cmp.Option
Creado
2026-10-19T07:08:39Z

Contrato

  1. cmp.Comparer returns a cmp.Option that customizes equality comparison
  2. cmp.Transformer returns a cmp.Option that transforms values prior to comparison
  3. cmp.Options satisfies cmp.Option and combines multiple Option values
  4. cmp.FilterPath with cmp.Ignore produces a cmp.Option that ignores matching paths
  5. cmp.AllowUnexported returns a cmp.Option permitting comparison of unexported struct fields

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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

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

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:ca4fac25e77cd36cc33edbe502e56bbe71e2d03c62d273079bd87581fa2d51b3","contract":["cmp.Comparer returns a cmp.Option that customizes equality comparison","cmp.Transformer returns a cmp.Option that transforms values prior to comparison","cmp.Options satisfies cmp.Option and combines multiple Option values","cmp.FilterPath with cmp.Ignore produces a cmp.Option that ignores matching paths","cmp.AllowUnexported returns a cmp.Option permitting comparison of unexported struct fields"],"goal":"verify github.com/google/go-cmp/cmp.Option in pkg:golang/github.com/google/go-cmp@v0.3.0","kind":"HOW","packages":["pkg:golang/github.com/google/go-cmp@v0.3.0"],"schemaVersion":1,"symbols":["github.com/google/go-cmp/cmp.Option"]},"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.3.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/google/go-cmp@v0.3.0","symbols":["github.com/google/go-cmp/cmp.Option"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.22

require github.com/google/go-cmp v0.3.0
go.sum
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
main.go
package main

import (
	"fmt"
	"math"
	"strings"

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

type Measurement struct {
	Tag   string
	Value float64
}

type internalBox struct {
	Code   int
	secret string
}

func main() {
	var normTag cmp.Option = cmp.Transformer("NormalizeTag", strings.ToLower)
	var approxVal cmp.Option = cmp.Comparer(func(x, y float64) bool {
		return math.Abs(x-y) < 1e-4
	})
	var combined cmp.Option = cmp.Options{normTag, approxVal}

	m1 := Measurement{Tag: "TEMP", Value: 25.00001}
	m2 := Measurement{Tag: "temp", Value: 25.00002}

	if cmp.Equal(m1, m2, combined) {
		fmt.Println("Measurements equal under composite cmp.Option")
	}

	b1 := internalBox{Code: 7, secret: "hidden"}
	b2 := internalBox{Code: 7, secret: "hidden"}
	var allowOpt cmp.Option = cmp.AllowUnexported(internalBox{})
	if cmp.Equal(b1, b2, allowOpt) {
		fmt.Println("Unexported struct fields equal under cmp.Option")
	}
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/google/go-cmp/cmp.Option in pkg:golang/github.com/google/go-cmp@v0.3.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/google/go-cmp@v0.3.0"
  ],
  "symbols": [
    "github.com/google/go-cmp/cmp.Option"
  ]
}
test/contract.go
package main

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

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

type Measurement struct {
	Tag   string
	Value float64
}

type EventRecord struct {
	ID       int
	Sequence int64
}

type privateEntry struct {
	ID   int
	note string
}

func main() {
	// 1. cmp.Comparer returns a cmp.Option that customizes equality comparison
	{
		type score int
		var opt cmp.Option = cmp.Comparer(func(a, b score) bool {
			return a/10 == b/10
		})
		if !cmp.Equal(score(42), score(49), opt) {
			fmt.Fprintln(os.Stderr, "comparer option failed to match scores in same bucket")
			os.Exit(1)
		}
		if cmp.Equal(score(42), score(52), opt) {
			fmt.Fprintln(os.Stderr, "comparer option matched scores in different buckets")
			os.Exit(1)
		}
	}

	// 2. cmp.Transformer returns a cmp.Option that transforms values prior to comparison
	{
		var opt cmp.Option = cmp.Transformer("TrimLower", func(s string) string {
			return strings.ToLower(strings.TrimSpace(s))
		})
		if !cmp.Equal("  Hello ", "hello", opt) {
			fmt.Fprintln(os.Stderr, "transformer option failed to match normalized strings")
			os.Exit(1)
		}
		if cmp.Equal("  Hello ", "world", opt) {
			fmt.Fprintln(os.Stderr, "transformer option matched distinct strings")
			os.Exit(1)
		}
	}

	// 3. cmp.Options satisfies cmp.Option and combines multiple Option values
	{
		var optTag cmp.Option = cmp.Transformer("Lower", strings.ToLower)
		var optVal cmp.Option = cmp.Comparer(func(a, b float64) bool {
			return math.Abs(a-b) < 1e-3
		})
		var composite cmp.Option = cmp.Options{optTag, optVal}

		a := Measurement{Tag: "SENSOR", Value: 1.0001}
		b := Measurement{Tag: "sensor", Value: 1.0002}
		c := Measurement{Tag: "sensor", Value: 2.0}

		if !cmp.Equal(a, b, composite) {
			fmt.Fprintln(os.Stderr, "composite option failed to match equivalent measurements")
			os.Exit(1)
		}
		if cmp.Equal(a, c, composite) {
			fmt.Fprintln(os.Stderr, "composite option matched distinct measurements")
			os.Exit(1)
		}
	}

	// 4. cmp.FilterPath with cmp.Ignore produces a cmp.Option that ignores matching paths
	{
		var ignoreSeq cmp.Option = cmp.FilterPath(func(p cmp.Path) bool {
			return p.Last().String() == ".Sequence"
		}, cmp.Ignore())

		e1 := EventRecord{ID: 10, Sequence: 1}
		e2 := EventRecord{ID: 10, Sequence: 99}
		e3 := EventRecord{ID: 20, Sequence: 1}

		if !cmp.Equal(e1, e2, ignoreSeq) {
			fmt.Fprintln(os.Stderr, "filterpath ignore option failed to ignore Sequence field")
			os.Exit(1)
		}
		if cmp.Equal(e1, e3, ignoreSeq) {
			fmt.Fprintln(os.Stderr, "filterpath ignore option matched records with different IDs")
			os.Exit(1)
		}
	}

	// 5. cmp.AllowUnexported returns a cmp.Option permitting comparison of unexported struct fields
	{
		p1 := privateEntry{ID: 1, note: "same"}
		p2 := privateEntry{ID: 1, note: "same"}
		p3 := privateEntry{ID: 1, note: "diff"}

		var allowOpt cmp.Option = cmp.AllowUnexported(privateEntry{})
		if !cmp.Equal(p1, p2, allowOpt) {
			fmt.Fprintln(os.Stderr, "allowunexported option failed to match identical unexported fields")
			os.Exit(1)
		}
		if cmp.Equal(p1, p3, allowOpt) {
			fmt.Fprintln(os.Stderr, "allowunexported option matched differing unexported fields")
			os.Exit(1)
		}
	}

	fmt.Println("contract ok")
}

Seeder de origen

anónimo