PR Vision v0.2.0: admin/settings interface + correctness fixes

Requirements 1-8 + all non-negotiables:

1. Model manager (CRUD): PRV_Model_Registry, prv_models v2 option, versioned
   idempotent migration from v0.1.x flat-string format, Settings page CRUD.

2. Per-model run-health: PRV_Model_Registry::update_health() after each run;
   health badges (Healthy/Retired?/Disabled/Unknown) in model table + dashboard.

3. Metric comparability: PRV_Config_Version stamps every run with config_version;
   save-bar warning on scoring-relevant changes; orphaned rows excluded by version.

4. Projected cost at save: PRV_Config::get_projected_cost(); over-cap warning;
   prv_last_run_truncated option + visible notice when cap hit mid-run.

5. Config surface: peptide set, intents, cadence (reschedules cron), budget cap;
   all validated + sanitized; next-run timestamp shown.

6. API-key three-state: not-defined / defined-ok / defined-failed; derived from
   ledger; never displays the key.

7. Run-lock: PRV_Run_Lock (transient); cron tick skips if locked; Run-now
   refuses with clear message; lock released in finally block.

8. Design fixes: dark-ink focus ring on bright fills; disabled-row full AA
   contrast (no opacity); toggle disabled on retired rows; save-bar-level
   warning (role=alert); chip text #B4BDC7 6.83:1 AA; keyboard-sortable headers
   (<button>+aria-sort); aria-live on Test chip; z-index:50 save-bar;
   run-now double-fire guard; @media print light overrides.

New: PRV_Upgrader (runs migrations on plugins_loaded, not just activation),
PRV_Config_Version, PRV_Run_Lock, PRV_Settings_Page, PRV_Settings_Renderer,
PRV_Model_Manager_Table, PRV_Model_Test_Ajax.

Tests: test-model-registry, test-run-lock, test-config-version,
       test-projected-cost, test-cron-reschedule (+ updated probe-runner,
       uninstall, bootstrap).

Schema: config_version INT column added via dbDelta (idempotent).
Uninstall: purges all v0.2 prv_* options + transients.
This commit is contained in:
peptiderepo
2026-06-14 06:43:54 +00:00
parent 401077fe45
commit 8274d54a5e
26 changed files with 2758 additions and 435 deletions

View File

@@ -0,0 +1,85 @@
<?php
/**
* Tests for PRV_Run_Lock: acquire/release/is_locked concurrency guard.
*
* @package PrVision
*/
declare(strict_types=1);
require_once __DIR__ . '/../bootstrap.php';
echo "=== PRV Run Lock Tests ===\n";
// ── Test: acquire returns true when not locked ────────────────────────────
prv_test_reset();
prv_assert( PRV_Run_Lock::acquire(), 'acquire: returns true when lock is free' );
// ── Test: is_locked true while acquired ──────────────────────────────────
prv_assert( PRV_Run_Lock::is_locked(), 'is_locked: true immediately after acquire' );
// ── Test: second acquire returns false (lock busy) ───────────────────────
prv_assert( false === PRV_Run_Lock::acquire(), 'acquire: returns false when already locked' );
// ── Test: release clears the lock ────────────────────────────────────────
PRV_Run_Lock::release();
prv_assert( false === PRV_Run_Lock::is_locked(), 'is_locked: false after release' );
// ── Test: acquire succeeds again after release ───────────────────────────
prv_assert( PRV_Run_Lock::acquire(), 'acquire: succeeds again after release' );
PRV_Run_Lock::release();
// ── Test: locked_since returns null when not locked ──────────────────────
prv_test_reset();
prv_assert( null === PRV_Run_Lock::locked_since(), 'locked_since: null when not locked' );
// ── Test: locked_since returns non-null when locked ──────────────────────
PRV_Run_Lock::acquire();
$since = PRV_Run_Lock::locked_since();
prv_assert( null !== $since, 'locked_since: non-null when locked' );
prv_assert( $since >= 0, 'locked_since: >= 0 seconds' );
PRV_Run_Lock::release();
// ── Test: probe runner refuses when locked (skipped_error sentinel) ───────
prv_test_reset();
PRV_Model_Registry::run_migration_v2();
$GLOBALS['prv_test_state']['options']['prv_peptides'] = [ [ 'slug' => 'bpc-157', 'label' => 'BPC-157' ] ];
$GLOBALS['prv_test_state']['options']['prv_prompt_intents'] = [ 'what is {peptide}' ];
// Pre-acquire the lock.
PRV_Run_Lock::acquire();
if ( ! defined( 'PRV_OPENROUTER_API_KEY' ) ) {
define( 'PRV_OPENROUTER_API_KEY', 'sk-or-test-key' );
}
if ( ! defined( 'PRV_CF_ACCOUNT_ID' ) ) {
define( 'PRV_CF_ACCOUNT_ID', '' );
}
if ( ! defined( 'PRV_CF_GATEWAY_ID' ) ) {
define( 'PRV_CF_GATEWAY_ID', '' );
}
$runner = new PRV_Probe_Runner( new PRV_Cost_Ledger() );
$counts = $runner->run();
// When lock is busy, skipped_error is -1 (sentinel) and probed is 0.
prv_assert_equals( 0, $counts['probed'], 'run-lock: runner returns 0 probed when locked' );
prv_assert_equals( -1, $counts['skipped_error'], 'run-lock: skipped_error is -1 sentinel when lock busy' );
PRV_Run_Lock::release();
// ── Test: runner releases lock even on exception (lock cleanup) ──────────
prv_test_reset();
PRV_Model_Registry::run_migration_v2();
prv_assert( false === PRV_Run_Lock::is_locked(), 'run-lock cleanup: lock released after runner completes' );
exit( prv_test_summary() );