CodeSampleX

샘플

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

검증된 샘플 — golang github.com/google/go-cmp v0.6.0. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: assert cmp.Equal returns true when comparing…

sha256:e04c363e45ee265834a86a4cd2db305937ce88a0728272c287466718e7bc9209

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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-13

케이스

HOW
목표
verify pkg:golang/github.com/google/go-cmp@v0.6.0
패키지
생성일
2026-09-13T21:01:40Z

컨트랙트

  1. assert cmp.Equal returns true when comparing identical basic types and struct values
  2. assert cmp.Diff returns empty string for equal values and non-empty diff string describing field differences
  3. assert cmp.Diff panics on unexported fields by default unless cmp.AllowUnexported is provided
  4. assert cmpopts.IgnoreFields excludes specified struct fields from comparison
  5. assert cmp.Comparer customizes equality evaluation between types

파일

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

소스 아티팩트 내려받기 (tar.gz)

소스

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.6.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/google/go-cmp@v0.6.0

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:fe1c52d4051d8322eb291792f2449e793995aef8a503e6a3a4956d2eaa317b59","contract":["assert cmp.Equal returns true when comparing identical basic types and struct values","assert cmp.Diff returns empty string for equal values and non-empty diff string describing field differences","assert cmp.Diff panics on unexported fields by default unless cmp.AllowUnexported is provided","assert cmpopts.IgnoreFields excludes specified struct fields from comparison","assert cmp.Comparer customizes equality evaluation between types"],"goal":"verify 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},"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","verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

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=
main.go
package main

import (
	"fmt"

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

// User represents a user record with both public and private fields.
type User struct {
	ID    int
	Name  string
	Role  string
	token string
}

func main() {
	u1 := User{ID: 1, Name: "Alice", Role: "Admin", token: "secret-token-1"}
	u2 := User{ID: 1, Name: "Alice", Role: "Admin", token: "secret-token-2"}

	// Compare with AllowUnexported and IgnoreFields
	diff := cmp.Diff(u1, u2, cmp.AllowUnexported(User{}), cmpopts.IgnoreFields(User{}, "token"))
	if diff == "" {
		fmt.Println("Users match when ignoring token field")
	} else {
		fmt.Printf("Users differ:\n%s\n", diff)
	}

	u3 := User{ID: 2, Name: "Bob", Role: "Member", token: "secret-token-1"}
	diff2 := cmp.Diff(u1, u3, cmp.AllowUnexported(User{}))
	fmt.Printf("Difference between Alice and Bob:\n%s\n", diff2)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/github.com/google/go-cmp@v0.6.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/google/go-cmp@v0.6.0"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"
	"strings"

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

type Item struct {
	ID        int
	Title     string
	Timestamp int64
}

type Record struct {
	ID     int
	secret string
}

func main() {
	// Assertion 1: cmp.Equal returns true when comparing identical basic types and struct values
	{
		i1 := Item{ID: 10, Title: "first", Timestamp: 100}
		i2 := Item{ID: 10, Title: "first", Timestamp: 100}
		if !cmp.Equal(i1, i2) {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: identical items should be equal\n")
			os.Exit(1)
		}
		if !cmp.Equal([]string{"a", "b"}, []string{"a", "b"}) {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: identical slices should be equal\n")
			os.Exit(1)
		}
	}

	// Assertion 2: cmp.Diff returns empty string for equal values and non-empty diff string describing field differences
	{
		i1 := Item{ID: 10, Title: "alpha", Timestamp: 100}
		i2 := Item{ID: 10, Title: "beta", Timestamp: 100}
		diff := cmp.Diff(i1, i2)
		if diff == "" || !strings.Contains(diff, "alpha") || !strings.Contains(diff, "beta") {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: diff should describe field mismatch, got %q\n", diff)
			os.Exit(1)
		}

		sameDiff := cmp.Diff(i1, i1)
		if sameDiff != "" {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: equal values must produce empty diff\n")
			os.Exit(1)
		}
	}

	// Assertion 3: cmp.Diff panics on unexported fields by default unless cmp.AllowUnexported is provided
	{
		r1 := Record{ID: 1, secret: "a"}
		r2 := Record{ID: 1, secret: "b"}

		panicked := false
		func() {
			defer func() {
				if r := recover(); r != nil {
					panicked = true
				}
			}()
			_ = cmp.Diff(r1, r2)
		}()

		if !panicked {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: cmp.Diff must panic on unexported fields without AllowUnexported\n")
			os.Exit(1)
		}

		diffAllowed := cmp.Diff(r1, r2, cmp.AllowUnexported(Record{}))
		if diffAllowed == "" || !strings.Contains(diffAllowed, "secret") {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: cmp.Diff with AllowUnexported should report secret difference, got %q\n", diffAllowed)
			os.Exit(1)
		}
	}

	// Assertion 4: cmpopts.IgnoreFields excludes specified struct fields from comparison
	{
		i1 := Item{ID: 100, Title: "sample", Timestamp: 1000}
		i2 := Item{ID: 100, Title: "sample", Timestamp: 9999}

		// Without ignore, they are different
		if cmp.Equal(i1, i2) {
			fmt.Fprintf(os.Stderr, "assertion 4 failed: timestamps differ, should not be equal without IgnoreFields\n")
			os.Exit(1)
		}

		// With ignore, they evaluate as equal
		if !cmp.Equal(i1, i2, cmpopts.IgnoreFields(Item{}, "Timestamp")) {
			fmt.Fprintf(os.Stderr, "assertion 4 failed: IgnoreFields should cause items to evaluate equal\n")
			os.Exit(1)
		}
	}

	// Assertion 5: cmp.Comparer customizes equality evaluation between types
	{
		type ApproxFloat float64
		approxEqual := cmp.Comparer(func(x, y ApproxFloat) bool {
			diff := float64(x - y)
			if diff < 0 {
				diff = -diff
			}
			return diff < 0.01
		})

		v1 := ApproxFloat(1.000)
		v2 := ApproxFloat(1.005)
		v3 := ApproxFloat(1.050)

		if !cmp.Equal(v1, v2, approxEqual) {
			fmt.Fprintf(os.Stderr, "assertion 5 failed: approxEqual should consider 1.000 and 1.005 equal\n")
			os.Exit(1)
		}
		if cmp.Equal(v1, v3, approxEqual) {
			fmt.Fprintf(os.Stderr, "assertion 5 failed: approxEqual should consider 1.000 and 1.050 unequal\n")
			os.Exit(1)
		}
	}

	fmt.Println("All contract assertions passed successfully.")
}

오리진 시더

익명