CodeSampleX

Пример

github.com/google/uuid v1.6.0: Serialize and deserialize UUIDs via binary and text interfaces and implement database/sql driver Valuer and Scanner in google/uuid

Проверенный пример — golang github.com/google/uuid v1.6.0: Serialize and deserialize UUIDs via binary and text interfaces and implement database/sql driver…

sha256:01559efd6f5d6619f403e032e1754ae489f0d8596359844c49f473b6d6189530

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
2
Ключи подписи, собравшие его
2
Заявленная среда linux 24 · ubuntu · glibc 2.39 x64 go wsl

Среды запусков проверки

Окружение Контракт Этапы Запуск
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 debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-09-07

Кейс

HOW
Цель
Serialize and deserialize UUIDs via binary and text interfaces and implement database/sql driver Valuer and Scanner in google/uuid
Пакеты
Символы
  • MarshalBinary
  • MarshalText
  • Scan
  • UnmarshalBinary
  • UnmarshalText
  • Value
Создан
2026-08-19T01:26:28Z

Контракт

  1. assert MarshalBinary serializes a UUID to 16 raw bytes and UnmarshalBinary restores the exact UUID or rejects invalid byte slice lengths
  2. assert MarshalText encodes a UUID into 36-byte lowercase hex string and UnmarshalText parses formatted byte slices or returns error on malformed input
  3. assert Value returns string representation conforming to database/sql driver.Valuer interface
  4. assert Scan implements database/sql sql.Scanner supporting string, 16-byte raw slice, 36-byte formatted slice, and nil inputs while rejecting unsupported types

Файлы

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • 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: Serialize and deserialize UUIDs via binary and text interfaces and implement database/sql driver Valuer and Scanner in google/uuid
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/google/uuid@v1.6.0
Demonstrate these symbols/APIs:
  - MarshalBinary
  - MarshalText
  - Scan
  - UnmarshalBinary
  - UnmarshalText
  - Value

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:17d1e48ad41d87a3e491d666c2be2a0cb65947bad4757c835c70e8c1f784c33e","contract":["assert MarshalBinary serializes a UUID to 16 raw bytes and UnmarshalBinary restores the exact UUID or rejects invalid byte slice lengths","assert MarshalText encodes a UUID into 36-byte lowercase hex string and UnmarshalText parses formatted byte slices or returns error on malformed input","assert Value returns string representation conforming to database/sql driver.Valuer interface","assert Scan implements database/sql sql.Scanner supporting string, 16-byte raw slice, 36-byte formatted slice, and nil inputs while rejecting unsupported types"],"goal":"Serialize and deserialize UUIDs via binary and text interfaces and implement database/sql driver Valuer and Scanner in google/uuid","kind":"HOW","packages":["pkg:golang/github.com/google/uuid@v1.6.0"],"schemaVersion":1,"symbols":["MarshalBinary","MarshalText","Scan","UnmarshalBinary","UnmarshalText","Value"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1,"virtualization":"wsl"},"license":"MIT-0","packages":["pkg:golang/github.com/google/uuid@v1.6.0"],"schemaVersion":1,"symbols":["MarshalBinary","MarshalText","Scan","UnmarshalBinary","UnmarshalText","Value"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.25.13

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=
spec.json
{
  "schemaVersion": 1,
  "goal": "Serialize and deserialize UUIDs via binary and text interfaces and implement database/sql driver Valuer and Scanner in google/uuid",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/google/uuid@v1.6.0"
  ],
  "symbols": [
    "MarshalBinary",
    "MarshalText",
    "Scan",
    "UnmarshalBinary",
    "UnmarshalText",
    "Value"
  ]
}
test/contract.go
package main

import (
	"database/sql/driver"
	"fmt"

	"github.com/google/uuid"
)

