feat(ai): add AI trace tracking and admin panel
Test Suite / backend-pr-quick (push) Has been skipped
Test Suite / quick-import-pr-quick (push) Has been skipped
Test Suite / backend-full (push) Successful in 12m45s
Test Suite / flutter-quality (push) Failing after 7m24s

- Add AiTrace model to Prisma schema with relations to User
- Implement AiTraceService with CRUD operations for AI traces
- Add new admin panel for AI traces with filtering and detail views
- Integrate trace persistence in receipt import flow
- Add API endpoints for listing and retrieving AI traces
- Update Flutter admin UI with new AI tab and navigation
- Add new domain models for AI traces and details
- Add migration for AiTrace table creation

BREAKING CHANGE: None
This commit is contained in:
Nils-Johan Gynther
2026-05-21 17:33:21 +02:00
parent c3520b5ad4
commit 67a7590525
21 changed files with 2477 additions and 509 deletions
@@ -12,12 +12,13 @@ describe('ReceiptImportService parseReceipt flow', () => {
cat(51, 'Godis', 'Glass, godis & snacks > Godis'),
];
const prismaMock = {
receiptAlias: { findMany: jest.fn() },
product: { findMany: jest.fn() },
unitMapping: { findMany: jest.fn() },
user: { findUnique: jest.fn() },
};
const prismaMock = {
aiTrace: { create: jest.fn() },
receiptAlias: { findMany: jest.fn() },
product: { findMany: jest.fn() },
unitMapping: { findMany: jest.fn() },
user: { findUnique: jest.fn() },
};
const aiServiceMock = {
suggestCategory: jest.fn(),
@@ -80,14 +81,21 @@ describe('ReceiptImportService parseReceipt flow', () => {
confidence: 'low',
});
jest
.spyOn(service as any, 'parseReceiptViaImporter')
.mockResolvedValue([
{ rawName: 'MIXAD VARA', quantity: 1, unit: 'st' },
{ rawName: 'GLOBAL CHOKLAD', quantity: 1, unit: 'st' },
{ rawName: 'SPECIALPRODUKT 1st', quantity: 1, unit: 'st' },
{ rawName: 'helt okänd vara', quantity: 1, unit: 'st' },
]);
jest
.spyOn(service as any, 'parseReceiptViaImporter')
.mockResolvedValue({
items: [
{ rawName: 'MIXAD VARA', quantity: 1, unit: 'st' },
{ rawName: 'GLOBAL CHOKLAD', quantity: 1, unit: 'st' },
{ rawName: 'SPECIALPRODUKT 1st', quantity: 1, unit: 'st' },
{ rawName: 'helt okänd vara', quantity: 1, unit: 'st' },
],
trace: {
prompt: 'test prompt',
rawOutput: '{"items":[]}',
normalizedOutput: { items: [] },
},
});
const file = {
buffer: Buffer.from('dummy'),