testkit

package
v0.3.1 Latest Latest
Warning

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

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

Documentation

Overview

Package testkit helps Go projects write Tuile-backed integration and browser smoke tests.

Start an in-process Tuile server, create sessions, assert on headless screen output, and optionally drive the /view browser terminal with chromedp (requires Chrome/Chromium).

Example:

func TestSmoke(t *testing.T) {
    srv := testkit.NewServer(t)
    sess := srv.NewSession(t, t.TempDir())
    sess.Input(t, "printf hello\\n")
    sess.WaitContains(t, "hello")
}

Downstream projects: add github.com/newtosh/tuile to go.mod (use replace for local dev). Run integration tests in CI with headless Chrome; pre-commit is not recommended for browser tests.

Index

Constants

View Source
const DefaultBaseURL = "http://127.0.0.1:7710"

DefaultBaseURL is the standard loopback address for `tuile serve`.

Variables

This section is empty.

Functions

func BrowserContext

func BrowserContext(t *testing.T) (context.Context, context.CancelFunc)

BrowserContext returns a chromedp context with timeout; caller must cancel.

func DefaultListenHostPort added in v0.2.0

func DefaultListenHostPort() string

DefaultListenHostPort returns the host:port portion of DefaultBaseURL.

func FormatViewURL added in v0.2.0

func FormatViewURL(baseURL, sessionID, token string) string

FormatViewURL builds a browser observe link for a session.

func PortOpen added in v0.2.0

func PortOpen(hostport string) bool

PortOpen reports whether something is listening on host:port.

func ViewIndexURL added in v0.2.0

func ViewIndexURL(baseURL string) string

ViewIndexURL returns the Tuile session list / viewer root.

Types

type Server

type Server struct {
	URL  string
	Boot auth.BootstrapSecret
	// contains filtered or unexported fields
}

Server is an in-process Tuile HTTP server for tests.

func ConnectURL added in v0.2.0

func ConnectURL(t *testing.T, baseURL, bootstrap string) *Server

ConnectURL attaches to an already-running Tuile without starting serve.

func EnsureServe added in v0.2.0

func EnsureServe(t *testing.T) *Server

EnsureServe returns a Server connected to baseURL (TUILE_URL or DefaultBaseURL). If nothing is listening, it starts `tuile serve` on that address and registers cleanup. Bootstrap secret: TUILE_BOOTSTRAP_SECRET, then bootstrap_secret from tuile.toml (cwd/parents).

func NewServer

func NewServer(t *testing.T) *Server

NewServer starts Tuile on an ephemeral 127.0.0.1 port and registers cleanup on t.

func (*Server) DeleteSession added in v0.1.2

func (s *Server) DeleteSession(t *testing.T, id string)

DeleteSession closes a session via DELETE /v1/sessions/{id}.

func (*Server) HealthOK

func (s *Server) HealthOK(t *testing.T) bool

HealthOK reports whether GET /health returns 200.

func (*Server) NewSession

func (s *Server) NewSession(t *testing.T, workspace string) *Session

NewSession creates a shell session in workspace (use t.TempDir() for isolation).

type Session

type Session struct {
	ID    string
	Token string
	// contains filtered or unexported fields
}

Session is one Tuile PTY session created via the HTTP API.

func (*Session) AssertTerminalContains

func (sess *Session) AssertTerminalContains(t *testing.T, marker string)

AssertTerminalContains polls the viewer until marker appears or times out.

func (*Session) EmitMarker

func (sess *Session) EmitMarker(t *testing.T, workspace, marker string)

EmitMarker writes marker to a file in workspace and cats it. Unlike echo/printf, the shell echo line does not contain marker text, so WaitContains cannot match prematurely on typed command text.

func (*Session) GetWithToken

func (sess *Session) GetWithToken(t *testing.T, path string) *http.Response

GetWithToken performs GET with the session token (for isolation tests).

func (*Session) HumanResize

func (sess *Session) HumanResize(t *testing.T, cols, rows int)

HumanResize sets PTY size while human controls the session.

func (*Session) Input

func (sess *Session) Input(t *testing.T, input string)

Input writes PTY input (agent token auth).

func (*Session) PlainScreen

func (sess *Session) PlainScreen(t *testing.T, tail int) string

PlainScreen returns the plain-text tail of the session screen.

func (*Session) PostInputRaw

func (sess *Session) PostInputRaw(t *testing.T, body []byte)

PostInputRaw sends a pre-marshaled JSON body to /input (for advanced tests).

func (*Session) Resize

func (sess *Session) Resize(t *testing.T, cols, rows int)

Resize sets agent PTY dimensions.

func (*Session) ScreenGrid

func (sess *Session) ScreenGrid(t *testing.T) (cols, rows int)

ScreenGrid returns cols and rows from the JSON screen endpoint.

func (*Session) ServerURL

func (sess *Session) ServerURL() string

ServerURL returns the test server base URL.

func (*Session) SessionID

func (sess *Session) SessionID() string

SessionID returns the session identifier.

func (*Session) Takeover

func (sess *Session) Takeover(t *testing.T)

Takeover grants human PTY control.

func (*Session) TerminalText

func (sess *Session) TerminalText(t *testing.T) string

TerminalText opens the session view URL, waits for xterm, and returns visible terminal text. Skips the test when Chrome/chromedp is unavailable.

func (*Session) ViewURL

func (sess *Session) ViewURL() string

ViewURL returns the browser viewer URL for this session.

func (*Session) WaitContains

func (sess *Session) WaitContains(t *testing.T, marker string)

WaitContains blocks until the session screen tail contains marker (POST /wait).

func (*Session) WaitContainsTimeout

func (sess *Session) WaitContainsTimeout(t *testing.T, marker string, timeout time.Duration)

WaitContainsTimeout is WaitContains with a custom timeout.

func (*Session) WaitForShell

func (sess *Session) WaitForShell(t *testing.T)

WaitForShell blocks until the session PTY shows an interactive shell prompt.

Jump to

Keyboard shortcuts

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