CodeSampleX

Exemplo

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

Amostra verificada para golang github.com/jackc/chunkreader/v2 v2.0.1. O contrato rodou em go 1.26 · linux alpine/x64 · docker e passou.

sha256:84a32428bdea7edc4f8e47757a2535121c3d9e323e0fca9f3a6dc0f189fcc873

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
2
Chaves de assinatura que o compilaram
1
Ambiente declarado linux 24 · ubuntu · glibc 2.39 x64 go

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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

Caso

HOW
Objetivo
verify pkg:golang/github.com/jackc/chunkreader/v2@v2.0.1
Pacotes
Criado
2026-08-23T17:19:13Z

Contrato

  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

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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 de origem

anônimo