CodeSampleX

Exemplo

github.com/google/uuid v1.6.0: Generate and parse version 4 UUIDs using google uuid

Amostra verificada para golang github.com/google/uuid v1.6.0: Generate and parse version 4 UUIDs using google uuid. O contrato rodou em go 1.26 · linux…

sha256:cf7dcb376c795cca72c0d54bd76effc0f620134d07e7b0dc6f45673ef9e2eb5a

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
2
Chaves de assinatura que o compilaram
2
Ambiente declarado windows 11 x64 go

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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

Caso

HOW
Objetivo
Generate and parse version 4 UUIDs using google uuid
Pacotes
Símbolos
  • uuid.NewRandom
  • uuid.Parse
Criado
2026-08-18T23:42:35Z

Contrato

  1. uuid.NewRandom returns a random RFC 4122 Version 4 UUID without error
  2. uuid.Parse successfully parses a valid UUID string and matches the original
  3. uuid.Parse returns an error when given an invalid UUID string

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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 version 4 UUIDs 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:
  - uuid.NewRandom
  - uuid.Parse
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@11.8.0
  - runtime: node@24.13.1

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:fb5780a1f7dc998c5325dade73f40345be11b6a6cca06382df6fd49523c537e6","contract":["uuid.NewRandom returns a random RFC 4122 Version 4 UUID without error","uuid.Parse successfully parses a valid UUID string and matches the original","uuid.Parse returns an error when given an invalid UUID string"],"goal":"Generate and parse version 4 UUIDs using google uuid","kind":"HOW","packages":["pkg:golang/github.com/google/uuid@v1.6.0"],"schemaVersion":1,"symbols":["uuid.NewRandom","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":["uuid.NewRandom","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=
main.go
package main

import (
	"fmt"
	"log"

	"github.com/google/uuid"
)

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

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

func main() {
	id, err := GenerateRandomUUID()
	if err != nil {
		log.Fatalf("failed to generate random UUID: %v", err)
	}
	fmt.Printf("Generated UUID: %s (Version: %d, Variant: %d)\n", id.String(), id.Version(), id.Variant())

	parsed, err := ParseUUIDString(id.String())
	if err != nil {
		log.Fatalf("failed to parse UUID: %v", err)
	}
	fmt.Printf("Parsed UUID: %s (Matches: %t)\n", parsed.String(), parsed == id)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "Generate and parse version 4 UUIDs using google uuid",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/google/uuid@v1.6.0"
  ],
  "symbols": [
    "uuid.NewRandom",
    "uuid.Parse"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@11.8.0",
    "runtime": "node@24.13.1"
  }
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"github.com/google/uuid"
)

func main() {
	// Assertion 1: uuid.NewRandom returns a random RFC 4122 Version 4 UUID without error
	id, err := uuid.NewRandom()
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: uuid.NewRandom returned unexpected error: %v\n", err)
		os.Exit(1)
	}
	if id == uuid.Nil {
		fmt.Fprintf(os.Stderr, "FAIL: uuid.NewRandom returned Nil UUID\n")
		os.Exit(1)
	}
	if id.Version() != 4 {
		fmt.Fprintf(os.Stderr, "FAIL: expected UUID Version 4, got %v\n", id.Version())
		os.Exit(1)
	}
	if id.Variant() != uuid.RFC4122 {
		fmt.Fprintf(os.Stderr, "FAIL: expected RFC4122 variant, got %v\n", id.Variant())
		os.Exit(1)
	}

	// Assertion 2: uuid.Parse successfully parses a valid UUID string and matches the original
	idStr := id.String()
	parsed, err := uuid.Parse(idStr)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: uuid.Parse failed on valid string %q: %v\n", idStr, err)
		os.Exit(1)
	}
	if parsed != id {
		fmt.Fprintf(os.Stderr, "FAIL: parsed UUID %v != original %v\n", parsed, id)
		os.Exit(1)
	}
	if parsed.Version() != 4 {
		fmt.Fprintf(os.Stderr, "FAIL: expected parsed version 4, got %v\n", parsed.Version())
		os.Exit(1)
	}

	// Assertion 3: uuid.Parse returns an error when given an invalid UUID string
	invalidInputs := []string{
		"",
		"not-a-valid-uuid",
		"12345678-1234-1234-1234",
		"zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz",
	}
	for _, inv := range invalidInputs {
		if _, err := uuid.Parse(inv); err == nil {
			fmt.Fprintf(os.Stderr, "FAIL: expected uuid.Parse to fail on invalid input %q, got nil error\n", inv)
			os.Exit(1)
		}
	}

	fmt.Println("PASS: all contract assertions passed for uuid.NewRandom and uuid.Parse")
}

Seeder de origem

anônimo