CodeSampleX

Sample

golang.org/x/text v0.42.0: encoding.Encoder

Verified sample for golang golang.org/x/text v0.42.0: encoding.Encoder. The contract ran on go 1.26 · linux debian/x64 · docker and passed.

sha256:dd635ac30956af4d217601e8f5d50e769cd0b335fba31b2dd1edfbb33c5cd520

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 x64 go 1.26 go 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-15

Case

HOW
Goal
verify golang.org/x/text/encoding.Encoder in pkg:golang/golang.org/x/text@v0.42.0
Packages
Symbols
  • golang.org/x/text/encoding.Encoder
Environment
go 1.26.6
Created
2026-09-15T23:15:35Z

Contract

  1. Encoder.String transcodes valid UTF-8 strings into the target character encoding
  2. Encoder.Bytes transcodes valid UTF-8 byte slices into target encoding bytes
  3. Encoder returns an error when encountering characters unrepresentable in the target encoding
  4. ReplaceUnsupported wraps Encoder to substitute unrepresentable characters with encoding replacement
  5. HTMLEscapeUnsupported wraps Encoder to replace unrepresentable characters with HTML decimal entities
  6. Encoder.Writer wraps an io.Writer to transcode streaming UTF-8 bytes to the target encoding

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 golang.org/x/text/encoding.Encoder in pkg:golang/golang.org/x/text@v0.42.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/text@v0.42.0
Demonstrate these symbols/APIs:
  - golang.org/x/text/encoding.Encoder

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:624274d8d8eb6c72b5887e0243779d8eb9c8ed5ecf5b4ff68e89a5a440fb9872","contract":["Encoder.String transcodes valid UTF-8 strings into the target character encoding","Encoder.Bytes transcodes valid UTF-8 byte slices into target encoding bytes","Encoder returns an error when encountering characters unrepresentable in the target encoding","ReplaceUnsupported wraps Encoder to substitute unrepresentable characters with encoding replacement","HTMLEscapeUnsupported wraps Encoder to replace unrepresentable characters with HTML decimal entities","Encoder.Writer wraps an io.Writer to transcode streaming UTF-8 bytes to the target encoding"],"goal":"verify golang.org/x/text/encoding.Encoder in pkg:golang/golang.org/x/text@v0.42.0","kind":"HOW","packages":["pkg:golang/golang.org/x/text@v0.42.0"],"schemaVersion":1,"symbols":["golang.org/x/text/encoding.Encoder"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","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/golang.org/x/text@v0.42.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/text@v0.42.0","symbols":["golang.org/x/text/encoding.Encoder"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.0

require golang.org/x/text v0.42.0
go.sum
golang.org/x/text v0.42.0 h1:JbOZXgfeCPU9gacVtYliJqOhD+zhrEqK4LfdpmlUZqI=
golang.org/x/text v0.42.0/go.mod h1:ojzP1Z+2QtioaF8DTtO8K5q7JWVVYwZKenzujK0Zd0E=
main.go
package main

import (
	"bytes"
	"fmt"

	"golang.org/x/text/encoding"
	"golang.org/x/text/encoding/charmap"
)

func main() {
	// Standard ISO-8859-1 encoder
	enc := charmap.ISO8859_1.NewEncoder()

	// 1. Transform string
	encodedStr, err := enc.String("Café")
	if err != nil {
		fmt.Printf("Encoding error: %v\n", err)
		return
	}
	fmt.Printf("Encoded string bytes: % x\n", []byte(encodedStr))

	// 2. Transform bytes
	encodedBytes, err := enc.Bytes([]byte("Resumé"))
	if err != nil {
		fmt.Printf("Encoding error: %v\n", err)
		return
	}
	fmt.Printf("Encoded bytes: % x\n", encodedBytes)

	// 3. Handling unsupported characters with HTML escaping
	htmlEnc := encoding.HTMLEscapeUnsupported(charmap.ISO8859_1.NewEncoder())
	escaped, err := htmlEnc.String("Euro sign: €")
	if err != nil {
		fmt.Printf("HTML escape error: %v\n", err)
		return
	}
	fmt.Printf("HTML escaped: %s\n", escaped)

	// 4. Writer streaming
	var buf bytes.Buffer
	w := enc.Writer(&buf)
	_, _ = w.Write([]byte("Naïve"))
	fmt.Printf("Stream encoded: % x\n", buf.Bytes())
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify golang.org/x/text/encoding.Encoder in pkg:golang/golang.org/x/text@v0.42.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/text@v0.42.0"
  ],
  "symbols": [
    "golang.org/x/text/encoding.Encoder"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"fmt"
	"os"

	"golang.org/x/text/encoding"
	"golang.org/x/text/encoding/charmap"
)

func main() {
	if err := runContract(); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: %v\n", err)
		os.Exit(1)
	}
	fmt.Println("PASS: all contract assertions satisfied")
}

