CodeSampleX

Exemple

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

Échantillon vérifié pour golang github.com/google/go-cmp v0.6.0. Le contrat s'est exécuté sur go 1.26 · linux debian/x64 · docker et a réussi.

sha256:e04c363e45ee265834a86a4cd2db305937ce88a0728272c287466718e7bc9209

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 go

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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

Cas

HOW
Objectif
verify pkg:golang/github.com/google/go-cmp@v0.6.0
Paquets
Créé
2026-09-13T21:01:40Z

Contrat

  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

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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.")
}

Seeder d'origine

anonyme