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(plugin): 保持普通导出与投稿的打包行为

liugaowei554b43041fc0
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/exportGhostPackage.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/exportGhostPackage.test.ts
index a5daa9fe50..fe9b5a0a77 100644
--- a/apps/desktop/src/main/cindy-brain/__tests__/exportGhostPackage.test.ts
+++ b/apps/desktop/src/main/cindy-brain/__tests__/exportGhostPackage.test.ts
@@ -137,10 +137,10 @@ function makeDeps(overrides: Partial<Parameters<typeof exportGhostPackage>[1]> =
}
describe('snapshotInstalledGhostPackage', () => {
- // OSS reuse requires equal bytes, not only equal manifests. Existing export
- // tests never compare two snapshots across time/entry order. Unit tier: real
- // tiny directory, ZIP and signatures; Date is fake and no timers are awaited.
- it.each([false, true])('reproduces unchanged package bytes across time and enumeration order (signed=%s)', async signed => {
+ // Sharing reuses content identity across ZIP metadata/entry-order changes.
+ // Ordinary exports and contributions keep their existing ZIP timestamps.
+ // Unit tier: real tiny directory, ZIP and signatures; only Date is fake.
+ it.each([false, true])('keeps content identity stable without normalizing export ZIP metadata (signed=%s)', async signed => {
await fs.promises.mkdir(path.join(ghostDir, 'templates', 'empty'), { recursive: true });
await fs.promises.mkdir(path.join(ghostDir, 'another-empty'));
if (signed) await writeStatement(['ghost.json', 'locales/en.json', 'main.js']);
@@ -164,10 +164,12 @@ describe('snapshotInstalledGhostPackage', () => {
vi.setSystemTime(new Date('2026-10-29T12:34:56.000Z'));
const second = await snapshotInstalledGhostPackage('hello', makeDeps());
if (first.status !== 'prepared' || second.status !== 'prepared') throw new Error('Expected package snapshots');
- expect(second.bytes).toEqual(first.bytes);
+ expect(second.bytes).not.toEqual(first.bytes);
expect(content).toMatchObject({ status: 'prepared', contentSha256: first.shareContentSha256 });
expect(second.shareContentSha256).toBe(first.shareContentSha256);
+ expect(second.contentSha256).toBe(first.contentSha256);
const zip = await JSZip.loadAsync(second.bytes);
+ expect(zip.files['main.js']?.date.getUTCFullYear()).toBe(2026);
expect(zip.files['templates/empty/']?.dir).toBe(true);
expect(await verifyGhostZipSignatures(zip, '', makeGhost().manifest)).toMatchObject({ ok: true });
if (signed) expect(await zip.file('cindy-signatures.json')!.async('string'))
diff --git a/apps/desktop/src/main/cindy-brain/exportGhostPackage.ts b/apps/desktop/src/main/cindy-brain/exportGhostPackage.ts
index c2e71fdeba..51ef8ca8fe 100644
--- a/apps/desktop/src/main/cindy-brain/exportGhostPackage.ts
+++ b/apps/desktop/src/main/cindy-brain/exportGhostPackage.ts
@@ -589,17 +589,12 @@ export async function snapshotInstalledGhostPackage(
const { ghost, snapshot, maxEntries, maxArchive } = content;
const zip = new JSZip();
- // Equal installed content must produce equal bytes for local-share OSS reuse.
- // Use code-unit order so archive identity does not depend on host locale.
- for (const rel of snapshot.emptyDirs.slice().sort()) {
+ for (const rel of snapshot.emptyDirs) {
zip.folder(rel);
}
- for (const file of snapshot.entries.slice().sort((a, b) => a.rel < b.rel ? -1 : a.rel > b.rel ? 1 : 0)) {
+ for (const file of snapshot.entries) {
zip.file(file.rel, file.data, { unixPermissions: file.unixPermissions });
}
- // Include automatically created parent folders; timestamps are not package content.
- const archiveDate = new Date('1980-01-01T00:00:00.000Z');
- zip.forEach((_rel, entry) => { entry.date = archiveDate; });
if (Object.keys(zip.files).length > maxEntries) {
return { status: 'error' as const, code: 'too_large' as const };
}
diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.md
index f86c461d5c..996419a42b 100644
--- a/docs/dev-rules/protocol-compatibility.md
+++ b/docs/dev-rules/protocol-compatibility.md
@@ -3635,8 +3635,8 @@ Main 先用原一致性读取入口核对已批准的本地实例,绑定版本
普通 Access Token 用于创建、查看、图片和下载;关闭署名只隐藏姓名,不转匿名。
同一面板重试和署名切换复用原包,新的分享操作始终独立;ready 包不跟随本地文件或后来版本。
-逻辑分享与包存储分开:同一内容的快照打包采用稳定条目顺序与 ZIP 时间戳,保留实际文件、权限、
-空目录与签名字节。新的操作仍创建新的 snapshotId;相同包可指向同一 OSS 对象,服务端命中本人
+逻辑分享与包存储分开:内容摘要按确定顺序编码,打包沿用原 ZIP 条目与时间戳行为,保留实际文件、权限、
+空目录与签名字节,不改变普通导出和投稿的包元数据。新的操作仍创建新的 snapshotId;相同包可指向同一 OSS 对象,服务端命中本人
已验证的相同内容摘要时,check 直接返回 ready,客户端核对本次内容与身份后省略压缩、PUT/commit,
继续创建本轮分享素材。同版本内容改变不能复用;不凭其他用户包的摘要跳过上传验证。
本地分享先核对当前包与服务端复用结果:ready 时直接生成新链接,不再确认上传;需要传包时