testkit

package
v0.64.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 45 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 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

View Source
const (
	FwdMain = "/code/repo"
	FwdWT   = "/code/repo.GH-1"
	FwdText = "/f10:ship GH-1"
)
View Source
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"}}}`
)
View Source
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}`
)
View Source
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.

View Source
const (
	LsHeads   = "git ls-remote --heads origin"
	OriginURL = "git config --get remote.origin.url"
	RemoteURL = "git remote get-url origin"
	GhLogin   = "gh api user"
)
View Source
const (
	BoxRule  = "────────────────────────────────────────"
	SentText = "/f10:ship GH-1 resume at pr (entry 4) --driven"
)
View Source
const (
	SeedProjects    = 50
	SeedPerProject  = 10_000
	SeedSessionRows = 200
	SeedTaskSession = 3
)

The synthetic ledger SeedLedger writes: 50 projects of 10,000 events, sessions of 200 rows, each task worked over three sessions. Project p<n>'s session s<k> is "p<n>-s<k>" and carries task "FT-<k/3>".

View Source
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"}`
)
View Source
const HandoffBody = "## Config\n- set `LOCALE_DEFAULT` before the deploy"
View Source
const LinkProject = "github.com/o/r"

Variables

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

View Source
var Bundle12 = ref.Ref{ID: "GH-1", Number: "1", Origin: ref.OriginExplicit, Bundle: []string{"GH-1", "GH-2"}}
View Source
var Gh1 = ref.Ref{ID: "GH-1", Number: "1", Origin: ref.OriginExplicit}
View Source
var LinkSpan = regexp.MustCompile("\x1b\\]8;;([^\x1b]*)\x1b\\\\([^\x1b]*)\x1b\\]8;;\x1b\\\\")
View Source
var Missing = shell.Result{Code: 1}

Missing is what rev-parse --verify --quiet answers for a ref that is not there.

View Source
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",
}
View Source
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",
}
View Source
var StandupSince = time.Date(2026, 10, 14, 0, 0, 0, 0, time.UTC)
View Source
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.

View Source
var UpdateGolden = flag.Bool("update", false, "rewrite the golden files")

Functions

func AgentOf

func AgentOf(id string) string

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

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

Canonical matches the layout package, which reports physical paths - a temp dir on macOS is reached through a symlink.

func ChildTarget

func ChildTarget(t *testing.T, cli string) *target.Target

func CommitFile

func CommitFile(t *testing.T, dir, name string)

func DeclaredTracker

func DeclaredTracker(t *testing.T, kind facts.TrackerKind) *target.Target

DeclaredTracker is a child target whose project.md declares kind.

func ExitCode

func ExitCode(err error) int

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 GhHeadOf

func GhHeadOf(branch string) string

func GhReviewer

func GhReviewer(t *testing.T, f *Fakes, rf facts.Review) *reviews.Reviewer

GhReviewer is a gh reviewer over f, with the review the facts declare.

func GhStackOf

func GhStackOf(branch string) string

func Git

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

func GitExitCode

func GitExitCode(err error) int

GitExitCode is the code git exited with, 1 for a failure that never ran it, so a replayed absence reads as one.

func Heads

func Heads(names ...string) string

Heads prefixes branch names the way for-each-ref prints them.

func IndexAfter

func IndexAfter(calls []string, want string, after int) int

func IndexOf

func IndexOf(t *testing.T) *stack.BranchIndex

IndexOf loads a branch index from the records the test holds now.

func IsolateEnv

func IsolateEnv(t *testing.T) string

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 IssueURL

func IssueURL(id string) string

func Main

func Main(m *testing.M)

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

func MkRepo(t *testing.T) string

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 Porcelain

func Porcelain(pairs ...string) string

Porcelain is a worktree listing of main plus the given branch/path pairs.

func PrRepo

func PrRepo(t *testing.T) string

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 Raised

func Raised(t *testing.T, dir string, a asks.Ask) asks.Ask

func RefsKey

func RefsKey(root, id string) string

RefsKey is the for-each-ref call that looks for task id's branches under root.

func ScopeRepo

func ScopeRepo(t *testing.T, parent, name string) string

func ScreenWith

func ScreenWith(box string) string

func ScriptNoBranch

func ScriptNoBranch(f *Fakes, ids ...string)

func SeedLedger added in v0.61.0

func SeedLedger(tb testing.TB, path string)

SeedLedger migrates a ledger at path and fills it with the synthetic rows in one transaction: Append's row at a time would take minutes.

func SessionTask

func SessionTask(t *testing.T, id string)

SessionTask records id as this session's task, as a plan run's badge does.

func SettledFacts

func SettledFacts() facts.Review

func StaleOf

func StaleOf(value string) facts.StaleAfter

StaleOf is a stale_after value as the frontmatter writes it; "" is off.

func StatEvent

func StatEvent(at time.Time, session, task, kind string, payload any) ledger.Event

