Пример
github.com/rcrowley/go-metrics v0.0.0-20250401214520-65e299d6c5c9
Проверенный пример — golang github.com/rcrowley/go-metrics v0.0.0-20250401214520-65e299d6c5c9. Контракт выполнен на go 1.26 · linux debian/x64 · docker и…
sha256:9a2d0f7212e977b930d7763f445dc0102088d6b0035b2603e8b0ae6e6375625f
Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла.
Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди.
MIT-0
Свидетельства выполнения
Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.
- Основа свидетельства
- Подписанный контракт пройден
- Квитанции проверки
- 1
- Ключи подписи, собравшие его
- 1
Заявленная среда
linux 24 · ubuntu · glibc 2.39 x64 go
Среды запусков проверки
| Окружение | Контракт | Этапы | Запуск |
|---|---|---|---|
| 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-02 |
Кейс
HOW- Цель
- verify pkg:golang/github.com/rcrowley/go-metrics@v0.0.0-20250401214520-65e299d6c5c9
- Создан
- 2026-09-02T20:37:44Z
Контракт
- metrics.NewGauge constructs an int64 gauge with initial value 0
- Gauge.Update updates the stored int64 value
- Gauge.Value retrieves the current stored int64 value
- Gauge.Snapshot captures an immutable point-in-time snapshot of the gauge
- metrics.NewGaugeFloat64 constructs a float64 gauge with initial value 0.0
- GaugeFloat64.Update and Value store and retrieve float64 values
- metrics.NewFunctionalGauge evaluates a callback function to return dynamic values
- metrics.GetOrRegisterGauge registers a new gauge or returns an existing one from a registry
Файлы
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.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 pkg:golang/github.com/rcrowley/go-metrics@v0.0.0-20250401214520-65e299d6c5c9
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/rcrowley/go-metrics@v0.0.0-20250401214520-65e299d6c5c9
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:9254298e8182305dd05b987fdea712ebcd17e624094088da047e278c80f6e4ca","contract":["metrics.NewGauge constructs an int64 gauge with initial value 0","Gauge.Update updates the stored int64 value","Gauge.Value retrieves the current stored int64 value","Gauge.Snapshot captures an immutable point-in-time snapshot of the gauge","metrics.NewGaugeFloat64 constructs a float64 gauge with initial value 0.0","GaugeFloat64.Update and Value store and retrieve float64 values","metrics.NewFunctionalGauge evaluates a callback function to return dynamic values","metrics.GetOrRegisterGauge registers a new gauge or returns an existing one from a registry"],"goal":"verify pkg:golang/github.com/rcrowley/go-metrics@v0.0.0-20250401214520-65e299d6c5c9","kind":"HOW","packages":["pkg:golang/github.com/rcrowley/go-metrics@v0.0.0-20250401214520-65e299d6c5c9"],"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/rcrowley/go-metrics@v0.0.0-20250401214520-65e299d6c5c9"],"schemaVersion":1,"subject":"pkg:golang/github.com/rcrowley/go-metrics@v0.0.0-20250401214520-65e299d6c5c9","verifierAdapter":"golang@1"}
module example.com/sample
go 1.22
require github.com/rcrowley/go-metrics v0.0.0-20250401214520-65e299d6c5c9
github.com/rcrowley/go-metrics v0.0.0-20250401214520-65e299d6c5c9 h1:bsUq1dX0N8AOIL7EB/X911+m4EHsnWEHeJ0c+3TTBrg=
github.com/rcrowley/go-metrics v0.0.0-20250401214520-65e299d6c5c9/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
package main
import (
"fmt"
"github.com/rcrowley/go-metrics"
)
func main() {
// Create a new metrics registry
registry := metrics.NewRegistry()
// Create and register a standard int64 gauge
gauge := metrics.NewGauge()
if err := registry.Register("queue.size", gauge); err != nil {
panic(err)
}
gauge.Update(42)
// Create and register a float64 gauge
gaugeFloat := metrics.NewGaugeFloat64()
if err := registry.Register("cpu.load", gaugeFloat); err != nil {
panic(err)
}
gaugeFloat.Update(0.75)
// Register or get an existing gauge
cachedGauge := metrics.GetOrRegisterGauge("memory.used_mb", registry)
cachedGauge.Update(1024)
// Retrieve and print gauge values
g := registry.Get("queue.size").(metrics.Gauge)
gf := registry.Get("cpu.load").(metrics.GaugeFloat64)
gm := registry.Get("memory.used_mb").(metrics.Gauge)
fmt.Printf("queue.size: %d\n", g.Value())
fmt.Printf("cpu.load: %.2f\n", gf.Value())
fmt.Printf("memory.used_mb: %d\n", gm.Value())
}
{
"schemaVersion": 1,
"goal": "verify pkg:golang/github.com/rcrowley/go-metrics@v0.0.0-20250401214520-65e299d6c5c9",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/rcrowley/go-metrics@v0.0.0-20250401214520-65e299d6c5c9"
]
}
package main
import (
"fmt"
"math"
"os"
"github.com/rcrowley/go-metrics"
)
func main() {
// 1. metrics.NewGauge constructs an int64 gauge with initial value 0
g := metrics.NewGauge()
if g == nil {
fmt.Fprintf(os.Stderr, "metrics.NewGauge returned nil\n")
os.Exit(1)
}
if g.Value() != 0 {
fmt.Fprintf(os.Stderr, "expected initial gauge value 0, got %d\n", g.Value())
os.Exit(1)
}
// 2. Gauge.Update updates the stored int64 value
g.Update(42)
if g.Value() != 42 {
fmt.Fprintf(os.Stderr, "expected gauge value 42, got %d\n", g.Value())
os.Exit(1)
}
g.Update(-100)
if g.Value() != -100 {
fmt.Fprintf(os.Stderr, "expected gauge value -100, got %d\n", g.Value())
os.Exit(1)
}
// 3. Gauge.Value retrieves the current stored int64 value
g.Update(999999)
if val := g.Value(); val != 999999 {
fmt.Fprintf(os.Stderr, "expected gauge value 999999, got %d\n", val)
os.Exit(1)
}
// 4. Gauge.Snapshot captures an immutable point-in-time snapshot of the gauge
g.Update(500)
snap := g.Snapshot()
if snap == nil || snap.Value() != 500 {
fmt.Fprintf(os.Stderr, "expected snapshot value 500, got %v\n", snap)
os.Exit(1)
}
g.Update(1000)
if snap.Value() != 500 {
fmt.Fprintf(os.Stderr, "expected snapshot value to remain 500 after gauge update, got %d\n", snap.Value())
os.Exit(1)
}
panicked := false
func() {
defer func() {
if recover() != nil {
panicked = true
}
}()
snap.Update(2000)
}()
if !panicked {
fmt.Fprintf(os.Stderr, "expected snap.Update to panic on snapshot\n")
os.Exit(1)
}
// 5. metrics.NewGaugeFloat64 constructs a float64 gauge with initial value 0.0
gf := metrics.NewGaugeFloat64()
if gf == nil {
fmt.Fprintf(os.Stderr, "metrics.NewGaugeFloat64 returned nil\n")
os.Exit(1)
}
if gf.Value() != 0.0 {
fmt.Fprintf(os.Stderr, "expected initial float64 gauge value 0.0, got %f\n", gf.Value())
os.Exit(1)
}
// 6. GaugeFloat64.Update and Value store and retrieve float64 values
gf.Update(3.14159)
if math.Abs(gf.Value()-3.14159) > 1e-9 {
fmt.Fprintf(os.Stderr, "expected float64 gauge value 3.14159, got %f\n", gf.Value())
os.Exit(1)
}
gfSnap := gf.Snapshot()
if math.Abs(gfSnap.Value()-3.14159) > 1e-9 {
fmt.Fprintf(os.Stderr, "expected float64 snapshot value 3.14159, got %f\n", gfSnap.Value())
os.Exit(1)
}
gf.Update(2.71828)
if math.Abs(gfSnap.Value()-3.14159) > 1e-9 {
fmt.Fprintf(os.Stderr, "expected float64 snapshot to remain unchanged, got %f\n", gfSnap.Value())
os.Exit(1)
}
gfPanicked := false
func() {
defer func() {
if recover() != nil {
gfPanicked = true
}
}()
gfSnap.Update(1.0)
}()
if !gfPanicked {
fmt.Fprintf(os.Stderr, "expected gfSnap.Update to panic on snapshot\n")
os.Exit(1)
}
// 7. metrics.NewFunctionalGauge evaluates a callback function to return dynamic values
dynamicCount := int64(10)
fg := metrics.NewFunctionalGauge(func() int64 {
return dynamicCount * 2
})
if fg == nil || fg.Value() != 20 {
fmt.Fprintf(os.Stderr, "expected functional gauge value 20, got %v\n", fg)
os.Exit(1)
}
dynamicCount = 25
if fg.Value() != 50 {
fmt.Fprintf(os.Stderr, "expected updated functional gauge value 50, got %d\n", fg.Value())
os.Exit(1)
}
// 8. metrics.GetOrRegisterGauge registers a new gauge or returns an existing one from a registry
reg := metrics.NewRegistry()
rg1 := metrics.GetOrRegisterGauge("app.worker_count", reg)
if rg1 == nil {
fmt.Fprintf(os.Stderr, "GetOrRegisterGauge returned nil\n")
os.Exit(1)
}
rg1.Update(8)
rg2 := metrics.GetOrRegisterGauge("app.worker_count", reg)
if rg2.Value() != 8 {
fmt.Fprintf(os.Stderr, "expected existing registered gauge value 8, got %d\n", rg2.Value())
os.Exit(1)
}
rg2.Update(16)
if rg1.Value() != 16 {
fmt.Fprintf(os.Stderr, "expected both references to reflect updated value 16, got %d\n", rg1.Value())
os.Exit(1)
}
fmt.Println("All go-metrics contract assertions passed.")
}
Исходный сидер
аноним