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
2 changes: 1 addition & 1 deletion inc/Abilities/Email/EmailAbilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,7 @@ private function saveToSentFolder( array $to, string $subject, string $body, arr
*
* @param string $from The derived From address.
*/
$from = apply_filters( 'dm_email_sent_folder_from', $from );
$from = apply_filters( 'datamachine_email_sent_folder_from', $from );
$to_str = implode( ', ', $to );
$date = gmdate( 'r' );

Expand Down
2 changes: 1 addition & 1 deletion inc/Abilities/Engine/RunFlowAbility.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ private static function backpressureDeferSeconds( int $flow_id ): int {

// Deterministic jitter in [0, base) spreads deferred flows across the
// window instead of waking them all at base seconds.
$jitter = absint( crc32( 'dm_backpressure_' . $flow_id ) ) % $base;
$jitter = absint( crc32( 'datamachine_backpressure_' . $flow_id ) ) % $base;

return $base + $jitter;
}
Expand Down
2 changes: 1 addition & 1 deletion inc/Abilities/Flow/WebhookTriggerAbility.php
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ public function executeSetRateLimit( array $input ): array {
}

// Clear any existing rate limit counter so new config takes effect immediately.
delete_transient( 'dm_webhook_rate_' . $flow_id );
delete_transient( \DataMachine\Api\WebhookTrigger::rate_limit_transient_key( $flow_id ) );

$effective_max = $rate_config['max'] ?? \DataMachine\Api\WebhookTrigger::DEFAULT_RATE_LIMIT_MAX;
$effective_window = $rate_config['window'] ?? \DataMachine\Api\WebhookTrigger::DEFAULT_RATE_LIMIT_WINDOW;
Expand Down
2 changes: 1 addition & 1 deletion inc/Abilities/Media/GDRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ public function save_temp( string $format = 'png', int $quality = -1 ): ?string
return null;
}

$temp_file = tempnam( sys_get_temp_dir(), 'dm_img_' );
$temp_file = tempnam( sys_get_temp_dir(), 'datamachine_img_' );
$ext = 'jpeg' === $format ? '.jpg' : '.png';
$path = $temp_file . $ext;

Expand Down
12 changes: 11 additions & 1 deletion inc/Api/WebhookTrigger.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ private static function check_rate_limit( int $flow_id, array $scheduling_config
return null;
}

$transient_key = 'dm_webhook_rate_' . $flow_id;
$transient_key = self::rate_limit_transient_key( $flow_id );
$current_count = (int) get_transient( $transient_key );

