CodeSampleX

Ejemplo

github.com/jackc/chunkreader/v2 v2.0.0: chunkreader.ChunkReader.Next, chunkreader.New, chunkreader.NewConfig

Muestra verificada para golang github.com/jackc/chunkreader/v2 v2.0.0: chunkreader.ChunkReader.Next, chunkreader.New, chunkreader.NewConfig. El contrato se…

sha256:344dd5cbac7891288a03fe1e6297f37849d35b1f90db4b8db3e057397a847956

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 alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f…
2026-08-27

Caso

HOW
Objetivo
verify pkg:golang/github.com/jackc/chunkreader/v2@v2.0.0
Paquetes
Símbolos
  • chunkreader.ChunkReader.Next
  • chunkreader.New
  • chunkreader.NewConfig
Creado
2026-08-27T17:32:57Z

Contrato

  1. chunkreader.New initializes a ChunkReader wrapping an io.Reader with default configuration
  2. chunkreader.NewConfig initializes a ChunkReader with custom MinBufLen in Config
  3. chunkreader.ChunkReader.Next returns consecutive byte slices of requested lengths from stream
  4. chunkreader.ChunkReader.Next returns io.ErrUnexpectedEOF or io.EOF when stream has fewer bytes than requested
  5. chunkreader.ChunkReader.Next expands internal buffer when requested chunk exceeds initial buffer length
  6. chunkreader.ChunkReader.Next returns empty byte slice with nil error when requested length is 0

Archivos

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract.go

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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/jackc/chunkreader/v2@v2.0.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/jackc/chunkreader/v2@v2.0.0
Demonstrate these symbols/APIs:
  - chunkreader.ChunkReader.Next
  - chunkreader.New
  - chunkreader.NewConfig

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:9b3e669f7933ff52c8af053efac9b292c10bb6ba990c50b17a81383666882516","contract":["chunkreader.New initializes a ChunkReader wrapping an io.Reader with default configuration","chunkreader.NewConfig initializes a ChunkReader with custom MinBufLen in Config","chunkreader.ChunkReader.Next returns consecutive byte slices of requested lengths from stream","chunkreader.ChunkReader.Next returns io.ErrUnexpectedEOF or io.EOF when stream has fewer bytes than requested","chunkreader.ChunkReader.Next expands internal buffer when requested chunk exceeds initial buffer length","chunkreader.ChunkReader.Next returns empty byte slice with nil error when requested length is 0"],"goal":"verify pkg:golang/github.com/jackc/chunkreader/v2@v2.0.0","kind":"HOW","packages":["pkg:golang/github.com/jackc/chunkreader/v2@v2.0.0"],"schemaVersion":1,"symbols":["chunkreader.ChunkReader.Next","chunkreader.New","chunkreader.NewConfig"]},"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/jackc/chunkreader/v2@v2.0.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/jackc/chunkreader/v2@v2.0.0","symbols":["chunkreader.ChunkReader.Next","chunkreader.New","chunkreader.NewConfig"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require github.com/jackc/chunkreader/v2 v2.0.0 // indirect
go.sum
github.com/jackc/chunkreader/v2 v2.0.0 h1:DUwgMQuuPnS0rhMXenUtZpqZqrR/30NWY+qQvTpSvEs=
github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
main.go
package main

import (
	"fmt"
	"strings"

	"github.com/jackc/chunkreader/v2"
)

func main() {
	reader := strings.NewReader("Hello, ChunkReader v2!")
	cr := chunkreader.New(reader)

	chunk, err := cr.Next(5)
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}
	fmt.Printf("Read chunk: %s\n", string(chunk))
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/github.com/jackc/chunkreader/v2@v2.0.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/jackc/chunkreader/v2@v2.0.0"
  ],
  "symbols": [
    "chunkreader.ChunkReader.Next",
    "chunkreader.New",
    "chunkreader.NewConfig"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"errors"
	"fmt"
	"io"
	"strings"

	"github.com/jackc/chunkreader/v2"
)

func main() {
	// 1. chunkreader.New initializes a ChunkReader wrapping an io.Reader with default configuration
	{
		r := strings.NewReader("sample data for testing")
		cr := chunkreader.New(r)
		if cr == nil {
			panic("expected non-nil ChunkReader from chunkreader.New")
		}
		chunk, err := cr.Next(6)
		if err != nil || string(chunk) != "sample" {
			panic(fmt.Sprintf("expected 'sample', got '%s', err: %v", string(chunk), err))
		}
	}

	// 2. chunkreader.NewConfig initializes a ChunkReader with custom MinBufLen in Config
	{
		r := strings.NewReader("custom config stream data")
		cfg := chunkreader.Config{MinBufLen: 16}
		cr, err := chunkreader.NewConfig(r, cfg)
		if err != nil {
			panic(fmt.Sprintf("unexpected error from NewConfig: %v", err))
		}
		if cr == nil {
			panic("expected non-nil ChunkReader from NewConfig")
		}
		chunk, err := cr.Next(6)
		if err != nil || string(chunk) != "custom" {
			panic(fmt.Sprintf("expected 'custom', got '%s', err: %v", string(chunk), err))
		}
	}

	// 3. chunkreader.ChunkReader.Next returns consecutive byte slices of requested lengths from stream
	{
		data := "first, second, third"
		cr := chunkreader.New(strings.NewReader(data))

		c1, err := cr.Next(5)
		if err != nil || string(c1) != "first" {
			panic(fmt.Sprintf("unexpected c1: %q, err: %v", string(c1), err))
		}

		c2, err := cr.Next(2)
		if err != nil || string(c2) != ", " {
			panic(fmt.Sprintf("unexpected c2: %q, err: %v", string(c2), err))
		}

		c3, err := cr.Next(6)
		if err != nil || string(c3) != "second" {
			panic(fmt.Sprintf("unexpected c3: %q, err: %v", string(c3), err))
		}

		c4, err := cr.Next(7)
		if err != nil || string(c4) != ", third" {
			panic(fmt.Sprintf("unexpected c4: %q, err: %v", string(c4), err))
		}

		// EOF behavior
		cEOF, err := cr.Next(1)
		if !errors.Is(err, io.EOF) {
			panic(fmt.Sprintf("expected io.EOF at end of stream, got %v", err))
		}
		if cEOF != nil {
			panic("expected nil buffer on EOF")
		}
	}

	// 4. chunkreader.ChunkReader.Next returns io.ErrUnexpectedEOF or io.EOF when stream has fewer bytes than requested
	{
		cr := chunkreader.New(strings.NewReader("short"))
		c, err := cr.Next(10)
		if !errors.Is(err, io.ErrUnexpectedEOF) {
			panic(fmt.Sprintf("expected io.ErrUnexpectedEOF, got %v", err))
		}
		if c != nil {
			panic("expected nil buffer on ErrUnexpectedEOF")
		}
	}

	// 5. chunkreader.ChunkReader.Next expands internal buffer when requested chunk exceeds initial buffer length
	{
		cfg := chunkreader.Config{MinBufLen: 16}
		largePayload := bytes.Repeat([]byte("A"), 128)
		cr, err := chunkreader.NewConfig(bytes.NewReader(largePayload), cfg)
		if err != nil {
			panic(fmt.Sprintf("unexpected error: %v", err))
		}
		chunk, err := cr.Next(128)
		if err != nil {
			panic(fmt.Sprintf("unexpected error on large chunk read: %v", err))
		}
		if len(chunk) != 128 || !bytes.Equal(chunk, largePayload) {
			panic("large chunk payload mismatch")
		}
	}

	// 6. chunkreader.ChunkReader.Next returns empty byte slice with nil error when requested length is 0
	{
		cr := chunkreader.New(strings.NewReader("non-empty"))
		chunk, err := cr.Next(0)
		if err != nil {
			panic(fmt.Sprintf("unexpected error on Next(0): %v", err))
		}
		if len(chunk) != 0 {
			panic(fmt.Sprintf("expected empty slice from Next(0), got len %d", len(chunk)))
		}
	}

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

Seeder de origen

anónimo