CodeSampleX

Beispiel

go.etcd.io/bbolt v1.5.0: Open

Verifiziertes Beispiel für golang go.etcd.io/bbolt v1.5.0: Open. Der Vertrag lief auf go 1.26 · linux alpine/x64 · docker und bestand.

sha256:c73954db4af2c50c5f411ae0097c9a40ed58458842dde577e24cedc61b49f8ea

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung linux 24 · ubuntu · glibc 2.39 x64 go

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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-30

Fall

HOW
Ziel
verify go.etcd.io/bbolt.Open in pkg:golang/go.etcd.io/bbolt@v1.5.0
Pakete
Symbole
  • go.etcd.io/bbolt.Open
Erstellt
2026-08-30T15:05:20Z

Contract

  1. bbolt.Open opens or creates a Bolt database file at the specified path with file mode
  2. bbolt.DB allows reading and writing key-value pairs in buckets
  3. bbolt.DB.Close closes the database file and releases locks
  4. bbolt.Open with Options.ReadOnly opens the database in read-only mode
  5. bbolt.DB.Update returns bbolt.ErrDatabaseReadOnly when database is opened in read-only mode

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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 go.etcd.io/bbolt.Open in pkg:golang/go.etcd.io/bbolt@v1.5.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/go.etcd.io/bbolt@v1.5.0
Demonstrate these symbols/APIs:
  - go.etcd.io/bbolt.Open
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:4798058742ec59cbabb67f0a45b1ac432f6a2872003b09ce3b532eb01b18615f","contract":["bbolt.Open opens or creates a Bolt database file at the specified path with file mode","bbolt.DB allows reading and writing key-value pairs in buckets","bbolt.DB.Close closes the database file and releases locks","bbolt.Open with Options.ReadOnly opens the database in read-only mode","bbolt.DB.Update returns bbolt.ErrDatabaseReadOnly when database is opened in read-only mode"],"goal":"verify go.etcd.io/bbolt.Open in pkg:golang/go.etcd.io/bbolt@v1.5.0","kind":"HOW","packages":["pkg:golang/go.etcd.io/bbolt@v1.5.0"],"schemaVersion":1,"symbols":["go.etcd.io/bbolt.Open"]},"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/go.etcd.io/bbolt@v1.5.0"],"schemaVersion":1,"subject":"pkg:golang/go.etcd.io/bbolt@v1.5.0","symbols":["go.etcd.io/bbolt.Open"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.25.0

require go.etcd.io/bbolt v1.5.0

require golang.org/x/sys v0.45.0 // indirect
go.sum
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
go.etcd.io/bbolt v1.5.0 h1:S7GAl7Fxv12yohbwFfIbQCGDWbQbtDGPET4P/bD4lxU=
go.etcd.io/bbolt v1.5.0/go.mod h1:mkltfYE5aUHQxUct9N9V+Kp7aSjFqjgrhcXIS70Lrdk=
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY=
golang.org/x/sys v0.45.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
sample.go
package sample

import (
	"errors"
	"fmt"
	"time"

	bolt "go.etcd.io/bbolt"
)

// OpenDatabase opens a Bolt key-value database with the given options.
func OpenDatabase(path string, readOnly bool, timeout time.Duration) (*bolt.DB, error) {
	opts := &bolt.Options{
		ReadOnly: readOnly,
		Timeout:  timeout,
	}
	return bolt.Open(path, 0600, opts)
}

// PutValue writes a key-value pair to a specified bucket.
func PutValue(db *bolt.DB, bucketName, key, value string) error {
	return db.Update(func(tx *bolt.Tx) error {
		b, err := tx.CreateBucketIfNotExists([]byte(bucketName))
		if err != nil {
			return fmt.Errorf("create bucket: %w", err)
		}
		return b.Put([]byte(key), []byte(value))
	})
}

// GetValue reads a key from a specified bucket.
func GetValue(db *bolt.DB, bucketName, key string) (string, error) {
	var val string
	err := db.View(func(tx *bolt.Tx) error {
		b := tx.Bucket([]byte(bucketName))
		if b == nil {
			return errors.New("bucket not found")
		}
		data := b.Get([]byte(key))
		if data == nil {
			return errors.New("key not found")
		}
		val = string(data)
		return nil
	})
	return val, err
}

