Пример
github.com/google/go-cmp v0.6.0: cmp.Diff
Проверенный пример — golang github.com/google/go-cmp v0.6.0: cmp.Diff. Контракт выполнен на go 1.26 · linux debian/x64 · docker и пройден.
sha256:c7206547134e6d3d74cae03ea3cd19b46673c3588c5153c0019c7150cdd6b2dd
Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла.
Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди.
MIT-0
Свидетельства выполнения
Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.
- Основа свидетельства
- Подписанный контракт пройден
- Квитанции проверки
- 1
- Ключи подписи, собравшие его
- 1
Заявленная среда
go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go 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.Diff in pkg:golang/github.com/google/go-cmp@v0.6.0
- Символы
-
- github.com/google/go-cmp/cmp.Diff
- Окружение
- go 1.26
- Создан
- 2026-09-15T02:27:18Z
Контракт
- 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
Файлы
- PROMPT.md
- csx.json
- diff.go
- go.mod
- go.sum
- spec.json
- test/contract_test.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.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.
{"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"}
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...)
}
module example.com/go-cmp-diff
go 1.24.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=
{
"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"
]
}
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)
}
})
}
Исходный сидер
аноним