Repository navigation
feat: expose unrounded diffPercentageExact in server JSON - #187
iloveitaly wants to merge 1 commit into
Conversation
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>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
|
Here's an example implementation supporting this feature, to give you a better idea of the use case. |
Obviously, this was built with AI, but I human-reviewed the code on my end.
Summary
odiff --serverroundsdiffPercentageto two decimals. A1280x720image with 71 differing pixels is71 / (1280 * 720) * 100 = 0.00770399...%, but the server returns0.01. A caller that treats a diff below0.01%as a match then fails inside the allowed budget.diffCountis exact, andsrc/diff.zigalready computes the fullf64(100.0 * diff_count / (max_width * max_height)).writePixelDiffandwritePixelDiffWithLineswere throwing that precision away with{d:.2}. The OCaml printer usedFloat.to_stringfor--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
diffPercentagefield rounded to two decimals so current clients do not change, and emits the fullf64asdiffPercentageExacton every pixel-diff server response, including the diff-lines and diff-cols variant. The TypeScriptODiffResulttype includes the new field.--parsable-stdoutis 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 breakcount;percentage. The human CLI line stays at two decimals.Test plan
diffPercentagestays rounded to two decimals anddiffPercentageExactequals100 * diffCount / (width * height)diffPercentageof0.02and a largerdiffPercentageExact, both with and withoutdiffLines/diffColsSummary by CodeRabbit