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
33 changes: 24 additions & 9 deletions apps/desktop/src/main/__tests__/workhub-anchor-rail.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,23 @@ import {
matchesWorkHubFilter,
MAX_WORKHUB_ANCHORS,
WorkHubNavigationRail,
WorkHubResultCard,
workHubLinkedWork,
workHubTurnResultPreview,
} from "../../renderer/features/workhub/index.js";
import { ChatSurfaceLayout, LocaleProvider } from '@maka/ui';
import { WorkHubConversation, WorkHubDelegationStatus } from '../../renderer/features/workhub/testing.js';
import { getWorkHubRailCopy } from "../../renderer/locales/workhub-copy.js";
import type { ToolCallMessage, ToolResultMessage } from '@maka/core/session';

test('durable task results restore Host-scoped work links without treating failed or unrelated tools as delegations', () => {
const target = JSON.stringify(['host-a', 'task-a']);
const call: ToolCallMessage = { type: 'tool_call', id: 'task-call', turnId: 'turn', ts: 1, toolName: 'mcp__desktop_workhub__tasks', args: {} };
const result: ToolResultMessage = { type: 'tool_result', id: 'task-result', turnId: 'turn', ts: 2, toolUseId: call.id, isError: false, content: { kind: 'json', value: { disposition: 'create_new', targetSessionKey: target } } };
const expected = [{ id: result.id, coordinationTurnId: call.turnId, targetSessionId: target, targetSessionName: 'Renamed task' }];
const expected = [{ id: result.id, coordinationTurnId: call.turnId, targetSessionId: target, targetSessionName: 'Renamed task', workspaceName: undefined }];
assert.deepEqual(workHubLinkedWork([call, result], [{ id: target, name: 'Renamed task' }], 'Work'), expected);
for (const cwd of ['/projects/payments/', 'C:\\projects\\payments\\']) {
assert.deepEqual(workHubLinkedWork([call, result], [{ id: target, name: 'Renamed task', cwd }], 'Work'), [{ ...expected[0], workspaceName: 'payments' }]);
}
assert.deepEqual(workHubLinkedWork([call, { ...result, content: { kind: 'json', value: { content: [], structuredContent: { disposition: 'create_new', targetSessionKey: target } } } }], [{ id: target, name: 'Renamed task' }], 'Work'), expected);
assert.deepEqual(workHubLinkedWork([call, { ...result, content: { kind: 'text', text: JSON.stringify({ disposition: 'delegate_existing', targetSessionKey: target }) } }], [], 'Work'), [{ ...expected[0], targetSessionName: 'Work' }]);
assert.deepEqual(workHubLinkedWork([
Expand All @@ -50,9 +54,9 @@ test('durable task results restore Host-scoped work links without treating faile
], [], 'Work'), []);
});

test('a completed delegation returns its bounded result in the WorkHub conversation', () => {
test('a completed delegation renders only its status beside the prompt timestamp', () => {
const target = JSON.stringify(['host-a', 'task-a']);
const markup = renderToStaticMarkup(createElement(WorkHubResultCard, {
const markup = renderToStaticMarkup(createElement(WorkHubDelegationStatus, {
work: {
id: 'delegation-record',
coordinationTurnId: 'coordination-turn',
Expand All @@ -64,14 +68,10 @@ test('a completed delegation returns its bounded result in the WorkHub conversat
resultPreview: 'All release checks passed. The report is ready.',
},
locale: 'en',
highlighted: false,
onHighlight: () => undefined,
onOpenWork: () => undefined,
}));

assert.match(markup, /Completed/u);
assert.match(markup, /All release checks passed\. The report is ready\./u);
assert.match(markup, /Open result/u);
assert.doesNotMatch(markup, /All release checks|Open result/u);
});

test('delegated result previews select the exact Turn and stay character-bounded', () => {
Expand Down Expand Up @@ -186,3 +186,18 @@ test("focus display is derived from the selected Session ID, not delegation prio
assert.equal(markup.match(/aria-current="page"/gu)?.length, 1);
assert.equal(markup.match(/Focused · Running/gu)?.length, 1);
});


test('a shared coordination turn keeps every Work label without assigning one Work color to the whole turn', () => {
const markup = renderToStaticMarkup(createElement(LocaleProvider, { locale: 'en', children: null },
createElement(ChatSurfaceLayout, { composer: null, children: null }, createElement(WorkHubConversation, {
activeSession: { id: 'coordination', name: 'WorkHub', status: 'active', labels: [], isFlagged: false, isArchived: false, hasUnread: false, backend: 'ai-sdk', llmConnectionSlug: 'test', connectionLocked: false, model: 'test', permissionMode: 'ask' },
messages: [{ type: 'user', id: 'user', turnId: 'shared', text: 'Do both tasks', ts: 1 }],
scrollBehavior: 'auto', onNew: () => {}, onOpenWork: () => {},
workLinks: ['Alpha', 'Beta'].map((name) => ({ id: name, coordinationTurnId: 'shared', targetSessionId: name, targetSessionName: name, workspaceName: 'Workspace' })),
})),
));
assert.match(markup, /Workspace \/ Alpha/);
assert.match(markup, /Workspace \/ Beta/);
assert.doesNotMatch(markup, /data-turn-accent/);
});
10 changes: 7 additions & 3 deletions apps/desktop/src/main/__tests__/workhub-send-visibility.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ async function mountController(failFirstRead = false) {
updateQueueEntry: async (...input: Parameters<WorkHubServices['updateQueueEntry']>) => { queueMutations.push(['update', ...input]); },
reorderQueueEntries: async (...input: Parameters<WorkHubServices['reorderQueueEntries']>) => { queueMutations.push(['reorder', ...input]); },
enqueueMessage: async (...input: Parameters<WorkHubServices['enqueueMessage']>) => { steers.push(input); onSteer?.(input); return steerResult; },
listActiveInteractions: async () => [],
subscribeActiveInteractions: () => () => {},
respondToUserQuestion: async () => {},
answer: (_id: string, input: Parameters<WorkHubServices['answer']>[1]) => invoke('workhub:answer', input),
stop: async (target: string, turnId: string) => {
const result = await invoke('sessions:stop', target, { source: 'stop_button', expectedTurnId: turnId }) as DesktopSessionStopResult;
Expand Down Expand Up @@ -176,19 +179,20 @@ test('WorkHub shows the submitted prompt before admission and keeps it until its
h.latestRead.resolve();
});

test('WorkHub removes a failed submission from the conversation and preserves its retry identity', async () => {
test('WorkHub marks a failed submission and preserves its retry identity', async () => {
const h = await mountController();
let sent!: Promise<boolean>;
await act(async () => { sent = h.controller.send('retry this prompt', []); });
const turnId = h.requests[0]!.turnId;
await act(async () => { h.admission.reject(new Error('admission rejected')); assert.equal(await sent, false); });
assert.equal(h.controller.transientMessages.length, 0);
assert.equal(h.controller.transientMessages.length, 1);
assert.equal(h.controller.turnStates[turnId], 'failed');
assert.equal(h.controller.error, 'admission rejected');
assert.equal(h.controller.liveTurn, undefined, 'rejected admission retires the waiting feedback');
assert.equal(h.controller.busy, false);
await act(async () => { assert.equal(await h.controller.send('retry this prompt', []), false); });
assert.equal(h.requests[1]!.turnId, turnId);
assert.equal(h.controller.transientMessages.length, 0);
assert.equal(h.controller.transientMessages.length, 1);
h.latestRead.resolve();
});

Expand Down
5 changes: 4 additions & 1 deletion apps/desktop/src/main/runtime-host-workhub-ipc-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ export function registerRuntimeHostWorkHubIpc(
});
const submit = async (attempt: Attempt): Promise<WorkHubAnswerResult> => {
const { originHostEpoch: _originHostEpoch, ...input } = attempt;
return { kind: 'admitted', ...await client.answerWorkHubCoordination(input) };
const result = await client.answerWorkHubCoordination(input);
return result.targetSelection
? { kind: 'selection_required', turnId: result.turnId, request: result.targetSelection }
: { kind: 'admitted', turnId: result.turnId };
};
const reconcile = async (attempt: Attempt): Promise<WorkHubAnswerResult> => {
try {
Expand Down
5 changes: 3 additions & 2 deletions apps/desktop/src/preload/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2042,10 +2042,11 @@ const makaBridge = {
},
async answer(coordinationSessionId: string, input: WorkHubAnswerInput) {
const scope = await resolveDesktopWorkHubCoordinationCreateScope(coordinationSessionId, runtimeHostSessionRef);
return ipcRenderer.invoke('workhub:answer', scope, {
const result = await ipcRenderer.invoke('workhub:answer', scope, {
...input,
...(input.attachments ? { attachments: hostAttachmentRefs({ scope, sessionId: parseDesktopSessionKey(coordinationSessionId).sessionId }, input.attachments) } : {}),
}) as Promise<WorkHubAnswerResult>;
}) as WorkHubAnswerResult;
return result.kind === 'selection_required' ? { ...result, request: { ...result.request, candidates: result.request.candidates.map((candidate) => ({ ...candidate, sessionId: recordRuntimeHostSessionScope(scope, candidate.sessionId) })) } } : result;
},
async configureModel(coordinationSessionId: string, input: OperationInput<'workhub.coordination.configureModel'>) {
const scope = await resolveDesktopWorkHubCoordinationCreateScope(coordinationSessionId, runtimeHostSessionRef);
Expand Down
Loading
Loading