# zidane-ui/session/testing

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

## Functions

### `createFixturePlansBackend`

Function.

Creates a [`FixturePlansBackend`](https://zidane.si/docs/reference/ui-session-testing.md#FixturePlansBackend).

```ts
function createFixturePlansBackend(seed?: FixturePlansSeed): FixturePlansBackend
```

**Parameters**

- `seed?` (`FixturePlansSeed`, default `{}`): The plans and task lists it starts with.

**Returns** `FixturePlansBackend`

Source: [ui/src/session/headless/fixture-plans.ts:89](https://github.com/Tahul/zidane/blob/main/ui/src/session/headless/fixture-plans.ts#L89)

### `createFixtureScheduleBackend`

Function.

Creates a [`FixtureScheduleBackend`](https://zidane.si/docs/reference/ui-session-testing.md#FixtureScheduleBackend).

```ts
function createFixtureScheduleBackend(
  options?: FixtureScheduleOptions,
): FixtureScheduleBackend
```

**Parameters**

- `options?` (`FixtureScheduleOptions`, default `{}`): The starting schedules, fires, setting and clock.

**Returns** `FixtureScheduleBackend`

Source: [ui/src/session/headless/fixture-schedules.ts:65](https://github.com/Tahul/zidane/blob/main/ui/src/session/headless/fixture-schedules.ts#L65)

### `createFixtureSessionHost`

Function.

Creates a [`FixtureSessionHost`](https://zidane.si/docs/reference/ui-session-testing.md#FixtureSessionHost) over the fixture's data.

```ts
function createFixtureSessionHost(fixture?: SessionFixture): FixtureSessionHost
```

**Parameters**

- `fixture?` (`SessionFixture`, default `{}`): The data per session.

**Returns** `FixtureSessionHost`

Source: [ui/src/session/headless/fixture-host.ts:118](https://github.com/Tahul/zidane/blob/main/ui/src/session/headless/fixture-host.ts#L118)

### `demoUsageSummary`

Function.

A usage summary over `range`, ending on `today`: a few months of steady use across three models.

```ts
function demoUsageSummary(range: UsageRange, today?: Date): UsageSummary
```

**Parameters**

- `range` (`UsageRange`): The range it covers.
- `today?` (`Date`): The last day.

**Returns** `UsageSummary`

Source: [ui/src/session/testing/demo.ts:54](https://github.com/Tahul/zidane/blob/main/ui/src/session/testing/demo.ts#L54)

### `planOf`

Function.

A session-scope plan over a task list, for fixtures and tests.

```ts
function planOf(items: readonly TodoItem[], plan?: Partial<Plan>): Plan
```

**Parameters**

- `items` (`readonly TodoItem[]`): The steps, as todo items.
- `plan?` (`Partial<Plan>`, default `{}`): Fields over the defaults (an applying adhoc plan `plan-1`, untitled).

**Returns** `Plan`

Source: [ui/src/session/headless/fixture-plans.ts:58](https://github.com/Tahul/zidane/blob/main/ui/src/session/headless/fixture-plans.ts#L58)

### `plansSnapshotOf`

Function.

The snapshot of a session's plans, as the host broadcasts it (every run live: nothing reads as interrupted).

```ts
function plansSnapshotOf(plans: readonly PlanView[]): PlansSnapshot
```

**Parameters**

- `plans` (`readonly PlanView[]`): The plans, oldest first.

**Returns** `PlansSnapshot`

Source: [ui/src/session/headless/fixture-plans.ts:48](https://github.com/Tahul/zidane/blob/main/ui/src/session/headless/fixture-plans.ts#L48)

### `tallyTodos`

Function.

Counts todo items by status.

```ts
function tallyTodos(items: readonly { status: TodoStatus }[]): TodoTallyCounts
```

**Parameters**

- `items` (`readonly { status: TodoStatus }[]`): The todo list.

**Returns** `TodoTallyCounts`

Source: [ui/src/session/headless/fixture-plans.ts:78](https://github.com/Tahul/zidane/blob/main/ui/src/session/headless/fixture-plans.ts#L78)

## Constants

### `DEMO_ARTIFACT_KIND_LABELS`

Constant.

The artifact kinds' labels in the demo, as the backend's kind registry words them.

```ts
const DEMO_ARTIFACT_KIND_LABELS: Readonly<Record<string, string>>
```

Source: [ui/src/session/testing/demo.ts:25](https://github.com/Tahul/zidane/blob/main/ui/src/session/testing/demo.ts#L25)

### `DEMO_GITHUB_USAGE`

Constant.

GitHub's API limits in the demo.

```ts
const DEMO_GITHUB_USAGE: readonly ProviderUsageSnapshot[]
```

Source: [ui/src/session/testing/demo.ts:157](https://github.com/Tahul/zidane/blob/main/ui/src/session/testing/demo.ts#L157)

### `DEMO_PROVIDER_USAGE`

Constant.

Subscription windows: one provider with two accounts' worth of windows, one with credits.

```ts
const DEMO_PROVIDER_USAGE: readonly ProviderUsageSnapshot[]
```

Source: [ui/src/session/testing/demo.ts:109](https://github.com/Tahul/zidane/blob/main/ui/src/session/testing/demo.ts#L109)

### `DEMO_SESSION_FIXTURE`

Constant.

A session (`demo`) with todos mid-task, two queued messages, three artifacts, running work and turns, plus usage.

```ts
const DEMO_SESSION_FIXTURE: SessionFixture
```

Source: [ui/src/session/testing/demo.ts:177](https://github.com/Tahul/zidane/blob/main/ui/src/session/testing/demo.ts#L177)

### `DEMO_TURNS`

Constant.

The demo's stored turns: a prompt and the answer.

```ts
const DEMO_TURNS: readonly SessionTurn[]
```

Source: [ui/src/session/testing/demo.ts:33](https://github.com/Tahul/zidane/blob/main/ui/src/session/testing/demo.ts#L33)

### `SCHEDULES_OFF_MESSAGE`

Constant.

The message zidane's backend answers while the setting is off.

```ts
const SCHEDULES_OFF_MESSAGE: 'Reminders are off. Turn them on in Settings > Sessions > Reminders.'
```

Source: [ui/src/session/headless/fixture-schedules.ts:58](https://github.com/Tahul/zidane/blob/main/ui/src/session/headless/fixture-schedules.ts#L58)

## Interfaces

### `FixturePlansBackend`

Interface.

A plans backend in memory.

```ts
interface FixturePlansBackend
```

**Properties**

- `control` (`(sessionId: string, planId: string, action: PlanControlAction) => PlansSnapshot`): A stop or drop (`plans.control`). Throws the gate's reason.
- `edit` (`(sessionId: string, planId: string, op: PlanEditOp) => PlansSnapshot`): A user edit (`plans.edit`). Throws the gate's reason.
- `endRun` (`(sessionId: string, outcome?: 'error' | 'completed' | 'aborted') => void`): The session's run ended: the plan it applied stops.
- `setPlans` (`(sessionId: string, plans: readonly PlanView[]) => void`): Replaces a session's plans.
- `snapshot` (`(sessionId: string) => PlansSnapshot | null`): A session's snapshot, `null` for a session it does not hold.
- `subscribe` (`(listener: (sessionId: string) => void) => () => void`): Calls `listener` with a session's id after each change. Returns the unsubscribe.
- `writeTodos` (`(sessionId: string, items: readonly TodoItem[]) => void`): The agent's `todowrite`: updates the applying plan, starts one, or resumes a stopped one with the same step ids.

Source: [ui/src/session/headless/fixture-plans.ts:24](https://github.com/Tahul/zidane/blob/main/ui/src/session/headless/fixture-plans.ts#L24)

### `FixturePlansSeed`

Interface.

What a fixture plans backend starts with, per session id.

```ts
interface FixturePlansSeed
```

**Properties**

- `plans?` (`Readonly<Record<string, readonly PlanView[]>>`): Each session's plans, oldest first (`possiblyInterrupted` shows an applying plan with no live run).
- `todos?` (`Readonly<Record<string, readonly TodoItem[]>>`): Each session's task list as the agent wrote it (`todowrite`), applied over `plans`: an applying plan.

Source: [ui/src/session/headless/fixture-plans.ts:16](https://github.com/Tahul/zidane/blob/main/ui/src/session/headless/fixture-plans.ts#L16)

### `FixtureQueuedEntry`

Interface.

A queued entry the fixture holds, with its attachments' bytes.

```ts
interface FixtureQueuedEntry
```

**Properties**

- `attachments?` (`PromptAttachment[]`): Its attachments, with their bytes.
- `id` (`string`): The entry's id.
- `text` (`string`): The message text.

Source: [ui/src/session/headless/fixture-host.ts:40](https://github.com/Tahul/zidane/blob/main/ui/src/session/headless/fixture-host.ts#L40)

### `FixtureScheduleBackend`

Interface.

A scripted reminders backend.

```ts
interface FixtureScheduleBackend
```

**Properties**

- `create` (`(input: unknown) => Schedule`): `schedules.create`, as the person (`createdBy: user`).
- `fires` (`(id: string, limit?: number) => ScheduleFire[]`): `schedules.fires`: newest first.
- `list` (`(filter?: { sessionId?: string }) => Schedule[]`): `schedules.list`: every schedule, or those whose prompt goes to `sessionId`.
- `remove` (`(id: string) => boolean`): `schedules.delete`: `false` when it was gone.
- `replace` (`(list: readonly Schedule[]) => void`): Replaces the stored schedules from outside (the agent set one, one fired).
- `runNow` (`(id: string) => ScheduleFire`): `schedules.runNow`: records a fire now; the next time does not move.
- `setEnabled` (`(enabled: boolean) => void`): Turns the setting on or off.
- `status` (`() => SchedulesStatus`): `schedules.status`.
- `subscribe` (`(onChange: (scheduleId?: string) => void) => () => void`): Hears every change (`schedules:changed`). Returns the unsubscribe.
- `update` (`(id: string, patch: unknown) => Schedule`): `schedules.update`.

Source: [ui/src/session/headless/fixture-schedules.ts:22](https://github.com/Tahul/zidane/blob/main/ui/src/session/headless/fixture-schedules.ts#L22)

### `FixtureScheduleOptions`

Interface.

What [`createFixtureScheduleBackend`](https://zidane.si/docs/reference/ui-session-testing.md#createFixtureScheduleBackend) starts with.

```ts
interface FixtureScheduleOptions
```

**Properties**

- `enabled?` (`boolean`, default `true`): `Settings.schedules`.
- `fires?` (`Readonly<Record<string, readonly ScheduleFire[]>>`): Each schedule's fires, newest first.
- `now?` (`() => number`, default `Date.now`): The clock.
- `schedules?` (`readonly Schedule[]`): The stored schedules, oldest first.

Source: [ui/src/session/headless/fixture-schedules.ts:46](https://github.com/Tahul/zidane/blob/main/ui/src/session/headless/fixture-schedules.ts#L46)

### `FixtureSessionControl`

Interface.

Changes a fixture's data from outside and announces it, as the agent or another window would.

```ts
interface FixtureSessionControl
```

**Properties**

- `endRun` (`(sessionId: string, outcome?: 'error' | 'completed' | 'aborted') => void`): The session's run ended: the plan it applied stops.
- `recordArtifact` (`(sessionId: string, row: SessionArtifactRow) => void`): Records an artifact (newest first).
- `setPlans` (`(sessionId: string, plans: readonly PlanView[]) => void`): Replaces a session's plans.
- `setQueue` (`(sessionId: string, entries: readonly FixtureQueuedEntry[]) => void`): Replaces a session's queue.
- `setSchedules` (`(list: readonly Schedule[]) => void`): Replaces the stored reminders (the agent set one, one fired) and announces the change.
- `setSchedulesEnabled` (`(enabled: boolean) => void`): Turns the Reminders setting on or off and announces it.
- `setSecrets` (`(sessionId: string, entries: readonly SecretEntry[]) => void`): Replaces a session's saved secrets (the agent saved one, another window revoked one).
- `setWork` (`(sessionId: string, items: readonly RunningWorkItem[]) => void`): Replaces a session's running work.
- `writeTodos` (`(sessionId: string, items: readonly TodoItem[]) => void`): The agent's `todowrite`: updates the applying plan, starts one, or resumes a stopped one with the same step ids.

Source: [ui/src/session/headless/fixture-host.ts:86](https://github.com/Tahul/zidane/blob/main/ui/src/session/headless/fixture-host.ts#L86)

### `FixtureSessionHost`

Interface.

The fixture host: a full `SessionHost` plus its `control`.

```ts
interface FixtureSessionHost extends SessionHost
```

**Properties**

- `artifacts?` (`SessionArtifacts`, from `SessionHost`): The recorded artifacts. Absent: no Artifacts panel.
- `control` (`FixtureSessionControl`): Changes the data from outside.
- `details?` (`SessionDetailsActions`, from `SessionHost`): The details dialog's actions. Absent: the dialog shows facts only.
- `plans?` (`SessionPlans`, from `SessionHost`): The plans. Absent: no Todos panel.
- `queue?` (`SessionQueue`, from `SessionHost`): The type-ahead queues. Absent: no queue.
- `runningWork?` (`SessionRunningWork`, from `SessionHost`): The cancellable work. Absent: no running work dialog.
- `schedules?` (`SessionSchedules`, from `SessionHost`): Reminders (zidane's schedules). Absent: no Reminders panel, no badge.
- `secrets?` (`SessionSecrets`, from `SessionHost`): The saved secrets of a session's project. Absent: no Secrets panel.
- `side?` (`SessionSideChats`, from `SessionHost`): `/side` chats about a session. Absent: no side chat.
- `turns?` (`SessionTurns`, from `SessionHost`): The stored turns. Absent: no turn details dialog.
- `usage?` (`SessionUsage`, from `SessionHost`): Usage. Absent: no usage card, no usage panel.

Source: [ui/src/session/headless/fixture-host.ts:108](https://github.com/Tahul/zidane/blob/main/ui/src/session/headless/fixture-host.ts#L108)

### `SessionFixture`

Interface.

What a fixture session host starts with, per session id.

```ts
interface SessionFixture
```

**Properties**

- `artifacts?` (`Readonly<Record<string, readonly SessionArtifactRow[]>>`): The artifacts per session, newest first.
- `githubUsage?` (`readonly ProviderUsageSnapshot[]`): GitHub's API limits. Absent: no `usage.github`.
- `kindLabel?` (`(kind: string) => string`): An artifact kind's group label. Default: the raw kind.
- `plans?` (`Readonly<Record<string, readonly PlanView[]>>`): The plans per session, oldest first (`possiblyInterrupted` shows an applying plan with no live run).
- `providerUsage?` (`readonly ProviderUsageSnapshot[]`): The providers' subscription snapshots. Absent: no `usage.providers`.
- `queue?` (`Readonly<Record<string, readonly FixtureQueuedEntry[]>>`): The queued messages per session.
- `scheduleFires?` (`Readonly<Record<string, readonly ScheduleFire[]>>`): Each reminder's fires, newest first, by schedule id.
- `schedules?` (`readonly Schedule[]`): The stored reminders (zidane's schedules), oldest first. Absent: no `schedules`.
- `schedulesEnabled?` (`boolean`, default `true`): `Settings.schedules`.
- `secrets?` (`Readonly<Record<string, readonly SecretEntry[]>>`): The saved secrets per session (as the session's project holds them). Absent: no `secrets`.
- `secretsSaveError?` (`string`): `secrets.save` rejects with this message (a plain-text remote link refusing values).
- `sides?` (`Readonly<Record<string, string>>`): Each session's side chat id, by the parent's id. Absent: no `side`.
- `todos?` (`Readonly<Record<string, readonly TodoItem[]>>`): The task list per session as the agent wrote it (`todowrite`), over `plans`: an applying plan.
- `turns?` (`Readonly<Record<string, readonly SessionTurn[]>>`): The stored turns per session.
- `usage?` (`Partial<Record<UsageRange, UsageSummary>>`): The usage summary per range. Absent: no `usage.summary`.
- `work?` (`Readonly<Record<string, readonly RunningWorkItem[]>>`): The running work per session.

Source: [ui/src/session/headless/fixture-host.ts:50](https://github.com/Tahul/zidane/blob/main/ui/src/session/headless/fixture-host.ts#L50)
