CodeSampleX

Exemplo

github.com/prometheus/client_golang v1.23.2

Amostra verificada para golang github.com/prometheus/client_golang v1.23.2. O contrato rodou em go 1.26 · linux alpine/x64 · docker e passou.

sha256:868fb3c4df2829e73940e4ea37c6f62723ddca3473f743c8c79c8d00004b26b8

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado linux 24 · ubuntu · glibc 2.39 x64 go

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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-28

Caso

HOW
Objetivo
verify pkg:golang/github.com/prometheus/client_golang@v1.23.2
Pacotes
Criado
2026-08-28T00:20:44Z

Contrato

  1. prometheus.NewRegistry creates a distinct non-nil metric registry
  2. prometheus.NewCounterVec increments labeled counter metrics and gathers them
  3. prometheus.NewGauge records and updates gauge values in the registry
  4. prometheus.NewHistogram records observations with bucket counts and sum
  5. prometheus.NewSummary records observations with quantiles and sum

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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 pkg:golang/github.com/prometheus/client_golang@v1.23.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/prometheus/client_golang@v1.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:4771727cdd204465fd3688353317f0a7d4af139e44c2d52a6e39950bad77df12","contract":["prometheus.NewRegistry creates a distinct non-nil metric registry","prometheus.NewCounterVec increments labeled counter metrics and gathers them","prometheus.NewGauge records and updates gauge values in the registry","prometheus.NewHistogram records observations with bucket counts and sum","prometheus.NewSummary records observations with quantiles and sum"],"goal":"verify pkg:golang/github.com/prometheus/client_golang@v1.23.2","kind":"HOW","packages":["pkg:golang/github.com/prometheus/client_golang@v1.23.2"],"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/prometheus/client_golang@v1.23.2"],"schemaVersion":1,"subject":"pkg:golang/github.com/prometheus/client_golang@v1.23.2","verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require (
	github.com/prometheus/client_golang v1.23.2
	github.com/prometheus/client_model v0.6.2
)

require (
	github.com/beorn7/perks v1.0.1 // indirect
	github.com/cespare/xxhash/v2 v2.3.0 // indirect
	github.com/kr/text v0.2.0 // indirect
	github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
	github.com/prometheus/common v0.66.1 // indirect
	github.com/prometheus/procfs v0.16.1 // indirect
	go.yaml.in/yaml/v2 v2.4.2 // indirect
	golang.org/x/sys v0.35.0 // indirect
	google.golang.org/protobuf v1.36.8 // indirect
)
go.sum
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
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/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
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/prometheus/client_golang v1.23.2 h1:Je96obch5RDVy3FDMndoUsjAhG5Edi49h0RJWRi/o0o=
github.com/prometheus/client_golang v1.23.2/go.mod h1:Tb1a6LWHB3/SPIzCoaDXI4I8UHKeFTEQ1YCr+0Gyqmg=
github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=
github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE=
github.com/prometheus/common v0.66.1 h1:h5E0h5/Y8niHc5DlaLlWLArTQI7tMrsfQjHV+d9ZoGs=
github.com/prometheus/common v0.66.1/go.mod h1:gcaUsgf3KfRSwHY4dIMXLPV0K/Wg1oZ8+SbZk/HH/dA=
github.com/prometheus/procfs v0.16.1 h1:hZ15bTNuirocR6u0JZ6BAHHmwS1p8B4P6MRqxtzMyRg=
github.com/prometheus/procfs v0.16.1/go.mod h1:teAbpZRB1iIAJYREa1LsoWUXykVXA1KlTmWl8x/U+Is=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI=
go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU=
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
google.golang.org/protobuf v1.36.8 h1:xHScyCOEuuwZEc6UtSOvPbAT4zRh0xcNRYekJwfqyMc=
google.golang.org/protobuf v1.36.8/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
metrics.go
package sample

import (
	"github.com/prometheus/client_golang/prometheus"
)

// Metrics holds prometheus collectors registered to a custom registry.
type Metrics struct {
	Registry       *prometheus.Registry
	RequestCounter *prometheus.CounterVec
	ActiveGauge    prometheus.Gauge
	DurationHist   prometheus.Histogram
	PayloadSummary prometheus.Summary
}

