CodeSampleX

샘플

github.com/google/uuid v1.3.0

검증된 샘플 — golang github.com/google/uuid v1.3.0. go 1.26 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: uuid.NewUUID generates RFC 4122 version 1 UUID…

sha256:022998b8a6636b54f335c89661d63455a014845dc81677ff5cd4665ef762af7f

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
2
빌드한 서명 키
2
선언된 환경 linux 24 · ubuntu · glibc 2.39 x64 go

검증 실행 환경

환경 컨트랙트 단계 실행일
go 1.26 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 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

케이스

HOW
목표
verify pkg:golang/github.com/google/uuid@v1.3.0
패키지
생성일
2026-08-20T00:29:26Z

컨트랙트

  1. uuid.NewUUID generates RFC 4122 version 1 UUID with valid timestamp and node components
  2. uuid.FromBytes validates 16-byte slice length and converts to UUID without errors
  3. uuid.ParseBytes parses byte representations and validates format
  4. uuid.MustParse returns parsed UUID on valid input and panics on invalid input
  5. uuid.NullUUID handles database nullability with sql.Scanner and driver.Valuer implementations

파일

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

소스 아티팩트 내려받기 (tar.gz)

소스

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:a0450847a3f2de7e5649f04061b9d5f5c448b856e880b20f171609b80c9f8e9f","contract":["uuid.NewUUID generates RFC 4122 version 1 UUID with valid timestamp and node components","uuid.FromBytes validates 16-byte slice length and converts to UUID without errors","uuid.ParseBytes parses byte representations and validates format","uuid.MustParse returns parsed UUID on valid input and panics on invalid input","uuid.NullUUID handles database nullability with sql.Scanner and driver.Valuer implementations"],"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},"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,"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 (
	"bytes"
	"database/sql/driver"
	"fmt"
	"os"

	"github.com/google/uuid"
)

// Record represents a database entity with unique identifiers and optional parent reference.
type Record struct {
	ID       uuid.UUID
	ParentID uuid.NullUUID
}

// NewRecord creates a new Record with a generated Version 1 time-based UUID.
func NewRecord(parentID *uuid.UUID) (*Record, error) {
	id, err := uuid.NewUUID()
	if err != nil {
		return nil, fmt.Errorf("failed to generate v1 uuid: %w", err)
	}

	rec := &Record{
		ID: id,
	}

	if parentID != nil {
		rec.ParentID = uuid.NullUUID{
			UUID:  *parentID,
			Valid: true,
		}
	} else {
		rec.ParentID = uuid.NullUUID{
			Valid: false,
		}
	}

	return rec, nil
}

// ParseIdentifier safely converts raw binary or ASCII byte slice into a UUID.
func ParseIdentifier(raw []byte) (uuid.UUID, error) {
	if len(raw) == 16 {
		return uuid.FromBytes(raw)
	}
	return uuid.ParseBytes(raw)
}

// FormatDatabaseValue serializes nullable UUID for database driver compatibility.
func FormatDatabaseValue(nullUUID uuid.NullUUID) (driver.Value, error) {
	return nullUUID.Value()
}

