Skip to content

Commit e37ef04

Browse files
authored
test: align Playground coverage with pinned packages (Automattic#869)
AI assistance: OpenAI GPT-5.6 Sol via OpenCode diagnosed the post-Automattic#860 test regressions, updated assertions, and ran the full manifest. Chris Huber remains responsible for every line.
1 parent 699c5bd commit e37ef04

3 files changed

Lines changed: 46 additions & 7 deletions

File tree

tests/smoke-import-disposition.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,27 @@ function wp_json_encode( $data, int $options = 0, int $depth = 512 ) {
8686
}
8787
}
8888

89+
if ( ! class_exists( 'WP_Error' ) ) {
90+
class WP_Error {}
91+
}
92+
93+
if ( ! function_exists( 'is_wp_error' ) ) {
94+
function is_wp_error( $value ): bool {
95+
return $value instanceof WP_Error;
96+
}
97+
}
98+
8999
require_once STATIC_SITE_IMPORTER_PATH . 'includes/rest.php';
90100

101+
add_filter(
102+
'static_site_importer_playground_package',
103+
static fn() => array(
104+
'url' => 'https://github.com/Automattic/static-site-importer/releases/download/v1.2.3/static-site-importer.zip',
105+
'version' => 'v1.2.3',
106+
'sha256' => str_repeat( 'a', 64 ),
107+
)
108+
);
109+
91110
$assert(
92111
function_exists( 'static_site_importer_import_website_artifact_with_disposition' ),
93112
'function-exists',

tests/smoke-importer-block.php

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,14 @@ static function (): bool {
660660

661661
Static_Site_Importer_Theme_Generator::$last_artifact = array();
662662
Static_Site_Importer_Theme_Generator::$last_args = array();
663+
add_filter(
664+
'static_site_importer_playground_package',
665+
static fn() => array(
666+
'url' => 'https://github.com/Automattic/static-site-importer/releases/download/v1.2.3/static-site-importer.zip',
667+
'version' => 'v1.2.3',
668+
'sha256' => str_repeat( 'a', 64 ),
669+
)
670+
);
663671
$playground_response = static_site_importer_rest_create_import(
664672
new WP_REST_Request(
665673
array(
@@ -681,8 +689,14 @@ static function (): bool {
681689
$playground_blueprint = json_decode( $playground_blueprint_json, true );
682690
$assert( is_array( $playground_blueprint ), 'rest-playground-open-blueprint-decodes' );
683691
$playground_blueprint_code = wp_json_encode( $playground_blueprint );
684-
$playground_plugin_step = $playground_blueprint['steps'][1] ?? array();
685-
$assert( 'https://github.com/Automattic/static-site-importer/releases/latest/download/static-site-importer.zip' === ( $playground_plugin_step['pluginData']['url'] ?? '' ), 'rest-playground-open-blueprint-installs-release-zip' );
692+
$playground_download_steps = array_values( array_filter( $playground_blueprint['steps'] ?? array(), static fn( array $step ): bool => 'writeFile' === ( $step['step'] ?? '' ) ) );
693+
$playground_plugin_steps = array_values( array_filter( $playground_blueprint['steps'] ?? array(), static fn( array $step ): bool => 'installPlugin' === ( $step['step'] ?? '' ) ) );
694+
$playground_download_step = $playground_download_steps[0] ?? array();
695+
$playground_plugin_step = $playground_plugin_steps[0] ?? array();
696+
$assert( 'https://github.com/Automattic/static-site-importer/releases/download/v1.2.3/static-site-importer.zip' === ( $playground_download_step['data']['url'] ?? '' ), 'rest-playground-open-blueprint-downloads-pinned-release-zip' );
697+
$assert( 'vfs' === ( $playground_plugin_step['pluginData']['resource'] ?? '' ), 'rest-playground-open-blueprint-installs-verified-vfs-package' );
698+
$assert( ( $playground_download_step['path'] ?? null ) === ( $playground_plugin_step['pluginData']['path'] ?? null ), 'rest-playground-open-blueprint-installs-downloaded-package' );
699+
$assert( str_contains( (string) $playground_blueprint_code, str_repeat( 'a', 64 ) ), 'rest-playground-open-blueprint-verifies-package-digest' );
686700
$assert( str_contains( (string) $playground_blueprint_code, 'static_site_importer_ability_import' ), 'rest-playground-open-blueprint-runs-import-ability' );
687701
$assert( str_contains( (string) $playground_blueprint_code, "'activate' => true" ), 'rest-playground-open-blueprint-activates-generated-site' );
688702
$assert( str_contains( (string) $playground_blueprint_code, "'overwrite' => true" ), 'rest-playground-open-blueprint-overwrites-generated-site' );
@@ -748,7 +762,8 @@ static function ( mixed $output, array $request ): mixed {
748762
$assert( 'playground-provider-arg' === ( $GLOBALS['ssi_last_url_provider_request']['provider_args']['token'] ?? '' ), 'rest-playground-url-only-preserves-provider-args' );
749763
$url_playground_blueprint_json = rawurldecode( substr( (string) ( $url_playground_response['preview']['playground']['blueprint_url'] ?? '' ), strlen( 'https://playground.wordpress.net/#' ) ) );
750764
$url_playground_blueprint = json_decode( $url_playground_blueprint_json, true );
751-
$url_playground_import_code = is_array( $url_playground_blueprint ) ? (string) ( $url_playground_blueprint['steps'][2]['code'] ?? '' ) : '';
765+
$url_playground_import_steps = is_array( $url_playground_blueprint ) ? array_values( array_filter( $url_playground_blueprint['steps'] ?? array(), static fn( array $step ): bool => 'runPHP' === ( $step['step'] ?? '' ) && str_contains( (string) ( $step['code'] ?? '' ), 'static_site_importer_ability_import' ) ) ) : array();
766+
$url_playground_import_code = (string) ( $url_playground_import_steps[0]['code'] ?? '' );
752767
$assert( str_contains( $url_playground_blueprint_json, 'Facebook Fixture' ), 'rest-playground-url-only-blueprint-contains-fetched-artifact' );
753768
$assert( str_contains( $url_playground_import_code, "'source_url' => 'https://facebook.com'" ), 'rest-playground-url-only-blueprint-preserves-source-url' );
754769
$assert( str_contains( $url_playground_import_code, "'provider_token' => 'playground-provider-arg'" ), 'rest-playground-url-only-blueprint-preserves-provider-arg-metadata' );
@@ -1005,9 +1020,14 @@ static function ( mixed $output, array $request ): mixed {
10051020
$assert( str_contains( $blueprint_code, '"openInPlayground":true' ), 'playground-blueprint-targets-open-in-playground' );
10061021
$assert( ! str_contains( $blueprint_code, 'generateInCurrentRuntime' ), 'playground-blueprint-does-not-reference-current-runtime-generation' );
10071022
$assert( str_contains( $blueprint_code, 'static_site_importer_protected_pages' ), 'playground-blueprint-protects-import-page' );
1008-
$plugin_steps = array_values( array_filter( $blueprint['steps'] ?? array(), static fn( array $step ): bool => 'installPlugin' === ( $step['step'] ?? '' ) ) );
1009-
$plugin_step = $plugin_steps[0] ?? array();
1010-
$assert( 'https://github.com/Automattic/static-site-importer/releases/download/{{RELEASE_TAG}}/static-site-importer.zip' === ( $plugin_step['pluginData']['url'] ?? '' ), 'playground-blueprint-installs-same-release-package' );
1023+
$download_steps = array_values( array_filter( $blueprint['steps'] ?? array(), static fn( array $step ): bool => 'writeFile' === ( $step['step'] ?? '' ) ) );
1024+
$plugin_steps = array_values( array_filter( $blueprint['steps'] ?? array(), static fn( array $step ): bool => 'installPlugin' === ( $step['step'] ?? '' ) ) );
1025+
$download_step = $download_steps[0] ?? array();
1026+
$plugin_step = $plugin_steps[0] ?? array();
1027+
$assert( 'https://github.com/Automattic/static-site-importer/releases/download/{{RELEASE_TAG}}/static-site-importer.zip' === ( $download_step['data']['url'] ?? '' ), 'playground-blueprint-downloads-same-release-package' );
1028+
$assert( 'vfs' === ( $plugin_step['pluginData']['resource'] ?? '' ), 'playground-blueprint-installs-verified-vfs-package' );
1029+
$assert( ( $download_step['path'] ?? null ) === ( $plugin_step['pluginData']['path'] ?? null ), 'playground-blueprint-installs-downloaded-package' );
1030+
$assert( str_contains( $blueprint_code, '{{PACKAGE_SHA256}}' ), 'playground-blueprint-verifies-release-package' );
10111031

10121032
$GLOBALS['ssi_test_options']['static_site_importer_protected_pages'] = array( 'import', 'tools/settings', '42' );
10131033
$assert( Static_Site_Importer_Page_Materializer::is_protected_page( new WP_Post( 7, 'import' ) ), 'protected-page-matches-slug' );

tools/php-wasm-zstd.test.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ test( 'release publication keeps immutable assets and blueprints separate from t
5656
assert.match( workflow, /PHP_WASM_ZSTD_ASSET_BASE_URL: https:\/\/automattic\.github\.io\/static-site-importer\/playground\/extensions\/\$\{\{ env\.RELEASE_TAG \}\}/ );
5757
assert.match( workflow, /playground\/extensions\/\$RELEASE_TAG/ );
5858
assert.match( workflow, /playground\/extensions\/latest/ );
59-
assert.match( workflow, /releases\/download\/\$\{tag\}/ );
59+
assert.match( workflow, /releases\/download\/\$RELEASE_TAG/ );
6060
assert.match( workflow, /access-control-allow-origin/ );
6161
assert.match( workflow, /git -C "\$pages_dir" add \.nojekyll "playground\/\$RELEASE_TAG\.blueprint\.json"/ );
6262
assert.match( workflow, /git -C "\$pages_dir" diff --cached --quiet/ );

0 commit comments

Comments
 (0)