zidane-ui/ machines/ testing/ contract
import { … } from 'zidane-ui/machines/testing/contract'ui/src/machines/testing/contract.ts
Functions#
describeMachinesHostContractFunction#
Declares the shared MachinesHost suite for one implementation.
function describeMachinesHostContract(
name: string,
makeHarness: MachinesHostHarnessFactory,
capabilities: readonly MachinesHostCapability[],
): voidParameters
| Name | Type | Description |
|---|---|---|
| name | string | The implementation's name, shown in the suite title. |
| makeHarness | MachinesHostHarnessFactory | Builds a fresh host over a backend that holds and records what it is given, once per test. |
| capabilities | readonly MachinesHostCapability[] | The optional members the host offers. Every other optional member must be undefined. |
describeMachinesSyncContractFunction#
Declares the shared suite of MachinesHost.sync and signIn for one implementation.
function describeMachinesSyncContract(
name: string,
makeHarness: MachinesSyncHarnessFactory,
capabilities: readonly MachinesSyncCapability[],
): voidParameters
| Name | Type | Description |
|---|---|---|
| name | string | The implementation's name, shown in the suite title. |
| makeHarness | MachinesSyncHarnessFactory | Builds a fresh host over a backend that holds and records what it is given, once per test. |
| capabilities | readonly MachinesSyncCapability[] | The members the host offers. Every other one must be undefined. |
Interfaces#
MachinesHostContractBackendInterface#
What the backend behind the host holds, and what it records.
interface MachinesHostContractBackendProperties
| Name | Type | Description |
|---|---|---|
| capabilities | HostCapabilities | What the server can do. The backend counts the probes that asked to refresh in |
| capabilityRefreshes | number | How many capability reads asked for a fresh probe. |
| daemon | DaemonStatus | The local daemon's status. |
| folder | string | The folder the native dialog answers. |
| installs | string[] | The tools an install was asked for, in order. |
| links | MachineLinksStatus | This computer's links. Read at each status; the link recorders change it. |
| machines | MachineInfo[] | The server's machines. Read at each listing; the harness changes a status before it pushes. |
| presence | SessionPresence[] | Every live session's presence. Read at each listing; the harness changes it before it pushes. |
| server | { addedAt: number; id: string; lastConnectedAt: number; name: string; url: string; version: string } | The server under test, as its backend reports it. Its id is the one the suite passes to the host; the registry
( |
| tokens | ServerToken[] | The server's tokens. Read at each listing; |
| update | ServerUpdateStatus | The server's self-update. Read at each status; |
| added | (input: { name?: string; token: string; url: string }) => HostCheckResult | The backend calls this when an add reaches it. |
| created | (name: string, scope: ServerTokenScope) => ServerToken & { token: string } | The backend calls this when a token is created, and answers with what it returns. |
| daemonCalled | (action: 'restart' | 'reconnect' | 'stopRun' | 'relaunchApp', detail?: unknown) => void | The backend calls this when a daemon action reaches it. |
| forgot | (machineId: string) => void | The backend calls this when a forget reaches it: the machine leaves |
| invited | (params: { name?: string; ttlMs?: number }) => { code: string; expiresAt: number } | The backend calls this when a join code is asked for, and answers with what it returns. |
| linked | (action: 'shareStart' | 'shareStop' | 'useServer', detail?: unknown) => void | The backend calls this when a link action reaches it: |
| removed | (id: string) => void | The backend calls this when a removal reaches it. |
| renamed | (id: string, name: string) => HostCheckResult | The backend calls this when a rename reaches it. |
| retried | (hostId: string) => void | The backend calls this when a retry reaches it. |
| revoked | (id: string) => void | The backend calls this when a revoke reaches it. |
| tested | (target: { id: string } | { token: string; url: string }) => HostCheckResult | The backend calls this when a test reaches it, and answers with what it returns. |
| updated | (action: 'check' | 'install' | 'configure', enabled?: boolean) => void | The backend calls this when an update action reaches it: |
| urlChanged | (id: string, url: string) => HostCheckResult | The backend calls this when a URL change reaches it. |
MachinesHostHarnessInterface#
A host built over a contract backend, and the pushes its backend can make.
interface MachinesHostHarnessProperties
| Name | Type | Description |
|---|---|---|
| host | MachinesHost | The host under test. |
| dispose? | () => void | Closes connections and listeners after each test. |
| pushMachineStatus | (machineId: string, status: 'online' | 'offline') => void | Sets a machine's status in the backend and pushes the change, as the backend does. |
| pushPresence? | (sessions: SessionPresence[]) => void | Sets the backend's presence and pushes the snapshot, as the backend does (needed for |
| pushTokenCreated? | (name: string) => void | Adds a token elsewhere (another page, the CLI) and says so, as the backend does (needed for |
MachinesSyncContractBackendInterface#
What the backend behind the host holds, and what it records.
interface MachinesSyncContractBackendProperties
| Name | Type | Description |
|---|---|---|
| fail | string | null | When set, every action fails with this message. |
| providers | HostProviderAuth[] | The server's providers. |
| server | { id: string; name: string } | The server under test. Its id is the one the suite passes to the host. |
| signInUrl | string | The page a sign-in opens. |
| state | HostSyncState | This computer's sync to the server. Read at each state read; the recorders change it. |
| status | SyncStatus | The server's record. Read at each status read; |
| configured | (patch: HostSyncPatch) => void | The backend calls this when a configure reaches it: |
| pushed | () => void | The backend calls this when a push reaches it. |
| reset | (field: string) => void | The backend calls this when a reset reaches it: the override leaves |
| signedIn | (target: HostSignInTarget) => void | The backend calls this when a sign-in starts. |
| tookOver | () => void | The backend calls this when a take over reaches it. |
MachinesSyncHarnessInterface#
A host built over a contract backend, and the pushes its backend can make.
interface MachinesSyncHarnessProperties
| Name | Type | Description |
|---|---|---|
| host | MachinesHost | The host under test. |
| dispose? | () => void | Closes connections and listeners after each test. |
| pushSyncChanged? | () => void | Tells the host the sync of the server changed, as the backend does (needed for |
Types#
MachinesHostCapabilityType#
An optional MachinesHost member, by its path.
type MachinesHostCapability =
| 'hosts'
| 'refreshHosts'
| 'retry'
| 'testHost'
| 'addHost'
| 'renameHost'
| 'setHostUrl'
| 'removeHost'
| 'savedHosts'
| 'machines'
| 'machines.forget'
| 'machines.invite'
| 'links'
| 'links.shareStart'
| 'links.shareStop'
| 'links.useServer'
| 'pickFolder'
| 'updates'
| 'updates.check'
| 'updates.install'
| 'updates.configure'
| 'tokens'
| 'tokens.create'
| 'tokens.revoke'
| 'tokens.onChanged'
| 'daemon'
| 'daemon.reconnect'
| 'daemon.restart'
| 'daemon.stopRun'
| 'daemon.relaunchApp'
| 'presence'
| 'capabilities'
| 'installTool'
| 'permitted'MachinesHostHarnessFactoryType#
Builds a fresh host (and its backend) for one test.
type MachinesHostHarnessFactory = (backend: MachinesHostContractBackend) => MachinesHostHarness | Promise<MachinesHostHarness>MachinesSyncCapabilityType#
A member of MachinesHost.sync, or signIn, by its path.
type MachinesSyncCapability =
| 'sync'
| 'sync.state'
| 'sync.configure'
| 'sync.push'
| 'sync.takeOver'
| 'sync.reset'
| 'sync.providers'
| 'signIn'MachinesSyncHarnessFactoryType#
Builds a fresh host (and its backend) for one test.
type MachinesSyncHarnessFactory = (backend: MachinesSyncContractBackend) => MachinesSyncHarness | Promise<MachinesSyncHarness>