Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion data-machine-code.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
// PSR-4 Autoloading.
require_once __DIR__ . '/vendor/autoload.php';

// Bundle artifact types must be registered as soon as the plugin is loaded so
// Data Machine can validate DMC-owned artifacts during early import paths.
( new \DataMachineCode\Bundle\WorkspacePreloadArtifact() )->register();

/**
* Install DMC-owned database tables.
*/
Expand Down Expand Up @@ -99,7 +103,6 @@ function datamachine_code_bootstrap() {
new \DataMachineCode\Abilities\CodeTaskAbilities();
new \DataMachineCode\Abilities\WordPressRuntimeAbilities();
\DataMachineCode\SourceInventory\WorkspaceSourceInventory::register();
( new \DataMachineCode\Bundle\WorkspacePreloadArtifact() )->register();

// Project active workspace identity into Data Machine's engine_data
// snapshot at job init. Requires DM's datamachine_engine_snapshot
Expand Down
69 changes: 69 additions & 0 deletions tests/smoke-bundle-artifact-early-registration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/**
* Smoke test that DMC bundle artifact hooks register at plugin load time.
*
* Run: php tests/smoke-bundle-artifact-early-registration.php
*
* @package DataMachineCode\Tests
*/

declare( strict_types=1 );

if ( ! defined( 'WPINC' ) ) {
define( 'WPINC', 'wp-includes' );
}
if ( ! defined( 'ABSPATH' ) ) {
define( 'ABSPATH', __DIR__ . '/' );
}

$filters = array();
$actions = array();

function plugin_dir_path( string $file ): string {
return dirname( $file ) . '/';
}

function plugin_dir_url( string $file ): string {
return 'https://example.test/wp-content/plugins/' . basename( dirname( $file ) ) . '/';
}

function register_activation_hook( string $file, callable|string $callback ): void {
unset( $file, $callback );
}

function add_action( string $hook, callable|string|array $callback, int $priority = 10, int $accepted_args = 1 ): void {
global $actions;
$actions[ $hook ][ $priority ][] = array( $callback, $accepted_args );
}

function add_filter( string $hook, callable|string|array $callback, int $priority = 10, int $accepted_args = 1 ): void {
global $filters;
$filters[ $hook ][ $priority ][] = array( $callback, $accepted_args );
}

function apply_filters( string $hook, mixed $value, mixed ...$args ): mixed {
global $filters;
if ( empty( $filters[ $hook ] ) ) {
return $value;
}

ksort( $filters[ $hook ] );
foreach ( $filters[ $hook ] as $callbacks ) {
foreach ( $callbacks as $callback ) {
$value = call_user_func_array( $callback[0], array_slice( array_merge( array( $value ), $args ), 0, (int) $callback[1] ) );
}
}

return $value;
}

require __DIR__ . '/../data-machine-code.php';

$types = apply_filters( 'datamachine_agent_bundle_artifact_types', array( 'agent' ) );
$ok = in_array( 'datamachine-code/workspace_preload', $types, true );

echo 'Bundle artifact early registration - smoke' . PHP_EOL;
echo ( $ok ? ' ok registers workspace preload artifact before bootstrap' : ' fail registers workspace preload artifact before bootstrap' ) . PHP_EOL;
echo PHP_EOL . 'Result: ' . ( $ok ? '1/1 passed' : '0/1 passed' ) . PHP_EOL;

exit( $ok ? 0 : 1 );
Loading