if ( $current_count >= $max ) {
Expand Down Expand Up @@ -568,6 +568,16 @@ function ( $result ) use ( $window ) {
return null;
}

/**
* Build the per-flow rate-limit transient key.
*
* @param int $flow_id Flow ID.
* @return string Transient key.
*/
public static function rate_limit_transient_key( int $flow_id ): string {
return 'datamachine_webhook_rate_' . $flow_id;
}

/**
* Extract Bearer token from Authorization header.
*
Expand Down
2 changes: 1 addition & 1 deletion inc/Engine/Tasks/RecurringScheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ public static function calculateStaggerOffset( int $seed, int $interval_seconds
if ( $max_offset <= 0 ) {
return 0;
}
return absint( crc32( 'dm_stagger_' . $seed ) ) % $max_offset;
return absint( crc32( 'datamachine_stagger_' . $seed ) ) % $max_offset;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion inc/Engine/Tasks/TaskScheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ public static function scheduleBatch( string $taskType, array $itemParams, array
// so the chain caller → batch_parent is preserved even though
// per-item children chain off the caller directly (below).
$jobs_db = new Jobs();
$batch_id = 'dm_batch_' . wp_generate_uuid4();
$batch_id = 'datamachine_batch_' . wp_generate_uuid4();
$batch_create_args = array(
'pipeline_id' => 'direct',
'flow_id' => 'direct',
Expand Down
10 changes: 5 additions & 5 deletions inc/migrations/scaffolding.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ function datamachine_get_scaffold_defaults( string $agent_name = '' ): array {
$admin_name = $admin_user ? $admin_user->display_name : '';

// --- Versions ---
$wp_version = get_bloginfo( 'version' );
$php_version = PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION;
$dm_version = defined( 'DATAMACHINE_VERSION' ) ? DATAMACHINE_VERSION : 'unknown';
$created = wp_date( 'Y-m-d' );
$wp_version = get_bloginfo( 'version' );
$php_version = PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION;
$datamachine_version = defined( 'DATAMACHINE_VERSION' ) ? DATAMACHINE_VERSION : 'unknown';
$created = wp_date( 'Y-m-d' );

// --- Build SOUL.md context lines ---
$context_items = array();
Expand Down Expand Up @@ -187,7 +187,7 @@ function datamachine_get_scaffold_defaults( string $agent_name = '' ): array {
'This file tracks persistent knowledge. Keep it lean — persistent facts only, not session logs.',
'',
'## State',
"- Data Machine v{$dm_version} activated on {$created}",
"- Data Machine v{$datamachine_version} activated on {$created}",
"- WordPress {$wp_version}, PHP {$php_version}",
'',
'## Lessons Learned',
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Abilities/Engine/PipelineBatchSchedulerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function test_fanout_stores_batch_state_in_engine_data(): void {
$this->assertEquals( 'step_abc_123', $parent_engine['next_flow_step_id'] );

// No transient should exist.
$this->assertFalse( get_transient( 'dm_pipeline_batch_' . $parent_id ) );
$this->assertFalse( get_transient( 'datamachine_pipeline_batch_' . $parent_id ) );
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Abilities/TaxonomyAbilityWpErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class TaxonomyAbilityWpErrorTest extends WP_UnitTestCase {

private const TEST_TAXONOMY = 'dm_wp_error_terms';
private const TEST_TAXONOMY = 'datamachine_wp_error_terms';

public function set_up(): void {
parent::set_up();
Expand Down Expand Up @@ -80,7 +80,7 @@ public function test_merge_term_meta_callback_failure_returns_wp_error(): void {
'term_id' => 0,
'taxonomy' => self::TEST_TAXONOMY,
'data' => array( 'name' => 'Charleston' ),
'field_map' => array( 'name' => 'dm_name' ),
'field_map' => array( 'name' => 'datamachine_name' ),
)
);

Expand All @@ -94,7 +94,7 @@ public function test_merge_term_meta_static_helper_preserves_legacy_failure_arra
0,
self::TEST_TAXONOMY,
array( 'name' => 'Charleston' ),
array( 'name' => 'dm_name' )
array( 'name' => 'datamachine_name' )
);

$this->assertIsArray( $result );
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Api/WebhookTriggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function set_up(): void {

public function tear_down(): void {
remove_all_filters( 'datamachine_webhook_auth_presets' );
delete_transient( 'dm_webhook_rate_' . $this->flow_id );
delete_transient( WebhookTrigger::rate_limit_transient_key( $this->flow_id ) );
parent::tear_down();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Core/WordPress/TaxonomyHandlerFiltersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TaxonomyHandlerFiltersTest extends WP_UnitTestCase {
* Intentionally NOT named after any real Extra Chill taxonomy so the
* tests document the generic contract, not a vendor-specific shape.
*/
private const TEST_TAXONOMY = 'dm_test_region';
private const TEST_TAXONOMY = 'datamachine_test_region';

public function set_up(): void {
parent::set_up();
Expand Down
40 changes: 20 additions & 20 deletions tests/abilities-categories-load-order-smoke.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,32 +150,32 @@ function __( $text, $domain = null ) {
}
if ( ! function_exists( 'doing_action' ) ) {
function doing_action( $hook ) {
global $dm_2287_state;
return $dm_2287_state->doing && $hook === 'wp_abilities_api_categories_init';
global $datamachine_2287_state;
return $datamachine_2287_state->doing && $hook === 'wp_abilities_api_categories_init';
}
}
if ( ! function_exists( 'did_action' ) ) {
function did_action( $hook ) {
global $dm_2287_state;
return $hook === 'wp_abilities_api_categories_init' ? $dm_2287_state->did : 0;
global $datamachine_2287_state;
return $hook === 'wp_abilities_api_categories_init' ? $datamachine_2287_state->did : 0;
}
}
if ( ! function_exists( 'add_action' ) ) {
function add_action( $hook, $callback, $priority = 10, $accepted_args = 1 ) {
global $dm_2287_state;
$dm_2287_state->hooked[ $hook ][] = $callback;
global $datamachine_2287_state;
$datamachine_2287_state->hooked[ $hook ][] = $callback;
return true;
}
}
if ( ! function_exists( 'wp_register_ability_category' ) ) {
function wp_register_ability_category( $slug, $args ) {
global $dm_2287_state;
global $datamachine_2287_state;
// Only succeed when the action is firing (mirror core's guard).
if ( ! doing_action( 'wp_abilities_api_categories_init' ) ) {
$dm_2287_state->doing_it_wrong = ( $dm_2287_state->doing_it_wrong ?? 0 ) + 1;
$datamachine_2287_state->doing_it_wrong = ( $datamachine_2287_state->doing_it_wrong ?? 0 ) + 1;
return null;
}
$dm_2287_state->registered[ $slug ] = $args;
$datamachine_2287_state->registered[ $slug ] = $args;
return true;
}
}
Expand All @@ -195,28 +195,28 @@ public static function get_instance(): self {
return self::$instance;
}
public function is_registered( $slug ): bool {
global $dm_2287_state;
return isset( $dm_2287_state->registered[ $slug ] );
global $datamachine_2287_state;
return isset( $datamachine_2287_state->registered[ $slug ] );
}
public function register( $slug, $args ): bool {
global $dm_2287_state;
$dm_2287_state->registered[ $slug ] = $args;
global $datamachine_2287_state;
$datamachine_2287_state->registered[ $slug ] = $args;
return true;
}
}
}

