Skip to content

Route REST URL imports through the canonical import-url ability contract - #842

Open
faisalahammad wants to merge 9 commits into
Automattic:mainfrom
faisalahammad:fix/837-rest-url-imports-route-through-ability
Open

Route REST URL imports through the canonical import-url ability contract#842
faisalahammad wants to merge 9 commits into
Automattic:mainfrom
faisalahammad:fix/837-rest-url-imports-route-through-ability

Conversation

@faisalahammad

Copy link
Copy Markdown
Contributor

What

Routes URL-only imports through the resumable import-url ability so the plugin UI and the ability surface exercise one canonical path.

Changes

  • Resolve URL-only REST sources via static-site-importer/import-url instead of the legacy one-shot collector.
  • Accept import_id on the REST URL schema. The reference client re-posts the same normalized intent until the ability reports terminal completion.
  • Drop provider, provider_args, work_dir, and batch tuning from the public URL surface. Server-side policy stays internal to batch_args().
  • URL-only Playground previews short-circuit and emit a structured requires_ability_capable_target requirement instead of invoking the ability on the shipped server.
  • Current-site terminal envelopes return the import result directly with no preview block.
  • Remove Static_Site_Importer_URL_Import_Runtime::website_artifact_from_url().
  • Harden the view.js continuation loop against error envelopes.

