fix(auto): address PR #2131 review issues

- Fix OAuth expiry handling for ISO strings in virtualFactory.ts
- Move AutoRoutingBanner test from src/ to tests/unit/shared/components/
- Remove mock metrics from analytics endpoint, return only real data
- Fix error handling for bare 'auto' prefix in chat.ts (check isAutoRouting)
- Update vitest.config.ts to include tests/unit/**/*.test.tsx pattern
This commit is contained in:
oyi77
2026-05-11 01:39:38 +07:00
parent e1ab7c9273
commit fbb4dfaf37
5 changed files with 14 additions and 19 deletions

View File

@@ -34,7 +34,12 @@ export async function createVirtualAutoCombo(
const validConnections = connections.filter((conn) => {
const hasApiKey = !!conn.apiKey;
const expiresAt = Number(conn.oauthExpiresAt) || 0;
let expiresAt: number;
if (typeof conn.oauthExpiresAt === "string") {
expiresAt = new Date(conn.oauthExpiresAt).getTime();
} else {
expiresAt = Number(conn.oauthExpiresAt) || 0;
}
const hasOAuthToken = !!conn.oauthToken && new Date(expiresAt) > new Date();
return hasApiKey || hasOAuthToken;
});

View File

@@ -59,22 +59,14 @@ export async function GET(request: Request) {
GROUP BY provider
ORDER BY count DESC
LIMIT 10
`
`
)
.all() as Array<{ provider: string; count: number }>;
// Mock metrics (would need actual scoring data from auto-combo engine)
const mockMetrics = {
avgSelectionScore: 0.85,
explorationRate: 0.05,
lkgpHitRate: 0.72,
};
return NextResponse.json({
totalRequests: totalRequests.count,
variantBreakdown,
topProviders,
...mockMetrics,
});
} catch (error) {
console.error("Auto-routing analytics error:", error);
@@ -82,9 +74,6 @@ export async function GET(request: Request) {
totalRequests: 0,
variantBreakdown: {},
topProviders: [],
avgSelectionScore: 0,
explorationRate: 0.05,
lkgpHitRate: 0,
});
}
}

View File

@@ -352,7 +352,7 @@ export async function handleChat(request: any, clientRawRequest: any = null) {
}
// Auto-prefix short-circuit: if auto/ prefix was detected, replace combo with virtual one
if (autoVariant !== undefined && combo === null) {
if (isAutoRouting && combo === null) {
try {
const { createVirtualAutoCombo } =
await import("@omniroute/open-sse/services/autoCombo/virtualFactory.ts");

View File

@@ -32,7 +32,7 @@ describe("AutoRoutingBanner", () => {
});
it("renders banner on first mount", async () => {
const { default: AutoRoutingBanner } = await import("./AutoRoutingBanner");
const { default: AutoRoutingBanner } = await import("@/shared/components/AutoRoutingBanner");
const container = makeContainer();
const root = createRoot(container);
await act(async () => {
@@ -43,7 +43,7 @@ describe("AutoRoutingBanner", () => {
});
it("includes link to Combos page", async () => {
const { default: AutoRoutingBanner } = await import("./AutoRoutingBanner");
const { default: AutoRoutingBanner } = await import("@/shared/components/AutoRoutingBanner");
const container = makeContainer();
const root = createRoot(container);
await act(async () => {
@@ -54,7 +54,7 @@ describe("AutoRoutingBanner", () => {
});
it("can be dismissed by clicking close button", async () => {
const { default: AutoRoutingBanner } = await import("./AutoRoutingBanner");
const { default: AutoRoutingBanner } = await import("@/shared/components/AutoRoutingBanner");
const container = makeContainer();
const root = createRoot(container);
await act(async () => {
@@ -70,7 +70,7 @@ describe("AutoRoutingBanner", () => {
});
it("persists dismissal to localStorage", async () => {
const { default: AutoRoutingBanner } = await import("./AutoRoutingBanner");
const { default: AutoRoutingBanner } = await import("@/shared/components/AutoRoutingBanner");
const container = makeContainer();
const root = createRoot(container);
await act(async () => {
@@ -85,7 +85,7 @@ describe("AutoRoutingBanner", () => {
it("remains hidden after dismissal on remount", async () => {
localStorage.setItem("auto-routing-banner-dismissed", "true");
const { default: AutoRoutingBanner } = await import("./AutoRoutingBanner");
const { default: AutoRoutingBanner } = await import("@/shared/components/AutoRoutingBanner");
const container = makeContainer();
const root = createRoot(container);
await act(async () => {

View File

@@ -13,6 +13,7 @@ export default defineConfig({
"src/lib/memory/__tests__/**/*.test.ts",
"src/lib/skills/__tests__/**/*.test.ts",
"tests/unit/encryption.test.ts",
"tests/unit/**/*.test.tsx",
"open-sse/**/__tests__/**/*.test.ts",
"open-sse/services/**/__tests__/**/*.test.ts",
"tests/e2e/ecosystem.test.ts",