Documentation
¶
Overview ¶
Package testkit holds the fixtures the tests of several packages share: the scripted shell and git fakes, the listing builders, the agent and git repo helpers, and the TestMain that adds the drive watcher's no-op to the hermetic environment of package testenv.
Index ¶
- Constants
- Variables
- func AgentOf(id string) string
- func Canonical(t *testing.T, path string) string
- func ChildTarget(t *testing.T, cli string) *target.Target
- func CommitFile(t *testing.T, dir, name string)
- func DeclaredTracker(t *testing.T, kind facts.TrackerKind) *target.Target
- func ExitCode(err error) int
- func FakeDriver(t *testing.T) *trackerdriver.Driver
- func GhHeadOf(branch string) string
- func GhReviewer(t *testing.T, f *Fakes, rf facts.Review) *reviews.Reviewer
- func GhStackOf(branch string) string
- func Git(t *testing.T, dir string, args ...string) string
- func GitExitCode(err error) int
- func Heads(names ...string) string
- func IndexAfter(calls []string, want string, after int) int
- func IndexOf(t *testing.T) *stack.BranchIndex
- func IsolateEnv(t *testing.T) string
- func IssueURL(id string) string
- func Main(m *testing.M)
- func MkRepo(t *testing.T) string
- func PacedFlowIn(eff *facts.Effective, set *facts.PaceSet, pace, name string) (runplan.ShipFlow, error)
- func Porcelain(pairs ...string) string
- func PrRepo(t *testing.T) string
- func Raised(t *testing.T, dir string, a asks.Ask) asks.Ask
- func RefsKey(root, id string) string
- func ScopeRepo(t *testing.T, parent, name string) string
- func ScreenWith(box string) string
- func ScriptNoBranch(f *Fakes, ids ...string)
- func SessionTask(t *testing.T, id string)
- func SettledFacts() facts.Review
- func StaleOf(value string) facts.StaleAfter
- func StatEvent(at time.Time, session, task, kind string, p ledger.Payload) ledger.Event
- func StatEvents(day time.Time) []ledger.Event
- func StickyFacts() facts.Review
- func Titled(title string, err error) func(context.Context) (string, error)
- func TitledHost() hostops.Host
- func TracedRepo(t *testing.T, branch, traces string) string
- func WithLinks(t *testing.T, on bool)
- func WithTerminal(t *testing.T, on bool)
- func WriteDriver(t *testing.T, storageRoot string) string
- func WriteFile(t *testing.T, path, text string)
- func WriteHandoffFile(t *testing.T, path, head string)
- func WriteLore(t *testing.T, root string, entries ...lore.Entry)
- func WritePlan(t *testing.T, path string)
- func WriteUserFile(t *testing.T, home, name, body string)
- func WriteVerdict(t *testing.T, root, task, n, subject, verdict string, at time.Time) string
- type Fakes
- type FixtureCall
- type GitRepo
- type MemAgents
- func (m *MemAgents) Available() error
- func (m *MemAgents) Close(context.Context, string) error
- func (m *MemAgents) Focus(context.Context, string) error
- func (m *MemAgents) Name() string
- func (m *MemAgents) Occupancy(context.Context, agentctl.Opened) (agentctl.Occupancy, error)
- func (m *MemAgents) Open(_ context.Context, path, label string) (agentctl.Opened, []string, error)
- func (m *MemAgents) Prompt(_ context.Context, name, text string) error
- func (m *MemAgents) Screen(context.Context, string) (string, error)
- func (m *MemAgents) SendEnter(_ context.Context, name string) error
- func (m *MemAgents) StartAgent(_ context.Context, _ agentctl.Opened, name, _ string, args []string, ...) error
- func (m *MemAgents) Workspaces(context.Context) ([]agentctl.Workspace, error)
Constants ¶
const ( FwdMain = "/code/repo" FwdWT = "/code/repo.GH-1" FwdText = "/f10:ship GH-1" )
const ( RefsOrigin = "" /* 144-byte string literal not displayed */ RefsLocal = "git for-each-ref --format=%(refname) refs/heads/GH-1 refs/heads/GH-1-* refs/heads/GH-1+* refs/heads/GH-1+*/*" RefsAfter = "git for-each-ref --format=%(refname) refs/heads/GH-7 refs/heads/GH-7-* refs/heads/GH-7+* refs/heads/GH-7+*/*" RefsAfterO = "" /* 144-byte string literal not displayed */ AllHeads = "git for-each-ref --format=%(refname) refs/heads/" ShaAfter = "git rev-parse --verify --quiet GH-7/base" CfgTask = "set branch.GH-1.f10-after GH-7" CfgBranch = "set branch.GH-1.f10-after-branch GH-7/base" Worktrees = "git worktree list --porcelain" ShaLocal = "git rev-parse --verify --quiet refs/heads/release/1.2" ShaRemote = "git rev-parse --verify --quiet refs/remotes/release/1.2" ShaOrigin = "git rev-parse --verify --quiet refs/remotes/origin/release/1.2" HeadRef = "git symbolic-ref --short refs/remotes/origin/HEAD" ShaMain = "git rev-parse --verify --quiet refs/remotes/origin/main" Opened = `{"result":{"workspace":{"workspace_id":"ws:3"},"root_pane":{"pane_id":"pane:7"},"already_open":false}}` Reopened = `{"result":{"workspace":{"workspace_id":"ws:3"},"root_pane":{"pane_id":"pane:7"},"already_open":true}}` AgentFound = `{"result":{"agent":{"name":"claude-by-hand"}}}` )
const ( GhView = "" /* 166-byte string literal not displayed */ GhRepo = "gh repo view --json squashMergeAllowed,mergeCommitAllowed,rebaseMergeAllowed" GhMerge = "gh pr merge GH-1 --squash" GhDel = "gh api -X DELETE repos/{owner}/{repo}/git/refs/heads/GH-1" GhStack = "gh pr list --base GH-1 --state open --limit 1000 --json number,url,headRefName" LsRem = "git ls-remote --heads origin GH-1" // DropRemoteRef is finish dropping the local copy of origin's branch along with the branch DropRemoteRef = "git update-ref -d refs/remotes/origin/GH-1" CurBr = "git branch --show-current" WsList = "herdr workspace list" // GhChecks is the head checks read, every PR number GhChecks = "gh api graphql --paginate -f query=" + forge.HeadChecksQuery + " -F owner={owner} -F name={repo} -F number=" NoChecks = `{"data":{"repository":{"pullRequest":{"prev":{"nodes":[]},"head":{"nodes":[]}}}}}` PrOpen = `{"state":"OPEN","url":"https://gh/pr/9","number":9,"baseRefName":"main","mergeCommit":null}` PrMerged = `{"state":"MERGED","url":"https://gh/pr/9","number":9,"baseRefName":"main","mergeCommit":{"oid":"m3rge"}}` AllowAll = `{"squashMergeAllowed":true,"mergeCommitAllowed":true,"rebaseMergeAllowed":true}` )
const ( Before = "2026-10-10T10:00:00Z" During = "2026-10-14T10:00:00Z" Later = "2026-10-14T12:00:00Z" )
Dates the git fixtures commit at: before a period, during it, and after.
const ( LsHeads = "git ls-remote --heads origin" OriginURL = "git config --get remote.origin.url" RemoteURL = "git remote get-url origin" GhLogin = "gh api user" )
const ( BoxRule = "────────────────────────────────────────" SentText = "/f10:ship GH-1 resume at pr (entry 4) --driven" )
const ( CommentsPath = "gh api --paginate repos/{owner}/{repo}/issues/5/comments?per_page=100" ReactionsPath = "gh api repos/{owner}/{repo}/issues/comments/%s/reactions?per_page=100" ViewerJSON = `{"login":"eugene"}` )
const HandoffBody = "## Config\n- set `LOCALE_DEFAULT` before the deploy"
const LinkProject = "github.com/o/r"
Variables ¶
var Broken = shell.Result{Code: 128, Stderr: "fatal: unable to read config"}
Broken is git failing to read rather than finding nothing: a lock, a broken worktree path, a killed process.
var Bundle12 = ref.Ref{ID: "GH-1", Number: "1", Origin: ref.OriginExplicit, Bundle: []string{"GH-1", "GH-2"}}
var Gh1 = ref.Ref{ID: "GH-1", Number: "1", Origin: ref.OriginExplicit}
var LinkSpan = regexp.MustCompile("\x1b\\]8;;([^\x1b]*)\x1b\\\\([^\x1b]*)\x1b\\]8;;\x1b\\\\")
var Missing = shell.Result{Code: 1}
Missing is what rev-parse --verify --quiet answers for a ref that is not there.
var PickGH = &hostops.Pickup{
Number: "30",
URL: "https://github.com/o/r/pull/30",
Branch: "alice/fix-login",
View: "f10 pr view --comments 30",
Diff: "f10 pr diff 30",
}
var PickMerged = &hostops.Pickup{ Number: "30", URL: PickGH.URL, Branch: PickGH.Branch, View: PickGH.View, Diff: PickGH.Diff, SHA: "abc1234abc", State: "merged by alice on 2026-10-12", }
var StandupSince = time.Date(2026, 10, 14, 0, 0, 0, 0, time.UTC)
var Storage storage.Root
Storage is the storage root of a fixture that names none. The fakes drop the agent grants it adds, so a test that does not care about storage scripts the agent start without them.
var UpdateGolden = flag.Bool("update", false, "rewrite the golden files")
Functions ¶
func AgentOf ¶
AgentOf is the name start gives the agent of a task with no suffix, checked out at the sibling path these tests use.
func Canonical ¶
Canonical matches the layout package, which reports physical paths - a temp dir on macOS is reached through a symlink.
func CommitFile ¶
func DeclaredTracker ¶
DeclaredTracker is a child target whose project.md declares kind.
func FakeDriver ¶
func FakeDriver(t *testing.T) *trackerdriver.Driver
FakeDriver is an executable at <root>/driver so driver.Find accepts it; what it answers comes from the fakes, never from running it.
func GhReviewer ¶
GhReviewer is a gh reviewer over f, with the review the facts declare.
func GitExitCode ¶
GitExitCode is the code git exited with, 1 for a failure that never ran it, so a replayed absence reads as one.
func IndexOf ¶
func IndexOf(t *testing.T) *stack.BranchIndex
IndexOf loads a branch index from the records the test holds now.
func IsolateEnv ¶
IsolateEnv keeps the probes off the developer's own machine: both the gh/glab config lookup and the out-of-tree storage root hang off HOME.
func Main ¶
Main runs the tests in testenv's environment, with the drive watcher a no-op so a start or a drive run hands nothing to a real daemon.
func MkRepo ¶
MkRepo is a checkout named demo: the name derives the task id prefix init writes, and a temp dir's own basename derives none.
func PacedFlowIn ¶
func PacedFlowIn(eff *facts.Effective, set *facts.PaceSet, pace, name string) (runplan.ShipFlow, error)
PacedFlowIn resolves on a literal Effective, which Build would have given a pace set; nil is the built-ins.
func PrRepo ¶
PrRepo is a clone of a bare origin, so origin/HEAD and pushed branches exist; origin is a path, so no host CLI applies and every read is git's.
func ScreenWith ¶
func ScriptNoBranch ¶
func SessionTask ¶
SessionTask records id as this session's task, as a plan run's badge does.
func SettledFacts ¶
func StaleOf ¶
func StaleOf(value string) facts.StaleAfter
StaleOf is a stale_after value as the frontmatter writes it; "" is off.
func StatEvents ¶
StatEvents is two tasks shipped a day apart: FT-1 with a 10-minute wait inside a 30-minute implement, a review entry, a pr and a size; FT-2 with no size.
func StickyFacts ¶
func TitledHost ¶
TitledHost is a gh host whose project declares tracker.title.
func TracedRepo ¶
TracedRepo is a checkout on the given branch, its project.md declaring DM task ids and the traces switch as asked ("" leaves it undeclared).
func WithLinks ¶
WithLinks seeds the ledger with FT-1..FT-3 and makes every writer a terminal when on; ProjectOf answers linkProject for any directory.
func WithTerminal ¶
func WriteDriver ¶
WriteDriver puts an executable driver in a storage root.
func WriteHandoffFile ¶
func WriteUserFile ¶
Types ¶
type Fakes ¶
type Fakes struct {
T *testing.T
Calls []string
Answers map[string][]shell.Result
Has map[string]bool
// Absent answers a call with a key under one of these prefixes, and no
// script of its own, the way git answers a ref or config it lacks
Absent []string
// Defaults answers a call under one of these prefixes, and no script of
// its own, with that stdout
Defaults map[string]string
// Launches are the agent starts argvLaunch answered for a test
Launches []string
// Meta holds the branch records; its writes join calls in order
Meta *branchmetatest.Memory
// contains filtered or unexported fields
}
Fakes stands in for git, wt, herdr and the driver: every call recorded, every answer scripted, nothing executed. A key scripted with several answers hands them out in order, repeating the last, so a listing changes.
type FixtureCall ¶
type GitRepo ¶
GitRepo is gitxtest's repo with the helpers this module's tests add to it.
func NewCatchupRepo ¶
NewCatchupRepo is a clone with main pushed and FT-1/a branched from it; origin's main then moves on, so FT-1/a has something to bring in.
func NewStackedRepo ¶
NewStackedRepo is FT-1/a built on FT-2/b, which has a commit of its own, with the base tip start records.
func (GitRepo) Resolve ¶
func (r GitRepo) Resolve(in stack.CatchupInput) stack.CatchupPlan
type MemAgents ¶
type MemAgents struct {
Spaces []agentctl.Workspace
Started []string // agent names
Args map[string][]string
Prompts map[string][]string
Screens []string // what Screen answers, in turn, the last one repeated
Enters []string // agents SendEnter pressed Enter in
}
MemAgents is an agent backend held in memory: what a backend other than Herdr sees of start and forward.
func (*MemAgents) StartAgent ¶
Source Files
¶
- agents.go
- asks.go
- bundle.go
- catchupbase.go
- children.go
- doc.go
- exitcode.go
- fakes.go
- filelink.go
- finish.go
- gates.go
- gitread.go
- gitrepo.go
- golden.go
- handoff.go
- init.go
- janitor.go
- launch.go
- main.go
- paces.go
- pickup.go
- pr.go
- review.go
- scope.go
- standup.go
- standup_fixture.go
- stats.go
- tasklink.go
- taskstale.go
- tasktitle.go
- trace.go
- tracker.go
- userconfig.go
- writefile.go