CodeSampleX

Sample

github.com/go-logfmt/logfmt v0.6.0: MarshalKeyvals

Verified sample for golang github.com/go-logfmt/logfmt v0.6.0: MarshalKeyvals. The contract ran on go 1.26 · linux debian/x64 · docker and passed.

sha256:ee05189aefb62b07f0d1f354f99c3d41242f54e0fd6417c54f7e9ed310d8aeb6

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 amd64 go 1.26 go 1.26 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-02

Case

HOW
Goal
verify logfmt.MarshalKeyvals in pkg:golang/github.com/go-logfmt/logfmt@v0.6.0
Packages
Symbols
  • logfmt.MarshalKeyvals
Environment
go 1.26.6
Created
2026-09-02T01:50:00Z

Contract

  1. logfmt.MarshalKeyvals encodes alternating key-value pairs into logfmt format
  2. logfmt.MarshalKeyvals quotes string values containing whitespace and escapes inner quotes
  3. logfmt.MarshalKeyvals encodes empty string values as key= without quotes
  4. logfmt.MarshalKeyvals encodes nil values and trailing odd keys as key=null
  5. logfmt.MarshalKeyvals formats fmt.Stringer and error values and fmt.Stringer keys
  6. logfmt.MarshalKeyvals strips invalid characters from keys
  7. logfmt.MarshalKeyvals returns logfmt.ErrNilKey when nil key is provided

Files

  • PROMPT.md
  • contract_test.go
  • csx.json
  • go.mod
  • go.sum
  • sample.go
  • spec.json

Download the source artifact (tar.gz)

Source

PROMPT.md
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.
contract_test.go
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)
	}
}
csx.json
{"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"}
go.mod
module example.com/sample

go 1.26.6

require github.com/go-logfmt/logfmt v0.6.0
go.sum
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
sample.go
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...)
}
spec.json
{
  "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"
  ]
}

Origin Seeder

anonymous