// NewMetrics creates and registers custom Prometheus metrics with a dedicated registry.
func NewMetrics() *Metrics {
	reg := prometheus.NewRegistry()

	counter := prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name: "http_requests_total",
			Help: "Total number of HTTP requests processed.",
		},
		[]string{"method", "status"},
	)

	gauge := prometheus.NewGauge(
		prometheus.GaugeOpts{
			Name: "current_active_workers",
			Help: "Current number of active workers.",
		},
	)

	hist := prometheus.NewHistogram(
		prometheus.HistogramOpts{
			Name:    "task_duration_seconds",
			Help:    "Duration of tasks in seconds.",
			Buckets: []float64{0.1, 0.5, 1.0, 5.0},
		},
	)

	summary := prometheus.NewSummary(
		prometheus.SummaryOpts{
			Name:       "payload_size_bytes",
			Help:       "Size of request payloads in bytes.",
			Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
		},
	)

	reg.MustRegister(counter, gauge, hist, summary)

	return &Metrics{
		Registry:       reg,
		RequestCounter: counter,
		ActiveGauge:    gauge,
		DurationHist:   hist,
		PayloadSummary: summary,
	}
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/github.com/prometheus/client_golang@v1.23.2",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/prometheus/client_golang@v1.23.2"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

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

func main() {
	m := sample.NewMetrics()
	if m == nil || m.Registry == nil {
		fmt.Fprintf(os.Stderr, "failed to initialize metrics registry\n")
		os.Exit(1)
	}

	// 1. Record metric values
	m.RequestCounter.WithLabelValues("GET", "200").Inc()
	m.RequestCounter.WithLabelValues("POST", "201").Add(2)
	m.ActiveGauge.Set(42)
	m.DurationHist.Observe(0.35)
	m.PayloadSummary.Observe(1024)
	m.PayloadSummary.Observe(2048)

	// 2. Gather metrics from the registry
	mfs, err := m.Registry.Gather()
	if err != nil {
		fmt.Fprintf(os.Stderr, "registry.Gather failed: %v\n", err)
		os.Exit(1)
	}

	if len(mfs) != 4 {
		fmt.Fprintf(os.Stderr, "expected 4 metric families, got %d\n", len(mfs))
		os.Exit(1)
	}

	foundMap := make(map[string]*dto.MetricFamily)
	for _, mf := range mfs {
		foundMap[mf.GetName()] = mf
	}

	// 3. Verify counter family
	counterMF, ok := foundMap["http_requests_total"]
	if !ok {
		fmt.Fprintf(os.Stderr, "missing http_requests_total metric\n")
		os.Exit(1)
	}
	if counterMF.GetType() != dto.MetricType_COUNTER {
		fmt.Fprintf(os.Stderr, "expected COUNTER type, got %v\n", counterMF.GetType())
		os.Exit(1)
	}
	if len(counterMF.GetMetric()) != 2 {
		fmt.Fprintf(os.Stderr, "expected 2 counter metric instances, got %d\n", len(counterMF.GetMetric()))
		os.Exit(1)
	}

	// 4. Verify gauge family
	gaugeMF, ok := foundMap["current_active_workers"]
	if !ok {
		fmt.Fprintf(os.Stderr, "missing current_active_workers metric\n")
		os.Exit(1)
	}
	if gaugeMF.GetType() != dto.MetricType_GAUGE {
		fmt.Fprintf(os.Stderr, "expected GAUGE type, got %v\n", gaugeMF.GetType())
		os.Exit(1)
	}
	if len(gaugeMF.GetMetric()) != 1 || gaugeMF.GetMetric()[0].GetGauge().GetValue() != 42 {
		fmt.Fprintf(os.Stderr, "expected gauge value 42\n")
		os.Exit(1)
	}

	// 5. Verify histogram family
	histMF, ok := foundMap["task_duration_seconds"]
	if !ok {
		fmt.Fprintf(os.Stderr, "missing task_duration_seconds metric\n")
		os.Exit(1)
	}
	if histMF.GetType() != dto.MetricType_HISTOGRAM {
		fmt.Fprintf(os.Stderr, "expected HISTOGRAM type, got %v\n", histMF.GetType())
		os.Exit(1)
	}
	hist := histMF.GetMetric()[0].GetHistogram()
	if hist.GetSampleCount() != 1 || hist.GetSampleSum() != 0.35 {
		fmt.Fprintf(os.Stderr, "expected sample count 1 and sum 0.35, got %d, %f\n", hist.GetSampleCount(), hist.GetSampleSum())
		os.Exit(1)
	}

	// 6. Verify summary family
	summaryMF, ok := foundMap["payload_size_bytes"]
	if !ok {
		fmt.Fprintf(os.Stderr, "missing payload_size_bytes metric\n")
		os.Exit(1)
	}
	if summaryMF.GetType() != dto.MetricType_SUMMARY {
		fmt.Fprintf(os.Stderr, "expected SUMMARY type, got %v\n", summaryMF.GetType())
		os.Exit(1)
	}
	summary := summaryMF.GetMetric()[0].GetSummary()
	if summary.GetSampleCount() != 2 || summary.GetSampleSum() != 3072 {
		fmt.Fprintf(os.Stderr, "expected sample count 2 and sum 3072, got %d, %f\n", summary.GetSampleCount(), summary.GetSampleSum())
		os.Exit(1)
	}

	fmt.Println("All prometheus client_golang contract assertions passed.")
}

Seeder de origem

anônimo