Files
support_backend/tests/unit/platform/reports/confidence-distribution.test.ts
T
saqib mirandClaude Sonnet 5 d65683641a feat(015-reporting-dashboards): four real reporting/analytics endpoints
Wires the pre-scaffolded, unused platform/reports module (ReportsService
.generateSummaryReport previously returned {}) into four real, admin-
gated dashboards matching docs/09-testing-observability-cicd.md's own
table:

- GET /admin/reports/management: total cases, AI-resolved, human-
  escalated, resolved/open, SLA compliance/breaches, escalation count,
  average response/resolution time.
- GET /admin/reports/product/:externalProductId: support volume,
  problem-category breakdown, recurring problems, AI-resolution/human-
  escalation rate, top error codes.
- GET /admin/reports/support: current per-agent workload, SLA at-risk/
  breached counts, escalation count, response/resolution performance.
- GET /admin/reports/ai: AI resolution/human-handoff rate, failed-
  troubleshooting-then-escalated rate, knowledge-match rate, confidence
  distribution (reusing 005-ai-support's own decideConfidenceBand),
  tool invocation success/failure.

Every rate/average is number|null -- null means no qualifying data in
range, never a computed NaN or a misleading 0. Adds one new durable
table, ErrorCodeLookup, since 014-full-observability's own equivalent
metric is a process-lifetime Prometheus counter unusable for a
historical "top errors" report.

Verified end-to-end against real Postgres/Redis: every figure checked
against hand-computed expected values, including a no-activity range
(all-zero counts, all-null rates) and cross-product isolation.

Also fixes a real regression the new ErrorCodeLookup FK caused in the
pre-existing known-issues.test.ts (its afterAll deleted ErrorCode rows
before the now-referencing lookup rows).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-09 11:59:38 +05:30

30 lines
1.2 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { decideConfidenceBand } from '@/modules/ai-support/sessions';
import { aiConfig } from '@/config';
/**
* 015-reporting-dashboards research.md §7: the AI dashboard's confidence distribution reuses
* 005-ai-support's own decideConfidenceBand against the system-default thresholds, rather than
* reimplementing a threshold check — this test proves the reused function classifies values
* the way the dashboard's own bucketing loop (reports.service.ts) depends on.
*/
describe('AI dashboard confidence distribution reuses decideConfidenceBand', () => {
const policy = {
highThreshold: aiConfig.defaultHighConfidence,
lowThreshold: aiConfig.defaultLowConfidence,
};
it('classifies a high-confidence value as proceed', () => {
expect(decideConfidenceBand(policy.highThreshold, policy)).toBe('proceed');
});
it('classifies a low-confidence value as escalate', () => {
expect(decideConfidenceBand(policy.lowThreshold - 0.01, policy)).toBe('escalate');
});
it('classifies a mid-range value as ask', () => {
const midpoint = (policy.highThreshold + policy.lowThreshold) / 2;
expect(decideConfidenceBand(midpoint, policy)).toBe('ask');
});
});