Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
test(im): 补上 realpath 去重的平台无关回归用例,并订正注释
Lizibd0a7d5fb360
diff --git a/apps/desktop/src/main/im/shared/__tests__/localMarkdownImages.test.ts b/apps/desktop/src/main/im/shared/__tests__/localMarkdownImages.test.tsindex 942cb358ce..94849c80bf 100644--- a/apps/desktop/src/main/im/shared/__tests__/localMarkdownImages.test.ts+++ b/apps/desktop/src/main/im/shared/__tests__/localMarkdownImages.test.ts@@ -146,4 +146,36 @@ describe('materializeLocalMarkdownImages', () => {expect(result).toEqual({ absPaths: [], text: '图片' });expect(deps.ingest).not.toHaveBeenCalled();});++ it('existingAbsPaths 未经 realpath 规范化时仍然去重命中', async () => {+ // 上一个用例只在 os.tmpdir() 恰好是软链的宿主上才有区分力(macOS 的 /var →+ // /private/var);CI 是 ubuntu、/tmp 不是软链,去重键写错也照样绿。这里把+ // realpath 整个注入,不碰文件系统,三平台同一行为:入表键若不过 realpath,+ // 别名查不中规范路径,同一张受管图片会被重复追加。+ const canonical = path.join(path.sep, 'canonical', 'store', 'a.png');+ const alias = path.join(path.sep, 'alias', 'store', 'a.png');+ const realpath = vi.fn(async (value: string) => (value === alias ? canonical : value));+ const deps = {+ ...makeDeps(alias),+ realpath,+ // 去重命中时下面两个不会被调用;留桩是为了让回退的失败表现为「多追加一张」+ // 而不是抛错,断言才指向真正的原因。+ stat: async () => ({ isFile: () => true, size: PNG_BYTES.length }),+ readFile: async () => PNG_BYTES,+ };++ const result = await materializeLocalMarkdownImages(+ {+ text: `}.png)`,+ workingDir: path.join(path.sep, 'workdir'),+ sessionId: 'session-6',+ existingAbsPaths: [alias],+ },+ deps,+ );++ expect(realpath).toHaveBeenCalledWith(alias);+ expect(result).toEqual({ absPaths: [], text: '图片' });+ expect(deps.ingest).not.toHaveBeenCalled();+ });});diff --git a/apps/desktop/src/main/im/shared/localMarkdownImages.ts b/apps/desktop/src/main/im/shared/localMarkdownImages.tsindex b6a4df87c1..b8a234e85d 100644--- a/apps/desktop/src/main/im/shared/localMarkdownImages.ts+++ b/apps/desktop/src/main/im/shared/localMarkdownImages.ts@@ -106,8 +106,13 @@ export async function materializeLocalMarkdownImages(const materializedByRealPath = new Map<string, string>();for (const existingPath of params.existingAbsPaths ?? []) {// 键必须与下面的查询同口径(pathKey(sourceReal),即 realpath 之后)。按原样入表- // 会让含符号链接的入参查不中——macOS 的 /var 是 /private/var 的软链,tool_result- // 收集到的临时目录路径正是这种形态,于是同一张受管图片被判成新图重复追加。+ // 会让含符号链接的入参查不中,同一张受管图片被判成新图重复追加。+ //+ // 入参不保证已规范化:它们来自 turnRunner 的 handleToolResultFullEvent,经+ // blobStore / imageCacheStore 的 resolveSafe 用 path.join / path.resolve 拼出+ // `<userData>/cindy-media/blobs/…` 与 `<userData>/cc-agent/images/…`,两处都不做+ // realpath。所以只要 userData 路径链上有软链或 junction(home 被重定位、Windows+ // AppData 重定向、macOS home 挂在别的卷),生产上就会命中。let existingKey = existingPath;try {existingKey = await deps.realpath(existingPath);