worktreetest

package
v0.167.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
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.

View Source
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.

View Source
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.

View Source
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

func CommitFiles(markers string) map[string]string

CommitFiles is what the commit under review changes or adds on top of the default branch's tree.

func DefaultFiles

func DefaultFiles(markers string) map[string]string

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

func FakeSSH(t *testing.T, path, root string, writable bool) (logPath string)

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

func Git(t *testing.T, dir string, args ...string) string

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

func GitShim(t *testing.T, path string) string

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

func GitShimCalls(t *testing.T, log string) [][]string

GitShimCalls is every argv GitShim logged, in order.

func GitSubcommand added in v0.110.0

func GitSubcommand(argv []string) string

GitSubcommand is argv's git subcommand: the first argument that is not a global option (-c and -C take a value).

func SSHLog added in v0.110.0

func SSHLog(t *testing.T, logPath string) string

SSHLog is what FakeSSH logged: one argv per line, "" when ssh never ran.

Types

type Repo

type Repo struct {
	Origin, Checkout, Markers, AnonBase string
	Default, Commit, Stray              string
}

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

func New(t *testing.T, checkout, markers string) Repo

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

func (r Repo) AnonRoot() string

AnonRoot is the directory the fixture's anonymous base names (AnonBase without its file:// scheme): Origin is AnonRoot/acme/widgets.

func (Repo) MarkerFiles

func (r Repo) MarkerFiles(t *testing.T) map[string]string

MarkerFiles is the content of the markers directory: file name → content.

func (Repo) PlainWorktree

func (r Repo) PlainWorktree(t *testing.T, dir string)

PlainWorktree is the POSITIVE CONTROL: the commit checked out as a worktree at dir with NO overlay — what a job's directory would hold without it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL