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>
70 lines
2.9 KiB
TypeScript
70 lines
2.9 KiB
TypeScript
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
|
import { buildApp } from '@/app';
|
|
import { prismaClient } from '@/infrastructure/database';
|
|
import { FastifyInstance } from 'fastify';
|
|
import { loginAs, authHeader } from '../helpers/auth';
|
|
|
|
/** Covers specs/004-product-knowledge/quickstart.md Scenario 4 against a real Postgres. */
|
|
describe('Error codes and known issues', () => {
|
|
let app: FastifyInstance;
|
|
let token: string;
|
|
const externalProductId = `TEST_KNOWNISSUE_PROD_${Date.now()}`;
|
|
const errorCode = 'LAYOUT_PARSE_042';
|
|
|
|
beforeAll(async () => {
|
|
app = await buildApp();
|
|
token = await loginAs(app, 'ADMIN');
|
|
await prismaClient.product.create({
|
|
data: { externalProductId, name: 'Known Issue Test Product', status: 'active' },
|
|
});
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await prismaClient.knownIssue.deleteMany({ where: { product: { externalProductId } } });
|
|
// 015-reporting-dashboards: findKnownIssuesByErrorCode now also writes a durable
|
|
// ErrorCodeLookup row (RESTRICT FK to ErrorCode) — must be deleted before ErrorCode itself.
|
|
await prismaClient.errorCodeLookup.deleteMany({ where: { product: { externalProductId } } });
|
|
await prismaClient.errorCode.deleteMany({ where: { product: { externalProductId } } });
|
|
await prismaClient.product.deleteMany({ where: { externalProductId } });
|
|
await app.close();
|
|
});
|
|
|
|
it('Scenario 4: a known issue resolves by its error code in a single lookup', async () => {
|
|
const errorCodeResponse = await app.inject({
|
|
method: 'POST',
|
|
url: `/admin/products/${externalProductId}/error-codes`,
|
|
headers: authHeader(token),
|
|
payload: { code: errorCode, description: 'Layout parser failure' },
|
|
});
|
|
expect(errorCodeResponse.statusCode).toBe(201);
|
|
const { id: errorCodeId } = errorCodeResponse.json().data;
|
|
|
|
const knownIssueResponse = await app.inject({
|
|
method: 'POST',
|
|
url: `/admin/products/${externalProductId}/known-issues`,
|
|
headers: authHeader(token),
|
|
payload: { errorCodeId, description: 'Conversion fails for complex layouts' },
|
|
});
|
|
expect(knownIssueResponse.statusCode).toBe(201);
|
|
|
|
const lookupResponse = await app.inject({
|
|
method: 'GET',
|
|
url: `/admin/products/${externalProductId}/known-issues/by-error-code/${errorCode}`,
|
|
headers: authHeader(token),
|
|
});
|
|
expect(lookupResponse.statusCode).toBe(200);
|
|
const knownIssues = lookupResponse.json().data;
|
|
expect(knownIssues).toHaveLength(1);
|
|
expect(knownIssues[0].description).toBe('Conversion fails for complex layouts');
|
|
});
|
|
|
|
it('a lookup for a nonexistent error code returns 404', async () => {
|
|
const response = await app.inject({
|
|
method: 'GET',
|
|
url: `/admin/products/${externalProductId}/known-issues/by-error-code/NEVER_REGISTERED`,
|
|
headers: authHeader(token),
|
|
});
|
|
expect(response.statusCode).toBe(404);
|
|
});
|
|
});
|