Documentation
¶
Overview ¶
Package worktreetest builds, for tests only, the repository a machine job's worktree is made from: an origin whose default branch carries benign agent configuration, and a commit under review that carries hostile configuration of its own — a SessionStart hook, an MCP server, instructions, a nested `.claude/` — each of which, if it reached the CLI, would leave a marker file.
It is a package rather than a _test.go helper because three suites build the same repository: the adapter's script tests (internal/agentprovision), the job runner's end-to-end test (internal/api), and the real-CLI test that runs inside the agent image.
Index ¶
- Constants
- func CommitFiles(markers string) map[string]string
- func DefaultFiles(markers string) map[string]string
- func FakeSSH(t *testing.T, path, root string, writable bool) (logPath string)
- func Git(t *testing.T, dir string, args ...string) string
- func GitShim(t *testing.T, path string) string
- func GitShimCalls(t *testing.T, log string) [][]string
- func GitSubcommand(argv []string) string
- func SSHLog(t *testing.T, logPath string) string
- type Repo
Constants ¶
const ( // DefaultHookMarker is written by the DEFAULT branch's SessionStart hook: // its presence shows a CLI did start and run project hooks. DefaultHookMarker = "default-hook" // CommitHookMarker is written by the COMMIT's SessionStart hook. CommitHookMarker = "commit-hook" // NestedHookMarker is written by the hook in the commit's nested // deep/.claude/settings.json. NestedHookMarker = "nested-hook" // CommitMCPMarker is written by the MCP server the commit's .mcp.json // declares (and its settings auto-approve). CommitMCPMarker = "commit-mcp" )
The marker files a hook or server leaves in the markers directory. Each line is the directory it ran in.
const ( // RepoName is the job's `repo`. RepoName = "acme/widgets" // PR is the pull request whose head is Commit: refs/pull/7/head on Origin, // the ONLY ref Commit is reachable from. PR = 7 )
The fixture's repository and pull request, as a job names them.
const ( FakeSSHLogEnv = "MUSTER_FAKE_SSH_LOG" FakeSSHRootEnv = "MUSTER_FAKE_SSH_ROOT" FakeSSHWritableEnv = "MUSTER_FAKE_SSH_WRITABLE" // FakeSSHEnvLogEnv, set, is a file each invocation appends its whole // environment to (`env`), for a test that reads what reached ssh. FakeSSHEnvLogEnv = "MUSTER_FAKE_SSH_ENVLOG" )
FakeSSHLogEnv, FakeSSHRootEnv and FakeSSHWritableEnv steer the fake ssh FakeSSH installs.
const FakeSSHReadOnlyRefusal = "ERROR: The key you are authenticating with has been marked as read only."
FakeSSHReadOnlyRefusal is what the fake answers git-receive-pack with unless FakeSSHWritableEnv is set: GitHub's refusal of a read-only deploy key.
const GitShimLogEnv = "MUSTER_GIT_SHIM_LOG"
GitShimLogEnv names the file GitShim's `git` appends each invocation to.
Variables ¶
This section is empty.
Functions ¶
func CommitFiles ¶
CommitFiles is what the commit under review changes or adds on top of the default branch's tree.
func DefaultFiles ¶
DefaultFiles is the default branch's tree. A test asserts against these literal contents; with markers "" the marker paths read "/markers".
func FakeSSH ¶ added in v0.110.0
FakeSSH sets PATH to a directory holding a fake `ssh` followed by path (the caller's PATH, which the test reads: this package is not a _test.go file, and a variable read here would count as configuration) for the rest of the test, serving repositories from root (the fixture's anonymous base directory: Origin is root/acme/widgets), and returns the file each invocation's argv is appended to. With writable, it also accepts git-receive-pack (a deploy key that can push).
func Git ¶
Git runs git in dir ("" = the current directory) with a fixed identity and commit signing off, and returns its trimmed output.
func GitShim ¶ added in v0.110.0
GitShim puts a `git` first on PATH (path is the caller's PATH, which the test reads) for the rest of the test that logs every invocation's argv and then runs the real git — including the gits git itself starts through the shell (an --upload-pack command) — and returns the log's path (GitShimCalls).
func GitShimCalls ¶ added in v0.110.0
GitShimCalls is every argv GitShim logged, in order.
func GitSubcommand ¶ added in v0.110.0
GitSubcommand is argv's git subcommand: the first argument that is not a global option (-c and -C take a value).
Types ¶
type Repo ¶
Repo is the fixture. Origin is a bare repository at <AnonBase>acme/widgets — so a job's anonymous fetch URL is AnonBase + RepoName — and Checkout is the agent's clone of it, on the default branch. Commit, the commit under review, is on Origin only as refs/pull/7/head, which the clone has NOT fetched (so a job must fetch the pull ref). Stray is a commit on another branch, not reachable from the pull request's head.
func New ¶
New builds the fixture: Origin a bare repository in a temporary directory, Checkout a clone of it at checkout (which must not exist yet), markers the directory the hooks write to (created).
func (Repo) AnonRoot ¶ added in v0.110.0
AnonRoot is the directory the fixture's anonymous base names (AnonBase without its file:// scheme): Origin is AnonRoot/acme/widgets.
func (Repo) MarkerFiles ¶
MarkerFiles is the content of the markers directory: file name → content.