ttywatchtest

package
v0.0.51 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildTTYWatch

func BuildTTYWatch(t *testing.T) string

BuildTTYWatch builds the tty-watch binary for doctest harnesses.

func ContainsANSIEscape

func ContainsANSIEscape(s string) bool

ContainsANSIEscape reports whether s has CSI/OSC/C0 control sequences.

func ContentLinesAtColumnZero

func ContentLinesAtColumnZero(s string) ([]string, error)

ContentLinesAtColumnZero returns trimmed logical content lines that must start at column 0. Unlike VisibleContentLines, leading whitespace is preserved and rejected.

func DrainPTY

func DrainPTY(ptmx *os.File, timeout time.Duration) string

DrainPTY reads from ptmx until idle or timeout (test helper).

func EndsWithNewline

func EndsWithNewline(s string) bool

EndsWithNewline reports whether s ends with a newline (host prompt must start fresh).

func HasAlternateScreenExitPrefix

func HasAlternateScreenExitPrefix(s string) bool

HasAlternateScreenExitPrefix reports the scrollback replay prefix that smears a cleared terminal with blank lines before short-command output.

func HasBareLFNewlines added in v0.0.45

func HasBareLFNewlines(s string) bool

HasBareLFNewlines reports whether s contains LF not preceded by CR. On interactive TTYs, bare LF advances to the next line without resetting the cursor column.

func HasIndentedExitMarker

func HasIndentedExitMarker(s string) bool

HasIndentedExitMarker reports output where [Terminal exited] is not left-aligned.

func HasLeadingBlankLine

func HasLeadingBlankLine(s string) bool

HasLeadingBlankLine reports whether s begins with a blank line before first content.

func IsolatedHome

func IsolatedHome(t *testing.T) string

IsolatedHome returns a fresh TTY_WATCH_HOME directory for a test.

func ListRegistryIDs

func ListRegistryIDs(home string) ([]string, error)

ListRegistryIDs scans registry dir for all *.json session ids.

func ListTableClientCounts added in v0.0.45

func ListTableClientCounts(output, sessionID string) (watch, attached int, ok bool)

ListTableClientCounts parses WATCH and ATTACHED for sessionID from list table output.

func ListTableColumnsAligned added in v0.0.45

func ListTableColumnsAligned(output string) bool

ListTableColumnsAligned reports whether header and first data row share aligned columns.

func ListTableCommand added in v0.0.45

func ListTableCommand(output, sessionID string) (command string, ok bool)

ListTableCommand parses the COMMAND cell for sessionID from list table output.

func ListTableHeaderPresent added in v0.0.45

func ListTableHeaderPresent(output string) bool

ListTableHeaderPresent reports whether list stdout includes the table header columns in order.

func NoLeadingBlankLine

func NoLeadingBlankLine(s string) error

NoLeadingBlankLine reports an error when s begins with a blank line before the first visible content (e.g. relayTerminalOutput prepending "\n" before screen snapshot text).

func NormalizeTTYOutput added in v0.0.45

func NormalizeTTYOutput(b []byte) []byte

NormalizeTTYOutput mirrors pkgs/ttywatch/attach_client.go normalizeTTYOutput for doctest regression locks on raw TTY CRLF shaping (bare LF → CRLF; standalone CR preserved).

func PostDetachOutputHasKittyGarbage added in v0.0.45

func PostDetachOutputHasKittyGarbage(output string) bool

PostDetachOutputHasKittyGarbage reports visible kitty protocol fragments in post-detach PTY output (iTerm2 typing garbage after incomplete cleanup).

func RegistryDir

func RegistryDir(home string) string

RegistryDir returns the registry path under a TTY_WATCH_HOME.

func RegistryExists

func RegistryExists(home, sessionID string) bool

RegistryExists reports whether a session registry file exists.

func ScreenSnapshotTextFromScrollback

func ScreenSnapshotTextFromScrollback(scrollback []byte, cols, rows int) (string, bool)

ScreenSnapshotTextFromScrollback renders scrollback the way ptywrap screen attach does, then converts the snapshot frame to plain text the way tty-watch attach does.

func SessionReachable

func SessionReachable(home, sessionID string) bool

SessionReachable TCP-probes the registry listen address.

func StartDetachedSession

func StartDetachedSession(t *testing.T, req *Request) string

StartDetachedSession starts tty-watch in a PTY, detaches with Ctrl-], returns session id.

func VisibleContentLines

func VisibleContentLines(s string) []string

VisibleContentLines returns non-empty trimmed logical lines after stripping CSI sequences and normalizing CR to LF (what a user should see as content lines).

func WatchOutputHasTTYCleanup added in v0.0.45

func WatchOutputHasTTYCleanup(output string) bool

WatchOutputHasTTYCleanup reports whether watch restored the observer terminal after grok-like mode sequences (alt-screen, kitty keyboard, mouse tracking).

func WriteStaleRegistry

func WriteStaleRegistry(home, sessionID, listenAddr string) error

WriteStaleRegistry writes a registry entry pointing at an unreachable listen addr.

Types

type RegistryEntry

type RegistryEntry struct {
	SessionID  string   `json:"session_id"`
	ListenAddr string   `json:"listen_addr"`
	PID        int      `json:"pid"`
	CreatedAt  string   `json:"created_at"`
	Command    []string `json:"command"`
	Cwd        string   `json:"cwd,omitempty"`
}

RegistryEntry mirrors the tty-watch registry JSON shape for harness helpers.

func ReadRegistryEntry

func ReadRegistryEntry(home, sessionID string) (*RegistryEntry, error)

