CodeSampleX

Sample

gopkg.in/yaml.v2 v2.3.0: yaml.NewDecoder

Verified sample for golang gopkg.in/yaml.v2 v2.3.0: yaml.NewDecoder. The contract ran on go 1.26 · linux debian/x64 · docker and passed.

sha256:476465cdb5de3e454d532f702b7a0a367dd509faea065291bdfe3c9f2b2060ac

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment linux 24 · ubuntu · glibc 2.39 x64 go

Verification-run environments

Environment Contract Stages Run
go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-09-04

Case

HOW
Goal
verify pkg:golang/gopkg.in/yaml.v2@v2.3.0
Packages
Symbols
  • yaml.NewDecoder
Created
2026-09-04T19:37:41Z

Contract

  1. yaml.NewDecoder decodes multiple YAML documents sequentially from an io.Reader
  2. yaml.NewDecoder returns io.EOF after decoding all documents in a stream
  3. yaml.NewDecoder with SetStrict(true) returns TypeError when input contains unknown fields
  4. yaml.NewDecoder returns an error when encountering malformed YAML syntax

Files

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

Download the source artifact (tar.gz)

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.v2@v2.3.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/gopkg.in/yaml.v2@v2.3.0
Demonstrate these symbols/APIs:
  - yaml.NewDecoder

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:d2d19cec2a2a77474c0287f63ec89ee8b619553acb9167f4891f2537a20c56b3","contract":["yaml.NewDecoder decodes multiple YAML documents sequentially from an io.Reader","yaml.NewDecoder returns io.EOF after decoding all documents in a stream","yaml.NewDecoder with SetStrict(true) returns TypeError when input contains unknown fields","yaml.NewDecoder returns an error when encountering malformed YAML syntax"],"goal":"verify pkg:golang/gopkg.in/yaml.v2@v2.3.0","kind":"HOW","packages":["pkg:golang/gopkg.in/yaml.v2@v2.3.0"],"schemaVersion":1,"symbols":["yaml.NewDecoder"]},"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.v2@v2.3.0"],"schemaVersion":1,"subject":"pkg:golang/gopkg.in/yaml.v2@v2.3.0","symbols":["yaml.NewDecoder"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require gopkg.in/yaml.v2 v2.3.0
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.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
main.go
package main

import (
	"errors"
	"fmt"
	"io"
	"os"
	"strings"

	"gopkg.in/yaml.v2"
)

// Document represents a generic configuration document in a YAML stream.
type Document struct {
	Kind string                 `yaml:"kind"`
	Name string                 `yaml:"name"`
	Spec map[string]interface{} `yaml:"spec,omitempty"`
}

// DecodeStream parses multiple YAML documents from an io.Reader.
func DecodeStream(r io.Reader) ([]Document, error) {
	dec := yaml.NewDecoder(r)
	var docs []Document

	for {
		var doc Document
		err := dec.Decode(&doc)
		if errors.Is(err, io.EOF) {
			break
		}
		if err != nil {
			return nil, fmt.Errorf("failed to decode document: %w", err)
		}
		docs = append(docs, doc)
	}

	return docs, nil
}

func main() {
	sampleStream := `---
kind: Service
name: web-api
spec:
  port: 8080
---
kind: ConfigMap
name: app-settings
spec:
  environment: production
`
	docs, err := DecodeStream(strings.NewReader(sampleStream))
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error: %v\n", err)
		os.Exit(1)
	}

	for i, doc := range docs {
		fmt.Printf("Document %d: kind=%s, name=%s\n", i+1, doc.Kind, doc.Name)
	}
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/gopkg.in/yaml.v2@v2.3.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/gopkg.in/yaml.v2@v2.3.0"
  ],
  "symbols": [
    "yaml.NewDecoder"
  ]
}
test/contract.go
package main

import (
	"errors"
	"fmt"
	"io"
	"os"
	"strings"

	"gopkg.in/yaml.v2"
)

type Config struct {
	Name  string `yaml:"name"`
	Port  int    `yaml:"port"`
	Debug bool   `yaml:"debug,omitempty"`
}

func main() {
	// Assertion 1: yaml.NewDecoder decodes multiple YAML documents sequentially from an io.Reader
	multiDocYAML := `---
name: service-alpha
port: 8081
debug: true
---
name: service-beta
port: 9091
debug: false
`
	dec := yaml.NewDecoder(strings.NewReader(multiDocYAML))
	var docs []Config

	for {
		var c Config
		err := dec.Decode(&c)
		if errors.Is(err, io.EOF) {
			break
		}
		if err != nil {
			fmt.Fprintf(os.Stderr, "FAIL: unexpected decode error: %v\n", err)
			os.Exit(1)
		}
		docs = append(docs, c)
	}

	if len(docs) != 2 {
		fmt.Fprintf(os.Stderr, "FAIL: expected 2 documents, got %d\n", len(docs))
		os.Exit(1)
	}
	if docs[0].Name != "service-alpha" || docs[0].Port != 8081 || !docs[0].Debug {
		fmt.Fprintf(os.Stderr, "FAIL: doc[0] mismatch: %+v\n", docs[0])
		os.Exit(1)
	}
	if docs[1].Name != "service-beta" || docs[1].Port != 9091 || docs[1].Debug {
		fmt.Fprintf(os.Stderr, "FAIL: doc[1] mismatch: %+v\n", docs[1])
		os.Exit(1)
	}

	// Assertion 2: yaml.NewDecoder returns io.EOF after decoding all documents in a stream
	emptyStream := strings.NewReader("")
	emptyDec := yaml.NewDecoder(emptyStream)
	var dummy Config
	if err := emptyDec.Decode(&dummy); !errors.Is(err, io.EOF) {
		fmt.Fprintf(os.Stderr, "FAIL: expected io.EOF on empty stream, got: %v\n", err)
		os.Exit(1)
	}

	// Assertion 3: yaml.NewDecoder with SetStrict(true) returns TypeError when input contains unknown fields
	strictYAML := `name: service-gamma
port: 7071
unexpected_key: 12345
`
	strictDec := yaml.NewDecoder(strings.NewReader(strictYAML))
	strictDec.SetStrict(true)
	var strictConfig Config
	strictErr := strictDec.Decode(&strictConfig)
	if strictErr == nil {
		fmt.Fprintf(os.Stderr, "FAIL: expected TypeError for unknown field with SetStrict(true), got nil\n")
		os.Exit(1)
	}
	var typeErr *yaml.TypeError
	if !errors.As(strictErr, &typeErr) {
		fmt.Fprintf(os.Stderr, "FAIL: expected *yaml.TypeError, got: %T (%v)\n", strictErr, strictErr)
		os.Exit(1)
	}

	// Assertion 4: yaml.NewDecoder returns an error when encountering malformed YAML syntax
	malformedYAML := `name: [unclosed sequence`
	malformedDec := yaml.NewDecoder(strings.NewReader(malformedYAML))
	var malformedConfig Config
	if err := malformedDec.Decode(&malformedConfig); err == nil {
		fmt.Fprintf(os.Stderr, "FAIL: expected error on malformed YAML, got nil\n")
		os.Exit(1)
	}

	fmt.Println("PASS: pkg:golang/gopkg.in/yaml.v2@v2.3.0 contract passed")
}

Origin Seeder

anonymous