Phase 8 (Rest) + Umbauten vom 10./11.06.: - Ein Titelbild pro PM (Cover 1280x580), SVG-Platzhalter-Set + Picker, PressReleaseCoverImage-Resolver - Lizenz-/Rechteformular nach "Lizenztyp Bildupload" (7 Lizenztypen, Personen-/Sachrechte-Status, bedingte Pflichtfelder, Risikohinweise) - Veroeffentlichungs-Box vereinfacht (Embargo aus der Form-UI entfernt), geplante Termine in Europe/Berlin (Speicherung UTC, DISPLAY_TIMEZONE) - Quota-Stub (users.press_release_quota) + monatlicher Reset-Command - Einreichungs-Modal einheitlich in Show/Create/Edit; Ghost-Buttons auf filled; PM-Editor-Layout responsive entkoppelt (.pr-editor-layout) KI-Pruef-Pipeline (Phasen 1-5 des Entwicklungsplans): - API-Haertung: status nicht mehr per API setzbar, eigene Submit-Route durch denselben Funnel (Blacklist, Quota, Status-Log) - Klassifikation Rot/Gelb/Gruen asynchron (Queue classification, OpenAI-Treiber + deterministischer Fallback), ki_audits-Audit-Log - Routing: Rot -> rejected + Mail, Gelb -> Review-Queue, Gruen -> Auto-Publish; Scheduler publiziert nur gruene faellige PMs - Content-Score 0-100 -> Stufe (Standard/Geprueft/Hochwertig) inkl. Editor-Panel und Badges; Re-Klassifikation/-Score bei Aenderung - Admin: KI-Badge + Filter, On-Demand-Pruefung mit Anbieter-Override Suite: 442 passed, 4 skipped. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
114 lines
4.3 KiB
PHP
114 lines
4.3 KiB
PHP
<?php
|
|
|
|
use App\Enums\PressReleaseContentTier;
|
|
use App\Enums\PressReleaseStatus;
|
|
use App\Jobs\ScorePressRelease;
|
|
use App\Models\KiAudit;
|
|
use App\Models\PressRelease;
|
|
use App\Models\User;
|
|
use App\Services\PressRelease\ContentScore\ContentScoreManager;
|
|
use App\Services\PressRelease\PressReleaseService;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\Queue;
|
|
|
|
function fakeOpenAiScore(int $score): void
|
|
{
|
|
config()->set('scoring.content_score.provider', 'openai');
|
|
config()->set('services.openai.api_key', 'test-key');
|
|
|
|
Http::fake([
|
|
'*' => Http::response([
|
|
'choices' => [
|
|
['message' => ['content' => json_encode([
|
|
'score' => $score,
|
|
'breakdown' => ['pressestil' => 15],
|
|
])]],
|
|
],
|
|
], 200),
|
|
]);
|
|
}
|
|
|
|
test('tier mapping follows the configured thresholds', function () {
|
|
config()->set('scoring.content_score.tiers', ['gepruft' => 60, 'hochwertig' => 80]);
|
|
|
|
expect(PressReleaseContentTier::fromScore(45))->toBe(PressReleaseContentTier::Standard);
|
|
expect(PressReleaseContentTier::fromScore(60))->toBe(PressReleaseContentTier::Geprueft);
|
|
expect(PressReleaseContentTier::fromScore(79))->toBe(PressReleaseContentTier::Geprueft);
|
|
expect(PressReleaseContentTier::fromScore(80))->toBe(PressReleaseContentTier::Hochwertig);
|
|
});
|
|
|
|
test('only gepruft and hochwertig are publicly badged', function () {
|
|
expect(PressReleaseContentTier::Standard->isPubliclyBadged())->toBeFalse();
|
|
expect(PressReleaseContentTier::Geprueft->isPubliclyBadged())->toBeTrue();
|
|
expect(PressReleaseContentTier::Hochwertig->isPubliclyBadged())->toBeTrue();
|
|
});
|
|
|
|
test('score job stores the openai score, derives the tier and writes an audit', function () {
|
|
fakeOpenAiScore(72);
|
|
|
|
$pressRelease = PressRelease::factory()->create();
|
|
|
|
(new ScorePressRelease($pressRelease->id))->handle(app(ContentScoreManager::class));
|
|
|
|
$fresh = $pressRelease->fresh();
|
|
expect($fresh->content_score)->toBe(72);
|
|
expect($fresh->content_tier)->toBe(PressReleaseContentTier::Geprueft);
|
|
expect($fresh->scored_at)->not->toBeNull();
|
|
|
|
$audit = KiAudit::where('press_release_id', $pressRelease->id)
|
|
->where('type', KiAudit::TYPE_CONTENT_SCORE)
|
|
->firstOrFail();
|
|
expect($audit->provider)->toBe('openai');
|
|
expect($audit->result)->toBe('72');
|
|
});
|
|
|
|
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');
|
|
|
|
Http::fake(['*' => Http::response('error', 500)]);
|
|
|
|
$pressRelease = PressRelease::factory()->create([
|
|
'title' => 'Eine ausreichend lange und klare Pressemitteilungs-Headline',
|
|
'text' => str_repeat('Inhaltlicher Satz mit Substanz. ', 80),
|
|
]);
|
|
|
|
(new ScorePressRelease($pressRelease->id))->handle(app(ContentScoreManager::class));
|
|
|
|
$audit = KiAudit::where('press_release_id', $pressRelease->id)
|
|
->where('type', KiAudit::TYPE_CONTENT_SCORE)
|
|
->firstOrFail();
|
|
expect($audit->provider)->toBe('deterministic');
|
|
expect($pressRelease->fresh()->content_score)->toBeGreaterThan(0);
|
|
});
|
|
|
|
test('submitForReview dispatches the scoring job onto the classification queue', function () {
|
|
Queue::fake();
|
|
config()->set('blacklist.words', []);
|
|
|
|
$user = User::factory()->create();
|
|
$pressRelease = PressRelease::factory()->create([
|
|
'user_id' => $user->id,
|
|
'status' => PressReleaseStatus::Draft->value,
|
|
'title' => 'Sauber',
|
|
'text' => 'Inhalt',
|
|
]);
|
|
|
|
app(PressReleaseService::class)->submitForReview($pressRelease);
|
|
|
|
Queue::assertPushedOn('classification', ScorePressRelease::class, function (ScorePressRelease $job) use ($pressRelease) {
|
|
return $job->pressReleaseId === $pressRelease->id;
|
|
});
|
|
});
|
|
|
|
test('rescoreIfScored dispatches only for an already scored press release', function () {
|
|
Queue::fake();
|
|
|
|
$scored = PressRelease::factory()->create(['content_score' => 55]);
|
|
$neverScored = PressRelease::factory()->create(['content_score' => null]);
|
|
|
|
app(PressReleaseService::class)->rescoreIfScored($scored);
|
|
app(PressReleaseService::class)->rescoreIfScored($neverScored);
|
|
|
|
Queue::assertPushed(ScorePressRelease::class, 1);
|
|
});
|