test(2meet-data-optimizer): add live test runner and failing shadow_read write suite
- Add tests/live: a `wp eval-file` runner (PASS/FAIL/XFAIL/XPASS/SKIP) with fixtures that override entity modes in process (pre_option) and read native / flat values with plain SQL, so WP core meta flows run for real - shadow_write suite reproduces the dev36 finding: in shadow_read, update_*_meta returns false and native meta is never written (3 XFAIL marked for PR-056); the dual_write control passes - Move the dev36 integration harness into tests/live/tools; outputs go to cwd / $TMDO_LIVE_OUT, site URL and path are env-configurable - Verify: wp --path=<dev36> eval-file tests/live/run.php shadow_write → 1 passed, 3 xfail; unit 658 OK, integration 480 OK, phpcs (phpcs.xml) 0, stan OK - PR: PR-052
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* Suite: writes made in shadow_read must reach native meta.
|
||||
*
|
||||
* Bug (dev36, 2026-09-26): in shadow_read, update_metadata() fetches the old
|
||||
* value through get_metadata_raw(); the Hook Bus has already upserted the new
|
||||
* value and serves it from the flat table, so WP sees old === new and returns
|
||||
* false without writing native meta. Demoting afterwards exposes stale data.
|
||||
*
|
||||
* @package WP_Data_Optimizer
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
TMDO_Live::test(
|
||||
'dual_write: user first_name update reaches native and flat (control)',
|
||||
static function () {
|
||||
TMDO_Live_Fixtures::field( 'user', 'first_name' );
|
||||
TMDO_Live_Fixtures::use_modes( array( 'user' => 'dual_write' ) );
|
||||
$uid = TMDO_Live_Fixtures::user();
|
||||
update_user_meta( $uid, 'first_name', 'Before' );
|
||||
|
||||
$ret = update_user_meta( $uid, 'first_name', 'After' );
|
||||
|
||||
tmdo_live_assert_true( false !== $ret, 'update_user_meta returned false' );
|
||||
tmdo_live_assert_same( array( 'After' ), TMDO_Live_Fixtures::native( 'user', $uid, 'first_name' ), 'native first_name' );
|
||||
tmdo_live_assert_same( 'After', TMDO_Live_Fixtures::flat( 'user', $uid, 'first_name' ), 'flat first_name' );
|
||||
}
|
||||
);
|
||||
|
||||
TMDO_Live::test(
|
||||
'shadow_read: user first_name update reaches native',
|
||||
static function () {
|
||||
TMDO_Live_Fixtures::field( 'user', 'first_name' );
|
||||
TMDO_Live_Fixtures::use_modes( array( 'user' => 'dual_write' ) );
|
||||
$uid = TMDO_Live_Fixtures::user();
|
||||
update_user_meta( $uid, 'first_name', 'Before' );
|
||||
TMDO_Live_Fixtures::use_modes( array( 'user' => 'shadow_read' ) );
|
||||
|
||||
$ret = update_user_meta( $uid, 'first_name', 'After' );
|
||||
|
||||
tmdo_live_assert_true( false !== $ret, 'update_user_meta returned false' );
|
||||
tmdo_live_assert_same( array( 'After' ), TMDO_Live_Fixtures::native( 'user', $uid, 'first_name' ), 'native first_name' );
|
||||
},
|
||||
array( 'xfail' => 'PR-056' )
|
||||
);
|
||||
|
||||
TMDO_Live::test(
|
||||
'shadow_read → dual_write: value written in shadow_read survives demotion',
|
||||
static function () {
|
||||
TMDO_Live_Fixtures::field( 'user', 'last_name' );
|
||||
TMDO_Live_Fixtures::use_modes( array( 'user' => 'dual_write' ) );
|
||||
$uid = TMDO_Live_Fixtures::user();
|
||||
update_user_meta( $uid, 'last_name', 'Before' );
|
||||
TMDO_Live_Fixtures::use_modes( array( 'user' => 'shadow_read' ) );
|
||||
update_user_meta( $uid, 'last_name', 'After' );
|
||||
|
||||
TMDO_Live_Fixtures::use_modes( array( 'user' => 'dual_write' ) );
|
||||
wp_cache_delete( $uid, 'user_meta' );
|
||||
|
||||
tmdo_live_assert_same( 'After', get_user_meta( $uid, 'last_name', true ), 'last_name after demotion' );
|
||||
},
|
||||
array( 'xfail' => 'PR-056' )
|
||||
);
|
||||
|
||||
TMDO_Live::test(
|
||||
'shadow_read: HivePress term hp_icon update reaches native',
|
||||
static function () {
|
||||
TMDO_Live_Fixtures::field( 'term', 'hp_icon' );
|
||||
TMDO_Live_Fixtures::use_modes( array( 'term' => 'dual_write' ) );
|
||||
$tid = TMDO_Live_Fixtures::term( 'hp_listing_category' );
|
||||
update_term_meta( $tid, 'hp_icon', 'star' );
|
||||
TMDO_Live_Fixtures::use_modes( array( 'term' => 'shadow_read' ) );
|
||||
|
||||
$ret = update_term_meta( $tid, 'hp_icon', 'heart' );
|
||||
|
||||
tmdo_live_assert_true( false !== $ret, 'update_term_meta returned false' );
|
||||
tmdo_live_assert_same( array( 'heart' ), TMDO_Live_Fixtures::native( 'term', $tid, 'hp_icon' ), 'native hp_icon' );
|
||||
},
|
||||
array( 'xfail' => 'PR-056' )
|
||||
);
|
||||
Reference in New Issue
Block a user