fix(2meet-data-optimizer): stop false alarms in doctor, term-comment-diagnose and bridge-status
- doctor: entity flat tables come from the registry (TMDO_CLI::check_entity_tables()) instead of a hard-coded user list naming the never-registered sso group, which failed doctor on every site; it also reports Promotion Guard violations and the recorded drift status per entity (report_guard_and_drift()). - term-comment-diagnose: filter status comes from each filter's is_enabled() (the garbage filter and misc bucket default to off but were shown enabled); a filter whose add-on is not active shows "not installed". - bridge-status: flat_rows counts rows holding a value (wp_core keeps an all-NULL row per post: 15306% on dev36) and eav_ids of a post-type group counts only its post types. - Tests: the WP_CLI stubs record their output in $GLOBALS['_wp_cli_output']. - Verify: DoctorTest, CliFilterStatusTest, CliBridgeStatusTest (RED before); dev36 doctor exit 1 → 0, wp_core 15306% → 100%. - PR: PR-076
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* `wp tmdo doctor` false alarms (2.2 PR-076).
|
||||
*
|
||||
* The user flat tables were a hard-coded list including wpdo_user_sso, a group
|
||||
* never registered: doctor reported it MISSING and failed on every site. The
|
||||
* tables now come from the registry; doctor also reports Promotion Guard
|
||||
* violations and the recorded drift status.
|
||||
*/
|
||||
class DoctorTest extends TestCase {
|
||||
|
||||
private const HAVE = 'wp_itest_wpdo_user_dt_have';
|
||||
private const CORE = array( 'wp_itest_wpdo_migration_status', 'wp_itest_wpdo_user_points_ledger' );
|
||||
|
||||
public static function setUpBeforeClass(): void {
|
||||
foreach ( array(
|
||||
'includes/adapters/interface-entity-adapter.php',
|
||||
'includes/adapters/class-tmdo-adapter-user.php',
|
||||
'includes/engine/class-tmdo-promotion-guard.php',
|
||||
'cli/class-tmdo-cli.php',
|
||||
) as $file ) {
|
||||
require_once WPDO_PLUGIN_DIR . $file;
|
||||
}
|
||||
}
|
||||
|
||||
protected function setUp(): void {
|
||||
global $wpdb;
|
||||
self::drop();
|
||||
foreach ( array_merge( array( self::HAVE ), self::CORE ) as $table ) {
|
||||
$wpdb->query( "CREATE TABLE `{$table}` ( id BIGINT NOT NULL AUTO_INCREMENT, user_id BIGINT NOT NULL DEFAULT 0, PRIMARY KEY (id) ) ENGINE=InnoDB" );
|
||||
}
|
||||
|
||||
$GLOBALS['_wp_options'] = array();
|
||||
$GLOBALS['_wp_cli_output'] = array();
|
||||
TMDO_Mode_Manager::reset_cache();
|
||||
WPDO_Entity_Registry::init();
|
||||
WPDO_Entity_Registry::register_adapter( 'user', new WPDO_Adapter_User() );
|
||||
WPDO_Entity_Registry::register_group( 'user', 'dt_have', array( array( 'key' => 'dt_a', 'type' => 'text' ) ) );
|
||||
WPDO_Schema_Manager::flush_table_exists_cache();
|
||||
}
|
||||
|
||||
protected function tearDown(): void {
|
||||
self::drop();
|
||||
WPDO_Entity_Registry::init();
|
||||
TMDO_Mode_Manager::reset_cache();
|
||||
}
|
||||
|
||||
private static function drop(): void {
|
||||
global $wpdb;
|
||||
foreach ( array_merge( array( self::HAVE ), self::CORE ) as $table ) {
|
||||
$wpdb->query( "DROP TABLE IF EXISTS `{$table}`" );
|
||||
}
|
||||
}
|
||||
|
||||
private function cli_output(): string {
|
||||
return implode( "\n", $GLOBALS['_wp_cli_output'] ?? array() );
|
||||
}
|
||||
|
||||
public function test_entity_tables_come_from_the_registry(): void {
|
||||
$ok = TMDO_CLI::check_entity_tables();
|
||||
|
||||
$this->assertTrue( $ok, $this->cli_output() );
|
||||
$this->assertStringContainsString( '[OK] ' . self::HAVE, $this->cli_output() );
|
||||
$this->assertStringNotContainsString( 'wpdo_user_sso', $this->cli_output() );
|
||||
}
|
||||
|
||||
public function test_a_registered_group_without_its_table_is_reported(): void {
|
||||
WPDO_Entity_Registry::register_group( 'user', 'dt_missing', array( array( 'key' => 'dt_b', 'type' => 'text' ) ) );
|
||||
|
||||
$ok = TMDO_CLI::check_entity_tables();
|
||||
|
||||
$this->assertFalse( $ok );
|
||||
$this->assertStringContainsString( '[MISSING] wp_itest_wpdo_user_dt_missing', $this->cli_output() );
|
||||
}
|
||||
|
||||
public function test_reports_drifting_groups(): 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' => 1,
|
||||
'diff' => 2,
|
||||
'extra' => 0,
|
||||
'sample' => 0,
|
||||
'checked_at' => '2026-09-27 00:00:00',
|
||||
),
|
||||
),
|
||||
);
|
||||
TMDO_Mode_Manager::reset_cache();
|
||||
|
||||
TMDO_CLI::report_guard_and_drift();
|
||||
|
||||
$this->assertStringContainsString( 'dt_have miss=1 diff=2 extra=0', $this->cli_output() );
|
||||
$this->assertStringContainsString( 'wp tmdo drift-check user --fix', $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();
|
||||
|
||||
TMDO_CLI::report_guard_and_drift();
|
||||
|
||||
$this->assertStringContainsString( 'user: never checked', $this->cli_output() );
|
||||
$this->assertStringContainsString( 'Promotion Guard: no violation', $this->cli_output() );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user