CodeSampleX

샘플

golang.org/x/tools v0.44.0

검증된 샘플 — golang golang.org/x/tools v0.44.0. go 1.26 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: txtar.Parse parses txtar-formatted byte data into an…

sha256:12ba36a4332e2b9b2e7eb13365e790abafeb4ea1e09594ff445aed029f31caea

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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.44.0
패키지
생성일
2026-08-28T08:30:15Z

컨트랙트

  1. txtar.Parse parses txtar-formatted byte data into an Archive with comment and file entries
  2. txtar.Format serializes an Archive back into byte data preserving file boundaries and content
  3. astutil.Apply traverses AST nodes invoking pre and post functions and allows node inspection
  4. astutil.AddImport adds an import specification to an AST file
  5. astutil.DeleteImport removes an existing import specification from an AST file
  6. astutil.RewriteImport rewrites import path from old path to new path in an AST file

파일

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

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/tools@v0.44.0
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.
csx.json
{"case":{"caseId":"case:sha256:f58131f28077243d84437b38274cda13bcd7624a0dc750ec67c756d8c85d45ad","contract":["txtar.Parse parses txtar-formatted byte data into an Archive with comment and file entries","txtar.Format serializes an Archive back into byte data preserving file boundaries and content","astutil.Apply traverses AST nodes invoking pre and post functions and allows node inspection","astutil.AddImport adds an import specification to an AST file","astutil.DeleteImport removes an existing import specification from an AST file","astutil.RewriteImport rewrites import path from old path to new path in an AST file"],"goal":"verify pkg:golang/golang.org/x/tools@v0.44.0","kind":"HOW","packages":["pkg:golang/golang.org/x/tools@v0.44.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.44.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/tools@v0.44.0","verifierAdapter":"golang@1"}
go.mod
module sample-golang-tools

go 1.26.6

require golang.org/x/tools v0.44.0
go.sum
golang.org/x/tools v0.44.0 h1:UP4ajHPIcuMjT1GqzDWRlalUEoY+uzoZKnhOjbIPD2c=
golang.org/x/tools v0.44.0/go.mod h1:KA0AfVErSdxRZIsOVipbv3rQhVXTnlU6UhKxHd1seDI=
main.go
package main

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

	"golang.org/x/tools/go/ast/astutil"
	"golang.org/x/tools/txtar"
)

func main() {
	// Parse a txtar archive
	raw := []byte("Header comment\n-- file.txt --\nSample data\n")
	archive := txtar.Parse(raw)
	fmt.Printf("Archive comment: %s, files count: %d\n", string(archive.Comment), len(archive.Files))

	// Format txtar archive
	formatted := txtar.Format(archive)
	fmt.Printf("Formatted size: %d bytes\n", len(formatted))

	// Manipulate Go AST imports
	fset := token.NewFileSet()
	f, err := parser.ParseFile(fset, "example.go", "package main\nfunc run() {}", 0)
	if err == nil {
		astutil.AddImport(fset, f, "fmt")
		fmt.Printf("Package name: %s, imports count: %d\n", f.Name.Name, len(f.Imports))
	}
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/golang.org/x/tools@v0.44.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/tools@v0.44.0"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.go
package main

import (
	"fmt"
	"go/parser"
	"go/token"
	"os"

	"golang.org/x/tools/go/ast/astutil"
	"golang.org/x/tools/txtar"
)

func main() {
	// Assertion 1: txtar.Parse parses txtar-formatted byte data into an Archive with comment and file entries
	{
		archiveData := []byte("Archive comment header\n-- file1.txt --\nHello from file 1\n-- sub/file2.txt --\nLine 1\nLine 2\n")
		archive := txtar.Parse(archiveData)
		if archive == nil {
			fmt.Fprintln(os.Stderr, "FAIL: txtar.Parse returned nil archive")
			os.Exit(1)
		}
		if string(archive.Comment) != "Archive comment header\n" {
			fmt.Fprintf(os.Stderr, "FAIL: txtar.Parse unexpected comment: %q\n", string(archive.Comment))
			os.Exit(1)
		}
		if len(archive.Files) != 2 {
			fmt.Fprintf(os.Stderr, "FAIL: txtar.Parse expected 2 files, got %d\n", len(archive.Files))
			os.Exit(1)
		}
		if archive.Files[0].Name != "file1.txt" || string(archive.Files[0].Data) != "Hello from file 1\n" {
			fmt.Fprintf(os.Stderr, "FAIL: txtar.Parse unexpected file1 content: name=%q data=%q\n", archive.Files[0].Name, string(archive.Files[0].Data))
			os.Exit(1)
		}
		if archive.Files[1].Name != "sub/file2.txt" || string(archive.Files[1].Data) != "Line 1\nLine 2\n" {
			fmt.Fprintf(os.Stderr, "FAIL: txtar.Parse unexpected file2 content: name=%q data=%q\n", archive.Files[1].Name, string(archive.Files[1].Data))
			os.Exit(1)
		}
	}

	// Assertion 2: txtar.Format serializes an Archive back into byte data preserving file boundaries and content
	{
		archive := &txtar.Archive{
			Comment: []byte("Sample comment\n"),
			Files: []txtar.File{
				{Name: "data.json", Data: []byte("{\"ok\":true}\n")},
				{Name: "readme.txt", Data: []byte("Sample readme text\n")},
			},
		}
		formatted := txtar.Format(archive)
		expected := "Sample comment\n-- data.json --\n{\"ok\":true}\n-- readme.txt --\nSample readme text\n"
		if string(formatted) != expected {
			fmt.Fprintf(os.Stderr, "FAIL: txtar.Format mismatch:\ngot:\n%s\nexpected:\n%s\n", string(formatted), expected)
			os.Exit(1)
		}
	}

	// Assertion 3: astutil.Apply traverses AST nodes invoking pre and post functions and allows node inspection
	{
		src := `package main
import "fmt"
func main() {
	fmt.Println("test")
}`
		fset := token.NewFileSet()
		file, err := parser.ParseFile(fset, "src.go", src, parser.ParseComments)
		if err != nil {
			fmt.Fprintf(os.Stderr, "FAIL: parser.ParseFile failed: %v\n", err)
			os.Exit(1)
		}

		visitedPre := 0
		visitedPost := 0
		astutil.Apply(file, func(c *astutil.Cursor) bool {
			if c.Node() != nil {
				visitedPre++
			}
			return true
		}, func(c *astutil.Cursor) bool {
			if c.Node() != nil {
				visitedPost++
			}
			return true
		})

		if visitedPre == 0 || visitedPre != visitedPost {
			fmt.Fprintf(os.Stderr, "FAIL: astutil.Apply visit count mismatch: pre=%d post=%d\n", visitedPre, visitedPost)
			os.Exit(1)
		}
	}

	// Assertion 4: astutil.AddImport adds an import specification to an AST file
	{
		src := `package main

func hello() {}`
		fset := token.NewFileSet()
		file, err := parser.ParseFile(fset, "src.go", src, 0)
		if err != nil {
			fmt.Fprintf(os.Stderr, "FAIL: parser.ParseFile failed: %v\n", err)
			os.Exit(1)
		}

		added := astutil.AddImport(fset, file, "strings")
		if !added {
			fmt.Fprintln(os.Stderr, "FAIL: astutil.AddImport returned false for new import")
			os.Exit(1)
		}

		found := false
		for _, imp := range file.Imports {
			if imp.Path.Value == `"strings"` {
				found = true
				break
			}
		}
		if !found {
			fmt.Fprintln(os.Stderr, "FAIL: astutil.AddImport did not add import to file.Imports")
			os.Exit(1)
		}
	}

	// Assertion 5: astutil.DeleteImport removes an existing import specification from an AST file
	{
		src := `package main

import (
	"fmt"
	"strings"
)

func hello() {}`
		fset := token.NewFileSet()
		file, err := parser.ParseFile(fset, "src.go", src, 0)
		if err != nil {
			fmt.Fprintf(os.Stderr, "FAIL: parser.ParseFile failed: %v\n", err)
			os.Exit(1)
		}

		deleted := astutil.DeleteImport(fset, file, "fmt")
		if !deleted {
			fmt.Fprintln(os.Stderr, "FAIL: astutil.DeleteImport returned false for existing import")
			os.Exit(1)
		}

		for _, imp := range file.Imports {
			if imp.Path.Value == `"fmt"` {
				fmt.Fprintln(os.Stderr, "FAIL: astutil.DeleteImport failed to remove import")
				os.Exit(1)
			}
		}
	}

	// Assertion 6: astutil.RewriteImport rewrites import path from old path to new path in an AST file
	{
		src := `package main

import "old/path"

func hello() {}`
		fset := token.NewFileSet()
		file, err := parser.ParseFile(fset, "src.go", src, 0)
		if err != nil {
			fmt.Fprintf(os.Stderr, "FAIL: parser.ParseFile failed: %v\n", err)
			os.Exit(1)
		}

		rewritten := astutil.RewriteImport(fset, file, "old/path", "new/path")
		if !rewritten {
			fmt.Fprintln(os.Stderr, "FAIL: astutil.RewriteImport returned false")
			os.Exit(1)
		}

		found := false
		for _, imp := range file.Imports {
			if imp.Path.Value == `"new/path"` {
				found = true
				break
			}
		}
		if !found {
			fmt.Fprintln(os.Stderr, "FAIL: astutil.RewriteImport did not update to new path")
			os.Exit(1)
		}
	}

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

오리진 시더

익명