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 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 GitCheckoutNewBranch(t *testing.T, repoDir, branchName string)
- func GitCommit(t *testing.T, repoDir, message string)
- func GitIsolatedEnv() []string
- func GitReset(t *testing.T, dir string, ref string)
- func InitRepo(t *testing.T, repoDir string)
- func IsolateGitConfigEnv(t *testing.T)
- func WriteFile(t *testing.T, repoDir, path, content string)
- type RewindPoint
Constants ¶
const EnvGitHermetic = "ENTIRE_TEST_GIT_HERMETIC"
EnvGitHermetic, when set to a non-empty value, makes gitEmptyConfigPath append per-host HTTP proxy config that routes git HTTPS transport to real external hosts (github.com, gitlab.com) through an unroutable loopback proxy. Any test whose git commands accidentally dial those hosts then fails fast (connection refused at 127.0.0.1:1) instead of reaching the network or prompting for credentials. It is opt-in per test process — the integration TestMain sets it — so unit test packages that don't set it are unaffected. Because GitIsolatedEnv strips all inherited GIT_CONFIG_* env, this config must live in the file GIT_CONFIG_GLOBAL points at (this one), not in GIT_CONFIG_* env entries.
A dead proxy (not url.insteadOf) is used deliberately: insteadOf rewrites the effective URL that git reports on read, which breaks production code that resolves the origin URL to detect the forge (e.g. `entire trail`). The proxy blocks transport only, leaving the configured URL string intact, and is scoped per host so loopback (127.0.0.1) test servers are never proxied.
Regression class: tests accidentally hitting live github.com / the macOS keychain (#1463, 53bc37a88).
Variables ¶
This section is empty.
Functions ¶
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 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 GitIsolatedEnv ¶ added in v0.5.0
func GitIsolatedEnv() []string
GitIsolatedEnv returns os.Environ() with git isolation variables set. This prevents user/system git config (global gitignore, aliases, etc.) from affecting test behavior. Use this for any exec.Command that runs git or the CLI binary in integration tests.
See https://git-scm.com/docs/git#Documentation/git.txt-GITCONFIGGLOBAL
Every inherited GIT_CONFIG_* entry is filtered out — including GIT_CONFIG_PARAMETERS and the indexed KEY_/VALUE_ pairs that can inject `git -c` overrides — so our explicit isolation overrides take effect regardless of parent env.
func IsolateGitConfigEnv ¶ added in v0.7.0
IsolateGitConfigEnv applies the same git config isolation to the current process. Use this in tests that exercise production code paths which invoke git with os.Environ(). All inherited GIT_CONFIG_* variables are cleared before the isolation overrides are set, so values such as GIT_CONFIG_PARAMETERS or indexed KEY_/VALUE_ overrides cannot leak into child git invocations.
Types ¶
type RewindPoint ¶
type RewindPoint 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"`
}
RewindPoint mirrors the rewind --list JSON output.