clitest

package
v1.6.4 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 12 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 clitest runs the sitrep program in a throwaway HOME, through scenarios of commands, and compares what it printed and left behind with golden files. The scenarios were first run against the last bash version of the program (the git tag bash-final), and their golden files hold what the two agreed on, except where the Go program was changed on purpose since.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Golden

func Golden(t *testing.T, name string, scenario Scenario, goRunner Runner, norm ...func(Result) Result)

Golden runs the scenario with the Go program only and compares what it saw (each result, then the state files) with testdata/<name>.golden, or rewrites that file with -update-golden. Review the diff of a rewritten file as carefully as a change of code.

func GoldenT

func GoldenT(t *testing.T, scenario Scenario, goRunner Runner, norm ...func(Result) Result)

GoldenT is Golden with the file named after the test: its name with the characters that are not letters, digits or underscores replaced by underscores.

func Home

func Home(t testing.TB) string

Home makes an empty HOME with the folders Claude Code would have made.

func Path

func Path(home, name string) string

Path is where the program keeps the file with this name of the old flat layout (<id>.txt, .<id>.state, inbox.queue) in a home. Scenarios are written with the flat names, and the program keeps a folder for each session.

func Put

func Put(t testing.TB, home, name, body string) string

Put writes a file named as in the old flat layout where the program looks for it, making its folder, and returns the path.

func State

func State(t testing.TB, home string) map[string]File

State reads every regular file of the state, by the name it has in the old flat layout, with its mode and its content, in which the HOME is written as $HOME. The Go layout (sessions/<id>/<file>) is read as the flat names, so both are compared as one. A leftover temporary file (.sitrep.*) is kept under its own name, so a run that leaks one is a difference; the random part is dropped. Lock files are left out: they are not part of the state. Anything unexpected (a folder in the root, a file in a session folder that is not one of ours) is kept under its path, so that it is a difference too.

Types

type File

type File struct {
	Mode    os.FileMode
	Content string
}

File is one state file as the comparison sees it.

type Result

type Result struct {
	Code   int
	Stdout string
	Stderr string
}

Result is what one run of a command left behind.

func Normalize

func Normalize(r Result, home string) Result

Normalize makes a result comparable: the temporary HOME becomes $HOME.

type Runner

type Runner func(t testing.TB, home string, args ...string) Result

Runner runs `sitrep args...` in a given HOME.

func Binary

func Binary(t testing.TB) Runner

Binary builds the Go command into the test's temporary folder and returns a Runner for it.

func BuildInto

func BuildInto(dir string) (Runner, error)

BuildInto builds the Go command into dir, for a package that builds it once for all its tests (see TestMain).

type Scenario

type Scenario func(t testing.TB, home string, sitrep Runner) []Result

Scenario drives a Runner in a fresh HOME and returns everything it saw: each result, then the state files.

Jump to

Keyboard shortcuts

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