13 - Add language_confidence column and Page model cast

This commit is contained in:
myrmidex 2026-04-28 00:13:14 +02:00
parent cda1414cd8
commit a37b1da145
3 changed files with 23 additions and 0 deletions

View file

@ -25,6 +25,7 @@ class Page extends Model
'url',
'status',
'language',
'language_confidence',
'title',
'instance_id',
'posted_at',
@ -34,6 +35,7 @@ class Page extends Model
protected $casts = [
'status' => PageStatusEnum::class,
'language_confidence' => 'float',
'posted_at' => 'datetime',
'fetched_at' => 'datetime',
'failed_at' => 'datetime',

View file

@ -16,6 +16,7 @@ public function up(): void
$table->text('url')->unique();
$table->string('status')->default(PageStatusEnum::Discovered->value)->index();
$table->string('language', 35)->nullable()->index();
$table->decimal('language_confidence', 4, 3)->nullable();
$table->string('title')->nullable();
$table->foreignId('instance_id')
->nullable()

View file

@ -152,6 +152,26 @@ public function test_page_latest_crawl_returns_row_with_latest_created_at(): voi
$this->assertSame('sentinel-latest', $latest->error_message);
}
public function test_language_confidence_is_fillable_nullable_and_cast_to_float(): void
{
// Column must exist, be nullable (null round-trips cleanly), be mass-assignable,
// and the 'float' cast must be applied so we get a PHP float back, not a string.
$withConfidence = Page::factory()->createQuietly([
'language' => 'en',
'language_confidence' => 0.857,
]);
$fresh = $withConfidence->fresh();
$this->assertNotNull($fresh);
$this->assertIsFloat($fresh->language_confidence);
$this->assertEqualsWithDelta(0.857, $fresh->language_confidence, 0.001);
$withoutConfidence = Page::factory()->createQuietly();
$this->assertNull($withoutConfidence->fresh()->language_confidence);
}
public function test_page_status_is_cast_to_enum(): void
{
$cases = [