示例
github.com/google/go-cmp v0.6.0: cmp.Option
已验证示例 — golang github.com/google/go-cmp v0.6.0: cmp.Option. contract 在 go 1.26 · linux debian/x64 · docker 上运行并通过: cmp.Options composite slice satisfies…
sha256:e251407002e57aae04a73d6f944d710efafd7a02d29bfc46750cdfe5fba050a5
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
linux 24 · ubuntu · glibc 2.39 x64 go
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| 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 |
案例
HOW- 目标
- verify github.com/google/go-cmp/cmp.Option in pkg:golang/github.com/google/go-cmp@v0.6.0
- 符号
-
- github.com/google/go-cmp/cmp.Option
- 创建时间
- 2026-09-15T07:26:30Z
契约
- cmp.Options composite slice satisfies cmp.Option and applies all contained options
- cmp.Comparer returns a cmp.Option configuring custom equality logic
- cmp.Transformer returns a cmp.Option transforming values before equality comparison
- cmp.Ignore combined with cmp.FilterPath returns a cmp.Option ignoring specified struct fields
- cmp.AllowUnexported returns a cmp.Option allowing comparison of structs with unexported fields
文件
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
源代码
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.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.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.
{"case":{"caseId":"case:sha256:3e3defc6caa2119936059c1343f7db850899552962db0f0ef46c99fb845cdd42","contract":["cmp.Options composite slice satisfies cmp.Option and applies all contained options","cmp.Comparer returns a cmp.Option configuring custom equality logic","cmp.Transformer returns a cmp.Option transforming values before equality comparison","cmp.Ignore combined with cmp.FilterPath returns a cmp.Option ignoring specified struct fields","cmp.AllowUnexported returns a cmp.Option allowing comparison of structs with unexported fields"],"goal":"verify github.com/google/go-cmp/cmp.Option 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.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.6.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/google/go-cmp@v0.6.0","symbols":["github.com/google/go-cmp/cmp.Option"],"verifierAdapter":"golang@1"}
module sample
go 1.22.0
require github.com/google/go-cmp v0.6.0
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
package main
import (
"fmt"
"math"
"strings"
"github.com/google/go-cmp/cmp"
)
type Coordinate struct {
Label string
X float64
Y float64
}
type record struct {
ID int
token string
}
func main() {
// Example 1: cmp.Transformer to normalize strings during comparison
caseInsensitive := cmp.Transformer("ToLower", strings.ToLower)
// Example 2: cmp.Comparer for approximate floating point comparison
approxCoord := cmp.Comparer(func(a, b float64) bool {
return math.Abs(a-b) < 1e-4
})
// Example 3: cmp.Options combines multiple cmp.Option values into a composite Option
opts := cmp.Options{
caseInsensitive,
approxCoord,
}
c1 := Coordinate{Label: "ORIGIN", X: 0.00001, Y: 0.0}
c2 := Coordinate{Label: "origin", X: 0.0, Y: 0.00001}
if cmp.Equal(c1, c2, opts) {
fmt.Println("Coordinates match using cmp.Options composite.")
}
// Example 4: cmp.AllowUnexported allows comparing unexported fields
r1 := record{ID: 1, token: "active"}
r2 := record{ID: 1, token: "active"}
allowOpt := cmp.AllowUnexported(record{})
if cmp.Equal(r1, r2, allowOpt) {
fmt.Println("Records with unexported fields matched successfully.")
}
}
{
"schemaVersion": 1,
"goal": "verify github.com/google/go-cmp/cmp.Option 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.Option"
]
}
package main
import (
"fmt"
"math"
"os"
"strings"
"github.com/google/go-cmp/cmp"
)
type Coordinate struct {
Label string
X float64
Y float64
}
type Payload struct {
ID int
Timestamp int64
}
type secretRecord struct {
ID int
token string
}
func main() {
// Assertion 1: cmp.Options composite slice satisfies cmp.Option and applies all contained options
{
var opt1 cmp.Option = cmp.Transformer("ToLower", strings.ToLower)
var opt2 cmp.Option = cmp.Comparer(func(a, b float64) bool {
return math.Abs(a-b) < 1e-3
})
var composite cmp.Option = cmp.Options{opt1, opt2}
c1 := Coordinate{Label: "Alpha", X: 10.0001, Y: 20.0}
c2 := Coordinate{Label: "ALPHA", X: 10.0002, Y: 20.0}
c3 := Coordinate{Label: "BETA", X: 10.0001, Y: 20.0}
if !cmp.Equal(c1, c2, composite) {
fmt.Fprintf(os.Stderr, "assertion 1 failed: composite cmp.Options should match c1 and c2\n")
os.Exit(1)
}
if cmp.Equal(c1, c3, composite) {
fmt.Fprintf(os.Stderr, "assertion 1 failed: composite cmp.Options should differentiate c1 and c3\n")
os.Exit(1)
}
}
// Assertion 2: cmp.Comparer returns a cmp.Option configuring custom equality logic
{
type customNum int
modCompare := cmp.Comparer(func(x, y customNum) bool {
return x%10 == y%10
})
var opt cmp.Option = modCompare
if !cmp.Equal(customNum(13), customNum(23), opt) {
fmt.Fprintf(os.Stderr, "assertion 2 failed: 13 and 23 should be equal mod 10\n")
os.Exit(1)
}
if cmp.Equal(customNum(13), customNum(25), opt) {
fmt.Fprintf(os.Stderr, "assertion 2 failed: 13 and 25 should not be equal mod 10\n")
os.Exit(1)
}
}
// Assertion 3: cmp.Transformer returns a cmp.Option transforming values before equality comparison
{
trimAndLower := cmp.Transformer("TrimAndLower", func(s string) string {
return strings.ToLower(strings.TrimSpace(s))
})
var opt cmp.Option = trimAndLower
s1 := " GoLang "
s2 := "golang"
s3 := "rust"
if !cmp.Equal(s1, s2, opt) {
fmt.Fprintf(os.Stderr, "assertion 3 failed: trimmed lower string should match\n")
os.Exit(1)
}
if cmp.Equal(s1, s3, opt) {
fmt.Fprintf(os.Stderr, "assertion 3 failed: distinct strings should not match\n")
os.Exit(1)
}
}
// Assertion 4: cmp.Ignore combined with cmp.FilterPath returns a cmp.Option ignoring specified struct fields
{
ignoreTime := cmp.FilterPath(func(p cmp.Path) bool {
return p.Last().String() == ".Timestamp"
}, cmp.Ignore())
var opt cmp.Option = ignoreTime
p1 := Payload{ID: 101, Timestamp: 1000}
p2 := Payload{ID: 101, Timestamp: 9999}
p3 := Payload{ID: 202, Timestamp: 1000}
if !cmp.Equal(p1, p2, opt) {
fmt.Fprintf(os.Stderr, "assertion 4 failed: payload with different timestamp should match when ignored\n")
os.Exit(1)
}
if cmp.Equal(p1, p3, opt) {
fmt.Fprintf(os.Stderr, "assertion 4 failed: payload with different ID should not match\n")
os.Exit(1)
}
}
// Assertion 5: cmp.AllowUnexported returns a cmp.Option allowing comparison of structs with unexported fields
{
r1 := secretRecord{ID: 1, token: "alpha"}
r2 := secretRecord{ID: 1, token: "alpha"}
r3 := secretRecord{ID: 1, token: "beta"}
var panicked bool
func() {
defer func() {
if r := recover(); r != nil {
panicked = true
}
}()
_ = cmp.Equal(r1, r2)
}()
if !panicked {
fmt.Fprintf(os.Stderr, "assertion 5 failed: expected panic when comparing unexported fields without AllowUnexported\n")
os.Exit(1)
}
var opt cmp.Option = cmp.AllowUnexported(secretRecord{})
if !cmp.Equal(r1, r2, opt) {
fmt.Fprintf(os.Stderr, "assertion 5 failed: records should match with AllowUnexported\n")
os.Exit(1)
}
if cmp.Equal(r1, r3, opt) {
fmt.Fprintf(os.Stderr, "assertion 5 failed: different records should not match with AllowUnexported\n")
os.Exit(1)
}
}
fmt.Println("All contract assertions passed successfully.")
}
原始种子者
匿名