func runContract() error {
	// 1. Encoder.String transcodes valid UTF-8 strings into the target character encoding
	{
		enc := charmap.ISO8859_1.NewEncoder()
		res, err := enc.String("Café")
		if err != nil {
			return fmt.Errorf("Encoder.String returned unexpected error: %w", err)
		}
		expected := "Caf\xe9"
		if res != expected {
			return fmt.Errorf("Encoder.String got %q, want %q", res, expected)
		}
	}

	// 2. Encoder.Bytes transcodes valid UTF-8 byte slices into target encoding bytes
	{
		enc := charmap.ISO8859_1.NewEncoder()
		src := []byte("Naïve")
		res, err := enc.Bytes(src)
		if err != nil {
			return fmt.Errorf("Encoder.Bytes returned unexpected error: %w", err)
		}
		expected := []byte{'N', 'a', 0xef, 'v', 'e'}
		if !bytes.Equal(res, expected) {
			return fmt.Errorf("Encoder.Bytes got %v, want %v", res, expected)
		}
	}

	// 3. Encoder returns an error when encountering characters unrepresentable in the target encoding
	{
		enc := charmap.ISO8859_1.NewEncoder()
		_, err := enc.String("Hello 日本語")
		if err == nil {
			return fmt.Errorf("Encoder.String expected error on unrepresentable runes, got nil")
		}
	}

	// 4. ReplaceUnsupported wraps Encoder to substitute unrepresentable characters with encoding replacement
	{
		baseEnc := charmap.ISO8859_1.NewEncoder()
		repEnc := encoding.ReplaceUnsupported(baseEnc)
		res, err := repEnc.String("A 日本 B")
		if err != nil {
			return fmt.Errorf("ReplaceUnsupported Encoder returned unexpected error: %w", err)
		}
		// ISO-8859-1 replacement character is SUB (0x1a)
		expected := "A \x1a\x1a B"
		if res != expected {
			return fmt.Errorf("ReplaceUnsupported Encoder got %q (%+v), want %q", res, []byte(res), expected)
		}
	}

	// 5. HTMLEscapeUnsupported wraps Encoder to replace unrepresentable characters with HTML decimal entities
	{
		baseEnc := charmap.ISO8859_1.NewEncoder()
		htmlEnc := encoding.HTMLEscapeUnsupported(baseEnc)
		res, err := htmlEnc.String("Price: €5")
		if err != nil {
			return fmt.Errorf("HTMLEscapeUnsupported Encoder returned unexpected error: %w", err)
		}
		expected := "Price: €5"
		if res != expected {
			return fmt.Errorf("HTMLEscapeUnsupported Encoder got %q, want %q", res, expected)
		}
	}

	// 6. Encoder.Writer wraps an io.Writer to transcode streaming UTF-8 bytes to the target encoding
	{
		enc := charmap.ISO8859_1.NewEncoder()
		var buf bytes.Buffer
		w := enc.Writer(&buf)
		n, err := w.Write([]byte("Café"))
		if err != nil {
			return fmt.Errorf("Encoder.Writer Write returned unexpected error: %w", err)
		}
		if n == 0 {
			return fmt.Errorf("Encoder.Writer Write wrote 0 bytes")
		}
		expected := []byte{'C', 'a', 'f', 0xe9}
		if !bytes.Equal(buf.Bytes(), expected) {
			return fmt.Errorf("Encoder.Writer output got %v, want %v", buf.Bytes(), expected)
		}
	}

	return nil
}

Origin Seeder

anonymous