# zidane-ui/approvals/testing/contract

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

## Functions

### `describeApprovalsHostContract`

Function.

Declares the shared `ApprovalsHost` suite for one implementation.

```ts
function describeApprovalsHostContract(
  name: string,
  makeHarness: ApprovalsHostHarnessFactory,
  capabilities: readonly ApprovalsHostCapability[],
): void
```

**Parameters**

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

Source: [ui/src/approvals/testing/contract.ts:106](https://github.com/Tahul/zidane/blob/main/ui/src/approvals/testing/contract.ts#L106)

## Interfaces

### `ApprovalsHostContractBackend`

Interface.

What the backend behind the host holds, and what it records.

```ts
interface ApprovalsHostContractBackend
```

**Properties**

- `pending` (`WireApprovalRequest[]`): The approvals the backend holds: what a listing answers. Read at each listing; the suite changes it.
- `safelist` (`SafelistProject[]`): The safelist's projects. Read at each listing; a revoke changes it through `removeSafelistEntry`.
- `deniedAll` (`(sessionId: string | undefined) => void`): The backend calls this when a bulk deny reaches it (`undefined`: every session).
- `removeSafelistEntry` (`(project: string, entry: string) => void`): The backend calls this when a revoke reaches it: the entry leaves `safelist`.
- `resolved` (`(requestId: string, decision: ApprovalDecision) => void`): The backend calls this when a decision reaches it.

Source: [ui/src/approvals/testing/contract.ts:28](https://github.com/Tahul/zidane/blob/main/ui/src/approvals/testing/contract.ts#L28)

### `ApprovalsHostHarness`

Interface.

A host built over a contract backend, and the pushes its backend can make.

```ts
interface ApprovalsHostHarness
```

**Properties**

- `host` (`ApprovalsHost`): The host under test.
- `dispose?` (`() => void`): Closes connections and listeners after each test.
- `raise` (`(request: WireApprovalRequest) => void`): Pushes a new request, as the backend does when a tool call needs approval.
- `reconnect?` (`() => void`): Drops the connection and connects again, as a restarted backend would. Absent: the suite skips the re-read.
- `resolveElsewhere` (`(requestId: string, decision: ApprovalDecision) => void`): Pushes that another surface (a window, a terminal) answered a request.

Source: [ui/src/approvals/testing/contract.ts:42](https://github.com/Tahul/zidane/blob/main/ui/src/approvals/testing/contract.ts#L42)

## Types

### `ApprovalsHostCapability`

Type.

An optional `ApprovalsHost` member, by its path.

```ts
type ApprovalsHostCapability = 'resolve' | 'denyAll' | 'safelist' | 'safelist.remove'
```

Source: [ui/src/approvals/testing/contract.ts:23](https://github.com/Tahul/zidane/blob/main/ui/src/approvals/testing/contract.ts#L23)

### `ApprovalsHostHarnessFactory`

Type.

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

```ts
type ApprovalsHostHarnessFactory = (backend: ApprovalsHostContractBackend) => ApprovalsHostHarness | Promise<ApprovalsHostHarness>
```

Source: [ui/src/approvals/testing/contract.ts:56](https://github.com/Tahul/zidane/blob/main/ui/src/approvals/testing/contract.ts#L56)
