Skip to content

Fix the extension on Solidus 4.8 and run the specs on GitHub Actions - #2

Merged
filippoliverani merged 8 commits into
mainfrom
filippoliverani/fork-fixes
Nov 25, 2026
Merged

filippoliverani merged 8 commits into
mainfrom
filippoliverani/fork-fixes

Conversation

@filippoliverani

@filippoliverani filippoliverani commented Nov 25, 2026 •

Copy link
Copy Markdown

This PR fixes the bugs that break the extension on Solidus 4.8, gets the spec suite green, and replaces CircleCI with GitHub Actions so the fork finally has a CI signal.

On Solidus 4.8 and Rails 8.1 the extension had a few runtime bugs, and 26 of 200 examples failed, most of them in the spec setup. The worst one is in production code: every decorator body ran twice, so Spree::Payment registered avalara_finalize twice and committed the Avalara transaction twice per payment completion. CircleCI never reported on this fork, so none of this showed up anywhere.

Decorators load once (b3c3382):

  • SolidusSupport::EngineExtensions adds app/decorators to the autoload paths and then loads every decorator in to_prepare. The module keyword triggers Zeitwerk's autoload of the same file, and the outer load runs the body a second time.
  • I overrode Engine.load_solidus_decorators_from to resolve each file's constant through Rails.autoloaders.main.cpath_expected_at(decorator_path).constantize, so Zeitwerk runs each body once per boot and once per reload.
  • I dropped the engine's own to_prepare glob, which added a third run when classes aren't cached.
  • The gemspec now requires solidus_support >= 0.15, the version I checked the override against, and solidus_core >= 4.1, the minimum solidus_support 0.15 accepts. It also requires zeitwerk >= 2.6.9, the first release with Loader#cpath_expected_at, since Rails 7.0 and 7.1 accept older versions.

Calculator (8b327d2):

  • With document commit disabled, get_avalara_response asked for the final SalesInvoice of an order that can commit and got back the String "Avalara Document Committing Disabled", so AvalaraTransaction#tax_for_item raised NoMethodError on avalara_response['lines'].
  • It now asks for an uncommitted SalesOrder unless document committing is enabled, so the tax stays current on completed orders too.
  • It returns the previous tax amount for any other non-Hash response, as it already did for nil, and 0 for a Hash without lines (the guard from upstream 9310b80).
  • post_order_to_avalara returns nil on an AvaTax error instead of { 'totalTax' => 0.0 }, so a failed lookup keeps the previous tax. get_avalara_response caches the failure as a marker for one minute, so the other items and shipments in the same recalculation reuse it instead of each asking AvaTax again. SalesOrder quotes expire after five minutes, since the cache key leaves out inputs such as the document date and the customer's exemption. Committed SalesInvoice responses keep no expiry, so a later recalculation doesn't post the filed invoice again. The cache key prefix becomes avtx_v2, so results cached by the previous code aren't read after a deploy. Before, a completed order recalculated during an outage was saved with zero tax.

Admin (e5e6f66, 78cb756, 94242dc):

  • Solidus 4.8 has no button or button_link_to helpers, so the use code edit and index pages raised NoMethodError. The edit page now renders spree/admin/shared/edit_resource_links and the index page a btn btn-primary link, as Solidus's own admin pages do.
  • AvalaraEntityUseCodesController now implements permitted_resource_params, which ResourceController requires. Submitting the edit form raised NotImplementedError without it. It permits use_code and use_code_description, the two fields the form renders.
  • UsersControllerDecorator#avalara_information reads spree.account_updated, so the flash no longer says "Translation missing: en.account_updated". The spec comes from upstream 6c8d3c8.
  • Neither solidus_backend 4.8 nor solidus_frontend defines Spree.routes anymore, so the backend and frontend scripts threw a TypeError on load. Each one now creates the object when it's missing.

Migrations (21bd3e5):

  • The six migrations inherit from ActiveRecord::Migration[4.2] instead of the deprecated SolidusSupport::Migration[4.2], which already returned the same class. Versions and file names are unchanged.

