Skip to content
Open
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
6 changes: 5 additions & 1 deletion apps/desktop/e2e/workhub-reconstruction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { COMPOSER_INPUT, ensureSidebarExpanded, expect, test } from './fixtures';

test('WorkHub rebuilds Session conversation after navigating away and back', async ({
test('WorkHub rebuilds delegated execution feedback after navigating away and back', async ({
window: page,
}) => {
const initialPrompt = '检查支付回调重复投递时的幂等性';
Expand Down Expand Up @@ -64,6 +64,10 @@ test('WorkHub rebuilds Session conversation after navigating away and back', asy
hasText: routedPrompt,
}),
).toBeVisible();
await expect(
page.locator('.workhub-projected-turn', { hasText: routedPrompt })
.locator('.workhub-submitted-state'),
).toHaveText('进行中');
});

test('WorkHub defers destructive correction until linked delegation exists', async ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,37 @@ test('returns Host-owned cancellation proof to the renderer', async () => {
);
});

test('returns Host-owned Message execution proof to the renderer', async () => {
const ipc = ipcHarness();
registerExecutionIpc(
{
client: executionClient({
queryMessageExecutions: async (input) => ({
resolutions: input.messageIds.map((messageId) => ({
messageId,
state: 'owned' as const,
turnId: 'successor-turn',
runId: 'successor-run',
})),
}),
}),
},
ipc,
);

assert.deepEqual(
await ipc.invoke('sessions:queryMessageExecutions', 'session-1', ['message-delegated']),
{
resolutions: [{
messageId: 'message-delegated',
state: 'owned',
turnId: 'successor-turn',
runId: 'successor-run',
}],
},
);
});

test('submits a slash Skill message and reports the Host Skill outcome', async () => {
const submits: unknown[] = [];
const ipc = ipcHarness();
Expand Down Expand Up @@ -1502,6 +1533,7 @@ function executionClient(overrides: Partial<ExecutionClient>): ExecutionClient {
interruptTurn: unavailable,
listSessionTurnLandmarks: unavailable,
listSessionTurns: unavailable,
queryMessageExecutions: unavailable,
queryMessages: unavailable,
queryTurnResume: unavailable,
readExecutionBoundary: unavailable,
Expand Down
119 changes: 119 additions & 0 deletions apps/desktop/src/main/__tests__/workhub-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
WORKHUB_ROUTING_STRATEGY_ID,
type WorkHubSessionFacts,
type WorkHubSessionPort,
type WorkHubCoordinationTurn,
} from '../../renderer/workhub-controller.js';

const appShellUrl = [
Expand Down Expand Up @@ -76,6 +77,8 @@ function port(sessions: WorkHubSessionFacts[]): WorkHubSessionPort {
return {
list: async () => sessions,
recentTurns: async () => [],
delegationFeedback: async (references) =>
references.map(({ delegationId }) => ({ delegationId, state: 'accepted' })),
routingEvidence: async () => [],
create: async () => {
throw new Error('create is not used by this read test');
Expand All @@ -90,6 +93,122 @@ function port(sessions: WorkHubSessionFacts[]): WorkHubSessionPort {
};
}

function coordinationAssignmentTurn(): WorkHubCoordinationTurn {
return {
messageId: 'assignment-1',
turnId: 'action-1',
text: 'Continue payments',
state: 'completed',
assignment: {
delegationId: 'delegation-1',
targetSessionId: 'payment',
targetSessionName: 'Payments',
targetMessageId: 'payment-message',
targetTurnId: 'payment-turn',
feedbackState: 'accepted',
},
updatedAt: 10,
};
}

test('conversation acknowledges a durable assignment before projecting target execution', async () => {
const sessions = port([session('payment')]);
let onSessionChanged: (() => void) | undefined;
let feedbackState: 'completed' | 'waiting_for_user' = 'completed';
sessions.subscribe = (handler) => {
onSessionChanged = handler;
return () => {
onSessionChanged = undefined;
};
};
sessions.delegationFeedback = async (references) =>
references.map(({ delegationId }) => ({ delegationId, state: feedbackState }));
const assignment = coordinationAssignmentTurn();
const snapshots: string[] = [];
const controller = createGatedWorkHubController({
sessions,
coordination: {
open: async (handler) => {
handler([assignment]);
return { close: async () => undefined };
},
answer: async (input) => ({ turnId: input.turnId }),
record: async (input) => ({ turnId: input.turnId }),
candidates: async () => ({ candidateSetId: `sha256:${'a'.repeat(64)}`, candidates: [] }),
act: async () => ({ disposition: 'answer_here', coordinationTurnId: 'unused' }),
},
});

const handle = await controller.openConversation((turns) => {
snapshots.push(turns[0]?.assignment?.feedbackState ?? 'missing');
}, () => undefined);
await Promise.resolve();

assert.deepEqual(snapshots.slice(0, 2), ['accepted', 'completed']);

feedbackState = 'waiting_for_user';
onSessionChanged?.();
await Promise.resolve();
await Promise.resolve();
assert.equal(snapshots.at(-1), 'waiting_for_user');

await handle.close();
});

test('conversation feedback never lets an older refresh overwrite newer target state', async () => {
const sessions = port([session('payment')]);
let onSessionChanged: (() => void) | undefined;
sessions.subscribe = (handler) => {
onSessionChanged = handler;
return () => undefined;
};
type Feedback = Awaited<ReturnType<WorkHubSessionPort['delegationFeedback']>>;
const pending: Array<{
references: Parameters<WorkHubSessionPort['delegationFeedback']>[0];
resolve(feedback: Feedback): void;
}> = [];
sessions.delegationFeedback = (references) =>
new Promise((resolve) => pending.push({ references, resolve }));
const snapshots: string[] = [];
const controller = createGatedWorkHubController({
sessions,
coordination: {
open: async (handler) => {
handler([coordinationAssignmentTurn()]);
return { close: async () => undefined };
},
answer: async (input) => ({ turnId: input.turnId }),
record: async (input) => ({ turnId: input.turnId }),
candidates: async () => ({ candidateSetId: `sha256:${'b'.repeat(64)}`, candidates: [] }),
act: async () => ({ disposition: 'answer_here', coordinationTurnId: 'unused' }),
},
});

const handle = await controller.openConversation((turns) => {
snapshots.push(turns[0]?.assignment?.feedbackState ?? 'missing');
}, () => undefined);
assert.equal(pending.length, 1);
onSessionChanged?.();
assert.equal(pending.length, 2);

pending[1]!.resolve(pending[1]!.references.map(({ delegationId }) => ({
delegationId,
state: 'completed',
})));
await Promise.resolve();
await Promise.resolve();
pending[0]!.resolve(pending[0]!.references.map(({ delegationId }) => ({
delegationId,
state: 'failed',
})));
await Promise.resolve();
await Promise.resolve();

assert.equal(snapshots.at(-1), 'completed');
assert.equal(snapshots.includes('failed'), false);
await handle.close();
});

test('read exposes existing ordinary Sessions as factual Work summaries', async () => {
const controller = createWorkHubController({
sessions: port([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ test('WorkHub candidates follow the resolved Coordination Session Host only', as
completeHostIds: ['host-a', 'host-b'],
}),
listTurns: async () => [],
queryMessageExecutions: async () => ({ resolutions: [] }),
create: async () => {
throw new Error('unscoped create must not be used');
},
Expand Down
Loading