示例
golang.org/x/tools v0.22.0
已验证示例 — golang golang.org/x/tools v0.22.0. contract 在 go 1.26 · linux alpine/x64 · docker 上运行并通过: inspector.New constructs an Inspector from parsed AST files…
sha256:d436e0d102090de9d505556e9f57045e39e286aeeef96fc18244e40e5d79d888
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
linux 24 · ubuntu · glibc 2.39 x64 go
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| 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-28 |
案例
HOW- 目标
- verify pkg:golang/golang.org/x/tools@v0.22.0
- 创建时间
- 2026-08-28T09:02:21Z
契约
- inspector.New constructs an Inspector from parsed AST files for node filtering and traversal
- inspector.Preorder traverses AST nodes in preorder filtering by specific node types
- inspector.WithStack traverses AST nodes maintaining the ancestor stack and allowing branch control
- intsets.Sparse performs insertion, membership testing, union, and difference operations on sparse integer sets
- analysis.Analyzer defines a modular static analysis pass with metadata and execution function
文件
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.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 pkg:golang/golang.org/x/tools@v0.22.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/golang.org/x/tools@v0.22.0
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:1542a09e372d414dd865aeed54597d56499005bf6bde58693d9f7cd4d62b0591","contract":["inspector.New constructs an Inspector from parsed AST files for node filtering and traversal","inspector.Preorder traverses AST nodes in preorder filtering by specific node types","inspector.WithStack traverses AST nodes maintaining the ancestor stack and allowing branch control","intsets.Sparse performs insertion, membership testing, union, and difference operations on sparse integer sets","analysis.Analyzer defines a modular static analysis pass with metadata and execution function"],"goal":"verify pkg:golang/golang.org/x/tools@v0.22.0","kind":"HOW","packages":["pkg:golang/golang.org/x/tools@v0.22.0"],"schemaVersion":1},"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/golang.org/x/tools@v0.22.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/tools@v0.22.0","verifierAdapter":"golang@1"}
module sample-golang-tools
go 1.23.0
require golang.org/x/tools v0.22.0
golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA=
golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c=
package main
import (
"fmt"
"go/ast"
"go/parser"
"go/token"
"golang.org/x/tools/container/intsets"
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/ast/inspector"
)
func main() {
// Demonstrate inspector.New and inspector.Preorder
src := `package main
func hello() {
println("hello")
}
func world() {
println("world")
}
`
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, "example.go", src, 0)
if err == nil {
inspect := inspector.New([]*ast.File{f})
var funcs []string
inspect.Preorder([]ast.Node{(*ast.FuncDecl)(nil)}, func(n ast.Node) {
if fn, ok := n.(*ast.FuncDecl); ok && fn.Name != nil {
funcs = append(funcs, fn.Name.Name)
}
})
fmt.Printf("Inspector detected functions: %v\n", funcs)
}
// Demonstrate intsets.Sparse
var s intsets.Sparse
s.Insert(42)
s.Insert(100)
fmt.Printf("Sparse set length: %d, contains 42: %v\n", s.Len(), s.Has(42))
// Demonstrate analysis.Analyzer
analyzer := &analysis.Analyzer{
Name: "sampleanalyzer",
Doc: "verifies AST structure",
Run: func(pass *analysis.Pass) (interface{}, error) {
return nil, nil
},
}
fmt.Printf("Analyzer: %s (%s)\n", analyzer.Name, analyzer.Doc)
}
{
"schemaVersion": 1,
"goal": "verify pkg:golang/golang.org/x/tools@v0.22.0",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/tools@v0.22.0"
]
}
package main
import (
"fmt"
"go/ast"
"go/parser"
"go/token"
"os"
"golang.org/x/tools/container/intsets"
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/ast/inspector"
)
func main() {
// Assertion 1: inspector.New constructs an Inspector from parsed AST files for node filtering and traversal
src := `package sample
import "fmt"
func hello() {
fmt.Println("hello")
}
func world() {
fmt.Println("world")
}
`
fset := token.NewFileSet()
file, err := parser.ParseFile(fset, "sample.go", src, 0)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: parser.ParseFile failed: %v\n", err)
os.Exit(1)
}
inspect := inspector.New([]*ast.File{file})
if inspect == nil {
fmt.Fprintln(os.Stderr, "FAIL: inspector.New returned nil")
os.Exit(1)
}
// Assertion 2: inspector.Preorder traverses AST nodes in preorder filtering by specific node types
var funcNames []string
inspect.Preorder([]ast.Node{(*ast.FuncDecl)(nil)}, func(n ast.Node) {
fn, ok := n.(*ast.FuncDecl)
if ok && fn.Name != nil {
funcNames = append(funcNames, fn.Name.Name)
}
})
if len(funcNames) != 2 || funcNames[0] != "hello" || funcNames[1] != "world" {
fmt.Fprintf(os.Stderr, "FAIL: inspector.Preorder unexpected func names: %v\n", funcNames)
os.Exit(1)
}
// Assertion 3: inspector.WithStack traverses AST nodes maintaining the ancestor stack and allowing branch control
var stackDepthAtCall int
inspect.WithStack([]ast.Node{(*ast.CallExpr)(nil)}, func(n ast.Node, push bool, stack []ast.Node) bool {
if push {
stackDepthAtCall++
if len(stack) == 0 {
fmt.Fprintln(os.Stderr, "FAIL: inspector.WithStack stack is empty on push")
os.Exit(1)
}
}
return true
})
if stackDepthAtCall != 2 {
fmt.Fprintf(os.Stderr, "FAIL: inspector.WithStack expected 2 call expressions, got %d\n", stackDepthAtCall)
os.Exit(1)
}
// Assertion 4: intsets.Sparse performs insertion, membership testing, union, and difference operations on sparse integer sets
{
var a, b intsets.Sparse
a.Insert(1)
a.Insert(100)
a.Insert(10000)
if !a.Has(100) || a.Has(200) {
fmt.Fprintln(os.Stderr, "FAIL: intsets.Sparse Has failed")
os.Exit(1)
}
if a.Len() != 3 {
fmt.Fprintf(os.Stderr, "FAIL: intsets.Sparse Len expected 3, got %d\n", a.Len())
os.Exit(1)
}
b.Insert(100)
b.Insert(500)
var union intsets.Sparse
union.Copy(&a)
union.UnionWith(&b)
if union.Len() != 4 || !union.Has(500) || !union.Has(1) {
fmt.Fprintf(os.Stderr, "FAIL: intsets.Sparse UnionWith failed, len=%d\n", union.Len())
os.Exit(1)
}
var diff intsets.Sparse
diff.Copy(&a)
diff.DifferenceWith(&b)
if diff.Len() != 2 || diff.Has(100) || !diff.Has(10000) {
fmt.Fprintf(os.Stderr, "FAIL: intsets.Sparse DifferenceWith failed, len=%d\n", diff.Len())
os.Exit(1)
}
}
// Assertion 5: analysis.Analyzer defines a modular static analysis pass with metadata and execution function
{
ran := false
analyzer := &analysis.Analyzer{
Name: "testanalyzer",
Doc: "verifies test analyzer contract",
Run: func(pass *analysis.Pass) (interface{}, error) {
ran = true
return "ok", nil
},
}
if analyzer.Name != "testanalyzer" || analyzer.Doc != "verifies test analyzer contract" {
fmt.Fprintln(os.Stderr, "FAIL: analysis.Analyzer fields mismatch")
os.Exit(1)
}
res, err := analyzer.Run(nil)
if err != nil || !ran || res != "ok" {
fmt.Fprintf(os.Stderr, "FAIL: analysis.Analyzer Run failed: ran=%v, res=%v, err=%v\n", ran, res, err)
os.Exit(1)
}
}
fmt.Println("PASS: pkg:golang/golang.org/x/tools@v0.22.0 contract passed")
}
原始种子者
匿名