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。

perf(desktop): 普通插件读取凭证时跳过 Mivo 身份校验

david0531f6a5c4b5
diff --git a/apps/desktop/src/main/secrets/__tests__/providerSecretStore.test.ts b/apps/desktop/src/main/secrets/__tests__/providerSecretStore.test.ts
index 0eae2c4dc9..53a2a91cd0 100644
--- a/apps/desktop/src/main/secrets/__tests__/providerSecretStore.test.ts
+++ b/apps/desktop/src/main/secrets/__tests__/providerSecretStore.test.ts
@@ -425,6 +425,37 @@ describe('readGhostSecretTailFromIo(尾指纹读取 + 老键懒回填)', () => {
expect(io.store.get(ghostSecretHintStorageKey('my-ghost', 'api_key'))).toBe('5678');
});
+ it.each([
+ ['helper', 'api_key'],
+ ['xd-feishu', 'oauth_accounts'],
+ ['_ns__xd__xd-feishu', 'oauth_accounts'],
+ ['_ns__xd__xd-mivo', 'mivo_api_key'],
+ ['xd-mivo', 'oauth_accounts'],
+ ])('reads %s/%s without loading unrelated Mivo install facts', (instanceKey, secretKey) => {
+ const verifier = vi.fn(() => { throw new Error('Mivo install facts unavailable'); });
+ setMivoSecretAliasVerifier(verifier);
+ io.store.set(ghostSecretStorageKey(instanceKey, secretKey), 'fake-secret-value-1234');
+ try {
+ expect(readGhostSecretTailFromIo(io, instanceKey, secretKey)).toBe('1234');
+ expect(verifier).not.toHaveBeenCalled();
+ } finally {
+ setMivoSecretAliasVerifier(null);
+ }
+ });
+
+ it('rechecks Mivo alias eligibility after a successful historical-key read', () => {
+ const verifier = vi.fn(() => true);
+ setMivoSecretAliasVerifier(verifier);
+ io.store.set(ghostSecretStorageKey('xd-mivo', 'mivo_api_key', true), 'fake-mivo-legacy-9999');
+ try {
+ expect(readGhostSecretTailFromIo(io, 'xd-mivo', 'mivo_api_key')).toBe('9999');
+ verifier.mockReturnValue(false);
+ expect(readGhostSecretTailFromIo(io, 'xd-mivo', 'mivo_api_key')).toBeNull();
+ } finally {
+ setMivoSecretAliasVerifier(null);
+ }
+ });
+
it('官方别名键(xd-mivo 老用户)同样能懒回填', () => {
setMivoSecretAliasVerifier((id) => id === 'xd-mivo');
io.store.set(ghostSecretStorageKey('xd-mivo', 'mivo_api_key', true), 'mivo_legacy_key_9999');
diff --git a/apps/desktop/src/main/secrets/providerSecretStore.ts b/apps/desktop/src/main/secrets/providerSecretStore.ts
index b4e264b501..8f0a3901c6 100644
--- a/apps/desktop/src/main/secrets/providerSecretStore.ts
+++ b/apps/desktop/src/main/secrets/providerSecretStore.ts
@@ -44,19 +44,23 @@ export function setMivoSecretAliasVerifier(verifier: ((instanceKey: string) => b
canUseMivoAlias = verifier;
}
+// Only this historical key can use the Mivo alias. Loading install facts for
+// unrelated secrets rescans the full plugin list during Renderer projection.
+function isHistoricalMivoSecret(instanceKey: string, secretKey: string): boolean {
+ return instanceKey === 'xd-mivo' && secretKey === 'mivo_api_key';
+}
+
function approvedGhostSecretStorageKey(instanceKey: string, secretKey: string): string {
- return ghostSecretStorageKey(instanceKey, secretKey, canUseMivoAlias?.(instanceKey) === true);
+ const allowMivoAlias = isHistoricalMivoSecret(instanceKey, secretKey) &&
+ canUseMivoAlias?.(instanceKey) === true;
+ return ghostSecretStorageKey(instanceKey, secretKey, allowMivoAlias);
}
function approvedGhostSecretHintKey(instanceKey: string, secretKey: string): string {
// The historical hint stays on the standard key only while the same install
// fact maps the secret onto the historical Mivo key. Otherwise the hint
// follows the non-alias key, so read, write, and delete stay together.
- if (
- instanceKey === 'xd-mivo' &&
- secretKey === 'mivo_api_key' &&
- canUseMivoAlias?.(instanceKey) !== true
- ) {
+ if (isHistoricalMivoSecret(instanceKey, secretKey) && canUseMivoAlias?.(instanceKey) !== true) {
return 'ghost_hint__local__' + instanceKey + '_' + secretKey;
}
return ghostSecretHintStorageKey(instanceKey, secretKey);