Skip to content

Commit 2d93be2

Browse files
committed
Update native parser CI smoke checks
1 parent d349802 commit 2d93be2

2 files changed

Lines changed: 48 additions & 8 deletions

File tree

.github/workflows/mysql-parser-extension-tests.yml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,31 @@ jobs:
144144
$parser = $driver->create_parser( "SELECT 1" );
145145
$parser->next_query();
146146
$ast = $parser->get_query_ast();
147-
$property = ( new ReflectionClass( $ast ) )->getProperty( "native_ast" );
148-
$property->setAccessible( true );
149-
$native_ast = $property->getValue( $ast );
150-
if ( ! is_object( $native_ast ) || "WP_MySQL_Native_Ast" !== get_class( $native_ast ) ) {
147+
if ( ! ( $ast instanceof WP_MySQL_Native_Parser_Node ) ) {
151148
fwrite( STDERR, "SQLite driver did not return a native-backed AST.\n" );
152149
exit( 1 );
153150
}
151+
$reflection = new ReflectionObject( $ast );
152+
if ( $reflection->hasProperty( "native_ast" ) || $reflection->hasProperty( "native_node_index" ) ) {
153+
fwrite( STDERR, "Native wrapper still stores Rust AST handle properties.\n" );
154+
exit( 1 );
155+
}
156+
$first = $ast->get_first_child_node();
157+
if ( ! ( $first instanceof WP_MySQL_Native_Parser_Node ) ) {
158+
fwrite( STDERR, "Native wrapper did not return a native-backed child node.\n" );
159+
exit( 1 );
160+
}
161+
if ( $first !== $ast->get_first_child_node() ) {
162+
fwrite( STDERR, "Native wrapper identity is not stable across reads.\n" );
163+
exit( 1 );
164+
}
165+
$synthetic = new WP_Parser_Node( 0, "synthetic" );
166+
$first->append_child( $synthetic );
167+
$same_first = $ast->get_first_child_node();
168+
if ( $same_first !== $first || ! in_array( $synthetic, $same_first->get_children(), true ) ) {
169+
fwrite( STDERR, "Materialized native wrapper was lost from the parent cache.\n" );
170+
exit( 1 );
171+
}
154172
'
155173
156174
- name: Run PHPUnit tests with SQLite driver using parser extension

.github/workflows/wp-tests-phpunit-native-extension-setup.sh

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,36 @@ $driver = new WP_PDO_MySQL_On_SQLite( 'mysql-on-sqlite:path=:memory:;dbname=wp;'
125125
$parser = $driver->create_parser( 'SELECT 1' );
126126
$parser->next_query();
127127
$ast = $parser->get_query_ast();
128-
$property = ( new ReflectionClass( $ast ) )->getProperty( 'native_ast' );
129-
$property->setAccessible( true );
130-
$native_ast = $property->getValue( $ast );
131128
132-
if ( ! is_object( $native_ast ) || 'WP_MySQL_Native_Ast' !== get_class( $native_ast ) ) {
129+
if ( ! ( $ast instanceof WP_MySQL_Native_Parser_Node ) ) {
133130
fwrite( STDERR, "WordPress PHP test container did not select the native-backed AST.\n" );
134131
exit( 1 );
135132
}
133+
134+
$reflection = new ReflectionObject( $ast );
135+
if ( $reflection->hasProperty( 'native_ast' ) || $reflection->hasProperty( 'native_node_index' ) ) {
136+
fwrite( STDERR, "Native wrapper still stores Rust AST handle properties.\n" );
137+
exit( 1 );
138+
}
139+
140+
$first = $ast->get_first_child_node();
141+
if ( ! ( $first instanceof WP_MySQL_Native_Parser_Node ) ) {
142+
fwrite( STDERR, "Native wrapper did not return a native-backed child node.\n" );
143+
exit( 1 );
144+
}
145+
146+
if ( $first !== $ast->get_first_child_node() ) {
147+
fwrite( STDERR, "Native wrapper identity is not stable across reads.\n" );
148+
exit( 1 );
149+
}
150+
151+
$synthetic = new WP_Parser_Node( 0, 'synthetic' );
152+
$first->append_child( $synthetic );
153+
$same_first = $ast->get_first_child_node();
154+
if ( $same_first !== $first || ! in_array( $synthetic, $same_first->get_children(), true ) ) {
155+
fwrite( STDERR, "Materialized native wrapper was lost from the parent cache.\n" );
156+
exit( 1 );
157+
}
136158
EOF
137159

138160
node tools/local-env/scripts/docker.js run --rm php php -m | grep -qx 'wp_mysql_parser'

0 commit comments

Comments
 (0)