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(usage): preserve unsupported quota code through redaction

qianbo57efb35396dc
diff --git a/apps/desktop/src/main/usage/__tests__/organizationQuotaApi.test.ts b/apps/desktop/src/main/usage/__tests__/organizationQuotaApi.test.ts
new file mode 100644
index 0000000000..f84adeb451
--- /dev/null
+++ b/apps/desktop/src/main/usage/__tests__/organizationQuotaApi.test.ts
@@ -0,0 +1,24 @@
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+const mocks = vi.hoisted(() => ({ fetch: vi.fn(), error: vi.fn(), warn: vi.fn() }));
+vi.mock('electron', () => ({ net: { fetch: mocks.fetch } }));
+vi.mock('../../authManager', () => ({ getAccessToken: () => 'fixture-token', refresh: async () => false, invalidateSession: vi.fn() }));
+vi.mock('../../logger', () => ({ createLogger: () => ({ error: mocks.error, warn: mocks.warn }) }));
+vi.mock('../../i18n.js', () => ({ getResolvedMainLocale: () => 'en' }));
+vi.mock('../../clientEndpointsService.js', () => ({ getClientEndpoint: () => 'https://models.example.test' }));
+import { readOrganizationAccountUsage } from '../organizationAccountUsage';
+beforeEach(() => vi.clearAllMocks());
+describe('quota through real server API client', () => {
+ it('preserves the explicit Nova unsupported signal through redaction', async () => {
+ mocks.fetch.mockResolvedValue({ ok: false, status: 501, json: async () => ({ error: { code: 'MODEL_ACCESS_QUOTA_NOT_SUPPORTED', message: 'private-upstream-detail' } }) });
+ expect(await readOrganizationAccountUsage()).toBeUndefined();
+ expect(JSON.stringify([mocks.error.mock.calls, mocks.warn.mock.calls])).not.toContain('private-upstream-detail');
+ });
+ it('does not allow an unrelated 501 to activate legacy credentials', async () => {
+ mocks.fetch.mockResolvedValue({ ok: false, status: 501, json: async () => ({ error: { code: 'OTHER_UNSUPPORTED', message: 'private-upstream-detail' } }) });
+ expect(await readOrganizationAccountUsage()).toBeNull();
+ });
+ it('retains old-server 404 compatibility through redaction', async () => {
+ mocks.fetch.mockResolvedValue({ ok: false, status: 404, json: async () => ({ error: { code: 'NOT_FOUND' } }) });
+ expect(await readOrganizationAccountUsage()).toBeUndefined();
+ });
+});
diff --git a/apps/desktop/src/main/usage/organizationAccountUsage.ts b/apps/desktop/src/main/usage/organizationAccountUsage.ts
index 9f9da5bb85..9c482bbf5f 100644
--- a/apps/desktop/src/main/usage/organizationAccountUsage.ts
+++ b/apps/desktop/src/main/usage/organizationAccountUsage.ts
@@ -8,6 +8,7 @@ export async function readOrganizationAccountUsage(): Promise<ClaudeAccountUsage
const data = await serverApiFetch<unknown>('/api/model-access/quota', {
baseUrl: () => getClientEndpoint('modelAccessApiBaseUrl'),
timeoutMs: 8000, redactErrorDetails: true,
+ allowedRedactedErrorCodes: ['MODEL_ACCESS_QUOTA_NOT_SUPPORTED'],
});
if (!data || typeof data !== 'object') return null;
const row = data as Record<string, unknown>;