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(bots): retain pending shares across same-owner repair

Dashd73e7b86681f
diff --git a/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsx b/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsx
index c06e5dbab5..d4ca10aeb6 100644
--- a/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsx
+++ b/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsx
@@ -44,10 +44,11 @@ export type BotGroupSharedReplies = ReadonlyMap<string, { messageId: string; byS
* while the same thread is open again, and either way that panel shows the retry.
* Server groups keep their IDs across accounts, so the queue belongs to one data owner.
*/
-const unpostedStore = { owner: getDataOwnerGeneration(), replies: new Map<string, ReadonlySet<string>>(), listeners: new Set<() => void>() };
+const unpostedStore = { owner: getDataOwnerGeneration().dataOwnerId, replies: new Map<string, ReadonlySet<string>>(), listeners: new Set<() => void>() };
const NONE_UNPOSTED: ReadonlySet<string> = new Set();
function unpostedReplies() {
- const owner = getDataOwnerGeneration();
+ // Same-account runtime repairs advance generation without changing this queue's owner.
+ const owner = getDataOwnerGeneration().dataOwnerId;
if (unpostedStore.owner !== owner) { unpostedStore.owner = owner; unpostedStore.replies.clear(); }
return unpostedStore.replies;
}
diff --git a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx
index 5b594bfa19..c8a0989b9a 100644
--- a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx
+++ b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx
@@ -51,7 +51,7 @@ const mocks = vi.hoisted(() => ({
getControlledState: vi.fn(),
revoke: vi.fn(),
thread: vi.fn(),
- ownerGeneration: 1,
+ ownerGeneration: { dataOwnerId: 'account-a', generation: 1 },
reply: vi.fn(),
shareToMain: vi.fn(),
}));
@@ -71,7 +71,8 @@ vi.mock('react-router-dom', () => ({
}));
vi.mock('@/contexts/dataOwnerGeneration', () => ({
getDataOwnerGeneration: () => mocks.ownerGeneration,
- isDataOwnerGenerationCurrent: () => true,
+ isDataOwnerGenerationCurrent: (owner: { dataOwnerId: string; generation: number }) =>
+ owner.dataOwnerId === mocks.ownerGeneration.dataOwnerId && owner.generation === mocks.ownerGeneration.generation,
isDataOwnerPushCurrent: () => true,
}));
vi.mock('@/lib/toast', () => ({ toast: { error: mocks.toastError, warning: mocks.toastWarning, info: mocks.toastInfo } }));
@@ -3202,7 +3203,7 @@ describe('more older shares than one refresh re-reads', () => {
describe('pending main-chat copies across accounts', () => {
const t = (name: string) => `bots.groupChat.server.thread.${name}`;
beforeEach(() => { vi.stubGlobal('ResizeObserver', class { observe() {} disconnect() {} }); });
- afterEach(() => { mocks.ownerGeneration = 1; });
+ afterEach(() => { mocks.ownerGeneration = { dataOwnerId: 'account-a', generation: 1 }; });
it('does not offer one account\'s failed copy to the next account in the same group', async () => {
mocks.getBotGroup.mockResolvedValue({ ok: true, group: detail({ serverBacked: true, messages: [msg({ id: 'u1', content: 'A' })] }) });
@@ -3216,11 +3217,38 @@ describe('pending main-chat copies across accounts', () => {
await within(panel).findByRole('button', { name: t('retryPost') });
view.unmount();
// Another account opens the same server group and thread.
- mocks.ownerGeneration = 2;
+ mocks.ownerGeneration = { dataOwnerId: 'account-b', generation: 2 };
renderView();
await user.click(await screen.findByRole('button', { name: 'bots.groupChat.server.startTopic' }));
panel = await screen.findByRole('complementary');
await within(panel).findByText('Reply to u1');
expect(within(panel).queryByRole('button', { name: t('retryPost') })).toBeNull();
});
+
+ it('keeps failed copies across same-owner repair and ignores an old-generation retry result', async () => {
+ mocks.getBotGroup.mockResolvedValue({ ok: true, group: detail({ serverBacked: true, messages: [msg({ id: 'u1', content: 'A' })] }) });
+ let finishOldRetry!: (result: { ok: true; messageId: string; alreadyShared: boolean }) => void;
+ mocks.shareToMain.mockResolvedValueOnce({ ok: false, errorCode: 'SERVICE_ERROR' })
+ .mockImplementationOnce(() => new Promise(resolve => { finishOldRetry = resolve; }));
+ const user = userEvent.setup();
+ renderView();
+ await user.click(await screen.findByRole('button', { name: 'bots.groupChat.server.startTopic' }));
+ const panel = await screen.findByRole('complementary');
+ await user.click(within(panel).getByRole('checkbox', { name: t('alsoSend') }));
+ await user.type(within(panel).getByRole('textbox'), 'copy me{Enter}');
+ await user.click(await within(panel).findByRole('button', { name: t('retryPost') }));
+ expect(mocks.shareToMain).toHaveBeenCalledTimes(2);
+
+ // Runtime repair leaves the same account and panel mounted, but replaces generation.
+ mocks.ownerGeneration = { dataOwnerId: 'account-a', generation: 2 };
+ await user.type(within(panel).getByRole('textbox'), 'next draft');
+ expect(within(panel).getByRole('button', { name: t('retryPost') })).toBeTruthy();
+ await act(async () => { finishOldRetry({ ok: true, messageId: 'old-share', alreadyShared: false }); });
+ expect(within(panel).getByRole('button', { name: t('retryPost') })).toBeTruthy();
+
+ await user.click(within(panel).getByRole('button', { name: t('retryPost') }));
+ await waitFor(() => expect(within(panel).queryByRole('button', { name: t('retryPost') })).toBeNull());
+ expect(mocks.shareToMain.mock.calls).toEqual(Array.from({ length: 3 }, () => [{ groupId: 'g1', messageId: 'new-reply' }]));
+ expect(mocks.reply).toHaveBeenCalledTimes(1);
+ });
});