Admin-PM-Liste: KI-Pruefungs-Modal + geschaerfte KI-Prompts
- Spalten umsortiert (Aktionen, Datum, KI-Pruefung zuerst); Pruefen-Button nur noch Icon, oeffnet Detail-Modal mit Klassifikation, Begruendung, Content-Score inkl. Faktor-Breakdown und Re-Check (wire:poll bis Queue durch) - Content-Score: Bild-Punkte (10) systemseitig statt KI (nur ein Upload-Bild moeglich), Quellen 10->5, Pressestil 20->25; Breakdown wandert ins Audit-Log - Klassifikations-Prompt prueft gegen aktive Ablehnungskategorien (K1-K6, rejection_categories): klarer Verstoss => direkt rot mit Kategorie-Code Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
de532feec2
commit
3ae57d9dba
7 changed files with 613 additions and 89 deletions
|
|
@ -1,10 +1,16 @@
|
|||
<?php
|
||||
|
||||
use App\Enums\PressReleaseClassification;
|
||||
use App\Enums\PressReleaseContentTier;
|
||||
use App\Enums\PressReleaseStatus;
|
||||
use App\Jobs\ClassifyPressRelease;
|
||||
use App\Jobs\ScorePressRelease;
|
||||
use App\Models\AdminPreset;
|
||||
use App\Models\KiAudit;
|
||||
use App\Models\PressRelease;
|
||||
use App\Models\User;
|
||||
use Database\Seeders\RolesAndPermissionsSeeder;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Livewire\Volt\Volt as LivewireVolt;
|
||||
use Tests\TestCase;
|
||||
|
||||
|
|
@ -124,6 +130,140 @@ test('press release index renders confirmation modals for status actions', funct
|
|||
->assertSee('Pressemitteilung archivieren?');
|
||||
});
|
||||
|
||||
test('ai check modal shows classification details from the latest audit', function () {
|
||||
/** @var TestCase $this */
|
||||
$this->seed(RolesAndPermissionsSeeder::class);
|
||||
|
||||
$admin = User::factory()->create(['is_active' => true]);
|
||||
$admin->assignRole('admin');
|
||||
$this->actingAs($admin);
|
||||
|
||||
$pressRelease = PressRelease::factory()
|
||||
->inReview()
|
||||
->create(['classification' => PressReleaseClassification::Yellow->value]);
|
||||
|
||||
KiAudit::factory()
|
||||
->classification(PressReleaseClassification::Yellow)
|
||||
->create([
|
||||
'press_release_id' => $pressRelease->id,
|
||||
'reason' => 'Werbliche Sprache im Titel gefunden.',
|
||||
'provider' => 'anthropic',
|
||||
]);
|
||||
|
||||
LivewireVolt::test('admin.press-releases.index')
|
||||
->call('openAiCheck', $pressRelease->id)
|
||||
->assertSet('aiCheckId', $pressRelease->id)
|
||||
->assertSee('Werbliche Sprache im Titel gefunden.')
|
||||
->assertSee('anthropic')
|
||||
->assertSee('Erneut prüfen');
|
||||
});
|
||||
|
||||
test('ai check modal shows empty state and start button for unchecked press releases', function () {
|
||||
/** @var TestCase $this */
|
||||
$this->seed(RolesAndPermissionsSeeder::class);
|
||||
|
||||
$admin = User::factory()->create(['is_active' => true]);
|
||||
$admin->assignRole('admin');
|
||||
$this->actingAs($admin);
|
||||
|
||||
$pressRelease = PressRelease::factory()
|
||||
->inReview()
|
||||
->create(['classification' => null]);
|
||||
|
||||
LivewireVolt::test('admin.press-releases.index')
|
||||
->call('openAiCheck', $pressRelease->id)
|
||||
->assertSee('Noch nicht geprüft')
|
||||
->assertSee('Noch nicht bewertet')
|
||||
->assertSee('Prüfung starten');
|
||||
});
|
||||
|
||||
test('ai check modal shows the content score breakdown from the audit raw response', function () {
|
||||
/** @var TestCase $this */
|
||||
$this->seed(RolesAndPermissionsSeeder::class);
|
||||
|
||||
$admin = User::factory()->create(['is_active' => true]);
|
||||
$admin->assignRole('admin');
|
||||
$this->actingAs($admin);
|
||||
|
||||
$pressRelease = PressRelease::factory()
|
||||
->inReview()
|
||||
->create([
|
||||
'classification' => PressReleaseClassification::Green->value,
|
||||
'content_score' => 62,
|
||||
'content_tier' => PressReleaseContentTier::Geprueft->value,
|
||||
]);
|
||||
|
||||
KiAudit::factory()
|
||||
->contentScore(62)
|
||||
->create([
|
||||
'press_release_id' => $pressRelease->id,
|
||||
'provider' => 'openai',
|
||||
'raw_response' => [
|
||||
'breakdown' => [
|
||||
'pressestil' => 12,
|
||||
'struktur' => 8,
|
||||
'bild' => 0,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
LivewireVolt::test('admin.press-releases.index')
|
||||
->call('openAiCheck', $pressRelease->id)
|
||||
->assertSee('Pressestil')
|
||||
->assertSee('12 / 25')
|
||||
->assertSee('Struktur')
|
||||
->assertSee('8 / 15')
|
||||
->assertSee('Bildmaterial')
|
||||
->assertSee('0 / 10');
|
||||
});
|
||||
|
||||
test('ai check modal explains missing reason for green classifications', function () {
|
||||
/** @var TestCase $this */
|
||||
$this->seed(RolesAndPermissionsSeeder::class);
|
||||
|
||||
$admin = User::factory()->create(['is_active' => true]);
|
||||
$admin->assignRole('admin');
|
||||
$this->actingAs($admin);
|
||||
|
||||
$pressRelease = PressRelease::factory()
|
||||
->inReview()
|
||||
->create(['classification' => PressReleaseClassification::Green->value]);
|
||||
|
||||
KiAudit::factory()
|
||||
->classification(PressReleaseClassification::Green)
|
||||
->create([
|
||||
'press_release_id' => $pressRelease->id,
|
||||
'reason' => null,
|
||||
]);
|
||||
|
||||
LivewireVolt::test('admin.press-releases.index')
|
||||
->call('openAiCheck', $pressRelease->id)
|
||||
->assertSee('bei Grün liefert die KI keine Begründung');
|
||||
});
|
||||
|
||||
test('runAiCheck from modal dispatches jobs without routing and marks the run as pending', function () {
|
||||
/** @var TestCase $this */
|
||||
$this->seed(RolesAndPermissionsSeeder::class);
|
||||
Queue::fake();
|
||||
|
||||
$admin = User::factory()->create(['is_active' => true]);
|
||||
$admin->assignRole('admin');
|
||||
$this->actingAs($admin);
|
||||
|
||||
$pressRelease = PressRelease::factory()
|
||||
->inReview()
|
||||
->create(['classification' => null]);
|
||||
|
||||
LivewireVolt::test('admin.press-releases.index')
|
||||
->call('openAiCheck', $pressRelease->id)
|
||||
->assertSet('aiCheckStartedAt', null)
|
||||
->call('runAiCheck')
|
||||
->assertSee('Prüfung läuft');
|
||||
|
||||
Queue::assertPushed(ClassifyPressRelease::class, fn (ClassifyPressRelease $job): bool => $job->pressReleaseId === $pressRelease->id && $job->route === false);
|
||||
Queue::assertPushed(ScorePressRelease::class, fn (ScorePressRelease $job): bool => $job->pressReleaseId === $pressRelease->id);
|
||||
});
|
||||
|
||||
test('show page renders confirmation modals for status actions', function () {
|
||||
/** @var TestCase $this */
|
||||
$this->seed(RolesAndPermissionsSeeder::class);
|
||||
|
|
|
|||
|
|
@ -7,12 +7,16 @@ use App\Mail\PressReleasePublished;
|
|||
use App\Mail\PressReleaseRejected;
|
||||
use App\Models\KiAudit;
|
||||
use App\Models\PressRelease;
|
||||
use App\Models\RejectionCategory;
|
||||
use App\Models\User;
|
||||
use App\Services\PressRelease\Classification\ClassificationManager;
|
||||
use App\Services\PressRelease\PressReleaseService;
|
||||
use Database\Seeders\RejectionCategorySeeder;
|
||||
use Illuminate\Http\Client\Request;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Tests\TestCase;
|
||||
|
||||
function fakeOpenAiClassification(string $classification, array $reasons = []): void
|
||||
{
|
||||
|
|
@ -66,6 +70,30 @@ test('classify job records a yellow classification with reasons', function () {
|
|||
expect($audit->reason)->toContain('Werbesprache');
|
||||
});
|
||||
|
||||
test('openai classification prompt lists the active rejection categories', function () {
|
||||
/** @var TestCase $this */
|
||||
$this->seed(RejectionCategorySeeder::class);
|
||||
RejectionCategory::query()->where('code', 'K6')->update(['active' => false]);
|
||||
|
||||
fakeOpenAiClassification('green');
|
||||
|
||||
$pressRelease = PressRelease::factory()->create(['title' => 'Sauber', 'text' => 'Inhalt']);
|
||||
|
||||
(new ClassifyPressRelease($pressRelease->id))->handle(
|
||||
app(ClassificationManager::class),
|
||||
app(PressReleaseService::class),
|
||||
);
|
||||
|
||||
Http::assertSent(function (Request $request): bool {
|
||||
$systemPrompt = (string) data_get($request->data(), 'messages.0.content');
|
||||
|
||||
return str_contains($systemPrompt, 'K1 Rechtswidrige Inhalte')
|
||||
&& str_contains($systemPrompt, 'K5 Rechte Dritter')
|
||||
&& ! str_contains($systemPrompt, 'K6 Kein Pressecharakter')
|
||||
&& str_contains($systemPrompt, 'markiere die Mitteilung dann direkt rot');
|
||||
});
|
||||
});
|
||||
|
||||
test('classify job falls back to the deterministic driver when openai fails', function () {
|
||||
config()->set('scoring.classification.provider', 'openai');
|
||||
config()->set('services.openai.api_key', 'test-key');
|
||||
|
|
|
|||
|
|
@ -62,6 +62,42 @@ test('score job stores the openai score, derives the tier and writes an audit',
|
|||
expect($audit->result)->toBe('72');
|
||||
});
|
||||
|
||||
test('openai score awards the full image points when an upload image exists', function () {
|
||||
fakeOpenAiScore(62);
|
||||
|
||||
$pressRelease = PressRelease::factory()->create();
|
||||
$pressRelease->images()->create([
|
||||
'disk' => 'public',
|
||||
'path' => 'press-releases/'.$pressRelease->id.'/images/title.jpg',
|
||||
'is_preview' => true,
|
||||
'sort_order' => 1,
|
||||
]);
|
||||
|
||||
(new ScorePressRelease($pressRelease->id))->handle(app(ContentScoreManager::class));
|
||||
|
||||
expect($pressRelease->fresh()->content_score)->toBe(72);
|
||||
|
||||
$audit = KiAudit::where('press_release_id', $pressRelease->id)
|
||||
->where('type', KiAudit::TYPE_CONTENT_SCORE)
|
||||
->firstOrFail();
|
||||
expect($audit->raw_response['breakdown']['bild'])->toBe(10);
|
||||
});
|
||||
|
||||
test('openai score without image stays uncapped at the ai maximum of 90', function () {
|
||||
fakeOpenAiScore(100);
|
||||
|
||||
$pressRelease = PressRelease::factory()->create();
|
||||
|
||||
(new ScorePressRelease($pressRelease->id))->handle(app(ContentScoreManager::class));
|
||||
|
||||
expect($pressRelease->fresh()->content_score)->toBe(90);
|
||||
|
||||
$audit = KiAudit::where('press_release_id', $pressRelease->id)
|
||||
->where('type', KiAudit::TYPE_CONTENT_SCORE)
|
||||
->firstOrFail();
|
||||
expect($audit->raw_response['breakdown']['bild'])->toBe(0);
|
||||
});
|
||||
|
||||
test('score job falls back to the deterministic driver when openai fails', function () {
|
||||
config()->set('scoring.content_score.provider', 'openai');
|
||||
config()->set('services.openai.api_key', 'test-key');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue