CodeSampleX

Exemple

github.com/jackc/chunkreader/v2 v2.0.1

Échantillon vérifié pour golang github.com/jackc/chunkreader/v2 v2.0.1. Le contrat s'est exécuté sur go 1.26 · linux alpine/x64 · docker et a réussi.

sha256:84a32428bdea7edc4f8e47757a2535121c3d9e323e0fca9f3a6dc0f189fcc873

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
2
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 go

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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-23
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-07

Cas

HOW
Objectif
verify pkg:golang/github.com/jackc/chunkreader/v2@v2.0.1
Paquets
Créé
2026-08-23T17:19:13Z

Contrat

  1. chunkreader.New initializes a ChunkReader with default 8192-byte minimum buffer length wrapping an io.Reader
  2. chunkreader.NewConfig initializes a ChunkReader with a custom Config specifying MinBufLen
  3. chunkreader.ChunkReader.Next returns consecutive slices of requested byte lengths from the underlying stream
  4. chunkreader.ChunkReader.Next expands internal buffer when requested chunk size exceeds MinBufLen
  5. chunkreader.ChunkReader.Next returns io.ErrUnexpectedEOF or io.EOF when underlying reader has fewer bytes than requested
  6. chunkreader.ChunkReader.Next guarantees caller ownership of returned byte slices across subsequent reads

Fichiers

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

Télécharger l’artefact source (tar.gz)

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

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/jackc/chunkreader/v2@v2.0.1
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:a1ac5cce644ba9cd35ac020f879d19b1c3b370c2b0ac6f0c59ad4d29172262d6","contract":["chunkreader.New initializes a ChunkReader with default 8192-byte minimum buffer length wrapping an io.Reader","chunkreader.NewConfig initializes a ChunkReader with a custom Config specifying MinBufLen","chunkreader.ChunkReader.Next returns consecutive slices of requested byte lengths from the underlying stream","chunkreader.ChunkReader.Next expands internal buffer when requested chunk size exceeds MinBufLen","chunkreader.ChunkReader.Next returns io.ErrUnexpectedEOF or io.EOF when underlying reader has fewer bytes than requested","chunkreader.ChunkReader.Next guarantees caller ownership of returned byte slices across subsequent reads"],"goal":"verify pkg:golang/github.com/jackc/chunkreader/v2@v2.0.1","kind":"HOW","packages":["pkg:golang/github.com/jackc/chunkreader/v2@v2.0.1"],"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/jackc/chunkreader/v2@v2.0.1"],"schemaVersion":1,"subject":"pkg:golang/github.com/jackc/chunkreader/v2@v2.0.1","verifierAdapter":"golang@1"}
go.mod
module sample-chunkreader

go 1.22

require github.com/jackc/chunkreader/v2 v2.0.1
go.sum
github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8=
github.com/jackc/chunkreader/v2 v2.0.1/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
main.go
package main

import (
	"bytes"
	"fmt"

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

func main() {
	data := []byte("example payload stream for chunkreader")
	r := bytes.NewReader(data)
	cr := chunkreader.New(r)

	chunk, err := cr.Next(7)
	if err != nil {
		fmt.Printf("read 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.1",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/jackc/chunkreader/v2@v2.0.1"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.go
package main

import (
	"bytes"
	"errors"
	"fmt"
	"io"
	"os"

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

func main() {
	// Assertion 1: chunkreader.New initializes a ChunkReader with default 8192-byte minimum buffer length wrapping an io.Reader
	{
		data := []byte("hello world")
		r := bytes.NewReader(data)
		cr := chunkreader.New(r)
		if cr == nil {
			fmt.Fprintf(os.Stderr, "Assertion 1 failed: cr is nil\n")
			os.Exit(1)
		}
		chunk, err := cr.Next(5)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Assertion 1 failed on Next: %v\n", err)
			os.Exit(1)
		}
		if !bytes.Equal(chunk, []byte("hello")) {
			fmt.Fprintf(os.Stderr, "Assertion 1 failed: expected 'hello', got '%s'\n", string(chunk))
			os.Exit(1)
		}
	}

	// Assertion 2: chunkreader.NewConfig initializes a ChunkReader with a custom Config specifying MinBufLen
	{
		data := []byte("custom buffer size test")
		r := bytes.NewReader(data)
		cfg := chunkreader.Config{MinBufLen: 16}
		cr, err := chunkreader.NewConfig(r, cfg)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Assertion 2 failed: %v\n", err)
			os.Exit(1)
		}
		if cr == nil {
			fmt.Fprintf(os.Stderr, "Assertion 2 failed: cr is nil\n")
			os.Exit(1)
		}
		chunk, err := cr.Next(6)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Assertion 2 failed on Next: %v\n", err)
			os.Exit(1)
		}
		if !bytes.Equal(chunk, []byte("custom")) {
			fmt.Fprintf(os.Stderr, "Assertion 2 failed: expected 'custom', got '%s'\n", string(chunk))
			os.Exit(1)
		}
	}

	// Assertion 3: chunkreader.ChunkReader.Next returns consecutive slices of requested byte lengths from the underlying stream
	{
		payload := []byte("0123456789ABCDEF")
		r := bytes.NewReader(payload)
		cr := chunkreader.New(r)

		part1, err := cr.Next(4)
		if err != nil || !bytes.Equal(part1, []byte("0123")) {
			fmt.Fprintf(os.Stderr, "Assertion 3 failed part1: %v, got %s\n", err, string(part1))
			os.Exit(1)
		}

		part2, err := cr.Next(6)
		if err != nil || !bytes.Equal(part2, []byte("456789")) {
			fmt.Fprintf(os.Stderr, "Assertion 3 failed part2: %v, got %s\n", err, string(part2))
			os.Exit(1)
		}

		part3, err := cr.Next(6)
		if err != nil || !bytes.Equal(part3, []byte("ABCDEF")) {
			fmt.Fprintf(os.Stderr, "Assertion 3 failed part3: %v, got %s\n", err, string(part3))
			os.Exit(1)
		}
	}

	// Assertion 4: chunkreader.ChunkReader.Next expands internal buffer when requested chunk size exceeds MinBufLen
	{
		largeData := make([]byte, 32)
		for i := range largeData {
			largeData[i] = byte('A' + (i % 26))
		}
		r := bytes.NewReader(largeData)
		cr, err := chunkreader.NewConfig(r, chunkreader.Config{MinBufLen: 8})
		if err != nil {
			fmt.Fprintf(os.Stderr, "Assertion 4 failed NewConfig: %v\n", err)
			os.Exit(1)
		}

		// Request 20 bytes (larger than MinBufLen of 8)
		chunk, err := cr.Next(20)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Assertion 4 failed Next: %v\n", err)
			os.Exit(1)
		}
		if !bytes.Equal(chunk, largeData[:20]) {
			fmt.Fprintf(os.Stderr, "Assertion 4 failed: content mismatch\n")
			os.Exit(1)
		}
	}

	// Assertion 5: chunkreader.ChunkReader.Next returns io.ErrUnexpectedEOF or io.EOF when underlying reader has fewer bytes than requested
	{
		shortData := []byte("short")
		r := bytes.NewReader(shortData)
		cr := chunkreader.New(r)

		chunk, err := cr.Next(10)
		if err == nil {
			fmt.Fprintf(os.Stderr, "Assertion 5 failed: expected error, got nil error and chunk %v\n", chunk)
			os.Exit(1)
		}
		if chunk != nil {
			fmt.Fprintf(os.Stderr, "Assertion 5 failed: expected nil buffer on error, got %v\n", chunk)
			os.Exit(1)
		}
		if !errors.Is(err, io.ErrUnexpectedEOF) && !errors.Is(err, io.EOF) {
			fmt.Fprintf(os.Stderr, "Assertion 5 failed: expected EOF error, got %v\n", err)
			os.Exit(1)
		}
	}

	// Assertion 6: chunkreader.ChunkReader.Next guarantees caller ownership of returned byte slices across subsequent reads
	{
		data := []byte("first_chunk_data!second_chunk_data#third_chunk_data$")
		r := bytes.NewReader(data)
		cr, err := chunkreader.NewConfig(r, chunkreader.Config{MinBufLen: 16})
		if err != nil {
			fmt.Fprintf(os.Stderr, "Assertion 6 failed: %v\n", err)
			os.Exit(1)
		}

		c1, err := cr.Next(17)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Assertion 6 failed c1: %v\n", err)
			os.Exit(1)
		}
		c1Copy := string(c1)

		c2, err := cr.Next(18)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Assertion 6 failed c2: %v\n", err)
			os.Exit(1)
		}

		if string(c1) != c1Copy || string(c1) != "first_chunk_data!" {
			fmt.Fprintf(os.Stderr, "Assertion 6 failed: c1 mutated. expected 'first_chunk_data!', got '%s'\n", string(c1))
			os.Exit(1)
		}
		if string(c2) != "second_chunk_data#" {
			fmt.Fprintf(os.Stderr, "Assertion 6 failed: c2 mismatch. expected 'second_chunk_data#', got '%s'\n", string(c2))
			os.Exit(1)
		}
	}

	fmt.Println("PASS: pkg:golang/github.com/jackc/chunkreader/v2@v2.0.1 contract passed")
}

Seeder d'origine

anonyme