CodeSampleX

Sample

go.uber.org/zap v1.13.0

Verified sample for golang go.uber.org/zap v1.13.0. The contract ran on go 1.26 · linux debian/x64 · docker and passed: CreateDynamicLevelLogger creates a…

sha256:be91388d50916e3c79b86e671188a586d01930c25111339ef47cd7820421e8b5

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 linux 24 · ubuntu · glibc 2.39 x64 go

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-15

Case

HOW
Goal
verify pkg:golang/go.uber.org/zap@v1.13.0
Packages
Created
2026-09-15T21:18:49Z

Contract

  1. CreateDynamicLevelLogger creates a zap.Logger configured with an AtomicLevel threshold and buffer output
  2. SetLevel dynamically updates the active log level threshold at runtime
  3. LogMessages emits log entries filtered according to the current AtomicLevel threshold

Files

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • sample.go
  • spec.json
  • test/contract.go

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 pkg:golang/go.uber.org/zap@v1.13.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/go.uber.org/zap@v1.13.0

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.
csx.json
{"case":{"caseId":"case:sha256:1c19b02404d6bd8f75adf5ae93d4b5340f4293787874cffc86d2c01207915238","contract":["CreateDynamicLevelLogger creates a zap.Logger configured with an AtomicLevel threshold and buffer output","SetLevel dynamically updates the active log level threshold at runtime","LogMessages emits log entries filtered according to the current AtomicLevel threshold"],"goal":"verify pkg:golang/go.uber.org/zap@v1.13.0","kind":"HOW","packages":["pkg:golang/go.uber.org/zap@v1.13.0"],"schemaVersion":1,"symbols":["go.uber.org/zap.NewAtomicLevelAt","go.uber.org/zap.AtomicLevel","go.uber.org/zap.AtomicLevel.SetLevel","go.uber.org/zap.AtomicLevel.Level","go.uber.org/zap/zapcore.NewCore","go.uber.org/zap/zapcore.NewJSONEncoder","go.uber.org/zap/zapcore.AddSync","go.uber.org/zap/zapcore.DebugLevel","go.uber.org/zap/zapcore.InfoLevel","go.uber.org/zap/zapcore.WarnLevel","go.uber.org/zap.New","go.uber.org/zap.Logger.Debug","go.uber.org/zap.Logger.Info","go.uber.org/zap.Logger.Warn"]},"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/go.uber.org/zap@v1.13.0"],"schemaVersion":1,"subject":"pkg:golang/go.uber.org/zap@v1.13.0","verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.22.0

require go.uber.org/zap v1.13.0

require (
	github.com/BurntSushi/toml v0.3.1 // indirect
	go.uber.org/atomic v1.5.0 // indirect
	go.uber.org/multierr v1.3.0 // indirect
	go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee // indirect
	golang.org/x/lint v0.0.0-20190930215403-16217165b5de // indirect
	golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5 // indirect
	honnef.co/go/tools v0.0.1-2019.2.3 // indirect
)
go.sum
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
go.uber.org/atomic v1.5.0 h1:OI5t8sDa1Or+q8AeE+yKeB/SDYioSHAgcVljj9JIETY=
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/multierr v1.3.0 h1:sFPn2GLc3poCkfrpIXGhBD2X0CMIo4Q/zSULXrj/+uc=
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
go.uber.org/zap v1.13.0 h1:nR6NoDBgAf67s68NhaXbsojM+2gxp3S1hWkHDl27pVU=
go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5 h1:hKsoRgsbwY1NafxrwTs+k64bikrLBkAgPir1TNCj3Zs=
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM=
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
sample.go
package sample

import (
	"bytes"

	"go.uber.org/zap"
	"go.uber.org/zap/zapcore"
)

// DynamicLogger encapsulates a zap.Logger and its AtomicLevel controller.
type DynamicLogger struct {
	Logger *zap.Logger
	Level  zap.AtomicLevel
}

// CreateDynamicLevelLogger initializes a zap.Logger with a dynamically adjustable AtomicLevel.
func CreateDynamicLevelLogger(buf *bytes.Buffer, initialLevel zapcore.Level) *DynamicLogger {
	atom := zap.NewAtomicLevelAt(initialLevel)
	encoderCfg := zapcore.EncoderConfig{
		MessageKey:     "msg",
		LevelKey:       "level",
		NameKey:        "logger",
		EncodeLevel:    zapcore.LowercaseLevelEncoder,
		EncodeTime:     zapcore.ISO8601TimeEncoder,
		EncodeDuration: zapcore.StringDurationEncoder,
	}
	core := zapcore.NewCore(
		zapcore.NewJSONEncoder(encoderCfg),
		zapcore.AddSync(buf),
		atom,
	)
	logger := zap.New(core)
	return &DynamicLogger{
		Logger: logger,
		Level:  atom,
	}
}

// SetLevel dynamically modifies the minimum logging level threshold at runtime.
func (d *DynamicLogger) SetLevel(level zapcore.Level) {
	d.Level.SetLevel(level)
}

