CodeSampleX

샘플

golang.org/x/tools v0.49.0

검증된 샘플 — golang golang.org/x/tools v0.49.0. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: astutil.PathEnclosingInterval finds the enclosing AST…

sha256:7cc0f6a26eb180a4caec0328d4d8f57b1f622c1128f079e3522360c41679541e

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

케이스

HOW
목표
verify pkg:golang/golang.org/x/tools@v0.49.0
패키지
생성일
2026-09-02T20:02:57Z

컨트랙트

  1. astutil.PathEnclosingInterval finds the enclosing AST node path from innermost node to root file for an exact identifier
  2. astutil.PathEnclosingInterval reports exact true when the query interval encompasses an isolated AST expression node
  3. astutil.PathEnclosingInterval reports exact false when the interval spans across multiple sibling statements
  4. astutil.PathEnclosingInterval treats zero-length intervals with identical start and end positions as single-byte lookups
  5. astutil.PathEnclosingInterval returns the enclosing binary expression node when positioned on an arithmetic operator

파일

  • PROMPT.md
  • astinterval.go
  • csx.json
  • go.mod
  • go.sum
  • 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.49.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/tools@v0.49.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.
astinterval.go
package astinterval

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

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

// ParseSource parses a Go source code string into an AST file and token.FileSet.
func ParseSource(src string) (*token.FileSet, *ast.File, error) {
	fset := token.NewFileSet()
	file, err := parser.ParseFile(fset, "src.go", src, 0)
	if err != nil {
		return nil, nil, fmt.Errorf("parse error: %w", err)
	}
	return fset, file, nil
}

// FindEnclosingPath returns the path of AST nodes enclosing the [start, end) interval.
func FindEnclosingPath(root *ast.File, start, end token.Pos) ([]ast.Node, bool) {
	return astutil.PathEnclosingInterval(root, start, end)
}

// FindInnermostNode returns the innermost AST node enclosing the [start, end) interval.
func FindInnermostNode(root *ast.File, start, end token.Pos) (ast.Node, bool) {
	path, exact := astutil.PathEnclosingInterval(root, start, end)
	if len(path) == 0 {
		return nil, false
	}
	return path[0], exact
}

// FindNodeAtPoint returns the AST node at a single point position.
func FindNodeAtPoint(root *ast.File, pos token.Pos) (ast.Node, bool) {
	return FindInnermostNode(root, pos, pos)
}
csx.json
{"case":{"caseId":"case:sha256:2fd3fddd4bab9df420a576fcb34e4c7f3d53bfed33cf1759092391475632764c","contract":["astutil.PathEnclosingInterval finds the enclosing AST node path from innermost node to root file for an exact identifier","astutil.PathEnclosingInterval reports exact true when the query interval encompasses an isolated AST expression node","astutil.PathEnclosingInterval reports exact false when the interval spans across multiple sibling statements","astutil.PathEnclosingInterval treats zero-length intervals with identical start and end positions as single-byte lookups","astutil.PathEnclosingInterval returns the enclosing binary expression node when positioned on an arithmetic operator"],"goal":"verify pkg:golang/golang.org/x/tools@v0.49.0","kind":"HOW","packages":["pkg:golang/golang.org/x/tools@v0.49.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.49.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/tools@v0.49.0","verifierAdapter":"golang@1"}
go.mod
module example.com/astutil-interval

go 1.25.0

require golang.org/x/tools v0.49.0
go.sum
golang.org/x/tools v0.49.0 h1:3NI7VXzL9+1WZD52Dx2ttoPwD5DWrFGpl9mFZDlmisI=
golang.org/x/tools v0.49.0/go.mod h1:SJNXV9DBKT0UbdttsQjbfJlAE/q+y36++zo3uL3N0Oo=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/golang.org/x/tools@v0.49.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/tools@v0.49.0"
  ]
}
test/contract.go
package main

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

	"example.com/astutil-interval"
	"golang.org/x/tools/go/ast/astutil"
)

