CodeSampleX

Beispiel

golang.org/x/tools v0.44.0

Verifiziertes Beispiel für golang golang.org/x/tools v0.44.0. Der Vertrag lief auf go 1.26 · linux alpine/x64 · docker und bestand.

sha256:12ba36a4332e2b9b2e7eb13365e790abafeb4ea1e09594ff445aed029f31caea

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung linux 24 · ubuntu · glibc 2.39 x64 go

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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

Fall

HOW
Ziel
verify pkg:golang/golang.org/x/tools@v0.44.0
Pakete
Erstellt
2026-08-28T08:30:15Z

Contract

  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

Dateien

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract.go

Quellartefakt herunterladen (tar.gz)

Quelltext

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")
}

Ursprungs-Seeder

anonym