Skip to content

test(cli): add integration coverage for wp liveblog fix-archive#934

Open
faisalahammad wants to merge 1 commit into
Automattic:developfrom
faisalahammad:fix/789-wp-cli-fix-archive-tests
Open

test(cli): add integration coverage for wp liveblog fix-archive#934
faisalahammad wants to merge 1 commit into
Automattic:developfrom
faisalahammad:fix/789-wp-cli-fix-archive-tests

Conversation

@faisalahammad

Copy link
Copy Markdown

Summary

fix-archive had zero automated test coverage. Adds it, in the existing legacy style.
Refs #789

Investigation on #789

The issue asked for two things: drop the obsolete readme_for_github command, and refactor fix-archive into a namespaced command + service class with DI and behat tests.

  • readme_for_github is already gone — removed on develop in 5becaad (PR Restructure documentation around audience #872), the same change that dropped readme.txt in favor of a WordPress.org-compatible README.md. Nothing to do there.
  • The DDD refactor the issue describes already exists, but only on the 2.x branch (commit e760e10: FixArchiveCommand + ArchiveRepairService under src/php/, with DI and unit tests). develop is still the flat, legacy static-class style, and per project convention 2.x patterns are backported by hand when needed, not ported wholesale. Not doing that here.
  • Checked whether the corruption fix-archive repairs (broken liveblog_replaces commentmeta + duplicated content after editing an entry twice) is still reachable. PR users can edit more than 1x now and reloaded page will show #297 already closed the supported REST/AJAX path by canonicalizing entry_id through replaces before it reaches the client. But validate_entry_belongs_to_post() still doesn't reject an entry_id that is itself an already-replaced ghost comment, so the same corruption stays reachable in principle (stale cached page, direct API caller, future regression). Recommend keeping fix-archive, not deprecating it.

So the only real gap left under this issue is missing test coverage, which this PR adds.

Changes

tests/Integration/wp-cli-stub.php (new)

Minimal WP_CLI/WP_CLI_Command stub (log, success, colorize, add_command), guarded by class_exists(). Needed because the real WP-CLI runtime isn't loaded under PHPUnit, and class-wpcom-liveblog-wp-cli.php calls WP_CLI::add_command() at file-load time plus WP_CLI::log()/::success()/::colorize() inside fix_archive().

tests/Integration/WpCliFixArchiveTest.php (new)

Extends the same Yoast\WPTestUtils\WPIntegration\TestCase base as EntryQueryTest.php. Covers:

  • dry run (--dryrun) does not modify liveblog_replaces meta
  • actual run corrects a mis-pointed liveblog_replaces value
  • no liveblogs at all completes cleanly
  • a liveblog with no edited entries completes cleanly

Testing

Test 1: PHPCS

  1. composer cs
    Result: clean on both new files

Test 2: Lint

  1. composer lint
    Result: no syntax errors

Test 3: CodeRabbit

  1. coderabbit review --agent
    Result: 0 findings

Test 4: composer test:integration
Couldn't get a clean local wp-env run to verify this locally — repeated transient network failures during the WordPress core git clone / Alpine package install in the wp-env Docker build on this machine, unrelated to this change. Would appreciate a CI run or a maintainer re-run locally to confirm the four new test cases pass.

- add minimal WP_CLI stub for integration tests (log, success,
  colorize, add_command)
- add WpCliFixArchiveTest covering dry-run, actual repair, no
  liveblogs found, and no edited entries

fix-archive had zero automated test coverage. Issue Automattic#789 also asked to
drop readme_for_github (already removed in 5becaad) and to refactor
fix-archive with DI and a service class. That refactor already exists
on 2.x (commit e760e10) but develop keeps the legacy static class
style, so it is not ported here. Checked whether the corruption
fix-archive repairs (broken liveblog_replaces meta after editing an
entry twice) is still reachable: the supported REST/AJAX edit flow
closed that path via PR Automattic#297, but validate_entry_belongs_to_post()
still does not reject an entry_id that is itself an already-replaced
comment, so the corruption remains possible in principle. fix-archive
stays as a repair tool rather than being deprecated.

Refs Automattic#789
@faisalahammad faisalahammad requested a review from a team as a code owner July 4, 2026 00:46
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.

1 participant