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): block silent default upgrade for unapproved installs; fix readBoundedFile tests

Yuewei-LLe3f1dba6b020
diff --git a/apps/desktop/src/main/plugin-market/__tests__/service.test.ts b/apps/desktop/src/main/plugin-market/__tests__/service.test.ts
index 0d0ca26ace..18ef368f0f 100644
--- a/apps/desktop/src/main/plugin-market/__tests__/service.test.ts
+++ b/apps/desktop/src/main/plugin-market/__tests__/service.test.ts
@@ -1078,6 +1078,44 @@ describe('PluginMarketService migration and defaultInstall', () => {
});
});
+ it.each(['legacy-unapproved', 'invalid'] as const)(
+ 'skips the silent default upgrade for a %s install instead of minting a fresh receipt',
+ async (approvalState) => {
+ const item = summary({
+ scope: 'organization',
+ organizationId: 'org-1',
+ defaultInstall: true,
+ currentRelease: {
+ ...summary().currentRelease,
+ id: 'release-2',
+ version: '2.0.0',
+ },
+ });
+ const oldManifest = manifest(item.ghostId, '1.0.0');
+ const installDir = fs.mkdtempSync(path.join(os.tmpdir(), 'cindy-market-upgrade-'));
+ roots.push(installDir);
+ fs.writeFileSync(path.join(installDir, 'ghost.json'), JSON.stringify(oldManifest));
+ runtime.ghosts = [
+ { manifest: oldManifest, dir: installDir, enabled: false, approval: { state: approvalState } },
+ ];
+ const h = harness([item]);
+ h.ledger.upsertInstallation({
+ ...recordForTest(item),
+ releaseId: 'release-1',
+ version: '1.0.0',
+ manifestDigest: ghostManifestDigest(oldManifest),
+ });
+
+ const snapshot = await h.service.snapshot();
+
+ // 非 approved 安装没有已批准基线:静默默认升级会无用户确认签发新 receipt,
+ // 必须跳过,交给重新确认/恢复流程。runtime.install 不应被调用。
+ expect(runtime.install).not.toHaveBeenCalled();
+ expect(snapshot.items[0]).toMatchObject({ installState: 'update-available' });
+ expect(h.service.consumeUpgradeNotice()).toBeNull();
+ },
+ );
+
it('silently updates an organization defaultInstall package and preserves disabled state', async () => {
const item = summary({
scope: 'organization',
diff --git a/apps/desktop/src/main/plugin-market/service.ts b/apps/desktop/src/main/plugin-market/service.ts
index 10b195dba6..581ab62bbb 100644
--- a/apps/desktop/src/main/plugin-market/service.ts
+++ b/apps/desktop/src/main/plugin-market/service.ts
@@ -2034,6 +2034,19 @@ export class PluginMarketService {
});
return;
}
+ // A legacy-unapproved or invalid install has no approved baseline: a
+ // silent default upgrade would let Main mint a fresh approved receipt
+ // without the full permission review the user must confirm. Skip the
+ // silent upgrade and leave the plugin in its current state so it goes
+ // through the reapproval/recovery flow instead.
+ if (freshInstalled.approval.state !== 'approved') {
+ log.warn('default plugin upgrade skipped for unapproved install', {
+ pluginId: summary.id,
+ ghostId: summary.ghostId,
+ approvalState: freshInstalled.approval.state,
+ });
+ return;
+ }
const reviewedBaseline = ghostPermissionBaselineKey(freshInstalled.manifest);
const detail = await this.api.detail(summary.id);
requireSameMarketOwner(owner);
diff --git a/apps/desktop/src/main/utils/__tests__/readBoundedFile.test.ts b/apps/desktop/src/main/utils/__tests__/readBoundedFile.test.ts
index 062997cdb4..42dd20ef2c 100644
--- a/apps/desktop/src/main/utils/__tests__/readBoundedFile.test.ts
+++ b/apps/desktop/src/main/utils/__tests__/readBoundedFile.test.ts
@@ -30,7 +30,7 @@ afterEach(async () => {
});
describe('readBoundedFileNoFollow', () => {
- it('opens untrusted paths in non-blocking mode before checking the file type', async () => {
+ it('opens follow-links untrusted paths in non-blocking mode; no-follow defaults to blocking', async () => {
const file = path.join(workDir, 'plain.json');
await fs.promises.writeFile(file, '{"ok":1}');
const realOpen = fs.promises.open;
@@ -43,16 +43,25 @@ describe('readBoundedFileNoFollow', () => {
}) as typeof fs.promises.open);
try {
+ // readBoundedFileNoFollow opts into O_NONBLOCK only when the caller asks
+ // for it (special-file reads); the default no-follow open stays blocking.
await expect(readBoundedFileNoFollow(file, 1024)).resolves.not.toBeNull();
+ await expect(readBoundedFileNoFollow(file, 1024, { nonBlocking: true })).resolves.not.toBeNull();
+ // readBoundedFileFollowLinks always opens non-blocking so a FIFO/device
+ // entry cannot block Main forever.
await expect(readBoundedFileFollowLinks(file, 1024)).resolves.not.toBeNull();
} finally {
spy.mockRestore();
}
- expect(flags).toHaveLength(2);
+ expect(flags).toHaveLength(3);
const nonBlockingFlag = fs.constants.O_NONBLOCK ?? 0;
- expect(flags.every((flag) => (flag & nonBlockingFlag) === nonBlockingFlag))
- .toBe(true);
+ // flags[0]: readBoundedFileNoFollow default (blocking)
+ expect(flags[0] & nonBlockingFlag).toBe(0);
+ // flags[1]: readBoundedFileNoFollow with nonBlocking: true
+ expect(flags[1] & nonBlockingFlag).toBe(nonBlockingFlag);
+ // flags[2]: readBoundedFileFollowLinks (always non-blocking)
+ expect(flags[2] & nonBlockingFlag).toBe(nonBlockingFlag);
});
it('普通文件按实际字节返回,超限返回 null', async () => {
@@ -392,7 +401,7 @@ describe('readBoundedFileNoFollow', () => {
});
describe('readBoundedFileNoFollowSync', () => {
- it('opens untrusted paths in non-blocking mode before checking the file type', async () => {
+ it('opens untrusted no-follow paths in blocking mode by default (sync variant)', async () => {
const file = path.join(workDir, 'plain.json');
await fs.promises.writeFile(file, '{"ok":1}');
const realOpenSync = fs.openSync;
@@ -410,8 +419,10 @@ describe('readBoundedFileNoFollowSync', () => {
spy.mockRestore();
}
+ // The synchronous variant has no nonBlocking option; the default no-follow
+ // open stays blocking (regular files only, so this cannot block on a FIFO).
const nonBlockingFlag = fs.constants.O_NONBLOCK ?? 0;
- expect(flags & nonBlockingFlag).toBe(nonBlockingFlag);
+ expect(flags & nonBlockingFlag).toBe(0);
});
it('限量与回退闸语义和异步变体一致', async () => {