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。

fix(voice): 启动语音时立即保护提问答案与导航

Dashe63e1fd3a31f
diff --git a/apps/mobile/src/__tests__/InteractionPanelReceipt.test.tsx b/apps/mobile/src/__tests__/InteractionPanelReceipt.test.tsx
index f9ca6d99d1..79cbba9cd5 100644
--- a/apps/mobile/src/__tests__/InteractionPanelReceipt.test.tsx
+++ b/apps/mobile/src/__tests__/InteractionPanelReceipt.test.tsx
@@ -64,11 +64,11 @@ vi.mock('react-native', async () => {
vi.mock('@/components/AppText', async () => {
const { createElement } = await import('react');
return { Text: (await import('react-native')).Text,
- TextInput: ({ value, onChangeText, testID, multiline }: {
- value: string; onChangeText: (value: string) => void; testID: string; multiline?: boolean;
+ TextInput: ({ value, onChangeText, testID, multiline, editable }: {
+ value: string; onChangeText: (value: string) => void; testID: string; multiline?: boolean; editable?: boolean;
}) => createElement(multiline ? 'textarea' : 'input', { value, 'data-testid': testID,
onInput: (event: { currentTarget: HTMLInputElement }) => onChangeText(event.currentTarget.value),
- readOnly: true }),
+ readOnly: editable === false }),
};
});
vi.mock('lucide-react-native', () => ({ ShieldCheck: () => null, MessageCircle: () => null, ChevronDown: () => null, ChevronUp: () => null, Check: () => null, CornerDownLeft: () => null,
@@ -210,6 +210,55 @@ it.each(['free', 'custom', 'multi', 'failed', 'removed', 'connecting', 'connecti
},
);
+// PR #7017 review: no PCM has arrived yet, so the old hook left editing and
+// navigation enabled while Send awaited startup. Exercise actual card actions,
+// then resolve startup and verify the original answer/question is submitted.
+it.each(['options', 'previous'])('protects the answer while submitting before the first audio chunk: %s', async (action) => {
+ let connect!: () => void;
+ const stop = vi.fn();
+ startDictation.mockImplementation(async (input: { setText: (text: string) => void }) => {
+ stop.mockImplementation(async () => input.setText('Final answer'));
+ await new Promise<void>((resolve) => { connect = resolve; });
+ return { stop, cancel: vi.fn(async () => undefined) };
+ });
+ remoteSessionStore.setPendingInteractions('s1', [{ request: {
+ kind: 'ask_user_question', requestId, questions: [
+ ...(action === 'previous' ? [{ question: 'First?', multiSelect: true, options: [{ label: 'X' }, { label: 'Y' }] }] : []),
+ { question: 'Current?', multiSelect: true, options: [{ label: 'A' }, { label: 'B' }] },
+ ],
+ } }]);
+ resolveInteraction.mockResolvedValue({ accepted: true });
+ await act(async () => root.render(
+ <AskCardAuthContext.Provider value={{ getAccessToken: async () => 'test', refreshAccessToken: async () => 'test', apiFetch: async () => ({}) }}>
+ <Harness />
+ </AskCardAuthContext.Provider>,
+ ));
+ if (action === 'previous') {
+ await click('interaction.ask.option.1');
+ await click('interaction.ask.submitButton');
+ }
+ await click('interaction.ask.option.1');
+ await click('interaction.ask.voice');
+ await click('interaction.ask.submitButton');
+ expect(resolveInteraction).not.toHaveBeenCalled();
+ expect(stop).not.toHaveBeenCalled();
+ expect(host.querySelector<HTMLInputElement>('[data-testid="interaction.ask.customInput"]')!.readOnly).toBe(true);
+ for (const id of ['interaction.ask.option.2', 'interaction.ask.skipButton',
+ ...(action === 'previous' ? ['interaction.ask.previousButton'] : [])]) {
+ expect(host.querySelector<HTMLButtonElement>(`[data-testid="${id}"]`)!.disabled).toBe(true);
+ await click(id);
+ }
+ expect(host.querySelector('[data-testid="interaction.ask.question"]')!.textContent).toBe('Current?');
+ expect(readAskUserDraft(requestId)?.selectedLabels).toEqual(['A']);
+ await act(async () => connect());
+ expect(resolveInteraction).toHaveBeenCalledExactlyOnceWith(requestId, {
+ kind: 'ask_user_question', answers: {
+ ...(action === 'previous' ? { 'First?': '["X"]' } : {}),
+ 'Current?': '["A","Final answer"]',
+ },
+ });
+});
+
// Unit regression for PR #6306 review: a signed-out microphone tap used to
// render hardcoded Chinese. Existing receipt tests never tapped this entry.
// Exercise the real card and hook in each supported locale, without auth.
diff --git a/apps/mobile/src/session/InteractionPanel.tsx b/apps/mobile/src/session/InteractionPanel.tsx
index 58204fd66a..214417a793 100644
--- a/apps/mobile/src/session/InteractionPanel.tsx
+++ b/apps/mobile/src/session/InteractionPanel.tsx
@@ -1303,7 +1303,7 @@ function AskUserQuestionForm({
<View style={[styles.customInputRow, { gap: touchLayout.actionGap }]}>
<InteractionTouchButton
accessibilityLabel={t('interaction.panel.customAnswerPlaceholder')}
- disabled={busy}
+ disabled={busy || voice.listening}
onPress={() => {
if (!isMulti) {
clearCurrentAnswer();
diff --git a/apps/mobile/src/session/useAskCardVoice.ts b/apps/mobile/src/session/useAskCardVoice.ts
index 75f6953f7b..568fbfcfd2 100644
--- a/apps/mobile/src/session/useAskCardVoice.ts
+++ b/apps/mobile/src/session/useAskCardVoice.ts
@@ -104,6 +104,9 @@ export function useAskCardVoice(input: {
return;
}
startingRef.current = true;
+ // The answer belongs to this take from the initial tap, including startup
+ // before the first PCM chunk. Keep edits/navigation frozen until it settles.
+ setListening(true);
setError(null);
const abort = new AbortController();
startAbortRef.current = abort;