Пример
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38: profile.Function
Проверенный пример — golang github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38: profile.Function. Контракт выполнен на go 1.26 · linux debian/x64 …
sha256:45b9475261e81bf25533babdc421dfdbc4911d141130f8f3dfb8f713054f523e
Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла.
Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди.
MIT-0
Свидетельства выполнения
Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.
- Основа свидетельства
- Подписанный контракт пройден
- Квитанции проверки
- 1
- Ключи подписи, собравшие его
- 1
Заявленная среда
linux 24 · ubuntu · glibc 2.39 x64 go
Среды запусков проверки
| Окружение | Контракт | Этапы | Запуск |
|---|---|---|---|
| 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-04 |
Кейс
HOW- Цель
- verify github.com/google/pprof/profile.Function in pkg:golang/github.com/google/pprof@v0.0.0-20210407192527-94a9f03dee38
- Символы
-
- github.com/google/pprof/profile.Function
- Создан
- 2026-09-04T11:05:08Z
Контракт
- profile.Function stores symbol metadata including ID, Name, SystemName, Filename, and StartLine
- profile.Function binds to Location lines and passes Profile.CheckValid validation with unique non-zero IDs
- profile.Function with reserved ID 0 or duplicate IDs causes Profile.CheckValid to fail
- profile.Function preserves all metadata fields across protobuf serialization and deserialization
- profile.Function is cloned as an independent instance during Profile.Copy
Файлы
- PROMPT.md
- csx.json
- go.mod
- go.sum
- sample.go
- spec.json
- test/contract.go
Исходный код
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.Function in pkg:golang/github.com/google/pprof@v0.0.0-20210407192527-94a9f03dee38
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/google/pprof@v0.0.0-20210407192527-94a9f03dee38
Demonstrate these symbols/APIs:
- github.com/google/pprof/profile.Function
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:504a34d7d106889a3dc470d824bda13adf518e0b870e61a42bae1722e609587e","contract":["profile.Function stores symbol metadata including ID, Name, SystemName, Filename, and StartLine","profile.Function binds to Location lines and passes Profile.CheckValid validation with unique non-zero IDs","profile.Function with reserved ID 0 or duplicate IDs causes Profile.CheckValid to fail","profile.Function preserves all metadata fields across protobuf serialization and deserialization","profile.Function is cloned as an independent instance during Profile.Copy"],"goal":"verify github.com/google/pprof/profile.Function in pkg:golang/github.com/google/pprof@v0.0.0-20210407192527-94a9f03dee38","kind":"HOW","packages":["pkg:golang/github.com/google/pprof@v0.0.0-20210407192527-94a9f03dee38"],"schemaVersion":1,"symbols":["github.com/google/pprof/profile.Function"]},"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/google/pprof@v0.0.0-20210407192527-94a9f03dee38"],"schemaVersion":1,"subject":"pkg:golang/github.com/google/pprof@v0.0.0-20210407192527-94a9f03dee38","symbols":["github.com/google/pprof/profile.Function"],"verifierAdapter":"golang@1"}
module sample
go 1.22
require github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38
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-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
package sample
import (
"bytes"
"fmt"
"github.com/google/pprof/profile"
)
// BuildFunction instantiates a profile.Function with defined symbol metadata.
func BuildFunction(id uint64, name, systemName, filename string, startLine int64) *profile.Function {
return &profile.Function{
ID: id,
Name: name,
SystemName: systemName,
Filename: filename,
StartLine: startLine,
}
}
// BuildProfile constructs a valid profile incorporating the given functions.
func BuildProfile(functions []*profile.Function) *profile.Profile {
p := &profile.Profile{
SampleType: []*profile.ValueType{
{Type: "samples", Unit: "count"},
},
PeriodType: &profile.ValueType{Type: "cpu", Unit: "nanoseconds"},
Period: 10000000,
Function: functions,
}
for i, fn := range functions {
loc := &profile.Location{
ID: uint64(i + 1),
Line: []profile.Line{
{
Function: fn,
Line: fn.StartLine + 1,
},
},
}
p.Location = append(p.Location, loc)
p.Sample = append(p.Sample, &profile.Sample{
Location: []*profile.Location{loc},
Value: []int64{1},
})
}
return p
}
// RoundTripProfile serializes a profile to protobuf 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("write profile: %w", err)
}
parsed, err := profile.Parse(&buf)
if err != nil {
return nil, fmt.Errorf("parse profile: %w", err)
}
return parsed, nil
}
{
"schemaVersion": 1,
"goal": "verify github.com/google/pprof/profile.Function in pkg:golang/github.com/google/pprof@v0.0.0-20210407192527-94a9f03dee38",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/google/pprof@v0.0.0-20210407192527-94a9f03dee38"
],
"symbols": [
"github.com/google/pprof/profile.Function"
]
}
package main
import (
"fmt"
"os"
"github.com/google/pprof/profile"
"sample"
)
func main() {
// Assertion 1: profile.Function stores symbol metadata including ID, Name, SystemName, Filename, and StartLine
fn1 := sample.BuildFunction(1, "processWork", "sample.processWork", "processor.go", 42)
if fn1.ID != 1 || fn1.Name != "processWork" || fn1.SystemName != "sample.processWork" || fn1.Filename != "processor.go" || fn1.StartLine != 42 {
fmt.Fprintf(os.Stderr, "FAIL: fn1 attributes mismatch: %+v\n", fn1)
os.Exit(1)
}
// Assertion 2: profile.Function binds to Location lines and passes Profile.CheckValid validation with unique non-zero IDs
fn2 := sample.BuildFunction(2, "dispatchWork", "sample.dispatchWork", "dispatcher.go", 88)
p := sample.BuildProfile([]*profile.Function{fn1, fn2})
if err := p.CheckValid(); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: valid profile CheckValid returned error: %v\n", err)
os.Exit(1)
}
if len(p.Function) != 2 {
fmt.Fprintf(os.Stderr, "FAIL: expected 2 functions, got %d\n", len(p.Function))
os.Exit(1)
}
// Assertion 3: profile.Function with reserved ID 0 or duplicate IDs causes Profile.CheckValid to fail
badFnZero := sample.BuildFunction(0, "zeroID", "sample.zeroID", "zero.go", 10)
pZero := sample.BuildProfile([]*profile.Function{badFnZero})
if err := pZero.CheckValid(); err == nil {
fmt.Fprintf(os.Stderr, "FAIL: expected error for Function with reserved ID 0, got nil\n")
os.Exit(1)
}
fnDup1 := sample.BuildFunction(5, "fnA", "sample.fnA", "a.go", 10)
fnDup2 := sample.BuildFunction(5, "fnB", "sample.fnB", "b.go", 20)
pDup := sample.BuildProfile([]*profile.Function{fnDup1, fnDup2})
if err := pDup.CheckValid(); err == nil {
fmt.Fprintf(os.Stderr, "FAIL: expected error for duplicate Function IDs, got nil\n")
os.Exit(1)
}
// Assertion 4: profile.Function preserves all metadata fields across protobuf serialization and deserialization
roundTripped, err := sample.RoundTripProfile(p)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: serialization roundtrip failed: %v\n", err)
os.Exit(1)
}
if len(roundTripped.Function) != len(p.Function) {
fmt.Fprintf(os.Stderr, "FAIL: roundtripped functions count mismatch: %d != %d\n", len(roundTripped.Function), len(p.Function))
os.Exit(1)
}
rtFn1 := roundTripped.Function[0]
if rtFn1.ID != fn1.ID || rtFn1.Name != fn1.Name || rtFn1.SystemName != fn1.SystemName || rtFn1.Filename != fn1.Filename || rtFn1.StartLine != fn1.StartLine {
fmt.Fprintf(os.Stderr, "FAIL: roundtripped Function[0] metadata altered: got %+v, want %+v\n", rtFn1, fn1)
os.Exit(1)
}
// Assertion 5: profile.Function is cloned as an independent instance during Profile.Copy
copied := p.Copy()
if err := copied.CheckValid(); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: copied profile CheckValid failed: %v\n", err)
os.Exit(1)
}
if copied.Function[0] == p.Function[0] {
fmt.Fprintf(os.Stderr, "FAIL: copied profile shares Function pointer with original\n")
os.Exit(1)
}
copied.Function[0].Name = "mutatedName"
if p.Function[0].Name == "mutatedName" {
fmt.Fprintf(os.Stderr, "FAIL: mutating copied Function affected original Function\n")
os.Exit(1)
}
fmt.Println("PASS: github.com/google/pprof/profile.Function contract verified")
}
Исходный сидер
аноним