# zidane-ui/terminal/testing

Import: `import { … } from 'zidane-ui/terminal/testing'`. Source: [ui/src/terminal/testing/index.ts](https://github.com/Tahul/zidane/blob/main/ui/src/terminal/testing/index.ts).

## Functions

### `createDemoTerminalHost`

Function.

A fixture host holding the demo session's terminals.

```ts
function createDemoTerminalHost(): FixtureTerminalHost
```

**Returns** `FixtureTerminalHost`

Source: [ui/src/terminal/testing/demo.ts:20](https://github.com/Tahul/zidane/blob/main/ui/src/terminal/testing/demo.ts#L20)

### `createFixtureTerminalHost`

Function.

Creates a [`TerminalHost`](https://zidane.si/docs/reference/ui-terminal-headless.md#TerminalHost) held in memory.

```ts
function createFixtureTerminalHost(
  options?: FixtureTerminalOptions,
): FixtureTerminalHost
```

**Parameters**

- `options?` (`FixtureTerminalOptions`, default `{}`): The terminals per scope, availability, the prompt, and whether they can be changed.

**Returns** `FixtureTerminalHost`

Source: [ui/src/terminal/headless/fixture-host.ts:75](https://github.com/Tahul/zidane/blob/main/ui/src/terminal/headless/fixture-host.ts#L75)

## Constants

### `DEMO_TERMINAL_SCOPE`

Constant.

The demo session's scope.

```ts
const DEMO_TERMINAL_SCOPE: TerminalScope
```

Source: [ui/src/terminal/testing/demo.ts:9](https://github.com/Tahul/zidane/blob/main/ui/src/terminal/testing/demo.ts#L9)

## Interfaces

### `FixtureTerminal`

Interface.

A terminal the fixture starts with: its info (defaults filled in) and the output it already printed.

```ts
interface FixtureTerminal extends Partial<TerminalInfo>
```

**Properties**

- `cols?` (`number`, from `Partial`): Width in character cells.
- `createdAt?` (`number`, from `Partial`): Creation time in epoch ms.
- `cwd?` (`string`, from `Partial`): Working directory the terminal started in.
- `environment?` (`string`, from `Partial`): Environment kind it runs in (`local`, `worktree`, `docker`, `e2b`, …).
- `error?` (`string`, from `Partial`): Failure message, when `status` is `error`.
- `exitCode?` (`number`, from `Partial`): Exit code, once the process has exited.
- `hiddenFromAgent?` (`boolean`, from `Partial`): The agent's terminal tools skip it.
- `history?` (`string`): What it printed so far (ANSI allowed).
- `id` (`string`): Terminal id.
- `label?` (`string`, from `Partial`): Stable name ("Terminal 2", or the agent's command).
- `lastActivityAt?` (`number`, from `Partial`): Time of the last output or input in epoch ms.
- `owner?` (`TerminalOwner`, from `Partial`): Who started the terminal.
- `program?` (`string`, from `Partial`): The program in the foreground, for terminals on this machine.
- `rows?` (`number`, from `Partial`): Height in character cells.
- `scope?` (`TerminalProjectScope`, from `Partial`): Set on project / draft terminals (`sessionId` is `''`).
- `sessionId?` (`string`, from `Partial`): The session it belongs to; `''` for a project / draft terminal (see `scope`).
- `sizeSeq?` (`number`, from `Partial`): Bumped on every size change: signals and attach replies reach a view by
  different routes, so it keeps the newest size, not the last to arrive.
- `status?` (`TerminalStatus`, from `Partial`): Connection and process state.
- `target?` (`TerminalTarget`, from `Partial`): Where the terminal runs.
- `taskId?` (`string`, from `Partial`): The background task it runs (agent terminals).
- `title?` (`string`, from `Partial`): Title the program set (OSC 0/2), if any.

Source: [ui/src/terminal/headless/fixture-host.ts:18](https://github.com/Tahul/zidane/blob/main/ui/src/terminal/headless/fixture-host.ts#L18)

### `FixtureTerminalControl`

Interface.

Changes the fixture from outside.

```ts
interface FixtureTerminalControl
```

**Properties**

- `announce` (`(scope: TerminalScope) => void`): The scope's list goes out again (as after any change).
- `exit` (`(terminalId: string, code: number) => void`): The terminal's process exits with `code`.
- `print` (`(terminalId: string, data: string) => void`): The terminal prints `data`.
- `relink` (`() => void`): The link to the terminals came back: every scope reloads, every view attaches again.
- `terminals` (`() => TerminalInfo[]`): Every terminal now.
- `writes` (`(terminalId: string) => string[]`): The input a terminal received, one entry per write.

Source: [ui/src/terminal/headless/fixture-host.ts:44](https://github.com/Tahul/zidane/blob/main/ui/src/terminal/headless/fixture-host.ts#L44)

### `FixtureTerminalOptions`

Interface.

Options of [`createFixtureTerminalHost`](https://zidane.si/docs/reference/ui-terminal-testing.md#createFixtureTerminalHost).

```ts
interface FixtureTerminalOptions
```

**Properties**

- `available?` (`boolean`): `false`: the host runs no terminals (`state` says unavailable). Default: true.
- `drafts?` (`Readonly<Record<string, readonly FixtureTerminal[]>>`): The terminals per draft id.
- `projects?` (`Readonly<Record<string, readonly FixtureTerminal[]>>`): The terminals per project root (no session, no draft).
- `prompt?` (`string`): The prompt a new shell prints. Default: `$ `.
- `readOnly?` (`boolean`): Leave out `restart`, `setHidden`, `adoptDraft` and `releaseDraft`. Default: false.
- `reason?` (`string`): Why not, when `available` is false.
- `sessions?` (`Readonly<Record<string, readonly FixtureTerminal[]>>`): The terminals per session id.

Source: [ui/src/terminal/headless/fixture-host.ts:26](https://github.com/Tahul/zidane/blob/main/ui/src/terminal/headless/fixture-host.ts#L26)

## Types

### `FixtureTerminalHost`

Type.

An in-memory [`TerminalHost`](https://zidane.si/docs/reference/ui-terminal-headless.md#TerminalHost) and its control.

```ts
type FixtureTerminalHost = TerminalHost & { control: FixtureTerminalControl }
```

Source: [ui/src/terminal/headless/fixture-host.ts:60](https://github.com/Tahul/zidane/blob/main/ui/src/terminal/headless/fixture-host.ts#L60)
