CodeSampleX

サンプル

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

検証済みサンプル — golang github.com/google/go-cmp v0.6.0: cmp.Options. go 1.26 · linux debian/x64 · docker で contract を実行し、成功しました: cmp.Options satisfies cmp.Option…

sha256:1c2dbdf457fba72c8d0b8366f50d41500a8eaa1b9ae447199975811aedd9c153

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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.Options in pkg:golang/github.com/google/go-cmp@v0.6.0
パッケージ
シンボル
  • github.com/google/go-cmp/cmp.Options
作成日
2026-09-15T23:18:28Z

コントラクト

  1. cmp.Options satisfies cmp.Option and combines multiple options into a single option
  2. cmp.Options applies each grouped option during comparison
  3. cmp.Options can be nested to combine option groups hierarchically
  4. empty cmp.Options functions as a no-op option preserving standard comparison

ファイル

  • 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 github.com/google/go-cmp/cmp.Options 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.Options

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:16ab0fc0a8ac878e42a243fff1824594adab05df7f022f5a716d73bf867578e5","contract":["cmp.Options satisfies cmp.Option and combines multiple options into a single option","cmp.Options applies each grouped option during comparison","cmp.Options can be nested to combine option groups hierarchically","empty cmp.Options functions as a no-op option preserving standard comparison"],"goal":"verify github.com/google/go-cmp/cmp.Options 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.Options"]},"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.Options"],"verifierAdapter":"golang@1"}
go.mod
module sample

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

import (
	"fmt"
	"math"
	"strings"

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

type Config struct {
	Name  string
	Scale float64
	Debug bool
}

func main() {
	// cmp.Options groups multiple comparison options into a reusable composite option.
	opts := cmp.Options{
		cmp.Transformer("CanonicalName", strings.ToLower),
		cmp.Comparer(func(x, y float64) bool {
			return math.Abs(x-y) < 1e-4
		}),
	}

	cfg1 := Config{Name: "Production", Scale: 1.00002, Debug: true}
	cfg2 := Config{Name: "production", Scale: 1.00001, Debug: true}

	if cmp.Equal(cfg1, cfg2, opts) {
		fmt.Println("Configurations match under cmp.Options bundle.")
	} else {
		fmt.Println("Configurations differ.")
	}
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/google/go-cmp/cmp.Options 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.Options"
  ]
}
test/contract.go
package main

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

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

type Measurement struct {
	Tag   string
	Value float64
	Note  string
}

func main() {
	// Assertion 1: cmp.Options satisfies cmp.Option and combines multiple options into a single option
	{
		optTag := cmp.Transformer("NormalizeTag", strings.ToUpper)
		optVal := cmp.Comparer(func(a, b float64) bool {
			return math.Abs(a-b) < 1e-3
		})

		var group cmp.Option = cmp.Options{optTag, optVal}
		if group == nil {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: cmp.Options should satisfy cmp.Option\n")
			os.Exit(1)
		}

		m1 := Measurement{Tag: "temp", Value: 20.0001, Note: "exact"}
		m2 := Measurement{Tag: "TEMP", Value: 20.0004, Note: "exact"}
		if !cmp.Equal(m1, m2, group) {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: grouped options should match m1 and m2\n")
			os.Exit(1)
		}
	}

	// Assertion 2: cmp.Options applies each grouped option during comparison
	{
		ignoreNote := cmp.FilterPath(func(p cmp.Path) bool {
			return p.Last().String() == ".Note"
		}, cmp.Ignore())

		normTag := cmp.Transformer("TrimTag", strings.TrimSpace)

		opts := cmp.Options{ignoreNote, normTag}

		m1 := Measurement{Tag: " pressure ", Value: 101.3, Note: "sensor A"}
		m2 := Measurement{Tag: "pressure", Value: 101.3, Note: "sensor B"}
		m3 := Measurement{Tag: "volume", Value: 101.3, Note: "sensor A"}

		if !cmp.Equal(m1, m2, opts) {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: opts should ignore Note and trim Tag\n")
			os.Exit(1)
		}
		if cmp.Equal(m1, m3, opts) {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: opts should not equate different tags\n")
			os.Exit(1)
		}
	}

	// Assertion 3: cmp.Options can be nested to combine option groups hierarchically
	{
		group1 := cmp.Options{
			cmp.Transformer("NormalizeTag", strings.ToLower),
		}
		group2 := cmp.Options{
			cmp.Comparer(func(a, b float64) bool {
				return math.Abs(a-b) < 0.05
			}),
		}
		nested := cmp.Options{group1, group2}

		m1 := Measurement{Tag: "HUMIDITY", Value: 55.02, Note: "raw"}
		m2 := Measurement{Tag: "humidity", Value: 55.04, Note: "raw"}

		if !cmp.Equal(m1, m2, nested) {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: nested cmp.Options should apply all child options\n")
			os.Exit(1)
		}
	}

	// Assertion 4: empty cmp.Options functions as a no-op option preserving standard comparison
	{
		emptyOpts := cmp.Options{}

		m1 := Measurement{Tag: "v1", Value: 10.0, Note: "ok"}
		m2 := Measurement{Tag: "v1", Value: 10.0, Note: "ok"}
		m3 := Measurement{Tag: "v1", Value: 10.5, Note: "ok"}

		if !cmp.Equal(m1, m2, emptyOpts) {
			fmt.Fprintf(os.Stderr, "assertion 4 failed: empty cmp.Options should match identical values\n")
			os.Exit(1)
		}
		if cmp.Equal(m1, m3, emptyOpts) {
			fmt.Fprintf(os.Stderr, "assertion 4 failed: empty cmp.Options should not match different values\n")
			os.Exit(1)
		}
	}

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

オリジンシーダー

匿名