サンプル
golang.org/x/tools v0.49.0
検証済みサンプル — golang golang.org/x/tools v0.49.0. go 1.26 · linux debian/x64 · docker で contract を実行し、成功しました: astutil.PathEnclosingInterval finds the enclosing…
sha256:7cc0f6a26eb180a4caec0328d4d8f57b1f622c1128f079e3522360c41679541e
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
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-02 |
ケース
HOW- ゴール
- verify pkg:golang/golang.org/x/tools@v0.49.0
- 作成日
- 2026-09-02T20:02:57Z
コントラクト
- astutil.PathEnclosingInterval finds the enclosing AST node path from innermost node to root file for an exact identifier
- astutil.PathEnclosingInterval reports exact true when the query interval encompasses an isolated AST expression node
- astutil.PathEnclosingInterval reports exact false when the interval spans across multiple sibling statements
- astutil.PathEnclosingInterval treats zero-length intervals with identical start and end positions as single-byte lookups
- astutil.PathEnclosingInterval returns the enclosing binary expression node when positioned on an arithmetic operator
ファイル
- PROMPT.md
- astinterval.go
- csx.json
- go.mod
- go.sum
- 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.49.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/golang.org/x/tools@v0.49.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.
package astinterval
import (
"fmt"
"go/ast"
"go/parser"
"go/token"
"golang.org/x/tools/go/ast/astutil"
)
// ParseSource parses a Go source code string into an AST file and token.FileSet.
func ParseSource(src string) (*token.FileSet, *ast.File, error) {
fset := token.NewFileSet()
file, err := parser.ParseFile(fset, "src.go", src, 0)
if err != nil {
return nil, nil, fmt.Errorf("parse error: %w", err)
}
return fset, file, nil
}
// FindEnclosingPath returns the path of AST nodes enclosing the [start, end) interval.
func FindEnclosingPath(root *ast.File, start, end token.Pos) ([]ast.Node, bool) {
return astutil.PathEnclosingInterval(root, start, end)
}
// FindInnermostNode returns the innermost AST node enclosing the [start, end) interval.
func FindInnermostNode(root *ast.File, start, end token.Pos) (ast.Node, bool) {
path, exact := astutil.PathEnclosingInterval(root, start, end)
if len(path) == 0 {
return nil, false
}
return path[0], exact
}
// FindNodeAtPoint returns the AST node at a single point position.
func FindNodeAtPoint(root *ast.File, pos token.Pos) (ast.Node, bool) {
return FindInnermostNode(root, pos, pos)
}
{"case":{"caseId":"case:sha256:2fd3fddd4bab9df420a576fcb34e4c7f3d53bfed33cf1759092391475632764c","contract":["astutil.PathEnclosingInterval finds the enclosing AST node path from innermost node to root file for an exact identifier","astutil.PathEnclosingInterval reports exact true when the query interval encompasses an isolated AST expression node","astutil.PathEnclosingInterval reports exact false when the interval spans across multiple sibling statements","astutil.PathEnclosingInterval treats zero-length intervals with identical start and end positions as single-byte lookups","astutil.PathEnclosingInterval returns the enclosing binary expression node when positioned on an arithmetic operator"],"goal":"verify pkg:golang/golang.org/x/tools@v0.49.0","kind":"HOW","packages":["pkg:golang/golang.org/x/tools@v0.49.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.49.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/tools@v0.49.0","verifierAdapter":"golang@1"}
module example.com/astutil-interval
go 1.25.0
require golang.org/x/tools v0.49.0
golang.org/x/tools v0.49.0 h1:3NI7VXzL9+1WZD52Dx2ttoPwD5DWrFGpl9mFZDlmisI=
golang.org/x/tools v0.49.0/go.mod h1:SJNXV9DBKT0UbdttsQjbfJlAE/q+y36++zo3uL3N0Oo=
{
"schemaVersion": 1,
"goal": "verify pkg:golang/golang.org/x/tools@v0.49.0",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/tools@v0.49.0"
]
}
package main
import (
"fmt"
"go/ast"
"go/token"
"os"
"example.com/astutil-interval"
"golang.org/x/tools/go/ast/astutil"
)
func main() {
src := `package p
func sample() int {
x := 42
y := 10 + 20
return x + y
}
`
_, file, err := astinterval.ParseSource(src)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: failed to parse source: %v\n", err)
os.Exit(1)
}
var fnDecl *ast.FuncDecl
for _, decl := range file.Decls {
if fn, ok := decl.(*ast.FuncDecl); ok && fn.Name.Name == "sample" {
fnDecl = fn
break
}
}
if fnDecl == nil || fnDecl.Body == nil || len(fnDecl.Body.List) < 3 {
fmt.Fprintf(os.Stderr, "FAIL: expected sample function with at least 3 statements\n")
os.Exit(1)
}
stmt1, ok1 := fnDecl.Body.List[0].(*ast.AssignStmt)
stmt2, ok2 := fnDecl.Body.List[1].(*ast.AssignStmt)
if !ok1 || !ok2 {
fmt.Fprintf(os.Stderr, "FAIL: expected assignment statements in function body\n")
os.Exit(1)
}
// Assertion 1: astutil.PathEnclosingInterval finds the enclosing AST node path from innermost node to root file for an exact identifier
{
identX, ok := stmt1.Lhs[0].(*ast.Ident)
if !ok || identX.Name != "x" {
fmt.Fprintf(os.Stderr, "FAIL 1: expected lhs identifier 'x'\n")
os.Exit(1)
}
path, exact := astutil.PathEnclosingInterval(file, identX.Pos(), identX.End())
if len(path) == 0 {
fmt.Fprintf(os.Stderr, "FAIL 1: path is empty\n")
os.Exit(1)
}
if innermost, ok := path[0].(*ast.Ident); !ok || innermost.Name != "x" {
fmt.Fprintf(os.Stderr, "FAIL 1: innermost node is not identifier 'x', got %T\n", path[0])
os.Exit(1)
}
if _, ok := path[len(path)-1].(*ast.File); !ok {
fmt.Fprintf(os.Stderr, "FAIL 1: root node is not *ast.File, got %T\n", path[len(path)-1])
os.Exit(1)
}
if !exact {
fmt.Fprintf(os.Stderr, "FAIL 1: expected exact=true for complete identifier interval\n")
os.Exit(1)
}
}
// Assertion 2: astutil.PathEnclosingInterval reports exact true when the query interval encompasses an isolated AST expression node
{
lit, ok := stmt1.Rhs[0].(*ast.BasicLit)
if !ok || lit.Value != "42" {
fmt.Fprintf(os.Stderr, "FAIL 2: expected rhs basic lit '42'\n")
os.Exit(1)
}
node, exact := astinterval.FindInnermostNode(file, lit.Pos(), lit.End())
if !exact {
fmt.Fprintf(os.Stderr, "FAIL 2: expected exact=true for basic lit interval\n")
os.Exit(1)
}
if matchedLit, ok := node.(*ast.BasicLit); !ok || matchedLit.Value != "42" {
fmt.Fprintf(os.Stderr, "FAIL 2: expected BasicLit '42', got %v\n", node)
os.Exit(1)
}
}
// Assertion 3: astutil.PathEnclosingInterval reports exact false when the interval spans across multiple sibling statements
{
path, exact := astutil.PathEnclosingInterval(file, stmt1.Pos(), stmt2.End())
if exact {
fmt.Fprintf(os.Stderr, "FAIL 3: expected exact=false for multi-statement spanning range\n")
os.Exit(1)
}
if len(path) == 0 {
fmt.Fprintf(os.Stderr, "FAIL 3: expected non-empty path\n")
os.Exit(1)
}
if _, ok := path[0].(*ast.BlockStmt); !ok {
fmt.Fprintf(os.Stderr, "FAIL 3: expected enclosing node to be *ast.BlockStmt, got %T\n", path[0])
os.Exit(1)
}
}
// Assertion 4: astutil.PathEnclosingInterval treats zero-length intervals with identical start and end positions as single-byte lookups
{
identX := stmt1.Lhs[0].(*ast.Ident)
node, exact := astinterval.FindNodeAtPoint(file, identX.Pos())
if !exact {
fmt.Fprintf(os.Stderr, "FAIL 4: expected exact=true for point lookup at identifier start\n")
os.Exit(1)
}
if ident, ok := node.(*ast.Ident); !ok || ident.Name != "x" {
fmt.Fprintf(os.Stderr, "FAIL 4: expected ident 'x' on zero-length lookup, got %T\n", node)
os.Exit(1)
}
}
// Assertion 5: astutil.PathEnclosingInterval returns the enclosing binary expression node when positioned on an arithmetic operator
{
binExpr, ok := stmt2.Rhs[0].(*ast.BinaryExpr)
if !ok || binExpr.Op != token.ADD {
fmt.Fprintf(os.Stderr, "FAIL 5: expected binary expression with addition\n")
os.Exit(1)
}
path, exact := astutil.PathEnclosingInterval(file, binExpr.OpPos, binExpr.OpPos+1)
if !exact {
fmt.Fprintf(os.Stderr, "FAIL 5: expected exact=true for operator in binary expr\n")
os.Exit(1)
}
if len(path) == 0 {
fmt.Fprintf(os.Stderr, "FAIL 5: path is empty\n")
os.Exit(1)
}
if matchedBin, ok := path[0].(*ast.BinaryExpr); !ok || matchedBin.Op != token.ADD {
fmt.Fprintf(os.Stderr, "FAIL 5: expected enclosing *ast.BinaryExpr with '+', got %T\n", path[0])
os.Exit(1)
}
}
fmt.Println("PASS: all astutil.PathEnclosingInterval contract assertions verified")
}
オリジンシーダー
匿名