Spec setup (420e11f):

  • spec_helper.rb includes Devise::Test::ControllerHelpers in controller specs. Every controller example failed with Devise::MissingWarden before reaching the controller.
  • The avalara_order factory creates its store even under the build strategy, like Solidus core's order factory does. build(:avalara_order) raised "Store can't be blank" in 13 examples.
  • spec_helper.rb bootstraps the dummy app with bundle exec rake, since the repo has no bin/rake binstub.
  • New specs: engine_spec.rb checks each state machine callback is registered once, and the users decorator spec checks the flash. The use code controller spec now uses render_views so it catches template errors, and creates a use code before the index request so the rows and their links render. The six new calculator examples have VCR cassettes, so they run offline.

CI (b46e5b0):

  • .github/workflows/test.yml replaces the CircleCI config. It runs solidusio/test-solidus-extension, pinned by SHA, on Solidus v4.8, Rails 8.1, Ruby 4.0 and SQLite. The workflow token is limited to contents: read, and the README badge points at this workflow instead of CircleCI.
  • The Gemfile honours RAILS_VERSION, which the action exports, and takes solidus_frontend from GitHub, pinned to 16546d19, for every Solidus branch from v3.2. The released 4.8.0 gem depends on canonical-rails, which caps actionview below 8.1, and the pin keeps upstream commits from changing the CI run, since Gemfile.lock is ignored.

solidus_support 0.15 deprecates SolidusSupport::Migration, and its []
already returns ActiveRecord::Migration[4.2], so the superclass stays
the same class object. Versions and file names don't change, so apps
that already ran these migrations see no difference. Generating the
test app no longer logs six deprecation warnings.
Includes Devise::Test::ControllerHelpers in controller specs. Every
controller example failed with Devise::MissingWarden before reaching
the controller.

Creates the avalara_order factory's store even under the build
strategy. Spree::Order validates store_id, and the factory saves the
order while recalculating adjustments, so build(:avalara_order)
raised "Store can't be blank" in 13 examples. Solidus core's order
factory declares its store the same way.

Bootstraps the dummy app with bundle exec rake, since the repo has no
bin/rake binstub.
@filippoliverani filippoliverani self-assigned this Nov 25, 2026
@filippoliverani
filippoliverani requested an adaptive review from Copilot November 25, 2026 10:06
@filippoliverani
filippoliverani marked this pull request as ready for review November 25, 2026 10:06

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

Unresolved critical issues can cause boot failures with older Zeitwerk versions and leave recalculated order taxes stale, double-counted, or incorrectly zeroed.

4 open issues
What changed in this PR

Updates the Avalara tax extension for Solidus 4.8 and Rails 8.1, and moves CI to GitHub Actions so the fork can run its spec suite.

Changes:

  • Changes decorator loading to avoid duplicate callbacks and adds calculator response guards.
  • Updates admin forms, controller parameters, translations, JavaScript routes, and migration base classes.
  • Repairs spec setup, adds regression specs and offline fixtures, and replaces CircleCI with GitHub Actions.
