Skip to content

Commit e324355

Browse files
authored
Add visual regression reference prompt (.github/aw/visual-regression.md) (#18272)
1 parent 4570f89 commit e324355

2 files changed

Lines changed: 59 additions & 1 deletion

File tree

.github/aw/create-agentic-workflow.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ These resources contain workflow patterns, best practices, safe outputs, and per
208208
- `Package.swift`, `*.podspec` → add `swift`
209209
- `composer.json` → add `php`
210210
- `pubspec.yaml` → add `dart`
211-
- 💡 If you detect the task requires **browser automation**, suggest the **`playwright`** tool.
211+
- 💡 If you detect the task requires **browser automation**, suggest the **`playwright`** tool. For **visual regression testing** (comparing screenshots across PRs), consult `.github/aw/visual-regression.md` for the reference pattern using `playwright` + `cache-memory`.
212212
- 🔐 If building an **issue triage** workflow that should respond to issues filed by non-team members (users without write permission), suggest setting **`roles: all`** to allow any authenticated user to trigger the workflow. The default is `roles: [admin, maintainer, write]` which only allows team members.
213213

214214
**Scheduling Best Practices:**

.github/aw/visual-regression.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
name: visual-regression
3+
description: Reference prompt for visual regression testing using playwright + cache-memory for baseline screenshot storage across pull requests
4+
---
5+
6+
# Visual Regression Testing
7+
8+
Use `playwright` for screenshots and `cache-memory` to persist baselines between PR runs.
9+
10+
## Example Workflow
11+
12+
```markdown
13+
---
14+
description: Capture screenshots on every PR and compare against cached baselines to detect visual regressions
15+
on:
16+
pull_request:
17+
types: [opened, synchronize, reopened]
18+
permissions:
19+
contents: read
20+
pull-requests: read
21+
engine: copilot
22+
tools:
23+
playwright:
24+
allowed_domains:
25+
- localhost
26+
- 127.0.0.1
27+
cache-memory:
28+
key: visual-regression-baselines-${{ github.event.pull_request.base.ref }}
29+
retention-days: 30
30+
allowed-extensions: [".png", ".json"]
31+
bash:
32+
- "mkdir *"
33+
- "cp *"
34+
- "diff *"
35+
- "date *"
36+
safe-outputs:
37+
add-comment:
38+
max: 1
39+
timeout-minutes: 30
40+
---
41+
42+
Build and serve the app locally, then use Playwright to capture full-page screenshots of key pages into `/tmp/visual-regression/current/`.
43+
44+
Use filesystem-safe timestamps (no colons — colons break artifact uploads):
45+
`date -u "+%Y-%m-%d-%H-%M-%S"`
46+
47+
If `/tmp/gh-aw/cache-memory/baselines/manifest.json` does not exist, copy screenshots there as new baselines and post: "Baselines initialized — N pages captured."
48+
49+
Otherwise compare each screenshot to its baseline. Post a comment summarizing: pages unchanged / pages with diffs. If nothing changed, use the `noop` safe-output.
50+
```
51+
52+
## Key Design Decisions
53+
54+
- **`cache-memory` key per base branch** — scopes baselines to `main`, `develop`, etc. independently
55+
- **`allowed_domains: [localhost, 127.0.0.1]`** — prevents SSRF; app must be served locally
56+
- **`retention-days: 30`** — keeps baselines beyond the default 7-day cache expiry
57+
- **Filesystem-safe timestamps**`YYYY-MM-DD-HH-MM-SS` format; colons are invalid in artifact filenames
58+
- **Minimal permissions** — all PR writes go through `safe-outputs`, not GitHub tools

0 commit comments

Comments
 (0)