Skip to content

fix: do not build polled image URLs before the SDK is initialized - #1172

Merged
pirate-bot merged 2 commits into
developmentfrom
bugfix/1162
Oct 13, 2026
Merged

pirate-bot merged 2 commits into
developmentfrom
bugfix/1162

Conversation

@selul

@selul selul commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Related issue: #1162

The "Last optimized images" poll turned the API's list into image URLs through the Optimole SDK, which is only initialized for a connected site. On a site without a CDN key and secret it threw Please initialize the Optimole SDK first. It now returns an empty list there, without calling the API.

What changed

  • Optml_Rest::poll_optimized_images() — returns an empty list when Optml_Settings::is_connected() is false, before the API call. Connected sites behave as before.

Note

The dashboard already handles an empty list (the same response as an API error or an empty account), so the box shows its empty state.

Tests

  • tests/test-poll-optimized-images.php: with no service_data, polling returns success with an empty list and sends no request, even when the API would return images. The test fails on development (the SDK exception).

QA

  1. On a site where Optimole is not connected (no API key, or disconnected), open WP Admin → Optimole and check the browser console and PHP error log while the dashboard loads.

    Expect: no Please initialize the Optimole SDK first error.

  2. On a connected site, open the dashboard.

    Expect: the "Last optimized images" box shows images as before.

Verification (head dd5dcd13)

Check Result
PHPUnit, full suite, PHP 8.4 (WP 7.1.3) PASS: 365 tests (baseline 364 + 1 new)
tests/test-poll-optimized-images.php run alone PASS: 7 tests
New test on the development source FAILS (SDK exception)
phpcs, phpstan (build-only include errors excluded locally; CI builds assets first) PASS
CI on dd5dcd13 (PHPUnit on PHP 8.0–8.3, PHPStan, phpcs, ESLint, Jest, e2e, build) PASS: 12/12
Codex review (gpt-6-astra, high), 2ca97714 and the follow-up on dd5dcd13 No findings
pirate-bot Round 1 (2ca97714): changes requested, return types on the new test and its mock closure (fixed). Round 2 (dd5dcd13): approved

🤖 Generated with Claude Code

poll_optimized_images() turned the API's list into image URLs through the
Optimole SDK, which is only initialized for a connected site. On a site
without a CDN key and secret it threw "Please initialize the Optimole SDK
first". It now returns an empty list there, without calling the API.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pirate-bot

pirate-bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

Plugin build for dd5dcd1 is ready 🛎️!

@selul
selul requested a review from pirate-bot October 11, 2026 12:52

@pirate-bot pirate-bot left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🟡 Changes requested

The guard fixes the reported SDK exception, but the new test needs return types on its method and mock closure.

Validation details
  • Files reviewed: 2/2 changed files.
  • I ran sandbox-phpunit-ab.sh /repo pr-base --filter 'Test_Poll_Optimized_Images::' on PHP 8.3 with the WP 7.1.3 test library. HEAD passed 7 tests. With inc/rest.php from pr-base, the new test raised Please initialize the Optimole SDK first. The harness kept no run record. The log is at /workspace/checks/C4/ab.log.
  • A source trace showed that is_connected() matches the condition that initializes the SDK.
  • The route still requires manage_options. The guard reads only saved settings.
Untested areas
  • I did not check the dashboard empty state in a browser.
  • One path is still unverified. It needs OPTIML_USE_ENV auto-connect in the same request as the poll, and OPTIML_IMAGE_REPLACER=off. The same path exists on the base branch.

🤖 Automated review · run code-review-agent_6acb86a0160da0.99750732.


🤖 Review agent — review posted ✅ on 2ca97714 · changes requested · 1 finding · 18 min

Run code-review-agent_6acb86a0160da0.99750732 · trail

Comment thread tests/test-poll-optimized-images.php Outdated
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@selul
selul requested a review from pirate-bot October 11, 2026 13:23

@pirate-bot pirate-bot left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🟢 Approved

The PR passes. The earlier types finding is fixed, and the new commit changes only test types.

Validation details
  • Files reviewed: 2/2 changed files.
  • I read the diff since 2ca97714. It adds : void, : array and a shape docblock to the new test.
  • cd /repo; sandbox-env-record.sh 2>&1 | tail -20; php -l tests/test-poll-optimized-images.php; sed -n 180,232p tests/test… printed No syntax errors detected in tests/test-poll-optimized-images.php (run R1)
  • I ran sandbox-phpunit-ab.sh /repo pr-base --filter 'Test_Poll_Optimized_Images::' on PHP 8.3. The harness kept no run record. The log is at /workspace/checks/C1/ab2.log.
  • Security and standards checks on inc/rest.php come from run code-review-agent_6acb86a0160da0.99750732 on 2ca97714, not rerun. That file is unchanged since.
Untested areas
  • I did not check the dashboard empty state in a browser.
  • Auto-connect through OPTIML_USE_ENV in the same request as the poll is unverified. The same path exists on the base branch.

🤖 Automated review · run code-review-agent_6acb8db97578f1.59981029.


🤖 Review agent — review posted ✅ on dd5dcd13 · approved · 0 findings · 2 min

Run code-review-agent_6acb8db97578f1.59981029 · trail

@pirate-bot
pirate-bot merged commit d5e8ead into development Oct 13, 2026
16 checks passed
@pirate-bot
pirate-bot deleted the bugfix/1162 branch October 13, 2026 20:02
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