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(mobile): reset question file verification on reference changes

Lizi599f554d6e47
diff --git a/apps/mobile/src/__tests__/InteractionPanelReceipt.test.tsx b/apps/mobile/src/__tests__/InteractionPanelReceipt.test.tsx
index 77dd99cfcb..7f3193d09e 100644
--- a/apps/mobile/src/__tests__/InteractionPanelReceipt.test.tsx
+++ b/apps/mobile/src/__tests__/InteractionPanelReceipt.test.tsx
@@ -1,5 +1,5 @@
// @vitest-environment jsdom
-import { act, useState, type ReactNode } from 'react';
+import { act, useLayoutEffect, useState, type ReactNode } from 'react';
import { createRoot, type Root } from 'react-dom/client';
import { afterEach, beforeEach, expect, it, vi } from 'vitest';
import { sharedTaskHostPeer } from '@cindy/device-link';
@@ -9,7 +9,8 @@ import { InteractionPanel, PluginSetupMessageContent } from '@/session/Interacti
import { remoteSessionStore, useSessionPendingInteractions } from '@/session/remoteSessionStore';
import { clearAllInteractionDrafts, readAskUserDraft, readPlanReviewDraft } from '@/session/interactionDraftStore';
import { forwardNavigationLock } from '@/utils/navigationLock';
-import type { ChatFilePathContextValue } from '@/session/chatFilePathContext';
+import { ChatFilePathContext, type ChatFilePathContextValue } from '@/session/chatFilePathContext';
+import { QuestionReferenceText } from '@/session/QuestionReferenceText';
import { _clearRemotePathVerdictCache } from '@/session/remotePathVerdict';
const evidence = vi.hoisted(() => ({ openURL: vi.fn() }));
@@ -142,6 +143,34 @@ it('opens question files on the controlled computer and URLs without resolving t
expect(host.querySelector('[data-testid="interaction.ask.card"]')).not.toBeNull();
});
+// Unit: a new question must not borrow the last file's verified state. The
+// existing click test never changed the href at a retained span index. Inspect
+// the first committed frame before passive effects can clear the stale verdict.
+it('keeps a changed question reference unclickable until its own verification', async () => {
+ const onOpenPath = vi.fn();
+ const fileContext: ChatFilePathContextValue = {
+ deviceId: 'd1', sessionId: 's1', workdir: '/repo', onOpenPath,
+ statPath: vi.fn((absPath: string) => absPath.endsWith('present.html')
+ ? Promise.resolve({ kind: 'file' as const, resolvedPath: absPath })
+ : new Promise<never>(() => {})),
+ };
+ const changedFrame: boolean[] = [];
+ function ReferenceFrame({ text }: { text: string }) {
+ useLayoutEffect(() => {
+ if (text !== 'missing.html') return;
+ const chip = host.querySelector<HTMLElement>('[data-testid="message.markdownPathChip"]');
+ changedFrame.push(!!chip);
+ chip?.click();
+ }, [text]);
+ return <ChatFilePathContext.Provider value={fileContext}><QuestionReferenceText text={text} /></ChatFilePathContext.Provider>;
+ }
+ await act(async () => root.render(<ReferenceFrame text="present.html" />));
+ expect(host.querySelector('[data-testid="message.markdownPathChip"]')).not.toBeNull();
+ await act(async () => root.render(<ReferenceFrame text="missing.html" />));
+ expect(changedFrame).toEqual([false]);
+ expect(onOpenPath).not.toHaveBeenCalled();
+});
+
it.each(['push-first', 'receipt-first', 'lost-receipt', 'other-client'] as const)(
'finalizes retained answers without stale snapshot resurrection: %s',
async (order) => {
diff --git a/apps/mobile/src/session/QuestionReferenceText.tsx b/apps/mobile/src/session/QuestionReferenceText.tsx
index 2e505102b4..b9a422311a 100644
--- a/apps/mobile/src/session/QuestionReferenceText.tsx
+++ b/apps/mobile/src/session/QuestionReferenceText.tsx
@@ -1,12 +1,14 @@
-import { Fragment, useState } from 'react';
+import { Fragment, useContext, useState } from 'react';
import { Linking } from 'react-native';
import { Text } from '@/components/AppText';
import { splitQuestionReferences } from '@cindy/maker-shared/interaction';
import { ChatPathChipSpan } from '@/session/ChatPathChipSpan';
import { classifyChatPathLinkTarget } from '@/session/chatPathCandidate';
+import { ChatFilePathContext } from '@/session/chatFilePathContext';
/** Inline evidence inherits question typography; only verified links are underlined. */
export function QuestionReferenceText({ text }: { text: string }) {
+ const fileContext = useContext(ChatFilePathContext);
return <>{splitQuestionReferences(text).map((part, index) => {
if (!part.href) return <Fragment key={index}>{part.text}</Fragment>;
if (/^https?:\/\//i.test(part.href)) {
@@ -19,7 +21,9 @@ export function QuestionReferenceText({ text }: { text: string }) {
{part.text}
</Text>;
}
- return <ChatPathChipSpan key={index} candidate={classifyChatPathLinkTarget(part.href)}
+ // A new reference or source must read its own verdict in the first frame,
+ // before the span's verification effect runs.
+ return <ChatPathChipSpan key={JSON.stringify([index, fileContext?.deviceId, fileContext?.workdir, part.href])} candidate={classifyChatPathLinkTarget(part.href)}
display={part.text} plainStyle={undefined} chipStyle={{ textDecorationLine: 'underline' }} SpanText={Text} usePathState={useState} />;
})}</>;
}