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-market): recover stale GitHub trust receipts (#3094)

Battleplus0558df57ffa6
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 a2d3d30688..bf851e229d 100644
--- a/apps/desktop/src/main/plugin-market/__tests__/service.test.ts
+++ b/apps/desktop/src/main/plugin-market/__tests__/service.test.ts
@@ -8,6 +8,7 @@ import {
validateGhostManifest,
type GhostInstallApproval,
type GhostManifest,
+ type GhostTrustInfo,
} from '../../../shared/ghost.js';
const runtime = vi.hoisted(() => ({
ghosts: [] as Array<{
@@ -15,6 +16,7 @@ const runtime = vi.hoisted(() => ({
dir: string;
enabled: boolean;
approval?: GhostInstallApproval;
+ trust?: GhostTrustInfo;
}>,
install: vi.fn(),
inspect: vi.fn(),
@@ -72,6 +74,12 @@ vi.mock('../../cindy-brain/index.js', () => ({
state: 'approved',
revision: '00000000-0000-4000-8000-000000000001',
},
+ trust: ghost.trust ?? {
+ level: 'unverified',
+ publisherSigned: false,
+ publisherVerified: false,
+ reviewed: false,
+ },
})),
approvedInstallEvidence: runtime.approvedInstallEvidence,
inspect: runtime.inspect,
@@ -1453,13 +1461,33 @@ describe('PluginMarketService migration and defaultInstall', () => {
});
});
- it('旧 source:market + manifestDigest 安装会回填 cindy-github 官方 trust', async () => {
+ it('Host receipt 未可信时,目录中的完整 trust 镜像也不能阻止官方回填', async () => {
const item = summary({ ghostId: 'cindy-github' });
const rawManifest = manifest('cindy-github');
const installDir = fs.mkdtempSync(path.join(os.tmpdir(), 'cindy-market-github-'));
roots.push(installDir);
fs.writeFileSync(path.join(installDir, 'ghost.json'), JSON.stringify(rawManifest));
- runtime.ghosts = [{ manifest: rawManifest, dir: installDir, enabled: true }];
+ fs.writeFileSync(
+ path.join(installDir, '.cindy-trust.json'),
+ JSON.stringify({
+ level: 'cindy-official',
+ publisherSigned: true,
+ publisherVerified: true,
+ reviewed: true,
+ publisherName: 'Cindy Plugin Market',
+ }),
+ );
+ runtime.ghosts = [{
+ manifest: rawManifest,
+ dir: installDir,
+ enabled: true,
+ trust: {
+ level: 'unverified',
+ publisherSigned: false,
+ publisherVerified: false,
+ reviewed: false,
+ },
+ }];
const h = harness([item]);
const digest = ghostManifestDigest(rawManifest);
h.ledger.upsertInstallation({
@@ -1513,7 +1541,18 @@ describe('PluginMarketService migration and defaultInstall', () => {
publisherName: 'Cindy Plugin Market',
}),
);
- runtime.ghosts = [{ manifest: rawManifest, dir: installDir, enabled: true }];
+ runtime.ghosts = [{
+ manifest: rawManifest,
+ dir: installDir,
+ enabled: true,
+ trust: {
+ level: 'cindy-official',
+ publisherSigned: true,
+ publisherVerified: true,
+ reviewed: true,
+ publisherName: 'Cindy Plugin Market',
+ },
+ }];
const h = harness([item]);
h.ledger.upsertInstallation({
pluginId: item.id,
@@ -1535,7 +1574,58 @@ describe('PluginMarketService migration and defaultInstall', () => {
expect(runtime.install).not.toHaveBeenCalled();
});
- it('legacy-adopted cindy-github 只通过当前市场更新获得官方 trust', async () => {
+ it('Host receipt 已可信但目录镜像缺失时仍回填旧版兼容 trust', async () => {
+ const item = summary({ ghostId: 'cindy-github' });
+ const rawManifest = manifest('cindy-github');
+ const installDir = fs.mkdtempSync(path.join(os.tmpdir(), 'cindy-market-github-mirror-missing-'));
+ roots.push(installDir);
+ fs.writeFileSync(path.join(installDir, 'ghost.json'), JSON.stringify(rawManifest));
+ runtime.ghosts = [{
+ manifest: rawManifest,
+ dir: installDir,
+ enabled: true,
+ trust: {
+ level: 'cindy-official',
+ publisherSigned: true,
+ publisherVerified: true,
+ reviewed: true,
+ publisherName: 'Cindy Plugin Market',
+ },
+ }];
+ const h = harness([item]);
+ h.ledger.upsertInstallation({
+ pluginId: item.id,
+ ghostId: item.ghostId,
+ releaseId: item.currentRelease.id,
+ version: item.currentRelease.version,
+ sha256: item.currentRelease.sha256,
+ scope: item.scope,
+ organizationId: item.organizationId,
+ source: 'market',
+ installed: true,
+ updatedAt: '2026-08-07T00:00:00.000Z',
+ manifestDigest: ghostManifestDigest(rawManifest),
+ });
+ runtime.install.mockResolvedValue({
+ manifest: rawManifest,
+ dir: installDir,
+ enabled: true,
+ trust: { level: 'cindy-official' },
+ });
+
+ await h.service.snapshot();
+
+ expect(h.api.download).toHaveBeenCalledWith(item.id, item.currentRelease.id);
+ expect(runtime.install).toHaveBeenCalledWith(
+ expect.stringMatching(/cindy-plugin-trust-backfill-.*\.cindy$/),
+ expect.objectContaining({
+ ghostId: 'cindy-github',
+ officialCindyGithub: true,
+ }),
+ );
+ });
+
+ it('legacy-adopted 记录不能成为开发版冒充 cindy-github 的官方 trust 来源', async () => {
const item = summary({ ghostId: 'cindy-github' });
const rawManifest = manifest('cindy-github');
const installDir = fs.mkdtempSync(path.join(os.tmpdir(), 'cindy-legacy-github-'));
diff --git a/apps/desktop/src/main/plugin-market/service.ts b/apps/desktop/src/main/plugin-market/service.ts
index d601a94ab1..384cda3726 100644
--- a/apps/desktop/src/main/plugin-market/service.ts
+++ b/apps/desktop/src/main/plugin-market/service.ts
@@ -63,7 +63,10 @@ import {
isBuiltinGhostRemovedByUser,
uninstallGhostAndCleanup,
} from '../cindy-brain/index.js';
-import { hasCindyOfficialTrustMetadata } from '../cindy-brain/GhostManager.js';
+import {
+ hasCindyOfficialTrustMetadata,
+ isCindyOfficialTrustInfo,
+} from '../cindy-brain/GhostManager.js';
import {
getActiveAppSession,
isAppSessionBoundaryPending,
@@ -458,7 +461,10 @@ function canBackfillOfficialCindyGithubTrust(
record.source === 'market' &&
record.manifestDigest !== undefined &&
installed.approval.state === 'approved' &&
- !hasCindyOfficialTrustMetadata(installed.dir) &&
+ (
+ !isCindyOfficialTrustInfo(installed.trust) ||
+ !hasCindyOfficialTrustMetadata(installed.dir)
+ ) &&
serverRecordMatchesInstalledGhost(record.pluginId, installed, record)
);
}