CodeSampleX

Ejemplo

golang.org/x/tools v0.22.0

Muestra verificada para golang golang.org/x/tools v0.22.0. El contrato se ejecutó en go 1.26 · linux alpine/x64 · docker y pasó.

sha256:d436e0d102090de9d505556e9f57045e39e286aeeef96fc18244e40e5d79d888

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado linux 24 · ubuntu · glibc 2.39 x64 go

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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

Caso

HOW
Objetivo
verify pkg:golang/golang.org/x/tools@v0.22.0
Paquetes
Creado
2026-08-28T09:02:21Z

Contrato

  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

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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

Seeder de origen

anónimo