testutil

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 13 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 testutil provides shared test utilities for agent packages.

Package testutil holds shared test helpers for the agent package and its sub-packages. Not for production use.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertCommittedDogfoodConfigStable added in v0.10.1

func AssertCommittedDogfoodConfigStable(t *testing.T, repoRelPath string, install func(t *testing.T, dir string) (int, error))

AssertCommittedDogfoodConfigStable is the equivalent of AssertCommittedDogfoodFile for agents whose committed config is JSON that InstallHooks edits in place rather than a whole generated file.

It copies the committed config into an isolated temp repo, runs a non-force install there, and asserts the install reported nothing to do AND changed no bytes. That is the strongest statement available without re-deriving each agent's config format: if the committed file already is what InstallHooks writes, an install is a no-op.

install receives the temp directory that the copied config sits under and must perform a non-force InstallHooks rooted there, returning the hook count.

Fix a failure by re-running the install against the repo and committing the result — do not hand-edit the committed config.

func AssertCommittedDogfoodFile added in v0.10.1

func AssertCommittedDogfoodFile(t *testing.T, repoRelPath, rendered string)

AssertCommittedDogfoodFile checks that a generated agent config this repo commits for its own use (e.g. .pi/extensions/entire/index.ts) still matches what InstallHooks would write today, given repoRelPath and the rendered content.

These files are generated but tracked, so they only get refreshed when someone re-runs an install — and nothing failed when they didn't. They drifted that way once already: the committed copies kept a stale render long after the template moved on, and separately pointed at a launcher script inside the working tree that was later deleted, leaving hooks invoking a path that no longer existed. Runtime drift detection (CheckHookConfig, surfaced by `entire status` and `entire doctor`) only helps someone who runs those commands; this fails in CI instead.

Fix a failure by re-rendering the committed file from the template — do not edit it by hand, and do not relax this check.

func AssertLegacyHookReplaced added in v0.10.1

func AssertLegacyHookReplaced(t *testing.T, configPath, currentCmd, legacyCmd string, install func())

AssertLegacyHookReplaced pins the migration contract for agents whose config is JSON: a hook command written by an older version must be REPLACED by a plain install, not joined by the current one.

It installs, rewrites the installed command into legacyCmd to simulate a config an older version wrote, installs again with force=false, and asserts the legacy command is gone and the current one appears exactly once. Two hooks would both fire, and for the removed local-dev mode the legacy one ran a script inside the working tree — so "replaced" and "added alongside" are very different outcomes.

install must perform a non-force InstallHooks for the agent under test.

func AssertStaleHookDroppedAlongsideCurrent added in v0.10.1

func AssertStaleHookDroppedAlongsideCurrent(t *testing.T, configPath, currentCmd, legacyCmd string, seedBoth, install func())

AssertStaleHookDroppedAlongsideCurrent covers the state a machine lands in when a legacy hook and the current hook are both present: nothing needs *adding*, so an install that only writes when it added something would silently leave the legacy hook on disk.

seedBoth must write a config containing both currentCmd and legacyCmd; it needs per-agent format knowledge, which is why it is a callback rather than a string substitution.

func FakeStreamCmd added in v0.9.0

func FakeStreamCmd(stdout, stderr string, exitCode int) func(ctx context.Context, name string, args ...string) *exec.Cmd

FakeStreamCmd returns a CommandRunner factory whose *exec.Cmd, when Start()'d and Wait()'d, produces stdout/stderr/exit-code as configured. It relaunches the current Go test binary and is portable across supported platforms; package init handles the marked child before testing.Main runs.

func FakeStreamCmdHang added in v0.9.0

func FakeStreamCmdHang(stdout, stderr string) func(ctx context.Context, name string, args ...string) *exec.Cmd

FakeStreamCmdHang is FakeStreamCmd whose child writes the fixtures and then blocks until killed — it never exits on its own. Wire it to the real test ctx (do not detach) to deterministically exercise context-kill behavior: cancel the ctx and the child dies by signal with the fixtures already written to the pipe.

func GetKeys

func GetKeys(m map[string]json.RawMessage) []string

GetKeys returns the keys of a map as a slice.

func LegacyClaudeProjectDirCommand added in v0.10.1

func LegacyClaudeProjectDirCommand(suffix string) string

LegacyClaudeProjectDirCommand builds the local-dev hook command for Claude Code, which had ${CLAUDE_PROJECT_DIR} and so did not need git.

func LegacyLocalDevCommand added in v0.10.1

func LegacyLocalDevCommand(suffix string) string

LegacyLocalDevCommand builds the local-dev hook command for agents that resolved the repo root by shelling out to git.

func ReadRawHooks

func ReadRawHooks(t *testing.T, tempDir, settingsDir string) map[string]json.RawMessage

ReadRawHooks reads the raw hooks map from a settings file. settingsDir is the directory name (e.g., ".claude" or ".cursor").

Types

This section is empty.

Jump to

Keyboard shortcuts

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