CodeSampleX

Exemple

github.com/prometheus/client_model v0.2.0: go.Summary

Échantillon vérifié pour golang github.com/prometheus/client_model v0.2.0: go.Summary. Le contrat s'est exécuté sur go 1.26 · linux debian/x64 · docker et a…

sha256:10e9e08d3e4ef9895cf4862a842f55c9a031371ee875675e9c45ddb198ca92b1

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.Summary in pkg:golang/github.com/prometheus/client_model@v0.2.0
Paquets
Symboles
  • github.com/prometheus/client_model/go.Summary
Créé
2026-09-01T22:31:08Z

Contrat

  1. Summary struct holds SampleCount, SampleSum, and a slice of Quantile pairs with their respective Quantile and Value float64 pointers
  2. GetSampleCount returns the dereferenced SampleCount uint64 value or 0 if nil
  3. GetSampleSum returns the dereferenced SampleSum float64 value or 0.0 if nil
  4. GetQuantile returns the slice of Quantile pointers representing quantile-value pairs
  5. Reset clears all fields of the Summary struct back to zero or nil values

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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 github.com/prometheus/client_model/go.Summary 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.Summary

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:d7b161659bbefae7ff2f07fbc899d57556df81c21190ea83c6964a431a3208de","contract":["Summary struct holds SampleCount, SampleSum, and a slice of Quantile pairs with their respective Quantile and Value float64 pointers","GetSampleCount returns the dereferenced SampleCount uint64 value or 0 if nil","GetSampleSum returns the dereferenced SampleSum float64 value or 0.0 if nil","GetQuantile returns the slice of Quantile pointers representing quantile-value pairs","Reset clears all fields of the Summary struct back to zero or nil values"],"goal":"verify github.com/prometheus/client_model/go.Summary 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.Summary"]},"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/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.Summary"],"verifierAdapter":"golang@1"}
go.mod
module example.com/summarysample

go 1.26.6

require github.com/prometheus/client_model v0.2.0

require (
	github.com/golang/protobuf v1.5.3 // indirect
	google.golang.org/protobuf v1.26.0 // indirect
)
go.sum
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
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.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
main.go
package main

import (
	"fmt"

	dto "github.com/prometheus/client_model/go"
)

func createSummary(count uint64, sum float64, quantiles map[float64]float64) *dto.Summary {
	var qList []*dto.Quantile
	for q, v := range quantiles {
		qVal := q
		vVal := v
		qList = append(qList, &dto.Quantile{
			Quantile: &qVal,
			Value:    &vVal,
		})
	}
	return &dto.Summary{
		SampleCount: &count,
		SampleSum:   &sum,
		Quantile:    qList,
	}
}

func main() {
	s := createSummary(100, 250.5, map[float64]float64{0.5: 2.1, 0.9: 5.4, 0.99: 9.8})
	fmt.Printf("Summary: count=%d, sum=%.2f, quantiles=%d\n", s.GetSampleCount(), s.GetSampleSum(), len(s.GetQuantile()))
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/prometheus/client_model/go.Summary 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.Summary"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	dto "github.com/prometheus/client_model/go"
)

func uint64Ptr(v uint64) *uint64 {
	return &v
}

func float64Ptr(v float64) *float64 {
	return &v
}