func main() {
	// 1. Create a root record with Version 1 UUID
	root, err := NewRecord(nil)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error creating root record: %v\n", err)
		os.Exit(1)
	}
	fmt.Printf("Root Record ID (v%d): %s, URN: %s\n", root.ID.Version(), root.ID.String(), root.ID.URN())

	// 2. Create a child record referencing root
	child, err := NewRecord(&root.ID)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error creating child record: %v\n", err)
		os.Exit(1)
	}
	fmt.Printf("Child Record ID: %s, Parent ID: %s (valid: %v)\n",
		child.ID.String(), child.ParentID.UUID.String(), child.ParentID.Valid)

	// 3. Round-trip binary representation
	bin, err := root.ID.MarshalBinary()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Binary marshal error: %v\n", err)
		os.Exit(1)
	}

	restored, err := ParseIdentifier(bin)
	if err != nil || !bytes.Equal(root.ID[:], restored[:]) {
		fmt.Fprintf(os.Stderr, "Binary restore error: %v\n", err)
		os.Exit(1)
	}
	fmt.Printf("Restored ID from 16-byte binary: %s\n", restored.String())

	// 4. MustParse demonstration for well-known constants
	const namespaceStr = "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
	parsedConst := uuid.MustParse(namespaceStr)
	fmt.Printf("Constant parsed via MustParse: %s\n", parsedConst.String())
}
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.NewUUID generates RFC 4122 version 1 UUID with valid timestamp and node components
	{
		u, err := uuid.NewUUID()
		if err != nil {
			fmt.Fprintf(os.Stderr, "FAIL: uuid.NewUUID returned error: %v\n", err)
			os.Exit(1)
		}

		if u.Version() != 1 {
			fmt.Fprintf(os.Stderr, "FAIL: expected version 1, got %v\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)
		}

		node := u.NodeID()
		if len(node) != 6 {
			fmt.Fprintf(os.Stderr, "FAIL: expected 6-byte node ID, got %d bytes\n", len(node))
			os.Exit(1)
		}

		t := u.Time()
		if t == 0 {
			fmt.Fprintf(os.Stderr, "FAIL: expected non-zero timestamp from v1 UUID\n")
			os.Exit(1)
		}
	}

	// Assertion 2: uuid.FromBytes validates 16-byte slice length and converts to UUID without errors
	{
		validBytes := []byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10}
		u, err := uuid.FromBytes(validBytes)
		if err != nil {
			fmt.Fprintf(os.Stderr, "FAIL: uuid.FromBytes failed on valid 16-byte slice: %v\n", err)
			os.Exit(1)
		}

		if !bytes.Equal(u[:], validBytes) {
			fmt.Fprintf(os.Stderr, "FAIL: uuid.FromBytes produced bytes %x, expected %x\n", u[:], validBytes)
			os.Exit(1)
		}

		shortBytes := []byte{0x01, 0x02, 0x03}
		if _, err := uuid.FromBytes(shortBytes); err == nil {
			fmt.Fprintf(os.Stderr, "FAIL: uuid.FromBytes expected error on short slice, got nil\n")
			os.Exit(1)
		}

		longBytes := make([]byte, 17)
		if _, err := uuid.FromBytes(longBytes); err == nil {
			fmt.Fprintf(os.Stderr, "FAIL: uuid.FromBytes expected error on 17-byte slice, got nil\n")
			os.Exit(1)
		}
	}

	// Assertion 3: uuid.ParseBytes parses byte representations and validates format
	{
		inputStr := "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
		u, err := uuid.ParseBytes([]byte(inputStr))
		if err != nil {
			fmt.Fprintf(os.Stderr, "FAIL: uuid.ParseBytes failed on valid UUID bytes: %v\n", err)
			os.Exit(1)
		}

		if u.String() != inputStr {
			fmt.Fprintf(os.Stderr, "FAIL: uuid.ParseBytes result %s != expected %s\n", u.String(), inputStr)
			os.Exit(1)
		}

		invalidBytes := []byte("not-a-valid-uuid-format-here!!")
		if _, err := uuid.ParseBytes(invalidBytes); err == nil {
			fmt.Fprintf(os.Stderr, "FAIL: uuid.ParseBytes expected error on invalid input, got nil\n")
			os.Exit(1)
		}
	}

	// Assertion 4: uuid.MustParse returns parsed UUID on valid input and panics on invalid input
	{
		validStr := "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
		u := uuid.MustParse(validStr)
		if u.String() != validStr {
			fmt.Fprintf(os.Stderr, "FAIL: uuid.MustParse returned %s, expected %s\n", u.String(), validStr)
			os.Exit(1)
		}

		panicked := false
		func() {
			defer func() {
				if r := recover(); r != nil {
					panicked = true
				}
			}()
			_ = uuid.MustParse("invalid-uuid-string")
		}()

		if !panicked {
			fmt.Fprintf(os.Stderr, "FAIL: uuid.MustParse did not panic on invalid input\n")
			os.Exit(1)
		}
	}

	// Assertion 5: uuid.NullUUID handles database nullability with sql.Scanner and driver.Valuer implementations
	{
		var nullID uuid.NullUUID
		val, err := nullID.Value()
		if err != nil || val != nil {
			fmt.Fprintf(os.Stderr, "FAIL: NullUUID.Value() on invalid struct expected (nil, nil), got (%v, %v)\n", val, err)
			os.Exit(1)
		}

		if err := nullID.Scan(nil); err != nil {
			fmt.Fprintf(os.Stderr, "FAIL: NullUUID.Scan(nil) error: %v\n", err)
			os.Exit(1)
		}
		if nullID.Valid {
			fmt.Fprintf(os.Stderr, "FAIL: NullUUID.Scan(nil) should result in Valid=false\n")
			os.Exit(1)
		}

		targetStr := "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
		if err := nullID.Scan(targetStr); err != nil {
			fmt.Fprintf(os.Stderr, "FAIL: NullUUID.Scan(string) error: %v\n", err)
			os.Exit(1)
		}
		if !nullID.Valid || nullID.UUID.String() != targetStr {
			fmt.Fprintf(os.Stderr, "FAIL: NullUUID.Scan(string) failed: Valid=%v, UUID=%s\n", nullID.Valid, nullID.UUID.String())
			os.Exit(1)
		}

		val, err = nullID.Value()
		if err != nil {
			fmt.Fprintf(os.Stderr, "FAIL: NullUUID.Value() error: %v\n", err)
			os.Exit(1)
		}
		strVal, ok := val.(string)
		if !ok || strVal != targetStr {
			fmt.Fprintf(os.Stderr, "FAIL: NullUUID.Value() = %v (type %T), expected %q\n", val, val, targetStr)
			os.Exit(1)
		}
	}

	fmt.Println("PASS: github.com/google/uuid contract passed")
}

오리진 시더

익명