Skip to content

Doug/abn 287 error handling#77

Merged
dgjlindsay merged 6 commits intomainfrom
doug/ABN-287-error-handling
Mar 26, 2026
Merged

Doug/abn 287 error handling#77
dgjlindsay merged 6 commits intomainfrom
doug/ABN-287-error-handling

Conversation

@dgjlindsay
Copy link
Copy Markdown
Contributor

No description provided.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on improving the robustness and developer experience of the module. It refines how API errors are processed and presented to the user, making them clearer and more actionable. Concurrently, it establishes a foundational unit testing framework and enhances the local development environment setup through Makefile additions, ensuring better code quality and maintainability.

Highlights

  • Enhanced Error Handling: The error handling logic in Model/Two.php has been significantly refactored to provide more precise and user-friendly messages, distinguishing between validation, user-specific, and system errors. This includes cleaning up Pydantic-specific error message formatting.
  • Improved Build and Test Automation: The Makefile now includes new targets for compile (Magento DI compilation) and test (PHPUnit execution), streamlining the development and testing workflow. A comprehensive unit testing setup has been introduced, complete with Magento core class stubs.
  • Magento Application State Integration: The module now correctly determines the Magento application mode (e.g., developer, production) by injecting and utilizing Magento\Framework\App\State, replacing direct environment variable checks for more robust behavior.
  • Internationalization Updates: Norwegian, Dutch, and Swedish translation files have been updated to align with the new, more generic validation error message structure, improving consistency across languages.
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/phpunit.yml
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Bootstrap test infrastructure without composer install — uses a PSR-4
autoloader and Magento stub classes so tests run with just a phpunit
phar on a bare PHP image.

- 38 tests (65 assertions) covering getErrorFromResponse(),
  getFieldNameFromLoc(), getCheckoutApiUrl(), getCheckoutPageUrl()
- Docker-based `make test` target and CI workflow (PHP 7.4/8.1/8.2)
- Fix return type bug: SCHEMA_ERROR/ORDER_INVALID now returns Phrase

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dgjlindsay dgjlindsay force-pushed the doug/ABN-287-error-handling branch from c526a82 to d5ca31d Compare March 18, 2026 09:57
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request significantly improves error handling by providing more specific and user-friendly messages from the API, especially for validation errors. It also introduces a robust unit testing setup with stubs and a comprehensive test suite for the new error handling logic and URL generation, which is a great step towards better code quality and maintainability. The refactoring to use Magento's AppState instead of getenv is also a good practice. I've added a couple of suggestions to improve the developer experience with the new test runner and to prevent a potential translation bug.

I am having trouble creating individual review comments. Click here to see my feedback.

Model/Two.php (351-364)

high

Using a static variable to cache the $fieldNames array can lead to bugs related to translation. The __() calls are evaluated only once when the static variable is initialized. If the locale changes during a single PHP request (which can happen in some Magento API scenarios), this method will return stale translations from the previously active locale.

Since this array is small, the performance benefit of caching is negligible. It's safer to remove the static variable and initialize the array on every call.

        $fieldNames = [
            '["buyer","representative","phone_number"]' => __('Phone Number'),
            '["buyer","company","organization_number"]' => __('Company ID'),
            '["buyer","representative","first_name"]' => __('First Name'),
            '["buyer","representative","last_name"]' => __('Last Name'),
            '["buyer","representative","email"]' => __('Email Address'),
            '["billing_address","street_address"]' => __('Street Address'),
            '["billing_address","city"]' => __('City'),
            '["billing_address","country"]' => __('Country'),
            '["billing_address","postal_code"]' => __('Zip/Postal Code'),
        ];

Makefile (100-101)

medium

The test target downloads phpunit.phar on every run. This can slow down the test cycle.

To improve this, you could download it into a local bin directory, which is then available inside the container via the volume mount. This way, it's downloaded only once.

Remember to add bin/ to your .gitignore file.

		"if [ ! -f /app/bin/phpunit.phar ]; then mkdir -p /app/bin && php -r \"copy('https://phar.phpunit.de/phpunit-9.6.phar', '/app/bin/phpunit.phar');\"; fi; \
		php /app/bin/phpunit.phar"

Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

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

One security finding on the PHAR download in the new CI workflow (see inline comment). The Model/Two.php fix and unit test additions look correct — no other critical issues found.

Add tests asserting that in developer mode, TWO_API_BASE_URL and
TWO_CHECKOUT_BASE_URL env vars take precedence even when an explicit
$mode parameter is passed to getCheckoutApiUrl/getCheckoutPageUrl.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
dgjlindsay and others added 3 commits March 18, 2026 10:21
Pin to phpunit-9.6.34 with hardcoded SHA256 hash in both CI workflow
and Makefile to prevent supply chain attacks via compromised CDN.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Adds Test/E2E/ with a RealCurl HTTP implementation and three tests covering
valid key, invalid key (401), and bad payload. make test runs Unit only
(defaultTestSuite); make test-e2e forwards TWO_API_KEY/TWO_API_BASE_URL
into Docker and runs the E2E suite. Missing key fails naturally at the
assertion rather than skipping.
Stubs for Curl, LocalizedException, BundlePrice, ProductType; unit tests
for Adapter, OrderShouldSkip, and addVersionDataInURL; bootstrap wiring;
session summary and plan docs.
Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

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

Previously flagged PHAR checksum issues (workflow and Makefile) have been addressed with hardcoded SHA256 verification. No new critical issues found — PR is ready for human approval.

Remove session summaries and implementation plans that were
accidentally committed. Add Session Artifacts section to AGENTS.md
clarifying that session-specific content must not be committed to
this public repository.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

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

Previously flagged issues are addressed: PHAR checksum verification is now in place for both the CI workflow and the make test target. The docs/plans/ file was removed and the thread resolved.

No new critical issues found in the current diff. The Model/Two.php fix (ensuring $reason is always a Phrase) is correct. The test infrastructure looks solid. Ready for human approval.

@dgjlindsay dgjlindsay merged commit f57ef04 into main Mar 26, 2026
18 checks passed
@dgjlindsay dgjlindsay deleted the doug/ABN-287-error-handling branch March 26, 2026 15:11
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