File Description
spec/​vcr/​Spree_Calculator_AvalaraTransaction/​_compute_line_item/​when_tax_is_not_included_in_price/​returns_the_previous_tax_when_the_response_is_a_String.yml Adds an offline setup fixture for the String-response test.
spec/​vcr/​Spree_Calculator_AvalaraTransaction/​_compute_line_item/​when_tax_is_not_included_in_price/​returns_0_when_the_response_has_no_lines.yml Adds an offline setup fixture for the missing-lines test.
spec/​spec_helper.rb Uses Bundler rake and includes Devise controller helpers.
spec/​models/​spree/​calculator/​avalara_transaction_spec.rb Adds String-response and missing-lines examples.
spec/​lib/​solidus_avatax_certified/​engine_spec.rb Checks that state-machine callbacks register once.
spec/​controllers/​spree/​admin/​users_controller_decorator_spec.rb Checks the translated success flash.
spec/​controllers/​spree/​admin/​avalara_entity_use_codes_controller_spec.rb Enables view rendering to catch template errors.
solidus_avatax_certified.gemspec Raises the solidus_support minimum to 0.15.
lib/​solidus_avatax_certified/​testing_support/​factories/​avalara_order_factory.rb Persists the store association when building orders.
lib/​solidus_avatax_certified/​engine.rb Resolves decorators through Zeitwerk and removes redundant loading.
Gemfile Updates the frontend source and allows a Rails version constraint.
db/​migrate/​20170509201056_drop_spree_avalara_preferences.rb Uses ActiveRecord::Migration[4.2] directly.
db/​migrate/​20160805193512_add_vat_id_to_spree_users.rb Uses ActiveRecord::Migration[4.2] directly.
db/​migrate/​20160628200504_create_spree_avalara_preferences.rb Uses ActiveRecord::Migration[4.2] directly.
db/​migrate/​20160624155217_add_columns_to_spree_users.rb Uses ActiveRecord::Migration[4.2] directly.
db/​migrate/​20160624154423_create_spree_avalara_entity_use_codes.rb Uses ActiveRecord::Migration[4.2] directly.
db/​migrate/​20160624154205_create_spree_avalara_transactions.rb Uses ActiveRecord::Migration[4.2] directly.
app/​views/​spree/​admin/​avalara_entity_use_codes/​index.html.erb Replaces the removed button helper with a styled link.
app/​views/​spree/​admin/​avalara_entity_use_codes/​edit.html.erb Uses the shared resource-edit controls.
app/​models/​spree/​calculator/​avalara_transaction.rb Handles non-Hash responses and missing tax lines.
app/​decorators/​controllers/​solidus_avatax_certified/​spree/​admin/​users_controller_decorator.rb Corrects the success-message translation key.
app/​controllers/​spree/​admin/​avalara_entity_use_codes_controller.rb Permits the two editable use-code fields.
app/​assets/​javascripts/​spree/​frontend/​solidus_avatax_certified.js Initializes Spree.routes before assigning the validation route.
app/​assets/​javascripts/​spree/​backend/​solidus_avatax_certified.js Initializes Spree.routes before assigning admin routes.
.github/​workflows/​test.yml Adds CI for Solidus 4.8, Rails 8.1, Ruby 4.0, and SQLite.
.circleci/​config.yml Removes the previous CircleCI configuration.

Review effort: Max (adaptive)

Comment thread solidus_avatax_certified.gemspec Resolved
Comment thread solidus_avatax_certified.gemspec Resolved
SolidusSupport::EngineExtensions adds app/decorators to the autoload
paths and then loads every decorator file in to_prepare. The module
keyword hits Zeitwerk's pending autoload, Zeitwerk requires the file,
and the outer load then runs the body a second time. Every state
machine callback added in a decorator's prepended hook was registered
twice: Spree::Payment ran avalara_finalize twice per completion and
committed the Avalara transaction twice.

Overrides load_solidus_decorators_from to resolve each file's
constant through Zeitwerk, which runs each body once per boot and
once per reload. Drops the engine's own to_prepare glob, which added
a third run when classes are not cached.

Requires solidus_support 0.15, the version the override was checked
against, and solidus_core 4.1, the minimum solidus_support 0.15
accepts. Requires zeitwerk 2.6.9, the first release with
Loader#cpath_expected_at: Rails 7.0 and 7.1 accept older versions, so
a host could otherwise boot into a NoMethodError.
@filippoliverani
filippoliverani force-pushed the filippoliverani/fork-fixes branch from b373429 to cd0e327 Compare November 25, 2026 11:18

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

The loader requires Zeitwerk 2.6.9 without declaring that minimum, allowing otherwise valid dependency bundles to fail at application boot.

3 open issues
4 resolved since last review

Review effort: Max (adaptive)

Comment thread Gemfile Resolved

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

The AvaTax cache handling can mix old and new tax amounts within one order recalculation and repeatedly request the full order during service failures.

3 open issues
3 resolved since last review

Review effort: Max (adaptive)

Comment thread .github/workflows/test.yml Resolved

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

Successful quote cache writes lack an expiry, allowing unchanged carts to reuse stale tax quotes indefinitely on stores without a default expiration because the cache key omits the tax date.

1 open issue
3 resolved since last review

