示例
github.com/google/pprof v0.0.0-20260906184651-6331bc6350fe: profile.Parse
已验证示例 — golang github.com/google/pprof v0.0.0-20260906184651-6331bc6350fe: profile.Parse. contract 在 go 1.26 · linux debian/x64 · docker 上运行并通过.
sha256:62a46c29acf108bfebbc4f6ae422d6ee29df447dfc662f37554b9df2363f13ac
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| 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 |
案例
HOW- 目标
- verify github.com/google/pprof/profile.Parse in pkg:golang/github.com/google/pprof@v0.0.0-20260906184651-6331bc6350fe
- 符号
-
- github.com/google/pprof/profile.Parse
- 环境
- go 1.26.6
- 创建时间
- 2026-10-10T00:39:42Z
契约
- profile.Profile creates and validates a structured cpu/memory profile with CheckValid
- profile.Profile.Write serializes the profile into gzip-compressed protobuf format
- profile.Parse parses serialized profile data and restores samples, locations, and functions
文件
- 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.Parse 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.Parse
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
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:051ae67caf96d3d367f667baebcba46f325e981addbed53f8e65b8289a8207eb","contract":["profile.Profile creates and validates a structured cpu/memory profile with CheckValid","profile.Profile.Write serializes the profile into gzip-compressed protobuf format","profile.Parse parses serialized profile data and restores samples, locations, and functions"],"goal":"verify github.com/google/pprof/profile.Parse 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.Parse"]},"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.Parse"],"verifierAdapter":"golang@1"}
module sample
go 1.25.0
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=
package sample
import (
"bytes"
"io"
"github.com/google/pprof/profile"
)
// BuildSampleProfile constructs a valid profile with sample type, functions, locations, and samples.
func BuildSampleProfile(functionName, filename string, line int64, sampleCount, cpuNanos int64) (*profile.Profile, error) {
p := &profile.Profile{
SampleType: []*profile.ValueType{
{Type: "samples", Unit: "count"},
{Type: "cpu", Unit: "nanoseconds"},
},
PeriodType: &profile.ValueType{Type: "cpu", Unit: "nanoseconds"},
Period: 10000000,
}
fn := &profile.Function{
ID: 1,
Name: functionName,
SystemName: functionName,
Filename: filename,
StartLine: line,
}
p.Function = []*profile.Function{fn}
loc := &profile.Location{
ID: 1,
Line: []profile.Line{
{
Function: fn,
Line: line + 5,
},
},
}
p.Location = []*profile.Location{loc}
s := &profile.Sample{
Location: []*profile.Location{loc},
Value: []int64{sampleCount, cpuNanos},
}
p.Sample = []*profile.Sample{s}
if err := p.CheckValid(); err != nil {
return nil, err
}
return p, nil
}
// SerializeProfile writes a Profile to an io.Writer in standard pprof format.
func SerializeProfile(p *profile.Profile, w io.Writer) error {
return p.Write(w)
}
// ParseProfile parses a serialized pprof stream from an io.Reader.
func ParseProfile(r io.Reader) (*profile.Profile, error) {
return profile.Parse(r)
}
// EncodeAndDecode serializes and re-parses a profile, returning the decoded profile.
func EncodeAndDecode(p *profile.Profile) (*profile.Profile, error) {
var buf bytes.Buffer
if err := p.Write(&buf); err != nil {
return nil, err
}
return profile.Parse(&buf)
}
{
"schemaVersion": 1,
"goal": "verify github.com/google/pprof/profile.Parse 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.Parse"
],
"runtimeConditions": {
"ecosystem": "golang",
"language": "go",
"packageManager": "go@1.26.6",
"runtime": "go@1.26.6"
}
}
package main
import (
"bytes"
"fmt"
"os"
"github.com/google/pprof/profile"
"sample"
)
func main() {
// Assertion 1: profile.Profile creates and validates a structured cpu/memory profile with CheckValid
p, err := sample.BuildSampleProfile("worker.processTask", "worker.go", 10, 5, 50000000)
if err != nil {
fmt.Fprintf(os.Stderr, "BuildSampleProfile failed: %v\n", err)
os.Exit(1)
}
var _ *profile.Profile = p
if err := p.CheckValid(); err != nil {
fmt.Fprintf(os.Stderr, "p.CheckValid failed: %v\n", err)
os.Exit(1)
}
if len(p.Sample) != 1 {
fmt.Fprintf(os.Stderr, "expected 1 sample, got %d\n", len(p.Sample))
os.Exit(1)
}
// Assertion 2: profile.Profile.Write serializes the profile into gzip-compressed protobuf format
var buf bytes.Buffer
if err := p.Write(&buf); err != nil {
fmt.Fprintf(os.Stderr, "p.Write failed: %v\n", err)
os.Exit(1)
}
if buf.Len() == 0 {
fmt.Fprintf(os.Stderr, "serialized buffer is empty\n")
os.Exit(1)
}
// Assertion 3: profile.Parse parses serialized profile data and restores samples, locations, and functions
parsed, err := profile.Parse(&buf)
if err != nil {
fmt.Fprintf(os.Stderr, "profile.Parse failed: %v\n", err)
os.Exit(1)
}
if err := parsed.CheckValid(); err != nil {
fmt.Fprintf(os.Stderr, "parsed profile CheckValid failed: %v\n", err)
os.Exit(1)
}
if len(parsed.Sample) != 1 {
fmt.Fprintf(os.Stderr, "expected 1 sample in parsed profile, got %d\n", len(parsed.Sample))
os.Exit(1)
}
if parsed.Sample[0].Value[0] != 5 || parsed.Sample[0].Value[1] != 50000000 {
fmt.Fprintf(os.Stderr, "parsed sample values mismatch: got %v, expected [5, 50000000]\n", parsed.Sample[0].Value)
os.Exit(1)
}
if len(parsed.Function) != 1 || parsed.Function[0].Name != "worker.processTask" {
fmt.Fprintf(os.Stderr, "parsed function mismatch\n")
os.Exit(1)
}
if len(parsed.Location) != 1 || len(parsed.Location[0].Line) != 1 || parsed.Location[0].Line[0].Line != 15 {
fmt.Fprintf(os.Stderr, "parsed location line mismatch\n")
os.Exit(1)
}
fmt.Println("All pprof profile contract assertions passed.")
}
原始种子者
匿名