77 *
88 * Two kinds of assertions:
99 *
10- * 1. Source-string assertions — `data-machine.php` must call
11- * `ImageTemplateAbilities::ensure_registered()` UNCONDITIONALLY at
12- * file include time, NOT only inside the gated runtime function .
10+ * 1. Source-string assertions — `data-machine.php` must declare
11+ * `ImageTemplateAbilities::ensure_registered()` in the lightweight
12+ * ability manifest registered at file include time .
1313 *
1414 * 2. Behavioral assertions — `ImageTemplateAbilities::ensure_registered()`
1515 * must handle all three timing states defensively, matching the
5050}
5151
5252$ assert (
53- 'data-machine.php calls ImageTemplateAbilities::ensure_registered() unconditionally at file load ' ,
54- str_contains ( $ bootstrap , 'Register `datamachine/render-image-template` and ' )
55- && str_contains ( $ bootstrap , "require_once __DIR__ . '/inc/Abilities/Media/ImageTemplateAbilities.php'; \n\\DataMachine \\Abilities \\Media \\ImageTemplateAbilities::ensure_registered(); " )
53+ 'data-machine.php declares ImageTemplateAbilities::ensure_registered() in the lightweight manifest ' ,
54+ str_contains ( $ bootstrap , "'file' => __DIR__ . '/inc/Abilities/Media/ImageTemplateAbilities.php', " )
55+ && str_contains ( $ bootstrap , "'class' => \\DataMachine \\Abilities \\Media \\ImageTemplateAbilities::class, " )
56+ && str_contains ( $ bootstrap , "'method' => 'ensure_registered', " )
5657);
5758
5859$ assert (
59- 'unconditional call site is OUTSIDE datamachine_run_datamachine_plugin() ' ,
60- // The image-template registration must sit at file scope, after the
61- // unconditional `AbilityCategories::ensure_registered()` call (which other
62- // unconditional ability registrations — e.g. AgentAbilities — may follow).
60+ 'lightweight manifest registration is unconditional at file load ' ,
6361 (bool ) preg_match (
6462 '/^ \\\\DataMachine \\\\Abilities \\\\AbilityCategories::ensure_registered\(\);\s*\n/m ' ,
6563 $ bootstrap
6664 )
6765 && (bool ) preg_match (
68- '/^\/\*\*\s*\n\s*\*\s*Register `datamachine\/render-image-template` /m ' ,
66+ '/^ \\\\ DataMachine \\\\ Abilities \\\\ AbilityManifest::register\( datamachine_lightweight_ability_manifest\(\) \);\s*$ /m ' ,
6967 $ bootstrap
7068 )
7169);
@@ -180,7 +178,9 @@ function wp_register_ability( $name, $args ) {
180178 }
181179}
182180
183- // Stub PermissionHelper which the ability definitions reference.
181+ // Load or stub every collaborator used while building ability definitions.
182+ require_once $ plugin_root . '/inc/Abilities/AbilityRegistration.php ' ;
183+
184184if ( ! class_exists ( 'DataMachine \\Abilities \\PermissionHelper ' ) ) {
185185 eval (
186186 'namespace DataMachine \\Abilities;
@@ -190,6 +190,16 @@ public static function can_manage(): bool { return true; }
190190 );
191191}
192192
193+ $ assert (
194+ 'bootstrap loads AbilityRegistration used to build registration definitions ' ,
195+ class_exists ( 'DataMachine \\Abilities \\AbilityRegistration ' , false )
196+ );
197+
198+ $ assert (
199+ 'bootstrap loads PermissionHelper referenced by registration definitions ' ,
200+ class_exists ( 'DataMachine \\Abilities \\PermissionHelper ' , false )
201+ );
202+
193203require_once $ plugin_root . '/inc/Abilities/Media/ImageTemplateAbilities.php ' ;
194204
195205$ reset = static function (): void {
@@ -214,6 +224,8 @@ public static function can_manage(): bool { return true; }
214224 'state 1: when doing_action fires, abilities register immediately via wp_register_ability() ' ,
215225 isset ( $ GLOBALS ['datamachine_2290_state ' ]->registered ['datamachine/render-image-template ' ] )
216226 && isset ( $ GLOBALS ['datamachine_2290_state ' ]->registered ['datamachine/list-image-templates ' ] )
227+ && $ GLOBALS ['datamachine_2290_state ' ]->registered ['datamachine/render-image-template ' ]['execute_callback ' ] instanceof Closure
228+ && $ GLOBALS ['datamachine_2290_state ' ]->registered ['datamachine/list-image-templates ' ]['execute_callback ' ] instanceof Closure
217229 && empty ( $ GLOBALS ['datamachine_2290_state ' ]->hooked )
218230);
219231
0 commit comments