Skip to content

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.

TypeScript
function describeMachinesHostContract(
  name: string,
  makeHarness: MachinesHostHarnessFactory,
  capabilities: readonly MachinesHostCapability[],
): void
Parameters
NameTypeDescription
namestring

The implementation's name, shown in the suite title.

makeHarnessMachinesHostHarnessFactory

Builds a fresh host over a backend that holds and records what it is given, once per test.

capabilitiesreadonly MachinesHostCapability[]

The optional members the host offers. Every other optional member must be undefined.

ui/src/machines/testing/contract.ts:327

describeMachinesSyncContractFunction#

Declares the shared suite of MachinesHost.sync and signIn for one implementation.

TypeScript
function describeMachinesSyncContract(
  name: string,
  makeHarness: MachinesSyncHarnessFactory,
  capabilities: readonly MachinesSyncCapability[],
): void
Parameters
NameTypeDescription
namestring

The implementation's name, shown in the suite title.

makeHarnessMachinesSyncHarnessFactory

Builds a fresh host over a backend that holds and records what it is given, once per test.

capabilitiesreadonly MachinesSyncCapability[]

The members the host offers. Every other one must be undefined.

ui/src/machines/testing/sync.contract.ts:139

Interfaces#

MachinesHostContractBackendInterface#

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

TypeScript
interface MachinesHostContractBackend
MachinesHostContractBackend properties
NameTypeDescription
capabilitiesHostCapabilities

What the server can do. The backend counts the probes that asked to refresh in capabilityRefreshes.

capabilityRefreshesnumber

How many capability reads asked for a fresh probe.

daemonDaemonStatus

The local daemon's status.

folderstring

The folder the native dialog answers.

installsstring[]

The tools an install was asked for, in order.

linksMachineLinksStatus

This computer's links. Read at each status; the link recorders change it.

machinesMachineInfo[]

The server's machines. Read at each listing; the harness changes a status before it pushes.

presenceSessionPresence[]

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 (savedHosts) lists it with its dates.

tokensServerToken[]

The server's tokens. Read at each listing; created and revoked change it.

updateServerUpdateStatus

The server's self-update. Read at each status; updated changes it.

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 machines.

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: links changes.

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: update changes.

urlChanged(id: string, url: string) => HostCheckResult

The backend calls this when a URL change reaches it.

ui/src/machines/testing/contract.ts:121

MachinesHostHarnessInterface#

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

TypeScript
interface MachinesHostHarness
MachinesHostHarness properties
NameTypeDescription
hostMachinesHost

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 presence).

pushTokenCreated?(name: string) => void

Adds a token elsewhere (another page, the CLI) and says so, as the backend does (needed for tokens.onChanged).

ui/src/machines/testing/contract.ts:176

MachinesSyncContractBackendInterface#

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

TypeScript
interface MachinesSyncContractBackend
MachinesSyncContractBackend properties
NameTypeDescription
failstring | null

When set, every action fails with this message.

providersHostProviderAuth[]

The server's providers.

server{ id: string; name: string }

The server under test. Its id is the one the suite passes to the host.

signInUrlstring

The page a sign-in opens.

stateHostSyncState

This computer's sync to the server. Read at each state read; the recorders change it.

statusSyncStatus

The server's record. Read at each status read; reset changes it.

configured(patch: HostSyncPatch) => void

The backend calls this when a configure reaches it: state changes.

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 status.

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.

ui/src/machines/testing/sync.contract.ts:36

MachinesSyncHarnessInterface#

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

TypeScript
interface MachinesSyncHarness
MachinesSyncHarness properties
NameTypeDescription
hostMachinesHost

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 sync.state live reads).

ui/src/machines/testing/sync.contract.ts:62

Types#

MachinesHostCapabilityType#

An optional MachinesHost member, by its path.

TypeScript
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'

ui/src/machines/testing/contract.ts:35

MachinesHostHarnessFactoryType#

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

TypeScript
type MachinesHostHarnessFactory = (backend: MachinesHostContractBackend) => MachinesHostHarness | Promise<MachinesHostHarness>

ui/src/machines/testing/contract.ts:190

MachinesSyncCapabilityType#

A member of MachinesHost.sync, or signIn, by its path.

TypeScript
type MachinesSyncCapability =
  | 'sync'
  | 'sync.state'
  | 'sync.configure'
  | 'sync.push'
  | 'sync.takeOver'
  | 'sync.reset'
  | 'sync.providers'
  | 'signIn'

ui/src/machines/testing/sync.contract.ts:21

MachinesSyncHarnessFactoryType#

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

TypeScript
type MachinesSyncHarnessFactory = (backend: MachinesSyncContractBackend) => MachinesSyncHarness | Promise<MachinesSyncHarness>

ui/src/machines/testing/sync.contract.ts:72