CodeSampleX

Sample

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

Verified sample for golang github.com/prometheus/client_model v0.2.0: go.MetricType. The contract ran on go 1.26 · linux alpine/x64 · docker and passed.

sha256:7e02a1025780b735c56ad63720dad062d3eef6d6881bc0fa20fb112737bbdca4

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment go linux 24 · ubuntu · glibc 2.39 x64 go go go

Verification-run environments

Environment Contract Stages Run
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-27

Case

HOW
Goal
verify github.com/prometheus/client_model/go.MetricType in pkg:golang/github.com/prometheus/client_model@v0.2.0
Packages
Symbols
  • github.com/prometheus/client_model/go.MetricType
Environment
go
Created
2026-08-27T16:02:05Z

Contract

  1. dto.MetricType constants map to expected protobuf enum values (COUNTER=0, GAUGE=1, SUMMARY=2, UNTYPED=3, HISTOGRAM=4).
  2. dto.MetricType.String returns the uppercase string representation matching protobuf enum names.
  3. dto.MetricType_name and dto.MetricType_value maps correctly convert between enum values and string names.
  4. dto.MetricType.Enum returns a pointer to a copy of the enum value.

Files

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

Download the source artifact (tar.gz)

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.MetricType 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.MetricType

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:f77603fc14bb94bf641ca943ab89d3f06e4c0f42c12cdf607564c9f24a68fe7b","contract":["dto.MetricType constants map to expected protobuf enum values (COUNTER=0, GAUGE=1, SUMMARY=2, UNTYPED=3, HISTOGRAM=4).","dto.MetricType.String returns the uppercase string representation matching protobuf enum names.","dto.MetricType_name and dto.MetricType_value maps correctly convert between enum values and string names.","dto.MetricType.Enum returns a pointer to a copy of the enum value."],"goal":"verify github.com/prometheus/client_model/go.MetricType 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.MetricType"]},"contractCommand":["go","test","./..."],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","executionContext":"go","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","runtime":"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.MetricType"],"verifierAdapter":"golang@1"}
go.mod
module example.com/metrictype

go 1.22.0

require github.com/prometheus/client_model v0.2.0

require (
	github.com/golang/protobuf v1.5.0 // indirect
	google.golang.org/protobuf v1.36.6 // indirect
)
go.sum
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.5.0 h1:LUVKkCeviFUMKqHa4tXIIij/lbhnMbP7Fn5wKdKkRh4=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
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.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
main.go
package main

import (
	"fmt"

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

func main() {
	counterType := dto.MetricType_COUNTER
	gaugeType := dto.MetricType_GAUGE
	summaryType := dto.MetricType_SUMMARY
	untypedType := dto.MetricType_UNTYPED
	histogramType := dto.MetricType_HISTOGRAM

	fmt.Printf("COUNTER: %s (%d)\n", counterType.String(), counterType)
	fmt.Printf("GAUGE: %s (%d)\n", gaugeType.String(), gaugeType)
	fmt.Printf("SUMMARY: %s (%d)\n", summaryType.String(), summaryType)
	fmt.Printf("UNTYPED: %s (%d)\n", untypedType.String(), untypedType)
	fmt.Printf("HISTOGRAM: %s (%d)\n", histogramType.String(), histogramType)

	if val, ok := dto.MetricType_value["COUNTER"]; ok {
		fmt.Printf("Value for COUNTER: %d\n", val)
	}

	if name, ok := dto.MetricType_name[int32(dto.MetricType_GAUGE)]; ok {
		fmt.Printf("Name for 1: %s\n", name)
	}

	enumPtr := counterType.Enum()
	fmt.Printf("Enum pointer value: %v\n", *enumPtr)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/prometheus/client_model/go.MetricType 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.MetricType"
  ]
}
test/contract_test.go
package test

import (
	"testing"

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

func TestMetricTypeEnumValues(t *testing.T) {
	tests := []struct {
		name     string
		got      dto.MetricType
		expected int32
	}{
		{"COUNTER", dto.MetricType_COUNTER, 0},
		{"GAUGE", dto.MetricType_GAUGE, 1},
		{"SUMMARY", dto.MetricType_SUMMARY, 2},
		{"UNTYPED", dto.MetricType_UNTYPED, 3},
		{"HISTOGRAM", dto.MetricType_HISTOGRAM, 4},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if int32(tt.got) != tt.expected {
				t.Errorf("%s = %d, want %d", tt.name, int32(tt.got), tt.expected)
			}
		})
	}
}

func TestMetricTypeString(t *testing.T) {
	tests := []struct {
		val      dto.MetricType
		expected string
	}{
		{dto.MetricType_COUNTER, "COUNTER"},
		{dto.MetricType_GAUGE, "GAUGE"},
		{dto.MetricType_SUMMARY, "SUMMARY"},
		{dto.MetricType_UNTYPED, "UNTYPED"},
		{dto.MetricType_HISTOGRAM, "HISTOGRAM"},
		{dto.MetricType(999), "999"},
	}

	for _, tt := range tests {
		t.Run(tt.expected, func(t *testing.T) {
			if got := tt.val.String(); got != tt.expected {
				t.Errorf("MetricType(%d).String() = %q, want %q", int32(tt.val), got, tt.expected)
			}
		})
	}
}

func TestMetricTypeMaps(t *testing.T) {
	expectedNames := map[int32]string{
		0: "COUNTER",
		1: "GAUGE",
		2: "SUMMARY",
		3: "UNTYPED",
		4: "HISTOGRAM",
	}

	for val, name := range expectedNames {
		if gotName, ok := dto.MetricType_name[val]; !ok || gotName != name {
			t.Errorf("MetricType_name[%d] = %q (exists=%v), want %q", val, gotName, ok, name)
		}
	}

	for val, name := range expectedNames {
		if gotVal, ok := dto.MetricType_value[name]; !ok || gotVal != val {
			t.Errorf("MetricType_value[%q] = %d (exists=%v), want %d", name, gotVal, ok, val)
		}
	}
}

func TestMetricTypeEnum(t *testing.T) {
	mt := dto.MetricType_COUNTER
	ptr := mt.Enum()
	if ptr == nil {
		t.Fatal("mt.Enum() returned nil, want pointer to MetricType")
	}
	if *ptr != dto.MetricType_COUNTER {
		t.Errorf("*ptr = %v, want %v", *ptr, dto.MetricType_COUNTER)
	}
	mt = dto.MetricType_GAUGE
	if *ptr != dto.MetricType_COUNTER {
		t.Errorf("expected *ptr to remain COUNTER after mutating mt, got %v", *ptr)
	}
}

Origin Seeder

anonymous