ttywatchtest

package
v0.0.44 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 17 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 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 session-*.json ids.

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 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 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   string
	RunCommand                     []string
	Detach, SendCtrlC, Background  bool
	WatchProbe, SnapshotID, KillID 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
}

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

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