$GLOBALS['dm_2287_state'] = $state;
$GLOBALS['datamachine_2287_state'] = $state;

require_once $plugin_root . '/inc/Abilities/AbilityCategories.php';

$reset = static function (): void {
global $dm_2287_state;
$dm_2287_state->doing = false;
$dm_2287_state->did = 0;
$dm_2287_state->hooked = array();
$dm_2287_state->registered = array();
$dm_2287_state->doing_it_wrong = 0;
global $datamachine_2287_state;
$datamachine_2287_state->doing = false;
$datamachine_2287_state->did = 0;
$datamachine_2287_state->hooked = array();
$datamachine_2287_state->registered = array();
$datamachine_2287_state->doing_it_wrong = 0;

$reflection = new ReflectionClass( \DataMachine\Abilities\AbilityCategories::class );
$prop = $reflection->getProperty( 'registered' );
Expand Down
64 changes: 32 additions & 32 deletions tests/abilities-image-template-load-order-smoke.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
define( 'ABSPATH', '/tmp/' );
}

$GLOBALS['dm_2290_state'] = (object) array(
$GLOBALS['datamachine_2290_state'] = (object) array(
'doing' => false,
'did' => 0,
'hooked' => array(),
Expand All @@ -147,35 +147,35 @@ function __( $text, $domain = null ) {

if ( ! function_exists( 'doing_action' ) ) {
function doing_action( $hook ) {
global $dm_2290_state;
return $dm_2290_state->doing && $hook === 'wp_abilities_api_init';
global $datamachine_2290_state;
return $datamachine_2290_state->doing && $hook === 'wp_abilities_api_init';
}
}

if ( ! function_exists( 'did_action' ) ) {
function did_action( $hook ) {
global $dm_2290_state;
return $hook === 'wp_abilities_api_init' ? $dm_2290_state->did : 0;
global $datamachine_2290_state;
return $hook === 'wp_abilities_api_init' ? $datamachine_2290_state->did : 0;
}
}

if ( ! function_exists( 'add_action' ) ) {
function add_action( $hook, $callback, $priority = 10, $accepted_args = 1 ) {
global $dm_2290_state;
$dm_2290_state->hooked[ $hook ][] = $callback;
global $datamachine_2290_state;
$datamachine_2290_state->hooked[ $hook ][] = $callback;
return true;
}
}

if ( ! function_exists( 'wp_register_ability' ) ) {
function wp_register_ability( $name, $args ) {
global $dm_2290_state;
global $datamachine_2290_state;
// Mirror core's guard: only succeed when doing_action(wp_abilities_api_init) is true.
if ( ! doing_action( 'wp_abilities_api_init' ) ) {
++$dm_2290_state->doing_it_wrong;
++$datamachine_2290_state->doing_it_wrong;
return null;
}
$dm_2290_state->registered[ $name ] = $args;
$datamachine_2290_state->registered[ $name ] = $args;
return true;
}
}
Expand All @@ -193,12 +193,12 @@ public static function can_manage(): bool { return true; }
require_once $plugin_root . '/inc/Abilities/Media/ImageTemplateAbilities.php';

$reset = static function (): void {
global $dm_2290_state;
$dm_2290_state->doing = false;
$dm_2290_state->did = 0;
$dm_2290_state->hooked = array();
$dm_2290_state->registered = array();
$dm_2290_state->doing_it_wrong = 0;
global $datamachine_2290_state;
$datamachine_2290_state->doing = false;
$datamachine_2290_state->did = 0;
$datamachine_2290_state->hooked = array();
$datamachine_2290_state->registered = array();
$datamachine_2290_state->doing_it_wrong = 0;

$reflection = new ReflectionClass( \DataMachine\Abilities\Media\ImageTemplateAbilities::class );
$prop = $reflection->getProperty( 'registered' );
Expand All @@ -208,60 +208,60 @@ public static function can_manage(): bool { return true; }

// --- State 1: doing_action — register immediately.
$reset();
$GLOBALS['dm_2290_state']->doing = true;
$GLOBALS['datamachine_2290_state']->doing = true;
\DataMachine\Abilities\Media\ImageTemplateAbilities::ensure_registered();
$assert(
'state 1: when doing_action fires, abilities register immediately via wp_register_ability()',
isset( $GLOBALS['dm_2290_state']->registered['datamachine/render-image-template'] )
&& isset( $GLOBALS['dm_2290_state']->registered['datamachine/list-image-templates'] )
&& empty( $GLOBALS['dm_2290_state']->hooked )
isset( $GLOBALS['datamachine_2290_state']->registered['datamachine/render-image-template'] )
&& isset( $GLOBALS['datamachine_2290_state']->registered['datamachine/list-image-templates'] )
&& empty( $GLOBALS['datamachine_2290_state']->hooked )
);

// --- State 2: pre-action — hook for later.
$reset();
\DataMachine\Abilities\Media\ImageTemplateAbilities::ensure_registered();
$assert(
'state 2: when action has not fired, callback is hooked on wp_abilities_api_init',
isset( $GLOBALS['dm_2290_state']->hooked['wp_abilities_api_init'] )
&& count( $GLOBALS['dm_2290_state']->hooked['wp_abilities_api_init'] ) === 1
&& empty( $GLOBALS['dm_2290_state']->registered )
isset( $GLOBALS['datamachine_2290_state']->hooked['wp_abilities_api_init'] )
&& count( $GLOBALS['datamachine_2290_state']->hooked['wp_abilities_api_init'] ) === 1
&& empty( $GLOBALS['datamachine_2290_state']->registered )
);

// --- State 3: post-action — no-op instead of mutating registry internals.
$reset();
$GLOBALS['dm_2290_state']->did = 1;
$GLOBALS['datamachine_2290_state']->did = 1;
\DataMachine\Abilities\Media\ImageTemplateAbilities::ensure_registered();
$assert(
'state 3: when action already fired, abilities do not register late',
empty( $GLOBALS['dm_2290_state']->registered )
empty( $GLOBALS['datamachine_2290_state']->registered )
);

$assert(
'state 3: no-op path does not call wp_register_ability() (which would fire _doing_it_wrong)',
0 === $GLOBALS['dm_2290_state']->doing_it_wrong
0 === $GLOBALS['datamachine_2290_state']->doing_it_wrong
);

$assert(
'state 3: no-op path does not double-hook the action',
empty( $GLOBALS['dm_2290_state']->hooked )
empty( $GLOBALS['datamachine_2290_state']->hooked )
);

// --- Idempotency: a second post-action ensure_registered() remains a no-op.
$prior_registered = $GLOBALS['dm_2290_state']->registered;
$prior_registered = $GLOBALS['datamachine_2290_state']->registered;
\DataMachine\Abilities\Media\ImageTemplateAbilities::ensure_registered();
$assert(
'idempotent: second post-action ensure_registered() call is a no-op',
$GLOBALS['dm_2290_state']->registered === $prior_registered
&& 0 === $GLOBALS['dm_2290_state']->doing_it_wrong
$GLOBALS['datamachine_2290_state']->registered === $prior_registered
&& 0 === $GLOBALS['datamachine_2290_state']->doing_it_wrong
);

// --- Constructor path still works (for the in-runtime defensive call site).
$reset();
$GLOBALS['dm_2290_state']->doing = true;
$GLOBALS['datamachine_2290_state']->doing = true;
new \DataMachine\Abilities\Media\ImageTemplateAbilities();
$assert(
'constructor path: instantiating the class triggers ensure_registered()',
isset( $GLOBALS['dm_2290_state']->registered['datamachine/render-image-template'] )
isset( $GLOBALS['datamachine_2290_state']->registered['datamachine/render-image-template'] )
);

if ( $failed > 0 ) {
Expand Down
Loading
Loading