fix(confidence-engine): decouple app health from provider
This commit is contained in:
+1
-31
@@ -1,33 +1,3 @@
|
|||||||
import { getConfig } from "@/lib/config";
|
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
try {
|
return Response.json({ healthy: true }, { status: 200 });
|
||||||
const result = getConfig();
|
|
||||||
|
|
||||||
if (!result.ok) {
|
|
||||||
return Response.json({ healthy: false }, { status: 500 });
|
|
||||||
}
|
|
||||||
|
|
||||||
const { OLLAMA_BASE_URL, OLLAMA_MODEL } = result.config;
|
|
||||||
|
|
||||||
// Test reachability with a short timeout
|
|
||||||
let reachable = false;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const controller = new AbortController();
|
|
||||||
const timeout = setTimeout(() => controller.abort(), 3000);
|
|
||||||
|
|
||||||
const res = await fetch(`${OLLAMA_BASE_URL}/api/tags`, {
|
|
||||||
signal: controller.signal
|
|
||||||
});
|
|
||||||
clearTimeout(timeout);
|
|
||||||
reachable = res.ok;
|
|
||||||
} catch {
|
|
||||||
reachable = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Response.json({ healthy: reachable }, { status: reachable ? 200 : 503 });
|
|
||||||
} catch {
|
|
||||||
return Response.json({ healthy: false }, { status: 500 });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,23 +103,18 @@ describe("authenticated product boundary", () => {
|
|||||||
const response = await GET();
|
const response = await GET();
|
||||||
|
|
||||||
expect(mockGetAuthenticatedUser).not.toHaveBeenCalled();
|
expect(mockGetAuthenticatedUser).not.toHaveBeenCalled();
|
||||||
const body = await response.json();
|
expect(response.status).toBe(200);
|
||||||
expect(body).toHaveProperty("healthy");
|
await expect(response.json()).resolves.toEqual({ healthy: true });
|
||||||
// Must not expose private config details in the public response
|
|
||||||
expect(JSON.stringify(body)).not.toContain("baseUrl");
|
|
||||||
expect(JSON.stringify(body)).not.toContain("model");
|
|
||||||
expect(JSON.stringify(body)).not.toContain("ollama");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("reports unhealthy generic state when config is missing", async () => {
|
it("remains healthy when reasoning configuration is missing", async () => {
|
||||||
mockGetConfig.mockReturnValue({ ok: false });
|
mockGetConfig.mockReturnValue({ ok: false });
|
||||||
const { GET } = await import("@/app/api/health/route.js");
|
const { GET } = await import("@/app/api/health/route.js");
|
||||||
|
|
||||||
const response = await GET();
|
const response = await GET();
|
||||||
|
|
||||||
expect(response.status).toBe(500);
|
expect(response.status).toBe(200);
|
||||||
const body = await response.json();
|
await expect(response.json()).resolves.toEqual({ healthy: true });
|
||||||
expect(body).toEqual({ healthy: false });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not convert /api/health to 401 via middleware when unauthenticated", async () => {
|
it("does not convert /api/health to 401 via middleware when unauthenticated", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user