# zidane-ui/palette/testing/contract

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

## Functions

### `describePaletteHostContract`

Function.

Declares the shared `PaletteHost` suite for one implementation.

```ts
function describePaletteHostContract(
  name: string,
  makeHarness: PaletteHostHarnessFactory,
  capabilities: readonly PaletteHostCapability[],
): void
```

**Parameters**

- `name` (`string`): The implementation's name, shown in the suite title.
- `makeHarness` (`PaletteHostHarnessFactory`): Builds a fresh host over a backend that holds what it is given, once per test.
- `capabilities` (`readonly PaletteHostCapability[]`): The optional members the host offers. Every other optional member must be undefined.

Source: [ui/src/palette/testing/contract.ts:116](https://github.com/Tahul/zidane/blob/main/ui/src/palette/testing/contract.ts#L116)

## Interfaces

### `PaletteHostContractBackend`

Interface.

What the backend behind the host holds.

```ts
interface PaletteHostContractBackend
```

**Properties**

- `commands` (`readonly PaletteCommand[]`): The `/` commands for `cwd`.
- `conversations` (`Readonly<Record<string, string>>`): Each session's conversation text, by session id (what a content search scans).
- `cwd` (`string`): The project folder (the commands' `cwd`, the files' root).
- `extensionFailing` (`{ itemId: string; message: string }`): What running an extension item does: a notice with its id, or a failure with this message for `extensionFailing`.
- `extensionItems` (`readonly PaletteItem[]`): Extension items for `cwd` (each `source` is its provider's id).
- `files` (`readonly string[]`): The files under `cwd`, relative, `/`-separated.
- `sessionId` (`string`): A session in that folder (hosts that list a session's workspace list it through this one).
- `settings` (`Partial<Settings>`): The settings in effect. Writes land here.

Source: [ui/src/palette/testing/contract.ts:44](https://github.com/Tahul/zidane/blob/main/ui/src/palette/testing/contract.ts#L44)

### `PaletteHostHarness`

Interface.

A host built over a backend, and what the suite drives on it.

```ts
interface PaletteHostHarness
```

**Properties**

- `host` (`PaletteHost`): The host under test.
- `changeExtensions?` (`() => void`): Has the backend announce that the extension items changed (needed for `extensions.subscribe`).
- `dispose?` (`() => void`): Closes connections and timers after each test.

Source: [ui/src/palette/testing/contract.ts:64](https://github.com/Tahul/zidane/blob/main/ui/src/palette/testing/contract.ts#L64)

## Types

### `PaletteHostCapability`

Type.

An optional `PaletteHost` member, by its path.

```ts
type PaletteHostCapability =
  | 'listCommands'
  | 'listFiles'
  | 'extensions'
  | 'extensions.subscribe'
  | 'settings'
  | 'setSettings'
  | 'recents'
  | 'searchConversations'
```

Source: [ui/src/palette/testing/contract.ts:22](https://github.com/Tahul/zidane/blob/main/ui/src/palette/testing/contract.ts#L22)

### `PaletteHostHarnessFactory`

Type.

Builds a fresh host (and its backend) for one test.

```ts
type PaletteHostHarnessFactory = (backend: PaletteHostContractBackend) => PaletteHostHarness | Promise<PaletteHostHarness>
```

Source: [ui/src/palette/testing/contract.ts:74](https://github.com/Tahul/zidane/blob/main/ui/src/palette/testing/contract.ts#L74)
