CodeSampleX

Exemple

github.com/google/uuid v1.3.0: NewRandom, New, Parse

Échantillon vérifié pour golang github.com/google/uuid v1.3.0: NewRandom, New, Parse. Le contrat s'est exécuté sur go 1.26 · linux alpine/x64 · docker et a…

sha256:8071c99b7a0050b654cbc698004c028a42bcca9d468a71ffca82d115cb815420

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
3
Clés de signature qui l’ont compilé
2
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 alpine/x64 · docker ed25519:2a6aa94bf40f1df0 SKIPPED compile:SKIPPED · contract:SKIPPED · load:SKIPPED · resolve:FAIL
CONTAINER_RUN · golang@1
2026-08-20
go 1.26 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1
2026-08-20
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-08

Cas

HOW
Objectif
verify pkg:golang/github.com/google/uuid@v1.3.0
Paquets
Symboles
  • NewRandom
  • New
  • Parse
  • NewSHA1
  • NewMD5
Créé
2026-08-20T00:25:20Z

Contrat

  1. uuid.NewRandom generates RFC 4122 compliant version 4 UUID with correct variant and version
  2. uuid.Parse parses standard string representations and validates UUID bytes
  3. uuid.NewSHA1 generates deterministic version 5 UUID from namespace and data
  4. uuid.NewMD5 generates deterministic version 3 UUID from namespace and data
  5. uuid.NewString produces valid formatted 36-character hyphenated UUID strings

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/uuid@v1.3.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/google/uuid@v1.3.0
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:6a064f3bcd0e110274c5e5ddac4f657d46d348bdd78338d5bf4cc6d414269161","contract":["uuid.NewRandom generates RFC 4122 compliant version 4 UUID with correct variant and version","uuid.Parse parses standard string representations and validates UUID bytes","uuid.NewSHA1 generates deterministic version 5 UUID from namespace and data","uuid.NewMD5 generates deterministic version 3 UUID from namespace and data","uuid.NewString produces valid formatted 36-character hyphenated UUID strings"],"goal":"verify pkg:golang/github.com/google/uuid@v1.3.0","kind":"HOW","packages":["pkg:golang/github.com/google/uuid@v1.3.0"],"schemaVersion":1,"symbols":["NewRandom","New","Parse","NewSHA1","NewMD5"]},"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/uuid@v1.3.0"],"schemaVersion":1,"symbols":["NewRandom","New","Parse","NewSHA1","NewMD5"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require github.com/google/uuid v1.3.0
go.sum
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
main.go
package main

import (
	"fmt"
	"os"

	"github.com/google/uuid"
)

// GenerateRandomUUID generates a random UUID (version 4).
func GenerateRandomUUID() (uuid.UUID, error) {
	return uuid.NewRandom()
}

// ParseUUID parses a UUID string into a UUID struct.
func ParseUUID(s string) (uuid.UUID, error) {
	return uuid.Parse(s)
}

// GenerateNamespaceUUIDv5 generates a SHA-1 namespace-based UUID (version 5).
func GenerateNamespaceUUIDv5(space uuid.UUID, data []byte) uuid.UUID {
	return uuid.NewSHA1(space, data)
}

// GenerateNamespaceUUIDv3 generates an MD5 namespace-based UUID (version 3).
func GenerateNamespaceUUIDv3(space uuid.UUID, data []byte) uuid.UUID {
	return uuid.NewMD5(space, data)
}

func main() {
	id, err := GenerateRandomUUID()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error generating UUIDv4: %v\n", err)
		os.Exit(1)
	}

	fmt.Printf("Generated UUIDv4: %s (version %d, variant %s)\n", id.String(), id.Version(), id.Variant())

	parsed, err := ParseUUID(id.String())
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error parsing UUID: %v\n", err)
		os.Exit(1)
	}
	fmt.Printf("Parsed UUID: %s\n", parsed.String())

	dnsNamespace := uuid.NameSpaceDNS
	v5ID := GenerateNamespaceUUIDv5(dnsNamespace, []byte("example.com"))
	fmt.Printf("Generated UUIDv5 (DNS, 'example.com'): %s (version %d)\n", v5ID.String(), v5ID.Version())

	v3ID := GenerateNamespaceUUIDv3(dnsNamespace, []byte("example.com"))
	fmt.Printf("Generated UUIDv3 (DNS, 'example.com'): %s (version %d)\n", v3ID.String(), v3ID.Version())
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/github.com/google/uuid@v1.3.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/google/uuid@v1.3.0"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.go
package main

