CodeSampleX

Exemplo

github.com/peterbourgon/diskv/v3 v3.0.1

Amostra verificada para golang github.com/peterbourgon/diskv/v3 v3.0.1. O contrato rodou em go 1.26 · linux debian/x64 · docker e passou.

sha256:36e1f144075b72b3c19985a7939f50314f1e6b42f100957d3799a890739fbaee

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
1
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 debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-09-16

Caso

HOW
Objetivo
verify pkg:golang/github.com/peterbourgon/diskv/v3@v3.0.1
Pacotes
Criado
2026-09-16T01:44:38Z

Contrato

  1. diskv.New creates a Diskv instance with configured options
  2. diskv.Diskv.Write writes data to disk and Read retrieves it
  3. diskv.Diskv.Has verifies key presence in the store
  4. diskv.Diskv.Keys streams all stored keys over a channel
  5. diskv.Diskv.Erase removes a specific key from the store
  6. diskv.Diskv.EraseAll removes all keys from the store

Arquivos

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • sample.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/peterbourgon/diskv/v3@v3.0.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/peterbourgon/diskv/v3@v3.0.1

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:45e6b0e991f5080d13c74852e049ec3a97f954776de8e437614ba3e84d77f148","contract":["diskv.New creates a Diskv instance with configured options","diskv.Diskv.Write writes data to disk and Read retrieves it","diskv.Diskv.Has verifies key presence in the store","diskv.Diskv.Keys streams all stored keys over a channel","diskv.Diskv.Erase removes a specific key from the store","diskv.Diskv.EraseAll removes all keys from the store"],"goal":"verify pkg:golang/github.com/peterbourgon/diskv/v3@v3.0.1","kind":"HOW","packages":["pkg:golang/github.com/peterbourgon/diskv/v3@v3.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/peterbourgon/diskv/v3@v3.0.1"],"schemaVersion":1,"subject":"pkg:golang/github.com/peterbourgon/diskv/v3@v3.0.1","verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require github.com/peterbourgon/diskv/v3 v3.0.1

require github.com/google/btree v1.0.0 // indirect
go.sum
github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/peterbourgon/diskv/v3 v3.0.1 h1:x06SQA46+PKIUftmEujdwSEpIx8kR+M9eLYsUxeYveU=
github.com/peterbourgon/diskv/v3 v3.0.1/go.mod h1:kJ5Ny7vLdARGU3WUuy6uzO6T0nb/2gWcT1JiBvRmb5o=
sample.go
package sample

import (
	"github.com/peterbourgon/diskv/v3"
)

// NewStore creates a new Diskv store with a flat directory structure.
func NewStore(basePath string, cacheSizeMax uint64) *diskv.Diskv {
	flatTransform := func(s string) []string {
		return []string{}
	}
	return diskv.New(diskv.Options{
		BasePath:     basePath,
		Transform:    flatTransform,
		CacheSizeMax: cacheSizeMax,
	})
}

// WriteEntry stores a byte slice at the specified key.
func WriteEntry(d *diskv.Diskv, key string, val []byte) error {
	return d.Write(key, val)
}

// ReadEntry retrieves the byte slice stored at the specified key.
func ReadEntry(d *diskv.Diskv, key string) ([]byte, error) {
	return d.Read(key)
}

// HasEntry checks if the specified key exists in the store.
func HasEntry(d *diskv.Diskv, key string) bool {
	return d.Has(key)
}

// EraseEntry deletes the specified key and its data.
func EraseEntry(d *diskv.Diskv, key string) error {
	return d.Erase(key)
}

// EraseAllEntries removes all stored keys and data.
func EraseAllEntries(d *diskv.Diskv) error {
	return d.EraseAll()
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/github.com/peterbourgon/diskv/v3@v3.0.1",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/peterbourgon/diskv/v3@v3.0.1"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"fmt"
	"os"
	"path/filepath"

	"example.com/sample"
)

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

