CodeSampleX

샘플

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

검증된 샘플 — golang github.com/google/uuid v1.6.0: MarshalText, UnmarshalText. go 1.26 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다.

sha256:55563d7d57b6b57ae1906e21ff5a3adab1615ef563955b14231f7d4cc2eb3427

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

실행 증거

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

증거 기준
서명된 컨트랙트 통과
검증 영수증
2
빌드한 서명 키
2
선언된 환경 go 1.26 windows 11 x64 go 1.26 go go 1

검증 실행 환경

환경 컨트랙트 단계 실행일
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
패키지
심벌
  • github.com/google/uuid.MarshalText
  • github.com/google/uuid.UnmarshalText
환경
go 1.26.5
생성일
2026-08-18T22:40:52Z

컨트랙트

  1. uuid.MarshalText encodes UUID into 36-byte standard hyphenated string representation
  2. uuid.MarshalText encodes uuid.Nil into 36-byte zero UUID text
  3. uuid.UnmarshalText decodes standard 36-byte hyphenated UUID text
  4. uuid.UnmarshalText decodes 32-byte hex without hyphens, braced, and URN prefixed UUID text
  5. uuid.UnmarshalText rejects invalid UUID text with error
  6. uuid.MarshalText and uuid.UnmarshalText round-trip accurately preserves UUID value

파일

  • 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.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:ee14ae3ade3a219898f3ce45de4eb462581813fc3f002d0cae5eb137722cc8ad","contract":["uuid.MarshalText encodes UUID into 36-byte standard hyphenated string representation","uuid.MarshalText encodes uuid.Nil into 36-byte zero UUID text","uuid.UnmarshalText decodes standard 36-byte hyphenated UUID text","uuid.UnmarshalText decodes 32-byte hex without hyphens, braced, and URN prefixed UUID text","uuid.UnmarshalText rejects invalid UUID text with error","uuid.MarshalText and uuid.UnmarshalText round-trip accurately preserves UUID value"],"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":["github.com/google/uuid.MarshalText","github.com/google/uuid.UnmarshalText"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","ecosystem":"golang","language":"go","os":"windows","osVersionBucket":"11","packageManager":"go","packageManagerVersion":"1.26.5","runtime":"go","runtimeVersion":"1.26.5","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/google/uuid@v1.6.0"],"schemaVersion":1,"symbols":["github.com/google/uuid.MarshalText","github.com/google/uuid.UnmarshalText"],"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=
main.go
package main

import (
	"fmt"
	"log"

	"github.com/google/uuid"
)

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

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

func main() {
	original := uuid.New()
	text, err := MarshalUUIDText(original)
	if err != nil {
		log.Fatalf("MarshalText failed: %v", err)
	}
	fmt.Printf("Marshaled text: %s\n", string(text))

	restored, err := UnmarshalUUIDText(text)
	if err != nil {
		log.Fatalf("UnmarshalText failed: %v", err)
	}
	fmt.Printf("Restored UUID: %s\n", restored.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/contract.go
package main

import (
	"bytes"
	"fmt"
	"os"

	"github.com/google/uuid"
)

func main() {
	// Assertion 1: uuid.MarshalText encodes UUID into 36-byte standard hyphenated string representation
	sampleUUID, err := uuid.Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: setup parse failed: %v\n", err)
		os.Exit(1)
	}

	marshaled, err := sampleUUID.MarshalText()
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: MarshalText failed: %v\n", err)
		os.Exit(1)
	}
	if len(marshaled) != 36 {
		fmt.Fprintf(os.Stderr, "FAIL: expected length 36, got %d\n", len(marshaled))
		os.Exit(1)
	}
	if string(marshaled) != "6ba7b810-9dad-11d1-80b4-00c04fd430c8" {
		fmt.Fprintf(os.Stderr, "FAIL: unexpected marshaled text: %s\n", string(marshaled))
		os.Exit(1)
	}

	// Assertion 2: uuid.MarshalText encodes uuid.Nil into 36-byte zero UUID text
	nilMarshaled, err := uuid.Nil.MarshalText()
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: MarshalText on Nil failed: %v\n", err)
		os.Exit(1)
	}
	if string(nilMarshaled) != "00000000-0000-0000-0000-000000000000" {
		fmt.Fprintf(os.Stderr, "FAIL: Nil UUID marshaled text mismatch: got %s\n", string(nilMarshaled))
		os.Exit(1)
	}

	// Assertion 3: uuid.UnmarshalText decodes standard 36-byte hyphenated UUID text
	var u1 uuid.UUID
	if err := u1.UnmarshalText([]byte("6ba7b810-9dad-11d1-80b4-00c04fd430c8")); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: UnmarshalText failed on standard format: %v\n", err)
		os.Exit(1)
	}
	if u1 != sampleUUID {
		fmt.Fprintf(os.Stderr, "FAIL: UnmarshalText standard format mismatch: got %s, want %s\n", u1, sampleUUID)
		os.Exit(1)
	}

	// Assertion 4: uuid.UnmarshalText decodes 32-byte hex without hyphens, braced, and URN prefixed UUID text
	variants := [][]byte{
		[]byte("6ba7b8109dad11d180b400c04fd430c8"),
		[]byte("{6ba7b810-9dad-11d1-80b4-00c04fd430c8}"),
		[]byte("urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8"),
	}
	for _, v := range variants {
		var uv uuid.UUID
		if err := uv.UnmarshalText(v); err != nil {
			fmt.Fprintf(os.Stderr, "FAIL: UnmarshalText failed on variant %q: %v\n", string(v), err)
			os.Exit(1)
		}
		if uv != sampleUUID {
			fmt.Fprintf(os.Stderr, "FAIL: UnmarshalText variant %q mismatch: got %s, want %s\n", string(v), uv, sampleUUID)
			os.Exit(1)
		}
	}

	// Assertion 5: uuid.UnmarshalText rejects invalid UUID text with error
	invalidTexts := [][]byte{
		[]byte(""),
		[]byte("not-a-uuid"),
		[]byte("6ba7b810-9dad-11d1-80b4-00c04fd430c"),
		[]byte("6ba7b810-9dad-11d1-80b4-00c04fd430c89"),
		[]byte("6ba7b810-9dad-11d1-80b4-00c04fd430zz"),
	}
	for _, inv := range invalidTexts {
		var uInv uuid.UUID
		if err := uInv.UnmarshalText(inv); err == nil {
			fmt.Fprintf(os.Stderr, "FAIL: expected error for invalid text %q, got nil\n", string(inv))
			os.Exit(1)
		}
	}

	// Assertion 6: uuid.MarshalText and uuid.UnmarshalText round-trip accurately preserves UUID value
	randUUID := uuid.New()
	encoded, err := randUUID.MarshalText()
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: MarshalText on random UUID failed: %v\n", err)
		os.Exit(1)
	}
	var decoded uuid.UUID
	if err := decoded.UnmarshalText(encoded); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: UnmarshalText round-trip failed: %v\n", err)
		os.Exit(1)
	}
	if decoded != randUUID {
		fmt.Fprintf(os.Stderr, "FAIL: round-trip value mismatch: got %s, want %s\n", decoded, randUUID)
		os.Exit(1)
	}
	if !bytes.Equal(encoded, []byte(randUUID.String())) {
		fmt.Fprintf(os.Stderr, "FAIL: MarshalText output does not match String(): got %s, want %s\n", string(encoded), randUUID.String())
		os.Exit(1)
	}

	fmt.Println("PASS: all contract assertions passed for uuid.MarshalText and uuid.UnmarshalText")
}

오리진 시더

익명