Repository navigation
Sloped box, Reset confirmation, panel layout; laser-cutter 3.0 and Puma 7 - #91
Conversation
slopedProfile mirrors laser-cutter's Sloped::Profile (kigster/laser-cutter#25): the side outline, top strip depth and panel lengths from depth, height, front height and slope. isoSlopedBox draws it in the same isometric view as isoBox: side wall, front strip, tilted panel, top strip, finger joints, dimensions and the slope angle; a plain lid lifts the tilted panel off. Library modules import nothing, so the caller passes in the profile and tabCount. Not wired into the form yet: that needs the gem release with --slope.
kigster
left a comment
There was a problem hiding this comment.
💩 One rule disagrees with laser-cutter 3.0: neither BoxRequest#check_slope nor the JS slopeProblem refuses a slope that leaves no tilted panel (Sloped::Profile#refuse_no_tilted_panel!). The preview passes, Generate is enabled, and the server answers with the gem's raw error. You can hit it with the default box at front height 2.75 in, which the ↑ key reaches.
🙁 Ruby and JS round the angle differently in the 'deeper than the box' message, and they check the slope and the notch in a different order, so the hint and the 422 can name different problems.
🙁 The notch-count limit ignores the tilted panel, which can be about 1.4× the longest side.
🙁 config/puma.rb still calls on_restart, which Puma 7 deprecates. Also check that prod nginx keeps proxy_http_version 1.1 on /box/stream; the nginx config is not in this repo.
🙁 The error pill is white on #ff2020 at 14px bold, about 3.8:1, which is below WCAG AA (4.5:1).
🙁 The Reset popup stays open when focus Tabs out of it, and alertdialog would suit a yes/no confirmation better than dialog.
🙁 A Cypress comment says the step checks that an upright box sends no slope, but the step does not check that.
🙁 CI e2e is red on 'puts the units, the lid and the front first, wide enough for every option': the select is 173px and the test expects at least 182.1px. The custom-arrow fix in fa57a0b did not turn it green.
👍 Disabling the slope fields so they stay out of the payload is simple and robust. The lib.cy.js tests check the JS profile against the gem's own numbers. Dropping lids_supported? and its specs is correct now that laser-cutter ~> 3.0 is pinned.
| end | ||
|
|
||
| # The same rules laser-cutter's Sloped::Request applies, said in the form's words. | ||
| def check_slope |
There was a problem hiding this comment.
💩 The comment says check_slope applies the same rules as Sloped::Request, but it skips one: Sloped::Profile#refuse_no_tilted_panel!. When the strip cuts (t·tan(slope) at the front, t/tan(slope) at the top) take up more than the whole slope, laser-cutter raises InvalidOption.
To reproduce, take the default 5×3×4 in box with t = 0.245, slope 45° and front height 2.75. The ↑ key gets there, because clamp allows up to height − 0.25. valid? returns true, then rendering fails, and the user sees the raw laser-cutter could not draw this box: a 45.0° slope from a front height of 2.75 leaves no tilted panel in material 0.245 thick…. I checked this against Laser::Cutter::Sloped::Profile.new from 3.0.0.
Add the rule here: hypot(run, H − Hf) − (Hf > 0 ? t·tan : 0) − (Dt > 0 ? t/tan : 0) > 1e-6, with Dt floored at 1e-6 the way the gem floors it. Give it a message in the form's words, and add a spec.
| if (frontHeight >= height) return "Front height has to be lower than the height of the box." | ||
| if (lid === "back") return "A sloped box cannot have the lid with tabs along the back." | ||
| const run = (height - frontHeight) / Math.tan((slope * Math.PI) / 180) | ||
| if (run <= depth + PRECISION) return "" |
There was a problem hiding this comment.
💩 This is the browser side of the same gap. slopeProblem lets a box with no tilted panel through, and slopedProfile returns a profile with lengths.tilted < 0 where it should return null. The preview then draws a panel of negative length, Generate stays enabled, and the server refuses the box. Mirror the gem's refuse_no_tilted_panel! in both functions; slopeProblem will need thickness passed in. Use the same message as the Ruby side, and add a lib.cy.js case: height 3, depth 4, front 2.75, 45°, t 0.245.
| run = (number(:height) - front) / Math.tan(slope * Math::PI / 180) | ||
| return if run <= number(:depth) + 1e-6 | ||
|
|
||
| errors << "At #{trim(slope)}° the slope runs #{trim(run.round(2))} #{units} back, deeper than the box. " \ |
There was a problem hiding this comment.
🙁 The Ruby and JS messages can differ. Ruby prints the angle with trim(slope), up to 4 decimals; JS uses toFixed(2). So 20.125° reads 20.125° from the server and 20.13° in the hint. The order differs too: problem() checks the slope before the notch, but Ruby only gets to check_slope after check_notch and check_notch_count. With both wrong, the hint and the 422 name different problems. It's small, but the PR says the two must agree, so round the same way and check in the same order.
| check_notch if errors.empty? | ||
| check_notch_count if errors.empty? | ||
| check_choices | ||
| check_slope if errors.empty? |
There was a problem hiding this comment.
🙁 check_notch_count, and tabCount in problem(), count notches along sides.max. The tilted panel can be longer than any side: up to hypot(D, H), about 1.41× the longest side for a 45° wedge. So a sloped box can end up about 40% over MAX_NOTCHES on that panel, which is the render-time limit this check exists to enforce. When sloped?, count the slope length as an edge too.
| gem 'newrelic_rpm' | ||
| gem 'propshaft' | ||
| gem 'puma', '~> 6' | ||
| gem 'puma', '~> 7' |
There was a problem hiding this comment.
🙁 Puma 7 renamed its hooks, and config/puma.rb still calls on_restart. It still works, but it prints a deprecation warning on every boot; rename it to before_restart. The rest of 7.0 looks harmless for this config:
preload_app!is already set explicitly.- Response headers are now lowercase, and nginx matches
X-Accel-Bufferingregardless of case. persistent_timeoutgoes up to 65 s, which is still longer than nginx's 60 s upstream keepalive.
The nginx config is not in this repo, so before this ships, check that prod's /box/stream location still sets proxy_http_version 1.1. Without it, the drawn event is lost.
| --beam: #ff5a2b; /* the laser */ | ||
| --amber: #ffb53d; /* the accent: headings, edges, whatever is being edited */ | ||
| --alarm: #ff7a6b; | ||
| --error: #ff2020; /* the error pill */ |
There was a problem hiding this comment.
🙁 White on #ff2020 has a contrast of about 3.8:1. The pill text is 14px bold, which is not WCAG large text (that starts at 18.66px bold), so this fails AA's 4.5:1. Something like #d00000 (about 5.7:1) is still a loud red and passes.
| data: {generator_target: 'restart', action: 'generator#ask'}} | ||
| Reset | ||
| %span.wide to defaults | ||
| .confirm{role: 'dialog', 'aria-label': 'Reset to defaults?', hidden: true, data: {generator_target: 'confirm'}} |
There was a problem hiding this comment.
🙁 The popup closes on No, on Escape and on a click outside, but not when focus leaves it. Tab past Yes/No into Height and the popup stays open over the next cell, with aria-expanded="true" still on Reset. Add a focusout action that closes it when event.relatedTarget is outside .reset. A yes/no confirmation is also announced better as role="alertdialog", with aria-describedby pointing at the question text, and Reset could carry aria-controls for the popup.
| cy.screenshot("sloped", { capture: "viewport" }) | ||
| cy.get("dialog.cut button.x").click() | ||
|
|
||
| // An upright box sends no slope at all. |
There was a problem hiding this comment.
🙁 The comment says an upright box sends no slope at all, but the request below hard-codes box[slope]=60&box[front_height]=1.2 and checks for the -60deg filename. That tests how the server names the file. It doesn't test that the upright form leaves the slope out. To test that, check after select("upright") that #box_slope is disabled, and that the stream request the page makes has no slope (for example, cy.intercept it and check its query).
| shapeFields() { | ||
| const sloped = this.sloped | ||
| this.slopedTarget.hidden = !sloped | ||
| this.slopeTarget.disabled = this.frontHeightTarget.disabled = !sloped |
There was a problem hiding this comment.
👍 Disabling the slope fields so FormData leaves them out is a tidy approach. An upright box never sends a slope, the server's sloped? only has to check whether the fields are present, and save/restore picks up the shape with no extra code.
|
❌❌❌❌❌ Not ready: the sloped-box checks miss one of laser-cutter 3.0's rules, and CI e2e is red. Blocking:
|
Grok Review CommentSecurity review of #91. I'm only checking whether anything here can be exploited. 👍 The two new parameters, 👍 The sloped preview builds SVG markup and assigns it with 👍 The lockfile bump brings security patch releases of rack (3.2.9), nokogiri (1.19.7), loofah, rails-html-sanitizer and Rails 8.1.4.1, which is a plus. No secrets in the diff (gitleaks is clean). The red Security Whitehat |
Grok Review CommentRisk assessment for 🤔 The generator is the whole product on makeabox.io, and this PR changes it end to end. It changes what 🤔 The blocking comment above already shows the server-side checks miss one of laser-cutter 3.0's rules, the one that refuses a slope with no tilted panel. Until that's closed, some form inputs pass 👍 It's a two-way door. Nothing touches a schema, stored data or URLs, and reverting the merge restores the old generator. Unit tests and lint pass. e2e was still running when I checked, and the Mermaid check is a skipped third-party app with nothing to do with this change. 🤔 The Gemfile and Gemfile.lock changes in the description already reached Risk Assessor · PR Reviewer |
kigster
left a comment
There was a problem hiding this comment.
Grok Review Comment
Staff review of 03f4dba on main (05ebfc0), 771 insertions and 114 deletions against current main. I cloned the repository anonymously. I compared sloped_profile.js to a faithful port of laser-cutter 3.0.0's Sloped::Profile in Node, and I read AngledEdge and Transform. Ruby 4 is not on this machine, so I did not run the Rails suite. I read the CI check runs and the commit status, and I read the failed e2e log.
CI
Four check runs on 03f4dba. test passed and lint passed. The Mermaid Diagram Sync Assistant skipped. e2e failed: Cypress was 58 of 59, with lib.cy.js all 20 passing and one failure in generator.cy.js. The combined commit status reports 0 statuses. The repo asks SimpleCov for 50 percent line coverage. I have no coverage figure for this branch from CI, so I am not reporting one.
JS preview versus laser-cutter 3.0
👍 The side-view numbers match. PRECISION is 1e-6 on both sides. I compared eight cases. On every case the gem can draw, the JS angle, topDepth, slopeLength, outline, span and the three lengths agreed with Profile to 1e-12, including a front height of 0 and a slope that leaves no top strip. Kerf is not part of Profile or of the preview, which is the same choice iso_box.js already makes. Units are converted to inches only when the isometric preview is drawn, after the profile is computed in the form's units.
For a 5 deep × 3 high in box at 45° with a 1 in front and 0.125 in material, both sides gave a slope length of 2.8284271247461903, a tilted panel of 2.5784271247461903, and a span from (0.0884, 1.0884) to (1.9116, 2.9116). With a front height of 0 and a 60° slope, both dropped the front strip, set the front length to 0, and started the span at (0, 0).
AngledEdge and Transform are how the gem notches a sloped edge on the page. The preview does not emit a cut path. It does place fingers along Profile#tilted_span, which is the run those two classes would be given.
I also checked the JS trap that 0 is falsy. The preview uses Hf > 0 and Hf >= 0, and the controller reads front height with parse(...) rather than this.number(...), so a front of 0 stays 0.
🤔 One case diverges. When the front is so high that the strips eat the whole slope, Profile refuses the box (refuse_no_tilted_panel!). slopedProfile still returns a profile whose tilted length is negative, and the span's "high" end sits below its "low" end. slopeProblem and BoxRequest#check_slope are silent too. On a 3 in box of 1/4 in material at 45°, a front height of 2.75 already does this, and that is the high end of the form's own clamp (height minus one 0.25 in step). Generate would not return a 500: Laser::Cutter::Error is caught and returned as 422 with the gem's words. The preview would still draw a backwards panel. The same check belongs in check_slope and slopeProblem.
Validation
👍 BoxRequest#check_slope covers the cases I was asked to check: types, the open interval for the angle, a front height of 0 (Ruby 0 is truthy, and finite? plus !negative? keep it), a front that meets or passes the height, the back lid, a slope that needs more depth than the box has, and blank fields. Both slope fields blank is an upright box. One field filled and the other blank is a clean form error, not a 500. The stream and the download already turn valid? failures into a failed event or 422. A request spec pins the back lid. A model spec pins a front of 0 and the 20° too-deep message, which matches the JS wording (5.49 in).
Controller size, Reset, Puma, the rest
👍 BoxesController is 94 lines. This PR only adds the two sloped keys to PERMITTED. The slope rules live on BoxRequest. That meets the bar.
👍 Reset now asks first. Yes goes back to a closed, upright 5 × 4 × 3 in box of 1/4 in material and clears the slope fields. No, Escape, or a click outside keeps the box, and the popup opens with No focused so a stray Enter does not reset. The new Cypress tests for that passed in CI.
👍 There is no schema, query or migration in this diff.
🤔 generator_controller.js is 579 lines after this PR. It already did a lot. The slope and the Reset popup landed there too. A small profile or reset helper would thin it. Not a blocker.
🤔 The Puma bump is 6 to 7.2.4, with no change to config/puma.rb. CI started Puma with -w 0 and the Generate tests, including the new sloped one that waits on /box/stream, passed. I did not see a Puma 7 correctness bug in this run. There is an open Puma 7.2 report about chunked SSE not sending the last chunk, so the first production deploy of /box/stream is still worth watching.
The failed e2e run
🛑 The e2e job is red because of this PR, not because of Puma 7 or the Reset popup. Those tests passed, and so did the sloped preview, the sloped cut, and the phone layout. The failure is the new test puts the units, the lid and the front first, wide enough for every option. On the Ubuntu runner, at 1440×900, the lid <select> was 173px wide and the test required at least 182.11px. The assertion label Closed box is only the first option; the width is that of the longest option, Lid, tabs along the back. The test is new, and so is the third dropdown in .side and the custom arrow with 26px of right padding. The author's local run was 59/59; the Linux CI font is wider. The test also under-counts the arrow: it adds 16px, while the CSS keeps 26px. The column needs to grow so the longest lid option is not tight against the arrow on the OS that CI and the servers use.
Verdict
review-rejected. The geometry and the validation are in good shape, including a front height of 0. The e2e check is red on a layout assertion this PR added, and that has to be green before a merge.
Alan Turing
| const context = document.createElement("canvas").getContext("2d") | ||
| context.font = `${style.fontWeight} ${style.fontSize} ${style.fontFamily}` | ||
| const widest = Math.max(...[...select.options].map((option) => context.measureText(option.textContent).width)) | ||
| expect(select.getBoundingClientRect().width, select.options[0].textContent).to.be.at.least(widest + parseFloat(style.paddingLeft) + 16) |
There was a problem hiding this comment.
🛑 This is the assertion that failed in CI: the lid select was 173px wide and the test required 182.11px. The message says Closed box because that is options[0]; the measured text is the longest option, Lid, tabs along the back. The test adds 16px for the arrow, while .pick select keeps 26px of right padding, so even a pass here would not prove the option clears the arrow. The column needs to grow on Linux, where this runner's font is wider than a local 59/59 run.
Alan Turing
| .seg input:focus-visible + span { outline: 2px solid var(--amber); outline-offset: 2px; } | ||
| .pick select { padding: 4px 10px; max-width: 100%; } | ||
| /* Our own arrow, in 26px of padding kept for it: the native one takes no room on Linux, so the longest option ran under it. */ | ||
| .pick select { |
There was a problem hiding this comment.
🛑 The comment is right that the native arrow takes no room on Linux. The e2e failure is on that same Ubuntu runner: the lid select ended up 173px wide, which is not enough for the longest option plus this 26px of padding. Widening .side so the stretched select can reach that width will also let the test pass for the right reason.
Alan Turing
| if (front) outline.push([0, Hf]) | ||
|
|
||
| return { | ||
| angle, |
There was a problem hiding this comment.
👍 These numbers match laser-cutter 3.0.0's Sloped::Profile to 1e-12 on every case the gem can draw, including a front height of 0 (the front strip is dropped, the span starts at (0, 0)) and a slope that leaves no top strip. PRECISION is the same 1e-6.
Alan Turing
| errors << "At #{trim(slope)}° the slope runs #{trim(run.round(2))} #{units} back, deeper than the box. " \ | ||
| 'Make the slope steeper, the front taller, or the box deeper.' | ||
| end | ||
| end |
There was a problem hiding this comment.
🤔 This covers a slope that needs more depth than the box has, but not a slope so short that the strips eat the tilted panel. Profile#refuse_no_tilted_panel! still raises. On a 3 in box of 1/4 in material at 45°, a front height of 2.75 already does that, and that is the high end of the form's clamp. The controller would return 422 with the gem's words, not a 500. The same check here and in slopeProblem would keep the preview from drawing a backwards panel.
Alan Turing
There was a problem hiding this comment.
🟡 Changes recommended
Active findings include a critical geometry-validation gap that permits laser-cutter-rejected designs, plus keyboard focus, Escape handling, and text-contrast issues.
4 open issues
What changed in this PR
Adds sloped boxes to the generator with laser-cutter 3.0 support, live previews, and safer, more responsive controls.
Changes:
- Adds slope parameters, validation, previews, and angle-based filenames.
- Adds Reset confirmation and updates tablet/phone layouts.
- Expands model, request, and browser coverage.
| File | Description |
|---|---|
spec/requests/home_spec.rb |
Removes obsolete lid compatibility checks. |
spec/requests/boxes_spec.rb |
Tests sloped downloads and rejection. |
spec/models/box_request_spec.rb |
Updates lid expectations. |
spec/models/box_request_sloped_spec.rb |
Tests slope validation and rendering. |
lib/makeabox/svg_renderer.rb |
Updates the compatibility comment. |
docs/badges/coverage_badge.svg |
Updates displayed coverage. |
cypress/e2e/lib.cy.js |
Tests sloped geometry and previews. |
cypress/e2e/generator.cy.js |
Tests Reset, slopes, and responsive layouts. |
app/views/home/_generator.html.haml |
Adds shape controls and Reset confirmation. |
app/models/box_request.rb |
Validates and configures sloped boxes. |
app/javascript/lib/sloped_profile.js |
Computes sloped geometry and validation messages. |
app/javascript/lib/iso_sloped_box.js |
Renders sloped previews. |
app/javascript/controllers/generator_controller.js |
Connects slope controls, previews, and Reset behavior. |
app/controllers/home_controller.rb |
Removes legacy lid capability settings. |
app/controllers/boxes_controller.rb |
Permits slope parameters. |
app/assets/stylesheets/tokens.css |
Documents the error color token. |
app/assets/stylesheets/generator.css |
Styles previews, confirmation, errors, and layouts. |
.rubocop_todo.yml |
Refreshes generated lint metadata. |
Review effort: Balanced
| run = (number(:height) - front) / Math.tan(slope * Math::PI / 180) | ||
| return if run <= number(:depth) + 1e-6 |
| /* Why the box cannot be made: a bright red pill above the strip. */ | ||
| .hint { | ||
| position: absolute; left: var(--gutter); bottom: calc(100% + 10px); margin: 0; max-width: calc(100% - 2 * var(--gutter)); | ||
| padding: 6px 16px; border-radius: 99px; background: var(--error); color: #fff; font-size: 14px; font-weight: 700; line-height: 1.35; |
| // The slope fields are emptied, so a sloped front starts afresh. Everything | ||
| // else on the form is left as it is. | ||
| restart() { | ||
| this.confirming(false) |
| Reset | ||
| %span.wide to defaults | ||
| -# Reset asks first, in a small popup beside it. No, Escape or a click elsewhere puts it away. | ||
| .reset{data: {action: 'keydown.esc->generator#keep click@window->generator#dismiss'}} |
kigster
left a comment
There was a problem hiding this comment.
👍 The 💩 from the last review is fixed. BoxRequest#check_slope (via tilted_length) and the JS slopeProblem (via slopedProfile) now refuse a box with no tilted panel. Both use the same formula as Sloped::Profile#tilted_length, with the same 1e-6 floor on the top strip and the same message, and there are specs on both sides.
👍 config/puma.rb now uses before_restart, so Puma 7 no longer prints the deprecation warning.
👍 The e2e width test now measures the option text in the app's own document, which has the web font loaded. This fixes the real cause, the test itself, so reverting the custom-arrow CSS is right. CI is green: test, lint and e2e.
🙁 The angle and front height are now rounded to 2 places on both sides, but the rounding rules still differ: Ruby 2.675.round(2) gives 2.68, JS (2.675).toFixed(2) gives 2.67. Details inline. Not blocking.
🙁 These items from the last review are deferred to a follow-up PR the user approved, so I am not counting them as blockers: the #d00000 contrast fix, focusout and alertdialog on the Reset popup, the notch limit on the tilted panel, the order of the slope and notch checks, and the 'upright sends no slope' Cypress test.
| expect(errors_for(tight.merge('front_height' => '2'))).to be_empty | ||
| end | ||
|
|
||
| it 'is what laser-cutter refuses too' do |
There was a problem hiding this comment.
👍 This spec ties the hand-written tilted_length to the gem: it runs the same numbers through Sloped::Profile and expects it to raise. If laser-cutter ever changes the rule, this fails instead of the two copies silently drifting apart.
| angle = slope * Math::PI / 180 | ||
| run = (number(:height) - front) / Math.tan(angle) | ||
| if run > number(:depth) + 1e-6 | ||
| return errors << "At #{trim(slope.round(2))}° the slope runs #{trim(run.round(2))} #{units} back, deeper than the box. " \ |
There was a problem hiding this comment.
🙁 It now rounds to 2 places like JS, but the two don't round ties the same way. Ruby's Float#round works on the decimal value, so 2.675.round(2) gives 2.68. JS toFixed works on the binary value, so (2.675).toFixed(2) gives 2.67 (I checked both). So a typed front height of 2.675 (or 1.005) gives a hint and a 422 that differ by 0.01. value.to_r.round(2) rounds the exact binary value and matched toFixed on every case I tried (2.675, 1.005, 0.125, 33.335). format('%.2f') does not: it also gives 2.68. A small round2 helper used for slope, run and front would fix it. Not blocking.
| // app's web font, so it measures a fallback that is wider on Linux. | ||
| const fits = ($select) => { | ||
| const select = $select[0], page = select.ownerDocument, style = page.defaultView.getComputedStyle(select) | ||
| const probe = page.createElement("span") |
There was a problem hiding this comment.
👍 Good diagnosis. The canvas was measuring a fallback font in the spec's own document. Measuring a hidden span in select.ownerDocument uses the same font and stretch the select renders with, so the test no longer has to depend on how each platform draws the native arrow.
|
✅✅✅✅✅ Ready to merge at f7233b5. The no-tilted-panel 💩 is fixed on both sides with specs, The remaining 🙁 items are not blocking: tie rounding (Ruby |
* Darken the error red to pass WCAG AA White on #ff2020 was 3.8:1; #d00000 is 5.7:1, past the 4.5:1 that 14px bold text needs. * Close the Reset popup when focus leaves it 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. * Check the slope before the notch, as the form does The hint checks slope before notch; the server checked notch first, so the two could name different problems for the same box. * Count notches along the sloped panel too 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. * Test that an upright box sends no slope 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. * Round ties in slope messages as the form does 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.


Summary
A box whose front slopes back, drawn by laser-cutter 3.0 and previewed live. Also adds a confirmation for Reset, a bright red error pill, and a reworked panel layout for tablets and phones.
iso_sloped_box.js) draws a lifted plain lid without tabs.makeabox-5x4x3in-0.25t-45deg.svg.Evidence
After:
spec/models/box_request_sloped_spec.rb,boxes_specpermits slope params)generator.cy.js39,lib.cy.js20), including:resets to a closed, upright 5 × 4 × 3 in box of 1/4 in material→ Reset, Yes, values back,.slopedhiddenkeeps the box when the reset is answered No, or with Escapedraws the lifted plain lid without tabs.gobelow them, no horizontal scrollMerge Danger
Door: two-way
Revert the merge to go back. No data, schema or URL changes.
Blast Radius: generator
/box/streamSSE through nginx.