Documentation
¶
Overview ¶
Package testutil provides shared test utilities for both integration and e2e tests. This package has no build tags, making it usable by all test packages.
Index ¶
- Constants
- func AddRemote(t *testing.T, repoDir, name, url string)
- func BranchExists(t *testing.T, repoDir, branchName string) bool
- func CreateBranch(t *testing.T, dir string, name string)
- func GetHeadHash(t *testing.T, repoDir string) string
- func GitAdd(t *testing.T, repoDir string, paths ...string)
- func GitAddForce(t *testing.T, repoDir string, paths ...string)
- func GitCheckoutNewBranch(t *testing.T, repoDir, branchName string)
- func GitCommit(t *testing.T, repoDir, message string)
- func GitGrepGuard(t *testing.T, repoRoot string, args ...string) string
- func GitGrepGuardRepoRoot(t *testing.T) (string, bool)
- func GitIsolatedEnv() []string
- func GitReset(t *testing.T, dir string, ref string)
- func GitUpdateRef(t *testing.T, repoDir, ref, hash string)
- func GuardGitEnv() []string
- func InitRepo(t *testing.T, repoDir string)
- func IsolateGitConfigEnv(t *testing.T)
- func RunGit(t *testing.T, dir string, args ...string) string
- func SkipWithoutSymlinks(t *testing.T)
- func WriteCheckpointPushRemoteSetting(t *testing.T, repoDir, remoteName string)
- func WriteFile(t *testing.T, repoDir, path, content string)
- type PendingCheckpoint
Constants ¶
const EnvGitHermetic = gitenv.EnvHermetic
EnvGitHermetic opts a test process into gitenv's hermetic transport config; see gitenv.EnvHermetic.
Variables ¶
This section is empty.
Functions ¶
func AddRemote ¶ added in v0.10.0
AddRemote adds a git remote named name pointing at url in repoDir.
func BranchExists ¶
BranchExists checks if a branch exists in the repository.
func CreateBranch ¶ added in v0.5.6
CreateBranch creates a local branch at the current HEAD.
func GetHeadHash ¶
GetHeadHash returns the current HEAD commit hash.
func GitAddForce ¶ added in v0.10.2
GitAddForce stages paths past .gitignore. GitAdd goes through go-git's worktree.Add, which has no force option.
func GitCheckoutNewBranch ¶
GitCheckoutNewBranch creates and checks out a new branch. Uses git CLI to work around go-git v5 bug with checkout deleting untracked files.
func GitGrepGuard ¶ added in v0.11.0
GitGrepGuard runs `git grep` for a source-level guard test and returns its output, failing the test when the pattern matched nothing.
It exists because this repo has four guards that scan their own source with `git grep` — the root-base allowlist, the transcript-read ratchet, the `git status` flag check, and the agent hook-config coverage check — and getting the invocation right is not obvious. Each of the three flags below was missing from at least one of them, and the same bug was found in three: two copies is how they drift, and four is how they drifted.
--untracked, because git grep otherwise searches only the INDEX. Every one of these guards has "someone just added a file" as its subject, so the file it most needs to see is the one not yet staged. The hole is worse than a plain miss in two of them: the hook-config guard compares two sets built from the same blind grep, so a new agent missing its locator is invisible on both sides and the comparison passes; and the root-base guard's staleness half reported a just-added entry as STALE, telling the author to delete the entry that legitimises their new root. Ignored files stay excluded, which is right.
--no-color, because `color.ui` or `color.grep` set to `always` colorizes even into a pipe, and the escapes land in the FILENAME field. Confirmed for both output shapes: `-n` gives `\e[35mpath\e[m\e[36m:\e[m...`, and `-l` — which looks like it should be immune, being nothing but filenames — gives `\e[35mpath\e[m`. Every one of these guards then either misparses (a `.go` suffix check fails and the guard reports itself stale, which was read as a real staleness failure on main, #2248) or, worse, silently compares garbage to garbage while its "did we match anything" assertion still passes.
Repo-selector scrubbing, because git exports GIT_DIR / GIT_WORK_TREE to the hooks it runs and those take precedence over cmd.Dir. A `go test` launched from anywhere that exports them — a `git rebase --exec`, a hook, this CLI's own harnesses — pointed the grep at some other repository. Measured against a decoy repo, an unscrubbed grep returns the decoy's files while cmd.Dir names this one. GIT_CONFIG_* isolation is applied too (gitenv.Isolated), so a developer's global grep settings cannot change the pattern semantics either.
args are the caller's own flags, pattern and pathspecs, appended after the three above.
func GitGrepGuardRepoRoot ¶ added in v0.11.0
GitGrepGuardRepoRoot resolves the repository root for a guard test, skipping when there is no checkout to scan.
func GitIsolatedEnv ¶ added in v0.5.0
func GitIsolatedEnv() []string
GitIsolatedEnv returns os.Environ() with git isolation variables set; see gitenv.Isolated. The implementation lives in the dependency-free gitenv subpackage so internal tests of packages testutil imports (e.g. gitrepo) can use it without an import cycle; everything else keeps this spelling.
func GitUpdateRef ¶ added in v0.10.0
GitUpdateRef points ref at hash in repoDir via git update-ref.
func GuardGitEnv ¶ added in v0.11.0
func GuardGitEnv() []string
GuardGitEnv drops the repo selectors and the caller's git config, keeping both isolations in one place so the two subprocesses above cannot disagree about which repository they are looking at.
func IsolateGitConfigEnv ¶ added in v0.7.0
IsolateGitConfigEnv applies git config isolation to the current process; see gitenv.IsolateProcess.
func RunGit ¶ added in v0.10.2
RunGit runs one git command in dir with an isolated git config, failing the test on error and returning combined output. Use it for operations go-git cannot express (force-add past .gitignore, rm --cached, worktree add) or where shelling out is simply clearer. See gitenv.Run.
func SkipWithoutSymlinks ¶ added in v0.10.6
SkipWithoutSymlinks skips a test that needs to create a symlink. On Windows that takes elevation or developer mode, neither of which CI has.
Here rather than per-package because six copies in three different wordings had accumulated across cli, agent, worktreedir and vercelconfig tests, so there was nowhere to make the change when a runner does gain the privilege.
func WriteCheckpointPushRemoteSetting ¶ added in v0.10.0
WriteCheckpointPushRemoteSetting writes .entire/settings.json configuring strategy_options.checkpoint_push_remote to remoteName (with enabled: true).
Types ¶
type PendingCheckpoint ¶ added in v0.10.4
type PendingCheckpoint struct {
ID string `json:"id"`
Message string `json:"message"`
MetadataDir string `json:"metadata_dir"`
Date time.Time `json:"date"`
IsTaskCheckpoint bool `json:"is_task_checkpoint"`
ToolUseID string `json:"tool_use_id"`
IsLogsOnly bool `json:"is_logs_only"`
CondensationID string `json:"condensation_id"`
}
PendingCheckpoint mirrors the `checkpoint list --pending --json` JSON output.