Exemple
github.com/google/uuid v1.6.0: Serialize and deserialize UUIDs via binary and text interfaces and implement database/sql driver Valuer and Scanner in google/uuid
Échantillon vérifié pour golang github.com/google/uuid v1.6.0: Serialize and deserialize UUIDs via binary and text interfaces and implement database/sql…
sha256:01559efd6f5d6619f403e032e1754ae489f0d8596359844c49f473b6d6189530
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é
linux 24 · ubuntu · glibc 2.39 x64 go wsl
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 debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a… |
2026-09-07 |
Cas
HOW- Objectif
- Serialize and deserialize UUIDs via binary and text interfaces and implement database/sql driver Valuer and Scanner in google/uuid
- Paquets
- Symboles
-
- MarshalBinary
- MarshalText
- Scan
- UnmarshalBinary
- UnmarshalText
- Value
- Créé
- 2026-08-19T01:26:28Z
Contrat
- assert MarshalBinary serializes a UUID to 16 raw bytes and UnmarshalBinary restores the exact UUID or rejects invalid byte slice lengths
- assert MarshalText encodes a UUID into 36-byte lowercase hex string and UnmarshalText parses formatted byte slices or returns error on malformed input
- assert Value returns string representation conforming to database/sql driver.Valuer interface
- assert Scan implements database/sql sql.Scanner supporting string, 16-byte raw slice, 36-byte formatted slice, and nil inputs while rejecting unsupported types
Fichiers
- PROMPT.md
- csx.json
- go.mod
- go.sum
- spec.json
- test/contract.go
Code source
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: Serialize and deserialize UUIDs via binary and text interfaces and implement database/sql driver Valuer and Scanner in google/uuid
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/google/uuid@v1.6.0
Demonstrate these symbols/APIs:
- MarshalBinary
- MarshalText
- Scan
- UnmarshalBinary
- UnmarshalText
- Value
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.
{"case":{"caseId":"case:sha256:17d1e48ad41d87a3e491d666c2be2a0cb65947bad4757c835c70e8c1f784c33e","contract":["assert MarshalBinary serializes a UUID to 16 raw bytes and UnmarshalBinary restores the exact UUID or rejects invalid byte slice lengths","assert MarshalText encodes a UUID into 36-byte lowercase hex string and UnmarshalText parses formatted byte slices or returns error on malformed input","assert Value returns string representation conforming to database/sql driver.Valuer interface","assert Scan implements database/sql sql.Scanner supporting string, 16-byte raw slice, 36-byte formatted slice, and nil inputs while rejecting unsupported types"],"goal":"Serialize and deserialize UUIDs via binary and text interfaces and implement database/sql driver Valuer and Scanner in google/uuid","kind":"HOW","packages":["pkg:golang/github.com/google/uuid@v1.6.0"],"schemaVersion":1,"symbols":["MarshalBinary","MarshalText","Scan","UnmarshalBinary","UnmarshalText","Value"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1,"virtualization":"wsl"},"license":"MIT-0","packages":["pkg:golang/github.com/google/uuid@v1.6.0"],"schemaVersion":1,"symbols":["MarshalBinary","MarshalText","Scan","UnmarshalBinary","UnmarshalText","Value"],"verifierAdapter":"golang@1"}
module sample
go 1.25.13
require github.com/google/uuid v1.6.0
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=
{
"schemaVersion": 1,
"goal": "Serialize and deserialize UUIDs via binary and text interfaces and implement database/sql driver Valuer and Scanner in google/uuid",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/google/uuid@v1.6.0"
],
"symbols": [
"MarshalBinary",
"MarshalText",
"Scan",
"UnmarshalBinary",
"UnmarshalText",
"Value"
]
}
package main
import (
"database/sql/driver"
"fmt"
"github.com/google/uuid"
)
func main() {
// 1. assert MarshalBinary serializes a UUID to 16 raw bytes and UnmarshalBinary restores the exact UUID or rejects invalid byte slice lengths
original := uuid.MustParse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
binData, err := original.MarshalBinary()
if err != nil {
panic(fmt.Sprintf("MarshalBinary failed: %v", err))
}
if len(binData) != 16 {
panic(fmt.Sprintf("expected 16 bytes from MarshalBinary, got %d", len(binData)))
}
var restoredFromBin uuid.UUID
if err := restoredFromBin.UnmarshalBinary(binData); err != nil {
panic(fmt.Sprintf("UnmarshalBinary failed: %v", err))
}
if restoredFromBin != original {
panic(fmt.Sprintf("restored binary UUID %v != original %v", restoredFromBin, original))
}
var invalidBin uuid.UUID
if err := invalidBin.UnmarshalBinary([]byte{1, 2, 3}); err == nil {
panic("expected error when unmarshaling slice of length != 16")
}
// 2. assert MarshalText encodes a UUID into 36-byte lowercase hex string and UnmarshalText parses formatted byte slices or returns error on malformed input
textData, err := original.MarshalText()
if err != nil {
panic(fmt.Sprintf("MarshalText failed: %v", err))
}
if string(textData) != "6ba7b810-9dad-11d1-80b4-00c04fd430c8" {
panic(fmt.Sprintf("unexpected MarshalText output: %s", string(textData)))
}
var restoredFromText uuid.UUID
if err := restoredFromText.UnmarshalText(textData); err != nil {
panic(fmt.Sprintf("UnmarshalText failed: %v", err))
}
if restoredFromText != original {
panic(fmt.Sprintf("restored text UUID %v != original %v", restoredFromText, original))
}
var invalidText uuid.UUID
if err := invalidText.UnmarshalText([]byte("invalid-uuid-format")); err == nil {
panic("expected error on malformed text input")
}
// 3. assert Value returns string representation conforming to database/sql driver.Valuer interface
var valuer driver.Valuer = original
val, err := valuer.Value()
if err != nil {
panic(fmt.Sprintf("Value() failed: %v", err))
}
valStr, ok := val.(string)
if !ok {
panic(fmt.Sprintf("expected driver.Value to be string, got %T", val))
}
if valStr != original.String() {
panic(fmt.Sprintf("expected %s, got %s", original.String(), valStr))
}
// 4. assert Scan implements database/sql sql.Scanner supporting string, 16-byte raw slice, 36-byte formatted slice, and nil inputs while rejecting unsupported types
var scanFromNil uuid.UUID
if err := scanFromNil.Scan(nil); err != nil {
panic(fmt.Sprintf("Scan(nil) failed: %v", err))
}
if scanFromNil != uuid.Nil {
panic("expected Scan(nil) on zero UUID to remain uuid.Nil")
}
var scanEmptyStr uuid.UUID
if err := scanEmptyStr.Scan(""); err != nil {
panic(fmt.Sprintf("Scan(\"\") failed: %v", err))
}
if scanEmptyStr != uuid.Nil {
panic("expected Scan(\"\") on zero UUID to remain uuid.Nil")
}
var scanEmptyBytes uuid.UUID
if err := scanEmptyBytes.Scan([]byte{}); err != nil {
panic(fmt.Sprintf("Scan([]byte{}) failed: %v", err))
}
if scanEmptyBytes != uuid.Nil {
panic("expected Scan([]byte{}) on zero UUID to remain uuid.Nil")
}
var scanFromStr uuid.UUID
if err := scanFromStr.Scan("6ba7b810-9dad-11d1-80b4-00c04fd430c8"); err != nil {
panic(fmt.Sprintf("Scan(string) failed: %v", err))
}
if scanFromStr != original {
panic("Scan(string) did not match original")
}
var scanFromRawBytes uuid.UUID
if err := scanFromRawBytes.Scan(binData); err != nil {
panic(fmt.Sprintf("Scan(rawBytes) failed: %v", err))
}
if scanFromRawBytes != original {
panic("Scan(rawBytes) did not match original")
}
var scanFromFormattedBytes uuid.UUID
if err := scanFromFormattedBytes.Scan([]byte("6ba7b810-9dad-11d1-80b4-00c04fd430c8")); err != nil {
panic(fmt.Sprintf("Scan(formattedBytes) failed: %v", err))
}
if scanFromFormattedBytes != original {
panic("Scan(formattedBytes) did not match original")
}
var scanInvalidType uuid.UUID
if err := scanInvalidType.Scan(12345); err == nil {
panic("expected Scan(int) to return error for unsupported type")
}
fmt.Println("Contract passed")
}
Seeder d'origine
anonyme