func runContractTests() error {
	tmpDir, err := os.MkdirTemp("", "diskv-contract-*")
	if err != nil {
		return fmt.Errorf("failed to create temp dir: %w", err)
	}
	defer os.RemoveAll(tmpDir)

	storeDir := filepath.Join(tmpDir, "store")

	// Assertion 1: diskv.New creates a Diskv instance with configured options
	store := sample.NewStore(storeDir, 1024*1024)
	if store == nil {
		return fmt.Errorf("diskv.New returned nil")
	}
	if store.BasePath != storeDir {
		return fmt.Errorf("expected BasePath %q, got %q", storeDir, store.BasePath)
	}
	if store.CacheSizeMax != 1024*1024 {
		return fmt.Errorf("expected CacheSizeMax %d, got %d", 1024*1024, store.CacheSizeMax)
	}

	// Assertion 2: diskv.Diskv.Write writes data to disk and Read retrieves it
	testKey := "alpha"
	testVal := []byte("payload-value-1234")
	if err := sample.WriteEntry(store, testKey, testVal); err != nil {
		return fmt.Errorf("WriteEntry failed: %w", err)
	}

	readVal, err := sample.ReadEntry(store, testKey)
	if err != nil {
		return fmt.Errorf("ReadEntry failed: %w", err)
	}
	if !bytes.Equal(readVal, testVal) {
		return fmt.Errorf("expected value %q, got %q", string(testVal), string(readVal))
	}

	// Verify file actually exists on disk
	expectedFile := filepath.Join(storeDir, testKey)
	if _, err := os.Stat(expectedFile); err != nil {
		return fmt.Errorf("expected file %q on disk: %w", expectedFile, err)
	}

	// Assertion 3: diskv.Diskv.Has verifies key presence in the store
	if !sample.HasEntry(store, testKey) {
		return fmt.Errorf("HasEntry returned false for existing key %q", testKey)
	}
	if sample.HasEntry(store, "nonexistent-key") {
		return fmt.Errorf("HasEntry returned true for nonexistent key")
	}

	// Assertion 4: diskv.Diskv.Keys streams all stored keys over a channel
	testKey2 := "beta"
	testVal2 := []byte("payload-beta")
	if err := sample.WriteEntry(store, testKey2, testVal2); err != nil {
		return fmt.Errorf("WriteEntry key2 failed: %w", err)
	}

	seenKeys := make(map[string]bool)
	for k := range store.Keys(nil) {
		seenKeys[k] = true
	}
	if !seenKeys[testKey] || !seenKeys[testKey2] {
		return fmt.Errorf("Keys did not yield expected keys: got %v", seenKeys)
	}

	// Assertion 5: diskv.Diskv.Erase removes a specific key from the store
	if err := sample.EraseEntry(store, testKey); err != nil {
		return fmt.Errorf("EraseEntry failed: %w", err)
	}
	if sample.HasEntry(store, testKey) {
		return fmt.Errorf("HasEntry returned true after key %q was erased", testKey)
	}
	if _, err := sample.ReadEntry(store, testKey); err == nil {
		return fmt.Errorf("ReadEntry succeeded for erased key %q, expected error", testKey)
	}

	// Key2 should still exist
	if !sample.HasEntry(store, testKey2) {
		return fmt.Errorf("key2 unexpectedly missing after erasing key1")
	}

	// Assertion 6: diskv.Diskv.EraseAll removes all keys from the store
	if err := sample.EraseAllEntries(store); err != nil {
		return fmt.Errorf("EraseAllEntries failed: %w", err)
	}
	if sample.HasEntry(store, testKey2) {
		return fmt.Errorf("HasEntry returned true for key2 after EraseAll")
	}
	keysAfterEraseAll := 0
	for range store.Keys(nil) {
		keysAfterEraseAll++
	}
	if keysAfterEraseAll != 0 {
		return fmt.Errorf("Keys yielded %d items after EraseAll, expected 0", keysAfterEraseAll)
	}

	return nil
}

Seeder de origem

anônimo