# zidane-ui/machines/testing

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

## Functions

### `createFixtureMachinesHost`

Function.

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

```ts
function createFixtureMachinesHost(
  options?: FixtureMachinesOptions,
): FixtureMachinesHost
```

**Parameters**

- `options?` (`FixtureMachinesOptions`, default `{}`): The hosts, machines, links, updates, tokens and daemon it starts with, and the callbacks it tells.

**Returns** `FixtureMachinesHost`

Source: [ui/src/machines/headless/fixture-host.ts:152](https://github.com/Tahul/zidane/blob/main/ui/src/machines/headless/fixture-host.ts#L152)

## Constants

### `DEMO_CAPABILITIES`

Constant.

What a demo server can do: git and docker found, gh missing, the OS sandbox, Docker and E2B environments.

```ts
const DEMO_CAPABILITIES: HostCapabilities
```

Source: [ui/src/machines/headless/fixtures.ts:85](https://github.com/Tahul/zidane/blob/main/ui/src/machines/headless/fixtures.ts#L85)

### `DEMO_DAEMON`

Constant.

A connected daemon holding a running session and one waiting for an answer.

```ts
const DEMO_DAEMON: DaemonStatus
```

Source: [ui/src/machines/headless/fixtures.ts:104](https://github.com/Tahul/zidane/blob/main/ui/src/machines/headless/fixtures.ts#L104)

### `DEMO_HOSTS`

Constant.

A desktop's hosts: This computer, then three saved servers.

```ts
const DEMO_HOSTS: readonly HostSummary[]
```

Source: [ui/src/machines/headless/fixtures.ts:17](https://github.com/Tahul/zidane/blob/main/ui/src/machines/headless/fixtures.ts#L17)

### `DEMO_MACHINES`

Constant.

The machines Box holds.

```ts
const DEMO_MACHINES: readonly MachineInfo[]
```

Source: [ui/src/machines/headless/fixtures.ts:50](https://github.com/Tahul/zidane/blob/main/ui/src/machines/headless/fixtures.ts#L50)

### `DEMO_NOW`

Constant.

A fixed "now" for the demo data, so screenshots don't drift.

```ts
const DEMO_NOW: number
```

Source: [ui/src/machines/headless/fixtures.ts:14](https://github.com/Tahul/zidane/blob/main/ui/src/machines/headless/fixtures.ts#L14)

### `DEMO_SERVER_PROVIDERS`

Constant.

Box's providers: Anthropic set up, OpenAI signs in with OAuth there.

```ts
const DEMO_SERVER_PROVIDERS: readonly HostProviderAuth[]
```

Source: [ui/src/machines/headless/fixtures.ts:161](https://github.com/Tahul/zidane/blob/main/ui/src/machines/headless/fixtures.ts#L161)

### `DEMO_SYNC`

Constant.

This computer keeping Box in sync: settings, instructions and API keys (Anthropic's opted in), a field edited on Box since, a skipped MCP server.

```ts
const DEMO_SYNC: HostSyncState
```

Source: [ui/src/machines/headless/fixtures.ts:117](https://github.com/Tahul/zidane/blob/main/ui/src/machines/headless/fixtures.ts#L117)

### `DEMO_TOKENS`

Constant.

Box's client tokens.

```ts
const DEMO_TOKENS: readonly ServerToken[]
```

Source: [ui/src/machines/headless/fixtures.ts:72](https://github.com/Tahul/zidane/blob/main/ui/src/machines/headless/fixtures.ts#L72)

### `DEMO_UPDATE_WAITING`

Constant.

Box's self-update, a release waiting for runs to pause.

```ts
const DEMO_UPDATE_WAITING: ServerUpdateStatus
```

Source: [ui/src/machines/headless/fixtures.ts:62](https://github.com/Tahul/zidane/blob/main/ui/src/machines/headless/fixtures.ts#L62)

### `FIXTURE_LOCAL_HOST`

Constant.

This computer, as every host lists it first.

```ts
const FIXTURE_LOCAL_HOST: HostSummary
```

Source: [ui/src/machines/headless/fixture-host.ts:128](https://github.com/Tahul/zidane/blob/main/ui/src/machines/headless/fixture-host.ts#L128)

## Interfaces

### `FixtureMachinesControl`

Interface.

Pushes the fixture can make, as a backend would.

```ts
interface FixtureMachinesControl
```

**Properties**

- `setHealth` (`(health: DaemonHealth) => void`): Sets the daemon's health.
- `setHosts` (`(hosts: readonly HostSummary[]) => void`): Replaces the hosts (a status push).
- `setLinks` (`(links: MachineLinksStatus) => void`): Replaces the links (a links push).
- `setMachineStatus` (`(hostId: string, machineId: string, status: 'online' | 'offline') => void`): A machine came online or went offline: its server's list follows.
- `setPermitted` (`(actions: readonly MachinesAction[] | null) => void`): Sets what the token may do.
- `setPresence` (`(sessions: readonly SessionPresence[]) => void`): Replaces every session's presence (a presence push).

Source: [ui/src/machines/headless/fixture-host.ts:109](https://github.com/Tahul/zidane/blob/main/ui/src/machines/headless/fixture-host.ts#L109)

### `FixtureMachinesOptions`

Interface.

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

```ts
interface FixtureMachinesOptions
```

**Properties**

- `capabilities?` (`false | HostCapabilities`): What every host can do, or `false` for no `capabilities`. Default: false.
- `daemon?` (`false | DaemonStatus`): The local daemon's status, or `false` for no daemon. Default: no daemon.
- `enabled?` (`boolean`): More than This computer shows. Default: true.
- `folders?` (`readonly string[]`): The folders `pickFolder` answers, in turn. Default: `/home/me/project`.
- `health?` (`DaemonHealth`): The daemon's health. Default: `connected`.
- `hosts?` (`readonly HostSummary[]`): The hosts, This computer first. Default: This computer alone.
- `links?` (`MachineLinksStatus`): This computer's links. Default: none.
- `machines?` (`Readonly<Record<string, readonly MachineInfo[]>>`): Each server's machines, by host id.
- `onAdd?` (`(input: { name?: string; token: string; url: string }) => void`): Called when an add reaches the fixture.
- `onCapabilities?` (`(hostId: string, refresh: boolean) => void`): Called when a capability read reaches the fixture.
- `onCreateToken?` (`(hostId: string, name: string, scope: ServerTokenScope) => void`): Called when a token is created.
- `onDaemon?` (`(action: 'restart' | 'reconnect' | 'stopRun' | 'relaunchApp', detail?: unknown) => void`): Called when a daemon action reaches the fixture.
- `onForget?` (`(hostId: string, machineId: string) => void`): Called when a forget reaches the fixture.
- `onInstallTool?` (`(hostId: string, name: string) => { ok: boolean; output: string }`): Called when an install reaches the fixture (with `capabilities`); answers how it went. Default: it worked.
- `onInvite?` (`(hostId: string, options: { name?: string; ttlMs?: number }) => void | { code: string; expiresAt: number }`): Called when a join code is asked for; what it returns is the code. Default: a made-up code, 10 minutes.
- `onLink?` (`(action: 'shareStart' | 'shareStop' | 'useServer', hostId: string, detail?: unknown) => void`): Called when a link action reaches the fixture.
- `onRemove?` (`(id: string) => void`): Called when a removal reaches the fixture.
- `onRename?` (`(id: string, name: string) => void`): Called when a rename reaches the fixture.
- `onRetry?` (`(hostId: string) => void`): Called when a retry reaches the fixture.
- `onRevokeToken?` (`(hostId: string, id: string) => void`): Called when a token is revoked.
- `onSetUrl?` (`(id: string, url: string) => void`): Called when a URL change reaches the fixture.
- `onSignIn?` (`(hostId: string, target: unknown) => void`): Called when a sign-in starts.
- `onSync?` (`(action: 'reset' | 'push' | 'configure' | 'takeOver', hostId: string, detail?: unknown) => void`): Called when a sync action reaches the fixture; what it throws, the action rejects with.
- `onTest?` (`(target: { id: string } | { token: string; url: string }) => void`): Called when a test reaches the fixture.
- `onUpdate?` (`(hostId: string, action: 'check' | 'install' | 'configure', enabled?: boolean) => void`): Called when an update action reaches the fixture.
- `permitted?` (`false | readonly MachinesAction[]`): What the token may do, or `false` for no `permitted` store (everything). Default: false.
- `presence?` (`false | readonly SessionPresence[]`): Every live session's presence, or `false` for no `presence`. Default: false.
- `providers?` (`Readonly<Record<string, readonly HostProviderAuth[]>>`): Each server's providers (`sync.providers`), by host id. Default: none.
- `signIn?` (`boolean`): Offer `signIn` (a sign-in that shows its page and completes after `signInMs`). Default: false.
- `signInMs?` (`number`): How long a fixture sign-in waits on its page before it completes, ms. Default: never (it waits).
- `signInUrl?` (`string`): The page a fixture sign-in opens. Default: an example address.
- `sync?` (`false | Readonly<Record<string, HostSyncState>>`): Each server's sync from this computer, by host id, or `false` for no `sync`. Default: false.
- `tokens?` (`Readonly<Record<string, readonly ServerToken[]>>`): Each server's tokens, by host id. Default: none.
- `updates?` (`Readonly<Record<string, ServerUpdateStatus | null>>`): Each server's self-update, by host id; `null`: the server predates it. Default: an up-to-date one.

Source: [ui/src/machines/headless/fixture-host.ts:37](https://github.com/Tahul/zidane/blob/main/ui/src/machines/headless/fixture-host.ts#L37)

## Types

### `FixtureMachinesHost`

Type.

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

```ts
type FixtureMachinesHost = MachinesHost & { control: FixtureMachinesControl }
```

Source: [ui/src/machines/headless/fixture-host.ts:125](https://github.com/Tahul/zidane/blob/main/ui/src/machines/headless/fixture-host.ts#L125)
