CodeSampleX

Exemple

github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99: profile.ValueType

Échantillon vérifié pour golang github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99: profile.ValueType. Le contrat s'est exécuté sur go 1.26 · linux…

sha256:2e88cc0880cdbe396b8ec5f9fd7701ee215e2466f895bf916e698f53a9265c02

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é go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1

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-20

Cas

HOW
Objectif
verify github.com/google/pprof/profile.ValueType in pkg:golang/github.com/google/pprof@v0.0.0-20200708004538-1a94d8640e99
Paquets
Symboles
  • github.com/google/pprof/profile.ValueType
Environnement
go 1.26.6
Créé
2026-09-20T10:04:41Z

Contrat

  1. profile.ValueType specifies metric type and measurement unit for sample and period values
  2. profile.CheckValid enforces consistency between Profile.SampleType count and Sample.Value slice length
  3. Profile.SampleIndexByName locates metric index using ValueType Type identifier
  4. profile.Merge verifies compatible profiles share identical SampleType and PeriodType ValueType definitions
  5. Profile round-trip serialization preserves ValueType definitions for SampleType and PeriodType

Fichiers

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • spec.json
  • test/contract.go
  • value_type.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/google/pprof/profile.ValueType in pkg:golang/github.com/google/pprof@v0.0.0-20200708004538-1a94d8640e99
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/google/pprof@v0.0.0-20200708004538-1a94d8640e99
Demonstrate these symbols/APIs:
  - github.com/google/pprof/profile.ValueType
Required runtime conditions:
  - ecosystem: golang
  - language: go
  - packageManager: go@1.26.6
  - runtime: go@1.26.6

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:6943621e1b054b52c21a0a5139184129d3f90508974ebd93d0d64fef8cf7fd9e","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-20200708004538-1a94d8640e99","kind":"HOW","packages":["pkg:golang/github.com/google/pprof@v0.0.0-20200708004538-1a94d8640e99"],"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-20200708004538-1a94d8640e99"],"schemaVersion":1,"subject":"pkg:golang/github.com/google/pprof@v0.0.0-20200708004538-1a94d8640e99","symbols":["github.com/google/pprof/profile.ValueType"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99
go.sum
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99 h1:Ak8CrdlwwXwAZxzS66vgPt4U8yUZX7JwLvVR58FN5jM=
github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/google/pprof/profile.ValueType in pkg:golang/github.com/google/pprof@v0.0.0-20200708004538-1a94d8640e99",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/google/pprof@v0.0.0-20200708004538-1a94d8640e99"
  ],
  "symbols": [
    "github.com/google/pprof/profile.ValueType"
  ],
  "runtimeConditions": {
    "ecosystem": "golang",
    "language": "go",
    "packageManager": "go@1.26.6",
    "runtime": "go@1.26.6"
  }
}
test/contract.go
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.")
}
value_type.go
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 d'origine

anonyme