Skip to content

Polish the sloped box after the #91 review - #93

Merged
kigster merged 6 commits into
mainfrom
kig/polish-sloped-box-review
Dec 2, 2026
Merged

kigster merged 6 commits into
mainfrom
kig/polish-sloped-box-review

Conversation

@kigster

@kigster kigster commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Summary

Follow-up to #91: the six 🙁 items its review left open, one commit each.

 tokens.css
-  --error: #ff2020    # white on it 3.8:1, fails WCAG AA
+  --error: #d00000    # 5.7:1

 Reset popup (.reset)
+  focusout → close, when focus lands outside (Tab away)
-  role="dialog"
+  role="alertdialog", Reset has aria-controls="reset-confirm"

 BoxRequest#valid?                 form hint (problem())
   dimensions, optional              sides, thickness
-  notch, notch count, choices,      slope
-  slope                             notch, notch count
+  slope, notch, notch count,        (same order now)
+  choices

 notch count
-  longest = sides.max
+  longest = max(sides.max, tilted panel)      # Ruby and JS

 slope messages
-  Float#round(2)       2.675 → 2.68
+  value.to_r.round(2)  2.675 → 2.67, as toFixed(2)
  • The Cypress test "upright sends no slope" now checks the real stream request. It used to hard-code slope=60.

Evidence

  • Before: a 10×10×10 box in 0.025 material sloped at 45° from the floor passed with 191 notches on its tilted panel (limit 150). For slope 20 with notch 2, the server said "Notch length…" while the hint said "At 20° the slope runs…". Slope 2.675 showed as 2.68° from the server and 2.67° in the hint.
    After:
    • RSpec 148/0, with new examples for notch count, check order and tie rounding. The check-order spec fails when the reorder is reverted.
    • rubocop: 67 files, no offenses
    • Cypress 63/63: generator.cy.js 41, lib.cy.js 22. New tests: popup closes when focus leaves and is an alertdialog; 191 notches on the sloped panel; upright stream request has no box[slope]; JS ties round like Ruby.

Merge Danger

Door: two-way

Revert to go back. No data, schema or URL changes.

Blast Radius: generator

  • The error pill gets a darker red.
  • Some sloped boxes with tiny notches that used to pass are now refused before drawing.
  • For a box with both a slope problem and a notch problem, the server now reports the slope first.

White on #ff2020 was 3.8:1; #d00000 is 5.7:1, past the 4.5:1 that 14px bold text needs.
Tabbing out of Reset and its popup now closes it; a click that moves no focus (Safari) still goes through dismiss(). The popup is an alertdialog that Reset controls.
The hint checks slope before notch; the server checked notch first, so the two could name different problems for the same box.
The tilted panel can be up to about 1.41 times the longest side, so a sloped box could pass the notch limit and still draw past it. Both the server and the form now count the longer of the two.
The comment claimed it, but the request it checked hard-coded slope=60. The test now switches back to upright with the slope fields still filled in and checks the stream request leaves them out.
Float#round(2) gave 2.68 for 2.675 where the form's toFixed(2) gives 2.67, since 2.675 is 2.67499... in binary. Rounding the exact value with to_r matches toFixed.
@kigster kigster self-assigned this Dec 2, 2026
@kigster
kigster requested a balanced review from Copilot December 2, 2026 21:58
@kigster

kigster commented Dec 2, 2026

Copy link
Copy Markdown
Owner Author

Grok Review Comment

Security review of #93. I'm only checking whether anything here can be exploited.

👍 Counting the tilted panel in the notch limit closes a gap on the live site. Before this change, a sloped box with tiny notches could get past the 150-notch cap that keeps render work small. The PR's own example asks for 191. The server now applies the same cap to the sloped panel, so that request is refused before any drawing starts.

👍 Moving check_slope earlier is safe. It still runs only after check_dimensions and check_optional have passed, so height, depth and the slope are valid numbers before longest_edge does any trig. two_places only changes how a number in an error message is rounded.

👍 The Reset popup changes only add ARIA attributes and a focus handler. No user input reaches the markup.

