Skip to content

feat: expose unrounded diffPercentageExact in server JSON - #187

Open
iloveitaly wants to merge 1 commit into
dmtrKovalenko:mainfrom
iloveitaly:cursor/diff-percentage-exact-bf11
Open

iloveitaly wants to merge 1 commit into
dmtrKovalenko:mainfrom
iloveitaly:cursor/diff-percentage-exact-bf11

Conversation

@iloveitaly

@iloveitaly iloveitaly commented Oct 15, 2026 •

Copy link
Copy Markdown

Obviously, this was built with AI, but I human-reviewed the code on my end.

Summary

odiff --server rounds diffPercentage to two decimals. A 1280x720 image with 71 differing pixels is 71 / (1280 * 720) * 100 = 0.00770399...%, but the server returns 0.01. A caller that treats a diff below 0.01% as a match then fails inside the allowed budget.

diffCount is exact, and src/diff.zig already computes the full f64 (100.0 * diff_count / (max_width * max_height)). writePixelDiff and writePixelDiffWithLines were throwing that precision away with {d:.2}. The OCaml printer used Float.to_string for --parsable-stdout. The Zig rewrite dropped the field, and the follow-up that restored it copied the two-decimal human format. Consumers now re-open the image and recompute the ratio. That workaround is in iloveitaly/pytest-playwright-visual-snapshot#245.

This keeps the existing diffPercentage field rounded to two decimals so current clients do not change, and emits the full f64 as diffPercentageExact on every pixel-diff server response, including the diff-lines and diff-cols variant. The TypeScript ODiffResult type includes the new field.

--parsable-stdout is unchanged. That format is positional (count;percentage[;lines][;cols]), and the Node parser switches on the number of ;-separated fields, so an extra field would break count;percentage. The human CLI line stays at two decimals.

Test plan

  • Server tests check that diffPercentage stays rounded to two decimals and diffPercentageExact equals 100 * diffCount / (width * height)
  • The 510×234 orange fixtures (25 differing pixels at threshold 0.5) report diffPercentage of 0.02 and a larger diffPercentageExact, both with and without diffLines / diffCols

Summary by CodeRabbit

  • New Features
    • Pixel-diff results now include an exact, unrounded difference percentage alongside the existing percentage rounded to two decimal places.
  • Documentation
    • Clarified how both percentage values are calculated.

odiff --server rounded diffPercentage to two decimals, so a diff under
0.01% was reported as 0.01 and failed callers inside their allowed
budget. The exact f64 is already computed; emit it beside the rounded
field on every pixel-diff response.

Co-authored-by: Michael Bianco <mike@mikebian.co>
@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7a88664f-f1e0-4b3d-a1a7-d808707fe0ae
📥 Commits

Reviewing files that changed from the base of the PR and between 6dd1e96 and 137e850.

📒 Files selected for processing: 4
  • README.md
  • npm_packages/odiff-bin/odiff.d.ts
  • src/server.zig
  • src/test_server.zig

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

📝 Walkthrough

Pixel-diff server responses now include an unrounded diffPercentageExact alongside the existing two-decimal diffPercentage. The README and TypeScript declaration document both values. Server tests check the percentages in responses with and without diff-line and diff-column capture.

Changes: Diff percentage response

Layer / File(s) Summary
Document and return both percentages
README.md, npm_packages/odiff-bin/odiff.d.ts, src/server.zig
The pixel-diff contract documents the rounded and exact percentages. Both response formats include diffPercentageExact.
Verify percentage values
src/test_server.zig
Tests check exact and rounded percentages, including responses with diff-line and diff-column capture. They also verify the diff count and returned line and column arrays.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Suggested reviewers: dmtrkovalenko

Merge Risk: ⚪ Minimal · up to 137e8

No actionable merge-blocking risk is identified; this change is ready for normal checks.

Pre-merge checks: Passed 5
Passed Passed checks: 5 passed
Check name Status Explanation
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: exposing the unrounded diffPercentageExact value in server JSON responses.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@iloveitaly

iloveitaly commented Oct 15, 2026 •

Copy link
Copy Markdown
Author

Here's an example implementation supporting this feature, to give you a better idea of the use case.

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.

2 participants