create-command-center 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/LICENSE.agent-skills +21 -0
- package/README.md +62 -2
- package/RELEASING.md +29 -0
- package/UPSTREAM.md +13 -0
- package/bin/create-command-center.mjs +34 -0
- package/installer/build-parsers.mjs +21 -0
- package/installer/install.mjs +103 -0
- package/installer/template/AGENTS.md +9 -0
- package/installer/template/README.md +13 -0
- package/installer/template/gitignore +5 -0
- package/installer/template/repos/index.md +5 -0
- package/package.json +41 -4
- package/references/accessibility-checklist.md +160 -0
- package/references/definition-of-done.md +67 -0
- package/references/observability-checklist.md +92 -0
- package/references/orchestration-patterns.md +370 -0
- package/references/performance-checklist.md +239 -0
- package/references/security-checklist.md +250 -0
- package/references/testing-patterns.md +236 -0
- package/skills/accessibility-engineering/SKILL.md +133 -0
- package/skills/accessibility-engineering/scripts/audit-a11y.sh +233 -0
- package/skills/api-and-interface-design/SKILL.md +369 -0
- package/skills/browser-testing-with-devtools/SKILL.md +319 -0
- package/skills/cc/SKILL.md +26 -0
- package/skills/cc/assets/config.md +28 -0
- package/skills/cc/assets/progress.md +23 -0
- package/skills/cc/references/jobs.md +30 -0
- package/skills/cc/references/registration.md +63 -0
- package/skills/cc/scripts/checks.mjs +109 -0
- package/skills/cc/scripts/errors.mjs +3 -0
- package/skills/cc/scripts/home.mjs +60 -0
- package/skills/cc/scripts/init.mjs +499 -0
- package/skills/cc/scripts/inspection.mjs +315 -0
- package/skills/cc/scripts/vendor/LICENSE.parsers.txt +70 -0
- package/skills/cc/scripts/vendor/parsers.mjs +9951 -0
- package/skills/ci-cd-and-automation/SKILL.md +395 -0
- package/skills/code-review-and-quality/SKILL.md +402 -0
- package/skills/code-simplification/SKILL.md +331 -0
- package/skills/constraint-driven-development/SKILL.md +319 -0
- package/skills/constraint-driven-development/references/floor-guard.md +182 -0
- package/skills/constraint-driven-development/scripts/quality-gate.mjs +45 -0
- package/skills/context-engineering/SKILL.md +353 -0
- package/skills/debugging-and-error-recovery/SKILL.md +300 -0
- package/skills/deprecation-and-migration/SKILL.md +252 -0
- package/skills/documentation-and-adrs/SKILL.md +320 -0
- package/skills/doubt-driven-development/SKILL.md +245 -0
- package/skills/frontend-ui-engineering/SKILL.md +346 -0
- package/skills/git-workflow-and-versioning/SKILL.md +355 -0
- package/skills/idea-refine/SKILL.md +195 -0
- package/skills/idea-refine/examples.md +238 -0
- package/skills/idea-refine/frameworks.md +99 -0
- package/skills/idea-refine/refinement-criteria.md +113 -0
- package/skills/idea-refine/scripts/idea-refine.sh +15 -0
- package/skills/incremental-implementation/SKILL.md +249 -0
- package/skills/interview-me/SKILL.md +235 -0
- package/skills/observability-and-instrumentation/SKILL.md +238 -0
- package/skills/performance-optimization/SKILL.md +267 -0
- package/skills/performance-optimization/references/optimization-patterns.md +250 -0
- package/skills/planning-and-task-breakdown/SKILL.md +259 -0
- package/skills/security-and-hardening/SKILL.md +216 -0
- package/skills/security-and-hardening/references/hardening-patterns.md +333 -0
- package/skills/shipping-and-launch/SKILL.md +336 -0
- package/skills/source-driven-development/SKILL.md +217 -0
- package/skills/spec-driven-development/SKILL.md +307 -0
- package/skills/test-driven-development/SKILL.md +400 -0
- package/skills/using-agent-skills/SKILL.md +194 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
# Testing Patterns Reference (JavaScript/TypeScript)
|
|
2
|
+
|
|
3
|
+
Quick reference of JavaScript/TypeScript testing patterns — Jest, React Testing Library, Supertest, and Playwright — illustrating the universal principles from the `test-driven-development` skill. The principles (Arrange-Act-Assert, naming, mock discipline, anti-patterns) apply in any ecosystem; the syntax and tooling shown here are JS/TS-specific. In another stack, follow the same principles with the repository's own test framework and commands.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Test Structure (Arrange-Act-Assert)](#test-structure-arrange-act-assert)
|
|
8
|
+
- [Test Naming Conventions](#test-naming-conventions)
|
|
9
|
+
- [Common Assertions](#common-assertions)
|
|
10
|
+
- [Mocking Patterns](#mocking-patterns)
|
|
11
|
+
- [React/Component Testing](#reactcomponent-testing)
|
|
12
|
+
- [API / Integration Testing](#api--integration-testing)
|
|
13
|
+
- [E2E Testing (Playwright)](#e2e-testing-playwright)
|
|
14
|
+
- [Test Anti-Patterns](#test-anti-patterns)
|
|
15
|
+
|
|
16
|
+
## Test Structure (Arrange-Act-Assert)
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
it('describes expected behavior', () => {
|
|
20
|
+
// Arrange: Set up test data and preconditions
|
|
21
|
+
const input = { title: 'Test Task', priority: 'high' };
|
|
22
|
+
|
|
23
|
+
// Act: Perform the action being tested
|
|
24
|
+
const result = createTask(input);
|
|
25
|
+
|
|
26
|
+
// Assert: Verify the outcome
|
|
27
|
+
expect(result.title).toBe('Test Task');
|
|
28
|
+
expect(result.priority).toBe('high');
|
|
29
|
+
expect(result.status).toBe('pending');
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Test Naming Conventions
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
// Pattern: [unit] [expected behavior] [condition]
|
|
37
|
+
describe('TaskService.createTask', () => {
|
|
38
|
+
it('creates a task with default pending status', () => {});
|
|
39
|
+
it('throws ValidationError when title is empty', () => {});
|
|
40
|
+
it('trims whitespace from title', () => {});
|
|
41
|
+
it('generates a unique ID for each task', () => {});
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Common Assertions
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
// Equality
|
|
49
|
+
expect(result).toBe(expected); // Strict equality (===)
|
|
50
|
+
expect(result).toEqual(expected); // Deep equality (objects/arrays)
|
|
51
|
+
expect(result).toStrictEqual(expected); // Deep equality + type matching
|
|
52
|
+
|
|
53
|
+
// Truthiness
|
|
54
|
+
expect(result).toBeTruthy();
|
|
55
|
+
expect(result).toBeFalsy();
|
|
56
|
+
expect(result).toBeNull();
|
|
57
|
+
expect(result).toBeDefined();
|
|
58
|
+
expect(result).toBeUndefined();
|
|
59
|
+
|
|
60
|
+
// Numbers
|
|
61
|
+
expect(result).toBeGreaterThan(5);
|
|
62
|
+
expect(result).toBeLessThanOrEqual(10);
|
|
63
|
+
expect(result).toBeCloseTo(0.3, 5); // Floating point
|
|
64
|
+
|
|
65
|
+
// Strings
|
|
66
|
+
expect(result).toMatch(/pattern/);
|
|
67
|
+
expect(result).toContain('substring');
|
|
68
|
+
|
|
69
|
+
// Arrays / Objects
|
|
70
|
+
expect(array).toContain(item);
|
|
71
|
+
expect(array).toHaveLength(3);
|
|
72
|
+
expect(object).toHaveProperty('key', 'value');
|
|
73
|
+
|
|
74
|
+
// Errors
|
|
75
|
+
expect(() => fn()).toThrow();
|
|
76
|
+
expect(() => fn()).toThrow(ValidationError);
|
|
77
|
+
expect(() => fn()).toThrow('specific message');
|
|
78
|
+
|
|
79
|
+
// Async
|
|
80
|
+
await expect(asyncFn()).resolves.toBe(value);
|
|
81
|
+
await expect(asyncFn()).rejects.toThrow(Error);
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Mocking Patterns
|
|
85
|
+
|
|
86
|
+
### Mock Functions
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
const mockFn = jest.fn();
|
|
90
|
+
mockFn.mockReturnValue(42);
|
|
91
|
+
mockFn.mockResolvedValue({ data: 'test' });
|
|
92
|
+
mockFn.mockImplementation((x) => x * 2);
|
|
93
|
+
|
|
94
|
+
expect(mockFn).toHaveBeenCalled();
|
|
95
|
+
expect(mockFn).toHaveBeenCalledWith('arg1', 'arg2');
|
|
96
|
+
expect(mockFn).toHaveBeenCalledTimes(3);
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Mock Modules
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
// Mock an entire module
|
|
103
|
+
jest.mock('./database', () => ({
|
|
104
|
+
query: jest.fn().mockResolvedValue([{ id: 1, title: 'Test' }]),
|
|
105
|
+
}));
|
|
106
|
+
|
|
107
|
+
// Mock specific exports
|
|
108
|
+
jest.mock('./utils', () => ({
|
|
109
|
+
...jest.requireActual('./utils'),
|
|
110
|
+
generateId: jest.fn().mockReturnValue('test-id'),
|
|
111
|
+
}));
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Mock at Boundaries Only
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
Mock these: Don't mock these:
|
|
118
|
+
├── Database calls ├── Internal utility functions
|
|
119
|
+
├── HTTP requests ├── Business logic
|
|
120
|
+
├── File system operations ├── Data transformations
|
|
121
|
+
├── External API calls ├── Validation functions
|
|
122
|
+
└── Time/Date (when needed) └── Pure functions
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## React/Component Testing
|
|
126
|
+
|
|
127
|
+
```tsx
|
|
128
|
+
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
|
129
|
+
|
|
130
|
+
describe('TaskForm', () => {
|
|
131
|
+
it('submits the form with entered data', async () => {
|
|
132
|
+
const onSubmit = jest.fn();
|
|
133
|
+
render(<TaskForm onSubmit={onSubmit} />);
|
|
134
|
+
|
|
135
|
+
// Find elements by accessible role/label (not test IDs)
|
|
136
|
+
await screen.findByRole('textbox', { name: /title/i });
|
|
137
|
+
fireEvent.change(screen.getByRole('textbox', { name: /title/i }), {
|
|
138
|
+
target: { value: 'New Task' },
|
|
139
|
+
});
|
|
140
|
+
fireEvent.click(screen.getByRole('button', { name: /create/i }));
|
|
141
|
+
|
|
142
|
+
await waitFor(() => {
|
|
143
|
+
expect(onSubmit).toHaveBeenCalledWith({ title: 'New Task' });
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('shows validation error for empty title', async () => {
|
|
148
|
+
render(<TaskForm onSubmit={jest.fn()} />);
|
|
149
|
+
|
|
150
|
+
fireEvent.click(screen.getByRole('button', { name: /create/i }));
|
|
151
|
+
|
|
152
|
+
expect(await screen.findByText(/title is required/i)).toBeInTheDocument();
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## API / Integration Testing
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
import request from 'supertest';
|
|
161
|
+
import { app } from '../src/app';
|
|
162
|
+
|
|
163
|
+
describe('POST /api/tasks', () => {
|
|
164
|
+
it('creates a task and returns 201', async () => {
|
|
165
|
+
const response = await request(app)
|
|
166
|
+
.post('/api/tasks')
|
|
167
|
+
.send({ title: 'Test Task' })
|
|
168
|
+
.set('Authorization', `Bearer ${testToken}`)
|
|
169
|
+
.expect(201);
|
|
170
|
+
|
|
171
|
+
expect(response.body).toMatchObject({
|
|
172
|
+
id: expect.any(String),
|
|
173
|
+
title: 'Test Task',
|
|
174
|
+
status: 'pending',
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('returns 422 for invalid input', async () => {
|
|
179
|
+
const response = await request(app)
|
|
180
|
+
.post('/api/tasks')
|
|
181
|
+
.send({ title: '' })
|
|
182
|
+
.set('Authorization', `Bearer ${testToken}`)
|
|
183
|
+
.expect(422);
|
|
184
|
+
|
|
185
|
+
expect(response.body.error.code).toBe('VALIDATION_ERROR');
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('returns 401 without authentication', async () => {
|
|
189
|
+
await request(app)
|
|
190
|
+
.post('/api/tasks')
|
|
191
|
+
.send({ title: 'Test' })
|
|
192
|
+
.expect(401);
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## E2E Testing (Playwright)
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
import { test, expect } from '@playwright/test';
|
|
201
|
+
|
|
202
|
+
test('user can create and complete a task', async ({ page }) => {
|
|
203
|
+
// Navigate and authenticate
|
|
204
|
+
await page.goto('/');
|
|
205
|
+
await page.getByRole('textbox', { name: /email/i }).fill('test@example.com');
|
|
206
|
+
await page.getByLabel(/password/i).fill('testpass123');
|
|
207
|
+
await page.getByRole('button', { name: /log in/i }).click();
|
|
208
|
+
|
|
209
|
+
// Create a task
|
|
210
|
+
await page.getByRole('button', { name: /new task/i }).click();
|
|
211
|
+
await page.getByRole('textbox', { name: /title/i }).fill('Buy groceries');
|
|
212
|
+
await page.getByRole('button', { name: /create/i }).click();
|
|
213
|
+
|
|
214
|
+
// Verify task appears
|
|
215
|
+
// listitem has no accessible name from its content, so filter by text
|
|
216
|
+
const task = page.getByRole('listitem').filter({ hasText: /buy groceries/i });
|
|
217
|
+
await expect(task).toBeVisible();
|
|
218
|
+
|
|
219
|
+
// Complete the task
|
|
220
|
+
await task.getByRole('checkbox', { name: /complete buy groceries/i }).check();
|
|
221
|
+
await expect(task).toHaveCSS('text-decoration-line', 'line-through');
|
|
222
|
+
});
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Test Anti-Patterns
|
|
226
|
+
|
|
227
|
+
| Anti-Pattern | Problem | Better Approach |
|
|
228
|
+
|---|---|---|
|
|
229
|
+
| Testing implementation details | Breaks on refactor | Test inputs/outputs |
|
|
230
|
+
| Snapshot everything | No one reviews snapshot diffs | Assert specific values |
|
|
231
|
+
| Shared mutable state | Tests pollute each other | Setup/teardown per test |
|
|
232
|
+
| Testing third-party code | Wastes time, not your bug | Mock the boundary |
|
|
233
|
+
| Skipping tests to pass CI | Hides real bugs | Fix or delete the test |
|
|
234
|
+
| Using `test.skip` permanently | Dead code | Remove or fix it |
|
|
235
|
+
| Overly broad assertions | Doesn't catch regressions | Be specific |
|
|
236
|
+
| No async error handling | Swallowed errors, false passes | Always `await` async tests |
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: accessibility-engineering
|
|
3
|
+
description: Audits existing interfaces for WCAG 2.2 AA conformance and remediates the violations found. Use when auditing a page or component for accessibility, running axe-core or pa11y, triaging a11y violations, or checking screen reader and contrast issues before shipping.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Accessibility Engineering
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
Accessibility is not a polish step — it's a legal requirement in many jurisdictions, an engineering quality standard, and a prerequisite for shipping. This skill audits existing interfaces, triages the findings, and remediates verified violations. The goal is WCAG 2.2 AA compliance supported by automated tools and manual testing.
|
|
11
|
+
|
|
12
|
+
## When to Use
|
|
13
|
+
|
|
14
|
+
- Before shipping a user-facing change that needs an accessibility audit
|
|
15
|
+
- When a11y issues are reported (e.g., "screen reader can't read this", "keyboard navigation broken")
|
|
16
|
+
- When auditing an existing interface for compliance
|
|
17
|
+
- When triaging axe-core or pa11y findings
|
|
18
|
+
- When remediating verified accessibility violations
|
|
19
|
+
|
|
20
|
+
**Do NOT use** for building new UI components from scratch; use `frontend-ui-engineering` for construction guidance. Do not use for backend-only changes, CLIs, or library code with no UI output.
|
|
21
|
+
|
|
22
|
+
## Workflow
|
|
23
|
+
|
|
24
|
+
### Phase 1: Route New UI Work
|
|
25
|
+
|
|
26
|
+
For component construction, interaction patterns, and focus-management guidance, use `../frontend-ui-engineering/SKILL.md`. Do not restate that skill here. Return to this workflow once an interface exists and needs auditing or remediation.
|
|
27
|
+
|
|
28
|
+
### Phase 2: Run Automated Audit
|
|
29
|
+
|
|
30
|
+
Execute accessibility checks in this order:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# axe-core rules through pinned @axe-core/cli (the axe-core package ships no CLI)
|
|
34
|
+
npx --yes @axe-core/cli@4.13.0 http://localhost:3000 --exit
|
|
35
|
+
|
|
36
|
+
# Keep the JSON for the accessibility-auditor
|
|
37
|
+
npx --yes @axe-core/cli@4.13.0 http://localhost:3000 --dir ./a11y-reports --save axe.json
|
|
38
|
+
|
|
39
|
+
# Pinned pa11y for HTML validation (WCAG2AA rules via HTML_CodeSniffer)
|
|
40
|
+
npx --yes pa11y@9.1.1 http://localhost:3000
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
For a combined report, run `bash skills/accessibility-engineering/scripts/audit-a11y.sh url <url> --json`. It runs both pinned tools, records their status and versions, and fails rather than reporting a clean result when either tool does not produce a valid report.
|
|
44
|
+
|
|
45
|
+
Review the violations grouped by severity:
|
|
46
|
+
- **Critical** — Blocks screen reader access entirely (missing alt text on info images, empty buttons)
|
|
47
|
+
- **Serious** — Makes content difficult or impossible to access (low contrast, missing labels)
|
|
48
|
+
- **Moderate** — Causes confusion or extra effort (heading level skips, redundant ARIA)
|
|
49
|
+
- **Minor** — Cosmetic or progressive enhancement (missing lang attribute on inner elements)
|
|
50
|
+
|
|
51
|
+
For each violation, verify it's a real issue (not a false positive) by inspecting the element in the browser.
|
|
52
|
+
|
|
53
|
+
### Phase 3: Manual Testing
|
|
54
|
+
|
|
55
|
+
Automated checks are a smoke test, not proof of conformance. Complete the audit manually.
|
|
56
|
+
|
|
57
|
+
**Keyboard audit:**
|
|
58
|
+
1. Tab through every interactive element — can you see where you are?
|
|
59
|
+
2. Activate buttons and links with Enter/Space
|
|
60
|
+
3. Close modals with Escape
|
|
61
|
+
4. Navigate lists with Arrow keys
|
|
62
|
+
5. Verify no keyboard traps exist
|
|
63
|
+
|
|
64
|
+
**Screen reader audit (VoiceOver on macOS, NVDA on Windows):**
|
|
65
|
+
1. Navigate by heading (VoiceOver: Ctrl+Option+Cmd+H) — is the structure logical?
|
|
66
|
+
2. Navigate by landmark (open the rotor with Ctrl+Option+U, choose Landmarks) — are regions labeled?
|
|
67
|
+
3. Navigate by link (open the rotor with Ctrl+Option+U, choose Links) — do link descriptions make sense out of context?
|
|
68
|
+
4. Interact with a form — are labels announced? Are error messages read?
|
|
69
|
+
5. Navigate a dynamic update — are changes announced?
|
|
70
|
+
|
|
71
|
+
**Visual audit:**
|
|
72
|
+
1. Verify color contrast (4.5:1 text, 3:1 large text, 3:1 UI components)
|
|
73
|
+
2. Zoom to 200% — does layout break or overlap?
|
|
74
|
+
3. Test with forced colors / high contrast mode (Windows High Contrast)
|
|
75
|
+
4. Reduce motion (prefers-reduced-motion) — are animations disabled?
|
|
76
|
+
5. Test focus visibility — is the focus ring visible against all backgrounds?
|
|
77
|
+
|
|
78
|
+
### Phase 4: Fix Violations
|
|
79
|
+
|
|
80
|
+
For each finding, apply the remediation in order:
|
|
81
|
+
|
|
82
|
+
1. **Fix the root cause** — Replace a `<div>` with `<button>`, add `<label>`, set `alt` text
|
|
83
|
+
2. **Add ARIA as bridge** — If native HTML can't express the pattern, add ARIA attributes
|
|
84
|
+
3. **Test the fix** — Re-run the automated check and manual verification
|
|
85
|
+
|
|
86
|
+
Apply the accessibility checklist (`../../references/accessibility-checklist.md`) as a minimal baseline.
|
|
87
|
+
|
|
88
|
+
## Common Rationalizations
|
|
89
|
+
|
|
90
|
+
| Rationalization | Reality |
|
|
91
|
+
|---|---|
|
|
92
|
+
| "We'll fix a11y later" | Delayed remediation compounds across components and can create legal liability. Audit before shipping. |
|
|
93
|
+
| "Automated tools caught everything" | Automated checks cannot prove keyboard or screen reader behavior. Manual testing is mandatory. |
|
|
94
|
+
| "Screen reader users are a tiny minority" | Accessibility is a requirement, not a usage-share calculation. Keyboard navigation, captions, and clear structure also help users across contexts. |
|
|
95
|
+
| "This is an internal tool, it doesn't need a11y" | Internal tools are subject to the same regulations. Disabled employees and contractors need access. |
|
|
96
|
+
| "I'll just use aria-label everywhere" | ARIA is a bridge, not a foundation. Semantic HTML first. Overusing ARIA creates maintenance burden and can make things worse. |
|
|
97
|
+
| "The design system handles accessibility" | Design systems provide accessible primitives. How you compose them determines whether the result is accessible. |
|
|
98
|
+
| "The audit passed axe-core, so we're done" | Pass axe-core as a smoke test, then test with screen readers and keyboard. A green lighthouse score is not a clean bill of health. |
|
|
99
|
+
|
|
100
|
+
## Red Flags
|
|
101
|
+
|
|
102
|
+
- Elements that look clickable but aren't keyboard-focusable
|
|
103
|
+
- Color as the sole indicator of state (red for error, green for success)
|
|
104
|
+
- Focus outline removed without a visible replacement
|
|
105
|
+
- Missing labels on form inputs
|
|
106
|
+
- No heading hierarchy or skipped heading levels
|
|
107
|
+
- Empty or unlabeled buttons and links
|
|
108
|
+
- Modals that don't trap focus or restore focus on close
|
|
109
|
+
- No `alt` text on meaningful images (or `alt=""` missing on decorative ones)
|
|
110
|
+
- Touch targets that fail SC 2.5.8's 24x24 CSS px size-or-spacing requirement and do not qualify for an exception (AA; 44x44 is the AAA target, SC 2.5.5)
|
|
111
|
+
- Autoplaying video or audio without controls
|
|
112
|
+
- Low contrast text (especially on hover, disabled states, placeholders)
|
|
113
|
+
|
|
114
|
+
## See Also
|
|
115
|
+
|
|
116
|
+
- `../../references/accessibility-checklist.md` — Quick reference for WCAG 2.2 AA
|
|
117
|
+
- `../frontend-ui-engineering/SKILL.md` — Building accessible components from the start
|
|
118
|
+
- `../../agents/accessibility-auditor.md` — Dedicated a11y audit persona for deep reviews
|
|
119
|
+
|
|
120
|
+
## Verification
|
|
121
|
+
|
|
122
|
+
After completing the accessibility workflow:
|
|
123
|
+
|
|
124
|
+
- [ ] Automated audit passes with no Critical or Serious violations
|
|
125
|
+
- [ ] All interactive elements are keyboard accessible (Tab, Enter, Escape, Arrow keys)
|
|
126
|
+
- [ ] Screen reader navigation by heading, landmark, and link verified with a named browser + AT pair (or recorded as `manual` and untested — never reported as verified)
|
|
127
|
+
- [ ] Focus order matches visual order
|
|
128
|
+
- [ ] Color contrast passes 4.5:1 text / 3:1 large text / 3:1 UI components
|
|
129
|
+
- [ ] All form inputs have associated labels
|
|
130
|
+
- [ ] All images have appropriate `alt` text
|
|
131
|
+
- [ ] Dynamic content changes are announced (aria-live)
|
|
132
|
+
- [ ] Page is usable at 200% zoom with no content loss
|
|
133
|
+
- [ ] Touch targets satisfy SC 2.5.8's 24x24 CSS px size-or-spacing requirement or a normative exception (AA); 44x44 is the enhanced AAA target (SC 2.5.5)
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
set -e
|
|
3
|
+
|
|
4
|
+
# accessibility-engineering: audit-a11y.sh
|
|
5
|
+
# Runs automated accessibility checks on a given URL or file.
|
|
6
|
+
# Outputs structured JSON with violations grouped by severity.
|
|
7
|
+
#
|
|
8
|
+
# Usage:
|
|
9
|
+
# bash audit-a11y.sh url <url> [--json]
|
|
10
|
+
# bash audit-a11y.sh file <path> [--json]
|
|
11
|
+
#
|
|
12
|
+
# Requires: npx (@axe-core/cli and pa11y are fetched at the pinned versions below)
|
|
13
|
+
|
|
14
|
+
SCRIPT_NAME="audit-a11y"
|
|
15
|
+
AXE_VERSION="4.13.0"
|
|
16
|
+
PA11Y_VERSION="9.1.1"
|
|
17
|
+
TEMP_DIR=$(mktemp -d)
|
|
18
|
+
trap 'rm -rf "$TEMP_DIR"' EXIT
|
|
19
|
+
|
|
20
|
+
MODE="${1:-}"
|
|
21
|
+
TARGET="${2:-}"
|
|
22
|
+
FORMAT="${3:-text}"
|
|
23
|
+
|
|
24
|
+
if [ -z "$MODE" ] || [ -z "$TARGET" ]; then
|
|
25
|
+
echo "Usage: bash audit-a11y.sh url <url> [--json]" >&2
|
|
26
|
+
echo " bash audit-a11y.sh file <path> [--json]" >&2
|
|
27
|
+
exit 1
|
|
28
|
+
fi
|
|
29
|
+
|
|
30
|
+
case "$MODE" in
|
|
31
|
+
url)
|
|
32
|
+
echo "Running axe-core audit on $TARGET..." >&2
|
|
33
|
+
if npx --yes "@axe-core/cli@$AXE_VERSION" "$TARGET" --dir "$TEMP_DIR" --save axe-report.json >&2; then
|
|
34
|
+
AXE_EXIT=0
|
|
35
|
+
else
|
|
36
|
+
AXE_EXIT=$?
|
|
37
|
+
fi
|
|
38
|
+
|
|
39
|
+
echo "Running pa11y audit on $TARGET..." >&2
|
|
40
|
+
if npx --yes "pa11y@$PA11Y_VERSION" "$TARGET" --reporter json 2>/dev/null > "$TEMP_DIR/pa11y-report.json"; then
|
|
41
|
+
PA11Y_EXIT=0
|
|
42
|
+
else
|
|
43
|
+
PA11Y_EXIT=$?
|
|
44
|
+
fi
|
|
45
|
+
;;
|
|
46
|
+
file)
|
|
47
|
+
AXE_EXIT=-1
|
|
48
|
+
echo "Running pa11y on file $TARGET..." >&2
|
|
49
|
+
if npx --yes "pa11y@$PA11Y_VERSION" "$TARGET" --reporter json > "$TEMP_DIR/pa11y-report.json" 2>/dev/null; then
|
|
50
|
+
PA11Y_EXIT=0
|
|
51
|
+
else
|
|
52
|
+
PA11Y_EXIT=$?
|
|
53
|
+
fi
|
|
54
|
+
echo "File-based axe analysis limited; prefer URL mode for full coverage." >&2
|
|
55
|
+
;;
|
|
56
|
+
*)
|
|
57
|
+
echo "Unknown mode: $MODE. Use 'url' or 'file'." >&2
|
|
58
|
+
exit 1
|
|
59
|
+
;;
|
|
60
|
+
esac
|
|
61
|
+
|
|
62
|
+
report_status() {
|
|
63
|
+
local tool="$1"
|
|
64
|
+
local report="$2"
|
|
65
|
+
local exit_code="$3"
|
|
66
|
+
if [ ! -s "$report" ]; then
|
|
67
|
+
printf 'failed'
|
|
68
|
+
return
|
|
69
|
+
fi
|
|
70
|
+
|
|
71
|
+
# axe runs without --exit, so any non-zero status is an execution failure.
|
|
72
|
+
# pa11y uses exit 2 when a valid report contains violations; other non-zero
|
|
73
|
+
# statuses mean the audit itself failed.
|
|
74
|
+
if { [ "$tool" = "axe" ] && [ "$exit_code" -ne 0 ]; } || \
|
|
75
|
+
{ [ "$tool" = "pa11y" ] && [ "$exit_code" -ne 0 ] && [ "$exit_code" -ne 2 ]; }; then
|
|
76
|
+
printf 'failed'
|
|
77
|
+
elif node -e "
|
|
78
|
+
const fs = require('fs');
|
|
79
|
+
const tool = process.argv[1];
|
|
80
|
+
const report = JSON.parse(fs.readFileSync(process.argv[2], 'utf8'));
|
|
81
|
+
const valid = tool === 'axe'
|
|
82
|
+
? Array.isArray(report) && report.length > 0 && report.every(run => run && Array.isArray(run.violations))
|
|
83
|
+
: Array.isArray(report);
|
|
84
|
+
if (!valid) process.exit(1);
|
|
85
|
+
" "$tool" "$report" >/dev/null 2>&1; then
|
|
86
|
+
printf 'completed'
|
|
87
|
+
else
|
|
88
|
+
printf 'invalid-report'
|
|
89
|
+
fi
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if [ "$MODE" = "url" ]; then
|
|
93
|
+
AXE_STATUS=$(report_status axe "$TEMP_DIR/axe-report.json" "$AXE_EXIT")
|
|
94
|
+
else
|
|
95
|
+
AXE_STATUS="not-run"
|
|
96
|
+
fi
|
|
97
|
+
PA11Y_STATUS=$(report_status pa11y "$TEMP_DIR/pa11y-report.json" "$PA11Y_EXIT")
|
|
98
|
+
|
|
99
|
+
# A URL audit promises both engines. A valid report is the success signal because
|
|
100
|
+
# pa11y may return non-zero when it found violations. Never turn a partial run
|
|
101
|
+
# into a clean result just because the remaining engine returned an empty list.
|
|
102
|
+
if [ "$PA11Y_STATUS" != "completed" ] || { [ "$MODE" = "url" ] && [ "$AXE_STATUS" != "completed" ]; }; then
|
|
103
|
+
echo "$SCRIPT_NAME: incomplete audit; refusing to report a violation total" >&2
|
|
104
|
+
echo "$SCRIPT_NAME: tool status: @axe-core/cli@$AXE_VERSION=$AXE_STATUS (exit $AXE_EXIT), pa11y@$PA11Y_VERSION=$PA11Y_STATUS (exit $PA11Y_EXIT)" >&2
|
|
105
|
+
exit 1
|
|
106
|
+
fi
|
|
107
|
+
|
|
108
|
+
# Merge results into structured JSON output
|
|
109
|
+
RESULT_FILE="$TEMP_DIR/result.json"
|
|
110
|
+
|
|
111
|
+
cat > "$RESULT_FILE" << RESULT_EOF
|
|
112
|
+
{
|
|
113
|
+
"tool": "audit-a11y",
|
|
114
|
+
"tools": [
|
|
115
|
+
{"name": "@axe-core/cli", "version": "$AXE_VERSION", "status": "$AXE_STATUS", "exitCode": $AXE_EXIT},
|
|
116
|
+
{"name": "pa11y", "version": "$PA11Y_VERSION", "status": "$PA11Y_STATUS", "exitCode": $PA11Y_EXIT}
|
|
117
|
+
],
|
|
118
|
+
"summary": {
|
|
119
|
+
"violations": 0,
|
|
120
|
+
"critical": 0,
|
|
121
|
+
"serious": 0,
|
|
122
|
+
"moderate": 0,
|
|
123
|
+
"minor": 0
|
|
124
|
+
},
|
|
125
|
+
"violations": [],
|
|
126
|
+
"recommendations": []
|
|
127
|
+
}
|
|
128
|
+
RESULT_EOF
|
|
129
|
+
|
|
130
|
+
# Parse axe results
|
|
131
|
+
if [ -f "$TEMP_DIR/axe-report.json" ]; then
|
|
132
|
+
node -e "
|
|
133
|
+
const fs = require('fs');
|
|
134
|
+
const result = JSON.parse(fs.readFileSync('$TEMP_DIR/result.json', 'utf8'));
|
|
135
|
+
try {
|
|
136
|
+
const axe = JSON.parse(fs.readFileSync('$TEMP_DIR/axe-report.json', 'utf8'));
|
|
137
|
+
// @axe-core/cli saves an array with one result per URL, and no results wrapper.
|
|
138
|
+
for (const run of (Array.isArray(axe) ? axe : [axe])) {
|
|
139
|
+
const violations = run.violations || [];
|
|
140
|
+
result.summary.violations += violations.length;
|
|
141
|
+
for (const v of violations) {
|
|
142
|
+
const sev = v.impact || 'minor';
|
|
143
|
+
if (result.summary[sev] !== undefined) result.summary[sev]++;
|
|
144
|
+
result.violations.push({
|
|
145
|
+
source: 'axe-core',
|
|
146
|
+
id: v.id,
|
|
147
|
+
impact: sev,
|
|
148
|
+
description: v.description,
|
|
149
|
+
help: v.help,
|
|
150
|
+
helpUrl: v.helpUrl,
|
|
151
|
+
tags: v.tags || [],
|
|
152
|
+
nodes: (v.nodes || []).map(n => ({
|
|
153
|
+
html: n.html,
|
|
154
|
+
target: n.target,
|
|
155
|
+
failureSummary: n.failureSummary
|
|
156
|
+
}))
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
} catch (e) {
|
|
161
|
+
// An empty report is covered by the guard above; a non-empty one that does
|
|
162
|
+
// not parse is a tool failure, not a clean result.
|
|
163
|
+
if (fs.statSync('$TEMP_DIR/axe-report.json').size > 0) {
|
|
164
|
+
console.error('$SCRIPT_NAME: axe-report.json is not valid JSON: ' + e.message);
|
|
165
|
+
process.exit(1);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
fs.writeFileSync('$TEMP_DIR/result.json', JSON.stringify(result, null, 2));
|
|
169
|
+
"
|
|
170
|
+
fi
|
|
171
|
+
|
|
172
|
+
# Parse pa11y results
|
|
173
|
+
if [ -f "$TEMP_DIR/pa11y-report.json" ]; then
|
|
174
|
+
node -e "
|
|
175
|
+
const fs = require('fs');
|
|
176
|
+
const result = JSON.parse(fs.readFileSync('$TEMP_DIR/result.json', 'utf8'));
|
|
177
|
+
try {
|
|
178
|
+
const pa11y = JSON.parse(fs.readFileSync('$TEMP_DIR/pa11y-report.json', 'utf8'));
|
|
179
|
+
const issues = Array.isArray(pa11y) ? pa11y : (pa11y.issues || []);
|
|
180
|
+
result.summary.violations += issues.length;
|
|
181
|
+
for (const issue of issues) {
|
|
182
|
+
// pa11y has no impact scale: typeCode 1 is "error", and by default pa11y
|
|
183
|
+
// reports only errors. Mapping that to critical would turn every pa11y
|
|
184
|
+
// result into a /ship NO-GO, because axe rates the same failure serious.
|
|
185
|
+
const sev = (issue.typeCode === 1 ? 'serious' : issue.typeCode === 2 ? 'moderate' : 'minor');
|
|
186
|
+
if (result.summary[sev] !== undefined) result.summary[sev]++;
|
|
187
|
+
result.violations.push({
|
|
188
|
+
source: 'pa11y',
|
|
189
|
+
code: issue.code,
|
|
190
|
+
impact: sev,
|
|
191
|
+
message: issue.message,
|
|
192
|
+
selector: issue.selector,
|
|
193
|
+
context: issue.context,
|
|
194
|
+
type: issue.type
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
} catch (e) {
|
|
198
|
+
// Same as the axe block: an empty report is covered by the guard above.
|
|
199
|
+
if (fs.statSync('$TEMP_DIR/pa11y-report.json').size > 0) {
|
|
200
|
+
console.error('$SCRIPT_NAME: pa11y-report.json is not valid JSON: ' + e.message);
|
|
201
|
+
process.exit(1);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
fs.writeFileSync('$TEMP_DIR/result.json', JSON.stringify(result, null, 2));
|
|
205
|
+
"
|
|
206
|
+
fi
|
|
207
|
+
|
|
208
|
+
if [ "$FORMAT" = "--json" ]; then
|
|
209
|
+
cat "$RESULT_FILE"
|
|
210
|
+
else
|
|
211
|
+
node -e "
|
|
212
|
+
const r = JSON.parse(require('fs').readFileSync('$RESULT_FILE', 'utf8'));
|
|
213
|
+
console.log('Accessibility Audit Results');
|
|
214
|
+
console.log('===========================');
|
|
215
|
+
console.log('Tools:');
|
|
216
|
+
for (const tool of r.tools) {
|
|
217
|
+
console.log(' ' + tool.name + '@' + tool.version + ': ' + tool.status + ' (exit ' + tool.exitCode + ')');
|
|
218
|
+
}
|
|
219
|
+
console.log('');
|
|
220
|
+
console.log('Total violations: ' + r.summary.violations);
|
|
221
|
+
console.log(' Critical: ' + r.summary.critical);
|
|
222
|
+
console.log(' Serious: ' + r.summary.serious);
|
|
223
|
+
console.log(' Moderate: ' + r.summary.moderate);
|
|
224
|
+
console.log(' Minor: ' + r.summary.minor);
|
|
225
|
+
console.log('');
|
|
226
|
+
for (const v of r.violations) {
|
|
227
|
+
console.log('[' + v.impact.toUpperCase() + '] ' + (v.help || v.message || v.id));
|
|
228
|
+
if (v.nodes && v.nodes[0]) console.log(' → ' + v.nodes[0].target);
|
|
229
|
+
if (v.selector) console.log(' → ' + v.selector);
|
|
230
|
+
console.log('');
|
|
231
|
+
}
|
|
232
|
+
"
|
|
233
|
+
fi
|