func main() {
	// 1. Summary struct holds SampleCount, SampleSum, and a slice of Quantile pairs with their respective Quantile and Value float64 pointers
	{
		q50 := &dto.Quantile{
			Quantile: float64Ptr(0.50),
			Value:    float64Ptr(12.5),
		}
		q99 := &dto.Quantile{
			Quantile: float64Ptr(0.99),
			Value:    float64Ptr(45.2),
		}
		s := &dto.Summary{
			SampleCount: uint64Ptr(150),
			SampleSum:   float64Ptr(1875.0),
			Quantile:    []*dto.Quantile{q50, q99},
		}

		if s.SampleCount == nil || *s.SampleCount != 150 {
			fmt.Fprintf(os.Stderr, "FAIL: SampleCount mismatch: got %v\n", s.SampleCount)
			os.Exit(1)
		}
		if s.SampleSum == nil || *s.SampleSum != 1875.0 {
			fmt.Fprintf(os.Stderr, "FAIL: SampleSum mismatch: got %v\n", s.SampleSum)
			os.Exit(1)
		}
		if len(s.Quantile) != 2 {
			fmt.Fprintf(os.Stderr, "FAIL: Quantile length mismatch: got %d\n", len(s.Quantile))
			os.Exit(1)
		}
		if s.Quantile[0].GetQuantile() != 0.50 || s.Quantile[0].GetValue() != 12.5 {
			fmt.Fprintf(os.Stderr, "FAIL: Quantile[0] values mismatch\n")
			os.Exit(1)
		}
		if s.Quantile[1].GetQuantile() != 0.99 || s.Quantile[1].GetValue() != 45.2 {
			fmt.Fprintf(os.Stderr, "FAIL: Quantile[1] values mismatch\n")
			os.Exit(1)
		}
	}

	// 2. GetSampleCount returns the dereferenced SampleCount uint64 value or 0 if nil
	{
		var nilSummary *dto.Summary
		if nilSummary.GetSampleCount() != 0 {
			fmt.Fprintf(os.Stderr, "FAIL: nil Summary.GetSampleCount() expected 0, got %d\n", nilSummary.GetSampleCount())
			os.Exit(1)
		}

		emptySummary := &dto.Summary{}
		if emptySummary.GetSampleCount() != 0 {
			fmt.Fprintf(os.Stderr, "FAIL: empty Summary.GetSampleCount() expected 0, got %d\n", emptySummary.GetSampleCount())
			os.Exit(1)
		}

		popSummary := &dto.Summary{SampleCount: uint64Ptr(42)}
		if popSummary.GetSampleCount() != 42 {
			fmt.Fprintf(os.Stderr, "FAIL: popSummary.GetSampleCount() expected 42, got %d\n", popSummary.GetSampleCount())
			os.Exit(1)
		}
	}

	// 3. GetSampleSum returns the dereferenced SampleSum float64 value or 0.0 if nil
	{
		var nilSummary *dto.Summary
		if nilSummary.GetSampleSum() != 0.0 {
			fmt.Fprintf(os.Stderr, "FAIL: nil Summary.GetSampleSum() expected 0.0, got %f\n", nilSummary.GetSampleSum())
			os.Exit(1)
		}

		emptySummary := &dto.Summary{}
		if emptySummary.GetSampleSum() != 0.0 {
			fmt.Fprintf(os.Stderr, "FAIL: empty Summary.GetSampleSum() expected 0.0, got %f\n", emptySummary.GetSampleSum())
			os.Exit(1)
		}

		popSummary := &dto.Summary{SampleSum: float64Ptr(123.456)}
		if popSummary.GetSampleSum() != 123.456 {
			fmt.Fprintf(os.Stderr, "FAIL: popSummary.GetSampleSum() expected 123.456, got %f\n", popSummary.GetSampleSum())
			os.Exit(1)
		}
	}

	// 4. GetQuantile returns the slice of Quantile pointers representing quantile-value pairs
	{
		var nilSummary *dto.Summary
		if nilSummary.GetQuantile() != nil {
			fmt.Fprintf(os.Stderr, "FAIL: nil Summary.GetQuantile() expected nil\n")
			os.Exit(1)
		}

		q1 := &dto.Quantile{Quantile: float64Ptr(0.9), Value: float64Ptr(100.0)}
		s := &dto.Summary{Quantile: []*dto.Quantile{q1}}
		quantiles := s.GetQuantile()
		if len(quantiles) != 1 || quantiles[0].GetQuantile() != 0.9 || quantiles[0].GetValue() != 100.0 {
			fmt.Fprintf(os.Stderr, "FAIL: GetQuantile returned unexpected values\n")
			os.Exit(1)
		}
	}

	// 5. Reset clears all fields of the Summary struct back to zero or nil values
	{
		s := &dto.Summary{
			SampleCount: uint64Ptr(10),
			SampleSum:   float64Ptr(50.0),
			Quantile:    []*dto.Quantile{{Quantile: float64Ptr(0.5), Value: float64Ptr(25.0)}},
		}
		s.Reset()
		if s.SampleCount != nil || s.SampleSum != nil || s.Quantile != nil {
			fmt.Fprintf(os.Stderr, "FAIL: Summary.Reset() did not clear fields: %+v\n", s)
			os.Exit(1)
		}
	}

	fmt.Println("PASS: all Summary contract assertions passed")
}

Seeder d'origine

anonyme