PR Vision v0.1.1: rename from peptide-geo-monitor + P2 fixes

- Exhaustive rename: PGM_ -> PRV_, pgm_ -> prv_, text domain and
  slug peptide-geo-monitor -> pr-vision, admin menu GEO Monitor ->
  PR Vision, main file peptide-geo-monitor.php -> pr-vision.php,
  DB table pgm_ai_visibility -> prv_ai_visibility.
- P2-A: replace ltrim($host,'www.') character-mask with
  str_starts_with/substr prefix strip in PRV_Citation_Detector.
  Adds test coverage for wikipedia.org, webmd.com survival.
- P2-B: drop continue-on-error: true from PHPCS CI step;
  WordPress Coding Standards now gates the build.
- P2-C: remove dead in-run cache from PRV_Probe_Runner::run();
  each (peptide, intent, model) triplet is visited once per run,
  cache hit is structurally impossible.
- Version bump 0.1.0 -> 0.1.1 + CHANGELOG [0.1.1] entry.

Agent-Session: pr-vision rename v0.1.1
This commit is contained in:
peptiderepo
2026-06-13 09:32:56 +00:00
parent 46fda89e18
commit 60ae52663c
39 changed files with 852 additions and 830 deletions

View File

@@ -2,25 +2,25 @@
/**
* Tests for provider response parsing.
*
* Exercises PGM_Perplexity_Provider::parse_response() and
* PGM_OpenRouter_Provider::parse_response() with mock HTTP responses,
* Exercises PRV_Perplexity_Provider::parse_response() and
* PRV_OpenRouter_Provider::parse_response() with mock HTTP responses,
* verifying domain extraction, citation detection, and cost calculation.
*
* @package PeptideGeoMonitor
* @package PrVision
*/
declare(strict_types=1);
require_once __DIR__ . '/../bootstrap.php';
echo "=== PGM Provider Response Parsing Tests ===\n";
echo "=== PRV Provider Response Parsing Tests ===\n";
// ── PGM_Perplexity_Provider parsing ─────────────────────────────────────
// ── PRV_Perplexity_Provider parsing ─────────────────────────────────────
$provider = new PGM_Perplexity_Provider( null, new PGM_Citation_Detector() );
$provider = new PRV_Perplexity_Provider( null, new PRV_Citation_Detector() );
// Test: cited via citations array
pgm_test_reset();
prv_test_reset();
$data = [
'choices' => [[ 'message' => [ 'content' => 'BPC-157 is a peptide. See peptiderepo.com' ] ]],
'citations' => [
@@ -30,34 +30,34 @@ $data = [
'usage' => [ 'total_tokens' => 500 ],
];
$result = $provider->parse_response( $data );
pgm_assert( $result->is_cited(), 'Perplexity: cited=true when peptiderepo.com in citations' );
pgm_assert_equals( 1, $result->get_our_position(), 'Perplexity: position=1 when first in citations' );
pgm_assert( count( $result->get_source_domains() ) === 2, 'Perplexity: 2 source domains extracted' );
pgm_assert_equals( 500 * 0.000001, $result->get_cost_usd(), 'Perplexity: cost from token usage' );
prv_assert( $result->is_cited(), 'Perplexity: cited=true when peptiderepo.com in citations' );
prv_assert_equals( 1, $result->get_our_position(), 'Perplexity: position=1 when first in citations' );
prv_assert( count( $result->get_source_domains() ) === 2, 'Perplexity: 2 source domains extracted' );
prv_assert_equals( 500 * 0.000001, $result->get_cost_usd(), 'Perplexity: cost from token usage' );
// Test: not cited, no citations
pgm_test_reset();
prv_test_reset();
$data_empty = [
'choices' => [[ 'message' => [ 'content' => 'BPC-157 info here.' ] ]],
'citations' => [],
'usage' => [ 'total_tokens' => 200 ],
];
$result_empty = $provider->parse_response( $data_empty );
pgm_assert( ! $result_empty->is_cited(), 'Perplexity: cited=false with empty citations' );
pgm_assert_equals( null, $result_empty->get_our_position(), 'Perplexity: position=null when not cited' );
prv_assert( ! $result_empty->is_cited(), 'Perplexity: cited=false with empty citations' );
prv_assert_equals( null, $result_empty->get_our_position(), 'Perplexity: position=null when not cited' );
// Test: excerpt truncated to 500 chars
pgm_test_reset();
prv_test_reset();
$long_content = str_repeat( 'a', 600 );
$data_long = [
'choices' => [[ 'message' => [ 'content' => $long_content ] ]],
'citations' => [],
];
$result_long = $provider->parse_response( $data_long );
pgm_assert_equals( 500, mb_strlen( $result_long->get_raw_excerpt() ), 'Perplexity: excerpt truncated to 500 chars' );
prv_assert_equals( 500, mb_strlen( $result_long->get_raw_excerpt() ), 'Perplexity: excerpt truncated to 500 chars' );
// Test: object-style citations
pgm_test_reset();
prv_test_reset();
$data_obj = [
'choices' => [[ 'message' => [ 'content' => 'answer' ] ]],
'citations' => [
@@ -66,26 +66,26 @@ $data_obj = [
],
];
$result_obj = $provider->parse_response( $data_obj );
pgm_assert( $result_obj->is_cited(), 'Perplexity: object-style citations — cited=true' );
pgm_assert_equals( 1, $result_obj->get_our_position(), 'Perplexity: object-style — position=1' );
prv_assert( $result_obj->is_cited(), 'Perplexity: object-style citations — cited=true' );
prv_assert_equals( 1, $result_obj->get_our_position(), 'Perplexity: object-style — position=1' );
// Test: fallback cost when no usage data
pgm_test_reset();
prv_test_reset();
$data_no_usage = [
'choices' => [[ 'message' => [ 'content' => 'answer' ] ]],
'citations' => [],
];
$result_no_usage = $provider->parse_response( $data_no_usage );
pgm_assert_equals( PGM_Perplexity_Provider::ESTIMATED_COST_PER_PROBE, $result_no_usage->get_cost_usd(), 'Perplexity: fallback to ESTIMATED_COST_PER_PROBE when no usage' );
prv_assert_equals( PRV_Perplexity_Provider::ESTIMATED_COST_PER_PROBE, $result_no_usage->get_cost_usd(), 'Perplexity: fallback to ESTIMATED_COST_PER_PROBE when no usage' );
// ── PGM_OpenRouter_Provider parsing ─────────────────────────────────────
// ── PRV_OpenRouter_Provider parsing ─────────────────────────────────────
echo "\n--- OpenRouter provider parsing ---\n";
$or_provider = new PGM_OpenRouter_Provider( 'openai/gpt-4o-search-preview', null, new PGM_Citation_Detector() );
$or_provider = new PRV_OpenRouter_Provider( 'openai/gpt-4o-search-preview', null, new PRV_Citation_Detector() );
// Test: annotations path (structured citations)
pgm_test_reset();
prv_test_reset();
$data_ann = [
'choices' => [[
'message' => [
@@ -99,11 +99,11 @@ $data_ann = [
'usage' => [ 'total_tokens' => 300 ],
];
$result_ann = $or_provider->parse_response( $data_ann );
pgm_assert( $result_ann->is_cited(), 'OpenRouter: annotations path — cited=true' );
pgm_assert_equals( 1, $result_ann->get_our_position(), 'OpenRouter: annotations path — position=1' );
prv_assert( $result_ann->is_cited(), 'OpenRouter: annotations path — cited=true' );
prv_assert_equals( 1, $result_ann->get_our_position(), 'OpenRouter: annotations path — position=1' );
// Test: regex URL extraction fallback
pgm_test_reset();
prv_test_reset();
$data_regex = [
'choices' => [[
'message' => [
@@ -113,23 +113,23 @@ $data_regex = [
'usage' => [ 'total_tokens' => 150 ],
];
$result_regex = $or_provider->parse_response( $data_regex );
pgm_assert( $result_regex->is_cited(), 'OpenRouter: regex fallback — cited=true from inline URL' );
prv_assert( $result_regex->is_cited(), 'OpenRouter: regex fallback — cited=true from inline URL' );
// Test: not cited
pgm_test_reset();
prv_test_reset();
$data_no_cite = [
'choices' => [[ 'message' => [ 'content' => 'Some response without our domain.' ] ]],
];
$result_no_cite = $or_provider->parse_response( $data_no_cite );
pgm_assert( ! $result_no_cite->is_cited(), 'OpenRouter: not cited when peptiderepo.com absent from text' );
prv_assert( ! $result_no_cite->is_cited(), 'OpenRouter: not cited when peptiderepo.com absent from text' );
// Test: cost calculation from token usage
pgm_test_reset();
prv_test_reset();
$data_cost = [
'choices' => [[ 'message' => [ 'content' => 'test' ] ]],
'usage' => [ 'total_tokens' => 1000 ],
];
$result_cost = $or_provider->parse_response( $data_cost );
pgm_assert_equals( 1000 * 0.000002, $result_cost->get_cost_usd(), 'OpenRouter: cost from token usage (2$/1M)' );
prv_assert_equals( 1000 * 0.000002, $result_cost->get_cost_usd(), 'OpenRouter: cost from token usage (2$/1M)' );
exit( pgm_test_summary() );
exit( prv_test_summary() );