import (
	"bytes"
	"fmt"
	"os"

	"github.com/google/uuid"
)

func main() {
	// Assertion 1: uuid.NewRandom generates RFC 4122 compliant version 4 UUID with correct variant and version
	{
		u, err := uuid.NewRandom()
		if err != nil {
			fmt.Fprintf(os.Stderr, "FAIL: uuid.NewRandom returned error: %v\n", err)
			os.Exit(1)
		}
		if u.Version() != 4 {
			fmt.Fprintf(os.Stderr, "FAIL: expected UUID version 4, got %d\n", u.Version())
			os.Exit(1)
		}
		if u.Variant() != uuid.RFC4122 {
			fmt.Fprintf(os.Stderr, "FAIL: expected RFC4122 variant, got %v\n", u.Variant())
			os.Exit(1)
		}
		if len(u) != 16 {
			fmt.Fprintf(os.Stderr, "FAIL: expected 16 bytes, got %d\n", len(u))
			os.Exit(1)
		}
	}

	// Assertion 2: uuid.Parse parses standard string representations and validates UUID bytes
	{
		validStr := "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
		parsed, err := uuid.Parse(validStr)
		if err != nil {
			fmt.Fprintf(os.Stderr, "FAIL: uuid.Parse failed on valid UUID string: %v\n", err)
			os.Exit(1)
		}
		if parsed.String() != validStr {
			fmt.Fprintf(os.Stderr, "FAIL: parsed.String() %q != %q\n", parsed.String(), validStr)
			os.Exit(1)
		}

		invalidStr := "invalid-uuid-string"
		if _, err := uuid.Parse(invalidStr); err == nil {
			fmt.Fprintf(os.Stderr, "FAIL: uuid.Parse should have failed on invalid string\n")
			os.Exit(1)
		}
	}

	// Assertion 3: uuid.NewSHA1 generates deterministic version 5 UUID from namespace and data
	{
		space := uuid.NameSpaceDNS
		data := []byte("example.com")
		u1 := uuid.NewSHA1(space, data)
		u2 := uuid.NewSHA1(space, data)
		if !bytes.Equal(u1[:], u2[:]) {
			fmt.Fprintf(os.Stderr, "FAIL: uuid.NewSHA1 is not deterministic\n")
			os.Exit(1)
		}
		if u1.Version() != 5 {
			fmt.Fprintf(os.Stderr, "FAIL: expected UUID version 5, got %d\n", u1.Version())
			os.Exit(1)
		}
		if u1.Variant() != uuid.RFC4122 {
			fmt.Fprintf(os.Stderr, "FAIL: expected RFC4122 variant, got %v\n", u1.Variant())
			os.Exit(1)
		}
	}

	// Assertion 4: uuid.NewMD5 generates deterministic version 3 UUID from namespace and data
	{
		space := uuid.NameSpaceDNS
		data := []byte("example.com")
		u1 := uuid.NewMD5(space, data)
		u2 := uuid.NewMD5(space, data)
		if !bytes.Equal(u1[:], u2[:]) {
			fmt.Fprintf(os.Stderr, "FAIL: uuid.NewMD5 is not deterministic\n")
			os.Exit(1)
		}
		if u1.Version() != 3 {
			fmt.Fprintf(os.Stderr, "FAIL: expected UUID version 3, got %d\n", u1.Version())
			os.Exit(1)
		}
		if u1.Variant() != uuid.RFC4122 {
			fmt.Fprintf(os.Stderr, "FAIL: expected RFC4122 variant, got %v\n", u1.Variant())
			os.Exit(1)
		}
	}

	// Assertion 5: uuid.NewString produces valid formatted 36-character hyphenated UUID strings
	{
		s := uuid.NewString()
		if len(s) != 36 {
			fmt.Fprintf(os.Stderr, "FAIL: expected 36 char UUID string, got %d\n", len(s))
			os.Exit(1)
		}
		u, err := uuid.Parse(s)
		if err != nil {
			fmt.Fprintf(os.Stderr, "FAIL: uuid.NewString produced unparseable UUID: %v\n", err)
			os.Exit(1)
		}
		if u.Version() != 4 {
			fmt.Fprintf(os.Stderr, "FAIL: expected UUID version 4 from NewString, got %d\n", u.Version())
			os.Exit(1)
		}
	}

	fmt.Println("PASS: pkg:golang/github.com/google/uuid@v1.3.0 contract verified")
}

Seeder d'origine

anonyme