Files
Jeremy 8b02abb0aa feat: AI self-healing store config
Add AiConfigHealer to bootstrap or repair a store config via a
tool-using structured agent (fetch/css/regex tools, HealingContext,
shared StrategyExtractor).

- Run healing before the one-shot enhancer; AI-bootstrap a store config
  when product create would otherwise fail; StoreUrl validation defers
  to self-healing when enabled
- Per-feature AI provider resolution (AiFeature enum) and settings
- Per-store self-healing opt-out plus cooldown; log heal attempts and
  unusable proposals
- Heal with AI action with non-persisting preview/apply/discard in the
  store test modal; prompt switches to browser scraping when blocked
2026-06-09 15:07:40 +10:00

38 lines
1.3 KiB
PHP

<?php
namespace Tests\Feature\Models;
use App\Models\Store;
use App\Models\Url;
use App\Services\AiConfigHealer;
use App\Services\AiScrapeEnhancer;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Mockery;
use Tests\TestCase;
class UrlHealingOrderTest extends TestCase
{
use RefreshDatabase;
public function test_heal_runs_before_enhancer_and_recovered_price_is_saved(): void
{
$store = Store::factory()->create(['settings' => ['scraper_service' => 'http']]);
$url = Url::factory()->for($store)->create(['url' => 'https://shop.test/x']);
$this->mock(AiConfigHealer::class, fn ($m) => $m->shouldReceive('heal')
->once()
->andReturnUsing(fn ($u, $r) => array_merge($r, ['price' => '9.99'])));
// Enhancer must receive the price the healer recovered (proves ordering).
$this->mock(AiScrapeEnhancer::class, fn ($m) => $m->shouldReceive('enhance')
->once()
->with(Mockery::any(), Mockery::on(fn ($r) => data_get($r, 'price') === '9.99'))
->andReturnUsing(fn ($u, $r) => $r));
$price = $url->updatePrice(null, ['price' => null, 'body' => '<html></html>', 'availability' => null]);
$this->assertNotNull($price);
$this->assertSame(9.99, (float) $price->price);
}
}