Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

test(desktop): cover pending handoff step reminders

guyong69234f53adc6
diff --git a/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts b/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts
index 56beaa72d9..22ce90cc9c 100644
--- a/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts
+++ b/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts
@@ -447,6 +447,34 @@ describe('getRunningSnapshot pending request identity', () => {
makerChatStore.purgeSession(sessionId);
}
});
+
+ it('publishes a new handoff step without a pending-state transition', () => {
+ // #3259: the same request stays pending through multiple owner-input steps.
+ const sessionId = 'pending-handoff-step';
+ const handoff = (stepNumber: number, revision: number): void => {
+ makerChatStore.__applyInputHandoffRequestForTest(sessionId, {
+ kind: 'input_handoff', requestId: 'same-request', revision,
+ phase: 'ready', purpose: 'Sign in', source: { app: 'Test' },
+ stepNumber, controls: [],
+ });
+ };
+ try {
+ handoff(1, 1);
+ const first = makerChatStore.getRunningSnapshot();
+ expect(first.get(sessionId)?.pendingRequestKeys).toEqual(['handoff:same-request:1']);
+
+ handoff(1, 2);
+ expect(makerChatStore.getRunningSnapshot()).toBe(first);
+
+ handoff(2, 3);
+ const second = makerChatStore.getRunningSnapshot();
+ expect(second).not.toBe(first);
+ expect(second.get(sessionId)?.hasPendingInputHandoff).toBe(true);
+ expect(second.get(sessionId)?.pendingRequestKeys).toEqual(['handoff:same-request:2']);
+ } finally {
+ makerChatStore.purgeSession(sessionId);
+ }
+ });
});
describe('getRunningSnapshot 后台 subagent 折算(真 store)', () => {
diff --git a/apps/desktop/src/renderer/__tests__/useSessionRunningStatusSilence.test.ts b/apps/desktop/src/renderer/__tests__/useSessionRunningStatusSilence.test.ts
index 0e84ddd17e..0068930b07 100644
--- a/apps/desktop/src/renderer/__tests__/useSessionRunningStatusSilence.test.ts
+++ b/apps/desktop/src/renderer/__tests__/useSessionRunningStatusSilence.test.ts
@@ -662,6 +662,33 @@ describe('useSessionRunningStatus silenced completion handling', () => {
expect(addSessionAttention).not.toHaveBeenCalledWith('s-remount', 'awaiting');
});
+ it('alerts on the next handoff step after remount without repeating the current step', async () => {
+ // #3259: a new owner-input step needs a fresh reminder even while pending stays true.
+ setDataOwnerGeneration('handoff-owner');
+ const onSessionNeedsReply = vi.fn();
+ const first = renderHook(() => useSessionRunningStatus(undefined, { onSessionNeedsReply }));
+ const handoffStatus = (step: number): SessionStatusInfo => ({
+ ...status(false), hasPendingInputHandoff: true,
+ pendingRequestKeys: [`handoff:same-request:${step}`],
+ });
+
+ await emitSnapshot(new Map([['s-handoff', handoffStatus(1)]]));
+ expect(onSessionNeedsReply).toHaveBeenCalledExactlyOnceWith('s-handoff');
+ first.result.current.clearNotification('s-handoff');
+ first.unmount();
+ vi.mocked(addSessionAttention).mockClear();
+
+ renderHook(() => useSessionRunningStatus(undefined, { onSessionNeedsReply }));
+ expect(onSessionNeedsReply).toHaveBeenCalledTimes(1);
+ expect(addSessionAttention).not.toHaveBeenCalledWith('s-handoff', 'awaiting');
+
+ await emitSnapshot(new Map([['s-handoff', handoffStatus(2)]]));
+ expect(onSessionNeedsReply).toHaveBeenCalledTimes(2);
+ expect(addSessionAttention).toHaveBeenCalledWith('s-handoff', 'awaiting');
+ await emitSnapshot(new Map([['s-handoff', handoffStatus(2)]]));
+ expect(onSessionNeedsReply).toHaveBeenCalledTimes(2);
+ });
+
it('alerts for a different request while the sidebar is hidden, then again for a new owner', async () => {
setDataOwnerGeneration('first-owner');
const onSessionNeedsReply = vi.fn();
diff --git a/apps/desktop/src/renderer/lib/makerChatStore.ts b/apps/desktop/src/renderer/lib/makerChatStore.ts
index 4978578dc4..4efa00ed4c 100644
--- a/apps/desktop/src/renderer/lib/makerChatStore.ts
+++ b/apps/desktop/src/renderer/lib/makerChatStore.ts
@@ -8637,13 +8637,7 @@ function initGlobalListeners(options: GlobalListenerOptions = {}): void {
}
if (request.kind === 'input_handoff') {
- const parsed = parsePendingInputHandoff(request);
- if (!parsed) return;
- setState(sessionId, (s) => {
- const current = s.pendingInputHandoff;
- if (current?.requestId === parsed.requestId && parsed.revision < current.revision) return s;
- return { ...s, pendingInputHandoff: parsed };
- });
+ applyInputHandoffInteractionRequest(sessionId, request);
return;
}
@@ -10199,6 +10193,16 @@ function pendingRequestKeys(state: SessionChatState): string[] {
return keys.sort();
}
+function applyInputHandoffInteractionRequest(sessionId: string, raw: unknown): void {
+ const parsed = parsePendingInputHandoff(raw);
+ if (!parsed) return;
+ setState(sessionId, (state) => {
+ const current = state.pendingInputHandoff;
+ if (current?.requestId === parsed.requestId && parsed.revision < current.revision) return state;
+ return { ...state, pendingInputHandoff: parsed };
+ });
+}
+
function samePendingRequestKeys(
left: readonly string[] | undefined,
right: readonly string[] | undefined,
@@ -18648,6 +18652,8 @@ export const makerChatStore = {
setState(sessionId, (s) => handleStreamEvent(s, event));
scheduleWakeBridgeReconciliation(sessionId);
},
+ /** Exposed for tests only: use the same request path as the live interaction handler. */
+ __applyInputHandoffRequestForTest: applyInputHandoffInteractionRequest,
/** Exposed for tests only: 把 status update 打进真实 store。 */
__applyStatusUpdateForTest: (sessionId: string, update: CCAgentStatusUpdate): void => {
if (!isTurnContinuationBoundaryEvent(update) && !update.skipTurnReset && !update.isRunning) {