benchutil

package
v0.5.1 Latest Latest
Warning

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

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

Documentation

Overview

Package benchutil provides test fixture helpers for CLI benchmarks.

It creates realistic git repositories, transcripts, session states, and checkpoint data for benchmarking the hot paths (SaveStep, PostCommit/Condense).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateFileContent

func GenerateFileContent(seed, sizeBytes int) string

GenerateFileContent creates generic file content of approximately the given byte size.

func GenerateGoFile

func GenerateGoFile(seed, lines int) string

GenerateGoFile creates a synthetic Go source file with the given number of lines. The seed value ensures unique content for each file.

func GenerateTranscript

func GenerateTranscript(opts TranscriptOpts) []byte

GenerateTranscript creates realistic Claude Code JSONL transcript data. Returns the raw bytes suitable for writing to full.jsonl.

Types

type BenchRepo

type BenchRepo struct {
	// Dir is the absolute path to the repository root.
	Dir string

	// Repo is the go-git repository handle.
	Repo *git.Repository

	// Store is the checkpoint GitStore for this repo.
	Store *checkpoint.GitStore

	// HeadHash is the current HEAD commit hash string.
	HeadHash string

	// WorktreeID is the worktree identifier (empty for main worktree).
	WorktreeID string

	// Strategy is the strategy name used in .entire/settings.json.
	Strategy string
}

BenchRepo is a fully initialized git repository with Entire configured, ready for checkpoint benchmarks.

func NewBenchRepo

func NewBenchRepo(b *testing.B, opts RepoOpts) *BenchRepo

NewBenchRepo creates an isolated git repository for benchmarks. The repo has an initial commit with the configured number of files, a .gitignore excluding .entire/, and Entire settings initialized.

Uses b.TempDir() so cleanup is automatic.

func (*BenchRepo) AddAndCommit

func (br *BenchRepo) AddAndCommit(b *testing.B, message string, files ...string) string

AddAndCommit stages the given files and creates a commit. Returns the new HEAD hash.

func (*BenchRepo) CreateSessionState

func (br *BenchRepo) CreateSessionState(b *testing.B, opts SessionOpts) string

CreateSessionState writes a session state file to .git/entire-sessions/. Returns the session ID used.

func (*BenchRepo) PackRefs

func (br *BenchRepo) PackRefs(b *testing.B)

PackRefs runs `git pack-refs --all` to simulate a real repo where most refs are in the packed-refs file. Large repos almost always have packed refs.

func (*BenchRepo) SeedBranches

func (br *BenchRepo) SeedBranches(b *testing.B, prefix string, count int)

SeedBranches creates N branches pointing at the current HEAD. The branches are named with the given prefix (e.g., "feature/bench-" → "feature/bench-000"). This simulates a repo with many refs, which affects go-git ref scanning performance.

func (*BenchRepo) SeedGitObjects

func (br *BenchRepo) SeedGitObjects(b *testing.B, count int)

SeedGitObjects creates loose git objects to bloat .git/objects/. Each call creates N blob objects via `git hash-object -w`. After seeding, runs `git gc` to pack them into a packfile (realistic).

func (*BenchRepo) SeedMetadataBranch

func (br *BenchRepo) SeedMetadataBranch(b *testing.B, checkpointCount int)

SeedMetadataBranch creates N committed checkpoints on the entire/checkpoints/v1 branch. This simulates a repository with prior checkpoint history.

func (*BenchRepo) SeedShadowBranch

func (br *BenchRepo) SeedShadowBranch(b *testing.B, sessionID string, checkpointCount int, filesPerCheckpoint int)

SeedShadowBranch creates N checkpoint commits on the shadow branch for the current HEAD. This simulates a session that already has prior checkpoints saved.

Temporarily changes cwd to br.Dir because WriteTemporary uses paths.WorktreeRoot() which depends on os.Getwd().

func (*BenchRepo) WriteFile

func (br *BenchRepo) WriteFile(b *testing.B, relPath, content string)

WriteFile creates or overwrites a file relative to the repo root.

func (*BenchRepo) WriteTranscriptFile

func (br *BenchRepo) WriteTranscriptFile(b *testing.B, sessionID string, data []byte) string

WriteTranscriptFile writes transcript data to a file and returns the path.

type RepoOpts

type RepoOpts struct {
	// FileCount is the number of tracked files to create in the initial commit.
	// Each file is ~100 lines of Go code. Defaults to 10.
	FileCount int

	// FileSizeLines is the number of lines per file. Defaults to 100.
	FileSizeLines int

	// CommitCount is the number of commits to create. Defaults to 1.
	CommitCount int

	// Strategy is the strategy name for .entire/settings.json.
	// Defaults to "manual-commit".
	Strategy string

	// FeatureBranch, if non-empty, creates and checks out this branch
	// after the initial commits.
	FeatureBranch string
}

RepoOpts configures how NewBenchRepo creates the test repository.

type SessionOpts

type SessionOpts struct {
	// SessionID is the session identifier. Auto-generated if empty.
	SessionID string

	// Phase is the session phase. Defaults to session.PhaseActive.
	Phase session.Phase

	// StepCount is the number of prior checkpoints. Defaults to 0.
	StepCount int

	// FilesTouched is the list of files tracked by this session.
	FilesTouched []string

	// TranscriptPath is the path to the live transcript file.
	TranscriptPath string

	// AgentType is the agent type. Defaults to agent.AgentTypeClaudeCode.
	AgentType types.AgentType
}

SessionOpts configures how CreateSessionState creates a session state file.

type TranscriptOpts

type TranscriptOpts struct {
	// MessageCount is the number of JSONL messages to generate.
	MessageCount int

	// AvgMessageBytes is the approximate size of each message's content field.
	// Defaults to 500.
	AvgMessageBytes int

	// IncludeToolUse adds realistic tool_use messages (file edits, bash commands).
	IncludeToolUse bool

	// FilesTouched is the list of files to reference in tool_use messages.
	// Only used when IncludeToolUse is true.
	FilesTouched []string
}

TranscriptOpts configures how GenerateTranscript creates JSONL data.

Jump to

Keyboard shortcuts

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