CodeSampleX

Ejemplo

gopkg.in/yaml.v3 v3.0.1

Muestra verificada para golang gopkg.in/yaml.v3 v3.0.1. El contrato se ejecutó en go 1.26 · linux alpine/x64 · docker y pasó: yaml.Unmarshal parses YAML…

sha256:db6dca2a91841f6de8a86f243f1187ccbbe00fe3b89c7f173df4c169ec47a658

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado linux 24 · ubuntu · glibc 2.39 x64 go

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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

Caso

HOW
Objetivo
verify pkg:golang/gopkg.in/yaml.v3@v3.0.1
Paquetes
Creado
2026-08-23T06:05:53Z

Contrato

  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

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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
}

Seeder de origen

anónimo