// CloseDatabase closes the opened Bolt database.
func CloseDatabase(db *bolt.DB) error {
	if db == nil {
		return nil
	}
	return db.Close()
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify go.etcd.io/bbolt.Open in pkg:golang/go.etcd.io/bbolt@v1.5.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/go.etcd.io/bbolt@v1.5.0"
  ],
  "symbols": [
    "go.etcd.io/bbolt.Open"
  ],
  "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 (
	"errors"
	"fmt"
	"os"
	"path/filepath"
	"time"

	bolt "go.etcd.io/bbolt"
	"sample"
)

func main() {
	tmpDir, err := os.MkdirTemp("", "bbolt-test-*")
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to create temp dir: %v\n", err)
		os.Exit(1)
	}
	defer os.RemoveAll(tmpDir)

	dbPath := filepath.Join(tmpDir, "test.db")

	// Assertion 1: bbolt.Open opens or creates a Bolt database file at the specified path with file mode
	db, err := sample.OpenDatabase(dbPath, false, 1*time.Second)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to open database: %v\n", err)
		os.Exit(1)
	}
	if db == nil {
		fmt.Fprintf(os.Stderr, "expected db instance, got nil\n")
		os.Exit(1)
	}
	var _ *bolt.DB = db

	// Check file created on disk
	if _, err := os.Stat(dbPath); os.IsNotExist(err) {
		fmt.Fprintf(os.Stderr, "database file was not created: %v\n", err)
		os.Exit(1)
	}

	// Assertion 2: bbolt.DB allows reading and writing key-value pairs in buckets
	bucketName := "settings"
	key := "theme"
	expectedVal := "dark"

	if err := sample.PutValue(db, bucketName, key, expectedVal); err != nil {
		fmt.Fprintf(os.Stderr, "PutValue failed: %v\n", err)
		os.Exit(1)
	}

	val, err := sample.GetValue(db, bucketName, key)
	if err != nil {
		fmt.Fprintf(os.Stderr, "GetValue failed: %v\n", err)
		os.Exit(1)
	}
	if val != expectedVal {
		fmt.Fprintf(os.Stderr, "expected value %q, got %q\n", expectedVal, val)
		os.Exit(1)
	}

	// Assertion 3: bbolt.DB.Close closes the database file and releases locks
	if err := sample.CloseDatabase(db); err != nil {
		fmt.Fprintf(os.Stderr, "CloseDatabase failed: %v\n", err)
		os.Exit(1)
	}

	// Assertion 4: bbolt.Open with Options.ReadOnly opens the database in read-only mode
	roDB, err := sample.OpenDatabase(dbPath, true, 1*time.Second)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to open database in read-only mode: %v\n", err)
		os.Exit(1)
	}
	defer sample.CloseDatabase(roDB)

	// Can read existing data
	roVal, err := sample.GetValue(roDB, bucketName, key)
	if err != nil {
		fmt.Fprintf(os.Stderr, "GetValue in read-only mode failed: %v\n", err)
		os.Exit(1)
	}
	if roVal != expectedVal {
		fmt.Fprintf(os.Stderr, "expected read-only value %q, got %q\n", expectedVal, roVal)
		os.Exit(1)
	}

	// Assertion 5: bbolt.DB.Update returns bbolt.ErrDatabaseReadOnly when database is opened in read-only mode
	writeErr := sample.PutValue(roDB, bucketName, "newKey", "newValue")
	if writeErr == nil {
		fmt.Fprintf(os.Stderr, "expected write transaction in read-only mode to fail, but it succeeded\n")
		os.Exit(1)
	}
	if !errors.Is(writeErr, bolt.ErrDatabaseReadOnly) {
		fmt.Fprintf(os.Stderr, "expected ErrDatabaseReadOnly, got %v\n", writeErr)
		os.Exit(1)
	}

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

Ursprungs-Seeder

anonym