No secrets in the diff (gitleaks is clean). CI is green.

Security Whitehat

@kigster kigster added review-opsec-ok Security Whitehat found no exploitable holes or leaked secrets low-risk-ai-mergeable Low blast radius; safe for an AI to merge labels Dec 2, 2026
@kigster

kigster commented Dec 2, 2026

Copy link
Copy Markdown
Owner Author

Grok Review Comment

Risk assessment for d843a50: low risk, labeled low-risk-ai-mergeable.

👍 This is a small follow-up to #91, which is already on main, so the larger generator change has already shipped. The diff only touches validation order, the notch count for sloped boxes, message rounding, one color token and the Reset popup's accessibility attributes. Nothing touches data, schema, URLs, routes, controller params or dependencies.

👍 The one behavior change on the server is stricter. Sloped boxes whose tilted panel would need more than 150 notches are now refused with a form error before drawing, where they used to pass. The refused boxes would have hit the same cap the upright boxes already obey, so no reasonable box that worked yesterday stops working. longest_edge runs only after check_slope passes, so the trigonometry never sees a bad angle.

👍 Moving check_slope ahead of the notch checks changes which message wins when a box has both problems. It doesn't change whether a box is accepted.

👍 The Reset popup change adds a focusout handler that only closes the popup, and the error red gets darker. A bug in either is cosmetic.

👍 test, lint and e2e are all green, including 63 Cypress tests. The skipped Mermaid check is a third-party app with nothing to do with this change. Reverting the merge undoes everything.

Risk Assessor · PR Reviewer

@kigster kigster left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grok Review Comment

