Files
prautoblogger/tests/unit/Services/ImageModelRegistryTest.php
peptiderepo 2cacaa3512 v0.9.0: Runware FLUX.1 schnell as default image provider
New Runware image backend at ~$0.0006/image (FLUX.1 schnell) — 65× cheaper
than Gemini 2.5 Flash Image. Provider mirrors OpenRouter's split: interface
+ provider + support + pricing + batch, all under the 300-line cap. Batch
class uses curl_multi for true parallel A/B dispatch — wall-clock drops to
the slowest single image instead of the sum.

Changes:
- Add PRAutoBlogger_Runware_Image_Provider + Pricing + Support + Batch
- Flip PRAUTOBLOGGER_DEFAULT_IMAGE_PROVIDER/MODEL to runware:100@1
- Add prautoblogger_runware_api_key settings field (encrypted at rest)
- v0.9.0 one-time migration flips legacy default model + re-derives provider
- Wire runware branch into Image_Pipeline::create_default_provider()
- Add runware:100@1 and runware:101@1 to Image_Model_Registry (defaults top)
- Update image prompt builder: no more anthropomorphized molecules;
  prefer concrete human-scale scenes (gym bros, doctors, scientists)
- ARCHITECTURE.md + CHANGELOG.md updated with new integration + decision
- Unit tests for pricing, support, provider; update model registry test

Cost impact at 100 images/day (50 articles × A/B):
- Before (Gemini via OpenRouter): $3.90/day ≈ $117/mo
- After  (FLUX schnell via Runware): $0.06/day ≈ $1.80/mo
Net saving: ~$115/mo
2026-04-21 15:56:35 +00:00

86 lines
2.6 KiB
PHP

<?php
/**
* Tests for PRAutoBlogger_Image_Model_Registry.
*
* The admin save flow (v0.8.0) collapses Provider and Image Model into a
* single dropdown and derives the provider from the model via
* Image_Model_Registry::provider_for(). This test pins that mapping down
* so a registry edit that breaks the contract fails CI.
*
* @package PRAutoBlogger\Tests\Services
*/
namespace PRAutoBlogger\Tests\Services;
use PRAutoBlogger\Tests\BaseTestCase;
class ImageModelRegistryTest extends BaseTestCase {
/**
* Every entry returned by get_models() must carry a non-empty id and
* a provider of 'runware', 'openrouter', or 'cloudflare'. If this breaks, the
* admin save flow will silently drop the provider derivation.
*/
public function test_every_registry_entry_has_id_and_known_provider(): void {
$models = \PRAutoBlogger_Image_Model_Registry::get_models();
$this->assertNotEmpty( $models );
foreach ( $models as $model ) {
$this->assertArrayHasKey( 'id', $model );
$this->assertNotEmpty( $model['id'] );
$this->assertArrayHasKey( 'provider', $model );
$this->assertContains(
$model['provider'],
[ 'runware', 'openrouter', 'cloudflare' ],
sprintf( 'Unexpected provider %s for model %s', (string) $model['provider'], (string) $model['id'] )
);
}
}
/**
* provider_for() returns the paired provider for a known model id.
* This is the core of the v0.8.0 collapsed-dropdown contract.
*/
public function test_provider_for_returns_paired_provider_for_known_model(): void {
$this->assertSame(
'cloudflare',
\PRAutoBlogger_Image_Model_Registry::provider_for( 'flux-1-schnell' )
);
$this->assertSame(
'openrouter',
\PRAutoBlogger_Image_Model_Registry::provider_for( 'google/gemini-2.5-flash-image' )
);
}
/**
* Runware model ids (added v0.9.0) resolve to the 'runware' provider.
* This test pins the v0.9.0 default flip so a registry regression
* that loses the Runware entries fails CI loudly.
*/
public function test_provider_for_runware_models(): void {
$this->assertSame(
'runware',
\PRAutoBlogger_Image_Model_Registry::provider_for( 'runware:100@1' )
);
$this->assertSame(
'runware',
\PRAutoBlogger_Image_Model_Registry::provider_for( 'runware:101@1' )
);
}
/**
* Unknown model ids return an empty string so callers can distinguish
* "not in registry" from a valid provider and show a settings error.
*/
public function test_provider_for_returns_empty_for_unknown_model(): void {
$this->assertSame(
'',
\PRAutoBlogger_Image_Model_Registry::provider_for( 'nonexistent/model' )
);
$this->assertSame(
'',
\PRAutoBlogger_Image_Model_Registry::provider_for( '' )
);
}
}