@avi770/testteam 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +54 -0
- package/LICENSE +21 -0
- package/README.md +167 -0
- package/agents/01-analyst.ts +100 -0
- package/agents/02-seed-architect.ts +59 -0
- package/agents/03-test-generator.ts +191 -0
- package/agents/04-unit-runner.ts +160 -0
- package/agents/05-browser-crawler.ts +790 -0
- package/agents/06-api-exerciser.ts +311 -0
- package/agents/07-security-scout.ts +188 -0
- package/agents/08-a11y-guardian.ts +212 -0
- package/agents/09-healer.ts +228 -0
- package/agents/10-reporter.ts +266 -0
- package/agents/11-fixer.ts +253 -0
- package/agents/12-ux-inspector.ts +444 -0
- package/agents/13-performance-profiler.ts +271 -0
- package/agents/14-data-integrity-auditor.ts +417 -0
- package/agents/15-regression-sentinel.ts +307 -0
- package/agents/16-chaos-agent.ts +228 -0
- package/agents/17-documentation-validator.ts +266 -0
- package/agents/18-integration-watchdog.ts +178 -0
- package/agents/19-tenant-isolation-auditor.ts +199 -0
- package/agents/20-workflow-completion-tester.ts +203 -0
- package/agents/21-state-session-tester.ts +262 -0
- package/agents/22-email-notification-verifier.ts +244 -0
- package/agents/23-migration-tester.ts +80 -0
- package/agents/__tests__/01-analyst.test.ts +188 -0
- package/agents/__tests__/02-seed-architect.test.ts +152 -0
- package/agents/__tests__/03-test-generator-full.test.ts +321 -0
- package/agents/__tests__/03-test-generator.test.ts +318 -0
- package/agents/__tests__/04-unit-runner.test.ts +320 -0
- package/agents/__tests__/05-browser-crawler-beta.test.ts +492 -0
- package/agents/__tests__/05-browser-crawler-release.test.ts +412 -0
- package/agents/__tests__/05-browser-crawler-uat.test.ts +578 -0
- package/agents/__tests__/05-browser-crawler.test.ts +518 -0
- package/agents/__tests__/06-api-exerciser.test.ts +619 -0
- package/agents/__tests__/07-security-scout.test.ts +382 -0
- package/agents/__tests__/08-a11y-guardian.test.ts +530 -0
- package/agents/__tests__/09-healer.test.ts +384 -0
- package/agents/__tests__/10-reporter.test.ts +366 -0
- package/agents/__tests__/11-fixer.test.ts +406 -0
- package/agents/__tests__/12-ux-inspector-extended.test.ts +465 -0
- package/agents/__tests__/12-ux-inspector.test.ts +443 -0
- package/agents/__tests__/13-performance-profiler.test.ts +411 -0
- package/agents/__tests__/14-data-integrity-auditor-extended.test.ts +573 -0
- package/agents/__tests__/14-data-integrity-auditor.test.ts +407 -0
- package/agents/__tests__/15-regression-sentinel.test.ts +657 -0
- package/agents/__tests__/16-chaos-agent.test.ts +427 -0
- package/agents/__tests__/17-documentation-validator.test.ts +402 -0
- package/agents/__tests__/18-integration-watchdog.test.ts +263 -0
- package/agents/__tests__/19-tenant-isolation-auditor.test.ts +400 -0
- package/agents/__tests__/20-workflow-completion-tester.test.ts +586 -0
- package/agents/__tests__/21-state-session-tester.test.ts +374 -0
- package/agents/__tests__/22-email-notification-verifier.test.ts +441 -0
- package/agents/__tests__/23-migration-tester.test.ts +145 -0
- package/agents/__tests__/base-agent.test.ts +188 -0
- package/agents/__tests__/registry.test.ts +218 -0
- package/agents/base-agent.ts +77 -0
- package/agents/registry.ts +136 -0
- package/baselines/api-schemas/.gitkeep +0 -0
- package/baselines/performance/.gitkeep +0 -0
- package/baselines/screenshots/.gitkeep +0 -0
- package/bin/testteam.js +10 -0
- package/core/__tests__/ci-output.test.ts +430 -0
- package/core/__tests__/cli.test.ts +387 -0
- package/core/__tests__/config.test.ts +78 -0
- package/core/__tests__/cost-tracker.test.ts +158 -0
- package/core/__tests__/evidence.test.ts +265 -0
- package/core/__tests__/fix-loop.test.ts +210 -0
- package/core/__tests__/health-check.test.ts +44 -0
- package/core/__tests__/init.test.ts +609 -0
- package/core/__tests__/integration.test.ts +204 -0
- package/core/__tests__/license-gen.test.ts +227 -0
- package/core/__tests__/license.test.ts +326 -0
- package/core/__tests__/multi-browser.test.ts +278 -0
- package/core/__tests__/orchestrator.test.ts +519 -0
- package/core/__tests__/phase-gate.test.ts +43 -0
- package/core/__tests__/report-html.test.ts +398 -0
- package/core/__tests__/report-upload.test.ts +325 -0
- package/core/__tests__/run-counter.test.ts +234 -0
- package/core/ci-output.ts +240 -0
- package/core/cli.ts +232 -0
- package/core/config.ts +178 -0
- package/core/cost-tracker.ts +59 -0
- package/core/evidence.ts +132 -0
- package/core/fix-loop.ts +85 -0
- package/core/health-check.ts +54 -0
- package/core/init.ts +546 -0
- package/core/license-gen.ts +212 -0
- package/core/license.ts +211 -0
- package/core/messages.ts +67 -0
- package/core/multi-browser.ts +136 -0
- package/core/orchestrator.ts +354 -0
- package/core/phase-gate.ts +55 -0
- package/core/report-html.ts +657 -0
- package/core/report-upload.ts +188 -0
- package/core/run-counter.ts +175 -0
- package/core/types.ts +57 -0
- package/dist/agents/01-analyst.d.ts +11 -0
- package/dist/agents/01-analyst.d.ts.map +1 -0
- package/dist/agents/01-analyst.js +75 -0
- package/dist/agents/01-analyst.js.map +1 -0
- package/dist/agents/02-seed-architect.d.ts +11 -0
- package/dist/agents/02-seed-architect.d.ts.map +1 -0
- package/dist/agents/02-seed-architect.js +51 -0
- package/dist/agents/02-seed-architect.js.map +1 -0
- package/dist/agents/03-test-generator.d.ts +9 -0
- package/dist/agents/03-test-generator.d.ts.map +1 -0
- package/dist/agents/03-test-generator.js +167 -0
- package/dist/agents/03-test-generator.js.map +1 -0
- package/dist/agents/04-unit-runner.d.ts +9 -0
- package/dist/agents/04-unit-runner.d.ts.map +1 -0
- package/dist/agents/04-unit-runner.js +113 -0
- package/dist/agents/04-unit-runner.js.map +1 -0
- package/dist/agents/05-browser-crawler.d.ts +30 -0
- package/dist/agents/05-browser-crawler.d.ts.map +1 -0
- package/dist/agents/05-browser-crawler.js +685 -0
- package/dist/agents/05-browser-crawler.js.map +1 -0
- package/dist/agents/06-api-exerciser.d.ts +23 -0
- package/dist/agents/06-api-exerciser.d.ts.map +1 -0
- package/dist/agents/06-api-exerciser.js +253 -0
- package/dist/agents/06-api-exerciser.js.map +1 -0
- package/dist/agents/07-security-scout.d.ts +11 -0
- package/dist/agents/07-security-scout.d.ts.map +1 -0
- package/dist/agents/07-security-scout.js +142 -0
- package/dist/agents/07-security-scout.js.map +1 -0
- package/dist/agents/08-a11y-guardian.d.ts +13 -0
- package/dist/agents/08-a11y-guardian.d.ts.map +1 -0
- package/dist/agents/08-a11y-guardian.js +176 -0
- package/dist/agents/08-a11y-guardian.js.map +1 -0
- package/dist/agents/09-healer.d.ts +33 -0
- package/dist/agents/09-healer.d.ts.map +1 -0
- package/dist/agents/09-healer.js +167 -0
- package/dist/agents/09-healer.js.map +1 -0
- package/dist/agents/10-reporter.d.ts +26 -0
- package/dist/agents/10-reporter.d.ts.map +1 -0
- package/dist/agents/10-reporter.js +215 -0
- package/dist/agents/10-reporter.js.map +1 -0
- package/dist/agents/11-fixer.d.ts +26 -0
- package/dist/agents/11-fixer.d.ts.map +1 -0
- package/dist/agents/11-fixer.js +195 -0
- package/dist/agents/11-fixer.js.map +1 -0
- package/dist/agents/12-ux-inspector.d.ts +15 -0
- package/dist/agents/12-ux-inspector.d.ts.map +1 -0
- package/dist/agents/12-ux-inspector.js +364 -0
- package/dist/agents/12-ux-inspector.js.map +1 -0
- package/dist/agents/13-performance-profiler.d.ts +13 -0
- package/dist/agents/13-performance-profiler.d.ts.map +1 -0
- package/dist/agents/13-performance-profiler.js +216 -0
- package/dist/agents/13-performance-profiler.js.map +1 -0
- package/dist/agents/14-data-integrity-auditor.d.ts +12 -0
- package/dist/agents/14-data-integrity-auditor.d.ts.map +1 -0
- package/dist/agents/14-data-integrity-auditor.js +356 -0
- package/dist/agents/14-data-integrity-auditor.js.map +1 -0
- package/dist/agents/15-regression-sentinel.d.ts +25 -0
- package/dist/agents/15-regression-sentinel.d.ts.map +1 -0
- package/dist/agents/15-regression-sentinel.js +251 -0
- package/dist/agents/15-regression-sentinel.js.map +1 -0
- package/dist/agents/16-chaos-agent.d.ts +9 -0
- package/dist/agents/16-chaos-agent.d.ts.map +1 -0
- package/dist/agents/16-chaos-agent.js +207 -0
- package/dist/agents/16-chaos-agent.js.map +1 -0
- package/dist/agents/17-documentation-validator.d.ts +31 -0
- package/dist/agents/17-documentation-validator.d.ts.map +1 -0
- package/dist/agents/17-documentation-validator.js +246 -0
- package/dist/agents/17-documentation-validator.js.map +1 -0
- package/dist/agents/18-integration-watchdog.d.ts +10 -0
- package/dist/agents/18-integration-watchdog.d.ts.map +1 -0
- package/dist/agents/18-integration-watchdog.js +138 -0
- package/dist/agents/18-integration-watchdog.js.map +1 -0
- package/dist/agents/19-tenant-isolation-auditor.d.ts +9 -0
- package/dist/agents/19-tenant-isolation-auditor.d.ts.map +1 -0
- package/dist/agents/19-tenant-isolation-auditor.js +166 -0
- package/dist/agents/19-tenant-isolation-auditor.js.map +1 -0
- package/dist/agents/20-workflow-completion-tester.d.ts +12 -0
- package/dist/agents/20-workflow-completion-tester.d.ts.map +1 -0
- package/dist/agents/20-workflow-completion-tester.js +159 -0
- package/dist/agents/20-workflow-completion-tester.js.map +1 -0
- package/dist/agents/21-state-session-tester.d.ts +10 -0
- package/dist/agents/21-state-session-tester.d.ts.map +1 -0
- package/dist/agents/21-state-session-tester.js +233 -0
- package/dist/agents/21-state-session-tester.js.map +1 -0
- package/dist/agents/22-email-notification-verifier.d.ts +11 -0
- package/dist/agents/22-email-notification-verifier.d.ts.map +1 -0
- package/dist/agents/22-email-notification-verifier.js +199 -0
- package/dist/agents/22-email-notification-verifier.js.map +1 -0
- package/dist/agents/23-migration-tester.d.ts +10 -0
- package/dist/agents/23-migration-tester.d.ts.map +1 -0
- package/dist/agents/23-migration-tester.js +74 -0
- package/dist/agents/23-migration-tester.js.map +1 -0
- package/dist/agents/base-agent.d.ts +19 -0
- package/dist/agents/base-agent.d.ts.map +1 -0
- package/dist/agents/base-agent.js +67 -0
- package/dist/agents/base-agent.js.map +1 -0
- package/dist/agents/registry.d.ts +29 -0
- package/dist/agents/registry.d.ts.map +1 -0
- package/dist/agents/registry.js +117 -0
- package/dist/agents/registry.js.map +1 -0
- package/dist/core/ci-output.d.ts +35 -0
- package/dist/core/ci-output.d.ts.map +1 -0
- package/dist/core/ci-output.js +193 -0
- package/dist/core/ci-output.js.map +1 -0
- package/dist/core/cli.d.ts +11 -0
- package/dist/core/cli.d.ts.map +1 -0
- package/dist/core/cli.js +197 -0
- package/dist/core/cli.js.map +1 -0
- package/dist/core/config.d.ts +111 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +42 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/cost-tracker.d.ts +22 -0
- package/dist/core/cost-tracker.d.ts.map +1 -0
- package/dist/core/cost-tracker.js +41 -0
- package/dist/core/cost-tracker.js.map +1 -0
- package/dist/core/evidence.d.ts +28 -0
- package/dist/core/evidence.d.ts.map +1 -0
- package/dist/core/evidence.js +95 -0
- package/dist/core/evidence.js.map +1 -0
- package/dist/core/fix-loop.d.ts +29 -0
- package/dist/core/fix-loop.d.ts.map +1 -0
- package/dist/core/fix-loop.js +70 -0
- package/dist/core/fix-loop.js.map +1 -0
- package/dist/core/health-check.d.ts +21 -0
- package/dist/core/health-check.d.ts.map +1 -0
- package/dist/core/health-check.js +26 -0
- package/dist/core/health-check.js.map +1 -0
- package/dist/core/init.d.ts +2 -0
- package/dist/core/init.d.ts.map +1 -0
- package/dist/core/init.js +435 -0
- package/dist/core/init.js.map +1 -0
- package/dist/core/license-gen.d.ts +12 -0
- package/dist/core/license-gen.d.ts.map +1 -0
- package/dist/core/license-gen.js +169 -0
- package/dist/core/license-gen.js.map +1 -0
- package/dist/core/license.d.ts +33 -0
- package/dist/core/license.d.ts.map +1 -0
- package/dist/core/license.js +170 -0
- package/dist/core/license.js.map +1 -0
- package/dist/core/messages.d.ts +10 -0
- package/dist/core/messages.d.ts.map +1 -0
- package/dist/core/messages.js +47 -0
- package/dist/core/messages.js.map +1 -0
- package/dist/core/multi-browser.d.ts +36 -0
- package/dist/core/multi-browser.d.ts.map +1 -0
- package/dist/core/multi-browser.js +88 -0
- package/dist/core/multi-browser.js.map +1 -0
- package/dist/core/orchestrator.d.ts +48 -0
- package/dist/core/orchestrator.d.ts.map +1 -0
- package/dist/core/orchestrator.js +291 -0
- package/dist/core/orchestrator.js.map +1 -0
- package/dist/core/phase-gate.d.ts +4 -0
- package/dist/core/phase-gate.d.ts.map +1 -0
- package/dist/core/phase-gate.js +39 -0
- package/dist/core/phase-gate.js.map +1 -0
- package/dist/core/report-html.d.ts +9 -0
- package/dist/core/report-html.d.ts.map +1 -0
- package/dist/core/report-html.js +617 -0
- package/dist/core/report-html.js.map +1 -0
- package/dist/core/report-upload.d.ts +16 -0
- package/dist/core/report-upload.d.ts.map +1 -0
- package/dist/core/report-upload.js +124 -0
- package/dist/core/report-upload.js.map +1 -0
- package/dist/core/run-counter.d.ts +40 -0
- package/dist/core/run-counter.d.ts.map +1 -0
- package/dist/core/run-counter.js +120 -0
- package/dist/core/run-counter.js.map +1 -0
- package/dist/core/types.d.ts +53 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +2 -0
- package/dist/core/types.js.map +1 -0
- package/dist/helpers/api-client.d.ts +30 -0
- package/dist/helpers/api-client.d.ts.map +1 -0
- package/dist/helpers/api-client.js +77 -0
- package/dist/helpers/api-client.js.map +1 -0
- package/dist/helpers/element-discovery.d.ts +18 -0
- package/dist/helpers/element-discovery.d.ts.map +1 -0
- package/dist/helpers/element-discovery.js +82 -0
- package/dist/helpers/element-discovery.js.map +1 -0
- package/dist/helpers/env-resolver.d.ts +29 -0
- package/dist/helpers/env-resolver.d.ts.map +1 -0
- package/dist/helpers/env-resolver.js +51 -0
- package/dist/helpers/env-resolver.js.map +1 -0
- package/dist/helpers/form-filler.d.ts +13 -0
- package/dist/helpers/form-filler.d.ts.map +1 -0
- package/dist/helpers/form-filler.js +98 -0
- package/dist/helpers/form-filler.js.map +1 -0
- package/dist/helpers/modal-handler.d.ts +16 -0
- package/dist/helpers/modal-handler.d.ts.map +1 -0
- package/dist/helpers/modal-handler.js +95 -0
- package/dist/helpers/modal-handler.js.map +1 -0
- package/dist/helpers/navigation.d.ts +37 -0
- package/dist/helpers/navigation.d.ts.map +1 -0
- package/dist/helpers/navigation.js +83 -0
- package/dist/helpers/navigation.js.map +1 -0
- package/dist/helpers/quality-gate.d.ts +17 -0
- package/dist/helpers/quality-gate.d.ts.map +1 -0
- package/dist/helpers/quality-gate.js +144 -0
- package/dist/helpers/quality-gate.js.map +1 -0
- package/dist/helpers/screenshot.d.ts +24 -0
- package/dist/helpers/screenshot.d.ts.map +1 -0
- package/dist/helpers/screenshot.js +76 -0
- package/dist/helpers/screenshot.js.map +1 -0
- package/dist/helpers/seed-validator.d.ts +15 -0
- package/dist/helpers/seed-validator.d.ts.map +1 -0
- package/dist/helpers/seed-validator.js +53 -0
- package/dist/helpers/seed-validator.js.map +1 -0
- package/helpers/__tests__/api-client.test.ts +199 -0
- package/helpers/__tests__/element-discovery.test.ts +202 -0
- package/helpers/__tests__/form-filler-extended.test.ts +212 -0
- package/helpers/__tests__/form-filler.test.ts +99 -0
- package/helpers/__tests__/modal-handler.test.ts +152 -0
- package/helpers/__tests__/navigation.test.ts +214 -0
- package/helpers/__tests__/quality-gate.test.ts +117 -0
- package/helpers/__tests__/screenshot.test.ts +139 -0
- package/helpers/__tests__/seed-validator.test.ts +114 -0
- package/helpers/api-client.ts +111 -0
- package/helpers/element-discovery.ts +105 -0
- package/helpers/env-resolver.ts +69 -0
- package/helpers/form-filler.ts +126 -0
- package/helpers/modal-handler.ts +108 -0
- package/helpers/navigation.ts +100 -0
- package/helpers/quality-gate.ts +180 -0
- package/helpers/screenshot.ts +111 -0
- package/helpers/seed-validator.ts +70 -0
- package/package.json +88 -0
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import type { ValidatedConfig } from '../../core/config';
|
|
3
|
+
import type { Phase } from '../../core/types';
|
|
4
|
+
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
// Stub config
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
|
|
9
|
+
const stubConfig = {
|
|
10
|
+
schemaVersion: 1,
|
|
11
|
+
name: 'test',
|
|
12
|
+
auth: {
|
|
13
|
+
loginUrl: 'http://localhost/login',
|
|
14
|
+
credentials: { admin: { email: 'admin@test.com', password: 'secret' } },
|
|
15
|
+
},
|
|
16
|
+
modules: [{ id: 'clients', route: '/clients', sidebarIcon: true }],
|
|
17
|
+
environments: {
|
|
18
|
+
beta: { baseUrl: 'http://localhost:3000', seed: false },
|
|
19
|
+
},
|
|
20
|
+
portals: [],
|
|
21
|
+
breakpoints: [],
|
|
22
|
+
integrations: [],
|
|
23
|
+
workers: [],
|
|
24
|
+
workflows: [],
|
|
25
|
+
accuracy: { enabled: true, decimalPrecision: 2, currencySymbol: '$', timezone: 'UTC' },
|
|
26
|
+
tenancy: { enabled: false, isolationField: 'firmId', testFirms: [] },
|
|
27
|
+
costBudget: { maxPerRun: 100, maxPerAgent: 10, alertThreshold: 0.8, onExceeded: 'abort' as const },
|
|
28
|
+
agentClassification: { blocking: [], advisory: [] },
|
|
29
|
+
thresholds: {
|
|
30
|
+
unitCoverage: { lines: 80, functions: 80, branches: 80, statements: 80 },
|
|
31
|
+
lighthouse: { accessibility: 90, performance: 90, bestPractices: 90, seo: 90 },
|
|
32
|
+
apiResponseTime: 2000,
|
|
33
|
+
bundleSizeLimit: 500000,
|
|
34
|
+
maxConsoleErrors: 0,
|
|
35
|
+
},
|
|
36
|
+
disabledAgents: [],
|
|
37
|
+
disabledAgentSet: new Set<number>(),
|
|
38
|
+
} satisfies ValidatedConfig;
|
|
39
|
+
|
|
40
|
+
const stubConfigAccuracyDisabled: ValidatedConfig = {
|
|
41
|
+
...stubConfig,
|
|
42
|
+
accuracy: { ...stubConfig.accuracy, enabled: false },
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// ---------------------------------------------------------------------------
|
|
46
|
+
// Mock fetch (used in preFlight isUrlReachable)
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
|
|
49
|
+
const fetchMock = vi.fn();
|
|
50
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
51
|
+
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
// Mock ApiClient
|
|
54
|
+
// ---------------------------------------------------------------------------
|
|
55
|
+
|
|
56
|
+
type MockApiResponse = { status: number; body: unknown; headers: Record<string, string>; durationMs: number };
|
|
57
|
+
|
|
58
|
+
interface MockApiClientInstance {
|
|
59
|
+
get: ReturnType<typeof vi.fn>;
|
|
60
|
+
post: ReturnType<typeof vi.fn>;
|
|
61
|
+
put: ReturnType<typeof vi.fn>;
|
|
62
|
+
delete: ReturnType<typeof vi.fn>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const mockApiClientInstance: MockApiClientInstance = {
|
|
66
|
+
get: vi.fn(),
|
|
67
|
+
post: vi.fn(),
|
|
68
|
+
put: vi.fn(),
|
|
69
|
+
delete: vi.fn(),
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const createAuthenticatedMock = vi.fn().mockResolvedValue(mockApiClientInstance);
|
|
73
|
+
|
|
74
|
+
vi.mock('../../helpers/api-client', () => ({
|
|
75
|
+
ApiClient: {
|
|
76
|
+
createAuthenticated: (...args: unknown[]) => createAuthenticatedMock(...args),
|
|
77
|
+
},
|
|
78
|
+
}));
|
|
79
|
+
|
|
80
|
+
// ---------------------------------------------------------------------------
|
|
81
|
+
// Helper to build mock API responses
|
|
82
|
+
// ---------------------------------------------------------------------------
|
|
83
|
+
|
|
84
|
+
function ok(body: unknown): MockApiResponse {
|
|
85
|
+
return { status: 200, body, headers: {}, durationMs: 10 };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function created(body: unknown): MockApiResponse {
|
|
89
|
+
return { status: 201, body, headers: {}, durationMs: 10 };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function noContent(): MockApiResponse {
|
|
93
|
+
return { status: 204, body: null, headers: {}, durationMs: 10 };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function notFound(): MockApiResponse {
|
|
97
|
+
return { status: 404, body: { message: 'Not Found' }, headers: {}, durationMs: 10 };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function serverError(): MockApiResponse {
|
|
101
|
+
return { status: 500, body: { message: 'Error' }, headers: {}, durationMs: 10 };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// ---------------------------------------------------------------------------
|
|
105
|
+
// Dynamic import AFTER mocks
|
|
106
|
+
// ---------------------------------------------------------------------------
|
|
107
|
+
|
|
108
|
+
const { DataIntegrityAuditorAgent } = await import('../14-data-integrity-auditor');
|
|
109
|
+
|
|
110
|
+
function createAgent(
|
|
111
|
+
config: ValidatedConfig = stubConfig,
|
|
112
|
+
phase: Phase = 'beta',
|
|
113
|
+
): InstanceType<typeof DataIntegrityAuditorAgent> {
|
|
114
|
+
return new DataIntegrityAuditorAgent(config, phase, '/tmp/test-run');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// ---------------------------------------------------------------------------
|
|
118
|
+
// Tests
|
|
119
|
+
// ---------------------------------------------------------------------------
|
|
120
|
+
|
|
121
|
+
describe('DataIntegrityAuditorAgent', () => {
|
|
122
|
+
beforeEach(() => {
|
|
123
|
+
fetchMock.mockReset().mockResolvedValue({ ok: true, status: 200 });
|
|
124
|
+
createAuthenticatedMock.mockReset().mockResolvedValue(mockApiClientInstance);
|
|
125
|
+
mockApiClientInstance.get.mockReset();
|
|
126
|
+
mockApiClientInstance.post.mockReset();
|
|
127
|
+
mockApiClientInstance.put.mockReset();
|
|
128
|
+
mockApiClientInstance.delete.mockReset();
|
|
129
|
+
|
|
130
|
+
// Default happy-path CRUD responses
|
|
131
|
+
const clientRecord = {
|
|
132
|
+
id: 'test-id-123',
|
|
133
|
+
name: 'TF-DataIntegrity-Test',
|
|
134
|
+
email: 'tf-integrity-test@test.invalid',
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
mockApiClientInstance.post.mockResolvedValue(created(clientRecord));
|
|
138
|
+
mockApiClientInstance.get.mockResolvedValue(ok(clientRecord));
|
|
139
|
+
mockApiClientInstance.put.mockResolvedValue(ok({ ...clientRecord, name: 'TF-DataIntegrity-Updated' }));
|
|
140
|
+
mockApiClientInstance.delete.mockResolvedValue(noContent());
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('has agentId 14 and agentName "Data Integrity Auditor"', () => {
|
|
144
|
+
const agent = createAgent();
|
|
145
|
+
expect(agent.agentId).toBe(14);
|
|
146
|
+
expect(agent.agentName).toBe('Data Integrity Auditor');
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
// -------------------------------------------------------------------------
|
|
150
|
+
// preFlight()
|
|
151
|
+
// -------------------------------------------------------------------------
|
|
152
|
+
|
|
153
|
+
describe('preFlight()', () => {
|
|
154
|
+
it('throws when accuracy.enabled is false', async () => {
|
|
155
|
+
const agent = createAgent(stubConfigAccuracyDisabled);
|
|
156
|
+
const result = await agent.run();
|
|
157
|
+
|
|
158
|
+
expect(result.status).toBe('failed');
|
|
159
|
+
expect(result.findings[0].description).toContain('accuracy.enabled is false');
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('throws when base URL is not reachable', async () => {
|
|
163
|
+
fetchMock.mockRejectedValue(new Error('ECONNREFUSED'));
|
|
164
|
+
|
|
165
|
+
const agent = createAgent();
|
|
166
|
+
const result = await agent.run();
|
|
167
|
+
|
|
168
|
+
expect(result.status).toBe('failed');
|
|
169
|
+
expect(result.findings[0].description).toContain('not reachable');
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('passes when accuracy enabled and URL reachable', async () => {
|
|
173
|
+
const agent = createAgent();
|
|
174
|
+
const result = await agent.run();
|
|
175
|
+
|
|
176
|
+
expect(result.findings.some((f) => f.description.includes('accuracy.enabled'))).toBe(false);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// -------------------------------------------------------------------------
|
|
181
|
+
// CRUD round-trip
|
|
182
|
+
// -------------------------------------------------------------------------
|
|
183
|
+
|
|
184
|
+
describe('CRUD round-trip', () => {
|
|
185
|
+
it('returns no findings when create→read fields match', async () => {
|
|
186
|
+
// The agent generates a unique email using Date.now() so we capture the
|
|
187
|
+
// post body and echo it back in the get response to ensure fields match.
|
|
188
|
+
let capturedCreateBody: Record<string, unknown> = {};
|
|
189
|
+
|
|
190
|
+
mockApiClientInstance.post.mockImplementation(async (_path: string, body: unknown) => {
|
|
191
|
+
capturedCreateBody = body as Record<string, unknown>;
|
|
192
|
+
return created({ id: 'abc-123', ...capturedCreateBody, createdAt: '2026-03-27T10:00:00Z' });
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
let getCallCount = 0;
|
|
196
|
+
mockApiClientInstance.get.mockImplementation(async () => {
|
|
197
|
+
getCallCount++;
|
|
198
|
+
if (getCallCount === 1) {
|
|
199
|
+
// read after create — echo back captured body
|
|
200
|
+
return ok({ id: 'abc-123', ...capturedCreateBody, createdAt: '2026-03-27T10:00:00Z' });
|
|
201
|
+
}
|
|
202
|
+
if (getCallCount === 2) {
|
|
203
|
+
// read after update — return updated name
|
|
204
|
+
return ok({ id: 'abc-123', ...capturedCreateBody, name: 'TF-DataIntegrity-Updated', createdAt: '2026-03-27T10:00:00Z' });
|
|
205
|
+
}
|
|
206
|
+
// read after delete — 404
|
|
207
|
+
return notFound();
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
mockApiClientInstance.put.mockResolvedValue(
|
|
211
|
+
ok({ id: 'abc-123', name: 'TF-DataIntegrity-Updated', createdAt: '2026-03-27T10:00:00Z' }),
|
|
212
|
+
);
|
|
213
|
+
mockApiClientInstance.delete.mockResolvedValue(noContent());
|
|
214
|
+
|
|
215
|
+
const agent = createAgent();
|
|
216
|
+
const result = await agent.run();
|
|
217
|
+
|
|
218
|
+
expect(result.findings).toHaveLength(0);
|
|
219
|
+
expect(result.status).toBe('passed');
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it('creates a finding when read returns mismatched name field', async () => {
|
|
223
|
+
const created_record = {
|
|
224
|
+
id: 'abc-123',
|
|
225
|
+
name: 'TF-DataIntegrity-Test',
|
|
226
|
+
email: 'tf-integrity-test@test.invalid',
|
|
227
|
+
createdAt: '2026-03-27T10:00:00Z',
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
const mismatched_record = {
|
|
231
|
+
...created_record,
|
|
232
|
+
name: 'WRONG-NAME', // mismatch!
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
mockApiClientInstance.post
|
|
236
|
+
.mockResolvedValueOnce(created(created_record))
|
|
237
|
+
.mockResolvedValue(serverError());
|
|
238
|
+
|
|
239
|
+
mockApiClientInstance.get
|
|
240
|
+
.mockResolvedValueOnce(ok(mismatched_record))
|
|
241
|
+
.mockResolvedValue(ok({ ...mismatched_record, name: 'TF-DataIntegrity-Updated' }));
|
|
242
|
+
|
|
243
|
+
mockApiClientInstance.put.mockResolvedValueOnce(ok({ ...mismatched_record }));
|
|
244
|
+
mockApiClientInstance.delete.mockResolvedValueOnce(noContent());
|
|
245
|
+
|
|
246
|
+
const agent = createAgent();
|
|
247
|
+
const result = await agent.run();
|
|
248
|
+
|
|
249
|
+
const mismatchFinding = result.findings.find((f) => f.id.includes('crud-field-mismatch'));
|
|
250
|
+
expect(mismatchFinding).toBeDefined();
|
|
251
|
+
expect(mismatchFinding!.severity).toBe('high');
|
|
252
|
+
expect(mismatchFinding!.description).toContain('name');
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('creates a finding when resource is still accessible after DELETE', async () => {
|
|
256
|
+
const clientRecord = {
|
|
257
|
+
id: 'abc-123',
|
|
258
|
+
name: 'TF-DataIntegrity-Test',
|
|
259
|
+
email: 'tf-integrity-test@test.invalid',
|
|
260
|
+
createdAt: '2026-03-27T10:00:00Z',
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
mockApiClientInstance.post
|
|
264
|
+
.mockResolvedValueOnce(created(clientRecord))
|
|
265
|
+
.mockResolvedValue(serverError());
|
|
266
|
+
|
|
267
|
+
mockApiClientInstance.get
|
|
268
|
+
.mockResolvedValueOnce(ok(clientRecord)) // read after create
|
|
269
|
+
.mockResolvedValueOnce(ok({ ...clientRecord, name: 'TF-DataIntegrity-Updated' })) // read after update
|
|
270
|
+
.mockResolvedValueOnce(ok(clientRecord)); // still accessible after delete!
|
|
271
|
+
|
|
272
|
+
mockApiClientInstance.put.mockResolvedValueOnce(ok({ ...clientRecord, name: 'TF-DataIntegrity-Updated' }));
|
|
273
|
+
mockApiClientInstance.delete.mockResolvedValueOnce(noContent());
|
|
274
|
+
|
|
275
|
+
const agent = createAgent();
|
|
276
|
+
const result = await agent.run();
|
|
277
|
+
|
|
278
|
+
const deleteFinding = result.findings.find((f) => f.id.includes('crud-delete-verify'));
|
|
279
|
+
expect(deleteFinding).toBeDefined();
|
|
280
|
+
expect(deleteFinding!.severity).toBe('high');
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
// -------------------------------------------------------------------------
|
|
285
|
+
// Decimal precision
|
|
286
|
+
// -------------------------------------------------------------------------
|
|
287
|
+
|
|
288
|
+
describe('decimal precision', () => {
|
|
289
|
+
it('creates a finding when decimal drift is detected', async () => {
|
|
290
|
+
// Capture post bodies to echo fields back with correct email.
|
|
291
|
+
let crudCaptured: Record<string, unknown> = {};
|
|
292
|
+
let decimalCaptured: Record<string, unknown> = {};
|
|
293
|
+
let postCallCount = 0;
|
|
294
|
+
|
|
295
|
+
mockApiClientInstance.post.mockImplementation(async (_path: string, body: unknown) => {
|
|
296
|
+
const b = body as Record<string, unknown>;
|
|
297
|
+
postCallCount++;
|
|
298
|
+
if (postCallCount === 1) {
|
|
299
|
+
// CRUD create
|
|
300
|
+
crudCaptured = b;
|
|
301
|
+
return created({ id: 'crud-id', ...b, createdAt: '2026-03-27T10:00:00Z' });
|
|
302
|
+
}
|
|
303
|
+
if (postCallCount === 2) {
|
|
304
|
+
// Decimal create
|
|
305
|
+
decimalCaptured = b;
|
|
306
|
+
return created({ id: 'decimal-id', ...b });
|
|
307
|
+
}
|
|
308
|
+
// tz → skip
|
|
309
|
+
return serverError();
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
let getCallCount = 0;
|
|
313
|
+
mockApiClientInstance.get.mockImplementation(async () => {
|
|
314
|
+
getCallCount++;
|
|
315
|
+
if (getCallCount === 1) {
|
|
316
|
+
return ok({ id: 'crud-id', ...crudCaptured, createdAt: '2026-03-27T10:00:00Z' });
|
|
317
|
+
}
|
|
318
|
+
if (getCallCount === 2) {
|
|
319
|
+
return ok({ id: 'crud-id', ...crudCaptured, name: 'TF-DataIntegrity-Updated', createdAt: '2026-03-27T10:00:00Z' });
|
|
320
|
+
}
|
|
321
|
+
if (getCallCount === 3) {
|
|
322
|
+
return notFound(); // after delete
|
|
323
|
+
}
|
|
324
|
+
// decimal read — return drifted amount (1000.1 rounds to 1000.10, not 1000.11)
|
|
325
|
+
return ok({ id: 'decimal-id', ...decimalCaptured, amount: 1000.1 });
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
mockApiClientInstance.put.mockResolvedValue(
|
|
329
|
+
ok({ id: 'crud-id', name: 'TF-DataIntegrity-Updated', createdAt: '2026-03-27T10:00:00Z' }),
|
|
330
|
+
);
|
|
331
|
+
mockApiClientInstance.delete.mockResolvedValue(noContent());
|
|
332
|
+
|
|
333
|
+
const agent = createAgent();
|
|
334
|
+
const result = await agent.run();
|
|
335
|
+
|
|
336
|
+
const decimalFinding = result.findings.find((f) => f.id.includes('decimal-drift'));
|
|
337
|
+
expect(decimalFinding).toBeDefined();
|
|
338
|
+
expect(decimalFinding!.severity).toBe('high');
|
|
339
|
+
expect(decimalFinding!.description).toContain('1000.105');
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
it('does NOT create a finding when amount is stored with correct precision', async () => {
|
|
343
|
+
let crudCaptured: Record<string, unknown> = {};
|
|
344
|
+
let decimalCaptured: Record<string, unknown> = {};
|
|
345
|
+
let postCallCount = 0;
|
|
346
|
+
|
|
347
|
+
mockApiClientInstance.post.mockImplementation(async (_path: string, body: unknown) => {
|
|
348
|
+
const b = body as Record<string, unknown>;
|
|
349
|
+
postCallCount++;
|
|
350
|
+
if (postCallCount === 1) {
|
|
351
|
+
crudCaptured = b;
|
|
352
|
+
return created({ id: 'crud-id', ...b, createdAt: '2026-03-27T10:00:00Z' });
|
|
353
|
+
}
|
|
354
|
+
if (postCallCount === 2) {
|
|
355
|
+
decimalCaptured = b;
|
|
356
|
+
return created({ id: 'decimal-id', ...b });
|
|
357
|
+
}
|
|
358
|
+
return serverError();
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
let getCallCount = 0;
|
|
362
|
+
mockApiClientInstance.get.mockImplementation(async () => {
|
|
363
|
+
getCallCount++;
|
|
364
|
+
if (getCallCount === 1) {
|
|
365
|
+
return ok({ id: 'crud-id', ...crudCaptured, createdAt: '2026-03-27T10:00:00Z' });
|
|
366
|
+
}
|
|
367
|
+
if (getCallCount === 2) {
|
|
368
|
+
return ok({ id: 'crud-id', ...crudCaptured, name: 'TF-DataIntegrity-Updated', createdAt: '2026-03-27T10:00:00Z' });
|
|
369
|
+
}
|
|
370
|
+
if (getCallCount === 3) {
|
|
371
|
+
return notFound();
|
|
372
|
+
}
|
|
373
|
+
// Decimal read — correctly rounded to 2 decimal places
|
|
374
|
+
return ok({ id: 'decimal-id', ...decimalCaptured, amount: 1000.11 });
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
mockApiClientInstance.put.mockResolvedValue(
|
|
378
|
+
ok({ id: 'crud-id', name: 'TF-DataIntegrity-Updated', createdAt: '2026-03-27T10:00:00Z' }),
|
|
379
|
+
);
|
|
380
|
+
mockApiClientInstance.delete.mockResolvedValue(noContent());
|
|
381
|
+
|
|
382
|
+
const agent = createAgent();
|
|
383
|
+
const result = await agent.run();
|
|
384
|
+
|
|
385
|
+
const decimalFindings = result.findings.filter((f) => f.id.includes('decimal-drift'));
|
|
386
|
+
expect(decimalFindings).toHaveLength(0);
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
// -------------------------------------------------------------------------
|
|
391
|
+
// Authentication failure
|
|
392
|
+
// -------------------------------------------------------------------------
|
|
393
|
+
|
|
394
|
+
describe('authentication failure', () => {
|
|
395
|
+
it('creates a medium finding when authentication fails', async () => {
|
|
396
|
+
createAuthenticatedMock.mockRejectedValueOnce(new Error('401 Unauthorized'));
|
|
397
|
+
|
|
398
|
+
const agent = createAgent();
|
|
399
|
+
const result = await agent.run();
|
|
400
|
+
|
|
401
|
+
expect(result.status).toBe('passed'); // medium severity doesn't trigger failure
|
|
402
|
+
const authFinding = result.findings.find((f) => f.id === '14-auth-failed');
|
|
403
|
+
expect(authFinding).toBeDefined();
|
|
404
|
+
expect(authFinding!.severity).toBe('medium');
|
|
405
|
+
});
|
|
406
|
+
});
|
|
407
|
+
});
|