Review effort: Max (adaptive)

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

With a non-storing cache, repeated AvaTax lookups can mix old and new taxes within one recalculation, while decorator callback registration after reload remains untested.

2 open issues
1 resolved since last review

Review effort: Max (adaptive)

Comment thread lib/solidus_avatax_certified/engine.rb Resolved

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

The quote cache omits exemption inputs and can save stale tax, error paths break the public Hash return contract, and the index spec leaves row rendering untested.

3 open issues
2 resolved since last review

Review effort: Max (adaptive)

Comment thread app/models/spree/avalara_transaction.rb Resolved
@filippoliverani
filippoliverani force-pushed the filippoliverani/fork-fixes branch from 0c7b7d6 to b76d35e Compare November 25, 2026 14:32
@filippoliverani
filippoliverani requested an adaptive review from Copilot November 25, 2026 14:34

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

Recalculation can resubmit finalized invoices and raise errors on locked transactions, while unchanged cache keys can leave paid orders uncommitted after committing is enabled.

2 open issues
3 resolved since last review

Review effort: Max (adaptive)

With document commit disabled, get_avalara_response asked for the
final SalesInvoice of an order that can commit and got back the String
"Avalara Document Committing Disabled", so tax_for_item raised
NoMethodError on avalara_response['lines']. It now asks for a
SalesOrder unless document committing is enabled, so the tax stays
current on the confirm step.

Returns the previous tax amount for any other non-Hash response, as it
already did for nil, and 0 for a Hash without lines (the guard from
upstream 9310b80).

Returns nil from post_order_to_avalara when Avalara answers with an
error, instead of a zero totalTax. A failed lookup leaves the previous
tax in place instead of zeroing it, and is cached as a marker for one
minute, so the other items of the same order reuse the failure instead
of each asking Avalara again. SalesOrder quotes expire after five
minutes, the lifetime time_to_idle was meant to set: ActiveSupport::Cache
doesn't recognise that option, so they never expired, and the key leaves
out inputs such as the document date and the customer's exemption.
Committed SalesInvoice responses keep no expiry, as before: the invoice
is dated at completion, and posting it again on a later recalculation
would adjust the filed document, which AvaTax rejects once the period
is locked. The key prefix becomes avtx_v2, so the zero-tax error results cached by the
previous code are not read after a deploy.

Adds VCR cassettes for the six new examples so they run offline.
They hold the sandbox's 401 reply to the factory's order setup, sent
with the fake 12345:12345 credentials.
Solidus 4.8 has no button or button_link_to helpers, so the edit and
index pages raised NoMethodError. The edit page renders the shared
edit_resource_links partial and the index page a btn-primary link,
as Solidus's own admin pages do.

Implements permitted_resource_params, which ResourceController
requires. Without it, submitting the new or edit form raised
NotImplementedError. It permits the two fields the form renders.

Renders views in the controller spec so it catches template errors,
and creates a use code before the index request so the rows and their
edit and delete links render.
The account_updated key lives under the spree namespace, so the flash
read "Translation missing: en.account_updated". The spec comes from
upstream 6c8d3c8.
Neither solidus_backend 4.8 nor solidus_frontend defines
Spree.routes any more, so the backend and frontend scripts threw a
TypeError on load. Each now creates the object when it's missing.
Replaces the CircleCI config, which never reported on this fork, with
a workflow on solidusio/test-solidus-extension pinned by SHA. It tests
Solidus v4.8 on Rails 8.1 and Ruby 4.0 with SQLite.

The Gemfile honours RAILS_VERSION, which the action exports, and
takes solidus_frontend from GitHub for every Solidus branch from v3.2,
pinned to commit 16546d19. The released 4.8.0 gem depends on
canonical-rails, which caps actionview below 8.1; that commit vendors
the canonical tag helper instead.

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

Default cache expiration, uncached payment-finalization responses, and discarded legacy entries can cause committed invoices to be reposted, failing when those invoices are filed or locked.

3 open issues
2 resolved since last review

Review effort: Max (adaptive)

@filippoliverani
filippoliverani merged commit e9cb21c into main Nov 25, 2026
2 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.

2 participants