CodeSampleX

Sample

github.com/pelletier/go-toml/v2 v2.4.3

Verified sample for golang github.com/pelletier/go-toml/v2 v2.4.3. The contract ran on go 1.26 · linux debian/x64 · docker and passed.

sha256:c8be58061ab1c0a01d0ed254c4f19fcce5950745fa38f9c72f51be2518b15a30

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

Case

HOW
Goal
verify pkg:golang/github.com/pelletier/go-toml/v2@v2.4.3
Packages
Created
2026-09-13T19:22:45Z

Contract

  1. toml.Marshal serializes structs and maps into valid TOML bytes
  2. toml.Unmarshal deserializes TOML bytes into target structs with matching fields
  3. toml.NewDecoder and toml.NewEncoder stream TOML content via io.Reader and io.Writer
  4. toml.Unmarshal returns an error when parsing malformed TOML syntax

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 pkg:golang/github.com/pelletier/go-toml/v2@v2.4.3
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/pelletier/go-toml/v2@v2.4.3

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:009c7c94a3d384dc640b97d176115f670294dbe1fb76f70686bd905d2842694a","contract":["toml.Marshal serializes structs and maps into valid TOML bytes","toml.Unmarshal deserializes TOML bytes into target structs with matching fields","toml.NewDecoder and toml.NewEncoder stream TOML content via io.Reader and io.Writer","toml.Unmarshal returns an error when parsing malformed TOML syntax"],"goal":"verify pkg:golang/github.com/pelletier/go-toml/v2@v2.4.3","kind":"HOW","packages":["pkg:golang/github.com/pelletier/go-toml/v2@v2.4.3"],"schemaVersion":1},"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/pelletier/go-toml/v2@v2.4.3"],"schemaVersion":1,"subject":"pkg:golang/github.com/pelletier/go-toml/v2@v2.4.3","verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require github.com/pelletier/go-toml/v2 v2.4.3
go.sum
github.com/pelletier/go-toml/v2 v2.4.3 h1:GTRvJQutkOSftxIFD5xw9aepkYNuPWmVJpffdDPYVpY=
github.com/pelletier/go-toml/v2 v2.4.3/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
main.go
package main

import (
	"fmt"
	"os"

	"github.com/pelletier/go-toml/v2"
)

type Config struct {
	Title   string   `toml:"title"`
	Version string   `toml:"version"`
	Ports   []int    `toml:"ports"`
	Server  Server   `toml:"server"`
}

type Server struct {
	Host string `toml:"host"`
	Port int    `toml:"port"`
}

func main() {
	doc := `
title = "Sample Application"
version = "1.0.0"
ports = [8080, 8081]

[server]
host = "127.0.0.1"
port = 8080
`

	var cfg Config
	if err := toml.Unmarshal([]byte(doc), &cfg); err != nil {
		fmt.Fprintf(os.Stderr, "failed to unmarshal: %v\n", err)
		os.Exit(1)
	}

	fmt.Printf("Parsed config title: %s\n", cfg.Title)
	fmt.Printf("Server host: %s:%d\n", cfg.Server.Host, cfg.Server.Port)

	out, err := toml.Marshal(cfg)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to marshal: %v\n", err)
		os.Exit(1)
	}

	fmt.Printf("Marshaled output:\n%s\n", string(out))
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/github.com/pelletier/go-toml/v2@v2.4.3",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/pelletier/go-toml/v2@v2.4.3"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"fmt"
	"os"
	"strings"

	"github.com/pelletier/go-toml/v2"
)

type DatabaseConfig struct {
	Enabled bool   `toml:"enabled"`
	Host    string `toml:"host"`
	Port    int    `toml:"port"`
}

type AppConfig struct {
	Name     string         `toml:"name"`
	Database DatabaseConfig `toml:"database"`
	Tags     []string       `toml:"tags"`
}

func main() {
	// Assertion 1: toml.Marshal serializes structs and maps into valid TOML bytes
	{
		cfg := AppConfig{
			Name: "test-app",
			Database: DatabaseConfig{
				Enabled: true,
				Host:    "localhost",
				Port:    5432,
			},
			Tags: []string{"backend", "v2"},
		}

		data, err := toml.Marshal(cfg)
		if err != nil {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: unexpected marshal error: %v\n", err)
			os.Exit(1)
		}

		text := string(data)
		if !strings.Contains(text, "name = 'test-app'") && !strings.Contains(text, `name = "test-app"`) {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: name field missing or incorrect in %s\n", text)
			os.Exit(1)
		}
		if !strings.Contains(text, "[database]") {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: [database] section missing in %s\n", text)
			os.Exit(1)
		}
	}

	// Assertion 2: toml.Unmarshal deserializes TOML bytes into target structs with matching fields
	{
		raw := `
name = "demo-service"
tags = ["alpha", "beta"]

[database]
enabled = true
host = "127.0.0.1"
port = 3306
`
		var parsed AppConfig
		if err := toml.Unmarshal([]byte(raw), &parsed); err != nil {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: unexpected unmarshal error: %v\n", err)
			os.Exit(1)
		}

		if parsed.Name != "demo-service" {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: expected name 'demo-service', got '%s'\n", parsed.Name)
			os.Exit(1)
		}
		if !parsed.Database.Enabled || parsed.Database.Host != "127.0.0.1" || parsed.Database.Port != 3306 {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: database mismatch: %+v\n", parsed.Database)
			os.Exit(1)
		}
		if len(parsed.Tags) != 2 || parsed.Tags[0] != "alpha" || parsed.Tags[1] != "beta" {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: tags mismatch: %+v\n", parsed.Tags)
			os.Exit(1)
		}
	}

	// Assertion 3: toml.NewDecoder and toml.NewEncoder stream TOML content via io.Reader and io.Writer
	{
		source := `
name = "streamed-app"

[database]
enabled = false
host = "remotehost"
port = 9000
`
		var cfg AppConfig
		decoder := toml.NewDecoder(strings.NewReader(source))
		if err := decoder.Decode(&cfg); err != nil {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: decode error: %v\n", err)
			os.Exit(1)
		}
		if cfg.Name != "streamed-app" || cfg.Database.Port != 9000 {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: decoded config mismatch: %+v\n", cfg)
			os.Exit(1)
		}

		var buf bytes.Buffer
		encoder := toml.NewEncoder(&buf)
		if err := encoder.Encode(cfg); err != nil {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: encode error: %v\n", err)
			os.Exit(1)
		}
		if buf.Len() == 0 || !strings.Contains(buf.String(), "streamed-app") {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: encoded buffer invalid: %s\n", buf.String())
			os.Exit(1)
		}
	}

	// Assertion 4: toml.Unmarshal returns an error when parsing malformed TOML syntax
	{
		malformed := `
name = "unclosed-string
invalid toml line here = = =
`
		var target map[string]any
		err := toml.Unmarshal([]byte(malformed), &target)
		if err == nil {
			fmt.Fprintf(os.Stderr, "assertion 4 failed: expected error for malformed TOML, got nil\n")
			os.Exit(1)
		}
	}

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

Origin Seeder

anonymous