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): preserve receipt round-trip compatibility

jiajiayaoe6940e93bfa8
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/ghostInstallReceipt.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/ghostInstallReceipt.test.ts
index e5855a743f..6ba48b6b67 100644
--- a/apps/desktop/src/main/cindy-brain/__tests__/ghostInstallReceipt.test.ts
+++ b/apps/desktop/src/main/cindy-brain/__tests__/ghostInstallReceipt.test.ts
@@ -227,6 +227,29 @@ describe('GhostInstallReceiptStore cleanup', () => {
});
});
+ it('reads receipts through a state-root path with a linked ancestor', async () => {
+ const realRoot = path.join(workDir, 'real-state');
+ const linkedRoot = path.join(workDir, 'linked-state');
+ await fs.promises.mkdir(realRoot);
+ try {
+ await fs.promises.symlink(
+ realRoot,
+ linkedRoot,
+ process.platform === 'win32' ? 'junction' : 'dir',
+ );
+ } catch {
+ return;
+ }
+ const linkedStore = new GhostInstallReceiptStore(
+ () => linkedRoot,
+ async () => {},
+ );
+
+ await linkedStore.write(createSetupReceipt());
+
+ expect(linkedStore.read('hello')).toMatchObject({ state: 'approved' });
+ });
+
it('treats only a missing migration marker as absent', () => {
expect(store.hasMigrationMarker('hello')).toBe(false);
});
diff --git a/apps/desktop/src/main/cindy-brain/ghostInstallReceipt.ts b/apps/desktop/src/main/cindy-brain/ghostInstallReceipt.ts
index 2dcefd9dc6..012c715447 100644
--- a/apps/desktop/src/main/cindy-brain/ghostInstallReceipt.ts
+++ b/apps/desktop/src/main/cindy-brain/ghostInstallReceipt.ts
@@ -8,6 +8,7 @@ import {
GHOST_SKILL_MD_MAX_BYTES,
ghostManifestToAuthorFormat,
isValidGhostId,
+ validateGhostManifest,
validateGhostManifestLocaleResource,
validateNormalizedGhostManifest,
type GhostManifest,
@@ -188,6 +189,10 @@ export class GhostInstallReceiptStore {
return path.resolve(this.getRootDir());
}
+ private realRootDirSync(): string {
+ return fs.realpathSync(this.rootDir());
+ }
+
read(id: string): GhostInstallReceiptReadResult {
const result = this.readForRecovery(id);
if (result.state === 'approved') return result;
@@ -201,7 +206,7 @@ export class GhostInstallReceiptStore {
let bytes: Buffer | null;
try {
bytes = readBoundedFileNoFollowSync(receiptPath, MAX_RECEIPT_BYTES, {
- containWithin: this.rootDir(),
+ containWithin: this.realRootDirSync(),
});
} catch (error) {
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
@@ -449,7 +454,7 @@ export class GhostInstallReceiptStore {
const bytes = readBoundedFileNoFollowSync(
this.migrationLedgerPath(),
MAX_MIGRATION_LEDGER_BYTES,
- { containWithin: this.rootDir() },
+ { containWithin: this.realRootDirSync() },
);
if (bytes === null) return null;
const raw = JSON.parse(
@@ -684,7 +689,7 @@ export class GhostInstallReceiptStore {
// reads from the same handle with O_NONBLOCK so a FIFO/device blocks
// neither the open nor the subsequent read.
bytes = readBoundedFileNoFollowSync(markerPath, MAX_PENDING_MUTATION_BYTES, {
- containWithin: this.rootDir(),
+ containWithin: this.realRootDirSync(),
});
} catch (error) {
if ((error as NodeJS.ErrnoException).code === 'ENOENT') return { state: 'missing' };
@@ -1084,7 +1089,14 @@ function validateReceipt(
if (typeof value.revision !== 'string' || !isRevision(value.revision)) {
return { ok: false, reason: 'receipt revision 不合法' };
}
- const manifestResult = validateNormalizedGhostManifest(value.manifest);
+ // v0.1.48 reads author-format receipt manifests, while a short-lived affected
+ // build persisted the internal normalized setup shape. Accept only those two
+ // strictly validated representations and normalize both before continuing
+ // the receipt-level authorization checks below.
+ const normalizedManifest = validateNormalizedGhostManifest(value.manifest);
+ const manifestResult = normalizedManifest.ok
+ ? normalizedManifest
+ : validateGhostManifest(value.manifest);
if (!manifestResult.ok || manifestResult.manifest.id !== expectedId) {
return {
ok: false,