From a37b1da1457995e01dc4865a177e16942b8e3338 Mon Sep 17 00:00:00 2001 From: myrmidex Date: Tue, 28 Apr 2026 00:13:14 +0200 Subject: [PATCH] 13 - Add language_confidence column and Page model cast --- app/Models/Page.php | 2 ++ .../2026_04_25_234157_create_pages_table.php | 1 + tests/Unit/Models/PageTest.php | 20 +++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/app/Models/Page.php b/app/Models/Page.php index 02a0a8e..52a131c 100644 --- a/app/Models/Page.php +++ b/app/Models/Page.php @@ -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', diff --git a/database/migrations/2026_04_25_234157_create_pages_table.php b/database/migrations/2026_04_25_234157_create_pages_table.php index e1df51f..2379f87 100644 --- a/database/migrations/2026_04_25_234157_create_pages_table.php +++ b/database/migrations/2026_04_25_234157_create_pages_table.php @@ -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() diff --git a/tests/Unit/Models/PageTest.php b/tests/Unit/Models/PageTest.php index 3e08b56..95645ad 100644 --- a/tests/Unit/Models/PageTest.php +++ b/tests/Unit/Models/PageTest.php @@ -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 = [