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(desktop): do not confirm bot delivery visibility from a bare seed

MagicLizi4f88cf91a3bc
diff --git a/apps/desktop/src/renderer/__tests__/botGeneratedArtifactsCard.test.tsx b/apps/desktop/src/renderer/__tests__/botGeneratedArtifactsCard.test.tsx
index c595b6f431..edee8ab802 100644
--- a/apps/desktop/src/renderer/__tests__/botGeneratedArtifactsCard.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/botGeneratedArtifactsCard.test.tsx
@@ -4,7 +4,7 @@ import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-libra
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { ChatSessionFileProvider } from '../components/chat/ChatSessionFileContext';
-import { GeneratedFilesCard } from '../components/chat/GeneratedFilesCard';
+import { _clearLocalGeneratedFileStatCache, GeneratedFilesCard } from '../components/chat/GeneratedFilesCard';
import { groupWorkRuns, type RenderItem } from '../components/chat/messageWorkGroups';
import { simplifyBotRenderItems } from '../features/bots/botConversationPresentation';
import { useBotGeneratedFileDeliveries } from '../features/bots/useBotGeneratedFileDeliveries';
@@ -136,7 +136,15 @@ describe('伙伴成果卡', () => {
});
});
- afterEach(cleanup);
+ // The module-level local-stat cache is shared process-wide. Several tests
+ // below reuse the same '/bot/workspace/result.pdf' path across different
+ // turn windows; without clearing it, a later test's fresh mount can get
+ // seeded from an earlier test's confirmed stat instead of starting from
+ // unknown visibility, making assertions timing-dependent on the real check.
+ afterEach(() => {
+ cleanup();
+ _clearLocalGeneratedFileStatCache();
+ });
it('展示 SVG 缩略图与网页成品,默认收起 index 预览页和辅助文件', async () => {
renderCard([
diff --git a/apps/desktop/src/renderer/components/chat/GeneratedFilesCard.tsx b/apps/desktop/src/renderer/components/chat/GeneratedFilesCard.tsx
index 3348b931ff..e8e2aeb341 100644
--- a/apps/desktop/src/renderer/components/chat/GeneratedFilesCard.tsx
+++ b/apps/desktop/src/renderer/components/chat/GeneratedFilesCard.tsx
@@ -796,6 +796,10 @@ export const GeneratedFilesCard = memo(function GeneratedFilesCard({
const checkKey = generatedFilesCheckKey(files, turnStartMs, turnEndMs, turnSealed);
const filesRef = useRef(files);
filesRef.current = files;
+ // onVisibilityChange 取这个快照,不让尚未复核的 seed 被下游(useBotGeneratedFileDeliveries)
+ // 当成已确认成果来隐藏 fallback 正文。
+ const pendingPathsRef = useRef(pendingPaths);
+ pendingPathsRef.current = pendingPaths;
const visibleRef = useRef<GeneratedFileRef[] | null>(initialVisible);
// 首屏来自缓存的结论仍要整卡复核一次:缓存只负责不留空白帧,不替代本次 stat。
// 复核结果真正应用后才收起标记:检查中途被 checkKey 变化取消时,下一轮必须继续
@@ -858,7 +862,19 @@ export const GeneratedFilesCard = memo(function GeneratedFilesCard({
visibleRef.current = plan.visible;
// A remounted viewport starts with unknown visibility. Keep the parent's
// last confirmation until this check settles instead of reviving prose.
- if (plan.visible !== null) onVisibilityChange?.(checkKey, plan.visible.length > 0);
+ // A seed that is still pending (not yet re-checked by *this* mount) is
+ // not a fresh confirmation either, so it must not actively assert
+ // visible=true: useBotGeneratedFileDeliveries already keeps a prior
+ // true confirmation across the remount on its own (no jump either way);
+ // what it must not do is derive a *new* true from an unconfirmed seed.
+ // A plan with no visible files at all (confirmed gone, or genuinely new)
+ // is a real verdict and still reports immediately.
+ if (plan.visible !== null) {
+ const pendingNow = pendingPathsRef.current;
+ const hasConfirmedVisible = plan.visible.some((file) => !pendingNow.has(file.path));
+ const pendingOnly = plan.visible.length > 0 && !hasConfirmedVisible;
+ if (!pendingOnly) onVisibilityChange?.(checkKey, plan.visible.length > 0);
+ }
if (plan.visible === null) {
setExisting(null);
} else {
diff --git a/apps/desktop/src/renderer/components/chat/__tests__/GeneratedFilesCard.localSeed.test.tsx b/apps/desktop/src/renderer/components/chat/__tests__/GeneratedFilesCard.localSeed.test.tsx
index 4ae64f0a41..7759305014 100644
--- a/apps/desktop/src/renderer/components/chat/__tests__/GeneratedFilesCard.localSeed.test.tsx
+++ b/apps/desktop/src/renderer/components/chat/__tests__/GeneratedFilesCard.localSeed.test.tsx
@@ -38,6 +38,7 @@ function renderCard(props: {
turnStartMs: number;
turnEndMs?: number | null;
botArtifacts?: boolean;
+ onVisibilityChange?: (checkKey: string, visible: boolean) => void;
}) {
return render(cardElement(props));
}
@@ -48,6 +49,7 @@ function cardElement(props: {
turnStartMs: number;
turnEndMs?: number | null;
botArtifacts?: boolean;
+ onVisibilityChange?: (checkKey: string, visible: boolean) => void;
}) {
return (
<ChatSessionFileProvider
@@ -59,6 +61,7 @@ function cardElement(props: {
turnStartMs={props.turnStartMs}
turnEndMs={props.turnEndMs ?? null}
botArtifacts={props.botArtifacts}
+ onVisibilityChange={props.onVisibilityChange}
/>
</ChatSessionFileProvider>
);
@@ -225,6 +228,35 @@ describe('local generated files remount', () => {
expect(screen.queryByText('report.md')).toBeNull();
});
+ it('does not report a seeded-but-pending chip as a confirmed visibility', async () => {
+ const pendingStat: Array<(stat: unknown) => void> = [];
+ const statPath = vi.fn(
+ () =>
+ new Promise((resolve) => {
+ pendingStat.push(resolve);
+ }),
+ );
+ stubStat(statPath);
+ const first = renderCard({ renderItemKey: 'genfiles-a', turnStartMs: START });
+ await waitFor(() => expect(pendingStat).toHaveLength(1));
+ pendingStat[0]({ kind: 'file', birthtimeMs: START + 5_000, mtimeMs: START + 5_000 });
+ await waitFor(() => expect(screen.getByText('report.md')).toBeTruthy());
+ first.unmount();
+
+ // The chip itself is seeded and shown immediately, but it is not a fresh
+ // confirmation: useBotGeneratedFileDeliveries already keeps a prior true
+ // confirmation across a remount on its own, so a bare unconfirmed seed
+ // must not actively assert a *new* true (chatgpt-codex-connector P2,
+ // botConversationPresentation.ts) before this mount's own recheck lands.
+ const onVisibilityChange = vi.fn();
+ renderCard({ renderItemKey: 'genfiles-a', turnStartMs: START, onVisibilityChange });
+ expect(screen.getByText('report.md')).toBeTruthy();
+ expect(onVisibilityChange).not.toHaveBeenCalled();
+ await waitFor(() => expect(pendingStat).toHaveLength(2));
+ pendingStat[1]({ kind: 'file', birthtimeMs: START + 5_000, mtimeMs: START + 5_000 });
+ await waitFor(() => expect(onVisibilityChange).toHaveBeenCalledWith(expect.any(String), true));
+ });
+
it('re-checks a seeded path when another file finishes during the first check', async () => {
const notes: GeneratedFileRef = {
path: 'C:\\work\\notes.md',