示例
go.etcd.io/bbolt v1.5.0: Tx
已验证示例 — golang go.etcd.io/bbolt v1.5.0: Tx. contract 在 go 1.26 · linux alpine/x64 · docker 上运行并通过: Tx.Writable returns true for read-write transactions and…
sha256:b4251ec8f89b797b58240775d4f73f72de0f523b6f3e49e864566e19d7449bef
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
linux 24 · ubuntu · glibc 2.39 x64 go
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| 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 |
案例
HOW- 目标
- verify go.etcd.io/bbolt.Tx in pkg:golang/go.etcd.io/bbolt@v1.5.0
- 符号
-
- go.etcd.io/bbolt.Tx
- 创建时间
- 2026-08-30T15:13:00Z
契约
- Tx.Writable returns true for read-write transactions and false for read-only transactions
- Tx.CreateBucket creates a new bucket in a writable transaction and returns ErrTxNotWritable in a read-only transaction
- Tx.Commit persists modifications and Tx.Rollback discards uncommitted modifications
- Tx.Bucket retrieves an existing bucket and returns nil for non-existent buckets
- Tx.DB returns the parent DB instance that created the transaction
文件
- PROMPT.md
- csx.json
- go.mod
- go.sum
- sample.go
- spec.json
- test/contract.go
源代码
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.Tx 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.Tx
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.
{"case":{"caseId":"case:sha256:e700f8ad66558d459eb2b1db8be11904f4f42adba9850622a81bf0f08f8631e5","contract":["Tx.Writable returns true for read-write transactions and false for read-only transactions","Tx.CreateBucket creates a new bucket in a writable transaction and returns ErrTxNotWritable in a read-only transaction","Tx.Commit persists modifications and Tx.Rollback discards uncommitted modifications","Tx.Bucket retrieves an existing bucket and returns nil for non-existent buckets","Tx.DB returns the parent DB instance that created the transaction"],"goal":"verify go.etcd.io/bbolt.Tx 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.Tx"]},"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.Tx"],"verifierAdapter":"golang@1"}
module sample
go 1.26.6
require go.etcd.io/bbolt v1.5.0
require golang.org/x/sys v0.45.0 // indirect
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=
package sample
import (
"fmt"
bolt "go.etcd.io/bbolt"
)
// OpenDB opens or creates a Bolt database at the specified path.
func OpenDB(path string) (*bolt.DB, error) {
db, err := bolt.Open(path, 0600, nil)
if err != nil {
return nil, fmt.Errorf("failed to open bolt db: %w", err)
}
return db, nil
}
// PutKV executes a writable transaction to store a key-value pair in a bucket.
func PutKV(db *bolt.DB, bucketName, key, value []byte) error {
return db.Update(func(tx *bolt.Tx) error {
b, err := tx.CreateBucketIfNotExists(bucketName)
if err != nil {
return err
}
return b.Put(key, value)
})
}
// GetKV executes a read-only transaction to retrieve a value for a key in a bucket.
func GetKV(db *bolt.DB, bucketName, key []byte) ([]byte, error) {
var val []byte
err := db.View(func(tx *bolt.Tx) error {
b := tx.Bucket(bucketName)
if b == nil {
return bolt.ErrBucketNotFound
}
v := b.Get(key)
if v != nil {
val = make([]byte, len(v))
copy(val, v)
}
return nil
})
return val, err
}
{
"schemaVersion": 1,
"goal": "verify go.etcd.io/bbolt.Tx 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.Tx"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
package main
import (
"bytes"
"errors"
"fmt"
"os"
"path/filepath"
bolt "go.etcd.io/bbolt"
"sample"
)
func main() {
tmpDir, err := os.MkdirTemp("", "bbolt-test-*")
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: failed to create temp dir: %v\n", err)
os.Exit(1)
}
defer os.RemoveAll(tmpDir)
dbPath := filepath.Join(tmpDir, "test.db")
db, err := sample.OpenDB(dbPath)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: failed to open db: %v\n", err)
os.Exit(1)
}
defer db.Close()
bucketName := []byte("users")
key := []byte("user:1001")
val := []byte("alice")
// Assertion 1: Tx.Writable returns true for read-write transactions and false for read-only transactions
rwTx, err := db.Begin(true)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: db.Begin(true) failed: %v\n", err)
os.Exit(1)
}
if !rwTx.Writable() {
fmt.Fprintf(os.Stderr, "FAIL: expected rwTx.Writable() to be true\n")
os.Exit(1)
}
roTx, err := db.Begin(false)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: db.Begin(false) failed: %v\n", err)
os.Exit(1)
}
if roTx.Writable() {
fmt.Fprintf(os.Stderr, "FAIL: expected roTx.Writable() to be false\n")
os.Exit(1)
}
// Assertion 2: Tx.CreateBucket creates a new bucket in a writable transaction and returns ErrTxNotWritable in a read-only transaction
_, err = roTx.CreateBucket(bucketName)
if !errors.Is(err, bolt.ErrTxNotWritable) {
fmt.Fprintf(os.Stderr, "FAIL: expected ErrTxNotWritable on read-only transaction, got: %v\n", err)
os.Exit(1)
}
if err := roTx.Rollback(); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: roTx.Rollback() failed: %v\n", err)
os.Exit(1)
}
b, err := rwTx.CreateBucket(bucketName)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: rwTx.CreateBucket failed: %v\n", err)
os.Exit(1)
}
if b == nil {
fmt.Fprintf(os.Stderr, "FAIL: created bucket is nil\n")
os.Exit(1)
}
if err := b.Put(key, val); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: b.Put failed: %v\n", err)
os.Exit(1)
}
// Assertion 3: Tx.Commit persists modifications and Tx.Rollback discards uncommitted modifications
if err := rwTx.Commit(); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: rwTx.Commit failed: %v\n", err)
os.Exit(1)
}
gotVal, err := sample.GetKV(db, bucketName, key)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: GetKV failed: %v\n", err)
os.Exit(1)
}
if !bytes.Equal(gotVal, val) {
fmt.Fprintf(os.Stderr, "FAIL: expected value %q, got %q\n", string(val), string(gotVal))
os.Exit(1)
}
rollbackTx, err := db.Begin(true)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: db.Begin(true) failed: %v\n", err)
os.Exit(1)
}
bRollback := rollbackTx.Bucket(bucketName)
if err := bRollback.Put([]byte("temp_key"), []byte("temp_val")); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: put temp_key failed: %v\n", err)
os.Exit(1)
}
if err := rollbackTx.Rollback(); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: rollbackTx.Rollback failed: %v\n", err)
os.Exit(1)
}
tempVal, err := sample.GetKV(db, bucketName, []byte("temp_key"))
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: GetKV for temp_key failed: %v\n", err)
os.Exit(1)
}
if tempVal != nil {
fmt.Fprintf(os.Stderr, "FAIL: rolled back key should be nil, got: %q\n", string(tempVal))
os.Exit(1)
}
// Assertion 4: Tx.Bucket retrieves an existing bucket and returns nil for non-existent buckets
err = db.View(func(tx *bolt.Tx) error {
if tx.Bucket(bucketName) == nil {
return fmt.Errorf("expected existing bucket to be non-nil")
}
if tx.Bucket([]byte("non_existent_bucket")) != nil {
return fmt.Errorf("expected non-existent bucket to be nil")
}
return nil
})
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: Tx.Bucket assertions failed: %v\n", err)
os.Exit(1)
}
// Assertion 5: Tx.DB returns the parent DB instance that created the transaction
err = db.View(func(tx *bolt.Tx) error {
if tx.DB() != db {
return fmt.Errorf("expected tx.DB() to match parent db")
}
return nil
})
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: tx.DB() assertion failed: %v\n", err)
os.Exit(1)
}
fmt.Println("PASS: go.etcd.io/bbolt.Tx contract assertions passed")
}
原始种子者
匿名