CodeSampleX

Ejemplo

github.com/google/uuid v1.6.0: FromBytes, MarshalText, UnmarshalText

Muestra verificada para golang github.com/google/uuid v1.6.0: FromBytes, MarshalText, UnmarshalText. El contrato se ejecutó en go 1.26 · linux alpine/x64 …

sha256:28dca31d0cee951b24d52435c220f7f6d3450268305d7336f229b8379786a701

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
2
Claves de firma que lo compilaron
2
Entorno declarado windows 11 x64 go

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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
verify pkg:golang/github.com/google/uuid@v1.6.0
Paquetes
Símbolos
  • FromBytes
  • UUID.MarshalText
  • UUID.UnmarshalText
Creado
2026-08-18T22:55:58Z

Contrato

  1. uuid.FromBytes converts valid 16-byte slice to UUID
  2. uuid.FromBytes returns error when slice length is not 16
  3. uuid.UUID.MarshalText marshals UUID to standard 36-byte canonical string representation
  4. uuid.UUID.UnmarshalText unmarshals valid 36-byte string into matching UUID
  5. uuid.UUID.UnmarshalText returns error when text is invalid UUID format

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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.6.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/google/uuid@v1.6.0
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:0fb93485fad2d6d2bde5cc200c071c4742d130c42f22d6ad03ed88cef7c77177","contract":["uuid.FromBytes converts valid 16-byte slice to UUID","uuid.FromBytes returns error when slice length is not 16","uuid.UUID.MarshalText marshals UUID to standard 36-byte canonical string representation","uuid.UUID.UnmarshalText unmarshals valid 36-byte string into matching UUID","uuid.UUID.UnmarshalText returns error when text is invalid UUID format"],"goal":"verify pkg:golang/github.com/google/uuid@v1.6.0","kind":"HOW","packages":["pkg:golang/github.com/google/uuid@v1.6.0"],"schemaVersion":1,"symbols":["FromBytes","UUID.MarshalText","UUID.UnmarshalText"]},"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":["FromBytes","UUID.MarshalText","UUID.UnmarshalText"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.5

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"

	"github.com/google/uuid"
)

// UUIDFromBytes constructs a UUID from a byte slice.
func UUIDFromBytes(b []byte) (uuid.UUID, error) {
	return uuid.FromBytes(b)
}

// MarshalUUIDText converts a UUID to its text representation.
func MarshalUUIDText(u uuid.UUID) ([]byte, error) {
	return u.MarshalText()
}

// UnmarshalUUIDText parses text bytes into a UUID.
func UnmarshalUUIDText(text []byte) (uuid.UUID, error) {
	var u uuid.UUID
	err := u.UnmarshalText(text)
	return u, err
}

func main() {
	rawBytes := []byte{
		0x6b, 0xa7, 0xb8, 0x10,
		0x9d, 0xad,
		0x11, 0xd1,
		0x80, 0xb4,
		0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8,
	}

	u, err := UUIDFromBytes(rawBytes)
	if err != nil {
		fmt.Printf("Error creating UUID from bytes: %v\n", err)
		return
	}
	fmt.Printf("UUID from bytes: %s\n", u.String())

	textBytes, err := MarshalUUIDText(u)
	if err != nil {
		fmt.Printf("Error marshaling UUID text: %v\n", err)
		return
	}
	fmt.Printf("Marshaled text: %s\n", string(textBytes))

	parsed, err := UnmarshalUUIDText(textBytes)
	if err != nil {
		fmt.Printf("Error unmarshaling UUID text: %v\n", err)
		return
	}
	fmt.Printf("Unmarshaled UUID: %s\n", parsed.String())
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/github.com/google/uuid@v1.6.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/google/uuid@v1.6.0"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@11.8.0",
    "runtime": "node@24.13.1"
  }
}
test/main.go
package main

import (
	"bytes"
	"fmt"
	"os"

	"github.com/google/uuid"
)

func assertTrue(name string, condition bool) {
	if !condition {
		fmt.Fprintf(os.Stderr, "Assertion failed for %s: expected true, got false\n", name)
		os.Exit(1)
	}
}

func assertEqual(name, actual, expected string) {
	if actual != expected {
		fmt.Fprintf(os.Stderr, "Assertion failed for %s: got %q, expected %q\n", name, actual, expected)
		os.Exit(1)
	}
}

func main() {
	raw16Bytes := []byte{
		0x6b, 0xa7, 0xb8, 0x10,
		0x9d, 0xad,
		0x11, 0xd1,
		0x80, 0xb4,
		0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8,
	}
	canonicalStr := "6ba7b810-9dad-11d1-80b4-00c04fd430c8"

	// 1. uuid.FromBytes converts valid 16-byte slice to UUID
	u, err := uuid.FromBytes(raw16Bytes)
	assertTrue("uuid.FromBytes succeeds on 16-byte slice", err == nil)
	assertEqual("uuid.FromBytes returns correct canonical string", u.String(), canonicalStr)
	assertTrue("uuid.FromBytes slice matches bytes", bytes.Equal(u[:], raw16Bytes))

	// 2. uuid.FromBytes returns error when slice length is not 16
	_, shortErr := uuid.FromBytes([]byte{0x01, 0x02, 0x03})
	assertTrue("uuid.FromBytes fails on short slice", shortErr != nil)

	_, longErr := uuid.FromBytes(make([]byte, 17))
	assertTrue("uuid.FromBytes fails on 17-byte slice", longErr != nil)

	// 3. uuid.UUID.MarshalText marshals UUID to standard 36-byte canonical string representation
	marshaled, mErr := u.MarshalText()
	assertTrue("uuid.UUID.MarshalText succeeds", mErr == nil)
	assertEqual("uuid.UUID.MarshalText matches canonical string", string(marshaled), canonicalStr)
	assertTrue("uuid.UUID.MarshalText length is 36", len(marshaled) == 36)

	// 4. uuid.UUID.UnmarshalText unmarshals valid 36-byte string into matching UUID
	var unmarshaled uuid.UUID
	uErr := unmarshaled.UnmarshalText([]byte(canonicalStr))
	assertTrue("uuid.UUID.UnmarshalText succeeds on canonical string", uErr == nil)
	assertEqual("unmarshaled UUID matches original UUID string", unmarshaled.String(), canonicalStr)
	assertTrue("unmarshaled UUID matches original UUID object", unmarshaled == u)

	// 5. uuid.UUID.UnmarshalText returns error when text is invalid UUID format
	var badU uuid.UUID
	badErr := badU.UnmarshalText([]byte("invalid-uuid-format-not-36-chars"))
	assertTrue("uuid.UUID.UnmarshalText returns error on invalid text", badErr != nil)
	assertTrue("badU remains Nil on error", badU == uuid.Nil)

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

Seeder de origen

anónimo