Sample
golang.org/x/text v0.31.0: encoding.ReplaceUnsupported
Verified sample for golang golang.org/x/text v0.31.0: encoding.ReplaceUnsupported. The contract ran on go 1.26 · linux debian/x64 · docker and passed.
sha256:c76d82bf7e643ea82834eec25113826820728dae40cbe78fae5c657d6685bef8
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-10-11 |
Case
HOW- Goal
- verify golang.org/x/text/encoding.ReplaceUnsupported in pkg:golang/golang.org/x/text@v0.31.0
- Packages
- Symbols
-
- golang.org/x/text/encoding.ReplaceUnsupported
- Created
- 2026-10-11T17:12:34Z
Contract
- encoding.ReplaceUnsupported wraps an Encoder replacing unsupported runes with the destination replacement byte
- encoding.ReplaceUnsupported preserves valid runes in destination repertoire without replacement
- encoding.ReplaceUnsupported replaces multiple consecutive unsupported runes with corresponding replacement bytes
- encoding.ReplaceUnsupported returns transform.ErrShortDst when destination buffer is too small to receive replacement
- encoding.ReplaceUnsupported works with Encoder.String and Encoder.Bytes methods without returning repertoire errors
Files
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Source
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.ReplaceUnsupported in pkg:golang/golang.org/x/text@v0.31.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/golang.org/x/text@v0.31.0
Demonstrate these symbols/APIs:
- golang.org/x/text/encoding.ReplaceUnsupported
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.
{"case":{"caseId":"case:sha256:6ef559d31ad78023893636ea0200f617daceaadb128d30f092f4e8e6e2393140","contract":["encoding.ReplaceUnsupported wraps an Encoder replacing unsupported runes with the destination replacement byte","encoding.ReplaceUnsupported preserves valid runes in destination repertoire without replacement","encoding.ReplaceUnsupported replaces multiple consecutive unsupported runes with corresponding replacement bytes","encoding.ReplaceUnsupported returns transform.ErrShortDst when destination buffer is too small to receive replacement","encoding.ReplaceUnsupported works with Encoder.String and Encoder.Bytes methods without returning repertoire errors"],"goal":"verify golang.org/x/text/encoding.ReplaceUnsupported in pkg:golang/golang.org/x/text@v0.31.0","kind":"HOW","packages":["pkg:golang/golang.org/x/text@v0.31.0"],"schemaVersion":1,"symbols":["golang.org/x/text/encoding.ReplaceUnsupported"]},"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/golang.org/x/text@v0.31.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/text@v0.31.0","symbols":["golang.org/x/text/encoding.ReplaceUnsupported"],"verifierAdapter":"golang@1"}
module example.com/sample
go 1.24.0
require golang.org/x/text v0.31.0
golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM=
golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM=
package main
import (
"fmt"
"os"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/charmap"
)
func main() {
baseEncoder := charmap.Windows1252.NewEncoder()
wrappedEncoder := encoding.ReplaceUnsupported(baseEncoder)
inputWithUnsupported := "Hello World \u4e16\u754c"
encodedBytes, err := wrappedEncoder.Bytes([]byte(inputWithUnsupported))
if err != nil {
fmt.Fprintf(os.Stderr, "encoding failed: %v\n", err)
os.Exit(1)
}
fmt.Printf("Encoded bytes (with replacements): %q\n", encodedBytes)
inputSupported := "Caf\u00e9"
encodedSupported, err := wrappedEncoder.String(inputSupported)
if err != nil {
fmt.Fprintf(os.Stderr, "string encoding failed: %v\n", err)
os.Exit(1)
}
fmt.Printf("Encoded supported string (raw bytes): %x\n", encodedSupported)
fmt.Println("golang.org/x/text/encoding.ReplaceUnsupported demonstrated successfully.")
}
{
"schemaVersion": 1,
"goal": "verify golang.org/x/text/encoding.ReplaceUnsupported in pkg:golang/golang.org/x/text@v0.31.0",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/text@v0.31.0"
],
"symbols": [
"golang.org/x/text/encoding.ReplaceUnsupported"
]
}
package main
import (
"bytes"
"errors"
"fmt"
"os"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/charmap"
"golang.org/x/text/transform"
)
func main() {
if err := runContractTests(); err != nil {
fmt.Fprintf(os.Stderr, "Contract test failed: %v\n", err)
os.Exit(1)
}
fmt.Println("All contract assertions passed successfully.")
}
func runContractTests() error {
// Assertion 1: encoding.ReplaceUnsupported wraps an Encoder replacing unsupported runes with the destination replacement byte
{
baseEncoder := charmap.Windows1252.NewEncoder()
_, rawErr := baseEncoder.Bytes([]byte("hello \uac00 world"))
if rawErr == nil {
return errors.New("assertion 1 failed: unwrapped base encoder unexpectedly succeeded on unsupported rune")
}
wrapped := encoding.ReplaceUnsupported(charmap.Windows1252.NewEncoder())
out, err := wrapped.Bytes([]byte("hello \uac00 world"))
if err != nil {
return fmt.Errorf("assertion 1 failed: wrapped encoder returned error: %w", err)
}
expected := []byte("hello \x1a world")
if !bytes.Equal(out, expected) {
return fmt.Errorf("assertion 1 failed: expected %q, got %q", expected, out)
}
}
// Assertion 2: encoding.ReplaceUnsupported preserves valid runes in destination repertoire without replacement
{
wrapped := encoding.ReplaceUnsupported(charmap.Windows1252.NewEncoder())
input := "Caf\u00e9 123!"
out, err := wrapped.Bytes([]byte(input))
if err != nil {
return fmt.Errorf("assertion 2 failed: wrapped encoder returned error: %w", err)
}
expected := []byte{'C', 'a', 'f', 0xe9, ' ', '1', '2', '3', '!'}
if !bytes.Equal(out, expected) {
return fmt.Errorf("assertion 2 failed: expected %v, got %v", expected, out)
}
}
// Assertion 3: encoding.ReplaceUnsupported replaces multiple consecutive unsupported runes with corresponding replacement bytes
{
wrapped := encoding.ReplaceUnsupported(charmap.Windows1252.NewEncoder())
input := "\uac00\ub098\ub2e4"
out, err := wrapped.Bytes([]byte(input))
if err != nil {
return fmt.Errorf("assertion 3 failed: wrapped encoder returned error: %w", err)
}
expected := []byte{0x1a, 0x1a, 0x1a}
if !bytes.Equal(out, expected) {
return fmt.Errorf("assertion 3 failed: expected %v, got %v", expected, out)
}
}
// Assertion 4: encoding.ReplaceUnsupported returns transform.ErrShortDst when destination buffer is too small to receive replacement
{
wrapped := encoding.ReplaceUnsupported(charmap.Windows1252.NewEncoder())
src := []byte("\uac00")
dst := make([]byte, 0)
_, _, err := wrapped.Transform(dst, src, true)
if !errors.Is(err, transform.ErrShortDst) {
return fmt.Errorf("assertion 4 failed: expected transform.ErrShortDst, got %v", err)
}
}
// Assertion 5: encoding.ReplaceUnsupported works with Encoder.String and Encoder.Bytes methods without returning repertoire errors
{
wrapped := encoding.ReplaceUnsupported(charmap.Windows1252.NewEncoder())
inputStr := "Value: \u20ac and \u4e16" // \u20ac is supported in Windows-1252 (0x80), \u4e16 is not
outStr, err := wrapped.String(inputStr)
if err != nil {
return fmt.Errorf("assertion 5 failed: String returned error: %w", err)
}
expectedStr := "Value: \x80 and \x1a"
if outStr != expectedStr {
return fmt.Errorf("assertion 5 failed: expected %q, got %q", expectedStr, outStr)
}
outBytes, err := wrapped.Bytes([]byte(inputStr))
if err != nil {
return fmt.Errorf("assertion 5 failed: Bytes returned error: %w", err)
}
if !bytes.Equal(outBytes, []byte(expectedStr)) {
return fmt.Errorf("assertion 5 failed: expected bytes %q, got %q", expectedStr, outBytes)
}
}
return nil
}
Origin Seeder
anonymous