CodeSampleX

Beispiel

gopkg.in/yaml.v3 v3.0.1

Verifiziertes Beispiel für golang gopkg.in/yaml.v3 v3.0.1. Der Vertrag lief auf go 1.26 · linux alpine/x64 · docker und bestand.

sha256:db6dca2a91841f6de8a86f243f1187ccbbe00fe3b89c7f173df4c169ec47a658

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung linux 24 · ubuntu · glibc 2.39 x64 go

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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

Fall

HOW
Ziel
verify pkg:golang/gopkg.in/yaml.v3@v3.0.1
Pakete
Erstellt
2026-08-23T06:05:53Z

Contract

  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

Dateien

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • spec.json
  • test/contract.go

Quellartefakt herunterladen (tar.gz)

Quelltext

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
}

Ursprungs-Seeder

anonym