hauntview 0.0.0-stage → 0.0.6

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.
Files changed (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +358 -2
  3. package/VERSION +1 -0
  4. package/dist/cli.js +8184 -0
  5. package/package.json +120 -4
  6. package/scripts/postinstall.mjs +47 -0
  7. package/src/core/browser-launch.ts +60 -0
  8. package/src/core/browser-pool.ts +267 -0
  9. package/src/core/concurrency-resolver.ts +154 -0
  10. package/src/core/finding-classifier.ts +346 -0
  11. package/src/core/index.ts +8 -0
  12. package/src/core/profile-manager.ts +499 -0
  13. package/src/core/report-store.ts +117 -0
  14. package/src/core/screenshot-manager.ts +312 -0
  15. package/src/core/system-capability.ts +161 -0
  16. package/src/core/visual-diff.ts +230 -0
  17. package/src/engine.ts +473 -0
  18. package/src/profiles/accessibility-cognitive.ts +261 -0
  19. package/src/profiles/accessibility-keyboard.ts +225 -0
  20. package/src/profiles/accessibility-screenreader.ts +243 -0
  21. package/src/profiles/accessibility-visual.ts +257 -0
  22. package/src/profiles/broken-links.ts +261 -0
  23. package/src/profiles/browser-edge.ts +192 -0
  24. package/src/profiles/browser-firefox.ts +254 -0
  25. package/src/profiles/browser-legacy.ts +213 -0
  26. package/src/profiles/console-errors.ts +192 -0
  27. package/src/profiles/desktop-4k.ts +273 -0
  28. package/src/profiles/desktop.ts +192 -0
  29. package/src/profiles/font-failure.ts +148 -0
  30. package/src/profiles/form-resilience.ts +285 -0
  31. package/src/profiles/i18n-cjk.ts +218 -0
  32. package/src/profiles/i18n-mixed.ts +255 -0
  33. package/src/profiles/i18n-rtl.ts +236 -0
  34. package/src/profiles/image-failure.ts +178 -0
  35. package/src/profiles/index.ts +42 -0
  36. package/src/profiles/js-disabled.ts +179 -0
  37. package/src/profiles/mobile.ts +175 -0
  38. package/src/profiles/network-resilience.ts +208 -0
  39. package/src/profiles/offline.ts +165 -0
  40. package/src/profiles/performance.ts +244 -0
  41. package/src/profiles/reduced-motion.ts +144 -0
  42. package/src/profiles/security-hygiene.ts +206 -0
  43. package/src/profiles/tablet.ts +176 -0
  44. package/src/reports/factory.ts +56 -0
  45. package/src/reports/html-generator.ts +1105 -0
  46. package/src/reports/index.ts +9 -0
  47. package/src/reports/markdown-generator.ts +349 -0
  48. package/src/reports/types.ts +34 -0
  49. package/src/reports/zip-generator.ts +85 -0
  50. package/src/types/contracts.ts +238 -0
  51. package/src/types/finding-utils.ts +121 -0
  52. package/src/types/index.ts +8 -0
  53. package/src/types/profiles.ts +175 -0
  54. package/src/types/results.ts +135 -0
  55. package/src/version.ts +5 -0
@@ -0,0 +1,243 @@
1
+ /**
2
+ * Accessibility: Screen Reader Profile
3
+ * Validates ARIA, semantic HTML, and screen reader compatibility
4
+ */
5
+
6
+ import { Page } from 'playwright';
7
+ import { Finding, ProfileResult } from '../types';
8
+
9
+ export class AccessibilityScreenReaderProfile {
10
+ private profileId: string;
11
+ private profileName: string;
12
+
13
+ constructor(profileId: string, profileName: string) {
14
+ this.profileId = profileId;
15
+ this.profileName = profileName;
16
+ }
17
+
18
+ async execute(page: Page, url: string): Promise<ProfileResult> {
19
+ const startTime = Date.now();
20
+ const findings: Finding[] = [];
21
+
22
+ try {
23
+ await page.goto(url, { waitUntil: 'networkidle', timeout: 30000 });
24
+
25
+ // Check for page language
26
+ const langAttr = await page.locator('html').getAttribute('lang');
27
+ if (!langAttr) {
28
+ findings.push({
29
+ id: `${this.profileId}-no-lang`,
30
+ profileId: this.profileId,
31
+ severity: 'error',
32
+ category: 'accessibility',
33
+ message: 'Missing lang attribute on html element',
34
+ timestamp: Date.now(),
35
+ isClassified: false,
36
+ });
37
+ }
38
+
39
+ // Check for main landmark
40
+ const hasMain = await page.locator('main, [role="main"]').count();
41
+ if (hasMain === 0) {
42
+ findings.push({
43
+ id: `${this.profileId}-no-main`,
44
+ profileId: this.profileId,
45
+ severity: 'warning',
46
+ category: 'accessibility',
47
+ message: 'Page missing <main> or role="main" landmark',
48
+ timestamp: Date.now(),
49
+ isClassified: false,
50
+ });
51
+ }
52
+
53
+ // Check for heading hierarchy
54
+ const headings = await page.evaluate(() => {
55
+ const h = Array.from(document.querySelectorAll('h1, h2, h3, h4, h5, h6'));
56
+ return h.map((el: Element) => parseInt(el.tagName[1]));
57
+ });
58
+
59
+ if (headings.length === 0) {
60
+ findings.push({
61
+ id: `${this.profileId}-no-headings`,
62
+ profileId: this.profileId,
63
+ severity: 'warning',
64
+ category: 'accessibility',
65
+ message: 'Page contains no heading elements',
66
+ timestamp: Date.now(),
67
+ isClassified: false,
68
+ });
69
+ } else if (headings[0] !== 1) {
70
+ findings.push({
71
+ id: `${this.profileId}-h1-missing`,
72
+ profileId: this.profileId,
73
+ severity: 'warning',
74
+ category: 'accessibility',
75
+ message: 'Page should start with <h1> element',
76
+ timestamp: Date.now(),
77
+ isClassified: false,
78
+ });
79
+ }
80
+
81
+ // Check for heading order violations
82
+ for (let i = 1; i < headings.length; i++) {
83
+ if (headings[i] > headings[i - 1] + 1) {
84
+ findings.push({
85
+ id: `${this.profileId}-heading-order`,
86
+ profileId: this.profileId,
87
+ severity: 'warning',
88
+ category: 'accessibility',
89
+ message: `Heading order skips level (h${headings[i - 1]} to h${headings[i]})`,
90
+ timestamp: Date.now(),
91
+ isClassified: false,
92
+ });
93
+ break;
94
+ }
95
+ }
96
+
97
+ // Check for images without alt text
98
+ const imgsNoAlt = await page.evaluate(() => {
99
+ return Array.from(document.querySelectorAll('img')).filter(
100
+ (img: Element) =>
101
+ !(img as HTMLImageElement).getAttribute('alt') ||
102
+ ((img as HTMLImageElement).getAttribute('alt') || '').trim() === ''
103
+ ).length;
104
+ });
105
+
106
+ if (imgsNoAlt > 0) {
107
+ findings.push({
108
+ id: `${this.profileId}-img-alt`,
109
+ profileId: this.profileId,
110
+ severity: 'error',
111
+ category: 'accessibility',
112
+ message: `${imgsNoAlt} images missing alt text`,
113
+ timestamp: Date.now(),
114
+ isClassified: false,
115
+ });
116
+ }
117
+
118
+ // Check for form labels
119
+ const inputs = await page.locator('input, textarea, select').all();
120
+ let missingLabels = 0;
121
+
122
+ for (const input of inputs) {
123
+ const id = await input.getAttribute('id');
124
+ const ariaLabel = await input.getAttribute('aria-label');
125
+ const ariaLabelledBy = await input.getAttribute('aria-labelledby');
126
+
127
+ if (!ariaLabel && !ariaLabelledBy && id) {
128
+ const label = await page.locator(`label[for="${id}"]`).count();
129
+ if (label === 0) {
130
+ missingLabels++;
131
+ }
132
+ }
133
+ }
134
+
135
+ if (missingLabels > 0) {
136
+ findings.push({
137
+ id: `${this.profileId}-form-labels`,
138
+ profileId: this.profileId,
139
+ severity: 'error',
140
+ category: 'accessibility',
141
+ message: `${missingLabels} form inputs missing associated labels`,
142
+ timestamp: Date.now(),
143
+ isClassified: false,
144
+ });
145
+ }
146
+
147
+ // Check for skip to main link
148
+ const skipLink = await page.locator('a[href="#main"], a[href="#content"]').count();
149
+ if (skipLink === 0) {
150
+ findings.push({
151
+ id: `${this.profileId}-skip-link`,
152
+ profileId: this.profileId,
153
+ severity: 'warning',
154
+ category: 'accessibility',
155
+ message: 'Missing skip-to-main-content link',
156
+ timestamp: Date.now(),
157
+ isClassified: false,
158
+ });
159
+ }
160
+
161
+ // Check for ARIA attributes on interactive elements
162
+ const ariaErrors = await page.evaluate(() => {
163
+ const errors: string[] = [];
164
+ const elements = document.querySelectorAll('[role]');
165
+
166
+ for (const el of elements) {
167
+ const role = el.getAttribute('role');
168
+ // Check for conflicting ARIA roles
169
+ if (['button', 'link', 'tab'].includes(role || '')) {
170
+ const actualTag = el.tagName.toLowerCase();
171
+ if (
172
+ actualTag !== 'button' &&
173
+ actualTag !== 'a' &&
174
+ !el.getAttribute('aria-pressed') &&
175
+ !el.getAttribute('aria-selected')
176
+ ) {
177
+ errors.push(`Semantic <${actualTag}> with role="${role}"`);
178
+ }
179
+ }
180
+ }
181
+
182
+ return errors;
183
+ });
184
+
185
+ if (ariaErrors.length > 0) {
186
+ findings.push({
187
+ id: `${this.profileId}-aria-conflicts`,
188
+ profileId: this.profileId,
189
+ severity: 'warning',
190
+ category: 'accessibility',
191
+ message: `Found ${ariaErrors.length} potential ARIA/semantic conflicts`,
192
+ timestamp: Date.now(),
193
+ isClassified: false,
194
+ });
195
+ }
196
+
197
+ // Check for focus management
198
+ const focusableCount = await page
199
+ .locator('a, button, input, select, textarea, [tabindex]')
200
+ .count();
201
+ if (focusableCount === 0) {
202
+ findings.push({
203
+ id: `${this.profileId}-no-focusable`,
204
+ profileId: this.profileId,
205
+ severity: 'info',
206
+ category: 'accessibility',
207
+ message: 'Page has no focusable elements',
208
+ timestamp: Date.now(),
209
+ isClassified: false,
210
+ });
211
+ }
212
+ } catch (error) {
213
+ findings.push({
214
+ id: `${this.profileId}-execution-error`,
215
+ profileId: this.profileId,
216
+ severity: 'error',
217
+ category: 'execution',
218
+ message: `Screen reader profile error: ${error instanceof Error ? error.message : String(error)}`,
219
+ timestamp: Date.now(),
220
+ isClassified: false,
221
+ });
222
+ }
223
+
224
+ const endTime = Date.now();
225
+ const metadata = await page.context().browser()?.version();
226
+
227
+ return {
228
+ profileId: this.profileId,
229
+ profileName: this.profileName,
230
+ success: findings.filter((f) => f.severity === 'error').length === 0,
231
+ startTime,
232
+ endTime,
233
+ duration: endTime - startTime,
234
+ findings,
235
+ screenshots: [],
236
+ metadata: {
237
+ browserEngine: 'webkit',
238
+ browserVersion: metadata || 'unknown',
239
+ nodeVersion: process.version,
240
+ },
241
+ };
242
+ }
243
+ }
@@ -0,0 +1,257 @@
1
+ /**
2
+ * Accessibility: Visual Impairment Profile
3
+ * Validates color contrast and visual accessibility
4
+ */
5
+
6
+ import { Page } from 'playwright';
7
+ import { Finding, ProfileResult } from '../types';
8
+
9
+ export class AccessibilityVisualProfile {
10
+ private profileId: string;
11
+ private profileName: string;
12
+
13
+ constructor(profileId: string, profileName: string) {
14
+ this.profileId = profileId;
15
+ this.profileName = profileName;
16
+ }
17
+
18
+ async execute(page: Page, url: string): Promise<ProfileResult> {
19
+ const startTime = Date.now();
20
+ const findings: Finding[] = [];
21
+
22
+ try {
23
+ await page.goto(url, { waitUntil: 'networkidle', timeout: 30000 });
24
+
25
+ // Calculate contrast ratio
26
+ const contrastIssues = await page.evaluate(() => {
27
+ interface ContrastIssue {
28
+ text?: string;
29
+ contrast: string;
30
+ level: string;
31
+ }
32
+ const issues: ContrastIssue[] = [];
33
+
34
+ function getLuminance(r: number, g: number, b: number): number {
35
+ const [rs, gs, bs] = [r, g, b].map((x) => {
36
+ x = x / 255;
37
+ return x <= 0.03928 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
38
+ });
39
+ return 0.2126 * rs + 0.7152 * gs + 0.0722 * bs;
40
+ }
41
+
42
+ function getContrast(rgb1: string, rgb2: string): number {
43
+ const parse = (rgb: string) => {
44
+ const match = rgb.match(/\d+/g);
45
+ return match
46
+ ? [parseInt(match[0], 10), parseInt(match[1], 10), parseInt(match[2], 10)]
47
+ : [0, 0, 0];
48
+ };
49
+ const [r1, g1, b1] = parse(rgb1);
50
+ const [r2, g2, b2] = parse(rgb2);
51
+ const l1 = getLuminance(r1, g1, b1);
52
+ const l2 = getLuminance(r2, g2, b2);
53
+ const lighter = Math.max(l1, l2);
54
+ const darker = Math.min(l1, l2);
55
+ return (lighter + 0.05) / (darker + 0.05);
56
+ }
57
+
58
+ const textElements = document.querySelectorAll(
59
+ 'p, span, a, button, label, h1, h2, h3, h4, h5, h6'
60
+ );
61
+
62
+ function getEffectiveBg(element: Element): string {
63
+ let current: Element | null = element;
64
+ while (current) {
65
+ const bg = window.getComputedStyle(current).backgroundColor;
66
+ if (bg && bg !== 'transparent' && !bg.match(/rgba\([^)]+,\s*0\)/)) {
67
+ return bg;
68
+ }
69
+ current = current.parentElement;
70
+ }
71
+ return 'rgb(10, 7, 17)';
72
+ }
73
+
74
+ for (const el of textElements) {
75
+ const style = window.getComputedStyle(el);
76
+ const bgColor = getEffectiveBg(el);
77
+ const color = style.color;
78
+
79
+ if (bgColor && color && (el as HTMLElement).offsetHeight > 0) {
80
+ const contrast = getContrast(color, bgColor);
81
+
82
+ // WCAG AA: 4.5:1 for normal text, 3:1 for large text
83
+ if (contrast < 4.5) {
84
+ issues.push({
85
+ text: el.textContent?.substring(0, 50),
86
+ contrast: contrast.toFixed(2),
87
+ level: contrast >= 3 ? 'AA-large' : 'fail',
88
+ });
89
+ }
90
+ }
91
+ }
92
+
93
+ return issues;
94
+ });
95
+
96
+ if (contrastIssues.length > 0) {
97
+ const failCount = contrastIssues.filter((i) => i.level === 'fail').length;
98
+ findings.push({
99
+ id: `${this.profileId}-contrast-ratio`,
100
+ profileId: this.profileId,
101
+ severity: failCount > 0 ? 'error' : 'warning',
102
+ category: 'accessibility',
103
+ message: `${contrastIssues.length} text elements have insufficient color contrast (< 4.5:1)`,
104
+ timestamp: Date.now(),
105
+ isClassified: false,
106
+ });
107
+ }
108
+
109
+ // Check for color-only information
110
+ const colorOnlyInfo = await page.evaluate(() => {
111
+ const issues: string[] = [];
112
+
113
+ // Check for elements that use color alone to convey info
114
+ const elements = document.querySelectorAll(
115
+ '[style*="color"], [class*="red"], [class*="green"], [class*="error"], [class*="success"]'
116
+ );
117
+
118
+ for (const el of elements) {
119
+ const text = el.textContent?.trim();
120
+ if (
121
+ text &&
122
+ text.length < 10 &&
123
+ !text.includes('•') &&
124
+ !text.includes('✓') &&
125
+ !text.includes('×')
126
+ ) {
127
+ issues.push(text);
128
+ }
129
+ }
130
+
131
+ return issues;
132
+ });
133
+
134
+ if (colorOnlyInfo.length > 0) {
135
+ findings.push({
136
+ id: `${this.profileId}-color-only`,
137
+ profileId: this.profileId,
138
+ severity: 'warning',
139
+ category: 'accessibility',
140
+ message: `Found ${colorOnlyInfo.length} elements that may use color alone to convey meaning`,
141
+ timestamp: Date.now(),
142
+ isClassified: false,
143
+ });
144
+ }
145
+
146
+ // Check for high contrast mode support
147
+ const highContrastSupport = await page.evaluate(() => {
148
+ return window.matchMedia('(prefers-contrast: more)').matches;
149
+ });
150
+
151
+ if (!highContrastSupport) {
152
+ findings.push({
153
+ id: `${this.profileId}-high-contrast`,
154
+ profileId: this.profileId,
155
+ severity: 'info',
156
+ category: 'accessibility',
157
+ message: 'Consider adding high-contrast mode support with prefers-contrast media query',
158
+ timestamp: Date.now(),
159
+ isClassified: false,
160
+ });
161
+ }
162
+
163
+ // Check for forced colors mode support
164
+ const forcedColorsSupport = await page.evaluate(() => {
165
+ return window.matchMedia('(forced-colors: active)').matches;
166
+ });
167
+
168
+ if (!forcedColorsSupport) {
169
+ findings.push({
170
+ id: `${this.profileId}-forced-colors`,
171
+ profileId: this.profileId,
172
+ severity: 'info',
173
+ category: 'accessibility',
174
+ message: 'Consider testing with forced colors mode (Windows High Contrast)',
175
+ timestamp: Date.now(),
176
+ isClassified: false,
177
+ });
178
+ }
179
+
180
+ // Check for background images with text
181
+ const bgImageText = await page.evaluate(() => {
182
+ let count = 0;
183
+ const elements = document.querySelectorAll(
184
+ '[style*="background-image"], [style*="background"]'
185
+ );
186
+
187
+ for (const el of elements) {
188
+ if (el.textContent?.trim().length ?? 0 > 0) {
189
+ count++;
190
+ }
191
+ }
192
+
193
+ return count;
194
+ });
195
+
196
+ if (bgImageText > 0) {
197
+ findings.push({
198
+ id: `${this.profileId}-bg-image-text`,
199
+ profileId: this.profileId,
200
+ severity: 'warning',
201
+ category: 'accessibility',
202
+ message: `${bgImageText} elements have text over background images, verify contrast`,
203
+ timestamp: Date.now(),
204
+ isClassified: false,
205
+ });
206
+ }
207
+
208
+ // Check for text resizing
209
+ const allowsZoom = await page.evaluate(() => {
210
+ const viewport = document.querySelector('meta[name="viewport"]');
211
+ const content = viewport?.getAttribute('content') || '';
212
+ return !content.includes('user-scalable=no');
213
+ });
214
+
215
+ if (!allowsZoom) {
216
+ findings.push({
217
+ id: `${this.profileId}-no-zoom`,
218
+ profileId: this.profileId,
219
+ severity: 'warning',
220
+ category: 'accessibility',
221
+ message: 'Page disables user zoom, violates visual accessibility guidelines',
222
+ timestamp: Date.now(),
223
+ isClassified: false,
224
+ });
225
+ }
226
+ } catch (error) {
227
+ findings.push({
228
+ id: `${this.profileId}-execution-error`,
229
+ profileId: this.profileId,
230
+ severity: 'error',
231
+ category: 'execution',
232
+ message: `Visual profile error: ${error instanceof Error ? error.message : String(error)}`,
233
+ timestamp: Date.now(),
234
+ isClassified: false,
235
+ });
236
+ }
237
+
238
+ const endTime = Date.now();
239
+ const metadata = await page.context().browser()?.version();
240
+
241
+ return {
242
+ profileId: this.profileId,
243
+ profileName: this.profileName,
244
+ success: findings.filter((f) => f.severity === 'error').length === 0,
245
+ startTime,
246
+ endTime,
247
+ duration: endTime - startTime,
248
+ findings,
249
+ screenshots: [],
250
+ metadata: {
251
+ browserEngine: 'webkit',
252
+ browserVersion: metadata || 'unknown',
253
+ nodeVersion: process.version,
254
+ },
255
+ };
256
+ }
257
+ }