@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,412 @@
|
|
|
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 with release environment
|
|
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: [
|
|
17
|
+
{ id: 'dashboard', route: '/dashboard', sidebarIcon: true },
|
|
18
|
+
{ id: 'invoices', route: '/invoices', sidebarIcon: true },
|
|
19
|
+
],
|
|
20
|
+
environments: {
|
|
21
|
+
alpha: { baseUrl: 'http://localhost:3000', seed: false },
|
|
22
|
+
release: { baseUrl: 'https://app.example.com', seed: false },
|
|
23
|
+
},
|
|
24
|
+
portals: [],
|
|
25
|
+
breakpoints: [],
|
|
26
|
+
integrations: [],
|
|
27
|
+
workers: [],
|
|
28
|
+
workflows: [],
|
|
29
|
+
accuracy: { enabled: false, decimalPrecision: 2, currencySymbol: '$', timezone: 'UTC' },
|
|
30
|
+
tenancy: { enabled: false, isolationField: 'firmId', testFirms: [] },
|
|
31
|
+
costBudget: { maxPerRun: 100, maxPerAgent: 10, alertThreshold: 0.8, onExceeded: 'abort' as const },
|
|
32
|
+
agentClassification: { blocking: [], advisory: [] },
|
|
33
|
+
thresholds: {
|
|
34
|
+
unitCoverage: { lines: 80, functions: 80, branches: 80, statements: 80 },
|
|
35
|
+
lighthouse: { accessibility: 90, performance: 90, bestPractices: 90, seo: 90 },
|
|
36
|
+
apiResponseTime: 2000,
|
|
37
|
+
bundleSizeLimit: 500000,
|
|
38
|
+
maxConsoleErrors: 0,
|
|
39
|
+
},
|
|
40
|
+
disabledAgents: [],
|
|
41
|
+
disabledAgentSet: new Set<number>(),
|
|
42
|
+
} satisfies ValidatedConfig;
|
|
43
|
+
|
|
44
|
+
// ---------------------------------------------------------------------------
|
|
45
|
+
// Mock child_process
|
|
46
|
+
// ---------------------------------------------------------------------------
|
|
47
|
+
|
|
48
|
+
const spawnMock = vi.fn();
|
|
49
|
+
|
|
50
|
+
vi.mock('child_process', () => ({
|
|
51
|
+
execFile: (...args: unknown[]) => spawnMock(...args),
|
|
52
|
+
}));
|
|
53
|
+
|
|
54
|
+
// ---------------------------------------------------------------------------
|
|
55
|
+
// Mock fetch
|
|
56
|
+
// ---------------------------------------------------------------------------
|
|
57
|
+
|
|
58
|
+
const fetchMock = vi.fn();
|
|
59
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
60
|
+
|
|
61
|
+
// ---------------------------------------------------------------------------
|
|
62
|
+
// Mock helpers (needed for preFlight's resolveEnvironment + isUrlReachable)
|
|
63
|
+
// ---------------------------------------------------------------------------
|
|
64
|
+
|
|
65
|
+
vi.mock('../../helpers/navigation', () => ({
|
|
66
|
+
login: vi.fn().mockResolvedValue(undefined),
|
|
67
|
+
navigateToSection: vi.fn().mockResolvedValue(undefined),
|
|
68
|
+
waitForSectionLoad: vi.fn().mockResolvedValue(undefined),
|
|
69
|
+
}));
|
|
70
|
+
|
|
71
|
+
vi.mock('../../helpers/screenshot', () => ({
|
|
72
|
+
captureScreenshot: vi.fn().mockResolvedValue('/tmp/test-run/screenshot.png'),
|
|
73
|
+
}));
|
|
74
|
+
|
|
75
|
+
vi.mock('../../helpers/element-discovery', () => ({
|
|
76
|
+
discoverInteractiveElements: vi.fn().mockResolvedValue([]),
|
|
77
|
+
}));
|
|
78
|
+
|
|
79
|
+
vi.mock('../../helpers/form-filler', () => ({
|
|
80
|
+
fillForm: vi.fn().mockResolvedValue(undefined),
|
|
81
|
+
}));
|
|
82
|
+
|
|
83
|
+
vi.mock('../../helpers/modal-handler', () => ({
|
|
84
|
+
openModal: vi.fn().mockResolvedValue(false),
|
|
85
|
+
closeModal: vi.fn().mockResolvedValue(undefined),
|
|
86
|
+
}));
|
|
87
|
+
|
|
88
|
+
vi.mock('../../helpers/api-client', () => ({
|
|
89
|
+
ApiClient: { createAuthenticated: vi.fn().mockResolvedValue({}) },
|
|
90
|
+
}));
|
|
91
|
+
|
|
92
|
+
// Mock playwright (not used in release mode but imported at module level)
|
|
93
|
+
vi.mock('playwright', () => ({
|
|
94
|
+
chromium: {
|
|
95
|
+
launch: vi.fn().mockImplementation(async () => ({
|
|
96
|
+
newPage: vi.fn().mockResolvedValue({ close: vi.fn() }),
|
|
97
|
+
close: vi.fn(),
|
|
98
|
+
})),
|
|
99
|
+
},
|
|
100
|
+
}));
|
|
101
|
+
|
|
102
|
+
// ---------------------------------------------------------------------------
|
|
103
|
+
// Dynamic import AFTER mocks
|
|
104
|
+
// ---------------------------------------------------------------------------
|
|
105
|
+
|
|
106
|
+
const { BrowserCrawlerAgent } = await import('../05-browser-crawler');
|
|
107
|
+
|
|
108
|
+
function createAgent(phase: Phase = 'release', config: ValidatedConfig = stubConfig): InstanceType<typeof BrowserCrawlerAgent> {
|
|
109
|
+
return new BrowserCrawlerAgent(config, phase, '/tmp/test-run');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// ---------------------------------------------------------------------------
|
|
113
|
+
// Tests
|
|
114
|
+
// ---------------------------------------------------------------------------
|
|
115
|
+
|
|
116
|
+
describe('BrowserCrawlerAgent — release mode', () => {
|
|
117
|
+
beforeEach(() => {
|
|
118
|
+
spawnMock.mockReset();
|
|
119
|
+
fetchMock.mockReset();
|
|
120
|
+
|
|
121
|
+
// preFlight: playwright version check succeeds
|
|
122
|
+
spawnMock.mockImplementation(
|
|
123
|
+
(_file: string, _args: string[], _opts: unknown, cb: (err: Error | null, stdout: string, stderr: string) => void) => {
|
|
124
|
+
cb(null, '1.40.0\n', '');
|
|
125
|
+
},
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
// Default: preFlight isUrlReachable (HEAD) + release mode fetch both succeed
|
|
129
|
+
fetchMock.mockImplementation(async (url: string | URL | Request, opts?: RequestInit) => {
|
|
130
|
+
const method = opts?.method ?? 'GET';
|
|
131
|
+
if (method === 'HEAD') {
|
|
132
|
+
// preFlight reachability check
|
|
133
|
+
return { ok: true, status: 200 };
|
|
134
|
+
}
|
|
135
|
+
// release mode GET requests
|
|
136
|
+
return {
|
|
137
|
+
ok: true,
|
|
138
|
+
status: 200,
|
|
139
|
+
text: async () => '<html><head><title>App</title><meta charset="utf-8"></head><body></body></html>',
|
|
140
|
+
};
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// -----------------------------------------------------------------------
|
|
145
|
+
// Happy path
|
|
146
|
+
// -----------------------------------------------------------------------
|
|
147
|
+
|
|
148
|
+
it('returns no findings when base URL and all module routes return 200 with valid HTML', async () => {
|
|
149
|
+
const agent = createAgent();
|
|
150
|
+
const result = await agent.run();
|
|
151
|
+
|
|
152
|
+
expect(result.status).toBe('passed');
|
|
153
|
+
expect(result.findings).toHaveLength(0);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// -----------------------------------------------------------------------
|
|
157
|
+
// No environment configured
|
|
158
|
+
// -----------------------------------------------------------------------
|
|
159
|
+
|
|
160
|
+
it('returns critical finding when no environment is configured', async () => {
|
|
161
|
+
const noEnvConfig: ValidatedConfig = {
|
|
162
|
+
...stubConfig,
|
|
163
|
+
environments: {},
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
// preFlight resolveEnvironment will also fail, causing a thrown error
|
|
167
|
+
const agent = createAgent('release', noEnvConfig);
|
|
168
|
+
const result = await agent.run();
|
|
169
|
+
|
|
170
|
+
expect(result.status).toBe('failed');
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// -----------------------------------------------------------------------
|
|
174
|
+
// Base URL returns non-ok status
|
|
175
|
+
// -----------------------------------------------------------------------
|
|
176
|
+
|
|
177
|
+
it('creates critical finding when base URL returns non-OK HTTP status', async () => {
|
|
178
|
+
fetchMock.mockImplementation(async (_url: string | URL | Request, opts?: RequestInit) => {
|
|
179
|
+
const method = opts?.method ?? 'GET';
|
|
180
|
+
if (method === 'HEAD') return { ok: true, status: 200 };
|
|
181
|
+
return { ok: false, status: 503, text: async () => '' };
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
const agent = createAgent();
|
|
185
|
+
const result = await agent.run();
|
|
186
|
+
|
|
187
|
+
const finding = result.findings.find((f) => f.id === '5-release-base-status');
|
|
188
|
+
expect(finding).toBeDefined();
|
|
189
|
+
expect(finding!.severity).toBe('critical');
|
|
190
|
+
expect(finding!.description).toContain('503');
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
// -----------------------------------------------------------------------
|
|
194
|
+
// Base URL unreachable
|
|
195
|
+
// -----------------------------------------------------------------------
|
|
196
|
+
|
|
197
|
+
it('creates critical finding and returns early when base URL fetch throws', async () => {
|
|
198
|
+
let callCount = 0;
|
|
199
|
+
fetchMock.mockImplementation(async (_url: string | URL | Request, opts?: RequestInit) => {
|
|
200
|
+
const method = opts?.method ?? 'GET';
|
|
201
|
+
if (method === 'HEAD') return { ok: true, status: 200 };
|
|
202
|
+
callCount++;
|
|
203
|
+
if (callCount === 1) throw new Error('Network error');
|
|
204
|
+
return { ok: true, status: 200, text: async () => '<html></html>' };
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
const agent = createAgent();
|
|
208
|
+
const result = await agent.run();
|
|
209
|
+
|
|
210
|
+
const finding = result.findings.find((f) => f.id === '5-release-base-unreachable');
|
|
211
|
+
expect(finding).toBeDefined();
|
|
212
|
+
expect(finding!.severity).toBe('critical');
|
|
213
|
+
expect(finding!.description).toContain('unreachable');
|
|
214
|
+
// Should return early -- no route findings
|
|
215
|
+
const routeFindings = result.findings.filter((f) => f.id.includes('release-route'));
|
|
216
|
+
expect(routeFindings).toHaveLength(0);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
// -----------------------------------------------------------------------
|
|
220
|
+
// HTML markers missing
|
|
221
|
+
// -----------------------------------------------------------------------
|
|
222
|
+
|
|
223
|
+
it('creates high finding when HTML is missing all expected markers', async () => {
|
|
224
|
+
fetchMock.mockImplementation(async (_url: string | URL | Request, opts?: RequestInit) => {
|
|
225
|
+
const method = opts?.method ?? 'GET';
|
|
226
|
+
if (method === 'HEAD') return { ok: true, status: 200 };
|
|
227
|
+
return {
|
|
228
|
+
ok: true,
|
|
229
|
+
status: 200,
|
|
230
|
+
text: async () => 'just plain text with no html tags at all',
|
|
231
|
+
};
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
const agent = createAgent();
|
|
235
|
+
const result = await agent.run();
|
|
236
|
+
|
|
237
|
+
const markerFinding = result.findings.find((f) => f.id === '5-release-base-html-markers');
|
|
238
|
+
expect(markerFinding).toBeDefined();
|
|
239
|
+
expect(markerFinding!.severity).toBe('high');
|
|
240
|
+
expect(markerFinding!.description).toContain('missing expected markers');
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it('does NOT create marker finding when HTML has a <title> tag', async () => {
|
|
244
|
+
fetchMock.mockImplementation(async (_url: string | URL | Request, opts?: RequestInit) => {
|
|
245
|
+
const method = opts?.method ?? 'GET';
|
|
246
|
+
if (method === 'HEAD') return { ok: true, status: 200 };
|
|
247
|
+
return {
|
|
248
|
+
ok: true,
|
|
249
|
+
status: 200,
|
|
250
|
+
text: async () => '<title>My App</title>',
|
|
251
|
+
};
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
const agent = createAgent();
|
|
255
|
+
const result = await agent.run();
|
|
256
|
+
|
|
257
|
+
const markerFinding = result.findings.find((f) => f.id === '5-release-base-html-markers');
|
|
258
|
+
expect(markerFinding).toBeUndefined();
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it('does NOT create marker finding when HTML has a <meta charset> tag', async () => {
|
|
262
|
+
fetchMock.mockImplementation(async (_url: string | URL | Request, opts?: RequestInit) => {
|
|
263
|
+
const method = opts?.method ?? 'GET';
|
|
264
|
+
if (method === 'HEAD') return { ok: true, status: 200 };
|
|
265
|
+
return {
|
|
266
|
+
ok: true,
|
|
267
|
+
status: 200,
|
|
268
|
+
text: async () => '<meta charset="utf-8">',
|
|
269
|
+
};
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
const agent = createAgent();
|
|
273
|
+
const result = await agent.run();
|
|
274
|
+
|
|
275
|
+
const markerFinding = result.findings.find((f) => f.id === '5-release-base-html-markers');
|
|
276
|
+
expect(markerFinding).toBeUndefined();
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it('does NOT create marker finding when HTML has an <html> tag', async () => {
|
|
280
|
+
fetchMock.mockImplementation(async (_url: string | URL | Request, opts?: RequestInit) => {
|
|
281
|
+
const method = opts?.method ?? 'GET';
|
|
282
|
+
if (method === 'HEAD') return { ok: true, status: 200 };
|
|
283
|
+
return {
|
|
284
|
+
ok: true,
|
|
285
|
+
status: 200,
|
|
286
|
+
text: async () => '<html lang="en"><body>content</body></html>',
|
|
287
|
+
};
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
const agent = createAgent();
|
|
291
|
+
const result = await agent.run();
|
|
292
|
+
|
|
293
|
+
const markerFinding = result.findings.find((f) => f.id === '5-release-base-html-markers');
|
|
294
|
+
expect(markerFinding).toBeUndefined();
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
// -----------------------------------------------------------------------
|
|
298
|
+
// Module route checks
|
|
299
|
+
// -----------------------------------------------------------------------
|
|
300
|
+
|
|
301
|
+
it('creates a finding for each module route that returns 4xx or 5xx', async () => {
|
|
302
|
+
let fetchCount = 0;
|
|
303
|
+
fetchMock.mockImplementation(async (_url: string | URL | Request, opts?: RequestInit) => {
|
|
304
|
+
const method = opts?.method ?? 'GET';
|
|
305
|
+
if (method === 'HEAD') return { ok: true, status: 200 };
|
|
306
|
+
fetchCount++;
|
|
307
|
+
if (fetchCount === 1) {
|
|
308
|
+
// base URL
|
|
309
|
+
return {
|
|
310
|
+
ok: true,
|
|
311
|
+
status: 200,
|
|
312
|
+
text: async () => '<html><title>App</title></html>',
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
if (fetchCount === 2) {
|
|
316
|
+
// dashboard route -- 404
|
|
317
|
+
return { ok: false, status: 404 };
|
|
318
|
+
}
|
|
319
|
+
// invoices route -- 500
|
|
320
|
+
return { ok: false, status: 500 };
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
const agent = createAgent();
|
|
324
|
+
const result = await agent.run();
|
|
325
|
+
|
|
326
|
+
const dashboardFinding = result.findings.find((f) => f.id === '5-release-route-dashboard');
|
|
327
|
+
expect(dashboardFinding).toBeDefined();
|
|
328
|
+
expect(dashboardFinding!.severity).toBe('high'); // 4xx = high
|
|
329
|
+
|
|
330
|
+
const invoicesFinding = result.findings.find((f) => f.id === '5-release-route-invoices');
|
|
331
|
+
expect(invoicesFinding).toBeDefined();
|
|
332
|
+
expect(invoicesFinding!.severity).toBe('critical'); // 5xx = critical
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
it('creates a finding when a module route fetch throws', async () => {
|
|
336
|
+
let fetchCount = 0;
|
|
337
|
+
fetchMock.mockImplementation(async (_url: string | URL | Request, opts?: RequestInit) => {
|
|
338
|
+
const method = opts?.method ?? 'GET';
|
|
339
|
+
if (method === 'HEAD') return { ok: true, status: 200 };
|
|
340
|
+
fetchCount++;
|
|
341
|
+
if (fetchCount === 1) {
|
|
342
|
+
return {
|
|
343
|
+
ok: true,
|
|
344
|
+
status: 200,
|
|
345
|
+
text: async () => '<html><title>App</title></html>',
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
throw new Error('DNS resolution failed');
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
const agent = createAgent();
|
|
352
|
+
const result = await agent.run();
|
|
353
|
+
|
|
354
|
+
const routeFindings = result.findings.filter((f) => f.id.includes('release-route'));
|
|
355
|
+
expect(routeFindings.length).toBeGreaterThanOrEqual(1);
|
|
356
|
+
expect(routeFindings[0].severity).toBe('critical');
|
|
357
|
+
expect(routeFindings[0].description).toContain('unreachable');
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
it('handles absolute route URLs (starting with http)', async () => {
|
|
361
|
+
const configWithAbsoluteRoutes: ValidatedConfig = {
|
|
362
|
+
...stubConfig,
|
|
363
|
+
modules: [
|
|
364
|
+
{ id: 'ext', route: 'https://external.example.com/app', sidebarIcon: true },
|
|
365
|
+
],
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
fetchMock.mockImplementation(async (_url: string | URL | Request, opts?: RequestInit) => {
|
|
369
|
+
const method = opts?.method ?? 'GET';
|
|
370
|
+
if (method === 'HEAD') return { ok: true, status: 200 };
|
|
371
|
+
return {
|
|
372
|
+
ok: true,
|
|
373
|
+
status: 200,
|
|
374
|
+
text: async () => '<html><title>App</title></html>',
|
|
375
|
+
};
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
const agent = createAgent('release', configWithAbsoluteRoutes);
|
|
379
|
+
const result = await agent.run();
|
|
380
|
+
|
|
381
|
+
expect(result.findings).toHaveLength(0);
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
// -----------------------------------------------------------------------
|
|
385
|
+
// Environment fallback priority
|
|
386
|
+
// -----------------------------------------------------------------------
|
|
387
|
+
|
|
388
|
+
it('falls back through environment priority: release > uat > beta > alpha', async () => {
|
|
389
|
+
const alphaOnlyConfig: ValidatedConfig = {
|
|
390
|
+
...stubConfig,
|
|
391
|
+
environments: {
|
|
392
|
+
alpha: { baseUrl: 'http://alpha.example.com', seed: false },
|
|
393
|
+
},
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
fetchMock.mockImplementation(async (_url: string | URL | Request, opts?: RequestInit) => {
|
|
397
|
+
const method = opts?.method ?? 'GET';
|
|
398
|
+
if (method === 'HEAD') return { ok: true, status: 200 };
|
|
399
|
+
return {
|
|
400
|
+
ok: true,
|
|
401
|
+
status: 200,
|
|
402
|
+
text: async () => '<html><title>App</title></html>',
|
|
403
|
+
};
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
const agent = createAgent('release', alphaOnlyConfig);
|
|
407
|
+
const result = await agent.run();
|
|
408
|
+
|
|
409
|
+
// Should succeed using alpha env as fallback
|
|
410
|
+
expect(result.status).toBe('passed');
|
|
411
|
+
});
|
|
412
|
+
});
|