Ejemplo
golang.org/x/text v0.42.0: encoding.Decoder
Muestra verificada para golang golang.org/x/text v0.42.0: encoding.Decoder. El contrato se ejecutó en go 1.26 · linux debian/x64 · docker y pasó.
sha256:3ec017571660c661fdf356f75e6969b1eef594ffbefc45605ca1c09f96cab0e0
Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido.
Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas.
MIT-0
Evidencia de ejecución
El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.
- Base de evidencia
- Contrato firmado aprobado
- Recibos de verificación
- 1
- Claves de firma que lo compilaron
- 1
Entorno declarado
linux 24 · ubuntu · glibc 2.39 x64 go
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| 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 |
Caso
HOW- Objetivo
- verify golang.org/x/text/encoding.Decoder in pkg:golang/golang.org/x/text@v0.42.0
- Paquetes
- Símbolos
-
- golang.org/x/text/encoding.Decoder
- Creado
- 2026-09-15T20:55:38Z
Contrato
- Decoder.Bytes converts encoded byte slice to valid UTF-8 byte slice
- Decoder.String converts encoded string to valid UTF-8 string
- Decoder.Reader wraps io.Reader to decode streaming bytes into UTF-8
- Decoder.Transform satisfies transform.Transformer interface and converts bytes buffer
- Decoder.Transform returns transform.ErrShortDst when destination buffer is too small
- Decoder.Reset resets transformer state without error
- Nop NewDecoder produces identity Decoder that passes through bytes unchanged
- Replacement NewDecoder produces Decoder that decodes bytes to Unicode replacement character
Archivos
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Código fuente
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.Decoder 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.Decoder
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:0b95af8ebb2009243188948889c3f0ec7f1301bf9adb2be7dcb5ec0fba3bdbcc","contract":["Decoder.Bytes converts encoded byte slice to valid UTF-8 byte slice","Decoder.String converts encoded string to valid UTF-8 string","Decoder.Reader wraps io.Reader to decode streaming bytes into UTF-8","Decoder.Transform satisfies transform.Transformer interface and converts bytes buffer","Decoder.Transform returns transform.ErrShortDst when destination buffer is too small","Decoder.Reset resets transformer state without error","Nop NewDecoder produces identity Decoder that passes through bytes unchanged","Replacement NewDecoder produces Decoder that decodes bytes to Unicode replacement character"],"goal":"verify golang.org/x/text/encoding.Decoder 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.Decoder"]},"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.42.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/text@v0.42.0","symbols":["golang.org/x/text/encoding.Decoder"],"verifierAdapter":"golang@1"}
module example.com/sample
go 1.26.0
require golang.org/x/text v0.42.0
golang.org/x/text v0.42.0 h1:JbOZXgfeCPU9gacVtYliJqOhD+zhrEqK4LfdpmlUZqI=
golang.org/x/text v0.42.0/go.mod h1:ojzP1Z+2QtioaF8DTtO8K5q7JWVVYwZKenzujK0Zd0E=
package main
import (
"bytes"
"fmt"
"io"
"log"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/charmap"
)
func main() {
// Demonstrate golang.org/x/text/encoding.Decoder with Windows-1252 encoding
var dec *encoding.Decoder = charmap.Windows1252.NewDecoder()
// 1. Decode byte slice
win1252Bytes := []byte{0x43, 0x61, 0x66, 0xe9, 0x20, 0x80} // "Café €" in Windows-1252
utf8Bytes, err := dec.Bytes(win1252Bytes)
if err != nil {
log.Fatalf("failed to decode bytes: %v", err)
}
fmt.Printf("Decoded bytes: %s\n", string(utf8Bytes))
// 2. Decode string
utf8Str, err := dec.String(string(win1252Bytes))
if err != nil {
log.Fatalf("failed to decode string: %v", err)
}
fmt.Printf("Decoded string: %s\n", utf8Str)
// 3. Decode streaming reader
reader := dec.Reader(bytes.NewReader(win1252Bytes))
streamOutput, err := io.ReadAll(reader)
if err != nil {
log.Fatalf("failed to decode reader: %v", err)
}
fmt.Printf("Decoded stream: %s\n", string(streamOutput))
}
{
"schemaVersion": 1,
"goal": "verify golang.org/x/text/encoding.Decoder 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.Decoder"
]
}
package main
import (
"bytes"
"errors"
"fmt"
"io"
"os"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/charmap"
"golang.org/x/text/transform"
)
func main() {
dec := charmap.Windows1252.NewDecoder()
// 1. Decoder.Bytes converts encoded byte slice to valid UTF-8 byte slice
// In Windows-1252: 0x80 is Euro sign (€), 0xe9 is é
inputBytes := []byte{0x43, 0x61, 0x66, 0xe9, 0x20, 0x80}
decodedBytes, err := dec.Bytes(inputBytes)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 1 failed: error decoding bytes: %v\n", err)
os.Exit(1)
}
if string(decodedBytes) != "Café €" {
fmt.Fprintf(os.Stderr, "assertion 1 failed: expected %q, got %q\n", "Café €", string(decodedBytes))
os.Exit(1)
}
// 2. Decoder.String converts encoded string to valid UTF-8 string
inputStr := string(inputBytes)
decodedStr, err := dec.String(inputStr)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 2 failed: error decoding string: %v\n", err)
os.Exit(1)
}
if decodedStr != "Café €" {
fmt.Fprintf(os.Stderr, "assertion 2 failed: expected %q, got %q\n", "Café €", decodedStr)
os.Exit(1)
}
// 3. Decoder.Reader wraps io.Reader to decode streaming bytes into UTF-8
streamReader := dec.Reader(bytes.NewReader(inputBytes))
streamResult, err := io.ReadAll(streamReader)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 3 failed: error reading from decoded reader: %v\n", err)
os.Exit(1)
}
if string(streamResult) != "Café €" {
fmt.Fprintf(os.Stderr, "assertion 3 failed: expected %q, got %q\n", "Café €", string(streamResult))
os.Exit(1)
}
// 4. Decoder.Transform satisfies transform.Transformer interface and converts bytes buffer
var _ transform.Transformer = dec
dst := make([]byte, 32)
nDst, nSrc, err := dec.Transform(dst, []byte{0x80}, true)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 4 failed: transform returned unexpected error: %v\n", err)
os.Exit(1)
}
if nSrc != 1 || nDst != 3 || string(dst[:nDst]) != "€" {
fmt.Fprintf(os.Stderr, "assertion 4 failed: unexpected transform output: nSrc=%d, nDst=%d, out=%q\n", nSrc, nDst, string(dst[:nDst]))
os.Exit(1)
}
// 5. Decoder.Transform returns transform.ErrShortDst when destination buffer is too small
shortDst := make([]byte, 1)
_, _, err = dec.Transform(shortDst, []byte{0x80}, true)
if !errors.Is(err, transform.ErrShortDst) {
fmt.Fprintf(os.Stderr, "assertion 5 failed: expected ErrShortDst, got %v\n", err)
os.Exit(1)
}
// 6. Decoder.Reset resets transformer state without error
dec.Reset()
// 7. Nop NewDecoder produces identity Decoder that passes through bytes unchanged
nopDec := encoding.Nop.NewDecoder()
nopInput := []byte("plain text sample")
nopOutput, err := nopDec.Bytes(nopInput)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 7 failed: error on Nop Decoder: %v\n", err)
os.Exit(1)
}
if !bytes.Equal(nopOutput, nopInput) {
fmt.Fprintf(os.Stderr, "assertion 7 failed: expected unchanged bytes\n")
os.Exit(1)
}
// 8. Replacement NewDecoder produces Decoder that decodes bytes to Unicode replacement character
repDec := encoding.Replacement.NewDecoder()
repOutput, err := repDec.Bytes([]byte("test input"))
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 8 failed: error on Replacement Decoder: %v\n", err)
os.Exit(1)
}
if string(repOutput) != "\ufffd" {
fmt.Fprintf(os.Stderr, "assertion 8 failed: expected replacement rune, got %q\n", string(repOutput))
os.Exit(1)
}
fmt.Println("All contract assertions passed.")
}
Seeder de origen
anónimo