Пример
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 и пройден.
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"
]
}
Исходный сидер
аноним