Skip to content

Add page-scope style comparison (matcher + artifact) - #32

Merged
hungify merged 1 commit into
mainfrom
feature/page-scope-style-comparison
Aug 23, 2026
Merged

hungify merged 1 commit into
mainfrom
feature/page-scope-style-comparison

Conversation

@hungify

@hungify hungify commented Aug 22, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Page-scope toMatchFigma calls with styleChecks now run one compareStyles per declared check-point, each against its own baked expectStyle (no live per-checkpoint Figma re-fetch at verify time).
  • Added expectStyleToSnapshot() (packages/verify/src/figma-node-style.ts) to bridge the contract's baked ExpectStyle (0-255 RGB + separate alpha, fontSizePx) into the StyleSnapshot shape compareStyles consumes.
  • Each resulting issue is tagged with its originating check-point's selector (new optional TopIssue.selector / topIssueSchema.selector field) so multiple check-points stay distinguishable once merged into topIssues.
  • Style issues remain non-blocking: merged into topIssues the same way region-scope's existing bake-in is, and done-gate is unaffected since it only blocks on kind === "residual".
  • A check-point whose expectStyle never baked at authoring time (failed Figma fetch) is skipped rather than compared against nothing.
  • Page-scope contracts with an empty/absent styleChecks behave exactly as before (pixel-only); region-scope's existing single-selector style comparison is untouched.

Closes #27

Test plan

  • Unit tests for expectStyleToSnapshot (empty input, each field, color+colorProperty pairing, colorProperty omitted, combined fields) — packages/verify/tests/figma-node-style.test.ts
  • Matcher tests — packages/playwright/tests/to-match-figma.test.ts:
    • multiple page-scope check-points, mixed pass/fail, each issue tagged with its own selector
    • check-point missing expectStyle produces no issue
    • empty styleChecks array produces no style issues
    • existing "skips style comparison entirely in page scope (no selector)" test still passes unchanged
  • Full repo suite green: verify 186/186, playwright 51/51, cli 73/73, dashboard 47/47, dashboard-server 18/18
  • pnpm -r typecheck and oxlint clean

Summary by CodeRabbit

  • New Features

    • Added page-scope style checkpoints for validating expected colors, typography, and other supported style properties.
    • Style issues now identify the checkpoint selector that produced them.
    • Added support for converting expected style definitions into comparable snapshots.
  • Documentation

    • Documented page-scope style checkpoint usage and non-blocking issue reporting.
  • Tests

    • Added coverage for multiple checkpoints, missing expectations, empty configurations, and style conversion.

@coderabbitai

coderabbitai Bot commented Aug 22, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 909484d2-8fba-4896-801b-55640e5f4512

📥 Commits

Reviewing files that changed from the base of the PR and between 0100a13 and 2c03fce.

📒 Files selected for processing (1)
  • packages/playwright/src/matchers/to-match-figma.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The change adds page-scope styleChecks to toMatchFigma. Each checkpoint compares against its baked expected style. Returned style issues include the checkpoint selector and remain non-blocking.

Changes

Page-scope style comparison

Layer / File(s) Summary
Style conversion and issue contracts
packages/verify/src/figma-node-style.ts, packages/verify/src/index.ts, packages/verify/src/types.ts, packages/contracts/src/score.ts
Expected styles convert to StyleSnapshot values. TopIssue and topIssueSchema now support an optional checkpoint selector.
Matcher integration and validation
packages/playwright/src/matchers/to-match-figma.ts, packages/playwright/tests/to-match-figma.test.ts, packages/playwright/README.md
The matcher supports page-scope styleChecks, skips checkpoints without expectStyle, tags issues with selectors, and preserves non-blocking behavior. Tests and documentation cover these cases.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 2c03f

The change adds page-scope style diagnostics without altering pixel comparison or merge-gate behavior; no actionable merge-blocking risk remains after normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant Test as Playwright test
  participant Matcher as toMatchFigma
  participant Converter as expectStyleToSnapshot
  participant Comparator as compareStyles
  participant TopIssues as topIssues
  Test->>Matcher: provide page-scope styleChecks
  Matcher->>Converter: convert checkpoint expectStyle
  Matcher->>Comparator: compare selected element style
  Comparator->>TopIssues: return selector-tagged style issues
  Matcher->>Test: preserve passing pixel comparison
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: adding page-scope style comparison in the matcher and artifact.
Linked Issues check ✅ Passed The changes implement page-scope checkpoint comparisons, selector-tagged artifact issues, non-blocking behavior, pixel-only fallback, and supporting tests.
Out of Scope Changes check ✅ Passed All code, type, documentation, and test changes directly support page-scope style comparison and its artifact integration.
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/page-scope-style-comparison

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Aug 22, 2026 •

