CodeSampleX

Exemplo

github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4

Amostra verificada para golang github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4. O contrato rodou em go 1.26 · linux debian/x64 · docker…

sha256:60a27912d31702a0aa53c565621b42acbfc3604d01b9a9a85fbe7d3205d2c3fe

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 debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-10-13

Caso

HOW
Objetivo
verify pkg:golang/github.com/prometheus/client_model@v0.0.0-20190812154241-14fe0d1b01d4
Pacotes
Criado
2026-10-13T13:19:44Z

Contrato

  1. MetricFamily organizes metric metadata including name, help string, and metric type enum
  2. MetricFamily and Metric getter methods return safe zero-value defaults on nil receivers or unset fields
  3. Metric supports Counter and Gauge metrics with associated LabelPairs and timestamps
  4. MetricType enumeration defines standard Prometheus metric types including Counter, Gauge, Summary, Untyped, and Histogram
  5. MetricFamily structures round-trip losslessly through protobuf serialization and deserialization

Arquivos

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.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_model@v0.0.0-20190812154241-14fe0d1b01d4
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/prometheus/client_model@v0.0.0-20190812154241-14fe0d1b01d4

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:898a592ea33f6f40689cbc50e17a1e122284a0d0e0df50e9c669ec7739b05da2","contract":["MetricFamily organizes metric metadata including name, help string, and metric type enum","MetricFamily and Metric getter methods return safe zero-value defaults on nil receivers or unset fields","Metric supports Counter and Gauge metrics with associated LabelPairs and timestamps","MetricType enumeration defines standard Prometheus metric types including Counter, Gauge, Summary, Untyped, and Histogram","MetricFamily structures round-trip losslessly through protobuf serialization and deserialization"],"goal":"verify pkg:golang/github.com/prometheus/client_model@v0.0.0-20190812154241-14fe0d1b01d4","kind":"HOW","packages":["pkg:golang/github.com/prometheus/client_model@v0.0.0-20190812154241-14fe0d1b01d4"],"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_model@v0.0.0-20190812154241-14fe0d1b01d4"],"schemaVersion":1,"subject":"pkg:golang/github.com/prometheus/client_model@v0.0.0-20190812154241-14fe0d1b01d4","verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require (
	github.com/golang/protobuf v1.5.4
	github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4
)

require google.golang.org/protobuf v1.36.12 // indirect
go.sum
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.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 h1:gQz4mCbXsO+nc9n1hCxHcGA3Zx3Eo+UHZoInFGUIXNM=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc=
google.golang.org/protobuf v1.36.12/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
main.go
package main

import (
	"fmt"

	"github.com/golang/protobuf/proto"
	dto "github.com/prometheus/client_model/go"
)

func main() {
	name := "http_requests_total"
	help := "Total number of HTTP requests processed"
	labelName := "method"
	labelVal := "GET"
	counterVal := 128.0

	mf := &dto.MetricFamily{
		Name: proto.String(name),
		Help: proto.String(help),
		Type: dto.MetricType_COUNTER.Enum(),
		Metric: []*dto.Metric{
			{
				Label: []*dto.LabelPair{
					{
						Name:  proto.String(labelName),
						Value: proto.String(labelVal),
					},
				},
				Counter: &dto.Counter{
					Value: proto.Float64(counterVal),
				},
			},
		},
	}

	fmt.Printf("MetricFamily: %s (%s) type=%v\n", mf.GetName(), mf.GetHelp(), mf.GetType())
	for _, m := range mf.GetMetric() {
		fmt.Printf("  Metric: counter=%f\n", m.GetCounter().GetValue())
		for _, lbl := range m.GetLabel() {
			fmt.Printf("    Label %s=%s\n", lbl.GetName(), lbl.GetValue())
		}
	}
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/github.com/prometheus/client_model@v0.0.0-20190812154241-14fe0d1b01d4",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/prometheus/client_model@v0.0.0-20190812154241-14fe0d1b01d4"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"github.com/golang/protobuf/proto"
	dto "github.com/prometheus/client_model/go"
)

func main() {
	if err := runContractTests(); err != nil {
		fmt.Fprintf(os.Stderr, "Contract test failure: %v\n", err)
		os.Exit(1)
	}
	fmt.Println("All contract tests passed successfully.")
}

