CodeSampleX

サンプル

golang.org/x/tools v0.1.1

検証済みサンプル — golang golang.org/x/tools v0.1.1. go 1.26 · linux debian/x64 · docker で contract を実行し、成功しました: imports.Process formats Go source code and…

sha256:942db819ffe5ad60a3ad35d55845e07a075a379a9c5f802b12f945ea0e09edbf

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。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-10-13

ケース

HOW
ゴール
verify pkg:golang/golang.org/x/tools@v0.1.1
パッケージ
作成日
2026-10-13T19:02:40Z

コントラクト

  1. imports.Process formats Go source code and automatically resolves required standard package imports
  2. imports.VendorlessPath returns the un-vendored package import path
  3. cfg.New constructs a control flow graph containing entry, exit, and branch blocks for a function AST
  4. typeutil.Map associates arbitrary values with go/types Type keys using type identity
  5. txtar.Format serializes an Archive with comments and named files into txtar syntax
  6. txtar.Parse parses txtar formatted byte content into structured Archive comments and Files

ファイル

  • 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.1.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/tools@v0.1.1

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:55bf2645c5f2a9821905146cca542108cb971874d3d43273df242e12c578ba4e","contract":["imports.Process formats Go source code and automatically resolves required standard package imports","imports.VendorlessPath returns the un-vendored package import path","cfg.New constructs a control flow graph containing entry, exit, and branch blocks for a function AST","typeutil.Map associates arbitrary values with go/types Type keys using type identity","txtar.Format serializes an Archive with comments and named files into txtar syntax","txtar.Parse parses txtar formatted byte content into structured Archive comments and Files"],"goal":"verify pkg:golang/golang.org/x/tools@v0.1.1","kind":"HOW","packages":["pkg:golang/golang.org/x/tools@v0.1.1"],"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.1.1"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/tools@v0.1.1","verifierAdapter":"golang@1"}
go.mod
module sample-tools

go 1.23.0

require golang.org/x/tools v0.1.1

require (
	golang.org/x/mod v0.4.2 // indirect
	golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect
	golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
)
go.sum
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.1 h1:wGiQel/hW0NnEkJUk8lbzkX2gFJU6PFxf1v5OlCfuOs=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
main.go
package main

import (
	"fmt"
	"go/ast"
	"go/parser"
	"go/token"
	"go/types"

	"golang.org/x/tools/go/cfg"
	"golang.org/x/tools/go/types/typeutil"
	"golang.org/x/tools/imports"
	"golang.org/x/tools/txtar"
)

func main() {
	// Demonstrate imports.Process
	src := []byte("package main\n\nfunc run() {\n\tfmt.Println(\"CodeSampleX\")\n}\n")
	opt := &imports.Options{
		TabWidth:  8,
		TabIndent: true,
		Comments:  true,
	}
	formatted, err := imports.Process("example.go", src, opt)
	if err == nil {
		fmt.Printf("Formatted source with imports:\n%s\n", string(formatted))
	}

	// Demonstrate cfg.New
	code := `package main
func calculate(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}`
	fset := token.NewFileSet()
	f, err := parser.ParseFile(fset, "calc.go", code, 0)
	if err == nil && len(f.Decls) > 0 {
		if fn, ok := f.Decls[0].(*ast.FuncDecl); ok {
			controlFlow := cfg.New(fn.Body, func(call *ast.CallExpr) bool { return true })
			fmt.Printf("Control-flow graph blocks count: %d\n", len(controlFlow.Blocks))
		}
	}

	// Demonstrate typeutil.Map
	var typeMap typeutil.Map
	intType := types.Typ[types.Int]
	typeMap.Set(intType, "builtin-int")
	fmt.Printf("typeutil.Map contains %d types, intType description: %v\n", typeMap.Len(), typeMap.At(intType))

	// Demonstrate txtar.Format and txtar.Parse
	archive := &txtar.Archive{
		Comment: []byte("sample txtar comment"),
		Files: []txtar.File{
			{Name: "hello.txt", Data: []byte("Hello, world!\n")},
		},
	}
	data := txtar.Format(archive)
	parsed := txtar.Parse(data)
	fmt.Printf("Txtar files count: %d\n", len(parsed.Files))
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/golang.org/x/tools@v0.1.1",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/tools@v0.1.1"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"fmt"
	"go/ast"
	"go/parser"
	"go/token"
	"go/types"
	"os"
	"strings"

	"golang.org/x/tools/go/cfg"
	"golang.org/x/tools/go/types/typeutil"
	"golang.org/x/tools/imports"
	"golang.org/x/tools/txtar"
)

