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): 稳定校验变更摘要身份

DavidShen0659d94dc8e3
diff --git a/apps/desktop/src/main/turn-change-set/__tests__/store.git-integration.test.ts b/apps/desktop/src/main/turn-change-set/__tests__/store.git-integration.test.ts
index e8bc0d17c0..cf6fd2808d 100644
--- a/apps/desktop/src/main/turn-change-set/__tests__/store.git-integration.test.ts
+++ b/apps/desktop/src/main/turn-change-set/__tests__/store.git-integration.test.ts
@@ -1134,6 +1134,58 @@ describe('turn change-set sidecar store', () => {
expect(detail?.diffs).toHaveLength(55);
});
+ it('matches detail summaries independently of persisted property order', async () => {
+ await beginTurnChangeSet({
+ sessionId: 'session-1',
+ anchorClientId: 'user-1',
+ provider: 'codex',
+ cwd: workdir,
+ });
+ noteTurnDiffEvent('session-1', {
+ type: 'turn_diff',
+ source: 'codex',
+ data: {
+ turnId: 'turn-reordered-summary',
+ cwd: workdir,
+ diff: [
+ 'diff --git a/a.ts b/a.ts',
+ '--- a/a.ts',
+ '+++ b/a.ts',
+ '@@ -1 +1 @@',
+ '-old',
+ '+new',
+ '',
+ ].join('\n'),
+ },
+ });
+ await finalizeTurnChangeSet('session-1', 'turn-reordered-summary', 'complete');
+
+ const [summary] = await listTurnChangeSets('session-1');
+ const indexPath = path.join(
+ mocks.userDataRoot,
+ 'turn-change-sets',
+ 'session-1',
+ 'index.json',
+ );
+ const index = JSON.parse(await fs.readFile(indexPath, 'utf8')) as {
+ entries: Array<Record<string, unknown>>;
+ };
+ const entry = index.entries[0]!;
+ const files = (entry.files as Array<Record<string, unknown>>).map((file) =>
+ Object.fromEntries(Object.entries(file).reverse()));
+ index.entries[0] = Object.fromEntries(
+ Object.entries({ ...entry, files }).reverse(),
+ );
+ await fs.writeFile(indexPath, `${JSON.stringify(index)}\n`, 'utf8');
+
+ const [detail] = await getTurnChangeSets('session-1', [summary!.id]);
+ expect(detail).toMatchObject({
+ id: summary!.id,
+ providerTurnId: 'turn-reordered-summary',
+ });
+ expect(detail?.diffs).toHaveLength(1);
+ });
+
it('removes orphan detail files after the next successful index publish', async () => {
const sidecarDir = path.join(
mocks.userDataRoot,
diff --git a/apps/desktop/src/main/turn-change-set/store.ts b/apps/desktop/src/main/turn-change-set/store.ts
index 3a9581dfad..485f8e6f20 100644
--- a/apps/desktop/src/main/turn-change-set/store.ts
+++ b/apps/desktop/src/main/turn-change-set/store.ts
@@ -4,6 +4,7 @@ import { createTwoFilesPatch, formatPatch, parsePatch, reversePatch } from 'diff
import { realpathSync } from 'node:fs';
import fs from 'node:fs/promises';
import path from 'node:path';
+import { isDeepStrictEqual } from 'node:util';
import type { AgentEvent, TurnDiffEventData } from '@cindy/maker-core';
import type {
@@ -1465,7 +1466,7 @@ export async function getTurnChangeSets(
const detailSummary = toSummary(value, summary.workspaceState);
const detailIdentity = { ...detailSummary, workspaceState: 'applied' as const, isReversible: false };
const summaryIdentity = { ...summary, workspaceState: 'applied' as const, isReversible: false };
- if (JSON.stringify(detailIdentity) !== JSON.stringify(summaryIdentity)) continue;
+ if (!isDeepStrictEqual(detailIdentity, summaryIdentity)) continue;
details.push({ ...detailSummary, diffs: parseDiffs(value.id, value.unifiedDiff) });
} catch (error) {
log.warn('turn change-set detail read failed', { sessionId, id, error });