func runContractTests() error {
	// 1. MetricFamily organizes metric metadata including name, help string, and metric type enum
	{
		name := "cpu_seconds_total"
		help := "Total CPU time spent in seconds"
		mf := &dto.MetricFamily{
			Name: proto.String(name),
			Help: proto.String(help),
			Type: dto.MetricType_COUNTER.Enum(),
		}
		if mf.GetName() != name {
			return fmt.Errorf("expected GetName() %q, got %q", name, mf.GetName())
		}
		if mf.GetHelp() != help {
			return fmt.Errorf("expected GetHelp() %q, got %q", help, mf.GetHelp())
		}
		if mf.GetType() != dto.MetricType_COUNTER {
			return fmt.Errorf("expected GetType() COUNTER, got %v", mf.GetType())
		}
	}

	// 2. MetricFamily and Metric getter methods return safe zero-value defaults on nil receivers or unset fields
	{
		var nilMF *dto.MetricFamily
		if nilMF.GetName() != "" {
			return fmt.Errorf("expected empty string for nil MetricFamily GetName")
		}
		if nilMF.GetHelp() != "" {
			return fmt.Errorf("expected empty string for nil MetricFamily GetHelp")
		}
		if nilMF.GetType() != dto.MetricType_COUNTER {
			return fmt.Errorf("expected default MetricType_COUNTER for nil MetricFamily GetType")
		}
		if nilMF.GetMetric() != nil {
			return fmt.Errorf("expected nil slice for nil MetricFamily GetMetric")
		}

		var nilMetric *dto.Metric
		if nilMetric.GetCounter() != nil {
			return fmt.Errorf("expected nil counter for nil Metric")
		}
		if nilMetric.GetGauge() != nil {
			return fmt.Errorf("expected nil gauge for nil Metric")
		}
		if nilMetric.GetTimestampMs() != 0 {
			return fmt.Errorf("expected 0 for nil Metric GetTimestampMs")
		}
	}

	// 3. Metric supports Counter and Gauge metrics with associated LabelPairs and timestamps
	{
		counterVal := 42.5
		ts := int64(1565624561000)
		counterMetric := &dto.Metric{
			Label: []*dto.LabelPair{
				{
					Name:  proto.String("service"),
					Value: proto.String("api"),
				},
				{
					Name:  proto.String("env"),
					Value: proto.String("prod"),
				},
			},
			Counter: &dto.Counter{
				Value: proto.Float64(counterVal),
			},
			TimestampMs: proto.Int64(ts),
		}

		if len(counterMetric.GetLabel()) != 2 {
			return fmt.Errorf("expected 2 labels, got %d", len(counterMetric.GetLabel()))
		}
		if counterMetric.GetLabel()[0].GetName() != "service" || counterMetric.GetLabel()[0].GetValue() != "api" {
			return fmt.Errorf("unexpected label[0]: %s=%s", counterMetric.GetLabel()[0].GetName(), counterMetric.GetLabel()[0].GetValue())
		}
		if counterMetric.GetCounter().GetValue() != counterVal {
			return fmt.Errorf("expected counter value %f, got %f", counterVal, counterMetric.GetCounter().GetValue())
		}
		if counterMetric.GetTimestampMs() != ts {
			return fmt.Errorf("expected timestamp %d, got %d", ts, counterMetric.GetTimestampMs())
		}

		gaugeVal := 1024.0
		gaugeMetric := &dto.Metric{
			Gauge: &dto.Gauge{
				Value: proto.Float64(gaugeVal),
			},
		}
		if gaugeMetric.GetGauge().GetValue() != gaugeVal {
			return fmt.Errorf("expected gauge value %f, got %f", gaugeVal, gaugeMetric.GetGauge().GetValue())
		}
	}

	// 4. MetricType enumeration defines standard Prometheus metric types including Counter, Gauge, Summary, Untyped, and Histogram
	{
		if dto.MetricType_COUNTER.String() != "COUNTER" {
			return fmt.Errorf("expected COUNTER string representation")
		}
		if dto.MetricType_GAUGE.String() != "GAUGE" {
			return fmt.Errorf("expected GAUGE string representation")
		}
		if dto.MetricType_SUMMARY.String() != "SUMMARY" {
			return fmt.Errorf("expected SUMMARY string representation")
		}
		if dto.MetricType_UNTYPED.String() != "UNTYPED" {
			return fmt.Errorf("expected UNTYPED string representation")
		}
		if dto.MetricType_HISTOGRAM.String() != "HISTOGRAM" {
			return fmt.Errorf("expected HISTOGRAM string representation")
		}
	}

	// 5. MetricFamily structures round-trip losslessly through protobuf serialization and deserialization
	{
		origMF := &dto.MetricFamily{
			Name: proto.String("memory_rss_bytes"),
			Help: proto.String("Current resident set size in bytes"),
			Type: dto.MetricType_GAUGE.Enum(),
			Metric: []*dto.Metric{
				{
					Label: []*dto.LabelPair{
						{
							Name:  proto.String("job"),
							Value: proto.String("node_exporter"),
						},
					},
					Gauge: &dto.Gauge{
						Value: proto.Float64(104857600.0),
					},
				},
			},
		}

		bytes, err := proto.Marshal(origMF)
		if err != nil {
			return fmt.Errorf("proto.Marshal failed: %w", err)
		}

		deserMF := &dto.MetricFamily{}
		if err := proto.Unmarshal(bytes, deserMF); err != nil {
			return fmt.Errorf("proto.Unmarshal failed: %w", err)
		}

		if deserMF.GetName() != origMF.GetName() {
			return fmt.Errorf("unmarshaled name mismatch: %s != %s", deserMF.GetName(), origMF.GetName())
		}
		if deserMF.GetHelp() != origMF.GetHelp() {
			return fmt.Errorf("unmarshaled help mismatch: %s != %s", deserMF.GetHelp(), origMF.GetHelp())
		}
		if deserMF.GetType() != origMF.GetType() {
			return fmt.Errorf("unmarshaled type mismatch: %v != %v", deserMF.GetType(), origMF.GetType())
		}
		if len(deserMF.GetMetric()) != 1 {
			return fmt.Errorf("expected 1 metric, got %d", len(deserMF.GetMetric()))
		}
		if deserMF.GetMetric()[0].GetGauge().GetValue() != origMF.GetMetric()[0].GetGauge().GetValue() {
			return fmt.Errorf("unmarshaled gauge value mismatch")
		}
	}

	return nil
}

Seeder de origem

anônimo