func main() {
	// Assertion 1: imports.Process formats Go source code and automatically resolves required standard package imports
	{
		unformattedSrc := []byte("package main\n\nfunc hello() {\n\tstrings.ToUpper(\"test\")\n}\n")
		opts := &imports.Options{
			TabWidth:  8,
			TabIndent: true,
			Comments:  true,
		}
		formatted, err := imports.Process("main.go", unformattedSrc, opts)
		if err != nil {
			fmt.Fprintf(os.Stderr, "FAIL: imports.Process returned error: %v\n", err)
			os.Exit(1)
		}
		formattedStr := string(formatted)
		if !strings.Contains(formattedStr, "\"strings\"") {
			fmt.Fprintf(os.Stderr, "FAIL: imports.Process did not insert strings import: %s\n", formattedStr)
			os.Exit(1)
		}
		if !strings.Contains(formattedStr, "func hello()") {
			fmt.Fprintf(os.Stderr, "FAIL: imports.Process corrupted function declaration: %s\n", formattedStr)
			os.Exit(1)
		}
	}

	// Assertion 2: imports.VendorlessPath returns the un-vendored package import path
	{
		vendoredPath := "github.com/example/repo/vendor/golang.org/x/tools"
		vendorless := imports.VendorlessPath(vendoredPath)
		if vendorless != "golang.org/x/tools" {
			fmt.Fprintf(os.Stderr, "FAIL: imports.VendorlessPath expected 'golang.org/x/tools', got %q\n", vendorless)
			os.Exit(1)
		}

		plainPath := "net/http"
		if imports.VendorlessPath(plainPath) != "net/http" {
			fmt.Fprintf(os.Stderr, "FAIL: imports.VendorlessPath modified non-vendored path: %q\n", imports.VendorlessPath(plainPath))
			os.Exit(1)
		}
	}

	// Assertion 3: cfg.New constructs a control flow graph containing entry, exit, and branch blocks for a function AST
	{
		src := `package main
func check(val int) string {
	if val > 0 {
		return "positive"
	}
	return "non-positive"
}`
		fset := token.NewFileSet()
		file, err := parser.ParseFile(fset, "check.go", src, 0)
		if err != nil {
			fmt.Fprintf(os.Stderr, "FAIL: parser.ParseFile failed: %v\n", err)
			os.Exit(1)
		}

		if len(file.Decls) == 0 {
			fmt.Fprintln(os.Stderr, "FAIL: no declarations parsed")
			os.Exit(1)
		}
		fn, ok := file.Decls[0].(*ast.FuncDecl)
		if !ok || fn.Body == nil {
			fmt.Fprintln(os.Stderr, "FAIL: expected FuncDecl with body")
			os.Exit(1)
		}

		c := cfg.New(fn.Body, func(call *ast.CallExpr) bool { return true })
		if c == nil {
			fmt.Fprintln(os.Stderr, "FAIL: cfg.New returned nil CFG")
			os.Exit(1)
		}
		if len(c.Blocks) < 3 {
			fmt.Fprintf(os.Stderr, "FAIL: cfg.New expected at least 3 blocks for if-return, got %d\n", len(c.Blocks))
			os.Exit(1)
		}

		entryBlock := c.Blocks[0]
		if len(entryBlock.Succs) == 0 && len(c.Blocks) > 1 {
			fmt.Fprintln(os.Stderr, "FAIL: entry block has no successors in multi-block CFG")
			os.Exit(1)
		}
	}

	// Assertion 4: typeutil.Map associates arbitrary values with go/types Type keys using type identity
	{
		var m typeutil.Map
		intType := types.Typ[types.Int]
		stringType := types.Typ[types.String]
		boolType := types.Typ[types.Bool]

		m.Set(intType, "integer-type")
		m.Set(stringType, "string-type")

		if m.Len() != 2 {
			fmt.Fprintf(os.Stderr, "FAIL: typeutil.Map Len expected 2, got %d\n", m.Len())
			os.Exit(1)
		}

		valInt := m.At(intType)
		if valInt != "integer-type" {
			fmt.Fprintf(os.Stderr, "FAIL: typeutil.Map At(intType) expected 'integer-type', got %v\n", valInt)
			os.Exit(1)
		}

		valStr := m.At(stringType)
		if valStr != "string-type" {
			fmt.Fprintf(os.Stderr, "FAIL: typeutil.Map At(stringType) expected 'string-type', got %v\n", valStr)
			os.Exit(1)
		}

		valBool := m.At(boolType)
		if valBool != nil {
			fmt.Fprintf(os.Stderr, "FAIL: typeutil.Map At(boolType) expected nil, got %v\n", valBool)
			os.Exit(1)
		}

		deleted := m.Delete(intType)
		if !deleted || m.Len() != 1 || m.At(intType) != nil {
			fmt.Fprintf(os.Stderr, "FAIL: typeutil.Map Delete failed: deleted=%v, len=%d\n", deleted, m.Len())
			os.Exit(1)
		}
	}

	// Assertion 5: txtar.Format serializes an Archive with comments and named files into txtar syntax
	{
		arch := &txtar.Archive{
			Comment: []byte("archive header comment\n"),
			Files: []txtar.File{
				{Name: "file1.txt", Data: []byte("line 1\nline 2\n")},
				{Name: "sub/file2.txt", Data: []byte("content 2\n")},
			},
		}
		formatted := txtar.Format(arch)
		if !bytes.Contains(formatted, []byte("-- file1.txt --\n")) {
			fmt.Fprintln(os.Stderr, "FAIL: txtar.Format missing file1.txt marker")
			os.Exit(1)
		}
		if !bytes.Contains(formatted, []byte("-- sub/file2.txt --\n")) {
			fmt.Fprintln(os.Stderr, "FAIL: txtar.Format missing sub/file2.txt marker")
			os.Exit(1)
		}
	}

	// Assertion 6: txtar.Parse parses txtar formatted byte content into structured Archive comments and Files
	{
		raw := []byte("Header comment\n-- doc.txt --\nDocumentation content\n-- code.go --\npackage main\n")
		parsed := txtar.Parse(raw)
		if string(parsed.Comment) != "Header comment\n" {
			fmt.Fprintf(os.Stderr, "FAIL: txtar.Parse unexpected comment: %q\n", string(parsed.Comment))
			os.Exit(1)
		}
		if len(parsed.Files) != 2 {
			fmt.Fprintf(os.Stderr, "FAIL: txtar.Parse expected 2 files, got %d\n", len(parsed.Files))
			os.Exit(1)
		}
		if parsed.Files[0].Name != "doc.txt" || string(parsed.Files[0].Data) != "Documentation content\n" {
			fmt.Fprintf(os.Stderr, "FAIL: txtar.Parse file 0 mismatch: %+v\n", parsed.Files[0])
			os.Exit(1)
		}
		if parsed.Files[1].Name != "code.go" || string(parsed.Files[1].Data) != "package main\n" {
			fmt.Fprintf(os.Stderr, "FAIL: txtar.Parse file 1 mismatch: %+v\n", parsed.Files[1])
			os.Exit(1)
		}
	}

	fmt.Println("PASS: golang.org/x/tools@v0.1.1 contract passed")
}

オリジンシーダー

匿名