zidane/ extensions/ testing
import { … } from 'zidane/extensions/testing'src/extensions/testing/index.ts
Functions#
createTestHostFunction#
Loads extensions into an extension runtime wired to in-memory ports.
function createTestHost(options: TestHostOptions): Promise<TestHost>Parameters
| Name | Type | Description |
|---|---|---|
| options | TestHostOptions | The extensions, port overrides, starting settings and paths. |
Returns
Promise<TestHost>The host, once every extension's setup settled.
Example
const host = await createTestHost({ extensions: [myExtension] })
await host.fire('turn:after', event)
expect(host.ui.items('slot')).toHaveLength(1)
await host.dispose()Interfaces#
TestHostInterface#
A loaded test host.
interface TestHostProperties
| Name | Type | Description |
|---|---|---|
| commandsreadonly | { list: () => readonly { bind?: readonly string[]; id: string; slash?: string; title: string }[]; run: (id: string, opts?: { args?: string; sessionId?: string }) => Promise<boolean> } | Runs commands by published id ( |
| ctx | <S extends SettingsSchema = SettingsSchema>(id: string) => ExtensionContext<S> | The context the extension's |
| dialogsreadonly | ScriptedDialogPort | The scripted dialog client: queue answers with |
| dispose | () => Promise<void> | Unloads everything. |
| extensions | () => ExtensionInfo[] | Every extension and its status. |
| facets | (session: TestSessionSnapshot, trigger?: SessionFacetTrigger) => Promise<Record<string, JsonValue>> | Computes the facets for one session as a host would: the ones that run on
|
| fire | <K extends keyof AgentHooks | 'run:settled' | 'session:event'>(event: K, payload: HookEvents[K]) => Promise<void> | Fires an agent hook or host event at the observers, then waits until they finished. |
| intercept | <K extends keyof Interceptors>(name: K, input: Interceptors[K][0], initial: Interceptors[K][1], opts?: { matchKey?: string }) => Promise<Interceptors[K][1]> | Runs the interceptor chain of |
| registryreadonly | ExtensionRuntimeOutputs | The shared registries: catalogs, interceptors, UI, commands, RPC, contracts, integrations. |
| rpc | <C extends RpcContract<Readonly<Record<string, RpcMethodSpec>>, Readonly<Record<string, RpcEventSpec>>>>(contract: C) => RpcClient<C> | A client for an RPC contract, calling as a separate test extension. |
| runtimereadonly | ExtensionRuntime | The runtime (load, unload, reload, settings wire). |
| schedulesreadonly | { advance: (ms: number) => Promise<void>; now: () => number; readonly prompts: readonly { scheduleId: string; sessionId: string; text: string }[]; setEnabled: (on: boolean) => void; setTime: (epochMs: number) => Promise<void> } |
|
| sessions | (rows: readonly TestSessionRow[]) => void | Replaces the sessions |
| settingsreadonly | MemorySettingsPort | The in-memory settings port ( |
| settled | () => Promise<void> | Waits until every async extension callback started so far has finished. |
| storagereadonly | MemoryStoragePort | The in-memory storage port ( |
| uireadonly | { readonly client: RecordingUiClientPort; items: <N extends keyof UiWireMap>(token: N) => readonly UiEntry<N>[]; snapshot: () => UiSnapshot } | UI contributions as the hosts see them, and the recorded client calls. |
TestHostOptionsInterface#
Options of createTestHost.
interface TestHostOptionsProperties
| Name | Type | Description |
|---|---|---|
| budget? | false | Partial<ErrorBudget> | Guard error budget. Default: the runtime's. |
| extensions | readonly TestHostExtension[] | The extensions, loaded in dependency order. |
| host? | ExtensionHostKind | The host kind |
| onLog? | (record: { attrs: Readonly<Record<string, unknown>>; level: string; message: string }) => void | Receives every log record (warnings, attributed errors). |
| paths? | Partial<ExtensionPaths> | Paths handed to the extensions. Default: under the OS temp folder. |
| ports? | RuntimePorts | Ports that replace the in-memory ones (storage, settings, dialogs and UI client stay reachable only when not replaced). |
| settings? | Readonly<Record<string, Readonly<Record<string, unknown>>>> | Starting settings values in the |
| setupTimeoutMs? | number | Bound of |
Types#
TestHostExtensionType#
One extension to load: a definition, or a definition with where it came from.
type TestHostExtension =
| ExtensionDefinition<any>
| { definition: unknown; dir?: string; enabled?: boolean; source?: ExtensionSource }TestSessionRowType#
A session for TestHost.sessions: an id, and any list-row fields the queries read.
type TestSessionRow = Partial<SessionListRow> & { id: string }TestSessionSnapshotType#
A session for TestHost.facets: an id, and any snapshot fields the facets read.
type TestSessionSnapshot = Partial<SessionSnapshot> & { id: string }Re-exports#
These names are documented on the entry point that owns them.