Ejemplo
github.com/google/pprof v0.0.0-20260906184651-6331bc6350fe: profile.ValueType
Muestra verificada para golang github.com/google/pprof v0.0.0-20260906184651-6331bc6350fe: profile.ValueType. El contrato se ejecutó en go 1.26 · linux…
sha256:c1af946d2333bd76b995406534698c026e21b6f8f9ce3b15cf5ae827c32c36d3
Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido.
Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas.
MIT-0
Evidencia de ejecución
El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.
- Base de evidencia
- Contrato firmado aprobado
- Recibos de verificación
- 1
- Claves de firma que lo compilaron
- 1
Entorno declarado
go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| 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-10 |
Caso
HOW- Objetivo
- verify github.com/google/pprof/profile.ValueType in pkg:golang/github.com/google/pprof@v0.0.0-20260906184651-6331bc6350fe
- Símbolos
-
- github.com/google/pprof/profile.ValueType
- Entorno
- go 1.26.6
- Creado
- 2026-10-10T02:31:26Z
Contrato
- profile.ValueType specifies metric type and measurement unit for sample and period values
- profile.CheckValid enforces consistency between Profile.SampleType count and Sample.Value slice length
- Profile.SampleIndexByName locates metric index using ValueType Type identifier
- profile.Merge verifies compatible profiles share identical SampleType and PeriodType ValueType definitions
- Profile round-trip serialization preserves ValueType definitions for SampleType and PeriodType
Archivos
- PROMPT.md
- csx.json
- go.mod
- go.sum
- spec.json
- test/contract.go
- value_type.go
Código fuente
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/google/pprof/profile.ValueType in pkg:golang/github.com/google/pprof@v0.0.0-20260906184651-6331bc6350fe
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/google/pprof@v0.0.0-20260906184651-6331bc6350fe
Demonstrate these symbols/APIs:
- github.com/google/pprof/profile.ValueType
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:f8200eb3d36a6b79728e1bf33a17e23ee8adbcd4977dbada02840bae90f129e9","contract":["profile.ValueType specifies metric type and measurement unit for sample and period values","profile.CheckValid enforces consistency between Profile.SampleType count and Sample.Value slice length","Profile.SampleIndexByName locates metric index using ValueType Type identifier","profile.Merge verifies compatible profiles share identical SampleType and PeriodType ValueType definitions","Profile round-trip serialization preserves ValueType definitions for SampleType and PeriodType"],"goal":"verify github.com/google/pprof/profile.ValueType in pkg:golang/github.com/google/pprof@v0.0.0-20260906184651-6331bc6350fe","kind":"HOW","packages":["pkg:golang/github.com/google/pprof@v0.0.0-20260906184651-6331bc6350fe"],"schemaVersion":1,"symbols":["github.com/google/pprof/profile.ValueType"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","packageManagerVersion":"1.26.6","runtime":"go","runtimeVersion":"1.26.6","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/google/pprof@v0.0.0-20260906184651-6331bc6350fe"],"schemaVersion":1,"subject":"pkg:golang/github.com/google/pprof@v0.0.0-20260906184651-6331bc6350fe","symbols":["github.com/google/pprof/profile.ValueType"],"verifierAdapter":"golang@1"}
module sample
go 1.26.6
require github.com/google/pprof v0.0.0-20260906184651-6331bc6350fe
github.com/google/pprof v0.0.0-20260906184651-6331bc6350fe h1:QAinXoAFJdGQYztXn3VpFey7KCwpedbZ/EkzbplQ0cY=
github.com/google/pprof v0.0.0-20260906184651-6331bc6350fe/go.mod h1:jl5iWTm0/hd5PjEYEOuwAJ57L/CibdZfrqZ5XA5GrCk=
{
"schemaVersion": 1,
"goal": "verify github.com/google/pprof/profile.ValueType in pkg:golang/github.com/google/pprof@v0.0.0-20260906184651-6331bc6350fe",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/google/pprof@v0.0.0-20260906184651-6331bc6350fe"
],
"symbols": [
"github.com/google/pprof/profile.ValueType"
]
}
package main
import (
"fmt"
"os"
"github.com/google/pprof/profile"
"sample"
)
func main() {
// Assertion 1: profile.ValueType specifies metric type and measurement unit for sample and period values
cpuType := sample.NewValueType("cpu", "nanoseconds")
samplesType := sample.NewValueType("samples", "count")
if cpuType.Type != "cpu" || cpuType.Unit != "nanoseconds" {
fmt.Fprintf(os.Stderr, "Assertion 1 failed: cpu ValueType mismatch: got %s/%s\n", cpuType.Type, cpuType.Unit)
os.Exit(1)
}
if samplesType.Type != "samples" || samplesType.Unit != "count" {
fmt.Fprintf(os.Stderr, "Assertion 1 failed: samples ValueType mismatch: got %s/%s\n", samplesType.Type, samplesType.Unit)
os.Exit(1)
}
// Assertion 2: profile.CheckValid enforces consistency between Profile.SampleType count and Sample.Value slice length
sampleTypes := []*profile.ValueType{samplesType, cpuType}
validProfile := sample.CreateProfile(sampleTypes, cpuType, []int64{10, 20000})
if err := validProfile.CheckValid(); err != nil {
fmt.Fprintf(os.Stderr, "Assertion 2 failed: valid profile failed CheckValid: %v\n", err)
os.Exit(1)
}
// Mismatched value count vs sample types count
invalidProfileMismatch := sample.CreateProfile(sampleTypes, cpuType, []int64{10})
if err := invalidProfileMismatch.CheckValid(); err == nil {
fmt.Fprintf(os.Stderr, "Assertion 2 failed: expected CheckValid error for mismatched value count, got nil\n")
os.Exit(1)
}
// Empty sample types with non-empty samples
invalidProfileMissing := sample.CreateProfile([]*profile.ValueType{}, cpuType, []int64{10, 20000})
if err := invalidProfileMissing.CheckValid(); err == nil {
fmt.Fprintf(os.Stderr, "Assertion 2 failed: expected CheckValid error for empty SampleType with samples, got nil\n")
os.Exit(1)
}
// Assertion 3: Profile.SampleIndexByName locates metric index using ValueType Type identifier
idxSamples, err := validProfile.SampleIndexByName("samples")
if err != nil || idxSamples != 0 {
fmt.Fprintf(os.Stderr, "Assertion 3 failed: SampleIndexByName('samples') got index %d, err %v\n", idxSamples, err)
os.Exit(1)
}
idxCPU, err := validProfile.SampleIndexByName("cpu")
if err != nil || idxCPU != 1 {
fmt.Fprintf(os.Stderr, "Assertion 3 failed: SampleIndexByName('cpu') got index %d, err %v\n", idxCPU, err)
os.Exit(1)
}
if _, err := validProfile.SampleIndexByName("nonexistent"); err == nil {
fmt.Fprintf(os.Stderr, "Assertion 3 failed: expected error for non-existent sample type name, got nil\n")
os.Exit(1)
}
// Assertion 4: profile.Merge verifies compatible profiles share identical SampleType and PeriodType ValueType definitions
p1 := sample.CreateProfile(
[]*profile.ValueType{sample.NewValueType("samples", "count")},
sample.NewValueType("cpu", "nanoseconds"),
[]int64{5},
)
p2Compatible := sample.CreateProfile(
[]*profile.ValueType{sample.NewValueType("samples", "count")},
sample.NewValueType("cpu", "nanoseconds"),
[]int64{15},
)
merged, err := profile.Merge([]*profile.Profile{p1, p2Compatible})
if err != nil || merged == nil {
fmt.Fprintf(os.Stderr, "Assertion 4 failed: profile.Merge for compatible profiles failed: %v\n", err)
os.Exit(1)
}
pIncompatible := sample.CreateProfile(
[]*profile.ValueType{sample.NewValueType("alloc_space", "bytes")},
sample.NewValueType("space", "bytes"),
[]int64{1024},
)
if _, err := profile.Merge([]*profile.Profile{p1, pIncompatible}); err == nil {
fmt.Fprintf(os.Stderr, "Assertion 4 failed: expected profile.Merge error for incompatible ValueType, got nil\n")
os.Exit(1)
}
// Assertion 5: Profile round-trip serialization preserves ValueType definitions for SampleType and PeriodType
rtProfile, err := sample.RoundTripProfile(validProfile)
if err != nil {
fmt.Fprintf(os.Stderr, "Assertion 5 failed: RoundTripProfile error: %v\n", err)
os.Exit(1)
}
if err := rtProfile.CheckValid(); err != nil {
fmt.Fprintf(os.Stderr, "Assertion 5 failed: round-trip profile invalid: %v\n", err)
os.Exit(1)
}
if len(rtProfile.SampleType) != len(sampleTypes) {
fmt.Fprintf(os.Stderr, "Assertion 5 failed: SampleType length mismatch: got %d, want %d\n", len(rtProfile.SampleType), len(sampleTypes))
os.Exit(1)
}
for i, wantVT := range sampleTypes {
gotVT := rtProfile.SampleType[i]
if gotVT.Type != wantVT.Type || gotVT.Unit != wantVT.Unit {
fmt.Fprintf(os.Stderr, "Assertion 5 failed: SampleType[%d] mismatch: got %s/%s, want %s/%s\n", i, gotVT.Type, gotVT.Unit, wantVT.Type, wantVT.Unit)
os.Exit(1)
}
}
if rtProfile.PeriodType == nil || rtProfile.PeriodType.Type != cpuType.Type || rtProfile.PeriodType.Unit != cpuType.Unit {
fmt.Fprintf(os.Stderr, "Assertion 5 failed: PeriodType mismatch: got %v, want %v\n", rtProfile.PeriodType, cpuType)
os.Exit(1)
}
fmt.Println("All profile.ValueType contract assertions passed.")
}
package sample
import (
"bytes"
"fmt"
"github.com/google/pprof/profile"
)
// NewValueType creates a profile.ValueType with the given type name and measurement unit.
func NewValueType(typeName, unit string) *profile.ValueType {
return &profile.ValueType{
Type: typeName,
Unit: unit,
}
}
// CreateProfile builds a minimal profile with the specified sample types and period type.
func CreateProfile(sampleTypes []*profile.ValueType, periodType *profile.ValueType, values []int64) *profile.Profile {
fn := &profile.Function{
ID: 1,
Name: "taskFunction",
SystemName: "taskFunction",
Filename: "task.go",
StartLine: 1,
}
loc := &profile.Location{
ID: 1,
Line: []profile.Line{
{
Function: fn,
Line: 10,
},
},
}
p := &profile.Profile{
SampleType: sampleTypes,
PeriodType: periodType,
Period: 1000000,
Function: []*profile.Function{fn},
Location: []*profile.Location{loc},
}
if len(values) > 0 {
p.Sample = []*profile.Sample{
{
Location: []*profile.Location{loc},
Value: values,
},
}
}
return p
}
// RoundTripProfile serializes a profile to gzip protobuf bytes and parses it back.
func RoundTripProfile(p *profile.Profile) (*profile.Profile, error) {
var buf bytes.Buffer
if err := p.Write(&buf); err != nil {
return nil, fmt.Errorf("failed to write profile: %w", err)
}
parsed, err := profile.Parse(&buf)
if err != nil {
return nil, fmt.Errorf("failed to parse profile: %w", err)
}
return parsed, nil
}
Seeder de origen
anónimo