func main() {
	// 1. assert MarshalBinary serializes a UUID to 16 raw bytes and UnmarshalBinary restores the exact UUID or rejects invalid byte slice lengths
	original := uuid.MustParse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
	binData, err := original.MarshalBinary()
	if err != nil {
		panic(fmt.Sprintf("MarshalBinary failed: %v", err))
	}
	if len(binData) != 16 {
		panic(fmt.Sprintf("expected 16 bytes from MarshalBinary, got %d", len(binData)))
	}

	var restoredFromBin uuid.UUID
	if err := restoredFromBin.UnmarshalBinary(binData); err != nil {
		panic(fmt.Sprintf("UnmarshalBinary failed: %v", err))
	}
	if restoredFromBin != original {
		panic(fmt.Sprintf("restored binary UUID %v != original %v", restoredFromBin, original))
	}

	var invalidBin uuid.UUID
	if err := invalidBin.UnmarshalBinary([]byte{1, 2, 3}); err == nil {
		panic("expected error when unmarshaling slice of length != 16")
	}

	// 2. assert MarshalText encodes a UUID into 36-byte lowercase hex string and UnmarshalText parses formatted byte slices or returns error on malformed input
	textData, err := original.MarshalText()
	if err != nil {
		panic(fmt.Sprintf("MarshalText failed: %v", err))
	}
	if string(textData) != "6ba7b810-9dad-11d1-80b4-00c04fd430c8" {
		panic(fmt.Sprintf("unexpected MarshalText output: %s", string(textData)))
	}

	var restoredFromText uuid.UUID
	if err := restoredFromText.UnmarshalText(textData); err != nil {
		panic(fmt.Sprintf("UnmarshalText failed: %v", err))
	}
	if restoredFromText != original {
		panic(fmt.Sprintf("restored text UUID %v != original %v", restoredFromText, original))
	}

	var invalidText uuid.UUID
	if err := invalidText.UnmarshalText([]byte("invalid-uuid-format")); err == nil {
		panic("expected error on malformed text input")
	}

	// 3. assert Value returns string representation conforming to database/sql driver.Valuer interface
	var valuer driver.Valuer = original
	val, err := valuer.Value()
	if err != nil {
		panic(fmt.Sprintf("Value() failed: %v", err))
	}
	valStr, ok := val.(string)
	if !ok {
		panic(fmt.Sprintf("expected driver.Value to be string, got %T", val))
	}
	if valStr != original.String() {
		panic(fmt.Sprintf("expected %s, got %s", original.String(), valStr))
	}

	// 4. assert Scan implements database/sql sql.Scanner supporting string, 16-byte raw slice, 36-byte formatted slice, and nil inputs while rejecting unsupported types
	var scanFromNil uuid.UUID
	if err := scanFromNil.Scan(nil); err != nil {
		panic(fmt.Sprintf("Scan(nil) failed: %v", err))
	}
	if scanFromNil != uuid.Nil {
		panic("expected Scan(nil) on zero UUID to remain uuid.Nil")
	}

	var scanEmptyStr uuid.UUID
	if err := scanEmptyStr.Scan(""); err != nil {
		panic(fmt.Sprintf("Scan(\"\") failed: %v", err))
	}
	if scanEmptyStr != uuid.Nil {
		panic("expected Scan(\"\") on zero UUID to remain uuid.Nil")
	}

	var scanEmptyBytes uuid.UUID
	if err := scanEmptyBytes.Scan([]byte{}); err != nil {
		panic(fmt.Sprintf("Scan([]byte{}) failed: %v", err))
	}
	if scanEmptyBytes != uuid.Nil {
		panic("expected Scan([]byte{}) on zero UUID to remain uuid.Nil")
	}

	var scanFromStr uuid.UUID
	if err := scanFromStr.Scan("6ba7b810-9dad-11d1-80b4-00c04fd430c8"); err != nil {
		panic(fmt.Sprintf("Scan(string) failed: %v", err))
	}
	if scanFromStr != original {
		panic("Scan(string) did not match original")
	}

	var scanFromRawBytes uuid.UUID
	if err := scanFromRawBytes.Scan(binData); err != nil {
		panic(fmt.Sprintf("Scan(rawBytes) failed: %v", err))
	}
	if scanFromRawBytes != original {
		panic("Scan(rawBytes) did not match original")
	}

	var scanFromFormattedBytes uuid.UUID
	if err := scanFromFormattedBytes.Scan([]byte("6ba7b810-9dad-11d1-80b4-00c04fd430c8")); err != nil {
		panic(fmt.Sprintf("Scan(formattedBytes) failed: %v", err))
	}
	if scanFromFormattedBytes != original {
		panic("Scan(formattedBytes) did not match original")
	}

	var scanInvalidType uuid.UUID
	if err := scanInvalidType.Scan(12345); err == nil {
		panic("expected Scan(int) to return error for unsupported type")
	}

	fmt.Println("Contract passed")
}

Исходный сидер

аноним