CodeSampleX

Sample

github.com/imdario/mergo v0.3.12: Merge

Verified sample for golang github.com/imdario/mergo v0.3.12: Merge. The contract ran on go 1.26 · linux debian/x64 · docker and passed.

sha256:c6dcacb2fbc2a23f26edd99bb26733535898be7e07c6b440c8f6bb2a10d07029

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 github.com/imdario/mergo.Merge in pkg:golang/github.com/imdario/mergo@v0.3.12
Packages
Symbols
  • github.com/imdario/mergo.Merge
Created
2026-09-04T14:54:01Z

Contract

  1. mergo.Merge merges non-zero fields from a source struct into zero-value fields of a destination struct pointer without overwriting existing non-zero fields
  2. mergo.Merge populates missing keys in a destination map from a source map while preserving existing destination keys
  3. mergo.Merge returns an error when destination is not a pointer

Files

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.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 github.com/imdario/mergo.Merge in pkg:golang/github.com/imdario/mergo@v0.3.12
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/imdario/mergo@v0.3.12
Demonstrate these symbols/APIs:
  - github.com/imdario/mergo.Merge

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:46b26e05401c05ee19705e9d72671a9306b994a0da80b091df47a5dc71a9cd43","contract":["mergo.Merge merges non-zero fields from a source struct into zero-value fields of a destination struct pointer without overwriting existing non-zero fields","mergo.Merge populates missing keys in a destination map from a source map while preserving existing destination keys","mergo.Merge returns an error when destination is not a pointer"],"goal":"verify github.com/imdario/mergo.Merge in pkg:golang/github.com/imdario/mergo@v0.3.12","kind":"HOW","packages":["pkg:golang/github.com/imdario/mergo@v0.3.12"],"schemaVersion":1,"symbols":["github.com/imdario/mergo.Merge"]},"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/github.com/imdario/mergo@v0.3.12"],"schemaVersion":1,"subject":"pkg:golang/github.com/imdario/mergo@v0.3.12","symbols":["github.com/imdario/mergo.Merge"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require github.com/imdario/mergo v0.3.12
go.sum
github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
main.go
package main

import (
	"fmt"

	"github.com/imdario/mergo"
)

type Config struct {
	Host string
	Port int
	TLS  bool
}

func main() {
	defaultCfg := Config{
		Host: "localhost",
		Port: 8080,
		TLS:  true,
	}

	userCfg := Config{
		Port: 9000,
	}

	if err := mergo.Merge(&userCfg, defaultCfg); err != nil {
		panic(err)
	}

	fmt.Printf("Merged Config: Host=%s, Port=%d, TLS=%t\n", userCfg.Host, userCfg.Port, userCfg.TLS)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/imdario/mergo.Merge in pkg:golang/github.com/imdario/mergo@v0.3.12",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/imdario/mergo@v0.3.12"
  ],
  "symbols": [
    "github.com/imdario/mergo.Merge"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"github.com/imdario/mergo"
)

type Config struct {
	Host string
	Port int
	TLS  bool
}

func main() {
	// Assertion 1: mergo.Merge merges non-zero fields from a source struct into zero-value fields of a destination struct pointer without overwriting existing non-zero fields
	dest1 := Config{
		Port: 9000,
	}
	src1 := Config{
		Host: "localhost",
		Port: 8080,
		TLS:  true,
	}
	if err := mergo.Merge(&dest1, src1); err != nil {
		fmt.Fprintf(os.Stderr, "assertion 1 failed: unexpected error: %v\n", err)
		os.Exit(1)
	}
	if dest1.Host != "localhost" || dest1.Port != 9000 || dest1.TLS != true {
		fmt.Fprintf(os.Stderr, "assertion 1 failed: expected Host=localhost, Port=9000, TLS=true; got Host=%s, Port=%d, TLS=%t\n", dest1.Host, dest1.Port, dest1.TLS)
		os.Exit(1)
	}

	// Assertion 2: mergo.Merge populates missing keys in a destination map from a source map while preserving existing destination keys
	destMap := map[string]string{
		"env":  "production",
		"tier": "backend",
	}
	srcMap := map[string]string{
		"tier":   "frontend",
		"region": "us-west",
	}
	if err := mergo.Merge(&destMap, srcMap); err != nil {
		fmt.Fprintf(os.Stderr, "assertion 2 failed: unexpected error: %v\n", err)
		os.Exit(1)
	}
	if destMap["env"] != "production" || destMap["tier"] != "backend" || destMap["region"] != "us-west" {
		fmt.Fprintf(os.Stderr, "assertion 2 failed: map content mismatch: %v\n", destMap)
		os.Exit(1)
	}

	// Assertion 3: mergo.Merge returns an error when destination is not a pointer
	destNonPtr := Config{}
	srcNonPtr := Config{Host: "example.com"}
	if err := mergo.Merge(destNonPtr, srcNonPtr); err == nil {
		fmt.Fprintf(os.Stderr, "assertion 3 failed: expected error when dst is not a pointer, got nil\n")
		os.Exit(1)
	}

	fmt.Println("All contract assertions passed.")
}

Origin Seeder

anonymous