func main() {
	src := `package p

func sample() int {
	x := 42
	y := 10 + 20
	return x + y
}
`
	_, file, err := astinterval.ParseSource(src)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: failed to parse source: %v\n", err)
		os.Exit(1)
	}

	var fnDecl *ast.FuncDecl
	for _, decl := range file.Decls {
		if fn, ok := decl.(*ast.FuncDecl); ok && fn.Name.Name == "sample" {
			fnDecl = fn
			break
		}
	}
	if fnDecl == nil || fnDecl.Body == nil || len(fnDecl.Body.List) < 3 {
		fmt.Fprintf(os.Stderr, "FAIL: expected sample function with at least 3 statements\n")
		os.Exit(1)
	}

	stmt1, ok1 := fnDecl.Body.List[0].(*ast.AssignStmt)
	stmt2, ok2 := fnDecl.Body.List[1].(*ast.AssignStmt)
	if !ok1 || !ok2 {
		fmt.Fprintf(os.Stderr, "FAIL: expected assignment statements in function body\n")
		os.Exit(1)
	}

	// Assertion 1: astutil.PathEnclosingInterval finds the enclosing AST node path from innermost node to root file for an exact identifier
	{
		identX, ok := stmt1.Lhs[0].(*ast.Ident)
		if !ok || identX.Name != "x" {
			fmt.Fprintf(os.Stderr, "FAIL 1: expected lhs identifier 'x'\n")
			os.Exit(1)
		}

		path, exact := astutil.PathEnclosingInterval(file, identX.Pos(), identX.End())
		if len(path) == 0 {
			fmt.Fprintf(os.Stderr, "FAIL 1: path is empty\n")
			os.Exit(1)
		}
		if innermost, ok := path[0].(*ast.Ident); !ok || innermost.Name != "x" {
			fmt.Fprintf(os.Stderr, "FAIL 1: innermost node is not identifier 'x', got %T\n", path[0])
			os.Exit(1)
		}
		if _, ok := path[len(path)-1].(*ast.File); !ok {
			fmt.Fprintf(os.Stderr, "FAIL 1: root node is not *ast.File, got %T\n", path[len(path)-1])
			os.Exit(1)
		}
		if !exact {
			fmt.Fprintf(os.Stderr, "FAIL 1: expected exact=true for complete identifier interval\n")
			os.Exit(1)
		}
	}

	// Assertion 2: astutil.PathEnclosingInterval reports exact true when the query interval encompasses an isolated AST expression node
	{
		lit, ok := stmt1.Rhs[0].(*ast.BasicLit)
		if !ok || lit.Value != "42" {
			fmt.Fprintf(os.Stderr, "FAIL 2: expected rhs basic lit '42'\n")
			os.Exit(1)
		}

		node, exact := astinterval.FindInnermostNode(file, lit.Pos(), lit.End())
		if !exact {
			fmt.Fprintf(os.Stderr, "FAIL 2: expected exact=true for basic lit interval\n")
			os.Exit(1)
		}
		if matchedLit, ok := node.(*ast.BasicLit); !ok || matchedLit.Value != "42" {
			fmt.Fprintf(os.Stderr, "FAIL 2: expected BasicLit '42', got %v\n", node)
			os.Exit(1)
		}
	}

	// Assertion 3: astutil.PathEnclosingInterval reports exact false when the interval spans across multiple sibling statements
	{
		path, exact := astutil.PathEnclosingInterval(file, stmt1.Pos(), stmt2.End())
		if exact {
			fmt.Fprintf(os.Stderr, "FAIL 3: expected exact=false for multi-statement spanning range\n")
			os.Exit(1)
		}
		if len(path) == 0 {
			fmt.Fprintf(os.Stderr, "FAIL 3: expected non-empty path\n")
			os.Exit(1)
		}
		if _, ok := path[0].(*ast.BlockStmt); !ok {
			fmt.Fprintf(os.Stderr, "FAIL 3: expected enclosing node to be *ast.BlockStmt, got %T\n", path[0])
			os.Exit(1)
		}
	}

	// Assertion 4: astutil.PathEnclosingInterval treats zero-length intervals with identical start and end positions as single-byte lookups
	{
		identX := stmt1.Lhs[0].(*ast.Ident)
		node, exact := astinterval.FindNodeAtPoint(file, identX.Pos())
		if !exact {
			fmt.Fprintf(os.Stderr, "FAIL 4: expected exact=true for point lookup at identifier start\n")
			os.Exit(1)
		}
		if ident, ok := node.(*ast.Ident); !ok || ident.Name != "x" {
			fmt.Fprintf(os.Stderr, "FAIL 4: expected ident 'x' on zero-length lookup, got %T\n", node)
			os.Exit(1)
		}
	}

	// Assertion 5: astutil.PathEnclosingInterval returns the enclosing binary expression node when positioned on an arithmetic operator
	{
		binExpr, ok := stmt2.Rhs[0].(*ast.BinaryExpr)
		if !ok || binExpr.Op != token.ADD {
			fmt.Fprintf(os.Stderr, "FAIL 5: expected binary expression with addition\n")
			os.Exit(1)
		}

		path, exact := astutil.PathEnclosingInterval(file, binExpr.OpPos, binExpr.OpPos+1)
		if !exact {
			fmt.Fprintf(os.Stderr, "FAIL 5: expected exact=true for operator in binary expr\n")
			os.Exit(1)
		}
		if len(path) == 0 {
			fmt.Fprintf(os.Stderr, "FAIL 5: path is empty\n")
			os.Exit(1)
		}
		if matchedBin, ok := path[0].(*ast.BinaryExpr); !ok || matchedBin.Op != token.ADD {
			fmt.Fprintf(os.Stderr, "FAIL 5: expected enclosing *ast.BinaryExpr with '+', got %T\n", path[0])
			os.Exit(1)
		}
	}

	fmt.Println("PASS: all astutil.PathEnclosingInterval contract assertions verified")
}

오리진 시더

익명