Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/web-ui/AGENTS-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ pnpm --dir src/web-ui run test:run src/app/layout/useNavResize.test.tsx src/app/

这些本地 DOM 测试覆盖手势状态和弹簧收敛,不代表原生 WebView 渲染或真实远程场景验证。

远端工作区状态核对与 ACP 能力缓存失效使用以下聚焦检查:

```bash
pnpm --dir src/web-ui run test:run src/features/ssh-remote/SSHRemoteProvider.test.tsx src/infrastructure/api/service-api/ACPClientAPI.test.ts src/app/components/NavPanel/sections/workspaces/workspaceAcpMenuClients.test.ts src/app/components/NavPanel/sections/workspaces/workspaceAcpMenuClients.integration.test.ts
```

这些测试覆盖空闲元数据更新、连接恢复、显式激活、并发改绑与关闭、部分工作区恢复失败、
配置失效、菜单探测反馈循环和模拟 Peer
设备切换,不代表真实 SSH、远程控制或离线派发验证。编辑器轮询检查见
`src/tools/editor/AGENTS.md`。

编辑/回滚结果、旧版本被控端响应与延迟记录重放使用以下聚焦检查:

```bash
Expand Down
12 changes: 12 additions & 0 deletions src/web-ui/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,18 @@ credential-only retries, custom container values, search clearing, independent a
numeric bounds, and focus ownership; DOM assertions do not establish native
rendering or live connections.

For remote workspace reconciliation and ACP requirement cache invalidation:

```bash
pnpm --dir src/web-ui run test:run src/features/ssh-remote/SSHRemoteProvider.test.tsx src/infrastructure/api/service-api/ACPClientAPI.test.ts src/app/components/NavPanel/sections/workspaces/workspaceAcpMenuClients.test.ts src/app/components/NavPanel/sections/workspaces/workspaceAcpMenuClients.integration.test.ts
```

These fixtures cover idle metadata updates, live-status recovery, explicit
activation, concurrent binding changes/closure, partial restore failures,
config invalidation, menu probe feedback, and simulated Peer surface changes.
They do not establish live SSH, Remote Control or Detached
Dispatch behavior. Editor polling checks belong in `src/tools/editor/AGENTS.md`.

For conversation selection and the floating annotation editor (placement,
dragging, resizing, draft retention, and nonmodal interaction):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,37 +503,42 @@ const WorkspaceItem: React.FC<WorkspaceItemProps> = ({
}

let cancelled = false;
let requestId = 0;
const remoteWorkspace = isRemoteWorkspace(workspace);

const loadAcpClients = async () => {
const loadAcpClients = async (refreshIfMissing = true) => {
const request = ++requestId;
setAcpClients([]);
setAcpClientsLoading(true);
try {
const clients = await loadWorkspaceAcpMenuClients({
remoteWorkspace,
remoteConnectionId: remoteWorkspace ? workspace.connectionId : undefined,
refreshIfMissing,
});
if (!cancelled) {
if (!cancelled && request === requestId) {
setAcpClients(clients);
}
} catch (_error) {
if (!cancelled) {
if (!cancelled && request === requestId) {
setAcpClients([]);
}
} finally {
if (!cancelled) {
if (!cancelled && request === requestId) {
setAcpClientsLoading(false);
}
}
};

const onClientsChanged = () => { void loadAcpClients(); };
const onRequirementsChanged = () => { void loadAcpClients(false); };
void loadAcpClients();
window.addEventListener('openbitfun:acp-clients-changed', loadAcpClients);
window.addEventListener('openbitfun:acp-requirements-changed', loadAcpClients);
window.addEventListener('openbitfun:acp-clients-changed', onClientsChanged);
window.addEventListener('openbitfun:acp-requirements-changed', onRequirementsChanged);
return () => {
cancelled = true;
window.removeEventListener('openbitfun:acp-clients-changed', loadAcpClients);
window.removeEventListener('openbitfun:acp-requirements-changed', loadAcpClients);
window.removeEventListener('openbitfun:acp-clients-changed', onClientsChanged);
window.removeEventListener('openbitfun:acp-requirements-changed', onRequirementsChanged);
};
}, [menuOpen, workspace]);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// @vitest-environment jsdom
import { beforeEach, expect, it, vi } from 'vitest';
import { activateSurface } from '@/infrastructure/peer-device/deviceSurface';
import { loadWorkspaceAcpMenuClients } from './workspaceAcpMenuClients';

const invoke = vi.hoisted(() => vi.fn());
vi.mock('@/infrastructure/api/service-api/ApiClient', () => ({ api: { invoke } }));

beforeEach(() => {
activateSurface('local');
invoke.mockReset();
});

it('settles an empty remote menu without a probe-completion feedback loop', async () => {
let probes = 0;
invoke.mockImplementation(async command => {
if (command === 'get_acp_clients') return [{ id: 'codex', enabled: true }];
if (command === 'probe_acp_client_requirements') {
// Bound a broken fixture so the assertion reports the feedback loop.
if (++probes > 4) throw new Error('Probe completion restarted probing');
return [];
}
throw new Error(`Unexpected command: ${command}`);
});
const options = { remoteWorkspace: true, remoteConnectionId: 'ssh-empty' };
const loads: Promise<unknown>[] = [];
const onCompletion = () => {
loads.push(loadWorkspaceAcpMenuClients({ ...options, refreshIfMissing: false }).catch(error => error));
};
window.addEventListener('openbitfun:acp-requirements-changed', onCompletion);
try {
const initial = loadWorkspaceAcpMenuClients(options);
await initial;
for (let index = 0; index < 30; index += 1) await Promise.resolve();
await Promise.all(loads);
expect(probes).toBe(2); // One cached-snapshot read and one live probe.
expect(await initial).toEqual([]);
} finally {
window.removeEventListener('openbitfun:acp-requirements-changed', onCompletion);
}
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { ACPClientAPI } from '@/infrastructure/api/service-api/ACPClientAPI';
import { loadWorkspaceAcpMenuClients } from './workspaceAcpMenuClients';
import { activateSurface } from '@/infrastructure/peer-device/deviceSurface';

vi.mock('@/infrastructure/api/service-api/ACPClientAPI', () => ({
ACPClientAPI: {
Expand All @@ -27,6 +28,7 @@ function client(id: string, enabled: boolean) {
describe('loadWorkspaceAcpMenuClients', () => {
beforeEach(() => {
vi.resetAllMocks();
activateSurface('local');
});

it('does not probe external ACP executables while loading workspace menu clients', async () => {
Expand Down Expand Up @@ -155,4 +157,18 @@ describe('loadWorkspaceAcpMenuClients', () => {
});
expect(clients.map(item => item.id)).toEqual(['codex']);
});

it('refreshes negative snapshots again after the same connection ID moves to another device', async () => {
vi.mocked(ACPClientAPI.getClients).mockResolvedValue([client('codex', true)]);
vi.mocked(ACPClientAPI.probeClientRequirements).mockResolvedValue([
{ id: 'codex', tool: { name: 'codex', installed: false }, runnable: false, notes: [] },
]);
const options = { remoteWorkspace: true, remoteConnectionId: 'same-id' };
await loadWorkspaceAcpMenuClients(options);
await loadWorkspaceAcpMenuClients(options);
expect(vi.mocked(ACPClientAPI.probeClientRequirements).mock.calls.filter(([options]) => options?.force)).toHaveLength(1);
activateSurface('peer-b');
await loadWorkspaceAcpMenuClients(options);
expect(vi.mocked(ACPClientAPI.probeClientRequirements).mock.calls.filter(([options]) => options?.force)).toHaveLength(2);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,28 @@ import {
ACPClientAPI,
type AcpClientInfo,
} from '@/infrastructure/api/service-api/ACPClientAPI';
import { getActiveSurfaceScope } from '@/infrastructure/peer-device/deviceSurface';

interface LoadWorkspaceAcpMenuClientsOptions {
remoteWorkspace?: boolean;
remoteConnectionId?: string;
/** Completion events consume the new snapshot without starting another probe. */
refreshIfMissing?: boolean;
}

const forcedRemoteRequirementRefreshes = new Set<string>();
let refreshEpoch = -1;

export async function loadWorkspaceAcpMenuClients(
options: LoadWorkspaceAcpMenuClientsOptions = {}
): Promise<AcpClientInfo[]> {
const scope = getActiveSurfaceScope();
if (refreshEpoch !== scope.epoch) {
refreshEpoch = scope.epoch;
forcedRemoteRequirementRefreshes.clear();
}
const clients = await ACPClientAPI.getClients();
scope.assertCurrent('load workspace ACP menu');

if (!options.remoteWorkspace) {
return clients.filter(client => client.enabled);
Expand All @@ -31,22 +41,19 @@ export async function loadWorkspaceAcpMenuClients(
let probes = await ACPClientAPI.probeClientRequirements({
remoteConnectionId: options.remoteConnectionId,
});
if (probes.length === 0) {
probes = await ACPClientAPI.probeClientRequirements({
remoteConnectionId: options.remoteConnectionId,
force: true,
});
}
scope.assertCurrent('load workspace ACP requirements');
let visibleClients = filterRunnableClients(enabledClients, probes);
if (
options.refreshIfMissing !== false &&
visibleClients.length === 0 &&
!forcedRemoteRequirementRefreshes.has(options.remoteConnectionId)
(probes.length === 0 || !forcedRemoteRequirementRefreshes.has(options.remoteConnectionId))
) {
forcedRemoteRequirementRefreshes.add(options.remoteConnectionId);
probes = await ACPClientAPI.probeClientRequirements({
remoteConnectionId: options.remoteConnectionId,
force: true,
});
scope.assertCurrent('refresh workspace ACP requirements');
visibleClients = filterRunnableClients(enabledClients, probes);
}
return visibleClients;
Expand Down
Loading
Loading