ReadRegistryEntry loads a registry JSON entry.

type Request

type Request struct {
	Phase string

	Bin, TTYWatchHome, SessionID, CustomSessionID    string
	RunCommand                                       []string
	Detach, SendCtrlC, Background                    bool
	WatchProbe, SnapshotID, KillID                   string
	SendID, SendMessage                              string
	AttachID, AttachInput, AttachInputB, AttachProbe string
}

Request is the doctest harness request for tty-watch CLI tests.

type Response

type Response struct {
	ExitCode                           int
	Stdout, Stderr, Combined           string
	SessionID                          string
	RegistryExists                     bool
	RegistryIDs                        []string
	ListOutput                         string
	SessionRunning                     bool
	SnapshotText                       string
	ContainsEscape                     bool
	TimedOut                           bool
	Elapsed                            time.Duration
	GrokModesSeen                      bool
	TTYCleanupOnDetach                 bool
	PostDetachOutput                   string
	SourceCheckOK                      bool
	SourceCheckNote                    string
	StdinRestoredBeforeCleanup         bool
	KittyPopCleanupInSrc               bool
	AttachStdoutWriterNormalizesRawTTY bool
	InjectedBytes                      []byte
	AltExitCode                        int
	AltStderr                          string
	AttachOutput                       string
	AttachBOutput                      string
	WatchOutput                        string
	RunOutput                          string
}

Response is the doctest harness response for tty-watch CLI tests.

func PhaseRunDetachMutuallyExclusiveWithHeadless added in v0.0.46

func PhaseRunDetachMutuallyExclusiveWithHeadless(t *testing.T, req *Request) (*Response, error)

PhaseRunDetachMutuallyExclusiveWithHeadless rejects --detach together with --headless.

func PhaseRunDetachNoAttachOutput added in v0.0.46

func PhaseRunDetachNoAttachOutput(t *testing.T, req *Request) (*Response, error)

PhaseRunDetachNoAttachOutput runs detach without writer attach; child output stays off host stdout.

func PhaseRunDetachPrintsSessionID added in v0.0.46

func PhaseRunDetachPrintsSessionID(t *testing.T, req *Request) (*Response, error)

PhaseRunDetachPrintsSessionID runs detach and expects prompt exit 0 with session-id on stdout.

func PhaseRunDetachSessionSurvivesInList added in v0.0.46

func PhaseRunDetachSessionSurvivesInList(t *testing.T, req *Request) (*Response, error)

PhaseRunDetachSessionSurvivesInList runs detach then probes list while serve child remains live.

func PhaseRunDetachStopOnFirstArg added in v0.0.46

func PhaseRunDetachStopOnFirstArg(t *testing.T, req *Request) (*Response, error)

PhaseRunDetachStopOnFirstArg runs detach with a command token that looks like a flag; probes via watch.

func PhaseRunDetachWithCustomSessionID added in v0.0.46

func PhaseRunDetachWithCustomSessionID(t *testing.T, req *Request) (*Response, error)

PhaseRunDetachWithCustomSessionID runs detach with an explicit --session-id.

func PhaseRunHeadlessCtrlCForwardsExits added in v0.0.46

func PhaseRunHeadlessCtrlCForwardsExits(t *testing.T, req *Request) (*Response, error)

PhaseRunHeadlessCtrlCForwardsExits sends SIGINT to the headless parent and waits for exit.

func PhaseRunHeadlessCtrlCWaitingLogs added in v0.0.46

func PhaseRunHeadlessCtrlCWaitingLogs(t *testing.T, req *Request) (*Response, error)

PhaseRunHeadlessCtrlCWaitingLogs sends SIGINT and captures the waiting-for-exit stderr line timing.

func PhaseRunHeadlessNoAttachOutput added in v0.0.46

func PhaseRunHeadlessNoAttachOutput(t *testing.T, req *Request) (*Response, error)

PhaseRunHeadlessNoAttachOutput runs headless without writer attach; child output stays off host stdout.

func PhaseRunHeadlessPrintsSessionID added in v0.0.46

func PhaseRunHeadlessPrintsSessionID(t *testing.T, req *Request) (*Response, error)

PhaseRunHeadlessPrintsSessionID runs headless and returns the session-id line on stdout.

func PhaseRunHeadlessSessionLiveWhileWaiting added in v0.0.46

func PhaseRunHeadlessSessionLiveWhileWaiting(t *testing.T, req *Request) (*Response, error)

PhaseRunHeadlessSessionLiveWhileWaiting probes list while headless parent is still blocked.

func PhaseRunHeadlessStopOnFirstArg added in v0.0.46

func PhaseRunHeadlessStopOnFirstArg(t *testing.T, req *Request) (*Response, error)

PhaseRunHeadlessStopOnFirstArg runs watch with the first program arg as session id (stop subcommand).

func PhaseRunHeadlessWaitsUntilChildExits added in v0.0.46

func PhaseRunHeadlessWaitsUntilChildExits(t *testing.T, req *Request) (*Response, error)

PhaseRunHeadlessWaitsUntilChildExits blocks until the headless child exits naturally.

func PhaseRunHeadlessWithCustomSessionID added in v0.0.46

func PhaseRunHeadlessWithCustomSessionID(t *testing.T, req *Request) (*Response, error)

PhaseRunHeadlessWithCustomSessionID runs headless with an explicit --session-id.

func Run

func Run(t *testing.T, req *Request) (*Response, error)

Run executes a tty-watch doctest phase.

Jump to

Keyboard shortcuts

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