From edf9e6bc93a113a5644af7920f110124fb4b8866 Mon Sep 17 00:00:00 2001 From: wpdev Date: Sun, 27 Sep 2026 10:07:02 +0800 Subject: [PATCH] fix(2meet-data-optimizer): doctor ignores drift records of groups no longer registered MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - A group's last drift record outlived its registration (wc_product and user hot on dev36, any add-on deactivated): doctor counted it and could warn forever with a --fix hint that cannot reach it. Only records of backfillable groups are read; the router and clean_since already go by the registry. - Verify: DoctorTest (RED before); dev36 doctor user 9 → 8 groups - PR: PR-089a --- cli/class-tmdo-cli.php | 3 ++- tests/integration/DoctorTest.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/cli/class-tmdo-cli.php b/cli/class-tmdo-cli.php index 48f044d..d87c79c 100644 --- a/cli/class-tmdo-cli.php +++ b/cli/class-tmdo-cli.php @@ -148,7 +148,8 @@ class TMDO_CLI { WP_CLI::log( 'Drift (last `wp tmdo drift-check` or daily sample):' ); foreach ( TMDO_Entity_Registry::VALID_ENTITY_TYPES as $entity_type ) { $groups = TMDO_Entity_Migration_Engine::backfillable_groups( $entity_type ); - $last = $status[ $entity_type ] ?? array(); + // Records of groups no longer registered can be neither re-checked nor fixed. + $last = array_intersect_key( (array) ( $status[ $entity_type ] ?? array() ), array_flip( $groups ) ); if ( empty( $groups ) || ( empty( $last ) && ! TMDO_Mode_Manager::writes_to_flat( $entity_type ) ) ) { continue; } diff --git a/tests/integration/DoctorTest.php b/tests/integration/DoctorTest.php index 14ef561..3a08d5f 100644 --- a/tests/integration/DoctorTest.php +++ b/tests/integration/DoctorTest.php @@ -98,6 +98,34 @@ class DoctorTest extends TestCase { $this->assertStringContainsString( 'wp tmdo drift-check user --fix', $this->cli_output() ); } + public function test_ignores_the_record_of_a_group_no_longer_registered(): void { + $GLOBALS['_wp_options']['wpdo_bridge_modes'] = array( 'user' => 'dual_write' ); + $GLOBALS['_wp_options'][ TMDO_Drift_Check::OPTION ] = array( + 'user' => array( + 'dt_have' => array( + 'miss' => 0, + 'diff' => 0, + 'extra' => 0, + 'sample' => 0, + 'checked_at' => '2026-09-27 00:00:00', + ), + 'dt_gone' => array( + 'miss' => 3, + 'diff' => 0, + 'extra' => 0, + 'sample' => 0, + 'checked_at' => '2026-09-20 00:00:00', + ), + ), + ); + TMDO_Mode_Manager::reset_cache(); + + TMDO_CLI::report_guard_and_drift(); + + $this->assertStringContainsString( '[OK] user: 1 group(s) clean (oldest check 2026-09-27 00:00:00 UTC)', $this->cli_output() ); + $this->assertStringNotContainsString( 'dt_gone', $this->cli_output() ); + } + public function test_reports_an_entity_never_checked(): void { $GLOBALS['_wp_options']['wpdo_bridge_modes'] = array( 'user' => 'dual_write' ); TMDO_Mode_Manager::reset_cache();