// GetLevel returns the current logging level threshold.
func (d *DynamicLogger) GetLevel() zapcore.Level {
	return d.Level.Level()
}

// LogMessages logs debug, info, and warn messages to demonstrate level filtering.
func (d *DynamicLogger) LogMessages(debugMsg, infoMsg, warnMsg string) {
	if d.Logger != nil {
		d.Logger.Debug(debugMsg)
		d.Logger.Info(infoMsg)
		d.Logger.Warn(warnMsg)
	}
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/go.uber.org/zap@v1.13.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/go.uber.org/zap@v1.13.0"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"os"

	"example.com/sample"
	"go.uber.org/zap/zapcore"
)

type logEntry struct {
	Level string `json:"level"`
	Msg   string `json:"msg"`
}

func parseEntries(buf *bytes.Buffer) ([]logEntry, error) {
	var entries []logEntry
	decoder := json.NewDecoder(buf)
	for decoder.More() {
		var entry logEntry
		if err := decoder.Decode(&entry); err != nil {
			return nil, err
		}
		entries = append(entries, entry)
	}
	return entries, nil
}

func main() {
	var buf bytes.Buffer

	// 1. Initialized at InfoLevel: Debug messages should be omitted, Info and Warn should be present
	dynLogger := sample.CreateDynamicLevelLogger(&buf, zapcore.InfoLevel)
	if dynLogger == nil || dynLogger.Logger == nil {
		fmt.Fprintf(os.Stderr, "expected non-nil dynamic logger\n")
		os.Exit(1)
	}

	if dynLogger.GetLevel() != zapcore.InfoLevel {
		fmt.Fprintf(os.Stderr, "expected initial level InfoLevel, got %v\n", dynLogger.GetLevel())
		os.Exit(1)
	}

	dynLogger.LogMessages("debug message 1", "info message 1", "warn message 1")

	entries, err := parseEntries(&buf)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to decode log entries: %v\n", err)
		os.Exit(1)
	}

	if len(entries) != 2 {
		fmt.Fprintf(os.Stderr, "expected 2 entries at InfoLevel, got %d\n", len(entries))
		os.Exit(1)
	}
	if entries[0].Level != "info" || entries[0].Msg != "info message 1" {
		fmt.Fprintf(os.Stderr, "unexpected entry 0: %+v\n", entries[0])
		os.Exit(1)
	}
	if entries[1].Level != "warn" || entries[1].Msg != "warn message 1" {
		fmt.Fprintf(os.Stderr, "unexpected entry 1: %+v\n", entries[1])
		os.Exit(1)
	}

	// 2. Change level dynamically to DebugLevel: Debug, Info, and Warn messages should all be captured
	buf.Reset()
	dynLogger.SetLevel(zapcore.DebugLevel)
	if dynLogger.GetLevel() != zapcore.DebugLevel {
		fmt.Fprintf(os.Stderr, "expected dynamic level DebugLevel, got %v\n", dynLogger.GetLevel())
		os.Exit(1)
	}

	dynLogger.LogMessages("debug message 2", "info message 2", "warn message 2")

	entries, err = parseEntries(&buf)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to decode log entries: %v\n", err)
		os.Exit(1)
	}

	if len(entries) != 3 {
		fmt.Fprintf(os.Stderr, "expected 3 entries at DebugLevel, got %d\n", len(entries))
		os.Exit(1)
	}
	if entries[0].Level != "debug" || entries[0].Msg != "debug message 2" {
		fmt.Fprintf(os.Stderr, "unexpected entry 0: %+v\n", entries[0])
		os.Exit(1)
	}
	if entries[1].Level != "info" || entries[1].Msg != "info message 2" {
		fmt.Fprintf(os.Stderr, "unexpected entry 1: %+v\n", entries[1])
		os.Exit(1)
	}
	if entries[2].Level != "warn" || entries[2].Msg != "warn message 2" {
		fmt.Fprintf(os.Stderr, "unexpected entry 2: %+v\n", entries[2])
		os.Exit(1)
	}

	// 3. Change level dynamically to WarnLevel: only Warn should be captured
	buf.Reset()
	dynLogger.SetLevel(zapcore.WarnLevel)
	if dynLogger.GetLevel() != zapcore.WarnLevel {
		fmt.Fprintf(os.Stderr, "expected dynamic level WarnLevel, got %v\n", dynLogger.GetLevel())
		os.Exit(1)
	}

	dynLogger.LogMessages("debug message 3", "info message 3", "warn message 3")

	entries, err = parseEntries(&buf)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to decode log entries: %v\n", err)
		os.Exit(1)
	}

	if len(entries) != 1 {
		fmt.Fprintf(os.Stderr, "expected 1 entry at WarnLevel, got %d\n", len(entries))
		os.Exit(1)
	}
	if entries[0].Level != "warn" || entries[0].Msg != "warn message 3" {
		fmt.Fprintf(os.Stderr, "unexpected entry 0: %+v\n", entries[0])
		os.Exit(1)
	}

	fmt.Println("All contracts passed successfully.")
}

Origin Seeder

anonymous