Staff review of d843a50 on current main (66c26cd, which already contains #91). This PR is the follow-up to review 6148001209. I cloned the repository anonymously. I ran sloped_profile.js in Node and a port of BoxRequest#tilted_length and laser-cutter 3.0's Sloped::Profile in the same script. Ruby 4 is not on this machine, so I did not run the Rails suite.

The #91 open item

👍 The form now refuses a slope that leaves no tilted panel, with a clean message, on both sides. The check itself landed in #91 before it merged. This PR keeps it, and two_places makes the wording match the hint. BoxRequest#check_slope returns early when tilted_length is not above 1e-6, the same cutoff refuse_no_tilted_panel! uses. slopeProblem asks slopedProfile for the same length and uses the same cutoff. A front height of 0 uses front.positive? in Ruby and Hf > 0 in JS, so there is no front cut, and 0 stays a valid front.

I compared the two implementations with the gem's formula. The spec box (3 in high, 4 in deep, 0.245 in material, 45°, front 2.75) is refused everywhere, with a tilted length of -0.1364466094067262, and a front of 2 is accepted (0.9242135623730953). The #91 clamp case (front 2.75 on a 3 in box of 1/4 in at 45°) is refused too. With a front of 0 and a 60° slope, all three accept the box. Around the cutoff, a front of 2.653516 is accepted (tilted length 2.37e-6) and 2.653517 is refused (9.58e-7), on JS, Ruby, and the gem together. Specs pin the 2.75 / 2 pair, and one example asks the gem for InvalidOption. lib.cy.js uses the same box.

e2e width test and CI

👍 The test puts the units, the lid and the front first, wide enough for every option passed in the e2e job on this SHA (587ms). Cypress was 63 of 63: generator.cy.js 41, lib.cy.js 22. The test itself was already fixed on main (it now measures in the app document, with the app font) and this PR does not change it.

test passed (148 examples, 0 failures) and lint passed. Mermaid was skipped. Copilot's review was still running when I read the checks.

get_commit_combined_status on d843a50 is pending with 0 statuses. CircleCI did not post a status for this SHA. The public CircleCI API also answers that the project is not found, so I could not read a CircleCI job. I took SimpleCov from the GitHub Actions test job instead: line coverage 442 / 563 (78.50%), reported as 78.51%, which is above the 50 percent bar in spec_helper.rb.

The rest of the PR

👍 Checking the slope before the notch matches the form, and the new spec fails if that order is put back. Counting notches on the sloped panel is right: a 10 in cube in 0.025 in material, sloped at 45° from a front of 0, has a panel of about 14.14 in and 191 notches, which both the model spec and Cypress now name. two_places matches toFixed(2): Ruby's 2.675.round(2) is 2.68, and 2.675.to_r.round(2) is 2.67, as the form shows. The upright stream test now reads the real request and checks that box[slope] and box[front_height] are absent. Closing the Reset popup when focus leaves it, and calling it an alertdialog, is a small, tested change.

The new code stays in BoxRequest and the generator controller. The controller does not grow a new job. The helpers (two_places, tilted_length, longest_edge) are small and have one job each.

Verdict

review-approved. The #91 item about a missing tilted-panel check is closed, the width test is green in CI, and the new tests lock the boundaries this PR cares about.

Alan Turing

Comment thread app/models/box_request.rb
return if tilted_length(angle, run, front) > 1e-6

errors << "At #{trim(slope.round(2))}° from a front of #{trim(front.round(2))} #{units}, " \
errors << "At #{trim(two_places(slope))}° from a front of #{trim(two_places(front))} #{units}, " \

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 This is the same 1e-6 cutoff as refuse_no_tilted_panel!. I compared tilted_length with slopedProfile and with laser-cutter 3.0's Profile. They agree, including a front of 0 (front.positive? drops the front cut) and the boundary: 2.653516 is accepted, 2.653517 is refused, all three ways.

Alan Turing

Comment thread app/models/box_request.rb
end

# Rounds the exact value, as JavaScript's toFixed(2) does: 2.675 is
# 2.67499... in binary, so 2.67 here as in the form's hint, not Float#round's 2.68.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I checked this against JS: 2.675.round(2) is 2.68 in Ruby, 2.675.to_r.round(2) is 2.67, and Number((2.675).toFixed(2)) is 2.67.

Alan Turing

expect(errors_for('slope' => '20.12345').first).to start_with 'At 20.12° the slope runs'
end

it 'rounds a tie the way the form does' do

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 This pins the tie that Float#round(2) would get wrong. The form and the server now both say 2.67.

Alan Turing

@kigster kigster added the review-approved Staff review approved label Dec 2, 2026 — with Cursor

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Plain-lid boxes are incorrectly rejected by notch-count validation, and the shared color change reduces Reset text contrast below WCAG AA.

2 open issues
What changed in this PR

Follow-up to #91 that refines the sloped-box generator’s validation, Reset accessibility, and regression coverage.

Changes:

  • Aligns server validation order and rounding with browser hints, and counts tilted-panel notches.
  • Improves Reset popup semantics and dismissal, and darkens error pills.
  • Adds regression tests, including inspection of the actual upright-box stream request.
File Description
spec/​models/​box_request_sloped_spec.rb Tests rounding, validation order, and sloped notch limits.
cypress/​e2e/​lib.cy.js Tests slope-message tie rounding.
cypress/​e2e/​generator.cy.js Covers popup behavior, notch limits, colors, and stream parameters.
app/​views/​home/​_generator.html.haml Adds popup accessibility attributes and focusout handling.
app/​models/​box_request.rb Updates validation order, rounding, and longest-edge calculation.
app/​javascript/​controllers/​generator_controller.js Counts tilted-panel notches and dismisses Reset on focus departure.
app/​assets/​stylesheets/​tokens.css Darkens the shared error color.

Review effort: Balanced

--amber: #ffb53d; /* the accent: headings, edges, whatever is being edited */
--alarm: #ff7a6b;
--error: #ff2020; /* the error pill */
--error: #d00000; /* the error pill: white on it is 5.7:1, past WCAG AA */
Comment thread app/models/box_request.rb
# The longest notched edge: a sloped panel can be longer than any side.
# Called once check_slope has passed, so the slope makes a box.
def longest_edge
return sides.max unless sloped?
@kigster
kigster merged commit 8ee387d into main Dec 2, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

low-risk-ai-mergeable Low blast radius; safe for an AI to merge review-approved Staff review approved review-opsec-ok Security Whitehat found no exploitable holes or leaked secrets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants