CodeSampleX

Sample

go.uber.org/zap v1.28.0: zapcore.Entry

Verified sample for golang go.uber.org/zap v1.28.0: zapcore.Entry. The contract ran on go 1.26 · linux debian/x64 · docker and passed.

sha256:7f8722176fa8590b505ac632aef8c588636b0f61dbf3a0b89975627b700af4ab

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

Case

HOW
Goal
verify go.uber.org/zap/zapcore.Entry in pkg:golang/go.uber.org/zap@v1.28.0
Packages
Symbols
  • go.uber.org/zap/zapcore.Entry
Created
2026-09-04T14:05:29Z

Contract

  1. zapcore.Entry captures log level, timestamp, logger name, message, caller, and stack trace metadata for downstream encoding.
  2. zapcore.NewEntryCaller formats call site information, returning trimmed relative paths via TrimmedPath and 'undefined' when undefined.
  3. zapcore.CheckedEntry combines an Entry with cores via AddCore and executes PreWriteHooks via Before to modify the Entry and fields before writing.
  4. zapcore.CheckedEntry.Write dispatches the Entry to registered cores and invokes CheckWriteHook callbacks registered via After upon completion.

Files

  • NOTES.md
  • PROMPT.md
  • csx.json
  • entry_test.go
  • go.mod
  • go.sum
  • spec.json

Download the source artifact (tar.gz)

Source

NOTES.md
# zap zapcore.Entry Verification

## Prior Findings
Search for known solutions for `go.uber.org/zap/zapcore.Entry` in `pkg:golang/go.uber.org/zap@v1.28.0` returned `NO_SAFE_MATCH`.
Existing samples covered atomic level switching, in-memory observer logging, and custom sink registration, but did not prove `zapcore.Entry` lifecycle and caller formatting semantics.

## Pinned Release
- `go.uber.org/zap` pinned to `v1.28.0` via `go.mod` and `go.sum`.

## Observed Behaviour
1. `zapcore.Entry` encapsulates core log message metadata (Level, Time, LoggerName, Message, Caller, and Stack) serialized by zap encoders during entry encoding.
2. `zapcore.NewEntryCaller` resolves call site information and formats trimmed relative paths (`TrimmedPath()`) or `undefined` when caller information is missing.
3. `zapcore.CheckedEntry` associates an `Entry` with active `Core` instances and executes `Before` pre-write transformation hooks before dispatching entries.
4. `zapcore.CheckedEntry.Write` dispatches entries and contextual fields to registered cores while triggering registered post-write hooks (`After`).
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 go.uber.org/zap/zapcore.Entry in pkg:golang/go.uber.org/zap@v1.28.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/go.uber.org/zap@v1.28.0
Demonstrate these symbols/APIs:
  - go.uber.org/zap/zapcore.Entry

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:5f51ee4a4b11f8d7fc77e5b43e4caabab0411cead602ac2059d4215f62927017","contract":["zapcore.Entry captures log level, timestamp, logger name, message, caller, and stack trace metadata for downstream encoding.","zapcore.NewEntryCaller formats call site information, returning trimmed relative paths via TrimmedPath and 'undefined' when undefined.","zapcore.CheckedEntry combines an Entry with cores via AddCore and executes PreWriteHooks via Before to modify the Entry and fields before writing.","zapcore.CheckedEntry.Write dispatches the Entry to registered cores and invokes CheckWriteHook callbacks registered via After upon completion."],"goal":"verify go.uber.org/zap/zapcore.Entry in pkg:golang/go.uber.org/zap@v1.28.0","kind":"HOW","packages":["pkg:golang/go.uber.org/zap@v1.28.0"],"schemaVersion":1,"symbols":["go.uber.org/zap/zapcore.Entry"]},"contractCommand":["go","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.28.0"],"schemaVersion":1,"subject":"pkg:golang/go.uber.org/zap@v1.28.0","symbols":["go.uber.org/zap/zapcore.Entry"],"verifierAdapter":"golang@1"}
entry_test.go
package sample

