Repair project grouping typed integration fixtures

This commit is contained in:
Brennan Benson
2026-10-31 07:13:03 -07:00
parent 0ea3bcb941
commit b11308cf00
15 changed files with 88 additions and 53 deletions
@@ -25,6 +25,7 @@ import { WORKSPACE_OPTION_CONTROLS } from '../host-screen/workspace-option-contr
import { projectHostSetupProjectionFromRepos } from '../../../src/shared/project-host-setup-projection'
import { buildFilterRepos } from '../worktree/workspace-filter-repos'
import type { HostScreenController } from '../host-screen/use-host-screen-controller'
// Keep the integration bound for real encrypted RPC, held ACKs and persisted-state settlement.
it('joins normally published nested Hx through the actual Projects pending writer and marked owner', async () => {
const acknowledgements: (() => void)[] = []
const owner = await createProjectGroupingSocketOwner({
@@ -20,7 +20,13 @@ import { afterEach, beforeEach, expect, it, vi } from 'vitest'
import { mkdtempSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { closeTestStores, createStore, readDataFile, testState } from '../persistence-test-harness'
import {
closeTestStores,
createStore,
readDataFile,
readPersistedState,
testState
} from '../persistence-test-harness'
import { RpcDispatcher } from '../../runtime/rpc/dispatcher'
import { CLIENT_UI_METHODS } from '../../runtime/rpc/methods/client-ui'
import { RUNTIME_CLIENT_CAPABILITY_METHODS } from '../../runtime/rpc/methods/runtime-client-capabilities'
@@ -331,7 +337,7 @@ it('saves the actual nested Hx edit exactly through native and marked RPC owners
electron.handlers.get('ui:set')!({}, { filterRepoIds: edited })
expect(store.getUI().filterRepoIds).toEqual(edited)
store.flush()
expect(readDataFile().ui.filterRepoIds).toEqual(edited)
expect(readPersistedState().ui.filterRepoIds).toEqual(edited)
const runtime = new OrcaRuntimeService(store)
const dispatcher = new RpcDispatcher({
runtime,
@@ -384,7 +390,7 @@ it('saves the actual nested Hx edit exactly through native and marked RPC owners
unresolved: ['offline']
})
store.flush()
expect(readDataFile().ui.filterRepoIds).toEqual(edited)
expect(readPersistedState().ui.filterRepoIds).toEqual(edited)
await closeTestStores()
const restored = createStore().getUI().filterRepoIds
// Hydration may prune absent literal raw ids; the existing qualified physical address survives while r exists.
@@ -447,12 +453,12 @@ it.each([100, 1000])(
expect(writes.mock.calls.at(-1)?.[0].filterRepoIds).toEqual(produced)
expect(store.getUI().filterRepoIds).toEqual(produced)
store.flush()
expect(readDataFile().ui.filterRepoIds).toEqual(produced)
expect(readPersistedState().ui.filterRepoIds).toEqual(produced)
const matches = projectRepoFilterMatcher(store.getUI().filterRepoIds)
const included = authored.filter((repo) => matches(repo.id, repo.executionHostId))
expect(included).toEqual(authored.slice(0, q))
process.stdout.write(
`F1 owner ${JSON.stringify({ n, q, sends: writes.mock.calls.length - before, returned: response.ok, savedTokens: readDataFile().ui.filterRepoIds.length, included: included.length })}\n`
`F1 owner ${JSON.stringify({ n, q, sends: writes.mock.calls.length - before, returned: response.ok, savedTokens: readPersistedState().ui.filterRepoIds.length, included: included.length })}\n`
)
}
writes.mockRestore()
@@ -107,7 +107,7 @@ export function prepareSettingsProjectRemoval(
members.push(member)
}
}
const recipeHosts = new Set(
const recipeHosts = new Set<ExecutionHostId>(
state.runtimeEnvironments.flatMap((environment) => {
const host = toRuntimeExecutionHostId(environment.id)
return getRecipeVmSshTargetForHost([environment], host) ? [host] : []
@@ -57,6 +57,7 @@ describe('useRepositorySourceControlAiGlobalUx', () => {
return originalQueue(options)
})
const available = { ...withRecipe('original'), enabled: false }
const initialProps: { snapshot: RepoSourceControlAiOverrides | null } = { snapshot: available }
const updateRepo = vi.fn().mockResolvedValue(true)
type Ux = ReturnType<typeof useRepositorySourceControlAiGlobalUx>
let onCommit: ((ux: Ux) => void) | undefined
@@ -77,7 +78,7 @@ describe('useRepositorySourceControlAiGlobalUx', () => {
})
return ux
},
{ initialProps: { snapshot: available } }
{ initialProps }
)
try {
act(() => {
@@ -15,7 +15,7 @@ import { registerUIHandlers } from '../../../../main/ipc/ui'
import {
createStore,
closeTestStores,
readDataFile,
readPersistedState,
testState,
writeDataFile
} from '../../../../main/persistence/persistence-test-harness'
@@ -686,7 +686,7 @@ it('completes the actual adopted nested Hx in Projects without borrowing Hy from
expect(setFilterRepoIds).toHaveBeenLastCalledWith(['offline', 'ssh:x\0r'])
expect(store.getUI().filterRepoIds).toEqual(['offline', 'ssh:x\0r'])
store.flush()
expect(readDataFile().ui.filterRepoIds).toEqual(['offline', 'ssh:x\0r'])
expect(readPersistedState().ui.filterRepoIds).toEqual(['offline', 'ssh:x\0r'])
const rows = [
{ id: 'r', host: 'ssh:x' as const, name: 'wx' },
{ id: 'r', host: 'ssh:y' as const, name: 'wy' },
@@ -613,7 +613,7 @@ it('retains own display and original beta-first context when host-mode ordering
{ ...worktree, id: 'alpha-main', repoId: 'same', hostId: 'ssh:gpu-vm' }
],
{
repoMap: new Map([
repoMap: new Map<string, Repo>([
[local.id, local],
[sshBeta.id, sshBeta]
]),
@@ -1,4 +1,5 @@
import type { Store } from '../../../../main/persistence'
import { ProjectGroupMoveProjectArgs } from '../../../../main/ipc/repos/repo-ipc-arg-schemas'
import type { ProjectHostSetup } from '../../../../shared/project-types'
import type { Repo } from '../../../../shared/repo-types'
import type userEvent from '@testing-library/user-event'
@@ -103,7 +104,7 @@ export async function groupActionFixture(input: {
)
}
const createLocal = vi.fn<Window['api']['projectGroups']['create']>(async (args) =>
localDisk.createProjectGroup(args)
localDisk.createProjectGroup({ ...args, createdFrom: args.createdFrom ?? 'manual' })
)
const createRemote = vi.fn((name: string) =>
remoteDisk.createProjectGroup({ name, createdFrom: 'manual' })
@@ -115,18 +116,24 @@ export async function groupActionFixture(input: {
projectGroups: {
...window.api?.projectGroups,
create: createLocal,
moveProject: async (args: Parameters<Window['api']['projectGroups']['moveProject']>[0]) =>
receivingMove('local', localDisk, {
moveProject: async (
input: Parameters<Window['api']['projectGroups']['moveProject']>[0]
) => {
const args = ProjectGroupMoveProjectArgs.parse(input)
return receivingMove('local', localDisk, {
id: args.projectId,
hostId: args.hostId,
groupId: args.groupId,
order: args.order
})
}
},
runtimeEnvironments: {
...window.api?.runtimeEnvironments,
call: async (request: Parameters<Window['api']['runtimeEnvironments']['call']>[0]) => {
const compatible = createCompatibleRuntimeStatusResponseIfNeeded(request)
const compatible = createCompatibleRuntimeStatusResponseIfNeeded({
method: request.method
})
if (compatible) {
return compatible
}
@@ -279,7 +279,7 @@ it('completes row New through the existing list dialog lifetime while its first
render(<ShippingSidebar />)
await user.pointer({ target: screen.getByText('b checkout'), keys: '[MouseRight]' })
await user.click(screen.getByRole('menuitem', { name: 'New group from project' }))
await user.click(screen.getByRole('button', { name: 'Create', exact: true }))
await user.click(screen.getByRole('button', { name: 'Create' }))
await waitFor(() => expect(fixture.moves).toHaveLength(3))
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())
expect(fixture.createLocal).toHaveBeenCalledTimes(1)
@@ -217,10 +217,11 @@ it('refreshes the open selected operation and predicates together, with equal/un
worktree: { ...worktree, repoId: 'a', hostId: 'local' }
}
let commits = 0
let selected: ReturnType<typeof useProjectGroupOperation> = null
const observed: { selected: ReturnType<typeof useProjectGroupOperation> } = { selected: null }
const resolver = vi.spyOn(groupOperations, 'resolveProjectGroupOperation')
function Probe() {
selected = useProjectGroupOperation(true, entrance)
const selected = useProjectGroupOperation(true, entrance)
observed.selected = selected
useLayoutEffect(() => {
commits++
})
@@ -271,8 +272,8 @@ it('refreshes the open selected operation and predicates together, with equal/un
}))
)
expect(commits).toBe(2)
expect(selected?.grouped).toBe(true)
expect(selected?.uniformGroupId).toBeUndefined()
expect(observed.selected?.grouped).toBe(true)
expect(observed.selected?.uniformGroupId).toBeUndefined()
act(() =>
useAppStore.setState((state) => ({
projectGroups: state.projectGroups.map((group) =>
@@ -159,13 +159,10 @@ it('uses the actual runtime host-copy New dialog once and retains its ID on fail
})
const quiet = vi.spyOn(console, 'error').mockImplementation(() => {})
try {
await user.click(screen.getByRole('button', { name: 'Create', exact: true }))
await user.click(screen.getByRole('button', { name: 'Create' }))
await waitFor(() => expect(fixture.moves).toHaveLength(2))
await waitFor(() =>
expect(screen.getByRole('button', { name: 'Create', exact: true })).toHaveProperty(
'disabled',
false
)
expect(screen.getByRole('button', { name: 'Create' })).toHaveProperty('disabled', false)
)
expect(screen.getByRole('dialog')).toBeTruthy()
expect(fixture.createRemote).toHaveBeenCalledTimes(1)
@@ -174,7 +171,7 @@ it('uses the actual runtime host-copy New dialog once and retains its ID on fail
expect(fixture.remoteDisk.getRepo('c')?.projectGroupId).toBe(created.id)
expect(fixture.remoteDisk.getRepo('d')?.projectGroupId ?? null).toBeNull()
failD = false
await user.click(screen.getByRole('button', { name: 'Create', exact: true }))
await user.click(screen.getByRole('button', { name: 'Create' }))
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())
expect(fixture.createRemote).toHaveBeenCalledTimes(1)
expect(fixture.moves.map((move) => move.id)).toEqual(['c', 'd', 'd', 'e'])
@@ -249,15 +246,12 @@ it('keeps row New bound to its captured own name and draft through foreign, equa
})
}
})
await user.click(screen.getByRole('button', { name: 'Create', exact: true }))
await user.click(screen.getByRole('button', { name: 'Create' }))
await waitFor(() => expect(release).toBeTypeOf('function'))
publishForeignName('Latest Quay')
expect(screen.getByRole('dialog')).toBe(dialog)
expect(input).toHaveProperty('value', 'My Harbor group')
expect(screen.getByRole('button', { name: 'Saving...', exact: true })).toHaveProperty(
'disabled',
true
)
expect(screen.getByRole('button', { name: 'Saving...' })).toHaveProperty('disabled', true)
expect(fixture.createLocal).toHaveBeenCalledTimes(1)
expect(fixture.createLocal).toHaveBeenCalledWith(
expect.objectContaining({ name: 'My Harbor group' })
@@ -429,10 +423,10 @@ it('fences an old card New continuation and dialog completion when closed and re
await user.click(screen.getByRole('menuitem', { name: 'New group from project' }))
await user.clear(screen.getByRole('textbox', { name: 'Group Name' }))
await user.type(screen.getByRole('textbox', { name: 'Group Name' }), 'Old row draft')
await user.click(screen.getByRole('button', { name: 'Create', exact: true }))
await user.click(screen.getByRole('button', { name: 'Create' }))
await waitFor(() => expect(release).toBeTypeOf('function'))
const oldGroup = fixture.createLocal.mock.results[0]!.value
await user.click(screen.getByRole('button', { name: 'Cancel', exact: true }))
await user.click(screen.getByRole('button', { name: 'Cancel' }))
await user.click(screen.getByRole('button', { name: 'Project actions for Harbor' }))
await user.click(screen.getByRole('menuitem', { name: 'New group from project' }))
const successor = screen.getByRole('dialog')
@@ -451,15 +445,12 @@ it('fences an old card New continuation and dialog completion when closed and re
'value',
'Successor group'
)
expect(screen.getByRole('button', { name: 'Create', exact: true })).toHaveProperty(
'disabled',
false
)
expect(screen.getByRole('button', { name: 'Create' })).toHaveProperty('disabled', false)
expect(fixture.moves.map((move) => move.id)).toEqual(['a'])
expect(fixture.localDisk.getRepo('b')?.projectGroupId ?? null).toBeNull()
expect(oldGroup).toBeDefined()
fixture.intercept()
await user.click(screen.getByRole('button', { name: 'Create', exact: true }))
await user.click(screen.getByRole('button', { name: 'Create' }))
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())
expect(fixture.createLocal).toHaveBeenCalledTimes(2)
expect(fixture.createLocal.mock.calls.map(([args]) => args.name)).toEqual([
@@ -487,30 +478,27 @@ it('prevalidates finite original sources before New, keeps create failure in the
act(() =>
useAppStore.setState((state) => ({ repos: state.repos.filter((entry) => entry.id !== 'b') }))
)
await user.click(screen.getByRole('button', { name: 'Create', exact: true }))
await user.click(screen.getByRole('button', { name: 'Create' }))
expect(fixture.createLocal).not.toHaveBeenCalled()
expect(fixture.moves).toEqual([])
expect(feedback).toHaveBeenCalledTimes(1)
expect(screen.getByRole('dialog')).toBeTruthy()
await user.click(screen.getByRole('button', { name: 'Cancel', exact: true }))
await user.click(screen.getByRole('button', { name: 'Cancel' }))
act(() => useAppStore.setState({ repos: fixture.repos }))
fixture.createLocal.mockRejectedValueOnce(new Error('create disconnected'))
await user.click(screen.getByRole('button', { name: 'Project actions for Harbor' }))
await user.click(screen.getByRole('menuitem', { name: 'New group from project' }))
await user.click(screen.getByRole('button', { name: 'Create', exact: true }))
await user.click(screen.getByRole('button', { name: 'Create' }))
await waitFor(() =>
expect(screen.getByRole('button', { name: 'Create', exact: true })).toHaveProperty(
'disabled',
false
)
expect(screen.getByRole('button', { name: 'Create' })).toHaveProperty('disabled', false)
)
await user.click(screen.getByRole('button', { name: 'Create', exact: true }))
await user.click(screen.getByRole('button', { name: 'Create' }))
expect(fixture.createLocal).toHaveBeenCalledTimes(1)
expect(fixture.moves).toEqual([])
await user.click(screen.getByRole('button', { name: 'Cancel', exact: true }))
await user.click(screen.getByRole('button', { name: 'Cancel' }))
await user.click(screen.getByRole('button', { name: 'Project actions for Harbor' }))
await user.click(screen.getByRole('menuitem', { name: 'New group from project' }))
await user.click(screen.getByRole('button', { name: 'Create', exact: true }))
await user.click(screen.getByRole('button', { name: 'Create' }))
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())
expect(fixture.createLocal).toHaveBeenCalledTimes(2)
expect((await fixture.saved()).local[0]?.projectGroupId).toBe(
@@ -13,10 +13,24 @@ import { EMPTY_RETIRED_NAME_REGISTRY } from '../../../../shared/worktree/retired
import { projectHostSetupProjectionFromRepos } from '../../../../shared/project-host-setup-projection'
import { expect, it, vi } from 'vitest'
import type { AppState } from '@/store/types'
import type { Repo } from '../../../../shared/repo-types'
import { useAppStore } from '@/store'
import { getDefaultSettings } from '../../../../shared/constants'
import { getRepoExecutionHostId } from '../../../../shared/execution-host'
import { getRepoExecutionHostId, parseExecutionHostId } from '../../../../shared/execution-host'
import { worktree } from './worktree-list-groups-test-fixtures'
function hasConcreteRepoUpdates(
updates: Parameters<AppState['updateRepo']>[1]
): updates is Parameters<AppState['updateRepo']>[1] & Partial<Repo> {
return (
updates.sourceControlAi !== null &&
updates.externalWorktreeVisibility !== null &&
updates.agentWorktreeVisibility !== null &&
updates.externalWorktreeDiscoverySuppressedAt !== null &&
updates.ghAccount !== null
)
}
it('keeps beta recoverable after its real Keep hidden action through the shipping merged header and one exact recovery list', async () => {
const alpha = {
...local,
@@ -36,6 +50,9 @@ it('keeps beta recoverable after its real Keep hidden action through the shippin
hostId: 'local'
})
const updateRepo = vi.fn<AppState['updateRepo']>(async (id, updates, options) => {
if (!hasConcreteRepoUpdates(updates)) {
throw new Error('This fixture expects concrete repo updates, not clear sentinels')
}
useAppStore.setState((state) => ({
repos: state.repos.map((entry) =>
entry.id === id && getRepoExecutionHostId(entry) === (options?.hostId ?? 'local')
@@ -231,7 +248,11 @@ it('routes the shipping merged Remove Project menu to current Settings scope and
if (repoId === beta.id && failBeta) {
throw new Error('beta host refused')
}
disk.removeProjectForHost({ id: repoId, executionHostId: hostId })
const host = parseExecutionHostId(hostId)
if (!host || host.id !== hostId) {
throw new Error('Expected the original exact execution host')
}
disk.removeProjectForHost({ id: repoId, executionHostId: host.id })
}
)
Object.assign(window, {
@@ -128,7 +128,7 @@ export function useProjectGroupDialogs(args: {
)
const handleSubmitProjectGroupName = useCallback(
async (name: string) => {
async (name: string): Promise<boolean | void> => {
if (!nameDialog) {
return
}
@@ -127,7 +127,10 @@ it.each(['github', 'gitlab'] as const)(
failedCount: 0,
githubUnavailable: false
}))
const count = vi.fn<LandingInput['countWorkItemsAcrossRepos']>(async () => ({ totalPages: 1 }))
const count = vi.fn<LandingInput['countWorkItemsAcrossRepos']>(async () => ({
totalCount: 0,
totalPages: 1
}))
const workItem: GitHubWorkItem = {
id: 'issue:1',
repoId: 'same',
@@ -448,7 +448,7 @@ it.each(['refusal', 'unique', 'absence'] as const)(
expect(f.survivors()).toEqual(['r/x', 'r/y', 'q/y'])
expect(listPendingRuntimeRepoRemovals('E')).toEqual([])
const action = vi.mocked(toast.error).mock.calls.at(-1)?.[1]?.action
if (!action || !('onClick' in action)) {
if (!action || typeof action !== 'object' || !('onClick' in action)) {
throw new Error('real unreachable toast must offer its action')
}
render(createElement('button', { onClick: action.onClick }, action.label))
@@ -82,7 +82,14 @@ it.each(['web', 'mobile', 'old'] as const)(
readonly OPEN: WebSocket['OPEN'] = 1
readyState: WebSocket['readyState'] = 1
bufferedAmount = 0
send = vi.fn<WebSocket['send']>()
send =
vi.fn<
(
data: Parameters<WebSocket['send']>[0],
optionsOrCallback?: Parameters<WebSocket['send']>[1] | Parameters<WebSocket['send']>[2],
callback?: Parameters<WebSocket['send']>[2]
) => void
>()
close = vi.fn<WebSocket['close']>()
}
const Q = 'runtime:server\0same'