CodeSampleX

Sample

github.com/klauspost/compress v1.19.1: zlib.BestCompression

Verified sample for golang github.com/klauspost/compress v1.19.1: zlib.BestCompression. The contract ran on go 1.26 · linux debian/x64 · docker and passed.

sha256:052a3612da2763b5a787876d573f8032d6a7685b2c52d64652ba49fff571e2b9

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 github.com/klauspost/compress/zlib.BestCompression in pkg:golang/github.com/klauspost/compress@v1.19.1
Packages
Symbols
  • github.com/klauspost/compress/zlib.BestCompression
Created
2026-10-11T01:26:50Z

Contract

  1. zlib.BestCompression constant equals 9
  2. zlib.NewWriterLevel accepts zlib.BestCompression without error
  3. data compressed with zlib.BestCompression round-trips through zlib.NewReader without loss
  4. zlib.BestCompression compresses repetitive input to fewer bytes than the uncompressed input
  5. zlib.NewWriterLevel rejects invalid compression level exceeding zlib.BestCompression

Files

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

Download the source artifact (tar.gz)

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 github.com/klauspost/compress/zlib.BestCompression in pkg:golang/github.com/klauspost/compress@v1.19.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/klauspost/compress@v1.19.1
Demonstrate these symbols/APIs:
  - github.com/klauspost/compress/zlib.BestCompression

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:27b97ce2025ed3500f0b7fa7e7c9da5fd4cf481240396050592e75369ba365b6","contract":["zlib.BestCompression constant equals 9","zlib.NewWriterLevel accepts zlib.BestCompression without error","data compressed with zlib.BestCompression round-trips through zlib.NewReader without loss","zlib.BestCompression compresses repetitive input to fewer bytes than the uncompressed input","zlib.NewWriterLevel rejects invalid compression level exceeding zlib.BestCompression"],"goal":"verify github.com/klauspost/compress/zlib.BestCompression in pkg:golang/github.com/klauspost/compress@v1.19.1","kind":"HOW","packages":["pkg:golang/github.com/klauspost/compress@v1.19.1"],"schemaVersion":1,"symbols":["github.com/klauspost/compress/zlib.BestCompression"]},"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/klauspost/compress@v1.19.1"],"schemaVersion":1,"subject":"pkg:golang/github.com/klauspost/compress@v1.19.1","symbols":["github.com/klauspost/compress/zlib.BestCompression"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.24

require github.com/klauspost/compress v1.19.1
go.sum
github.com/klauspost/compress v1.19.1 h1:VsB4HPswih7mmZ8WleSFQ75c/Ui1M4trX5oAsJnhSlk=
github.com/klauspost/compress v1.19.1/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ=
sample.go
package sample

import (
	"bytes"
	"io"

	"github.com/klauspost/compress/zlib"
)

// CompressWithBestCompression compresses the input data using zlib.BestCompression level.
func CompressWithBestCompression(src []byte) ([]byte, error) {
	var buf bytes.Buffer
	w, err := zlib.NewWriterLevel(&buf, zlib.BestCompression)
	if err != nil {
		return nil, err
	}
	if _, err := w.Write(src); err != nil {
		_ = w.Close()
		return nil, err
	}
	if err := w.Close(); err != nil {
		return nil, err
	}
	return buf.Bytes(), nil
}

// Decompress decompresses zlib-compressed data.
func Decompress(compressed []byte) ([]byte, error) {
	r, err := zlib.NewReader(bytes.NewReader(compressed))
	if err != nil {
		return nil, err
	}
	defer r.Close()

	return io.ReadAll(r)
}

// BestCompressionLevel returns the zlib.BestCompression constant.
func BestCompressionLevel() int {
	return zlib.BestCompression
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/klauspost/compress/zlib.BestCompression in pkg:golang/github.com/klauspost/compress@v1.19.1",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/klauspost/compress@v1.19.1"
  ],
  "symbols": [
    "github.com/klauspost/compress/zlib.BestCompression"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"fmt"
	"os"

	"github.com/klauspost/compress/zlib"
	"sample"
)

func main() {
	if err := runTests(); err != nil {
		fmt.Fprintf(os.Stderr, "Contract test failed: %v\n", err)
		os.Exit(1)
	}
	fmt.Println("All contract tests passed successfully.")
}

func runTests() error {
	// Assertion 1: zlib.BestCompression constant equals 9
	if zlib.BestCompression != 9 {
		return fmt.Errorf("expected zlib.BestCompression to be 9, got %d", zlib.BestCompression)
	}
	if sample.BestCompressionLevel() != zlib.BestCompression {
		return fmt.Errorf("sample.BestCompressionLevel mismatch")
	}

	// Assertion 2: zlib.NewWriterLevel accepts zlib.BestCompression without error
	var testBuf bytes.Buffer
	writer, err := zlib.NewWriterLevel(&testBuf, zlib.BestCompression)
	if err != nil {
		return fmt.Errorf("zlib.NewWriterLevel with BestCompression failed: %w", err)
	}
	if err := writer.Close(); err != nil {
		return fmt.Errorf("writer.Close failed: %w", err)
	}

	// Assertion 3: data compressed with zlib.BestCompression round-trips through zlib.NewReader without loss
	originalData := []byte("The quick brown fox jumps over the lazy dog. Repeat: " +
		"The quick brown fox jumps over the lazy dog. Again: " +
		"The quick brown fox jumps over the lazy dog.")
	compressed, err := sample.CompressWithBestCompression(originalData)
	if err != nil {
		return fmt.Errorf("CompressWithBestCompression failed: %w", err)
	}
	decompressed, err := sample.Decompress(compressed)
	if err != nil {
		return fmt.Errorf("Decompress failed: %w", err)
	}
	if !bytes.Equal(originalData, decompressed) {
		return fmt.Errorf("decompressed data does not match original")
	}

	// Assertion 4: zlib.BestCompression compresses repetitive input to fewer bytes than the uncompressed input
	repetitiveData := bytes.Repeat([]byte("CodeSampleX reproducible verification pattern "), 100)
	repCompressed, err := sample.CompressWithBestCompression(repetitiveData)
	if err != nil {
		return fmt.Errorf("compressing repetitive data failed: %w", err)
	}
	if len(repCompressed) >= len(repetitiveData) {
		return fmt.Errorf("expected compression to reduce size: uncompressed=%d, compressed=%d", len(repetitiveData), len(repCompressed))
	}

	// Assertion 5: zlib.NewWriterLevel rejects invalid compression level exceeding zlib.BestCompression
	invalidLevel := zlib.BestCompression + 1
	var dummyBuf bytes.Buffer
	_, err = zlib.NewWriterLevel(&dummyBuf, invalidLevel)
	if err == nil {
		return fmt.Errorf("expected error for invalid compression level %d, got nil", invalidLevel)
	}

	return nil
}

Origin Seeder

anonymous