CodeSampleX

サンプル

github.com/google/uuid v1.6.0: New, Parse, ParseBytes

検証済みサンプル — golang github.com/google/uuid v1.6.0: New, Parse, ParseBytes. go 1.26 · linux alpine/x64 · docker で contract を実行し、成功しました.

sha256:a38eeefc186090293c63986424076ffc26161543146a554351045ec5858c6500

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

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
2
ビルドした署名鍵
2
宣言された環境 windows 11 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-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

ケース

HOW
ゴール
verify pkg:golang/github.com/google/uuid@v1.6.0
パッケージ
シンボル
  • New
  • Parse
  • ParseBytes
  • Validate
  • FromBytes
作成日
2026-08-19T09:32:05Z

コントラクト

  1. uuid.New generates a valid version 4 UUID with RFC4122 variant
  2. uuid.Parse and uuid.ParseBytes parse 36-character hyphenated UUID strings and byte slices
  3. uuid.Parse parses 32-character hexadecimal UUID format and URN formatted strings
  4. uuid.Parse and uuid.Validate return errors for malformed or invalid length UUID strings
  5. uuid.FromBytes constructs UUID from 16-byte slice and rejects invalid slice lengths
  6. uuid.Nil represents zero value UUID with Version 0 and Reserved variant

ファイル

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • sample.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.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:b56bf2f5d836124c9de874a9244b3d786aa0e356ebc6675e71f4fc36bfeaf5fa","contract":["uuid.New generates a valid version 4 UUID with RFC4122 variant","uuid.Parse and uuid.ParseBytes parse 36-character hyphenated UUID strings and byte slices","uuid.Parse parses 32-character hexadecimal UUID format and URN formatted strings","uuid.Parse and uuid.Validate return errors for malformed or invalid length UUID strings","uuid.FromBytes constructs UUID from 16-byte slice and rejects invalid slice lengths","uuid.Nil represents zero value UUID with Version 0 and Reserved variant"],"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":["New","Parse","ParseBytes","Validate","FromBytes"]},"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":["New","Parse","ParseBytes","Validate","FromBytes"],"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=
sample.go
package sample

import (
	"github.com/google/uuid"
)

// GenerateUUID generates a new RFC 4122 Version 4 UUID.
func GenerateUUID() uuid.UUID {
	return uuid.New()
}

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

// ParseUUIDBytes parses a byte slice representation into a UUID.
func ParseUUIDBytes(b []byte) (uuid.UUID, error) {
	return uuid.ParseBytes(b)
}

// ValidateUUID checks if a string is a valid UUID representation.
func ValidateUUID(s string) error {
	return uuid.Validate(s)
}

// FromByteSlice constructs a UUID from a raw 16-byte slice.
func FromByteSlice(b []byte) (uuid.UUID, error) {
	return uuid.FromBytes(b)
}
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/contract.go
package main

import (
	"bytes"
	"fmt"
	"os"

	"github.com/google/uuid"
)

