CodeSampleX

Exemple

github.com/google/uuid v1.6.0: generate and parse UUID v4 using google uuid

Échantillon vérifié pour golang github.com/google/uuid v1.6.0: generate and parse UUID v4 using google uuid. Le contrat s'est exécuté sur go 1.26 · linux…

sha256:e8dbd063bf27ad16bbeaaef62313041501d6c7442f75262f8e51cd2b4a58dae4

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
2
Clés de signature qui l’ont compilé
2
Environnement déclaré windows 11 x64 go

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
go 1.26 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1
2026-08-19
go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f…
2026-09-07

Cas

HOW
Objectif
generate and parse UUID v4 using google uuid
Paquets
Symboles
  • github.com/google/uuid.NewRandom
  • github.com/google/uuid.Parse
Créé
2026-08-19T04:23:04Z

Contrat

  1. uuid.NewRandom generates a random version 4 UUID with RFC4122 variant and nil error
  2. uuid.Parse parses a valid UUID string representation back to the matching UUID value
  3. uuid.Parse returns a non-nil error when given an invalid UUID string

Fichiers

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • sample.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: generate and parse UUID v4 using google uuid
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/google/uuid@v1.6.0
Demonstrate these symbols/APIs:
  - github.com/google/uuid.NewRandom
  - github.com/google/uuid.Parse

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:10b002aa9a61d0f74b260f093b3831c8bd7cd6b3ce8f8f9966ba77a4bdc6af09","contract":["uuid.NewRandom generates a random version 4 UUID with RFC4122 variant and nil error","uuid.Parse parses a valid UUID string representation back to the matching UUID value","uuid.Parse returns a non-nil error when given an invalid UUID string"],"goal":"generate and parse UUID v4 using google uuid","kind":"HOW","packages":["pkg:golang/github.com/google/uuid@v1.6.0"],"schemaVersion":1,"symbols":["github.com/google/uuid.NewRandom","github.com/google/uuid.Parse"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","ecosystem":"golang","os":"windows","osVersionBucket":"11","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/google/uuid@v1.6.0"],"schemaVersion":1,"symbols":["github.com/google/uuid.NewRandom","github.com/google/uuid.Parse"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.22.0

require github.com/google/uuid v1.6.0
go.sum
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
sample.go
package sample

import (
	"fmt"

	"github.com/google/uuid"
)

// GenerateRandomUUID creates a new random (v4) UUID.
func GenerateRandomUUID() (uuid.UUID, error) {
	u, err := uuid.NewRandom()
	if err != nil {
		return uuid.Nil, fmt.Errorf("generate random uuid: %w", err)
	}
	return u, nil
}

// ParseUUID parses a standard 36-character string representation of a UUID.
func ParseUUID(s string) (uuid.UUID, error) {
	u, err := uuid.Parse(s)
	if err != nil {
		return uuid.Nil, fmt.Errorf("parse uuid: %w", err)
	}
	return u, nil
}
spec.json
{
  "schemaVersion": 1,
  "goal": "generate and parse UUID v4 using google uuid",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/google/uuid@v1.6.0"
  ],
  "symbols": [
    "github.com/google/uuid.NewRandom",
    "github.com/google/uuid.Parse"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"github.com/google/uuid"
	"sample"
)

func main() {
	// 1. Assert uuid.NewRandom generates a valid UUID v4
	u, err := uuid.NewRandom()
	if err != nil {
		fmt.Fprintf(os.Stderr, "uuid.NewRandom failed: %v\n", err)
		os.Exit(1)
	}
	if u.Version() != 4 {
		fmt.Fprintf(os.Stderr, "expected UUID version 4, got %d\n", u.Version())
		os.Exit(1)
	}
	if u.Variant() != uuid.RFC4122 {
		fmt.Fprintf(os.Stderr, "expected RFC4122 variant, got %v\n", u.Variant())
		os.Exit(1)
	}

	// 2. Assert uuid.Parse parses valid string representation
	str := u.String()
	parsed, err := uuid.Parse(str)
	if err != nil {
		fmt.Fprintf(os.Stderr, "uuid.Parse failed: %v\n", err)
		os.Exit(1)
	}
	if parsed != u {
		fmt.Fprintf(os.Stderr, "parsed UUID (%v) does not match original (%v)\n", parsed, u)
		os.Exit(1)
	}

	// 3. Assert uuid.Parse rejects invalid string
	if _, err := uuid.Parse("not-a-valid-uuid-string"); err == nil {
		fmt.Fprintf(os.Stderr, "expected error parsing invalid uuid string, got nil\n")
		os.Exit(1)
	}

	// 4. Assert helper functions in sample package
	wrapped, err := sample.GenerateRandomUUID()
	if err != nil {
		fmt.Fprintf(os.Stderr, "sample.GenerateRandomUUID failed: %v\n", err)
		os.Exit(1)
	}
	wrappedStr := wrapped.String()
	parsedWrapped, err := sample.ParseUUID(wrappedStr)
	if err != nil {
		fmt.Fprintf(os.Stderr, "sample.ParseUUID failed: %v\n", err)
		os.Exit(1)
	}
	if parsedWrapped != wrapped {
		fmt.Fprintf(os.Stderr, "sample.ParseUUID mismatch: got %v, want %v\n", parsedWrapped, wrapped)
		os.Exit(1)
	}

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

Seeder d'origine

anonyme