샘플
gopkg.in/yaml.v2 v2.3.0: yaml.Encoder
검증된 샘플 — golang gopkg.in/yaml.v2 v2.3.0: yaml.Encoder. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: yaml.NewEncoder writes serialized YAML…
sha256:0af4fb50dcdd3e5976a44009113154cbeb34028b35d96c519f2d7092e97dfe5b
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
linux 24 · ubuntu · glibc 2.39 x64 go
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| 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 |
케이스
HOW- 목표
- verify yaml.Encoder in pkg:golang/gopkg.in/yaml.v2@v2.3.0
- 심벌
-
- yaml.Encoder
- 생성일
- 2026-09-04T21:48:10Z
컨트랙트
- yaml.NewEncoder writes serialized YAML data to an io.Writer
- yaml.Encoder encodes multiple documents sequentially separated by document markers
- yaml.Encoder encodes struct fields observing yaml struct tags including omitempty and ignored fields
- yaml.Encoder Close flushes output and subsequent Encode calls return an error
파일
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
소스
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.Encoder 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.Encoder
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:0fc79444eaa7b964f09001a7bbf69136c75877747960f835afb2d2fe1b36ec88","contract":["yaml.NewEncoder writes serialized YAML data to an io.Writer","yaml.Encoder encodes multiple documents sequentially separated by document markers","yaml.Encoder encodes struct fields observing yaml struct tags including omitempty and ignored fields","yaml.Encoder Close flushes output and subsequent Encode calls return an error"],"goal":"verify yaml.Encoder 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.Encoder"]},"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.Encoder"],"verifierAdapter":"golang@1"}
module example.com/sample
go 1.26.6
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"
"io"
"os"
"gopkg.in/yaml.v2"
)
// Document represents a generic configuration entry to encode into YAML.
type Document struct {
Kind string `yaml:"kind"`
Name string `yaml:"name"`
Metadata map[string]string `yaml:"metadata,omitempty"`
}
// EncodeDocuments serializes multiple Document values to the destination writer using yaml.Encoder.
func EncodeDocuments(w io.Writer, docs []Document) error {
enc := yaml.NewEncoder(w)
defer enc.Close()
for _, doc := range docs {
if err := enc.Encode(doc); err != nil {
return fmt.Errorf("failed to encode document: %w", err)
}
}
return nil
}
func main() {
docs := []Document{
{
Kind: "Service",
Name: "web-server",
Metadata: map[string]string{
"env": "production",
},
},
{
Kind: "ConfigMap",
Name: "app-config",
},
}
var buf bytes.Buffer
if err := EncodeDocuments(&buf, docs); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
fmt.Print(buf.String())
}
{
"schemaVersion": 1,
"goal": "verify yaml.Encoder in pkg:golang/gopkg.in/yaml.v2@v2.3.0",
"kind": "HOW",
"packages": [
"pkg:golang/gopkg.in/yaml.v2@v2.3.0"
],
"symbols": [
"yaml.Encoder"
]
}
package main
import (
"bytes"
"fmt"
"os"
"strings"
"gopkg.in/yaml.v2"
)
type ResourceConfig struct {
Title string `yaml:"title"`
Port int `yaml:"port"`
Tags []string `yaml:"tags,omitempty"`
Secret string `yaml:"-"`
}
func main() {
// Assertion 1: yaml.NewEncoder writes serialized YAML data to an io.Writer
var buf1 bytes.Buffer
enc1 := yaml.NewEncoder(&buf1)
item := ResourceConfig{
Title: "web",
Port: 8080,
}
if err := enc1.Encode(item); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: assertion 1 encode failed: %v\n", err)
os.Exit(1)
}
if err := enc1.Close(); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: assertion 1 close failed: %v\n", err)
os.Exit(1)
}
expectedSingle := "title: web\nport: 8080\n"
if buf1.String() != expectedSingle {
fmt.Fprintf(os.Stderr, "FAIL: assertion 1 expected %q, got %q\n", expectedSingle, buf1.String())
os.Exit(1)
}
// Assertion 2: yaml.Encoder encodes multiple documents sequentially separated by document markers
var buf2 bytes.Buffer
enc2 := yaml.NewEncoder(&buf2)
doc1 := map[string]string{"name": "doc1"}
doc2 := map[string]string{"name": "doc2"}
if err := enc2.Encode(doc1); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: assertion 2 encode doc1 failed: %v\n", err)
os.Exit(1)
}
if err := enc2.Encode(doc2); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: assertion 2 encode doc2 failed: %v\n", err)
os.Exit(1)
}
if err := enc2.Close(); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: assertion 2 close failed: %v\n", err)
os.Exit(1)
}
expectedMulti := "name: doc1\n---\nname: doc2\n"
if buf2.String() != expectedMulti {
fmt.Fprintf(os.Stderr, "FAIL: assertion 2 expected %q, got %q\n", expectedMulti, buf2.String())
os.Exit(1)
}
// Assertion 3: yaml.Encoder encodes struct fields observing yaml struct tags including omitempty and ignored fields
var buf3 bytes.Buffer
enc3 := yaml.NewEncoder(&buf3)
tagged := ResourceConfig{
Title: "gateway",
Port: 443,
Tags: nil,
Secret: "do-not-serialize",
}
if err := enc3.Encode(tagged); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: assertion 3 encode failed: %v\n", err)
os.Exit(1)
}
if err := enc3.Close(); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: assertion 3 close failed: %v\n", err)
os.Exit(1)
}
out3 := buf3.String()
if strings.Contains(out3, "secret") || strings.Contains(out3, "do-not-serialize") {
fmt.Fprintf(os.Stderr, "FAIL: assertion 3 secret was not ignored: %s\n", out3)
os.Exit(1)
}
if strings.Contains(out3, "tags") {
fmt.Fprintf(os.Stderr, "FAIL: assertion 3 empty tags was not omitted: %s\n", out3)
os.Exit(1)
}
if !strings.Contains(out3, "title: gateway") || !strings.Contains(out3, "port: 443") {
fmt.Fprintf(os.Stderr, "FAIL: assertion 3 expected fields missing: %s\n", out3)
os.Exit(1)
}
// Assertion 4: yaml.Encoder Close flushes output and subsequent Encode calls return an error
var buf4 bytes.Buffer
enc4 := yaml.NewEncoder(&buf4)
if err := enc4.Encode(map[string]string{"status": "ok"}); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: assertion 4 initial encode failed: %v\n", err)
os.Exit(1)
}
if err := enc4.Close(); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: assertion 4 close failed: %v\n", err)
os.Exit(1)
}
errAfterClose := enc4.Encode(map[string]string{"status": "another"})
if errAfterClose == nil {
fmt.Fprintf(os.Stderr, "FAIL: assertion 4 expected error encoding after close, got nil\n")
os.Exit(1)
}
fmt.Println("PASS: yaml.Encoder contract passed")
}
오리진 시더
익명