@@ -115,78 +115,69 @@ cat > "$WP_DIR/native-verify-extension.php" <<'EOF'
115115<?php
116116require_once '/var/www/src/wp-content/plugins/sqlite-database-integration/wp-includes/database/load.php';
117117
118+ function wp_sqlite_native_parser_verification_fail( string $message ): void {
119+ fwrite( STDERR, $message . "\n" );
120+ exit( 1 );
121+ }
122+
123+ function wp_sqlite_assert_native_parser_delegate( WP_MySQL_Parser $parser, string $message ): void {
124+ $parser_reflection = new ReflectionObject( $parser );
125+ if ( ! $parser_reflection->hasProperty( 'native' ) ) {
126+ wp_sqlite_native_parser_verification_fail( $message );
127+ }
128+
129+ $native_property = $parser_reflection->getProperty( 'native' );
130+ $native_property->setAccessible( true );
131+ if ( ! ( $native_property->getValue( $parser ) instanceof WP_MySQL_Native_Parser ) ) {
132+ wp_sqlite_native_parser_verification_fail( $message );
133+ }
134+ }
135+
118136$lexer = new WP_MySQL_Lexer( 'SELECT 1' );
119137if ( ! ( $lexer instanceof WP_MySQL_Native_Lexer ) ) {
120- fwrite( STDERR, "Native lexer is not available in the WordPress PHP test container.\n" );
121- exit( 1 );
138+ wp_sqlite_native_parser_verification_fail( 'Native lexer is not available in the WordPress PHP test container.' );
122139}
123140
124141$tokens = $lexer->native_token_stream();
125142$rules = include '/var/www/src/wp-content/plugins/sqlite-database-integration/wp-includes/database/mysql/mysql-grammar.php';
126143$grammar = new WP_Parser_Grammar( $rules );
127144$parser = new WP_MySQL_Parser( $grammar, $tokens );
128- $parser_reflection = new ReflectionObject( $parser );
129- if ( ! $parser_reflection->hasProperty( 'native' ) ) {
130- fwrite( STDERR, "WordPress PHP test container did not select the native parser delegate.\n" );
131- exit( 1 );
132- }
133- $native_property = $parser_reflection->getProperty( 'native' );
134- $native_property->setAccessible( true );
135- if ( ! ( $native_property->getValue( $parser ) instanceof WP_MySQL_Native_Parser ) ) {
136- fwrite( STDERR, "WordPress PHP test container did not select the native parser delegate.\n" );
137- exit( 1 );
138- }
145+ wp_sqlite_assert_native_parser_delegate( $parser, 'WordPress PHP test container did not select the native parser delegate.' );
139146
140147$parser_ast = $parser->parse();
141148if ( ! ( $parser_ast instanceof WP_MySQL_Native_Parser_Node ) ) {
142- fwrite( STDERR, "Native parser did not produce a native-backed AST in the WordPress PHP test container.\n" );
143- exit( 1 );
149+ wp_sqlite_native_parser_verification_fail( 'Native parser did not produce a native-backed AST in the WordPress PHP test container.' );
144150}
145151
146152$driver = new WP_PDO_MySQL_On_SQLite( 'mysql-on-sqlite:path=:memory:;dbname=wp;' );
147153$parser = $driver->create_parser( 'SELECT 1' );
148- $parser_reflection = new ReflectionObject( $parser );
149- if ( ! $parser_reflection->hasProperty( 'native' ) ) {
150- fwrite( STDERR, "WordPress PHP test container SQLite driver did not create a native parser delegate.\n" );
151- exit( 1 );
152- }
153- $native_property = $parser_reflection->getProperty( 'native' );
154- $native_property->setAccessible( true );
155- if ( ! ( $native_property->getValue( $parser ) instanceof WP_MySQL_Native_Parser ) ) {
156- fwrite( STDERR, "WordPress PHP test container SQLite driver did not create a native parser delegate.\n" );
157- exit( 1 );
158- }
154+ wp_sqlite_assert_native_parser_delegate( $parser, 'WordPress PHP test container SQLite driver did not create a native parser delegate.' );
159155$parser->next_query();
160156$ast = $parser->get_query_ast();
161157
162158if ( ! ( $ast instanceof WP_MySQL_Native_Parser_Node ) ) {
163- fwrite( STDERR, "WordPress PHP test container did not select the native-backed AST.\n" );
164- exit( 1 );
159+ wp_sqlite_native_parser_verification_fail( 'WordPress PHP test container did not select the native-backed AST.' );
165160}
166161
167162$reflection = new ReflectionObject( $ast );
168163if ( $reflection->hasProperty( 'native_ast' ) || $reflection->hasProperty( 'native_node_index' ) ) {
169- fwrite( STDERR, "Native wrapper still stores Rust AST handle properties.\n" );
170- exit( 1 );
164+ wp_sqlite_native_parser_verification_fail( 'Native wrapper still stores Rust AST handle properties.' );
171165}
172166
173167$first = $ast->get_first_child_node();
174168if ( ! ( $first instanceof WP_MySQL_Native_Parser_Node ) ) {
175- fwrite( STDERR, "Native wrapper did not return a native-backed child node.\n" );
176- exit( 1 );
169+ wp_sqlite_native_parser_verification_fail( 'Native wrapper did not return a native-backed child node.' );
177170}
178171
179172if ( $first !== $ast->get_first_child_node() ) {
180- fwrite( STDERR, "Native wrapper identity is not stable across reads.\n" );
181- exit( 1 );
173+ wp_sqlite_native_parser_verification_fail( 'Native wrapper identity is not stable across reads.' );
182174}
183175
184176$synthetic = new WP_Parser_Node( 0, 'synthetic' );
185177$first->append_child( $synthetic );
186178$same_first = $ast->get_first_child_node();
187179if ( $same_first !== $first || ! in_array( $synthetic, $same_first->get_children(), true ) ) {
188- fwrite( STDERR, "Materialized native wrapper was lost from the parent cache.\n" );
189- exit( 1 );
180+ wp_sqlite_native_parser_verification_fail( 'Materialized native wrapper was lost from the parent cache.' );
190181}
191182EOF
192183
@@ -197,7 +188,7 @@ const file = process.argv[2];
197188const marker = "require_once ABSPATH . 'wp-settings.php';";
198189const guard = [
199190 '/*',
200- ' * Native parser CI guard. This file is generated by the SQLite integration workflow.',
191+ ' * Native parser extension guard. This file is generated by the SQLite integration workflow.',
201192 ' */',
202193 "require_once dirname( __DIR__, 3 ) . '/native-verify-extension.php';",
203194].join( '\n' );
0 commit comments