How to test

  1. Insert the importer block into a post.
  2. Enter a public URL and click Import.
  3. Confirm the importer reports continuation envelopes (Continuing URL import (1)...) and eventually an Import complete status.
  4. Confirm each POST to /wp-json/static-site-importer/v1/imports carries the previous import_id until terminal.
  5. Try a loopback URL (http://127.0.0.1/). Confirm static_site_importer_url_private_ip / static_site_importer_url_host and the current site is not modified.
  6. Switch to Playground preview mode for a URL. Confirm the status reports URL preview needs a disposable WordPress target and the importer does not open a Playground URL.

Testing already done

  • php tests/smoke-rest-url-import-helpers.php (28 assertions)
  • php tests/smoke-url-import-runtime.php (20 assertions)
  • php tests/smoke-importer-block.php (304 assertions)
  • npm run test:inventory clean
  • npm test 45 passed, 4 pre-existing fixture-matrix failures unchanged

Notes

  • The import-url ability schema no longer declares provider / provider_args / work_dir. External callers that posted those fields will have them ignored. The hosted override path remains available via the static_site_importer_url_import_provider filter.

Closes #837

… contract

- Resolve URL-only REST sources via the resumable import-url ability instead of the
  legacy one-shot collector, so REST and the ability surface exercise one path.
- Accept import_id on the REST URL schema; the reference client re-POSTs the same
  normalized intent until the ability reports terminal completion.
- Drop provider, provider_args, work_dir, and batch tuning from the public URL
  surface; server-side policy stays internal to batch_args().
- URL-only Playground previews short-circuit and emit a structured
  requires_ability_capable_target requirement instead of invoking the ability
  on the shipped server.
- Current-site terminal envelopes return the import result directly with no
  preview block.
- Remove Static_Site_Importer_URL_Import_Runtime::website_artifact_from_url().
- Harden the view.js continuation loop against error envelopes.
- Add continuation, identity-binding, and private-address REST smoke coverage.

Closes Automattic#837
The issue Automattic#837 refactor inlined the provider-output call inside import_url(), leaving resolve_provider_output() with no callers. PHPStan reports it as method.unused. Delete the method and its docblock; provider_output() and the static_site_importer_url_import_provider filter stay unchanged.
The new URL import caller passes a function-name string literal to static_site_importer_rest_execute_import_ability(), whose docblock declared the parameter callable-string. PHPStan cannot prove the literal names a defined function. Keep the runtime type as string (the body resolves it via call_user_func), widen the docblock to string, and add a scoped @phpstan-ignore-next-line at the single new call site. The two pre-existing callers are unchanged and now match the docblock.
…egression

Homeboy core 0.331.0 (PR #11553) validates the test.failures sidecar as a JSON array, but the wordpress extension wp-codebox adapter still emits an object sidecar. The same failure happens on main, so it is upstream, not introduced by this PR. Pin homeboy core to 0.330.0 (last known good) on both homeboy-action steps. The action SHA stays pinned. Remove the version pin once the extension ships an array-shaped sidecar.
Document the three CI fixes, the local verification commands, the manual wordpress-runtime smokes, and the rollback steps.
@faisalahammad

Copy link
Copy Markdown
Contributor Author

CI was red on three independent failures. Pushed 4 commits to fix all three so this PR can go green.

Fix 1: PHPStan method.unused (commit 6732e7b)
Static_Site_Importer_URL_Import_Runtime::resolve_provider_output() was dead code orphaned by the issue #837 refactor. import_url() already inlines the provider-output call. Deleted the method and its docblock. provider_output() and the static_site_importer_url_import_provider filter stay unchanged.

Fix 2: PHPStan argument.type (commit a8c0477)
The new URL import caller passes a function-name string literal to static_site_importer_rest_execute_import_ability(). Docblock declared the param callable-string but PHPStan could not prove the literal names a defined function. Kept the runtime type as string (the body resolves it via call_user_func), widened the docblock to string, and added a scoped @phpstan-ignore-next-line argument.type at the single new call site. The two pre-existing callers are unchanged and now match the docblock.

Fix 3: Homeboy test sidecar schema (commit f923fb8)
Not repo-introduced. Homeboy core 0.331.0 validates the test.failures sidecar as a JSON array, but the wordpress extension's wp-codebox adapter still emits an object sidecar. The same failure happens on main, so it is upstream. Pinned homeboy core to 0.330.0 (last known good) on both homeboy-action steps. The action SHA stays pinned. The pin can be removed once the extension ships an array-shaped sidecar.

Docs (commit 9042270)
TESTING_INSTRUCTIONS.md rewritten for this PR: the three fixes, local verification commands, the manual wordpress-runtime smokes, CI expectations, and rollback.

Local verification

  • php -l clean on both PHP files.
  • tests/smoke-url-import-runtime.php: 20 assertions pass.
  • tests/smoke-rest-url-import-helpers.php: 28 assertions pass.
  • npm run test:inventory and npm run test:runtime-package clean.
  • npm test: 46 pass, 1 pre-existing form-materializer-topology failure unrelated to this PR (reproduces on main).

The three new wordpress-runtime smokes (smoke-rest-url-import-via-ability.php, -continuation.php, -private-ip.php) are in the test manifest. They are not in homeboy-test-manifest.json so they only run on a live WP site.

Ready for CI.

- Suppress PHPStan argument.type at both inner call_user_func sites in static_site_importer_rest_execute_import_ability() and remove the stale outer ignore
- Re-align array double arrows in the continuation envelope, terminal envelope, and requires_ability_capable_target sub-array
- Drop the unused $input parameter from static_site_importer_rest_source_runtime() and update its 3 callers

Errors fixed:
- PHPStan argument.type at includes/rest.php:731 and includes/rest.php:743
- PHPCS WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned (15 warnings)
- PHPCS Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed (1 warning)

PHP 8.2 compatible. All CI checks passing. Refs Automattic#842
@faisalahammad

Copy link
Copy Markdown
Contributor Author

Fixed the failing Homeboy Lint check. All 18 findings were in includes/rest.php.

Finding Count Fix
PHPStan argument.type 2 Added ignore at both inner call_user_func sites in static_site_importer_rest_execute_import_ability(), removed the stale outer ignore
PHPCS DoubleArrowNotAligned 15 Re-aligned array arrows in the continuation envelope, terminal envelope, and requires_ability_capable_target sub-array
PHPCS UnusedFunctionParameter 1 Removed the unused $input parameter from static_site_importer_rest_source_runtime() and updated its 3 callers

Local checks:

  • php -l includes/rest.php clean
  • 6 standalone smokes pass (352 assertions)
  • npm run test:inventory clean
  • CodeRabbit clean on final diff

No behavior change. Formatting and static analysis fixes only. PHP 8.1+ compatible.

Resolves the includes/rest.php conflict introduced by main's
feat/840 plan-first import refactor, which unified URL import
handling inside the static-site-importer/import ability (no
separate import-url ability). Reconciles the branch onto main's
unified ability model:

- Includes/rest.php: keep main's source_runtime/create_import
  shape; remove the dead URL branch that called the deleted
  Static_Site_Importer_URL_Import_Runtime::website_artifact_from_url();
  route URL-only sources through static_site_importer_rest_route_url_import
  which dispatches them to the unified 'static-site-importer/import' ability
  with source.type=url; playground mode short-circuits to a
  requires_ability_capable_target envelope.
- tests/smoke-rest-url-import-{helpers,via-ability,continuation,private-ip}.php
  rewritten to drive the unified ability; assertions updated to match the
  new envelope shape.
- tests/smoke-importer-block.php: URL-only REST assertions updated to
  match the unified ability and new envelope.

Refs Automattic#837, Automattic#842.
faisalahammad added a commit to faisalahammad/static-site-importer that referenced this pull request Aug 6, 2026
…rough-ability

Rebase onto Automattic's actual main to resolve PR Automattic#842's merge conflict.
Re-resolved tests/smoke-importer-block.php playground URL test on the
rest.php URL router that short-circuits to requires_ability_capable_target
envelope (URL imports now route through the unified static-site-importer/import
ability; the playground preview path returns a structured
ability_capable_target_required envelope instead of a real blueprint).

Co-Authored-By: Claude <noreply@anthropic.com>
…rough-ability

Rebase onto Automattic's actual main to resolve PR Automattic#842's merge conflict.
Re-resolved tests/smoke-importer-block.php playground URL test on the
rest.php URL router that short-circuits to requires_ability_capable_target
envelope (URL imports now route through the unified static-site-importer/import
ability; the playground preview path returns a structured
ability_capable_target_required envelope instead of a real blueprint).
The file is not part of the canonical documentation set and was a
scratch artifact from the CI fix work.
@faisalahammad
faisalahammad force-pushed the fix/837-rest-url-imports-route-through-ability branch from 47ebd65 to 29c0e6e Compare August 6, 2026 23:48
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.

Route REST URL imports through the canonical ability contract

1 participant