import test from 'node:test'
import assert from 'node:assert/strict'

import { incrementMetric, observeHttpRequest, renderPrometheusMetrics } from '../src/lite/observability.mjs'

test('observability renders Prometheus counters and duration summaries', () => {
  incrementMetric('dlbdi_test_counter_total', { scope: 'unit' })
  observeHttpRequest({
    method: 'GET',
    route: '/api/test',
    statusCode: 200,
    durationMs: 12,
  })

  const output = renderPrometheusMetrics()
  assert.match(output, /dlbdi_test_counter_total\{scope="unit"\} 1/)
  assert.match(output, /dlbdi_http_requests_total\{method="GET",route="\/api\/test",status="2xx"\} 1/)
  assert.match(output, /dlbdi_http_request_duration_ms_sum\{method="GET",route="\/api\/test",status="2xx"\} 12/)
})
