CodeSampleX

サンプル

gopkg.in/yaml.v3 v3.0.1

検証済みサンプル — golang gopkg.in/yaml.v3 v3.0.1. go 1.26 · linux alpine/x64 · docker で contract を実行し、成功しました: yaml.Unmarshal parses YAML documents into Go struct…

sha256:db6dca2a91841f6de8a86f243f1187ccbbe00fe3b89c7f173df4c169ec47a658

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

実行証拠

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

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 linux 24 · ubuntu · glibc 2.39 x64 go

検証実行環境

環境 コントラクト ステージ 実行日
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-08-23

ケース

HOW
ゴール
verify pkg:golang/gopkg.in/yaml.v3@v3.0.1
パッケージ
作成日
2026-08-23T06:05:53Z

コントラクト

  1. yaml.Unmarshal parses YAML documents into Go struct fields with yaml tags
  2. yaml.Marshal serializes Go structs to YAML format
  3. yaml.Node decodes and preserves YAML document structure
  4. yaml.NewDecoder and yaml.NewEncoder stream YAML documents

ファイル

  • 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: verify pkg:golang/gopkg.in/yaml.v3@v3.0.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/gopkg.in/yaml.v3@v3.0.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:a4062d32eee4a0819244bf0fe70ecf8462b6133f069f4488c9074d2320c1ad59","contract":["yaml.Unmarshal parses YAML documents into Go struct fields with yaml tags","yaml.Marshal serializes Go structs to YAML format","yaml.Node decodes and preserves YAML document structure","yaml.NewDecoder and yaml.NewEncoder stream YAML documents"],"goal":"verify pkg:golang/gopkg.in/yaml.v3@v3.0.1","kind":"HOW","packages":["pkg:golang/gopkg.in/yaml.v3@v3.0.1"],"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/gopkg.in/yaml.v3@v3.0.1"],"schemaVersion":1,"subject":"pkg:golang/gopkg.in/yaml.v3@v3.0.1","verifierAdapter":"golang@1"}
go.mod
module sample

go 1.21

require gopkg.in/yaml.v3 v3.0.1
go.sum
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/gopkg.in/yaml.v3@v3.0.1",
  "kind": "HOW",
  "packages": [
    "pkg:golang/gopkg.in/yaml.v3@v3.0.1"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"fmt"
	"os"
	"reflect"
	"strings"

	"gopkg.in/yaml.v3"
)

type ServerConfig struct {
	Host    string            `yaml:"host"`
	Port    int               `yaml:"port"`
	Enabled bool              `yaml:"enabled"`
	Tags    []string          `yaml:"tags"`
	Meta    map[string]string `yaml:"meta"`
}

type AppConfig struct {
	Version string       `yaml:"version"`
	Server  ServerConfig `yaml:"server"`
}

func main() {
	if err := runTests(); err != nil {
		fmt.Fprintf(os.Stderr, "Contract test failed: %v\n", err)
		os.Exit(1)
	}
	fmt.Println("All contract tests passed successfully.")
}

func runTests() error {
	// 1. Test yaml.Unmarshal with struct tags, nested structs, slices, and maps
	yamlData := `
version: "1.0.0"
server:
  host: example.com
  port: 8080
  enabled: true
  tags:
    - web
    - api
  meta:
    env: production
`
	var cfg AppConfig
	if err := yaml.Unmarshal([]byte(yamlData), &cfg); err != nil {
		return fmt.Errorf("yaml.Unmarshal failed: %w", err)
	}

	if cfg.Version != "1.0.0" {
		return fmt.Errorf("expected version '1.0.0', got '%s'", cfg.Version)
	}
	if cfg.Server.Host != "example.com" || cfg.Server.Port != 8080 || !cfg.Server.Enabled {
		return fmt.Errorf("unexpected server config: %+v", cfg.Server)
	}
	if !reflect.DeepEqual(cfg.Server.Tags, []string{"web", "api"}) {
		return fmt.Errorf("unexpected tags: %+v", cfg.Server.Tags)
	}
	if cfg.Server.Meta["env"] != "production" {
		return fmt.Errorf("unexpected meta env: %s", cfg.Server.Meta["env"])
	}

	// 2. Test yaml.Marshal
	out, err := yaml.Marshal(&cfg)
	if err != nil {
		return fmt.Errorf("yaml.Marshal failed: %w", err)
	}
	if !strings.Contains(string(out), "example.com") || !strings.Contains(string(out), "8080") {
		return fmt.Errorf("marshaled YAML missing expected content: %s", string(out))
	}

	// 3. Test yaml.Node (AST parsing and manipulation)
	var node yaml.Node
	if err := yaml.Unmarshal([]byte(yamlData), &node); err != nil {
		return fmt.Errorf("yaml.Unmarshal into yaml.Node failed: %w", err)
	}
	if node.Kind != yaml.DocumentNode || len(node.Content) == 0 {
		return fmt.Errorf("expected DocumentNode with content, got kind=%v len=%d", node.Kind, len(node.Content))
	}
	rootMap := node.Content[0]
	if rootMap.Kind != yaml.MappingNode {
		return fmt.Errorf("expected root node to be MappingNode, got kind=%v", rootMap.Kind)
	}

	// 4. Test yaml.Decoder and yaml.Encoder with streams
	var buf bytes.Buffer
	enc := yaml.NewEncoder(&buf)
	if err := enc.Encode(&cfg); err != nil {
		return fmt.Errorf("yaml.NewEncoder Encode failed: %w", err)
	}
	if err := enc.Close(); err != nil {
		return fmt.Errorf("yaml.NewEncoder Close failed: %w", err)
	}

	var decodedCfg AppConfig
	dec := yaml.NewDecoder(&buf)
	if err := dec.Decode(&decodedCfg); err != nil {
		return fmt.Errorf("yaml.NewDecoder Decode failed: %w", err)
	}
	if !reflect.DeepEqual(cfg, decodedCfg) {
		return fmt.Errorf("encoder/decoder roundtrip mismatch: %+v vs %+v", cfg, decodedCfg)
	}

	return nil
}

オリジンシーダー

匿名