CodeSampleX

Exemple

gopkg.in/yaml.v3 v3.0.1

Échantillon vérifié pour golang gopkg.in/yaml.v3 v3.0.1. Le contrat s'est exécuté sur go 1.26 · linux alpine/x64 · docker et a réussi.

sha256:db6dca2a91841f6de8a86f243f1187ccbbe00fe3b89c7f173df4c169ec47a658

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 go

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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

Cas

HOW
Objectif
verify pkg:golang/gopkg.in/yaml.v3@v3.0.1
Paquets
Créé
2026-08-23T06:05:53Z

Contrat

  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

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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 d'origine

anonyme