Exemple
github.com/prometheus/client_model v0.2.0: go.Histogram
Échantillon vérifié pour golang github.com/prometheus/client_model v0.2.0: go.Histogram. Le contrat s'est exécuté sur go 1.26 · linux debian/x64 · docker et…
sha256:1a7ecb5f4e0f5a8f86abecf38eb96c1bc15e96b78ded53b56490a7d0bfb0e90f
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 1
- Clés de signature qui l’ont compilé
- 1
Environnement déclaré
linux 24 · ubuntu · glibc 2.39 x64 go
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| 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-01 |
Cas
HOW- Objectif
- verify github.com/prometheus/client_model/go.Histogram in pkg:golang/github.com/prometheus/client_model@v0.2.0
- Symboles
-
- github.com/prometheus/client_model/go.Histogram
- Créé
- 2026-09-01T22:29:38Z
Contrat
- dto.Histogram getters (GetSampleCount, GetSampleSum, GetBucket) return zero/nil values for nil and uninitialized instances.
- dto.Histogram stores and retrieves sample count, sample sum, and bucket slices.
- dto.Bucket getters (GetCumulativeCount, GetUpperBound) return zero/nil values for nil instances and retrieve configured values.
- dto.Histogram.Reset clears all fields back to zero values.
Fichiers
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract_test.go
Code source
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/prometheus/client_model/go.Histogram in pkg:golang/github.com/prometheus/client_model@v0.2.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/prometheus/client_model@v0.2.0
Demonstrate these symbols/APIs:
- github.com/prometheus/client_model/go.Histogram
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:7e4325e5fefedbc976afd016300ddb360241d84122fa53572887f717aaed60ac","contract":["dto.Histogram getters (GetSampleCount, GetSampleSum, GetBucket) return zero/nil values for nil and uninitialized instances.","dto.Histogram stores and retrieves sample count, sample sum, and bucket slices.","dto.Bucket getters (GetCumulativeCount, GetUpperBound) return zero/nil values for nil instances and retrieve configured values.","dto.Histogram.Reset clears all fields back to zero values."],"goal":"verify github.com/prometheus/client_model/go.Histogram in pkg:golang/github.com/prometheus/client_model@v0.2.0","kind":"HOW","packages":["pkg:golang/github.com/prometheus/client_model@v0.2.0"],"schemaVersion":1,"symbols":["github.com/prometheus/client_model/go.Histogram"]},"contractCommand":["go","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/prometheus/client_model@v0.2.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/prometheus/client_model@v0.2.0","symbols":["github.com/prometheus/client_model/go.Histogram"],"verifierAdapter":"golang@1"}
module example.com/histogram
go 1.22.0
require (
github.com/golang/protobuf v1.5.4
github.com/prometheus/client_model v0.2.0
)
require google.golang.org/protobuf v1.33.0 // indirect
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M=
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
package main
import (
"fmt"
"github.com/golang/protobuf/proto"
dto "github.com/prometheus/client_model/go"
)
func main() {
h := &dto.Histogram{
SampleCount: proto.Uint64(10),
SampleSum: proto.Float64(25.5),
Bucket: []*dto.Bucket{
{
CumulativeCount: proto.Uint64(4),
UpperBound: proto.Float64(2.5),
},
{
CumulativeCount: proto.Uint64(10),
UpperBound: proto.Float64(10.0),
},
},
}
fmt.Printf("Sample count: %d\n", h.GetSampleCount())
fmt.Printf("Sample sum: %f\n", h.GetSampleSum())
fmt.Printf("Buckets count: %d\n", len(h.GetBucket()))
for _, b := range h.GetBucket() {
fmt.Printf(" le %f: %d\n", b.GetUpperBound(), b.GetCumulativeCount())
}
}
{
"schemaVersion": 1,
"goal": "verify github.com/prometheus/client_model/go.Histogram in pkg:golang/github.com/prometheus/client_model@v0.2.0",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/prometheus/client_model@v0.2.0"
],
"symbols": [
"github.com/prometheus/client_model/go.Histogram"
]
}
package test
import (
"testing"
"github.com/golang/protobuf/proto"
dto "github.com/prometheus/client_model/go"
)
func TestHistogramNilAndDefaultGetters(t *testing.T) {
var nilHistogram *dto.Histogram
if got := nilHistogram.GetSampleCount(); got != 0 {
t.Errorf("nilHistogram.GetSampleCount() = %v, want 0", got)
}
if got := nilHistogram.GetSampleSum(); got != 0 {
t.Errorf("nilHistogram.GetSampleSum() = %v, want 0", got)
}
if got := nilHistogram.GetBucket(); got != nil {
t.Errorf("nilHistogram.GetBucket() = %v, want nil", got)
}
emptyHistogram := &dto.Histogram{}
if got := emptyHistogram.GetSampleCount(); got != 0 {
t.Errorf("emptyHistogram.GetSampleCount() = %v, want 0", got)
}
if got := emptyHistogram.GetSampleSum(); got != 0 {
t.Errorf("emptyHistogram.GetSampleSum() = %v, want 0", got)
}
if got := emptyHistogram.GetBucket(); got != nil {
t.Errorf("emptyHistogram.GetBucket() = %v, want nil", got)
}
}
func TestHistogramValuesAndBuckets(t *testing.T) {
b1 := &dto.Bucket{
CumulativeCount: proto.Uint64(5),
UpperBound: proto.Float64(1.0),
}
b2 := &dto.Bucket{
CumulativeCount: proto.Uint64(12),
UpperBound: proto.Float64(5.0),
}
h := &dto.Histogram{
SampleCount: proto.Uint64(12),
SampleSum: proto.Float64(34.5),
Bucket: []*dto.Bucket{b1, b2},
}
if got := h.GetSampleCount(); got != 12 {
t.Errorf("h.GetSampleCount() = %v, want 12", got)
}
if got := h.GetSampleSum(); got != 34.5 {
t.Errorf("h.GetSampleSum() = %v, want 34.5", got)
}
buckets := h.GetBucket()
if len(buckets) != 2 {
t.Fatalf("len(h.GetBucket()) = %v, want 2", len(buckets))
}
if buckets[0].GetCumulativeCount() != 5 || buckets[0].GetUpperBound() != 1.0 {
t.Errorf("bucket 0 mismatch: count=%v, upper=%v", buckets[0].GetCumulativeCount(), buckets[0].GetUpperBound())
}
if buckets[1].GetCumulativeCount() != 12 || buckets[1].GetUpperBound() != 5.0 {
t.Errorf("bucket 1 mismatch: count=%v, upper=%v", buckets[1].GetCumulativeCount(), buckets[1].GetUpperBound())
}
}
func TestBucketGetters(t *testing.T) {
var nilBucket *dto.Bucket
if got := nilBucket.GetCumulativeCount(); got != 0 {
t.Errorf("nilBucket.GetCumulativeCount() = %v, want 0", got)
}
if got := nilBucket.GetUpperBound(); got != 0 {
t.Errorf("nilBucket.GetUpperBound() = %v, want 0", got)
}
b := &dto.Bucket{
CumulativeCount: proto.Uint64(42),
UpperBound: proto.Float64(100.5),
}
if got := b.GetCumulativeCount(); got != 42 {
t.Errorf("b.GetCumulativeCount() = %v, want 42", got)
}
if got := b.GetUpperBound(); got != 100.5 {
t.Errorf("b.GetUpperBound() = %v, want 100.5", got)
}
}
func TestHistogramReset(t *testing.T) {
h := &dto.Histogram{
SampleCount: proto.Uint64(10),
SampleSum: proto.Float64(50.0),
Bucket: []*dto.Bucket{
{CumulativeCount: proto.Uint64(10), UpperBound: proto.Float64(5.0)},
},
}
h.Reset()
if got := h.GetSampleCount(); got != 0 {
t.Errorf("h.GetSampleCount() after Reset() = %v, want 0", got)
}
if got := h.GetSampleSum(); got != 0 {
t.Errorf("h.GetSampleSum() after Reset() = %v, want 0", got)
}
if got := h.GetBucket(); got != nil {
t.Errorf("h.GetBucket() after Reset() = %v, want nil", got)
}
}
Seeder d'origine
anonyme