# zidane-ui/git/testing

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

## Functions

### `createFixtureGitHost`

Function.

Creates a [`GitHost`](https://zidane.si/docs/reference/ui-git-headless.md#GitHost) held in memory. Switching and starting branches change its current
branch; a branch in `held` is refused with its worktree.

```ts
function createFixtureGitHost(options?: FixtureGitOptions): FixtureGitHost
```

**Parameters**

- `options?` (`FixtureGitOptions`, default `{}`): The data, or `false` to leave a member out.

**Returns** `FixtureGitHost`

Source: [ui/src/git/testing/index.ts:267](https://github.com/Tahul/zidane/blob/main/ui/src/git/testing/index.ts#L267)

## Constants

### `DEMO_GIT_BRANCH_PULL_REQUESTS`

Constant.

The demo branches' open pull requests.

```ts
const DEMO_GIT_BRANCH_PULL_REQUESTS: Readonly<Record<string, GitBranchPullRequest>>
```

Source: [ui/src/git/testing/index.ts:148](https://github.com/Tahul/zidane/blob/main/ui/src/git/testing/index.ts#L148)

### `DEMO_GIT_BRANCHES`

Constant.

Demo local branches, most recent first.

```ts
const DEMO_GIT_BRANCHES: readonly GitBranch[]
```

Source: [ui/src/git/testing/index.ts:32](https://github.com/Tahul/zidane/blob/main/ui/src/git/testing/index.ts#L32)

### `DEMO_GIT_CLONE`

Constant.

The demo repository import: what it parses, where it lands, and what a clone reports.

```ts
const DEMO_GIT_CLONE: FixtureClone
```

Source: [ui/src/git/testing/index.ts:153](https://github.com/Tahul/zidane/blob/main/ui/src/git/testing/index.ts#L153)

### `DEMO_GIT_ENVIRONMENTS`

Constant.

Demo environment kinds: the folder, a worktree, a Docker sandbox, and a shared machine's folder.

```ts
const DEMO_GIT_ENVIRONMENTS: readonly EnvironmentDescriptor[]
```

Source: [ui/src/git/testing/index.ts:109](https://github.com/Tahul/zidane/blob/main/ui/src/git/testing/index.ts#L109)

### `DEMO_GIT_FOLDERS`

Constant.

Demo folders on a remote host: the folders under each path.

```ts
const DEMO_GIT_FOLDERS: { roots: readonly string[]; tree: Readonly<Record<string, readonly string[]>> }
```

Source: [ui/src/git/testing/index.ts:121](https://github.com/Tahul/zidane/blob/main/ui/src/git/testing/index.ts#L121)

### `DEMO_GIT_ORIGINS`

Constant.

The demo `origin` of each checkout on this computer.

```ts
const DEMO_GIT_ORIGINS: Readonly<Record<string, string>>
```

Source: [ui/src/git/testing/index.ts:131](https://github.com/Tahul/zidane/blob/main/ui/src/git/testing/index.ts#L131)

### `DEMO_GIT_PULL_REQUESTS`

Constant.

Demo open pull requests: one waiting on you, one of yours, two others.

```ts
const DEMO_GIT_PULL_REQUESTS: readonly GitPullRequest[]
```

Source: [ui/src/git/testing/index.ts:69](https://github.com/Tahul/zidane/blob/main/ui/src/git/testing/index.ts#L69)

### `DEMO_GIT_STATUS`

Constant.

The demo checkout's status.

```ts
const DEMO_GIT_STATUS: GitStatus
```

Source: [ui/src/git/testing/index.ts:136](https://github.com/Tahul/zidane/blob/main/ui/src/git/testing/index.ts#L136)

## Interfaces

### `FixtureClone`

Interface.

A repository import held in memory.

```ts
interface FixtureClone
```

**Properties**

- `defaultParent` (`string`): Where clones land by default.
- `info?` (`Readonly<Record<string, GitRepoInfo>>`): What each input is, for the import dialog's card. Absent: no `info`.
- `progress` (`readonly GitCloneProgress[]`): What a clone reports, in order, before it lands.
- `refused?` (`Readonly<Record<string, string>>`): Inputs whose clone fails, with git's message.
- `repos` (`Readonly<Record<string, GitRepoSpec>>`): What each accepted input parses to. Anything else is not a repository.

Source: [ui/src/git/testing/index.ts:182](https://github.com/Tahul/zidane/blob/main/ui/src/git/testing/index.ts#L182)

### `FixtureGitHost`

Interface.

A [`GitHost`](https://zidane.si/docs/reference/ui-git-headless.md#GitHost) held in memory, with what it did.

```ts
interface FixtureGitHost extends GitHost
```

**Properties**

- `clone?` (`GitClone`, from `GitHost`): Clones a repository into a new folder. Absent: no repository import.
- `cloned` (`{ input: string; parent: string }[]`, readonly): The clones that ran.
- `moves` (`{ branch?: string; sessionId: string }[]`, readonly): The sessions moved into worktrees, and on which branch.
- `relocations` (`{ branch?: string; cwd?: string; kind: string; sessionId: string }[]`, readonly): The sessions moved anywhere (`moveSession`): where, and in which folder.
- `serverClones` (`{ hostId: string; input: string; parent: string }[]`, readonly): The clones that ran on a server.
- `synced` (`string[]`, readonly): The folders synced, in order.
- `activity` (`(sessionId: string) => void`): Tells a session's `subscribeActivity` listeners its work landed.
- `branches?` (`(cwd: string) => Promise<readonly GitBranch[]>`, from `GitHost`): Local branches, most recently committed first. Absent: no branch menu.
- `branchPullRequest?` (`(cwd: string, branch: string, fresh?: boolean) => Promise<GitBranchPullRequest | null>`, from `GitHost`): The open pull request of `branch`, or `null`. `fresh`: past any cache the host keeps. Absent: not shown.
- `changeEnvironments` (`(next: readonly EnvironmentDescriptor[]) => void`): Replaces the environment kinds and tells the `subscribeEnvironments` listeners.
- `checkout?` (`(cwd: string, target: GitCheckoutTarget, sessionId?: string | null) => Promise<GitCheckoutResult>`, from `GitHost`): Switches the checkout. Never forced: git's refusal comes back as the error. Absent: no branch menu.
- `cloneOnServer?` (`(hostId: string, input: string, parent: string) => Promise<GitCloneResult>`, from `GitHost`): Clones `input` into a new folder of `parent` on a saved server. Absent: no clone on send.
- `createBranch?` (`(cwd: string, name: string, sessionId?: string | null) => Promise<GitCheckoutResult>`, from `GitHost`): Starts a branch from the current checkout and switches to it. Absent: a typed name is not offered to start.
- `createFolder?` (`(query: GitCreateFolderQuery) => Promise<GitCreateFolderResult>`, from `GitHost`): Creates a folder on a remote host (not on a shared machine). Absent: no "New folder" in the folder picker.
- `current` (`() => string`): The current branch.
- `environments?` (`(query: GitEnvironmentQuery) => Promise<readonly EnvironmentDescriptor[]>`, from `GitHost`): The environment kinds a new session can run in. Absent: the app supplies them itself.
- `listFolders?` (`(query: GitFolderQuery) => Promise<GitFolderResult>`, from `GitHost`): The folders of a remote host. Absent: no remote folder picker.
- `moveRefs` (`() => void`): Tells the `subscribeRefs` listeners the refs moved.
- `moveSession?` (`(sessionId: string, target: GitMoveTarget) => Promise<GitMoveResult>`, from `GitHost`): Moves an idle session to another environment of its host, in `target.cwd` (a folder on the target; required for a
  machine's kinds). Nothing is copied; the session's terminals and background tasks stop. Absent: no "Move to…".
- `originUrl?` (`(cwd: string) => Promise<string | null>`, from `GitHost`): The `origin` URL of the checkout holding `cwd` on this computer; `null` outside git or without `origin`. Absent: no clone on send.
- `pickFolder?` (`() => Promise<string | null>`, from `GitHost`): Picks a folder on this computer (a native dialog); `null` when cancelled. Absent: no local folder picking.
- `pullRequests?` (`(query: GitPullRequestQuery) => Promise<GitPullRequestList>`, from `GitHost`): Open pull requests: waiting on you, yours, then recent others. Absent: the branch menu lists branches only.
- `searchFolders?` (`(query: GitFolderSearchQuery) => Promise<GitFolderSearchResult>`, from `GitHost`): Searches a remote host's folders by name (not a shared machine's). Absent: the folder picker filters the folder it shows only.
- `startWorktree?` (`(sessionId: string, branch?: string) => Promise<GitActionResult>`, from `GitHost`): Moves a local session into a new git worktree on `branch` (absent: the suggested one). Absent: no "Start a worktree".
- `status?` (`(cwd: string) => Promise<GitStatus | null>`, from `GitHost`): Where the checkout stands; `null` outside a git checkout. Absent: not shown.
- `subscribeActivity?` (`(sessionId: string, onChange: () => void) => () => void`, from `GitHost`): Calls `onChange` when a session's own work may have changed its checkout (a tool call finished, a command ended
  in one of its terminals). Returns the unsubscribe. Absent: the status refreshes on ref moves, focus and a timer.
- `subscribeEnvironments?` (`(query: GitEnvironmentQuery, onChange: () => void) => () => void`, from `GitHost`): Calls `onChange` when what `GitHost.environments` lists for `query` may have changed (environment settings
  edited, a reconnect). Returns the unsubscribe. Absent: the kinds are read once per folder and host.
- `subscribeRefs?` (`(cwd: string, onChange: () => void) => () => void`, from `GitHost`): Calls `onChange` when the checkout's refs move (a commit, fetch, push, switch). Returns the unsubscribe. Absent: lists refresh when reopened.
- `sync?` (`(cwd: string, sessionId?: string | null) => Promise<GitSyncResult>`, from `GitHost`): Pulls (merging) then pushes the current branch, or publishes it when it has no upstream. Absent: no sync.

Source: [ui/src/git/testing/index.ts:240](https://github.com/Tahul/zidane/blob/main/ui/src/git/testing/index.ts#L240)

### `FixtureGitOptions`

Interface.

Options of [`createFixtureGitHost`](https://zidane.si/docs/reference/ui-git-testing.md#createFixtureGitHost). Each defaults to the demo data; `false` leaves its members out.

```ts
interface FixtureGitOptions
```

**Properties**

- `branches?` (`false | readonly GitBranch[]`): The local branches. `false`: no `branches`, `checkout`, `createBranch`.
- `branchPullRequests?` (`false | Readonly<Record<string, GitBranchPullRequest>>`): The open pull request per branch. `false`: no `branchPullRequest`.
- `clone?` (`false | FixtureClone`): The repository import, also on a server (`cloneOnServer`, with `folders`). `false`: neither.
- `current?` (`string`): The current branch. Default: the first branch.
- `environments?` (`false | readonly EnvironmentDescriptor[]`): The environment kinds. `false`: no `environments`.
- `folderAllows?` (`GitFolderAllows`): What the remote host lets clients do in its folders. Default: everything.
- `folders?` (`false | { roots: readonly string[]; tree: Readonly<Record<string, readonly string[]>> }`): Remote folders: the roots and the folders under each path. `false`: no `listFolders`, `createFolder`, `searchFolders`.
- `held?` (`readonly FixtureHeldBranch[]`): Branches other worktrees hold: switching to one is refused, naming the worktree.
- `latencyMs?` (`number`): Milliseconds each answer takes. Default: 0.
- `origins?` (`false | Readonly<Record<string, string>>`): The `origin` URL of each checkout on this computer. `false`: no `originUrl`.
- `pickedFolder?` (`string | null`): What `pickFolder` answers. Absent: no `pickFolder`.
- `pullRequests?` (`false | readonly GitPullRequest[] | null`): The open pull requests; `null`: the host can't reach them. `false`: no `pullRequests`.
- `status?` (`false | GitStatus`): The checkout's status. `false`: no `status`.
- `sync?` (`false | { conflicts?: { cwd: string; files: readonly string[]; message: string } }`): A sync of `cwd` stops on conflicts. `false`: no `sync`. Default: syncs land, recorded in `synced`.
- `worktrees?` (`boolean`): `false`: no `startWorktree` and no `moveSession`. Default: offered, recorded in `moves` and `relocations`.

Source: [ui/src/git/testing/index.ts:206](https://github.com/Tahul/zidane/blob/main/ui/src/git/testing/index.ts#L206)

### `FixtureHeldBranch`

Interface.

A branch another worktree has checked out.

```ts
interface FixtureHeldBranch
```

**Properties**

- `branch` (`string`): The branch.
- `chats` (`readonly string[]`): The chats in that worktree.
- `worktree` (`string`): The worktree's path.

Source: [ui/src/git/testing/index.ts:196](https://github.com/Tahul/zidane/blob/main/ui/src/git/testing/index.ts#L196)
