peptide-geo-monitor v0.1.0: internal AI-visibility dashboard (#1)

New internal plugin: weekly LLM probes of core peptides (Perplexity sonar + GPT/Gemini-search via OpenRouter/CF gateway) -> custom table -> wp-admin trendline + standings. Provider interface + cost ledger w/ hard $5/mo cap + collector/panel seam (AI-visibility only). v1 = AI-visibility only.

QA: APPROVE-WITH-P2-NOTES — qa-reviews/peptide-geo-monitor/2026-06-13-f488f4a966cbb9e771d3abc20daee3fa49074520.md (P2 follow-ups: ltrim www display bug, PHPCS mandatory, dead cache)

Agent-Session: geomonitor v0.1.0 merge
This commit is contained in:
peptiderepo
2026-06-13 15:34:33 +07:00
committed by GitHub
parent ba58ead521
commit 46fda89e18
39 changed files with 3909 additions and 2 deletions

View File

@@ -0,0 +1,80 @@
<?php
/**
* Tests for the visibility score formula in PGM_Ai_Visibility_Collector.
*
* Score formula (CONTEXT.md):
* base_score = cited_probes / total_probes
* position_bonus = Σ(1/our_position for cited) / total_probes
* visibility_score = round((base_score + position_bonus) / 2, 4)
*
* @package PeptideGeoMonitor
*/
declare(strict_types=1);
require_once __DIR__ . '/../bootstrap.php';
echo "=== PGM Score Calculation Tests ===\n";
// Instantiate with a null ledger (no DB calls in these tests).
$collector = new PGM_Ai_Visibility_Collector( null );
// ── Test: zero total → score 0 ──────────────────────────────────────────
pgm_test_reset();
pgm_assert_equals( 0.0, $collector->compute_score( 0, 0, 0.0 ), 'score: zero total returns 0.0' );
// ── Test: all cited, position 1 ─────────────────────────────────────────
// 10 probes, all cited at position 1
// base_score = 10/10 = 1.0
// position_bonus = (1+1+1+…)/10 = 10/10 = 1.0
// score = (1.0 + 1.0) / 2 = 1.0
pgm_test_reset();
pgm_assert_equals( 1.0, $collector->compute_score( 10, 10, 10.0 ), 'score: all cited at position 1 → 1.0' );
// ── Test: none cited ────────────────────────────────────────────────────
// 10 probes, 0 cited, position_sum=0
// base_score = 0, position_bonus = 0 → score = 0
pgm_test_reset();
pgm_assert_equals( 0.0, $collector->compute_score( 0, 10, 0.0 ), 'score: none cited → 0.0' );
// ── Test: half cited at position 2 ──────────────────────────────────────
// 10 probes, 5 cited each at position 2 → position_sum = 5*(1/2) = 2.5
// base_score = 5/10 = 0.5
// position_bonus = 2.5/10 = 0.25
// score = (0.5 + 0.25) / 2 = 0.375
pgm_test_reset();
$score = $collector->compute_score( 5, 10, 2.5 );
pgm_assert_equals( 0.375, $score, 'score: half cited at position 2 → 0.375' );
// ── Test: single probe, cited at position 3 ─────────────────────────────
// 1 probe, 1 cited, position_sum = 1/3 ≈ 0.3333
// base_score = 1.0
// position_bonus = 0.3333
// score = (1.0 + 0.3333) / 2 ≈ 0.6667 (rounded to 4 decimals)
pgm_test_reset();
$score = $collector->compute_score( 1, 1, 1.0 / 3.0 );
pgm_assert_equals( 0.6667, $score, 'score: single probe cited at position 3 → 0.6667' );
// ── Test: score is bounded [0, 1] ───────────────────────────────────────
// Extreme: position_sum could theoretically exceed total but that's logically
// impossible with 1-based positions (position_sum ≤ cited_count ≤ total).
// Verify edge case: 1 probe, 1 cited, position 1
pgm_test_reset();
pgm_assert( $collector->compute_score( 1, 1, 1.0 ) <= 1.0, 'score: never exceeds 1.0' );
pgm_assert( $collector->compute_score( 0, 10, 0.0 ) >= 0.0, 'score: never below 0.0' );
// ── Test: precision — 4 decimal places ──────────────────────────────────
pgm_test_reset();
$score = $collector->compute_score( 3, 7, 1.5 );
// base = 3/7 ≈ 0.4286, bonus = 1.5/7 ≈ 0.2143, avg ≈ 0.3214
$expected = round( ( 3.0 / 7.0 + 1.5 / 7.0 ) / 2.0, 4 );
pgm_assert_equals( $expected, $score, 'score: 4-decimal precision maintained' );
exit( pgm_test_summary() );