Skip to content

Commit 88a0d49

Browse files
batuhanclaude
andcommitted
Trigger headless builds through the current build API
Spacefast replaced POST/GET /builds/wordpress with POST /builds {source: "wordpress"} and GET /builds/preflight, and renamed /uploads/resume to /uploads/refresh. 0.5.8 still called the removed routes, so headless rebuilds never started. Static publishing only kept working through a server-side alias. The behavior suite now pins exact method, URL, query, and body for the preflight, trigger, and upload refresh calls. The old suffix checks let the drift pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 04f0854 commit 88a0d49

6 files changed

Lines changed: 39 additions & 23 deletions

File tree

‎includes/class-spacefast-client.php‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public function repository_health(): array {
204204
$source_url = rawurlencode( untrailingslashit( home_url() ) );
205205
return $this->request(
206206
'GET',
207-
"/v1/spaces/{$space_id}/builds/wordpress?sourceUrl={$source_url}"
207+
"/v1/spaces/{$space_id}/builds/preflight?source=wordpress&sourceUrl={$source_url}"
208208
);
209209
}
210210

@@ -230,8 +230,9 @@ public function trigger_build( string $event_id ): array {
230230
$settings = Spacefast_Settings::get();
231231
$result = $this->request(
232232
'POST',
233-
'/v1/spaces/' . rawurlencode( $settings['space_id'] ) . '/builds/wordpress',
233+
'/v1/spaces/' . rawurlencode( $settings['space_id'] ) . '/builds',
234234
array(
235+
'source' => 'wordpress',
235236
'sourceUrl' => untrailingslashit( home_url() ),
236237
),
237238
array( 'Idempotency-Key' => $event_id )
@@ -300,12 +301,12 @@ public function create_static_version( array $files, string $event_id, string $p
300301
/**
301302
* @return array{ok:bool,retryable:bool,code:string,message:string,data:array<string,mixed>}
302303
*/
303-
public function resume_static_upload( string $version_id ): array {
304+
public function refresh_static_upload( string $version_id ): array {
304305
$settings = Spacefast_Settings::get();
305306
return $this->request(
306307
'POST',
307308
'/v1/spaces/' . rawurlencode( $settings['space_id'] ) . '/versions/'
308-
. rawurlencode( $version_id ) . '/uploads/resume'
309+
. rawurlencode( $version_id ) . '/uploads/refresh'
309310
);
310311
}
311312

‎includes/class-spacefast-static-publisher.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ private static function resume( array $state, Spacefast_Client $client ): array
236236
if ( $pages > 10000 ) {
237237
throw new RuntimeException( 'Spacefast returned too many upload instruction pages.' );
238238
}
239-
$result = $client->resume_static_upload( (string) $state['version_id'] );
239+
$result = $client->refresh_static_upload( (string) $state['version_id'] );
240240
if ( ! $result['ok'] ) {
241241
return self::retry_or_throw( $state, $result, 'uploading' );
242242
}
@@ -294,7 +294,7 @@ private static function poll_version( array $state, Spacefast_Client $client ):
294294
// refresh runs the same completion the runtime's upload callback runs,
295295
// so a lost callback cannot strand the version; when some are, upload
296296
// them before waiting.
297-
$refresh = $client->resume_static_upload( (string) $state['version_id'] );
297+
$refresh = $client->refresh_static_upload( (string) $state['version_id'] );
298298
if ( ! $refresh['ok'] && $refresh['retryable'] ) {
299299
return self::retry_or_throw( $state, $refresh, 'finalizing' );
300300
}

‎readme.txt‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Contributors: spacefast
33
Tags: static site, headless cms, simply static, deployment
44
Requires at least: 6.5
55
Requires PHP: 8.1
6-
Stable tag: 0.5.8
6+
Stable tag: 0.5.9
77
License: GPLv2 or later
88

99
Publish a Simply Static export to Spacefast, or rebuild a headless site when WordPress content changes.
@@ -31,6 +31,10 @@ OAuth access is limited to the Team you authorize and the mode you choose. WordP
3131

3232
== Changelog ==
3333

34+
= 0.5.9 =
35+
* Trigger headless builds and check the WordPress source through the current Spacefast build API. 0.5.8 called routes Spacefast removed, so headless rebuilds never started.
36+
* Page static upload instructions through the current upload refresh route.
37+
3438
= 0.5.8 =
3539
* Retry transient upload and upload-refresh failures in place, with exponential backoff for about four minutes, instead of restarting the whole export as a new version.
3640
* Once every file has uploaded, ask Spacefast which files it still lacks, upload any it names, and let that check trigger activation instead of depending on the upload-completion signal alone.

‎spacefast-wordpress.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: Spacefast
44
* Plugin URI: https://spacefast.com/
55
* Description: Publishes static WordPress exports or rebuilds a headless Spacefast site.
6-
* Version: 0.5.8
6+
* Version: 0.5.9
77
* Update URI: https://github.com/spacefast/wordpress
88
* Requires at least: 6.5
99
* Requires PHP: 8.1
@@ -14,7 +14,7 @@
1414

1515
defined( 'ABSPATH' ) || exit;
1616

17-
define( 'SPACEFAST_WORDPRESS_VERSION', '0.5.8' );
17+
define( 'SPACEFAST_WORDPRESS_VERSION', '0.5.9' );
1818
define( 'SPACEFAST_WORDPRESS_FILE', __FILE__ );
1919

2020
require_once __DIR__ . '/includes/class-spacefast-settings.php';

‎tests/acceptance/wordpress.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ function spacefast_accept( bool $condition, string $message ): void {
113113
);
114114

115115
$plugin = get_plugin_data( WP_PLUGIN_DIR . '/spacefast-wordpress/spacefast-wordpress.php', false, false );
116-
spacefast_accept( '0.5.8' === $plugin['Version'], 'Unexpected plugin version.' );
116+
spacefast_accept( '0.5.9' === $plugin['Version'], 'Unexpected plugin version.' );
117117
spacefast_accept( 'https://github.com/spacefast/wordpress' === $plugin['UpdateURI'], 'Update URI is missing.' );
118118

119119
Spacefast_Settings::disconnect();

‎tests/behavior.php‎

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ static function ( string $url, array $args ) use ( &$revoke_requests ): array {
465465
$connection_requests = array();
466466
$GLOBALS['spacefast_remote_handler'] = static function ( string $url, array $args ) use ( &$connection_requests ): array {
467467
$connection_requests[] = array( $url, $args );
468-
if ( 'POST' === $args['method'] && str_ends_with( $url, '/builds/wordpress' ) ) {
468+
if ( 'POST' === $args['method'] && str_ends_with( $url, '/builds' ) ) {
469469
return response( 201, array( 'build' => array( 'id' => 'bld_new_space', 'status' => 'queued' ) ) );
470470
}
471471
return response( 200, array( 'ready' => true ) );
@@ -783,18 +783,24 @@ static function ( string $url, array $args ): array {
783783
$result = ( new Spacefast_Client( $transport ) )->trigger_build( 'wp-event-123' );
784784
check( true === $result['ok'], 'healthy connection triggers a build' );
785785
check( 2 === count( $requests ), 'verifies the source before the build' );
786+
check(
787+
Spacefast_Settings::api_url() . '/v1/spaces/spc_demo/builds/preflight?source=wordpress&sourceUrl=https%3A%2F%2Fwp.example.test' === $requests[0][0]
788+
&& 'GET' === $requests[0][1]['method'],
789+
'checks the WordPress source through build preflight'
790+
);
786791
$build_request = $requests[1][1];
787792
check(
788793
'wp-event-123' === $build_request['headers']['Idempotency-Key'],
789794
'reuses the stable event as idempotency key'
790795
);
791796
$build_body = json_decode( $build_request['body'], true );
792797
check(
793-
'https://wp.example.test' === $build_body['sourceUrl'],
794-
'sends only the configured WordPress source'
798+
array( 'source' => 'wordpress', 'sourceUrl' => 'https://wp.example.test' ) === $build_body,
799+
'names the managed WordPress source and nothing else'
795800
);
796801
check(
797-
str_ends_with( $requests[1][0], '/builds/wordpress' ),
802+
Spacefast_Settings::api_url() . '/v1/spaces/spc_demo/builds' === $requests[1][0]
803+
&& 'POST' === $build_request['method'],
798804
'uses the constrained server-side trigger'
799805
);
800806
check(
@@ -932,9 +938,9 @@ static function ( string $url, array $args ) use ( &$static_requests ): array {
932938
)
933939
);
934940
}
935-
if ( str_contains( $url, '/uploads/resume' ) ) {
941+
if ( str_contains( $url, '/uploads/refresh' ) ) {
936942
// The completion check after the last page finds nothing missing.
937-
if ( count( array_filter( $static_requests, static fn ( array $request ): bool => str_contains( $request[0], '/uploads/resume' ) ) ) > 1 ) {
943+
if ( count( array_filter( $static_requests, static fn ( array $request ): bool => str_contains( $request[0], '/uploads/refresh' ) ) ) > 1 ) {
938944
return response( 200, array( 'upload' => null ) );
939945
}
940946
return response(
@@ -953,7 +959,7 @@ static function ( string $url, array $args ) use ( &$static_requests ): array {
953959
'headers' => array( 'X-Upload' => 'signed-2' ),
954960
),
955961
),
956-
'links' => array( 'resume' => '/resume', 'finalize' => '/finalize' ),
962+
'links' => array( 'refresh' => '/refresh', 'finalize' => '/finalize' ),
957963
),
958964
)
959965
);
@@ -975,7 +981,7 @@ static function ( string $url, array $args ) use ( &$static_requests ): array {
975981
'headers' => array( 'X-Upload' => 'signed' ),
976982
),
977983
),
978-
'links' => array( 'resume' => '/resume', 'finalize' => '/finalize' ),
984+
'links' => array( 'refresh' => '/refresh', 'finalize' => '/finalize' ),
979985
),
980986
)
981987
);
@@ -1017,6 +1023,11 @@ static function ( string $url, string $method, array $headers, string $file ) us
10171023
str_ends_with( $static_requests[3][3], '/assets/app.js' ),
10181024
'uploads the next opaque target after resuming'
10191025
);
1026+
check(
1027+
Spacefast_Settings::api_url() . '/v1/spaces/spc_demo/versions/ver_static/uploads/refresh' === $static_requests[2][0]
1028+
&& 'POST' === $static_requests[2][1]['method'],
1029+
'pages upload instructions through the version upload refresh'
1030+
);
10201031

10211032
Spacefast_Sync_State::save(
10221033
array_merge( Spacefast_Sync_State::defaults(), array( 'desired' => 2, 'active_generation' => 1 ) )
@@ -1109,7 +1120,7 @@ static function ( string $url, array $args ) use ( &$retry_requests, $retry_targ
11091120
if ( 'GET' === $args['method'] ) {
11101121
return response( 200, array( 'id' => 'ver_retry', 'status' => 'ready', 'isCurrentProduction' => true ) );
11111122
}
1112-
if ( str_contains( $url, '/uploads/resume' ) ) {
1123+
if ( str_contains( $url, '/uploads/refresh' ) ) {
11131124
return response( 200, array( 'upload' => null ) );
11141125
}
11151126
return response(
@@ -1148,7 +1159,7 @@ static function () use ( &$retry_uploads ): array {
11481159
);
11491160
$retry_confirms = array_filter(
11501161
$retry_requests,
1151-
static fn ( array $request ): bool => str_contains( $request[0], '/versions/ver_retry/uploads/resume' )
1162+
static fn ( array $request ): bool => str_contains( $request[0], '/versions/ver_retry/uploads/refresh' )
11521163
);
11531164
$retry_finalizes = array_filter(
11541165
$retry_requests,
@@ -1170,7 +1181,7 @@ static function ( string $url, array $args ) use ( &$expired_resumes, $retry_tar
11701181
'summary' => array( 'upload' => 1, 'reused' => 0, 'ignored' => 0 ),
11711182
'targets' => array( $retry_target ),
11721183
);
1173-
if ( str_contains( $url, '/uploads/resume' ) ) {
1184+
if ( str_contains( $url, '/uploads/refresh' ) ) {
11741185
$expired_resumes++;
11751186
if ( 1 === $expired_resumes ) return response( 503 );
11761187
return response( 200, array( 'upload' => 2 === $expired_resumes ? $upload : null ) );
@@ -1202,7 +1213,7 @@ static function ( string $url, array $args ) use ( &$missing_resumes, $retry_tar
12021213
'summary' => array( 'upload' => 1, 'reused' => 0, 'ignored' => 0 ),
12031214
'targets' => array( $retry_target ),
12041215
);
1205-
if ( str_contains( $url, '/uploads/resume' ) ) {
1216+
if ( str_contains( $url, '/uploads/refresh' ) ) {
12061217
$missing_resumes++;
12071218
return response( 200, array( 'upload' => 1 === $missing_resumes ? $upload : null ) );
12081219
}
@@ -1227,7 +1238,7 @@ static function ( string $url, array $args ) use ( $retry_target ): array {
12271238
'summary' => array( 'upload' => 1, 'reused' => 0, 'ignored' => 0 ),
12281239
'targets' => array( $retry_target ),
12291240
);
1230-
if ( str_contains( $url, '/uploads/resume' ) ) {
1241+
if ( str_contains( $url, '/uploads/refresh' ) ) {
12311242
return response( 200, array( 'upload' => $upload ) );
12321243
}
12331244
return response( 201, array( 'versionId' => 'ver_stuck', 'upload' => $upload ) );

0 commit comments

Comments
 (0)