샘플
github.com/go-logfmt/logfmt v0.6.0: MarshalKeyvals
검증된 샘플 — golang github.com/go-logfmt/logfmt v0.6.0: MarshalKeyvals. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다.
sha256:ee05189aefb62b07f0d1f354f99c3d41242f54e0fd6417c54f7e9ed310d8aeb6
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
go 1.26 linux 24 · ubuntu · glibc 2.39 amd64 go 1.26 go 1.26 go 1
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| 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-02 |
케이스
HOW- 목표
- verify logfmt.MarshalKeyvals in pkg:golang/github.com/go-logfmt/logfmt@v0.6.0
- 심벌
-
- logfmt.MarshalKeyvals
- 환경
- go 1.26.6
- 생성일
- 2026-09-02T01:50:00Z
컨트랙트
- logfmt.MarshalKeyvals encodes alternating key-value pairs into logfmt format
- logfmt.MarshalKeyvals quotes string values containing whitespace and escapes inner quotes
- logfmt.MarshalKeyvals encodes empty string values as key= without quotes
- logfmt.MarshalKeyvals encodes nil values and trailing odd keys as key=null
- logfmt.MarshalKeyvals formats fmt.Stringer and error values and fmt.Stringer keys
- logfmt.MarshalKeyvals strips invalid characters from keys
- logfmt.MarshalKeyvals returns logfmt.ErrNilKey when nil key is provided
파일
- PROMPT.md
- contract_test.go
- csx.json
- go.mod
- go.sum
- sample.go
- spec.json
소스
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 logfmt.MarshalKeyvals in pkg:golang/github.com/go-logfmt/logfmt@v0.6.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/go-logfmt/logfmt@v0.6.0
Demonstrate these symbols/APIs:
- logfmt.MarshalKeyvals
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.
package sample
import (
"errors"
"testing"
"github.com/go-logfmt/logfmt"
)
type stringerType struct {
val string
}
func (s stringerType) String() string {
return s.val
}
func TestContractMarshalKeyvals(t *testing.T) {
// 1. Primitive types serialization
data, err := MarshalKeyValues("msg", "job started", "count", 42, "ratio", 0.95, "active", true)
if err != nil {
t.Fatalf("unexpected error marshaling primitive keyvals: %v", err)
}
expected := `msg="job started" count=42 ratio=0.95 active=true`
if string(data) != expected {
t.Fatalf("expected %q, got %q", expected, string(data))
}
// 2. Value quoting and escaping
data, err = MarshalKeyValues("quote", `hello "world"`)
if err != nil {
t.Fatalf("unexpected error marshaling quoted string: %v", err)
}
expectedQuote := `quote="hello \"world\""`
if string(data) != expectedQuote {
t.Fatalf("expected %q, got %q", expectedQuote, string(data))
}
// 3. Empty string value encodes as key= without quotes
data, err = MarshalKeyValues("empty", "")
if err != nil {
t.Fatalf("unexpected error marshaling empty string: %v", err)
}
if string(data) != "empty=" {
t.Fatalf("expected empty=, got %q", string(data))
}
// 4. Nil value encodes as key=null
data, err = MarshalKeyValues("status", nil)
if err != nil {
t.Fatalf("unexpected error marshaling nil value: %v", err)
}
if string(data) != "status=null" {
t.Fatalf("expected status=null, got %q", string(data))
}
// 5. Odd argument count treats trailing key as key=null
data, err = MarshalKeyValues("standalone")
if err != nil {
t.Fatalf("unexpected error marshaling odd key: %v", err)
}
if string(data) != "standalone=null" {
t.Fatalf("expected standalone=null, got %q", string(data))
}
// 6. fmt.Stringer and error values and keys
data, err = MarshalKeyValues(stringerType{val: "tag"}, stringerType{val: "prod"}, "err", errors.New("timeout reached"))
if err != nil {
t.Fatalf("unexpected error marshaling Stringer and error: %v", err)
}
expectedCustom := `tag=prod err="timeout reached"`
if string(data) != expectedCustom {
t.Fatalf("expected %q, got %q", expectedCustom, string(data))
}
// 7. Invalid characters in keys are stripped
data, err = MarshalKeyValues("key with space", "value", "key=1", "val2")
if err != nil {
t.Fatalf("unexpected error marshaling keys with special chars: %v", err)
}
expectedStripped := "keywithspace=value key1=val2"
if string(data) != expectedStripped {
t.Fatalf("expected %q, got %q", expectedStripped, string(data))
}
// 8. Nil key returns ErrNilKey
_, err = MarshalKeyValues(nil, "value")
if !errors.Is(err, logfmt.ErrNilKey) {
t.Fatalf("expected ErrNilKey for nil key, got %v", err)
}
}
{"case":{"caseId":"case:sha256:da73ca28ac1d74d1e49955ffcc03539b19d014ba61b22c3873fa279c868babea","contract":["logfmt.MarshalKeyvals encodes alternating key-value pairs into logfmt format","logfmt.MarshalKeyvals quotes string values containing whitespace and escapes inner quotes","logfmt.MarshalKeyvals encodes empty string values as key= without quotes","logfmt.MarshalKeyvals encodes nil values and trailing odd keys as key=null","logfmt.MarshalKeyvals formats fmt.Stringer and error values and fmt.Stringer keys","logfmt.MarshalKeyvals strips invalid characters from keys","logfmt.MarshalKeyvals returns logfmt.ErrNilKey when nil key is provided"],"goal":"verify logfmt.MarshalKeyvals in pkg:golang/github.com/go-logfmt/logfmt@v0.6.0","kind":"HOW","packages":["pkg:golang/github.com/go-logfmt/logfmt@v0.6.0"],"schemaVersion":1,"symbols":["logfmt.MarshalKeyvals"]},"contractCommand":["go","test","./..."],"environment":{"arch":"amd64","compiler":"go","compilerVersion":"1.26.6","distro":"ubuntu","ecosystem":"golang","language":"go","languageVersion":"1.26.6","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/github.com/go-logfmt/logfmt@v0.6.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/go-logfmt/logfmt@v0.6.0","symbols":["logfmt.MarshalKeyvals"],"verifierAdapter":"golang@1"}
module example.com/sample
go 1.26.6
require github.com/go-logfmt/logfmt v0.6.0
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
package sample
import (
"github.com/go-logfmt/logfmt"
)
// MarshalKeyValues encodes alternating key-value pairs into logfmt structured format.
func MarshalKeyValues(keyvals ...interface{}) ([]byte, error) {
return logfmt.MarshalKeyvals(keyvals...)
}
{
"schemaVersion": 1,
"goal": "verify logfmt.MarshalKeyvals in pkg:golang/github.com/go-logfmt/logfmt@v0.6.0",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/go-logfmt/logfmt@v0.6.0"
],
"symbols": [
"logfmt.MarshalKeyvals"
]
}
오리진 시더
익명