Skip to content

Commit 0bcc08f

Browse files
op7418claude
andcommitted
fix: stale-default-provider test flaky in CI with existing providers
Test assumed no active providers exist after deleting the test one, but CI DB may have other active providers from previous runs, causing getActiveProvider() fallback to return a provider instead of undefined. Fix: temporarily deactivate non-test providers during the assertion, restore them in a finally block. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b2c3372 commit 0bcc08f

1 file changed

Lines changed: 23 additions & 11 deletions

File tree

src/__tests__/unit/stale-default-provider.test.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,29 @@ describe('Stale default_provider_id cleanup', () => {
126126
});
127127

128128
describe('resolveProvider does NOT auto-heal', () => {
129-
it('returns undefined provider when default points to deleted record', () => {
130-
const id = createTestProvider('__test_stale');
131-
setDefaultProviderId(id);
132-
deleteProvider(id);
133-
// Now default_provider_id points to a non-existent provider
134-
135-
const resolved = resolveProvider({});
136-
137-
// Resolver should NOT have auto-fixed the stale default
138-
// (that would cause side effects during Doctor diagnostics)
139-
assert.equal(resolved.provider, undefined, 'should return undefined, not auto-heal');
129+
it('returns undefined provider when default points to deleted record and no other providers exist', () => {
130+
// Deactivate all existing providers so fallback chain doesn't find one
131+
const existing = getAllProviders();
132+
const deactivated: string[] = [];
133+
for (const p of existing) {
134+
if (p.is_active && !p.name.startsWith('__test_')) {
135+
getDb().prepare('UPDATE api_providers SET is_active = 0 WHERE id = ?').run(p.id);
136+
deactivated.push(p.id);
137+
}
138+
}
139+
try {
140+
const id = createTestProvider('__test_stale');
141+
setDefaultProviderId(id);
142+
deleteProvider(id);
143+
144+
const resolved = resolveProvider({});
145+
assert.equal(resolved.provider, undefined, 'should return undefined when no active providers exist');
146+
} finally {
147+
// Restore deactivated providers
148+
for (const pid of deactivated) {
149+
getDb().prepare('UPDATE api_providers SET is_active = 1 WHERE id = ?').run(pid);
150+
}
151+
}
140152
});
141153

142154
it('does not modify default_provider_id setting on read', () => {

0 commit comments

Comments
 (0)