address comments
This commit is contained in:
@@ -130,4 +130,16 @@ describe('accounts manual models endpoint', () => {
|
|||||||
|
|
||||||
expect(response.statusCode).toBe(404);
|
expect(response.statusCode).toBe(404);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('returns validation error for empty models array', async () => {
|
||||||
|
const response = await app.inject({
|
||||||
|
method: 'POST',
|
||||||
|
url: '/api/accounts/1/models/manual',
|
||||||
|
payload: {
|
||||||
|
models: [],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(response.statusCode).toBe(400);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import Fastify, { type FastifyInstance } from 'fastify';
|
import Fastify, { type FastifyInstance } from 'fastify';
|
||||||
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
|
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||||
import { mkdtempSync } from 'node:fs';
|
import { mkdtempSync, rmSync } from 'node:fs';
|
||||||
import { tmpdir } from 'node:os';
|
import { tmpdir } from 'node:os';
|
||||||
import { join } from 'node:path';
|
import { join } from 'node:path';
|
||||||
|
|
||||||
@@ -50,6 +50,11 @@ describe('accounts skipModelFetch behavior', () => {
|
|||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
await app.close();
|
await app.close();
|
||||||
|
if (dataDir) {
|
||||||
|
try {
|
||||||
|
rmSync(dataDir, { recursive: true, force: true });
|
||||||
|
} catch { }
|
||||||
|
}
|
||||||
delete process.env.DATA_DIR;
|
delete process.env.DATA_DIR;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1432,30 +1432,32 @@ export async function accountsRoutes(app: FastifyInstance) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (const modelName of normalizedModels) {
|
await db.transaction(async (tx: any) => {
|
||||||
const existing = await db.select()
|
for (const modelName of normalizedModels) {
|
||||||
.from(schema.modelAvailability)
|
const existing = await tx.select()
|
||||||
.where(and(eq(schema.modelAvailability.accountId, accountId), eq(schema.modelAvailability.modelName, modelName)))
|
.from(schema.modelAvailability)
|
||||||
.get();
|
.where(and(eq(schema.modelAvailability.accountId, accountId), eq(schema.modelAvailability.modelName, modelName)))
|
||||||
|
.get();
|
||||||
|
|
||||||
if (existing) {
|
if (existing) {
|
||||||
if (!existing.available || !existing.isManual) {
|
if (!existing.available || !existing.isManual) {
|
||||||
await db.update(schema.modelAvailability)
|
await tx.update(schema.modelAvailability)
|
||||||
.set({ available: true, latencyMs: null, isManual: true, checkedAt: new Date().toISOString() })
|
.set({ available: true, latencyMs: null, isManual: true, checkedAt: new Date().toISOString() })
|
||||||
.where(eq(schema.modelAvailability.id, existing.id))
|
.where(eq(schema.modelAvailability.id, existing.id))
|
||||||
.run();
|
.run();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
await tx.insert(schema.modelAvailability).values({
|
||||||
|
accountId,
|
||||||
|
modelName,
|
||||||
|
available: true,
|
||||||
|
isManual: true,
|
||||||
|
latencyMs: null,
|
||||||
|
checkedAt: new Date().toISOString(),
|
||||||
|
}).run();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
await db.insert(schema.modelAvailability).values({
|
|
||||||
accountId,
|
|
||||||
modelName,
|
|
||||||
available: true,
|
|
||||||
isManual: true,
|
|
||||||
latencyMs: null,
|
|
||||||
checkedAt: new Date().toISOString(),
|
|
||||||
}).run();
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await rebuildTokenRoutesFromAvailability();
|
await rebuildTokenRoutesFromAvailability();
|
||||||
|
|||||||
@@ -354,7 +354,7 @@ describe('/v1/models route', () => {
|
|||||||
|
|
||||||
await db.insert(schema.downstreamApiKeys).values({
|
await db.insert(schema.downstreamApiKeys).values({
|
||||||
name: 'search-key',
|
name: 'search-key',
|
||||||
key: 'change-me-proxy-sk-token',
|
key: 'sk-search-key',
|
||||||
enabled: true,
|
enabled: true,
|
||||||
}).run();
|
}).run();
|
||||||
|
|
||||||
@@ -362,7 +362,7 @@ describe('/v1/models route', () => {
|
|||||||
method: 'GET',
|
method: 'GET',
|
||||||
url: '/v1/models',
|
url: '/v1/models',
|
||||||
headers: {
|
headers: {
|
||||||
authorization: 'Bearer change-me-proxy-sk-token',
|
authorization: 'Bearer sk-search-key',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user