Copy link
Copy Markdown

Greptile Summary

The PR adds page-scope style checkpoint comparisons using baked expectations and tags resulting diagnostics with their originating selectors. It also addresses the previously reported region-routing and matcher-budget issues.

  • Converts baked ExpectStyle values into style-comparison snapshots.
  • Runs bounded, page-scope checkpoint comparisons and merges their non-blocking issues into score artifacts.
  • Extends score schemas and issue types with optional checkpoint selectors.
  • Adds matcher and conversion coverage for checkpoint behavior and prior review fixes.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
packages/playwright/src/matchers/to-match-figma.ts Adds bounded page-checkpoint style comparison and correctly separates page and region behavior without leaving a blocking prior finding.
packages/verify/src/figma-node-style.ts Adds a focused conversion from baked contract styles to the existing comparison snapshot representation.
packages/contracts/src/score.ts Extends persisted top issues with an optional selector while preserving compatibility for existing issues.
packages/verify/src/types.ts Mirrors the optional checkpoint selector in the runtime TopIssue contract.
packages/playwright/tests/to-match-figma.test.ts Covers page checkpoints, missing expectations, empty checks, and the corrected region fallback behavior.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[toMatchFigma] --> B[Resolve baseline and capture page]
  B --> C[Run pixel comparison]
  C --> D{Region selector present?}
  D -->|Yes| E[Compare region style when Figma style exists]
  D -->|No| F[Compare baked page checkpoints]
  E --> G[Apply remaining timeout budget]
  F --> G
  G --> H[Merge non-blocking style issues]
  H --> I[Attach images and score artifact]
Loading

Reviews (5): Last reviewed commit: "Enhance style comparison with page-scope..." | Re-trigger Greptile

Comment thread packages/playwright/src/matchers/to-match-figma.ts Outdated
Comment thread packages/playwright/src/matchers/to-match-figma.ts Outdated
hungify added a commit that referenced this pull request Aug 22, 2026
… scope

Greptile review on #32 flagged two real bugs in the page-scope style-check
wiring:

- captureCheckPointStyleIssues (and region's own captureStyleIssues) ran
  outside the matcher's withTimeout boundary, so a stale/missing selector's
  page.$eval could hang past the matcher's own configured timeout instead
  of degrading to no style issues like every other style-capture failure.
- the styleIssues conditional fell through to the page check-point branch
  whenever a region call's figmaStyle was unavailable for any reason --
  including the retryable-cached-baseline fallback in baseline.ts, whose
  ResolvedBaseline omits figmaStyle entirely rather than an empty object.
  A region call could then pick up unrelated check-point diagnostics.

Fixes: gate the check-point branch strictly on `!options.selector`, and
wrap both style-check paths in a shared timeout that degrades to no issues
on expiry, consistent with captureStyleIssues' own best-effort semantics.

Added a regression test that reproduces the cached-baseline fallback via a
real two-call retryable-500 sequence and asserts no check-point diagnostic
leaks into the region result.
@hungify
hungify force-pushed the feature/page-scope-style-comparison branch from 0100a13 to 793ff37 Compare August 22, 2026 17:54
Comment thread packages/playwright/src/matchers/to-match-figma.ts
…gging

This commit introduces the ability to perform style comparisons at page-scope using defined check-points, allowing for multiple style checks to be executed per page. Each style issue is now tagged with its corresponding selector, improving the clarity of style mismatch reporting. The `expectStyleToSnapshot` function has been added to facilitate the conversion of expected styles into a format suitable for comparison. Additionally, tests have been implemented to validate the new functionality, ensuring that style issues are accurately captured and reported based on the defined check-points.
@hungify
hungify force-pushed the feature/page-scope-style-comparison branch from 2c03fce to c878ca1 Compare August 23, 2026 00:51
@hungify
hungify merged commit 86ce907 into main Aug 23, 2026
4 checks passed
@hungify
hungify deleted the feature/page-scope-style-comparison branch August 23, 2026 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Page-scope style comparison (matcher + artifact)

1 participant