샘플
go.yaml.in/yaml/v2 v2.4.4: Marshal
검증된 샘플 — golang go.yaml.in/yaml/v2 v2.4.4: Marshal. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: yaml.Marshal serializes primitive types…
sha256:e060b232d5c642a6ff7c49e93028c235f1ec0f5adeeb667d3d78b7c350689091
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
linux 24 · ubuntu · glibc 2.39 x64 go 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-06 |
케이스
HOW- 목표
- verify go.yaml.in/yaml/v2.Marshal in pkg:golang/go.yaml.in/yaml/v2@v2.4.4
- 심벌
-
- go.yaml.in/yaml/v2.Marshal
- 생성일
- 2026-09-06T13:02:29Z
컨트랙트
- yaml.Marshal serializes primitive types, structs, slices, and maps into standard YAML
- yaml.Marshal respects struct field tags for custom key names, omitempty, and ignored fields
- yaml.Marshal supports inlining embedded structs using the inline tag
- yaml.Marshal applies flow style to collections when flow tag is present
- yaml.Marshal invokes MarshalYAML on types implementing the Marshaler interface
- yaml.Marshal propagates errors returned by types implementing the Marshaler interface
파일
- PROMPT.md
- csx.json
- go.mod
- go.sum
- 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 go.yaml.in/yaml/v2.Marshal in pkg:golang/go.yaml.in/yaml/v2@v2.4.4
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/go.yaml.in/yaml/v2@v2.4.4
Demonstrate these symbols/APIs:
- go.yaml.in/yaml/v2.Marshal
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:ca4122add92a100006b1ba89a9dfdf0b3cb55a2a70bab285ddcbf7026b42a2f2","contract":["yaml.Marshal serializes primitive types, structs, slices, and maps into standard YAML","yaml.Marshal respects struct field tags for custom key names, omitempty, and ignored fields","yaml.Marshal supports inlining embedded structs using the inline tag","yaml.Marshal applies flow style to collections when flow tag is present","yaml.Marshal invokes MarshalYAML on types implementing the Marshaler interface","yaml.Marshal propagates errors returned by types implementing the Marshaler interface"],"goal":"verify go.yaml.in/yaml/v2.Marshal in pkg:golang/go.yaml.in/yaml/v2@v2.4.4","kind":"HOW","packages":["pkg:golang/go.yaml.in/yaml/v2@v2.4.4"],"schemaVersion":1,"symbols":["go.yaml.in/yaml/v2.Marshal"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/go.yaml.in/yaml/v2@v2.4.4"],"schemaVersion":1,"subject":"pkg:golang/go.yaml.in/yaml/v2@v2.4.4","symbols":["go.yaml.in/yaml/v2.Marshal"],"verifierAdapter":"golang@1"}
module example.com/sample
go 1.26.6
require go.yaml.in/yaml/v2 v2.4.4
go.yaml.in/yaml/v2 v2.4.4 h1:tuyd0P+2Ont/d6e2rl3be67goVK4R6deVxCUX5vyPaQ=
go.yaml.in/yaml/v2 v2.4.4/go.mod h1:gMZqIpDtDqOfM0uNfy0SkpRhvUryYH0Z6wdMYcacYXQ=
{
"schemaVersion": 1,
"goal": "verify go.yaml.in/yaml/v2.Marshal in pkg:golang/go.yaml.in/yaml/v2@v2.4.4",
"kind": "HOW",
"packages": [
"pkg:golang/go.yaml.in/yaml/v2@v2.4.4"
],
"symbols": [
"go.yaml.in/yaml/v2.Marshal"
]
}
package main
import (
"fmt"
"os"
"strings"
yaml "go.yaml.in/yaml/v2"
)
// 1. Types for testing basic serialization and struct tags
type ServerConfig struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
Active bool `yaml:"active"`
Labels []string `yaml:"labels,omitempty"`
Settings map[string]string `yaml:"settings,omitempty"`
SecretKey string `yaml:"-"`
CustomName string `yaml:"service_name"`
}
// 2. Types for inline tag testing
type BaseMetadata struct {
Version string `yaml:"version"`
}
type ServiceDefinition struct {
Name string `yaml:"name"`
BaseMetadata `yaml:",inline"`
}
// 3. Types for flow style testing
type FlowConfig struct {
Endpoints []string `yaml:"endpoints,flow"`
}
// 4. Types for custom Marshaler interface testing
type StatusValue struct {
code int
}
func (s StatusValue) MarshalYAML() (interface{}, error) {
switch s.code {
case 200:
return "OK", nil
case 404:
return "NOT_FOUND", nil
default:
return nil, fmt.Errorf("invalid status code: %d", s.code)
}
}
type StatusReport struct {
Status StatusValue `yaml:"status"`
}
func main() {
if err := runContractTests(); err != nil {
fmt.Fprintf(os.Stderr, "Contract test failed: %v\n", err)
os.Exit(1)
}
fmt.Println("All contract tests passed.")
}
func runContractTests() error {
// 1. yaml.Marshal serializes primitive types, structs, slices, and maps into standard YAML
cfg := ServerConfig{
Host: "127.0.0.1",
Port: 8080,
Active: true,
Labels: []string{"web", "prod"},
Settings: map[string]string{"timeout": "30s", "mode": "fast"},
SecretKey: "supersecret",
CustomName: "api-service",
}
out, err := yaml.Marshal(&cfg)
if err != nil {
return fmt.Errorf("yaml.Marshal basic failed: %w", err)
}
yamlStr := string(out)
if !strings.Contains(yamlStr, "host: 127.0.0.1") ||
!strings.Contains(yamlStr, "port: 8080") ||
!strings.Contains(yamlStr, "active: true") {
return fmt.Errorf("yaml.Marshal output missing scalar fields: %s", yamlStr)
}
// 2. yaml.Marshal respects struct field tags for custom key names, omitempty, and ignored fields
if !strings.Contains(yamlStr, "service_name: api-service") {
return fmt.Errorf("custom key tag failed: %s", yamlStr)
}
if strings.Contains(yamlStr, "supersecret") || strings.Contains(yamlStr, "SecretKey") {
return fmt.Errorf("ignored field '-' was included: %s", yamlStr)
}
// Verify omitempty
emptyCfg := ServerConfig{
Host: "localhost",
Port: 9000,
Active: false,
CustomName: "test-service",
}
emptyOut, err := yaml.Marshal(&emptyCfg)
if err != nil {
return fmt.Errorf("yaml.Marshal empty failed: %w", err)
}
emptyStr := string(emptyOut)
if strings.Contains(emptyStr, "labels:") || strings.Contains(emptyStr, "settings:") {
return fmt.Errorf("omitempty failed, empty fields present: %s", emptyStr)
}
// 3. yaml.Marshal supports inlining embedded structs using the inline tag
svc := ServiceDefinition{
Name: "auth",
BaseMetadata: BaseMetadata{
Version: "v1.2.3",
},
}
inlineOut, err := yaml.Marshal(&svc)
if err != nil {
return fmt.Errorf("yaml.Marshal inline failed: %w", err)
}
inlineStr := string(inlineOut)
if !strings.Contains(inlineStr, "name: auth") || !strings.Contains(inlineStr, "version: v1.2.3") {
return fmt.Errorf("inline tag failed: %s", inlineStr)
}
if strings.Contains(inlineStr, "basemetadata:") {
return fmt.Errorf("inline field was nested: %s", inlineStr)
}
// 4. yaml.Marshal applies flow style to collections when flow tag is present
flowCfg := FlowConfig{
Endpoints: []string{"api1", "api2"},
}
flowOut, err := yaml.Marshal(&flowCfg)
if err != nil {
return fmt.Errorf("yaml.Marshal flow failed: %w", err)
}
flowStr := string(flowOut)
if !strings.Contains(flowStr, "endpoints: [api1, api2]") {
return fmt.Errorf("flow tag failed: %s", flowStr)
}
// 5. yaml.Marshal invokes MarshalYAML on types implementing the Marshaler interface
rep := StatusReport{
Status: StatusValue{code: 200},
}
repOut, err := yaml.Marshal(&rep)
if err != nil {
return fmt.Errorf("yaml.Marshal custom Marshaler failed: %w", err)
}
if !strings.Contains(string(repOut), "status: OK") {
return fmt.Errorf("custom Marshaler failed: %s", string(repOut))
}
// 6. yaml.Marshal propagates errors returned by types implementing the Marshaler interface
repErr := StatusReport{
Status: StatusValue{code: 500},
}
if _, err := yaml.Marshal(&repErr); err == nil {
return fmt.Errorf("expected error from custom Marshaler, got nil")
}
// Verify roundtrip fidelity with a map to ensure valid YAML produced
var parsed map[string]interface{}
if err := yaml.Unmarshal(out, &parsed); err != nil {
return fmt.Errorf("unmarshaling generated YAML failed: %w", err)
}
if parsed["service_name"] != "api-service" {
return fmt.Errorf("roundtrip key check failed: %v", parsed)
}
return nil
}
오리진 시더
익명