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

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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")
}

オリジンシーダー

匿名