Skip to content

Validate and normalize auto-postpone period to days#2672

Merged
flavorjones merged 9 commits into
basecamp:mainfrom
robzolkos:entropy-validation-and-days
Mar 9, 2026
Merged

Validate and normalize auto-postpone period to days#2672
flavorjones merged 9 commits into
basecamp:mainfrom
robzolkos:entropy-validation-and-days

Conversation

@robzolkos

@robzolkos robzolkos commented Mar 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add Entropy::AUTO_POSTPONE_PERIODS_IN_DAYS as the single source of truth for allowed entropy values and validate auto_postpone_period against that allowlist (stored in seconds).
  • Move entropy form/controller inputs to auto_postpone_period_in_days for:
    • account entropy updates,
    • board entropy updates,
    • board updates (BoardsController).
  • Keep the existing Board#auto_postpone_period= seconds writer, but make it strict with update!; add Board#auto_postpone_period_in_days= plus delegation for auto_postpone_period_in_days.
  • Simplify the knob rendering to operate directly on day values and remove the entropy_auto_close_options helper.
  • Preserve the intended knob rendering order by keeping 11 as the last option.

Tests

  • Update controller/model tests to use day-based inputs and valid allowlisted values.
  • Add invalid-value coverage for account and board entropy updates (422 Unprocessable Entity, value unchanged).
  • Add a board edit rendering test that asserts the knob options are rendered in Entropy::AUTO_POSTPONE_PERIODS_IN_DAYS order and that 11 is last.

Copilot AI review requested due to automatic review settings March 7, 2026 17:58
@robzolkos robzolkos force-pushed the entropy-validation-and-days branch from beaa509 to ff83fbd Compare March 7, 2026 18:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR tightens validation around entropy auto-postpone periods and updates the UI/controller plumbing so the setting is expressed in days (not raw seconds), preventing crafted requests from persisting arbitrary/negative periods.

Changes:

  • Add Entropy::AUTO_POSTPONE_PERIODS and validate auto_postpone_period against the allowed set.
  • Introduce/use auto_postpone_period_in_days for forms and entropy update endpoints.
  • Remove the entropy_auto_close_options helper and update tests to use allowed values.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
test/models/entropy_test.rb Updates entropy-touch tests to use an allowed period value.
test/models/card/entropic_test.rb Updates entropic behavior tests to use allowed periods.
test/controllers/boards_controller_test.rb Updates board update test to use an allowed entropy period value.
test/controllers/boards/entropies_controller_test.rb Switches board entropy update requests to auto_postpone_period_in_days.
test/controllers/accounts/entropies_controller_test.rb Switches account entropy update requests to auto_postpone_period_in_days and adds an invalid-value rejection test.
app/views/entropy/_knob.html.erb Adjusts knob rendering to work with day values rather than durations.
app/views/entropy/_auto_close.html.erb Uses Entropy::AUTO_POSTPONE_PERIODS and posts auto_postpone_period_in_days.
app/models/entropy.rb Adds the allowed-periods constant, inclusion validation, and virtual day-based attribute accessors.
app/models/board/entropic.rb Delegates/accepts day-based entropy period updates on boards.
app/helpers/entropy_helper.rb Removes entropy_auto_close_options in favor of the model constant.
app/controllers/boards/entropies_controller.rb Permits auto_postpone_period_in_days for board entropy updates.
app/controllers/account/entropies_controller.rb Permits auto_postpone_period_in_days for account entropy updates.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/models/board/entropic.rb Outdated
Comment thread app/views/entropy/_knob.html.erb
Comment thread app/models/entropy.rb Outdated
Comment thread test/models/entropy_test.rb
@robzolkos robzolkos force-pushed the entropy-validation-and-days branch from ff83fbd to b910b45 Compare March 7, 2026 18:08
Copilot AI review requested due to automatic review settings March 7, 2026 18:13
@robzolkos robzolkos force-pushed the entropy-validation-and-days branch from 69ec014 to 27c1100 Compare March 7, 2026 18:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/views/entropy/_knob.html.erb
@robzolkos robzolkos force-pushed the entropy-validation-and-days branch from 27c1100 to e42dc5e Compare March 7, 2026 21:27
Copilot AI review requested due to automatic review settings March 7, 2026 21:38
@robzolkos robzolkos force-pushed the entropy-validation-and-days branch from e42dc5e to 1ca81bf Compare March 7, 2026 21:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/models/entropy.rb
@robzolkos robzolkos force-pushed the entropy-validation-and-days branch from 1ca81bf to a2a4847 Compare March 7, 2026 21:47
Copilot AI review requested due to automatic review settings March 7, 2026 22:09
@robzolkos robzolkos force-pushed the entropy-validation-and-days branch from a2a4847 to bed335e Compare March 7, 2026 22:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@robzolkos robzolkos force-pushed the entropy-validation-and-days branch from bed335e to fcf9d52 Compare March 7, 2026 22:23
@robzolkos robzolkos marked this pull request as ready for review March 7, 2026 22:40
Copilot AI review requested due to automatic review settings March 7, 2026 22:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@flavorjones flavorjones left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks like a big improvement. Thank you!

I'm a little worried that users may have already set arbitrary entropy periods via the API, though. Do you think we should consider writing a migration script in script/migrations/ to normalize the values?

Comment thread app/views/entropy/_knob.html.erb Outdated
@robzolkos robzolkos force-pushed the entropy-validation-and-days branch from fcf9d52 to 6f03b70 Compare March 9, 2026 19:01
Copilot AI review requested due to automatic review settings March 9, 2026 19:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/controllers/boards/entropies_controller.rb
Comment thread app/controllers/account/entropies_controller.rb
Comment thread app/controllers/boards_controller.rb
Comment thread app/models/entropy.rb Outdated
Copilot AI review requested due to automatic review settings March 9, 2026 20:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 17 out of 18 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/models/entropy.rb
Comment thread saas/lib/fizzy/saas/engine.rb
- Add Entropy::AUTO_POSTPONE_PERIODS and validate auto_postpone_period against the allowed set
- Introduce auto_postpone_period_in_days for forms and entropy update endpoints
- Fall back to index 0 in knob partial when current value isn't in options
- Remove entropy_auto_close_options helper in favor of model constant
- Update tests to use allowed period values
The JSON API was accepting auto_postpone_period (seconds) which
bypassed the days normalization and validation. Switch to
auto_postpone_period_in_days consistently and add explicit
wrap_parameters so flat JSON params are wrapped correctly for
the virtual attribute.
- Fall back to first knob option (index 0) when persisted value isn't in
  the allowed set, preventing nil index errors for legacy values
- Use integer division (1.day.to_i) for consistent day calculations
Rescue ActiveRecord::RecordInvalid in entropy controllers so invalid
auto_postpone_period_in_days values return 422 Unprocessable Entity
instead of raising a 500.
@robzolkos robzolkos force-pushed the entropy-validation-and-days branch from 75325fd to 0cbd4b2 Compare March 9, 2026 20:20
Use container.account.entropy.auto_postpone_period_in_days instead of
container.account.auto_postpone_period_in_days since Account doesn't
delegate that method.
Copilot AI review requested due to automatic review settings March 9, 2026 20:27
@robzolkos

Copy link
Copy Markdown
Collaborator Author

@flavorjones No migration script needed — there was no API for setting arbitrary entropy periods, so existing values should all be valid.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@flavorjones flavorjones left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Love it!

@flavorjones flavorjones merged commit 23ac765 into basecamp:main Mar 9, 2026
5 checks passed
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.

3 participants