The user wants a system (a "patrol") that automatically detects low-contrast issues in a UI, flags when these issues get worse ("regressions"), and feeds this information into the workflow for a design system team ("pipes into design system sprints").
Key Components:
- Detection: How do we find low contrast? (WCAG standards, automated tools).
- Patrol: When does this run? (CI/CD, scheduled cron jobs).
- Flagging Regressions: How do we know it's a new or worse issue? (Baselines, diffing).
- Piping into Sprints: How does this translate to actionable work? (Issue creation, prioritization, backlog grooming).
Target Audience: Engineering/Design leads, DevOps, UI/UX developers.
Tone: Professional, technical, actionable, slightly metaphorical (using "patrol").
Step-by-Step Engineering Plan:
-
Step 1: The "Sensors" (Detection Logic)
- Need a script that runs accessibility checks.
- Tools: Axe-core, Pa11y, Lighthouse.
- Specific focus: Color contrast ratio (WCAG AA/AAA).
- Mechanism: Snapshotting specific component states or pages.
-
Step 2: The "Patrol Route" (CI/CD Integration)
- Where does this live?
- Option A: Pull Request (PR) checks (Catch it early).
- Option B: Scheduled runs on production/staging (Catch drift).
- For "regressions," we need a comparison point.
-
Step 3: The "Regression Detector" (State Management)
- We need to store the current state of contrast issues.
- When the patrol runs:
- If issue exists in
current but not previous -> New Regression.
- If issue exists in both -> Known Debt (low priority for this specific patrol).
- If issue fixed in
current -> Fixed.
- Storage: JSON artifact in the repo, or a lightweight DB/JSON in cloud storage (S3).
-
Step 4: The "Pipe" (Workflow Integration)
- Automated Ticket Creation.
- Tool: Jira, Linear, GitHub Issues.
- Logic:
- Group issues by component (Design System focus).
- Create a ticket if one doesn't exist for that specific regression.
- Tag it with "Design System," "A11y," "Sprint Backlog."
- Reporting: A dashboard or a Slack notification.
Drafting the Architecture:
- Input: Pull Request / Scheduled Trigger.
- Process:
- Build Storybook (Design System source of truth).
- Run
axe-core via Playwright/Cypress on all stories.
- Filter results for
color-contrast.
- Load
baseline.json.
- Diff results.
- Output:
- If PR: Fail the build if new contrast violations occur (The "Gate").
- If Scheduled: Generate tickets for existing violations.
Refining the Output Structure:
- Architecture Overview: High-level diagram explanation.
- The Stack: Specific tool recommendations (Axe, Storybook, GitHub Actions).
- Implementation Guide (The "Patrol" Script): Code snippets for the diff logic.
- The "Gate" (CI/CD): Preventing new bad code.
- The "Pipe" (Sprint Integration): Automated ticket generation logic.
Self-Correction/Refinement:
- Initial thought: Just run Lighthouse.
- Correction: Lighthouse is good for pages, but for a Design System, Storybook is the better target. We need to test components in isolation.
- Constraint: "Low-contrast." I shouldn't just flag any a11y issue. I must filter specifically for contrast violations (
color-contrast in axe-core).
- Constraint: "Regressions." This implies diffing. I need to emphasize the Baseline concept.
Final Polish:
Make the distinction between blocking a PR (high friction but effective) vs. logging a ticket (lower friction but requires discipline). I will suggest a hybrid model: Block on new regressions, log backlog tickets for existing debt.
Let's write the response.
This engineering challenge requires bridging the gap between Automated QA (testing) and Product Management (sprint planning).
A standard accessibility check just lists errors. A Low-Contrast Patrol designed for regression focuses on state management (comparing current vs. past states) and signal-to-noise ratio (only bothering humans when things get worse).
Here is the architectural blueprint for the Contrast Regression Patrol (CRP).
🏗️ System Architecture
The system consists of three distinct layers:
- The Sensor Grid: Storybook + Axe-core (Detection)
- The Brain: A Node.js script that diffs results against a "Golden Baseline" (Regression Logic)
- The Conveyor Belt: GitHub Actions + Issue Labeling (Sprint Injection)
Phase 1: The Sensor Grid (Detection)
We don't run this on every single commit (too slow/noisy). We run this on a schedule (e.g., nightly) or on merges to main.
Tooling: Playwright (for rendering) + Axe-Core (for logic) + Storybook (for isolation).
The Configuration (contrast-patrol.config.js):
We want to target specific WCAG levels and ignore false positives (like disabled states or third-party iframes).
// contrast-patrol.config.js
module.exports = {
targetStorybookUrl: 'http://localhost:6006',
wcagLevel: 'AA', // Target 4.5:1 for text
// Rules to specifically ignore if necessary
rules: [
{ id: 'color-contrast', enabled: true }
],
// Elements to exclude from checks (e.g., disabled buttons, placeholders)
excludeSelectors: [
'.disabled',
'[aria-disabled="true"]',
'.placeholder-text'
]
};
Phase 2: The Brain (Regression Logic)
This is the core engineering differentiator. Most scanners just output a list of errors. Your system needs to flag regressions.
This requires storing a Baseline Artifact (a JSON file of known issues) in your repository or cloud storage.
The Algorithm:
- Run Scan: Crawl the Design System stories.
- Load Baseline: Fetch
known-issues.json.
- Diff:
- New Issue: Exists in Scan, not in Baseline → TRIGGER ALERT.
- Fixed Issue: Exists in Baseline, not in Scan → UPDATE BASELINE (Positive Reinforcement).
- Known Issue: Exists in both → SILENCE (Do not clutter the sprint).
The Node.js Implementation (patrol.js):
const { AxePuppeteer } = require('@axe-core/puppeteer');
const puppeteer = require('puppeteer');
const fs = require('fs');
const BASELINE_FILE = './contrast-baseline.json';
async function runPatrol() {
const browser = await puppeteer.launch();
const page = await browser.newPage();
// 1. Navigate to your Storybook iframe URL
// Ideally, iterate through a list of component URLs
await page.goto('http://localhost:6006/iframe.html?id=components-button--primary&viewMode=story');
// 2. Run Axe specifically for color contrast
const results = await new AxePuppeteer(page)
.withRules(['color-contrast'])
.analyze();
await browser.close();
// 3. Load Baseline
let baseline = [];
if (fs.existsSync(BASELINE_FILE)) {
baseline = JSON.parse(fs.readFileSync(BASELINE_FILE));
}
// 4. Calculate Regression (The "Diff")
const currentViolations = results.violations.flatMap(v =>
v.nodes.map(n => ({
fingerprint: n.html, // Ideally hash this to avoid exact string matching issues
contrastRatio: n.any[0].data.contrastRatio,
component: v.id
}))
);
// Filter for NEW regressions
const regressions = currentViolations.filter(current =>
!baseline.some(known => known.fingerprint === current.fingerprint)
);
// 5. Output Result
if (regressions.length > 0) {
console.error(`🚨 CONTRAST PATROL: ${regressions.length} new regression(s) detected!`);
// Create a JSON artifact for the CI pipeline to read
fs.writeFileSync('./regression-report.json', JSON.stringify(regressions, null, 2));
process.exit(1); // Fail the build
} else {
console.log('✅ PATROL: No new contrast regressions.');
// Optional: Update baseline if fixes were found
fs.writeFileSync(BASELINE_FILE, JSON.stringify(currentViolations, null, 2));
process.exit(0);
}
}
runPatrol();
Phase 3: The Pipe (Sprint Injection)
Now that the script has failed and generated a regression-report.json, we need to pipe that into your project management tool (Jira/Linear/GitHub).
We use a GitHub Action to automate this.
Workflow (.github/workflows/contrast-patrol.yml):
name: Contrast Patrol
on:
schedule:
- cron: "0 2 * * *" # Run nightly at 2 AM
workflow_dispatch: # Allow manual trigger
jobs:
patrol:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Dependencies
run: npm ci
- name: Build Storybook
run: npm run build-storybook
- name: Start Storybook & Run Patrol
run: |
npx http-server storybook-static -p 6006 &
npx wait-on http://localhost:6006
node patrol.js # The script from Phase 2
- name: Create Ticket on Failure
if: failure()
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const report = JSON.parse(fs.readFileSync('./regression-report.json', 'utf8'));
// Create a GitHub Issue (or call Jira API)
const issueTitle = `🚨 Contrast Regression: ${report.length} violations found`;
const issueBody = `
## Contrast Regression Detected
**Detected On:** ${new Date().toDateString()}
**Details:**
${report.map(r => `
- **Component:** ${r.component}
- **Ratio:** ${r.contrastRatio} (Required: 4.5)
`).join('')}
`;
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: issueTitle,
body: issueBody,
labels: ['design-system', 'bug', 'accessibility']
});
How to operationalize this
-
The "Gatekeeper" Mode:
Add a step in your PR pipeline that runs the patrol script. If regressions.length > 0, the PR is blocked from merging. This forces the engineer to fix the contrast immediately.
-
The "Janitor" Mode (Sprint Injection):
If you cannot block PRs, use the scheduled run (Nightly). When the patrol runs at 2 AM and finds a regression, it automatically creates a ticket labeled design-system and assigns it to the current sprint backlog.
-
Visual Regression Complement:
Contrast tools check math (hex codes). They sometimes miss context. Pair this with a visual regression tool (like Percy or Chromatic) configured to catch "visual noise" that contrast checkers might technically pass but look terrible to the human eye.