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): 防止恢复记录提升组织插件授权

liugaowei395b5b78469d
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/connectionAudienceResolver.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/connectionAudienceResolver.test.ts
index d4ab8b7b28..b808b5fe0d 100644
--- a/apps/desktop/src/main/cindy-brain/__tests__/connectionAudienceResolver.test.ts
+++ b/apps/desktop/src/main/cindy-brain/__tests__/connectionAudienceResolver.test.ts
@@ -85,6 +85,11 @@ describe('installed Plugin Connection audience resolver', () => {
resolverOptions(manifest, { ...marketInstallation, source: 'local-market' }),
);
expect(resolver.resolve('plugin-a', identity)).toBeNull();
+ expect(
+ loadConnectionAudienceResolver(
+ resolverOptions(manifest, { ...marketInstallation, source: 'legacy-adopted' }),
+ ).resolve('plugin-a', identity),
+ ).toBeNull();
expect(
loadConnectionAudienceResolver(
diff --git a/apps/desktop/src/main/plugin-market/__tests__/ledger.test.ts b/apps/desktop/src/main/plugin-market/__tests__/ledger.test.ts
index a4ebf656d7..1e8fae35b5 100644
--- a/apps/desktop/src/main/plugin-market/__tests__/ledger.test.ts
+++ b/apps/desktop/src/main/plugin-market/__tests__/ledger.test.ts
@@ -85,6 +85,25 @@ describe('PluginMarketLedger', () => {
).toBe(false);
});
+ it('keeps a recovered organization route out of market-only authorization', () => {
+ const { ledger } = harness();
+ ledger.upsertInstallation(record({
+ scope: 'organization',
+ organizationId: 'org-a',
+ }));
+ ledger.markRemoved('cindy-test', 'user-a');
+ const disconnected = ledger.installationForGhost('cindy-test');
+ expect(disconnected).not.toBeNull();
+ if (!disconnected) return;
+
+ expect(ledger.restoreDisconnectedInstallation(disconnected, 'user-a')).toBe(true);
+ expect(ledger.installationForGhost('cindy-test')).toMatchObject({
+ installed: true,
+ source: 'legacy-adopted',
+ scope: 'organization',
+ });
+ });
+
it('does not overwrite a disconnected record that changed after recovery captured it', () => {
const { ledger } = harness();
const disconnected = record({ installed: false });
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 aaf3a8452d..d4fe624c54 100644
--- a/apps/desktop/src/main/plugin-market/__tests__/service.test.ts
+++ b/apps/desktop/src/main/plugin-market/__tests__/service.test.ts
@@ -563,6 +563,57 @@ describe('PluginMarketService migration and defaultInstall', () => {
expect(runtime.install).not.toHaveBeenCalled();
});
+ it('restores an organization update route without restoring market-only authorization', async () => {
+ const canonicalManifest = normalizedManifest(manifest());
+ const item = summary({
+ scope: 'organization',
+ organizationId: 'org-1',
+ currentRelease: {
+ ...summary().currentRelease,
+ id: RELEASE_ID,
+ },
+ });
+ const installDir = fs.mkdtempSync(path.join(os.tmpdir(), 'cindy-market-org-recovery-'));
+ roots.push(installDir);
+ fs.writeFileSync(path.join(installDir, 'ghost.json'), JSON.stringify(canonicalManifest));
+ runtime.ghosts = [{
+ manifest: canonicalManifest as unknown as Record<string, unknown>,
+ dir: installDir,
+ enabled: true,
+ }];
+ runtime.approvedInstallEvidence.mockReturnValue({
+ packageSha256: item.currentRelease.sha256,
+ approvedManifest: canonicalManifest,
+ legacyMigrated: false,
+ });
+ 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-01T00:00:00.000Z',
+ manifestDigest: ghostManifestDigest(canonicalManifest),
+ });
+ h.ledger.markRemoved(item.ghostId, 'user-1');
+
+ const snapshot = await h.service.snapshot();
+
+ expect(snapshot.items[0]).toMatchObject({ installState: 'installed', enabled: true });
+ expect(h.ledger.installationForGhost(item.ghostId)).toMatchObject({
+ installed: true,
+ source: 'legacy-adopted',
+ releaseId: RELEASE_ID,
+ });
+ expect(h.api.download).not.toHaveBeenCalled();
+ expect(runtime.install).not.toHaveBeenCalled();
+ });
+
it.each([
{ receiptCase: 'missing', receiptSha: null },
{ receiptCase: 'different', receiptSha: 'f'.repeat(64) },
diff --git a/apps/desktop/src/main/plugin-market/ledger.ts b/apps/desktop/src/main/plugin-market/ledger.ts
index c54677c413..51ea838646 100644
--- a/apps/desktop/src/main/plugin-market/ledger.ts
+++ b/apps/desktop/src/main/plugin-market/ledger.ts
@@ -251,10 +251,13 @@ export class PluginMarketLedger {
}
/**
- * Reconnect an unchanged historical server record after the approved receipt
- * proves the original package hash. The compare-and-write prevents a
- * concurrent uninstall or source replacement from being overwritten by a
- * stale recovery snapshot.
+ * Reconnect a historical server update route after the approved receipt proves
+ * its original package identity. That receipt does not attest the current
+ * directory bytes, so an organization-scoped market record is demoted to
+ * legacy-adopted until a verified market update installs fresh bytes. This
+ * keeps automatic updates available without restoring Connection JWT trust
+ * from audit-only evidence. The compare-and-write prevents a concurrent
+ * uninstall or source replacement from being overwritten by a stale snapshot.
*/
restoreDisconnectedInstallation(
expected: PluginMarketInstallationRecord,
@@ -272,6 +275,10 @@ export class PluginMarketLedger {
}
data.installations[current.ghostId] = {
...current,
+ source:
+ current.scope === 'organization' && current.source === 'market'
+ ? 'legacy-adopted'
+ : current.source,
installed: true,
updatedAt: new Date().toISOString(),
};
diff --git a/apps/desktop/src/main/plugin-market/service.ts b/apps/desktop/src/main/plugin-market/service.ts
index f4d851b35c..2f5301a6f8 100644
--- a/apps/desktop/src/main/plugin-market/service.ts
+++ b/apps/desktop/src/main/plugin-market/service.ts
@@ -2027,6 +2027,9 @@ export class PluginMarketService {
* package hash. Legacy receipts intentionally omitted that audit-only hash, so
* they additionally require the completed one-time migration to name this id
* and the raw installed manifest to equal the manifest frozen in that receipt.
+ * This evidence reconnects the server update route, not current code bytes;
+ * the ledger therefore demotes recovered organization records to
+ * legacy-adopted until a verified market update restores stronger trust.
*/
private async recoverDisconnectedMarketInstallations(
plugins: readonly VisiblePluginSummary[],