func main() {
	// 1. uuid.New generates a valid version 4 UUID with RFC4122 variant
	u1 := uuid.New()
	if u1.Version() != 4 {
		fmt.Fprintf(os.Stderr, "expected version 4, got %v\n", u1.Version())
		os.Exit(1)
	}
	if u1.Variant() != uuid.RFC4122 {
		fmt.Fprintf(os.Stderr, "expected RFC4122 variant, got %v\n", u1.Variant())
		os.Exit(1)
	}
	if len(u1.String()) != 36 {
		fmt.Fprintf(os.Stderr, "expected 36 characters string, got %d\n", len(u1.String()))
		os.Exit(1)
	}
	u2 := uuid.New()
	if u1 == u2 {
		fmt.Fprintf(os.Stderr, "expected successive calls to uuid.New to be unique\n")
		os.Exit(1)
	}

	// 2. uuid.Parse and uuid.ParseBytes parse 36-character hyphenated UUID strings and byte slices
	canonicalStr := "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
	parsed, err := uuid.Parse(canonicalStr)
	if err != nil {
		fmt.Fprintf(os.Stderr, "unexpected error in uuid.Parse: %v\n", err)
		os.Exit(1)
	}
	if parsed.String() != canonicalStr {
		fmt.Fprintf(os.Stderr, "expected parsed string %q, got %q\n", canonicalStr, parsed.String())
		os.Exit(1)
	}
	parsedBytes, err := uuid.ParseBytes([]byte(canonicalStr))
	if err != nil {
		fmt.Fprintf(os.Stderr, "unexpected error in uuid.ParseBytes: %v\n", err)
		os.Exit(1)
	}
	if parsedBytes != parsed {
		fmt.Fprintf(os.Stderr, "expected parsedBytes %v, got %v\n", parsed, parsedBytes)
		os.Exit(1)
	}

	// 3. uuid.Parse parses 32-character hexadecimal UUID format and URN formatted strings
	hexStr := "6ba7b8109dad11d180b400c04fd430c8"
	parsedHex, err := uuid.Parse(hexStr)
	if err != nil {
		fmt.Fprintf(os.Stderr, "unexpected error parsing hex string: %v\n", err)
		os.Exit(1)
	}
	if parsedHex != parsed {
		fmt.Fprintf(os.Stderr, "expected hex parse to equal canonical parse, got %v vs %v\n", parsedHex, parsed)
		os.Exit(1)
	}

	urnStr := "urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8"
	parsedURN, err := uuid.Parse(urnStr)
	if err != nil {
		fmt.Fprintf(os.Stderr, "unexpected error parsing URN string: %v\n", err)
		os.Exit(1)
	}
	if parsedURN != parsed {
		fmt.Fprintf(os.Stderr, "expected URN parse to equal canonical parse, got %v vs %v\n", parsedURN, parsed)
		os.Exit(1)
	}

	// 4. uuid.Parse and uuid.Validate return errors for malformed or invalid length UUID strings
	invalidStrings := []string{
		"",
		"not-a-valid-uuid",
		"6ba7b810-9dad-11d1-80b4-00c04fd430c",   // 35 chars
		"6ba7b810-9dad-11d1-80b4-00c04fd430c89",  // 37 chars
		"6ba7b810-9dad-11d1-80b4-00c04fd430cg",  // invalid hex 'g'
		"urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c",
	}
	for _, s := range invalidStrings {
		if _, err := uuid.Parse(s); err == nil {
			fmt.Fprintf(os.Stderr, "expected error in uuid.Parse for %q, got nil\n", s)
			os.Exit(1)
		}
		if err := uuid.Validate(s); err == nil {
			fmt.Fprintf(os.Stderr, "expected error in uuid.Validate for %q, got nil\n", s)
			os.Exit(1)
		}
	}
	if err := uuid.Validate(canonicalStr); err != nil {
		fmt.Fprintf(os.Stderr, "unexpected error validating canonical UUID %q: %v\n", canonicalStr, err)
		os.Exit(1)
	}

	// 5. uuid.FromBytes constructs UUID from 16-byte slice and rejects invalid slice lengths
	rawBytes := parsed[:]
	fromBytesUUID, err := uuid.FromBytes(rawBytes)
	if err != nil {
		fmt.Fprintf(os.Stderr, "unexpected error in uuid.FromBytes: %v\n", err)
		os.Exit(1)
	}
	if fromBytesUUID != parsed {
		fmt.Fprintf(os.Stderr, "expected FromBytes UUID %v, got %v\n", parsed, fromBytesUUID)
		os.Exit(1)
	}
	invalidLengths := [][]byte{
		{},
		make([]byte, 15),
		make([]byte, 17),
	}
	for _, b := range invalidLengths {
		if _, err := uuid.FromBytes(b); err == nil {
			fmt.Fprintf(os.Stderr, "expected error in uuid.FromBytes for length %d, got nil\n", len(b))
			os.Exit(1)
		}
	}

	// 6. uuid.Nil represents zero value UUID with Version 0 and Reserved variant
	if uuid.Nil.String() != "00000000-0000-0000-0000-000000000000" {
		fmt.Fprintf(os.Stderr, "unexpected string for Nil UUID: %s\n", uuid.Nil.String())
		os.Exit(1)
	}
	if !bytes.Equal(uuid.Nil[:], make([]byte, 16)) {
		fmt.Fprintf(os.Stderr, "expected all zero bytes for uuid.Nil\n")
		os.Exit(1)
	}
	if uuid.Nil.Version() != 0 {
		fmt.Fprintf(os.Stderr, "expected Nil UUID version 0, got %v\n", uuid.Nil.Version())
		os.Exit(1)
	}
	if uuid.Nil.Variant() != uuid.Reserved {
		fmt.Fprintf(os.Stderr, "expected Nil UUID variant Reserved, got %v\n", uuid.Nil.Variant())
		os.Exit(1)
	}

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

オリジンシーダー

匿名