import (
	"encoding/json"
	"strings"
	"testing"
	"time"

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

type recordingCore struct {
	entry  zapcore.Entry
	fields []zapcore.Field
}

func (c *recordingCore) Enabled(zapcore.Level) bool { return true }
func (c *recordingCore) With(f []zapcore.Field) zapcore.Core { return c }
func (c *recordingCore) Check(ent zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.CheckedEntry {
	return ce.AddCore(ent, c)
}
func (c *recordingCore) Sync() error { return nil }
func (c *recordingCore) Write(ent zapcore.Entry, fields []zapcore.Field) error {
	c.entry = ent
	c.fields = fields
	return nil
}

type spyHook struct {
	called    bool
	lastEntry zapcore.Entry
	fields    []zapcore.Field
}

func (s *spyHook) OnWrite(ce *zapcore.CheckedEntry, fields []zapcore.Field) {
	s.called = true
	s.lastEntry = ce.Entry
	s.fields = fields
}

func TestEntryMetadataAndEncoding(t *testing.T) {
	fixedTime := time.Date(2026, time.September, 4, 12, 0, 0, 0, time.UTC)
	caller := zapcore.NewEntryCaller(100, "/app/internal/service.go", 42, true)

	ent := zapcore.Entry{
		Level:      zapcore.InfoLevel,
		Time:       fixedTime,
		LoggerName: "sample.service",
		Message:    "transaction processed successfully",
		Caller:     caller,
		Stack:      "goroutine 1 [running]",
	}

	encCfg := zapcore.EncoderConfig{
		MessageKey:     "msg",
		LevelKey:       "level",
		TimeKey:        "ts",
		NameKey:        "logger",
		CallerKey:      "caller",
		StacktraceKey:  "stack",
		EncodeLevel:    zapcore.LowercaseLevelEncoder,
		EncodeTime:     zapcore.ISO8601TimeEncoder,
		EncodeDuration: zapcore.StringDurationEncoder,
		EncodeCaller:   zapcore.ShortCallerEncoder,
	}

	encoder := zapcore.NewJSONEncoder(encCfg)
	buf, err := encoder.EncodeEntry(ent, []zapcore.Field{
		zap.String("txId", "tx-987"),
		zap.Int("items", 3),
	})
	if err != nil {
		t.Fatalf("EncodeEntry failed: %v", err)
	}

	var parsed map[string]interface{}
	if err := json.Unmarshal(buf.Bytes(), &parsed); err != nil {
		t.Fatalf("failed to parse encoded entry JSON: %v", err)
	}

	if parsed["level"] != "info" {
		t.Errorf("expected level 'info', got %v", parsed["level"])
	}
	if parsed["msg"] != "transaction processed successfully" {
		t.Errorf("expected message 'transaction processed successfully', got %v", parsed["msg"])
	}
	if parsed["logger"] != "sample.service" {
		t.Errorf("expected logger 'sample.service', got %v", parsed["logger"])
	}
	if parsed["caller"] != "internal/service.go:42" {
		t.Errorf("expected caller 'internal/service.go:42', got %v", parsed["caller"])
	}
	if parsed["txId"] != "tx-987" {
		t.Errorf("expected txId 'tx-987', got %v", parsed["txId"])
	}
	if parsed["stack"] != "goroutine 1 [running]" {
		t.Errorf("expected stack 'goroutine 1 [running]', got %v", parsed["stack"])
	}
}

func TestEntryCallerTrimming(t *testing.T) {
	t.Run("undefined caller", func(t *testing.T) {
		caller := zapcore.NewEntryCaller(0, "", 0, false)
		if caller.Defined {
			t.Errorf("expected Defined to be false")
		}
		if got := caller.FullPath(); got != "undefined" {
			t.Errorf("expected FullPath 'undefined', got %q", got)
		}
		if got := caller.TrimmedPath(); got != "undefined" {
			t.Errorf("expected TrimmedPath 'undefined', got %q", got)
		}
		if got := caller.String(); got != "undefined" {
			t.Errorf("expected String 'undefined', got %q", got)
		}
	})

	t.Run("defined caller path trimming", func(t *testing.T) {
		caller := zapcore.NewEntryCaller(100, "/workspace/pkg/handler/auth.go", 88, true)
		if !caller.Defined {
			t.Errorf("expected Defined to be true")
		}
		if got := caller.TrimmedPath(); got != "handler/auth.go:88" {
			t.Errorf("expected TrimmedPath 'handler/auth.go:88', got %q", got)
		}
		if got := caller.FullPath(); got != "/workspace/pkg/handler/auth.go:88" {
			t.Errorf("expected FullPath '/workspace/pkg/handler/auth.go:88', got %q", got)
		}
		if !strings.HasSuffix(caller.String(), "auth.go:88") {
			t.Errorf("expected String to end with 'auth.go:88', got %q", caller.String())
		}
	})
}

func TestCheckedEntryPreWriteHook(t *testing.T) {
	core := &recordingCore{}
	ent := zapcore.Entry{
		Level:   zapcore.InfoLevel,
		Message: "unmodified message",
	}

	var ce *zapcore.CheckedEntry
	ce = ce.AddCore(ent, core)
	ce = ce.Before(ent, func(e zapcore.Entry, fields []zapcore.Field) (zapcore.Entry, []zapcore.Field) {
		e.Message = "transformed: " + e.Message
		fields = append(fields, zap.String("hookInjected", "applied"))
		return e, fields
	})

	ce.Write(zap.String("originalField", "origVal"))

	if core.entry.Message != "transformed: unmodified message" {
		t.Errorf("expected transformed message, got %q", core.entry.Message)
	}
	if len(core.fields) != 2 {
		t.Fatalf("expected 2 fields, got %d", len(core.fields))
	}
	if core.fields[0].Key != "originalField" || core.fields[1].Key != "hookInjected" {
		t.Errorf("unexpected field keys: %v, %v", core.fields[0].Key, core.fields[1].Key)
	}
}

func TestCheckedEntryAfterWriteHook(t *testing.T) {
	core := &recordingCore{}
	hook := &spyHook{}
	ent := zapcore.Entry{
		Level:   zapcore.WarnLevel,
		Message: "resource quota warning",
	}

	var ce *zapcore.CheckedEntry
	ce = ce.AddCore(ent, core)
	ce = ce.After(ent, hook)

	ce.Write(zap.String("resource", "disk_space"))

	if !hook.called {
		t.Fatalf("expected hook to be invoked after write")
	}
	if hook.lastEntry.Message != "resource quota warning" {
		t.Errorf("expected hook entry message 'resource quota warning', got %q", hook.lastEntry.Message)
	}
	if hook.lastEntry.Level != zapcore.WarnLevel {
		t.Errorf("expected hook entry level WarnLevel, got %v", hook.lastEntry.Level)
	}
	if len(hook.fields) != 1 || hook.fields[0].Key != "resource" {
		t.Errorf("unexpected hook fields: %v", hook.fields)
	}
}
go.mod
module sample

go 1.26.5

require go.uber.org/zap v1.28.0

require go.uber.org/multierr v1.10.0 // indirect
go.sum
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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.28.0 h1:IZzaP1Fv73/T/pBMLk4VutPl36uNC+OSUh3JLG3FIjo=
go.uber.org/zap v1.28.0/go.mod h1:rDLpOi171uODNm/mxFcuYWxDsqWSAVkFdX4XojSKg/Q=
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify go.uber.org/zap/zapcore.Entry in pkg:golang/go.uber.org/zap@v1.28.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/go.uber.org/zap@v1.28.0"
  ],
  "symbols": [
    "go.uber.org/zap/zapcore.Entry"
  ]
}

Origin Seeder

anonymous