StatEvent is a row of kind with payload, the kind's current payload struct.

func StatEvents

func StatEvents(day time.Time) []ledger.Event

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 StickyFacts() facts.Review

func Titled

func Titled(title string, err error) func(context.Context) (string, error)

Titled is a title lookup that answers with one title, or fails.

func TitledHost

func TitledHost() hostops.Host

TitledHost is a gh host whose project declares tracker.title.

func TracedRepo

func TracedRepo(t *testing.T, branch, traces string) string

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(t *testing.T, on bool)

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 WithTerminal(t *testing.T, on bool)

func WriteDriver

func WriteDriver(t *testing.T, storageRoot string) string

WriteDriver puts an executable driver in a storage root.

func WriteFile

func WriteFile(t *testing.T, path, text string)

func WriteHandoffFile

func WriteHandoffFile(t *testing.T, path, head string)

func WriteLore

func WriteLore(t *testing.T, root string, entries ...lore.Entry)

WriteLore writes entries as `f10 lore add` would leave them.

func WritePlan

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

WritePlan saves a plan file at path, making its dir.

func WriteUserFile

func WriteUserFile(t *testing.T, home, name, body string)

func WriteVerdict

func WriteVerdict(t *testing.T, root, task, n, subject, verdict string, at time.Time) string

WriteVerdict puts a verdict file under root, its mtime age before now.

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.

func NewFakes

func NewFakes(t *testing.T) *Fakes

func (*Fakes) Answer

func (f *Fakes) Answer(key string) shell.Result

func (*Fakes) Called

func (f *Fakes) Called(prefix string) bool

func (*Fakes) Fail

func (f *Fakes) Fail(key string, res shell.Result)

func (*Fakes) Script

func (f *Fakes) Script(key string, stdouts ...string)

Script sets the answers for key: one per call, the last repeating.

type FixtureCall

type FixtureCall struct {
	Stdout string `json:"stdout"`
	Stderr string `json:"stderr,omitempty"`
	Code   int    `json:"code,omitempty"`
}

type GitRepo

type GitRepo struct{ gitxtest.Repo }

GitRepo is gitxtest's repo with the helpers this module's tests add to it.

func InitRepo

func InitRepo(t *testing.T, dir, branch string) GitRepo

InitRepo makes dir a repo on branch, with the default fixture identity.

func NewCatchupRepo

func NewCatchupRepo(t *testing.T) GitRepo

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

func NewStackedRepo(t *testing.T) (GitRepo, string)

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) Input

func (r GitRepo) Input(guard string) stack.CatchupInput

func (GitRepo) Resolve

func (r GitRepo) Resolve(in stack.CatchupInput) stack.CatchupPlan

func (GitRepo) Sha

func (r GitRepo) Sha(ref string) string

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
	Homes   map[string]string // each started agent's workspace id
}

MemAgents is an agent backend held in memory: what a backend other than Herdr sees of start and forward.

func UseAgents

func UseAgents(t *testing.T) *MemAgents

func UseListingAgents added in v0.64.0

func UseListingAgents(t *testing.T) *MemAgents

UseListingAgents is UseAgents with a backend that lists its agents.

func (*MemAgents) Available

func (m *MemAgents) Available() error

func (*MemAgents) Close

func (m *MemAgents) Close(context.Context, string) error

func (*MemAgents) Focus

func (m *MemAgents) Focus(context.Context, string) error

func (*MemAgents) Name

func (m *MemAgents) Name() string

func (*MemAgents) Occupancy

func (*MemAgents) Open

func (m *MemAgents) Open(_ context.Context, path, label string) (agentctl.Opened, []string, error)

func (*MemAgents) Prompt

func (m *MemAgents) Prompt(_ context.Context, name, text string) error

func (*MemAgents) RenameAgent added in v0.64.0

func (m *MemAgents) RenameAgent(_ context.Context, name, to string) error

RenameAgent renames a started agent, keeping its prompts under the new name.

func (*MemAgents) RenameWorkspace added in v0.64.0

func (m *MemAgents) RenameWorkspace(_ context.Context, id, label string) error

func (*MemAgents) Screen

func (m *MemAgents) Screen(context.Context, string) (string, error)

func (*MemAgents) SendEnter

func (m *MemAgents) SendEnter(_ context.Context, name string) error

func (*MemAgents) StartAgent

func (m *MemAgents) StartAgent(
	_ context.Context,
	ws agentctl.Opened,
	name, _ string,
	args []string,
	_ func(waited, limit time.Duration),
) error

func (*MemAgents) Workspaces

func (m *MemAgents) Workspaces(context.Context) ([]agentctl.Workspace, error)

type MemListing added in v0.64.0

type MemListing struct{ *MemAgents }

MemListing is MemAgents with a listing of its agents, which a backend may lack: a discussion's hand-over finds the agent to rename through it.

func (MemListing) Agents added in v0.64.0

Jump to

Keyboard shortcuts

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