docs/cmd/teststamp.md

teststamp: AgentHub test stamps

cmd/teststamp is a developer tool that the justfile runs to skip a self-contained AgentHub test target whose inputs match the committed stamp from its last passing run. It is not shipped or built by just build; the stamped recipes build it to build/teststamp so that its exit status is go test's own rather than go run's. The policy, what a stamp may and may not replace, and the merge-conflict rule are in the test guide.

RoleLocation
Subcommands and go test result parsingcmd/teststamp/main.go
Eligibility policy, hashed inputs and hashVersioncmd/teststamp/inputs.go
Stamp file format and writescmd/teststamp/stampfile.go
Stamp filetests/agenthub-stamps.txt
Callersjustfile (_go-test-stamped, test-agenthub-fixtures, test-stamps-refresh, test-hub-deep)

Subcommands

sh
1teststamp go-test -stamps FILE -hub REGEX [-timeout D] [-refresh] [-plan] PACKAGE...
2teststamp go-bypass -stamps FILE -packages LIST [GO-TEST-FLAG...]
3teststamp ruby -stamps FILE -ruby PATH -tree DIR [-refresh] SCRIPT
4teststamp hash -hub REGEX [-stamps FILE] PACKAGE...

go-test lists the named packages, skips each stamp-eligible AgentHub package whose closure hash matches its stamp, and runs the rest in one go test invocation. It records each eligible package with a passing summary line and removes stamps of ineligible or deleted packages. A package that fails or has no summary line keeps its trial counters, but its closure becomes failed, which never matches. Before running, it marks still-matching stamps failed the same way, so an interrupted refresh leaves nothing to match. -refresh, or a non-empty EZ_AGENT_HUB_DEEP, runs every eligible package. Non-hub packages in the selection always run. Its exit status is the go test status. -plan prints the lists and the packages whose passes would be recorded, then exits without starting go test or writing the stamp file.

An eligible package whose own Go files read an environment variable that is set to a non-empty value, other than EZ_AGENT_HUB_DEEP, runs in go-test without its stamp, because the variable may enable tests the stamp never ran. An example is EZ_AGENT_CAPACITY_PROBE in internal/agenthub/service. The output lists each such package with the variable names. That package is handled like a go-bypass run. A pass records nothing, even under refresh, a FAIL marks its stamp failed, and a missing result leaves the stamp alone. Packages that read no set variable keep normal stamp behavior in the same run. The variables are those named by a string-literal argument to os.Getenv or os.LookupEnv, or by a literal os.ExpandEnv template, in the package's source and test files.

go-bypass is the path for runs with caller-chosen Go flags, such as -run, -race or -count, and for EZ_AGENT_MAXIMUM_CAPACITY. It runs go test with those flags unchanged over LIST, and its output and exit status are go test's. It never records a pass. It marks failed only the stamped packages that reported FAIL. A package with no result keeps its stamp: the run may have been interrupted, or the flags may have kept it from running, and neither is evidence against the stamp.

ruby runs the script with this checkout's build/ez-agent-ruby whenever that file exists and is executable, and says so when -ruby names a different interpreter. Only that interpreter is stamped. A checkout with no build runs the script with the -ruby interpreter: a pass records nothing and a failure marks an existing stamp failed. The digest covers the checker's tree, the interpreter's RUBY_DESCRIPTION, the Go toolchain and the tracked ez-agent-ruby inputs that determine the embedded runtime: runtime/ (source lock and build scripts), lib/, the wrapper, launcher, payload packager and manifest sources, go.mod and LICENSE. The binary itself is not hashed because its build is not reproducible, so the stamp assumes it was built from this checkout by just build. The script runs on a mismatch. Its line is marked failed before it runs, so a failed or interrupted run leaves nothing to match, and a pass records the stamp.

hash writes nothing. It prints each AgentHub package's eligibility, its reason when ineligible, and its digests. Under each eligible package it lists the environment variables the package reads, the ones set now that would run it without its stamp, and any environment reads the scan could not classify. With -stamps it also prints whether the stored stamp matches. Use it to see why a package runs:

sh
1go run ./cmd/teststamp hash \
2 -hub '/(cmd/ez-agent-hub|internal/agenthub|internal/hubfeature|pkg/ezhubapi)(/|$)' \
3 -stamps tests/agenthub-stamps.txt ./internal/agenthub/...

The -hub pattern must match agenthub_go_pattern in the justfile. -refresh ignores matching stamps. Each write re-reads the stamp file and changes only the lines for the targets it ran. Writes are not locked, so run one stamped recipe per checkout at a time.

A stamp file with any unparseable non-comment line, such as a merge-conflict marker, or a repeated target is discarded whole: every target runs, the output says so, and the next write produces a clean file from that run's results.

Limits

Inputs are found statically: files listed by go list, the package's testdata, the shared corpus, string literals starting with ./ or ../, and the leading string-literal arguments of path.Join or filepath.Join when they join to a path starting with ... A test that reaches a file outside its package directory and the shared corpus through a path the tool cannot see statically, such as one built from a variable or by concatenation, is not detected; neither is a non-Go file in the package directory outside testdata. Such tests must use a literal relative path or keep the file under testdata.

Dependency sources that go.sum does not pin are not hashed. A local-directory replace in go.mod, a vendor directory, -mod=vendor or -modfile in GOFLAGS, or an active go.work makes every AgentHub package ineligible.

The environment scan sees only the package's own files. A variable read inside a dependency, or by a child program other than the package's own test binary, is not detected. os.Environ does not count as a read, because every use in the stamped packages forwards the environment to a child that re-runs the same test binary, whose literal reads are already collected. Any other use of os.Getenv, os.LookupEnv or os.ExpandEnv, such as a non-literal argument or passing os.Getenv as a function value, is reported by hash as unclassified and does not change eligibility or skipping. Current cases are the XDG reads in internal/agenthub/paths and internal/hubfeature, which tests set with t.Setenv. A variable that switches tests on must therefore be read with a literal name. A literal read of a variable that is normally set, such as XDG_RUNTIME_DIR, keeps that package from being skipped wherever the variable is set.

Change hashVersion in inputs.go whenever the hashed input set changes meaning. Unit tests are in cmd/teststamp/teststamp_test.go and run in the default just test-go scope.