fix(auth-files): sync quota priority display and credential ordering

Read OAuth priorities in quota cards and sort credentials by descending
priority followed by filename order across OAuth and quota pages.
This commit is contained in:
lzt404 committed 2026-10-05 16:10:37 +08:00
1 parent 46a9d3d449
commit a08f38df7f
5 files changed
+54 -4

No files matched your search

+22
View File
@@ -25,6 +25,28 @@ it('shows every reset expiry in chronological order, including duplicates, on bo
}
});
it('shows the OAuth credential priority on the quota card', () => {
const html = renderToStaticMarkup(<I18nProvider><QuotaCard
file={{ name: 'priority.json', provider: 'codex', priority: 7 }}
quota={{ status: 'success', rows: [] }} onRefresh={() => {}}
/></I18nProvider>);
expect(html).toContain('Priority 7');
expect(html).not.toContain('Priority 0');
});
it('normalizes a string priority and keeps zero as the default', () => {
const stringPriority = renderToStaticMarkup(<I18nProvider><QuotaCard
file={{ name: 'priority.json', provider: 'codex', priority: '3' }}
quota={{ status: 'idle', rows: [] }} onRefresh={() => {}}
/></I18nProvider>);
const missingPriority = renderToStaticMarkup(<I18nProvider><QuotaCard
file={{ name: 'default.json', provider: 'codex' }}
quota={{ status: 'idle', rows: [] }} onRefresh={() => {}}
/></I18nProvider>);
expect(stringPriority).toContain('Priority 3');
expect(missingPriority).toContain('Priority 0');
});
it('renders real quota values with bounded bars and keeps unknown distinct from zero', () => {
const html = render({ status: 'success', rows: [
{ label: 'empty', remainingPercent: 0 }, { label: 'full', remainingPercent: 100 },
+13
View File
@@ -9,6 +9,7 @@ import {
oauthModelProvidersFromAuthFiles,
parseAuthFilePriority,
setOAuthCredentialFileDisabled,
sortAuthFilesByPriority,
snapshotAuthFiles,
} from '../src/services/authFiles';
@@ -181,6 +182,18 @@ describe('authentication file priority', () => {
expect(normalizeAuthFilePriorityInput('1.5')).toBeNull();
});
it('sorts credentials by descending priority, then filename', () => {
expect(sortAuthFilesByPriority([
{ name: 'zeta.json', priority: 2 },
{ name: 'Beta.json', priority: 5 },
{ name: 'alpha.json', priority: 5 },
{ name: 'default.json' },
{ name: 'negative.json', priority: -1 },
]).map((file) => file.name)).toEqual([
'alpha.json', 'Beta.json', 'zeta.json', 'default.json', 'negative.json',
]);
});
it('finds only credentials created or updated by the completed OAuth provider', () => {
const before = snapshotAuthFiles([
{ name: 'codex-old.json', provider: 'codex', modtime: 1, priority: 8 },