Skip to content

zidane-ui/git/testing/contract

import { … } from 'zidane-ui/git/testing/contract'ui/src/git/testing/contract.ts

Functions#

describeGitHostContractFunction#

Declares the shared GitHost suite for one implementation.

TypeScript
function describeGitHostContract(
  name: string,
  makeHarness: GitHostHarnessFactory,
  capabilities: readonly GitHostCapability[],
): void
Parameters
NameTypeDescription
namestring

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

makeHarnessGitHostHarnessFactory

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

capabilitiesreadonly GitHostCapability[]

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

ui/src/git/testing/contract.ts:265

Interfaces#

GitHostContractBackendInterface#

What the backend behind the host holds, and what it does with each action.

TypeScript
interface GitHostContractBackend
GitHostContractBackend properties
NameTypeDescription
branchesGitBranch[]

Local branches, most recent first. The first is checked out.

branchPullRequestsRecord<string, GitBranchPullRequest>

The open pull request per branch. Branches left out have none.

cloned{ input: string; parent: string }[]

Clones that ran: what was cloned, and where.

currentstring

The current branch. Switches and new branches land here.

cwdstring

The checkout's folder.

environmentsEnvironmentDescriptor[]

The environment kinds for cwd.

existsMessagestring

Creating a branch that exists fails with this message.

folders{ existsMessage: string; outsideMessage: string; roots: string[]; tree: Record<string, string[]> }

The remote host's folders: its roots, and the folders under each path. A path outside the roots is refused with outsideMessage; a new folder whose name is taken, with existsMessage. New folders land in tree.

held{ branch: string; chats: string[]; message: string; worktree: string }

A branch another worktree has checked out: switching to it is refused with git's message, the worktree and its chats.

hostIdstring

The saved server whose folders listFolders lists (hosts that reach several pass it on).

moves{ branch?: string; sessionId: string }[]

Sessions moved into worktrees land here.

originsRecord<string, string>

The origin URL of each checkout on this computer. Other folders have none.

pickedFolderstring

What the native folder dialog answers.

pullRequestsGitPullRequest[]

Open pull requests. A search answers the ones prMatches finds.

relocations{ branch?: string; cwd?: string; kind: string; sessionId: string }[]

Sessions moved anywhere (moveSession) land here: where, and in which folder.

repo{ defaultParent: string; info: GitRepoInfo; input: string; progress: GitCloneProgress[]; refusedInput: string; refusedMessage: string; spec: GitRepoSpec }

The repository import: what repo.input parses to, where clones land by default, the progress a clone reports, and a refused input.

serverClones{ hostId: string; input: string; parent: string }[]

Clones that ran on a server: which server, what, and where.

sessionIdstring

A session in that folder.

statusGitStatus

The checkout's status.

sync{ conflictCwd: string; conflictMessage: string; conflicts: string[] }

What a sync does: it pulls behind and pushes ahead of status. Syncing conflictCwd fails with conflictMessage and conflicts.

syncedstring[]

Syncs that ran, by folder.

ui/src/git/testing/contract.ts:78

GitHostHarnessInterface#

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

TypeScript
interface GitHostHarness
GitHostHarness properties
NameTypeDescription
hostGitHost

The host under test.

activity?(sessionId: string) => void

Has the backend report work by a session that may have moved its checkout (needed for subscribeActivity).

changeEnvironments?() => void

Has the backend announce that the environment kinds may have changed (needed for subscribeEnvironments).

dispose?() => void

Closes connections and timers after each test.

moveRefs?() => void

Has the backend announce that the checkout's refs moved (needed for subscribeRefs).

ui/src/git/testing/contract.ts:136

Types#

GitHostCapabilityType#

An optional GitHost member.

TypeScript
type GitHostCapability =
  | 'branches'
  | 'pullRequests'
  | 'checkout'
  | 'createBranch'
  | 'startWorktree'
  | 'moveSession'
  | 'environments'
  | 'subscribeEnvironments'
  | 'status'
  | 'subscribeRefs'
  | 'listFolders'
  | 'pickFolder'
  | 'subscribeActivity'
  | 'branchPullRequest'
  | 'sync'
  | 'clone'
  | 'createFolder'
  | 'searchFolders'
  | 'originUrl'
  | 'cloneOnServer'

ui/src/git/testing/contract.ts:29

GitHostHarnessFactoryType#

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

TypeScript
type GitHostHarnessFactory = (backend: GitHostContractBackend) => GitHostHarness | Promise<GitHostHarness>

ui/src/git/testing/contract.ts:150