CodeSampleX

Sample

golang.org/x/tools v0.1.12: packages.Load

Verified sample for golang golang.org/x/tools v0.1.12: packages.Load. The contract ran on go 1.26 · linux debian/x64 · docker and passed.

sha256:aece438cd2c1205c417d61c72a6e5a92422b1dd22f9f3fff1914336306a3716b

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment linux 24 · ubuntu · glibc 2.39 x64 go

Verification-run environments

Environment Contract Stages Run
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-01

Case

HOW
Goal
verify golang.org/x/tools/go/packages.Load in pkg:golang/golang.org/x/tools@v0.1.12
Packages
Symbols
  • golang.org/x/tools/go/packages.Load
Created
2026-09-01T06:01:28Z

Contract

  1. packages.Load loads package metadata with packages.NeedName
  2. packages.Load returns non-empty slice of packages for valid patterns
  3. packages.Load populates PkgPath and ID on loaded packages
  4. packages.Config allows specifying custom Dir and LoadMode
  5. sample.LoadPackageNames returns expected package path for current module

Files

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

Download the source artifact (tar.gz)

Source

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 golang.org/x/tools/go/packages.Load in pkg:golang/golang.org/x/tools@v0.1.12
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/tools@v0.1.12
Demonstrate these symbols/APIs:
  - golang.org/x/tools/go/packages.Load

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:7538cbe2f9c7d66d315925358d12140f6769d9a91ad9778628fcf4084be5534b","contract":["packages.Load loads package metadata with packages.NeedName","packages.Load returns non-empty slice of packages for valid patterns","packages.Load populates PkgPath and ID on loaded packages","packages.Config allows specifying custom Dir and LoadMode","sample.LoadPackageNames returns expected package path for current module"],"goal":"verify golang.org/x/tools/go/packages.Load in pkg:golang/golang.org/x/tools@v0.1.12","kind":"HOW","packages":["pkg:golang/golang.org/x/tools@v0.1.12"],"schemaVersion":1,"symbols":["golang.org/x/tools/go/packages.Load"]},"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.12"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/tools@v0.1.12","symbols":["golang.org/x/tools/go/packages.Load"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.22

require golang.org/x/tools v0.1.12

require (
	golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
	golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
)
go.sum
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
loader.go
package sample

import (
	"fmt"

	"golang.org/x/tools/go/packages"
)

// LoadPackages loads packages matching given patterns with specified mode.
func LoadPackages(dir string, mode packages.LoadMode, patterns ...string) ([]*packages.Package, error) {
	cfg := &packages.Config{
		Mode: mode,
		Dir:  dir,
	}
	pkgs, err := packages.Load(cfg, patterns...)
	if err != nil {
		return nil, fmt.Errorf("packages.Load failed: %w", err)
	}
	return pkgs, nil
}

// LoadPackageNames loads packages and returns their PkgPath list.
func LoadPackageNames(dir string, patterns ...string) ([]string, error) {
	pkgs, err := LoadPackages(dir, packages.NeedName, patterns...)
	if err != nil {
		return nil, err
	}
	names := make([]string, 0, len(pkgs))
	for _, pkg := range pkgs {
		names = append(names, pkg.PkgPath)
	}
	return names, nil
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify golang.org/x/tools/go/packages.Load in pkg:golang/golang.org/x/tools@v0.1.12",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/tools@v0.1.12"
  ],
  "symbols": [
    "golang.org/x/tools/go/packages.Load"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"golang.org/x/tools/go/packages"
	"sample"
)

func main() {
	// Assertion 1: packages.Load can load package metadata with packages.NeedName
	cfg := &packages.Config{
		Mode: packages.NeedName,
		Dir:  ".",
	}
	pkgs, err := packages.Load(cfg, ".")
	if err != nil {
		fmt.Fprintf(os.Stderr, "packages.Load failed: %v\n", err)
		os.Exit(1)
	}

	// Assertion 2: packages.Load returns non-empty slice of packages for valid package patterns
	if len(pkgs) == 0 {
		fmt.Fprintf(os.Stderr, "expected at least 1 package, got 0\n")
		os.Exit(1)
	}

	// Assertion 3: packages.Load populates PkgPath and ID on loaded packages
	pkg := pkgs[0]
	if pkg.PkgPath != "sample" {
		fmt.Fprintf(os.Stderr, "expected PkgPath 'sample', got %q\n", pkg.PkgPath)
		os.Exit(1)
	}
	if pkg.ID != "sample" {
		fmt.Fprintf(os.Stderr, "expected ID 'sample', got %q\n", pkg.ID)
		os.Exit(1)
	}

	// Assertion 4: packages.Config allows specifying custom Dir and LoadMode
	modeCfg := &packages.Config{
		Mode: packages.NeedName | packages.NeedFiles,
		Dir:  ".",
	}
	modePkgs, err := packages.Load(modeCfg, ".")
	if err != nil || len(modePkgs) == 0 {
		fmt.Fprintf(os.Stderr, "packages.Load with NeedFiles failed: %v\n", err)
		os.Exit(1)
	}
	if len(modePkgs[0].GoFiles) == 0 {
		fmt.Fprintf(os.Stderr, "expected GoFiles to be populated with NeedFiles mode\n")
		os.Exit(1)
	}

	// Assertion 5: sample.LoadPackageNames returns expected package path for current module
	names, err := sample.LoadPackageNames(".", ".")
	if err != nil {
		fmt.Fprintf(os.Stderr, "LoadPackageNames failed: %v\n", err)
		os.Exit(1)
	}
	if len(names) != 1 || names[0] != "sample" {
		fmt.Fprintf(os.Stderr, "expected ['sample'], got %v\n", names)
		os.Exit(1)
	}

	fmt.Println("All golang.org/x/tools/go/packages.Load contract assertions passed.")
}

Origin Seeder

anonymous