testutil

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: MIT Imports: 11 Imported by: 0

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

This section is empty.

Variables

This section is empty.

Functions

func BranchExists

func BranchExists(t *testing.T, repoDir, branchName string) bool

BranchExists checks if a branch exists in the repository.

func FileExists

func FileExists(repoDir, path string) bool

FileExists checks if a file exists in the repo directory.

func GetCommitMessage

func GetCommitMessage(t *testing.T, repoDir, hash string) string

GetCommitMessage returns the commit message for the given commit hash.

func GetHeadHash

func GetHeadHash(t *testing.T, repoDir string) string

GetHeadHash returns the current HEAD commit hash.

func GetLatestCheckpointIDFromHistory

func GetLatestCheckpointIDFromHistory(t *testing.T, repoDir string) (string, error)

GetLatestCheckpointIDFromHistory walks backwards from HEAD and returns the checkpoint ID from the first commit with an Entire-Checkpoint trailer. Returns an error if no checkpoint trailer is found in any commit.

func GitAdd

func GitAdd(t *testing.T, repoDir string, paths ...string)

GitAdd stages files for commit.

func GitCheckoutNewBranch

func GitCheckoutNewBranch(t *testing.T, repoDir, branchName string)

GitCheckoutNewBranch creates and checks out a new branch. Uses git CLI to work around go-git v5 bug with checkout deleting untracked files.

func GitCommit

func GitCommit(t *testing.T, repoDir, message string)

GitCommit creates a commit with all staged 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

Existing GIT_CONFIG_GLOBAL/GIT_CONFIG_SYSTEM entries are filtered out before appending overrides to ensure they take effect regardless of parent env.

func InitRepo

func InitRepo(t *testing.T, repoDir string)

InitRepo initializes a git repository in the given directory with test user config.

func ReadFile

func ReadFile(t *testing.T, repoDir, path string) string

ReadFile reads a file from the repo directory.

func SafeIDPrefix

func SafeIDPrefix(id string) string

SafeIDPrefix returns first 12 chars of ID or the full ID if shorter. Use this when logging checkpoint IDs to avoid index out of bounds panic.

func TryReadFile

func TryReadFile(t *testing.T, repoDir, path string) string

TryReadFile reads a file from the repo directory, returning empty string if not found.

func WriteFile

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

WriteFile creates a file with the given content in the repo directory. It creates parent directories as needed.

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.

Jump to

Keyboard shortcuts

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