fix(2meet-data-optimizer): serve native meta in shadow_read and compare flat values

- In shadow_read, TMDO_Hook_Bus::intercept_get() returned the flat value.
  update_metadata() reads the old value through that filter after the Hook
  Bus has upserted the new one, so WP saw old === new and never wrote native
  meta: every update in shadow_read was lost on demotion (dev36 2026-09-26).
  shadow_read now returns $check (native) and compares flat on a sample of
  reads (filter tmdo_shadow_compare_sample_rate, default 0.1). aeav_only is
  unchanged; the post query router still routes in shadow_read.
- Live suite shadow_write: xfail markers removed, HivePress listing case
  added (new int key hp_rating_count); fixtures gain post() and a
  post_type-scoped field()/flat().
- Verify: live shadow_write + serialized 8/8 PASS (old code: 4 FAIL);
  unit 685 OK, integration 484 OK, phpcs (phpcs.xml) 0, stan OK
- PR: PR-056
This commit is contained in:
2026-09-26 18:56:45 +08:00
parent 08f9e313e0
commit b84252d787
5 changed files with 134 additions and 32 deletions
+48 -8
View File
@@ -89,6 +89,30 @@ final class TMDO_Live_Fixtures {
return (int) $t['term_id'];
}
/**
* Create a throwaway post.
*
* @param string $post_type Post type.
*/
public static function post( string $post_type ): int {
if ( ! post_type_exists( $post_type ) ) {
throw new TMDO_Live_Skip( "post type {$post_type} not registered on this site" );
}
$id = wp_insert_post(
array(
'post_type' => $post_type,
'post_title' => 'tmdo-live-' . wp_generate_password( 6, false, false ),
'post_status' => 'draft',
),
true
);
if ( is_wp_error( $id ) ) {
throw new TMDO_Live_Failure( 'fixture post: ' . $id->get_error_message() );
}
self::$created[] = array( 'post', (int) $id );
return (int) $id;
}
/**
* Native meta values for a key, read with SQL (no filters, no cache).
*
@@ -109,14 +133,15 @@ final class TMDO_Live_Fixtures {
/**
* Raw flat-table value for a key; 'NO-ROW' when the entity has no row.
*
* @param string $type Entity type.
* @param int $id Entity ID.
* @param string $key Meta key.
* @param string $type Entity type.
* @param int $id Entity ID.
* @param string $key Meta key.
* @param string $post_type For posts: the post type whose group owns the key.
* @return string|null
*/
public static function flat( string $type, int $id, string $key ) {
public static function flat( string $type, int $id, string $key, string $post_type = '' ) {
global $wpdb;
$field = self::field( $type, $key );
$field = self::field( $type, $key, $post_type );
$table = TMDO_Schema_Manager::get_table_name( $type, $field['group'] );
$col = TMDO_Schema_Manager::sanitize_column_name( $key );
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- table/column come from the registry.
@@ -127,11 +152,24 @@ final class TMDO_Live_Fixtures {
/**
* Registry field for a key, or skip the test when the site does not register it.
*
* @param string $type Entity type.
* @param string $key Meta key.
* A key can live in several post groups (hp_rating in listing and vendor
* groups); pass the post type to pick the group scoped to it.
*
* @param string $type Entity type.
* @param string $key Meta key.
* @param string $post_type For posts: the post type whose group owns the key.
*/
public static function field( string $type, string $key ): array {
public static function field( string $type, string $key, string $post_type = '' ): array {
$field = TMDO_Entity_Registry::get_field( $type, $key );
if ( '' !== $post_type ) {
foreach ( TMDO_Entity_Registry::get_groups_for_type( $type ) as $group ) {
if ( in_array( $post_type, TMDO_Entity_Registry::get_group_post_types( $type, $group ), true )
&& in_array( $key, TMDO_Entity_Registry::get_group_keys( $type, $group ), true ) ) {
$field = array( 'group' => $group ) + (array) $field;
break;
}
}
}
if ( ! $field ) {
throw new TMDO_Live_Skip( "{$type} key {$key} is not registered on this site" );
}
@@ -151,6 +189,8 @@ final class TMDO_Live_Fixtures {
wp_delete_user( $c[1] );
} elseif ( 'term' === $c[0] ) {
wp_delete_term( $c[1], $c[2] );
} elseif ( 'post' === $c[0] ) {
wp_delete_post( $c[1], true );
}
}
self::$created = array();