fix: QA remediation P1-A/P1-B/P1-C/P2 for v0.22.1 sync-mode
P1-A: wrap wp_schedule_single_event(GENERATE_ACTION) + fire_cron_now() in on_orchestrate_tick() with 'if ( ! self::$sync_mode )' guard. Mirrors the existing guard in on_generate_tick(). Prevents a background wp-cron process spawning in parallel with the VPS --sync loop and prematurely finalizing the run lock before Article_Worker completes. P1-B: add two unit tests to GenerationCheckpointRunnerTest.php: - test_orchestrate_tick_in_sync_mode_does_not_schedule_background_event: asserts sync_mode=true suppresses GENERATE_ACTION schedule + spawn_cron. - test_generate_tick_async_mode_schedules_generate_action: asserts sync_mode=false (async path) still reschedules GENERATE_ACTION. P1-C: create root CONTEXT.md with domain glossary (run, run_stages, checkpoint, idea queue, Generation_Lock) and execution mode reference (async wp-cron vs --sync VPS-driven). P2: update ARCHITECTURE.md §25 Entry Points table with the 'wp prautoblogger generate --sync' VPS path row. Agent-Session: prab-reliability-remediation-20260622
This commit is contained in:
@@ -227,4 +227,71 @@ class GenerationCheckpointRunnerTest extends BaseTestCase {
|
||||
$this->assertCount( 1, $remaining, 'Queue must have exactly 1 idea left after first tick' );
|
||||
}
|
||||
}
|
||||
|
||||
// ── sync mode guards ──────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* sync_mode=true: on_orchestrate_tick() must not schedule GENERATE_ACTION
|
||||
* or call spawn_cron (VPS loop drives generate ticks directly).
|
||||
*/
|
||||
public function test_orchestrate_tick_in_sync_mode_does_not_schedule_background_event(): void {
|
||||
$this->wire_wpdb_for_lock();
|
||||
if ( ! class_exists( 'PRAutoBlogger_Pipeline_Runner', false ) ) {
|
||||
// phpcs:ignore Squiz.Strings.DoubleQuoteUsage.NotRequired
|
||||
eval( 'class PRAutoBlogger_Pipeline_Runner {
|
||||
public function set_skip_dedup($v){ return $this; }
|
||||
public function orchestrate_only($ct){ return []; }
|
||||
}' );
|
||||
}
|
||||
$spawn_called = false;
|
||||
Functions\when( 'spawn_cron' )->alias( function() use ( &$spawn_called ) {
|
||||
$spawn_called = true;
|
||||
} );
|
||||
\PRAutoBlogger_Generation_Checkpoint_Runner::set_sync_mode( true );
|
||||
\PRAutoBlogger_Generation_Checkpoint_Runner::on_orchestrate_tick();
|
||||
\PRAutoBlogger_Generation_Checkpoint_Runner::set_sync_mode( false );
|
||||
$this->assertNotContains(
|
||||
\PRAutoBlogger_Generation_Checkpoint_Runner::GENERATE_ACTION,
|
||||
$this->scheduled,
|
||||
'sync mode: on_orchestrate_tick must not schedule GENERATE_ACTION'
|
||||
);
|
||||
$this->assertFalse( $spawn_called, 'sync mode: must not call spawn_cron' );
|
||||
}
|
||||
|
||||
/**
|
||||
* sync_mode=false: on_generate_tick() with ideas remaining DOES schedule
|
||||
* GENERATE_ACTION (regression guard — async path unaffected by sync guard).
|
||||
*/
|
||||
public function test_generate_tick_async_mode_schedules_generate_action(): void {
|
||||
$run_id = 'async-regression-uuid';
|
||||
$this->options['prautoblogger_article_queue'] = array(
|
||||
'run_id' => $run_id,
|
||||
'ideas' => array( $this->make_idea( 'A' ), $this->make_idea( 'B' ) ),
|
||||
'results' => array( 'generated' => 0, 'published' => 0, 'rejected' => 0, 'cost' => 0.0 ),
|
||||
);
|
||||
$wpdb = $this->create_mock_wpdb();
|
||||
$wpdb->options = 'wp_options';
|
||||
$GLOBALS['wpdb'] = $wpdb;
|
||||
$wpdb->method( 'get_row' )->willReturn( array( 'status' => 'running', 'ceiling_usd' => '0' ) );
|
||||
$wpdb->method( 'query' )->willReturn( 1 );
|
||||
$wpdb->method( 'get_var' )->willReturn( null );
|
||||
if ( ! class_exists( 'PRAutoBlogger_Article_Worker', false ) ) {
|
||||
// phpcs:ignore Squiz.Strings.DoubleQuoteUsage.NotRequired
|
||||
eval( 'class PRAutoBlogger_Article_Worker {
|
||||
public function __construct($ct){}
|
||||
public function generate($idea){ return ["generated"=>1,"published"=>1,"rejected"=>0,"cost"=>0.01]; }
|
||||
}' );
|
||||
}
|
||||
if ( ! class_exists( 'PRAutoBlogger_Post_Assembler', false ) ) {
|
||||
// phpcs:ignore Squiz.Strings.DoubleQuoteUsage.NotRequired
|
||||
eval( 'class PRAutoBlogger_Post_Assembler { public static function amortize_research_costs($r){} }' );
|
||||
}
|
||||
\PRAutoBlogger_Generation_Checkpoint_Runner::set_sync_mode( false );
|
||||
\PRAutoBlogger_Generation_Checkpoint_Runner::on_generate_tick();
|
||||
$this->assertContains(
|
||||
\PRAutoBlogger_Generation_Checkpoint_Runner::GENERATE_ACTION,
|
||||
$this->scheduled,
|
||||
'async mode: on_generate_tick must schedule GENERATE_ACTION when ideas remain'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user