fix: address latest coderabbit review findings
This commit is contained in:
@@ -316,4 +316,37 @@ describe('accounts credential mode', { timeout: 15_000 }, () => {
|
||||
};
|
||||
expect(parsedCleared.sub2apiAuth).toBeUndefined();
|
||||
});
|
||||
|
||||
it('does not refresh models for pin-only account edits', async () => {
|
||||
const site = await db.insert(schema.sites).values({
|
||||
name: 'Pinned Site',
|
||||
url: 'https://pinned.example.com',
|
||||
platform: 'new-api',
|
||||
}).returning().get();
|
||||
const account = await db.insert(schema.accounts).values({
|
||||
siteId: site.id,
|
||||
username: 'pinned-user',
|
||||
accessToken: 'access-token',
|
||||
status: 'active',
|
||||
isPinned: false,
|
||||
sortOrder: 0,
|
||||
}).returning().get();
|
||||
|
||||
const response = await app.inject({
|
||||
method: 'PUT',
|
||||
url: `/api/accounts/${account.id}`,
|
||||
payload: {
|
||||
isPinned: true,
|
||||
sortOrder: 5,
|
||||
},
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(getModelsMock).not.toHaveBeenCalled();
|
||||
expect(verifyTokenMock).not.toHaveBeenCalled();
|
||||
|
||||
const updated = await db.select().from(schema.accounts).where(eq(schema.accounts.id, account.id)).get();
|
||||
expect(updated?.isPinned).toBe(true);
|
||||
expect(updated?.sortOrder).toBe(5);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1315,12 +1315,18 @@ export async function accountsRoutes(app: FastifyInstance) {
|
||||
explicitNextMode && explicitNextMode !== 'auto'
|
||||
? explicitNextMode
|
||||
: (hasSessionTokenValue(nextAccessToken) ? 'session' : 'apikey');
|
||||
const needsModelRefresh =
|
||||
Object.prototype.hasOwnProperty.call(body, 'accessToken')
|
||||
|| Object.prototype.hasOwnProperty.call(body, 'apiToken')
|
||||
|| Object.prototype.hasOwnProperty.call(body, 'extraConfig')
|
||||
|| Object.prototype.hasOwnProperty.call(body, 'proxyUrl')
|
||||
|| wantsManagedSub2ApiAuthPatch;
|
||||
|
||||
await convergeAccountMutation({
|
||||
accountId: id,
|
||||
preferredApiToken: nextCredentialMode !== 'apikey' ? updates.apiToken : null,
|
||||
defaultTokenSource: 'manual',
|
||||
refreshModels: true,
|
||||
refreshModels: needsModelRefresh,
|
||||
rebuildRoutes: true,
|
||||
continueOnError: true,
|
||||
});
|
||||
|
||||
@@ -24,6 +24,8 @@ describe('route refresh workflow architecture boundaries', () => {
|
||||
|
||||
expect(statsSource).toContain("from '../../services/routeRefreshWorkflow.js'");
|
||||
expectNoDirectModelServiceRouteRefresh(statsSource);
|
||||
expect(tokensSource).toContain('const rebuild = await routeRefreshWorkflow.rebuildRoutesOnly();');
|
||||
expect(statsSource).toContain('const rebuild = await routeRefreshWorkflow.rebuildRoutesOnly();');
|
||||
});
|
||||
|
||||
it('keeps proxy fallback refreshes and scheduler hooks on the route refresh workflow', () => {
|
||||
|
||||
@@ -1387,7 +1387,7 @@ export async function statsRoutes(app: FastifyInstance) {
|
||||
}
|
||||
|
||||
const refresh = await refreshModelsForAccount(accountId);
|
||||
const rebuild = routeRefreshWorkflow.rebuildRoutesOnly();
|
||||
const rebuild = await routeRefreshWorkflow.rebuildRoutesOnly();
|
||||
return { success: true, refresh, rebuild };
|
||||
});
|
||||
|
||||
|
||||
@@ -1168,11 +1168,11 @@ export async function tokensRoutes(app: FastifyInstance) {
|
||||
|
||||
// Rebuild routes/channels from model availability.
|
||||
app.post<{ Body?: { refreshModels?: boolean; wait?: boolean } }>('/api/routes/rebuild', async (request, reply) => {
|
||||
const body = (request.body || {}) as { refreshModels?: boolean };
|
||||
if (body.refreshModels === false) {
|
||||
const rebuild = routeRefreshWorkflow.rebuildRoutesOnly();
|
||||
return { success: true, rebuild };
|
||||
}
|
||||
const body = (request.body || {}) as { refreshModels?: boolean };
|
||||
if (body.refreshModels === false) {
|
||||
const rebuild = await routeRefreshWorkflow.rebuildRoutesOnly();
|
||||
return { success: true, rebuild };
|
||||
}
|
||||
|
||||
if ((request.body as { wait?: boolean } | undefined)?.wait) {
|
||||
const result = await routeRefreshWorkflow.refreshModelsAndRebuildRoutes();
|
||||
|
||||
@@ -154,6 +154,7 @@ describe('proxy route architecture boundaries', () => {
|
||||
expect(chatSurfaceSource).not.toContain('refreshOauthAccessTokenSingleflight(');
|
||||
expect(chatSurfaceSource).not.toContain('resolveProxyUsageWithSelfLogFallback(');
|
||||
expect(chatSurfaceSource).not.toContain('resolveProxyLogBilling(');
|
||||
expect((chatSurfaceSource.match(/bestEffortMetrics:/g) || []).length).toBeGreaterThanOrEqual(2);
|
||||
|
||||
expect(responsesSurfaceSource).toContain('trySurfaceOauthRefreshRecovery(');
|
||||
expect(responsesSurfaceSource).toContain('recordSurfaceSuccess(');
|
||||
|
||||
Reference in New Issue
Block a user