Sample
gopkg.in/yaml.v2 v2.3.0: yaml.NewEncoder
Verified sample for golang gopkg.in/yaml.v2 v2.3.0: yaml.NewEncoder. The contract ran on go 1.26 · linux debian/x64 · docker and passed.
sha256:f708ce68278e3e5e047d9c6403e27ec805b59e6e6698363a9e00e1a66f463384
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
go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1
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 yaml.NewEncoder in pkg:golang/gopkg.in/yaml.v2@v2.3.0
- Packages
- Symbols
-
- yaml.NewEncoder
- Environment
- go 1.26.6
- Created
- 2026-09-04T21:54:36Z
Contract
- yaml.NewEncoder encodes Go structs into YAML output and flushes on Close
- yaml.NewEncoder encodes multiple documents sequentially separated by document markers
- yaml.NewEncoder respects struct field tags for custom keys and omitempty behavior
- yaml.NewEncoder returns an error when writing to an error-returning io.Writer
Files
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Source
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 yaml.NewEncoder in 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.NewEncoder
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.
{"case":{"caseId":"case:sha256:ef8dcd2cb9dd0a6907d1a06ce2d5b0c2a2b28f06fb15d677af483290bdfac366","contract":["yaml.NewEncoder encodes Go structs into YAML output and flushes on Close","yaml.NewEncoder encodes multiple documents sequentially separated by document markers","yaml.NewEncoder respects struct field tags for custom keys and omitempty behavior","yaml.NewEncoder returns an error when writing to an error-returning io.Writer"],"goal":"verify yaml.NewEncoder in 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.NewEncoder"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","packageManagerVersion":"1.26.6","runtime":"go","runtimeVersion":"1.26.6","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.NewEncoder"],"verifierAdapter":"golang@1"}
module sample
go 1.22.0
require gopkg.in/yaml.v2 v2.3.0
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=
package main
import (
"bytes"
"fmt"
"os"
"gopkg.in/yaml.v2"
)
// Config holds sample service configuration.
type Config struct {
AppName string `yaml:"app_name"`
Port int `yaml:"port"`
Tags []string `yaml:"tags,omitempty"`
}
func main() {
var buf bytes.Buffer
enc := yaml.NewEncoder(&buf)
cfg1 := Config{
AppName: "sample-service",
Port: 8080,
Tags: []string{"web", "production"},
}
if err := enc.Encode(cfg1); err != nil {
fmt.Fprintf(os.Stderr, "failed to encode doc 1: %v\n", err)
os.Exit(1)
}
cfg2 := Config{
AppName: "worker-service",
Port: 9090,
}
if err := enc.Encode(cfg2); err != nil {
fmt.Fprintf(os.Stderr, "failed to encode doc 2: %v\n", err)
os.Exit(1)
}
if err := enc.Close(); err != nil {
fmt.Fprintf(os.Stderr, "failed to close encoder: %v\n", err)
os.Exit(1)
}
fmt.Println("Successfully encoded multiple YAML documents:")
fmt.Print(buf.String())
}
{
"schemaVersion": 1,
"goal": "verify yaml.NewEncoder in pkg:golang/gopkg.in/yaml.v2@v2.3.0",
"kind": "HOW",
"packages": [
"pkg:golang/gopkg.in/yaml.v2@v2.3.0"
],
"symbols": [
"yaml.NewEncoder"
]
}
package main
import (
"bytes"
"fmt"
"os"
"strings"
"gopkg.in/yaml.v2"
)
type testConfig struct {
Title string `yaml:"title"`
Port int `yaml:"port"`
}
type taggedItem struct {
VisibleName string `yaml:"custom_name"`
Ignored string `yaml:"-"`
OmitIfEmpty string `yaml:"optional_field,omitempty"`
}
type failingWriter struct{}
func (failingWriter) Write([]byte) (int, error) {
return 0, fmt.Errorf("mock write failure")
}
func main() {
// Assertion 1: yaml.NewEncoder encodes Go structs into YAML output and flushes on Close
{
var buf bytes.Buffer
enc := yaml.NewEncoder(&buf)
item := testConfig{
Title: "Test Service",
Port: 8080,
}
if err := enc.Encode(item); err != nil {
fmt.Fprintf(os.Stderr, "assertion 1 failed: encode error: %v\n", err)
os.Exit(1)
}
if err := enc.Close(); err != nil {
fmt.Fprintf(os.Stderr, "assertion 1 failed: close error: %v\n", err)
os.Exit(1)
}
expected := "title: Test Service\nport: 8080\n"
if buf.String() != expected {
fmt.Fprintf(os.Stderr, "assertion 1 failed: expected %q, got %q\n", expected, buf.String())
os.Exit(1)
}
}
// Assertion 2: yaml.NewEncoder encodes multiple documents sequentially separated by document markers
{
var buf bytes.Buffer
enc := yaml.NewEncoder(&buf)
doc1 := map[string]string{"name": "first"}
doc2 := map[string]string{"name": "second"}
if err := enc.Encode(doc1); err != nil {
fmt.Fprintf(os.Stderr, "assertion 2 failed: encode doc1 error: %v\n", err)
os.Exit(1)
}
if err := enc.Encode(doc2); err != nil {
fmt.Fprintf(os.Stderr, "assertion 2 failed: encode doc2 error: %v\n", err)
os.Exit(1)
}
if err := enc.Close(); err != nil {
fmt.Fprintf(os.Stderr, "assertion 2 failed: close error: %v\n", err)
os.Exit(1)
}
expected := "name: first\n---\nname: second\n"
if buf.String() != expected {
fmt.Fprintf(os.Stderr, "assertion 2 failed: expected %q, got %q\n", expected, buf.String())
os.Exit(1)
}
}
// Assertion 3: yaml.NewEncoder respects struct field tags for custom keys and omitempty behavior
{
var buf bytes.Buffer
enc := yaml.NewEncoder(&buf)
val := taggedItem{
VisibleName: "hello",
Ignored: "secret",
OmitIfEmpty: "",
}
if err := enc.Encode(val); err != nil {
fmt.Fprintf(os.Stderr, "assertion 3 failed: encode error: %v\n", err)
os.Exit(1)
}
if err := enc.Close(); err != nil {
fmt.Fprintf(os.Stderr, "assertion 3 failed: close error: %v\n", err)
os.Exit(1)
}
expected := "custom_name: hello\n"
if buf.String() != expected {
fmt.Fprintf(os.Stderr, "assertion 3 failed: expected %q, got %q\n", expected, buf.String())
os.Exit(1)
}
}
// Assertion 4: yaml.NewEncoder returns an error when writing to an error-returning io.Writer
{
enc := yaml.NewEncoder(failingWriter{})
err := enc.Encode(map[string]string{"key": "value"})
if err == nil {
fmt.Fprintf(os.Stderr, "assertion 4 failed: expected write error, got nil\n")
os.Exit(1)
}
if !strings.Contains(err.Error(), "mock write failure") {
fmt.Fprintf(os.Stderr, "assertion 4 failed: expected error containing 'mock write failure', got %q\n", err.Error())
os.Exit(1)
}
}
fmt.Println("All contract assertions passed successfully.")
}
Origin Seeder
anonymous