From f13bd3c4c6a44a4a3f5deb0d9fcaf7252c543fb4 Mon Sep 17 00:00:00 2001 From: Nathan Hangen Date: Sun, 10 May 2026 21:34:15 -0400 Subject: [PATCH] test(mcp): assert documented bucket boundaries land in the Prom scrape The existing bucket tests pinned the exported JS constants; the views[] wiring in MeterProvider could be deleted and they would still pass. This test boots a real exporter, makes one observation, and asserts every documented boundary appears as an le= label on the bucket lines. --- gitnexus/test/unit/mcp/metrics.test.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/gitnexus/test/unit/mcp/metrics.test.ts b/gitnexus/test/unit/mcp/metrics.test.ts index 9c04ea0bf..e5e71c0d6 100644 --- a/gitnexus/test/unit/mcp/metrics.test.ts +++ b/gitnexus/test/unit/mcp/metrics.test.ts @@ -256,4 +256,28 @@ describe('bucket boundary contract', () => { it('publishes the documented result-size buckets verbatim', () => { expect(RESULT_BYTES_BUCKETS).toEqual([512, 2048, 8192, 32768, 131072, 524288, 2097152]); }); + + it('exposes the documented bucket boundaries in the Prometheus scrape', async () => { + process.env['GITNEXUS_OTEL_METRICS'] = 'on'; + await withRandomPort(async () => { + const init = await initMetrics(); + await observe( + 'context', + async () => ({ content: [{ type: 'text', text: 'x' }] }), + (r) => Buffer.byteLength(r.content[0]!.text, 'utf8'), + () => false, + ); + const text = await fetch(`http://127.0.0.1:${init.port}/metrics`).then((r) => r.text()); + for (const b of DURATION_BUCKETS_SECONDS) { + expect(text).toMatch( + new RegExp(`gitnexus_mcp_tool_request_duration_seconds_bucket\\{[^}]*le="${b}"\\}`), + ); + } + for (const b of RESULT_BYTES_BUCKETS) { + expect(text).toMatch( + new RegExp(`gitnexus_mcp_tool_result_bytes_bucket\\{[^}]*le="${b}"\\}`), + ); + } + }); + }); });