示例
github.com/google/uuid v1.6.0: FromBytes, MarshalText, UnmarshalText
已验证示例 — golang github.com/google/uuid v1.6.0: FromBytes, MarshalText, UnmarshalText. contract 在 go 1.26 · linux alpine/x64 · docker 上运行并通过.
sha256:28dca31d0cee951b24d52435c220f7f6d3450268305d7336f229b8379786a701
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
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
- 符号
-
- FromBytes
- UUID.MarshalText
- UUID.UnmarshalText
- 创建时间
- 2026-08-18T22:55:58Z
契约
- uuid.FromBytes converts valid 16-byte slice to UUID
- uuid.FromBytes returns error when slice length is not 16
- uuid.UUID.MarshalText marshals UUID to standard 36-byte canonical string representation
- uuid.UUID.UnmarshalText unmarshals valid 36-byte string into matching UUID
- uuid.UUID.UnmarshalText returns error when text is invalid UUID format
文件
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/main.go
源代码
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.
{"case":{"caseId":"case:sha256:0fb93485fad2d6d2bde5cc200c071c4742d130c42f22d6ad03ed88cef7c77177","contract":["uuid.FromBytes converts valid 16-byte slice to UUID","uuid.FromBytes returns error when slice length is not 16","uuid.UUID.MarshalText marshals UUID to standard 36-byte canonical string representation","uuid.UUID.UnmarshalText unmarshals valid 36-byte string into matching UUID","uuid.UUID.UnmarshalText returns error when text is invalid UUID format"],"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":["FromBytes","UUID.MarshalText","UUID.UnmarshalText"]},"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":["FromBytes","UUID.MarshalText","UUID.UnmarshalText"],"verifierAdapter":"golang@1"}
module sample
go 1.26.5
require github.com/google/uuid v1.6.0
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=
package main
import (
"fmt"
"github.com/google/uuid"
)
// UUIDFromBytes constructs a UUID from a byte slice.
func UUIDFromBytes(b []byte) (uuid.UUID, error) {
return uuid.FromBytes(b)
}
// MarshalUUIDText converts a UUID to its text representation.
func MarshalUUIDText(u uuid.UUID) ([]byte, error) {
return u.MarshalText()
}
// UnmarshalUUIDText parses text bytes into a UUID.
func UnmarshalUUIDText(text []byte) (uuid.UUID, error) {
var u uuid.UUID
err := u.UnmarshalText(text)
return u, err
}
func main() {
rawBytes := []byte{
0x6b, 0xa7, 0xb8, 0x10,
0x9d, 0xad,
0x11, 0xd1,
0x80, 0xb4,
0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8,
}
u, err := UUIDFromBytes(rawBytes)
if err != nil {
fmt.Printf("Error creating UUID from bytes: %v\n", err)
return
}
fmt.Printf("UUID from bytes: %s\n", u.String())
textBytes, err := MarshalUUIDText(u)
if err != nil {
fmt.Printf("Error marshaling UUID text: %v\n", err)
return
}
fmt.Printf("Marshaled text: %s\n", string(textBytes))
parsed, err := UnmarshalUUIDText(textBytes)
if err != nil {
fmt.Printf("Error unmarshaling UUID text: %v\n", err)
return
}
fmt.Printf("Unmarshaled UUID: %s\n", parsed.String())
}
{
"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"
}
}
package main
import (
"bytes"
"fmt"
"os"
"github.com/google/uuid"
)
func assertTrue(name string, condition bool) {
if !condition {
fmt.Fprintf(os.Stderr, "Assertion failed for %s: expected true, got false\n", name)
os.Exit(1)
}
}
func assertEqual(name, actual, expected string) {
if actual != expected {
fmt.Fprintf(os.Stderr, "Assertion failed for %s: got %q, expected %q\n", name, actual, expected)
os.Exit(1)
}
}
func main() {
raw16Bytes := []byte{
0x6b, 0xa7, 0xb8, 0x10,
0x9d, 0xad,
0x11, 0xd1,
0x80, 0xb4,
0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8,
}
canonicalStr := "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
// 1. uuid.FromBytes converts valid 16-byte slice to UUID
u, err := uuid.FromBytes(raw16Bytes)
assertTrue("uuid.FromBytes succeeds on 16-byte slice", err == nil)
assertEqual("uuid.FromBytes returns correct canonical string", u.String(), canonicalStr)
assertTrue("uuid.FromBytes slice matches bytes", bytes.Equal(u[:], raw16Bytes))
// 2. uuid.FromBytes returns error when slice length is not 16
_, shortErr := uuid.FromBytes([]byte{0x01, 0x02, 0x03})
assertTrue("uuid.FromBytes fails on short slice", shortErr != nil)
_, longErr := uuid.FromBytes(make([]byte, 17))
assertTrue("uuid.FromBytes fails on 17-byte slice", longErr != nil)
// 3. uuid.UUID.MarshalText marshals UUID to standard 36-byte canonical string representation
marshaled, mErr := u.MarshalText()
assertTrue("uuid.UUID.MarshalText succeeds", mErr == nil)
assertEqual("uuid.UUID.MarshalText matches canonical string", string(marshaled), canonicalStr)
assertTrue("uuid.UUID.MarshalText length is 36", len(marshaled) == 36)
// 4. uuid.UUID.UnmarshalText unmarshals valid 36-byte string into matching UUID
var unmarshaled uuid.UUID
uErr := unmarshaled.UnmarshalText([]byte(canonicalStr))
assertTrue("uuid.UUID.UnmarshalText succeeds on canonical string", uErr == nil)
assertEqual("unmarshaled UUID matches original UUID string", unmarshaled.String(), canonicalStr)
assertTrue("unmarshaled UUID matches original UUID object", unmarshaled == u)
// 5. uuid.UUID.UnmarshalText returns error when text is invalid UUID format
var badU uuid.UUID
badErr := badU.UnmarshalText([]byte("invalid-uuid-format-not-36-chars"))
assertTrue("uuid.UUID.UnmarshalText returns error on invalid text", badErr != nil)
assertTrue("badU remains Nil on error", badU == uuid.Nil)
fmt.Println("All contract assertions passed successfully.")
}
原始种子者
匿名