Add metrics, request logs, and graceful shutdown
ci / test (pull_request) Successful in 9s

This commit is contained in:
2026-07-21 18:03:43 +00:00
parent 4d30598e6b
commit efb0cb0447
8 changed files with 230 additions and 10 deletions
+19
View File
@@ -106,6 +106,25 @@ test("GET /loc accepts api_key query param as an unsafe fallback", async () => {
assert.equal(response.body.lineCount, 5);
});
test("GET /metrics is authenticated and exposes Prometheus counters", async () => {
const app = createApp({ ...baseConfig, apiKey: "secret" }, {
getHealth: () => ({ cacheEntries: 0, inFlight: 0, maxConcurrentScans: 4, activeScans: 0, queuedScans: 0 }),
getPublicKey: async () => "ssh-ed25519 AAAA",
getDefaultKeyName: () => "loc_via_git_ed25519",
count: async () => {
throw new Error("not used");
}
});
const unauthenticated = await request(app).get("/metrics");
const authenticated = await request(app).get("/metrics").set("x-api-key", "secret");
assert.equal(unauthenticated.status, 401);
assert.equal(authenticated.status, 200);
assert.match(authenticated.text, /loc_via_git_http_requests_total/);
assert.match(authenticated.text, /loc_via_git_scans_total 0/);
});
test("GET /loc/diff returns aggregate and language deltas", async () => {
const app = createApp(baseConfig, {
getHealth: () => ({ cacheEntries: 0, inFlight: 0, maxConcurrentScans: 4, activeScans: 0, queuedScans: 0 }),