forked from boos/BoosAPI
fix failed expired api-key recovery route preservation (#421)
This commit is contained in:
@@ -175,6 +175,21 @@ describe('accounts api key recovery', { timeout: 15_000 }, () => {
|
||||
checkedAt: '2026-04-01T10:00:00.000Z',
|
||||
}).run();
|
||||
|
||||
const route = await db.insert(schema.tokenRoutes).values({
|
||||
modelPattern: 'gpt-4.1',
|
||||
enabled: true,
|
||||
}).returning().get();
|
||||
|
||||
const seededChannel = await db.insert(schema.routeChannels).values({
|
||||
routeId: route.id,
|
||||
accountId: account.id,
|
||||
tokenId: null,
|
||||
priority: 0,
|
||||
weight: 10,
|
||||
enabled: true,
|
||||
manualOverride: false,
|
||||
}).returning().get();
|
||||
|
||||
const response = await app.inject({
|
||||
method: 'PUT',
|
||||
url: `/api/accounts/${account.id}`,
|
||||
@@ -211,6 +226,11 @@ describe('accounts api key recovery', { timeout: 15_000 }, () => {
|
||||
});
|
||||
|
||||
const routeChannels = await db.select().from(schema.routeChannels).all();
|
||||
expect(routeChannels.some((channel) => channel.accountId === account.id)).toBe(false);
|
||||
expect(routeChannels).toContainEqual(expect.objectContaining({
|
||||
id: seededChannel.id,
|
||||
routeId: route.id,
|
||||
accountId: account.id,
|
||||
tokenId: null,
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17,6 +17,11 @@ type AccountUpdateWorkflowInput = {
|
||||
};
|
||||
|
||||
export async function applyAccountUpdateWorkflow(input: AccountUpdateWorkflowInput) {
|
||||
const isExpiredApiKeyRecoveryFlow = Boolean(
|
||||
input.preserveExpiredStatus
|
||||
&& input.allowInactiveModelRefresh
|
||||
&& input.reactivateAfterSuccessfulModelRefresh,
|
||||
);
|
||||
const persistedUpdates: Partial<typeof schema.accounts.$inferInsert> = {
|
||||
...input.updates,
|
||||
...(input.preserveExpiredStatus ? { status: 'expired' } : {}),
|
||||
@@ -51,7 +56,11 @@ export async function applyAccountUpdateWorkflow(input: AccountUpdateWorkflowInp
|
||||
.run();
|
||||
}
|
||||
|
||||
await rebuildRoutesBestEffort();
|
||||
const shouldRebuildRoutes = !isExpiredApiKeyRecoveryFlow
|
||||
|| convergence.modelRefreshResult?.status === 'success';
|
||||
if (shouldRebuildRoutes) {
|
||||
await rebuildRoutesBestEffort();
|
||||
}
|
||||
|
||||
const account = await db.select()
|
||||
.from(schema.accounts)
|
||||
|
||||
Reference in New Issue
Block a user