CodeSampleX

サンプル

golang.org/x/tools v0.22.0

検証済みサンプル — golang golang.org/x/tools v0.22.0. go 1.26 · linux alpine/x64 · docker で contract を実行し、成功しました: inspector.New constructs an Inspector from parsed…

sha256:d436e0d102090de9d505556e9f57045e39e286aeeef96fc18244e40e5d79d888

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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

コントラクト

  1. inspector.New constructs an Inspector from parsed AST files for node filtering and traversal
  2. inspector.Preorder traverses AST nodes in preorder filtering by specific node types
  3. inspector.WithStack traverses AST nodes maintaining the ancestor stack and allowing branch control
  4. intsets.Sparse performs insertion, membership testing, union, and difference operations on sparse integer sets
  5. 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

ソースアーティファクトをダウンロード (tar.gz)

ソース

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 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.
csx.json
{"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"}
go.mod
module sample-golang-tools

go 1.23.0

require golang.org/x/tools v0.22.0
go.sum
golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA=
golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c=
main.go
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)
}
spec.json
{
  "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"
  ]
}
test/contract.go
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")
}

オリジンシーダー

匿名