festbench-web/tests/Feature/ResultsPageTest.php

119 lines
4.8 KiB
PHP

<?php
use App\Models\BenchmarkRun;
use App\Models\ProsebenchResult;
use App\Models\SoftbenchResult;
use App\Models\User;
use Livewire\Volt\Volt;
test('guests see public task results on the results page', function () {
$publicRun = BenchmarkRun::factory()->create(['model_id' => 'public/model', 'suite' => 'softbench']);
ProsebenchResult::factory()->count(3)->create(['benchmark_run_id' => $publicRun->id]);
BenchmarkRun::factory()->private()->create(['model_id' => 'private/model', 'suite' => 'softbench']);
$response = $this->get(route('results'));
$response->assertOk()
->assertSee('public/model')
->assertDontSee('private/model');
});
test('authenticated users see their private runs mixed in on results', function () {
$me = User::factory()->create();
BenchmarkRun::factory()->private()->create(['model_id' => 'my-private/model', 'user_id' => $me->id, 'suite' => 'softbench']);
BenchmarkRun::factory()->private()->create(['model_id' => 'other-private/model', 'suite' => 'softbench']);
$this->actingAs($me);
$this->get(route('results'))->assertOk()
->assertSee('my-private/model')
->assertDontSee('other-private/model');
});
test('home page sorting orders by user tok/s through the view', function () {
$run = BenchmarkRun::factory()->create(['suite' => 'softbench']);
SoftbenchResult::factory()->create(['benchmark_run_id' => $run->id, 'task' => 'slow-task', 'user_tps' => 5]);
SoftbenchResult::factory()->create(['benchmark_run_id' => $run->id, 'task' => 'fast-task', 'user_tps' => 95]);
Volt::test('results.index', ['sortBy' => 'user_tps', 'sortDirection' => 'asc'])
->assertSeeInOrder(['slow-task', 'fast-task']);
});
test('home page suite filter queries the concrete suite table', function () {
$softRun = BenchmarkRun::factory()->create(['suite' => 'softbench']);
$proseRun = BenchmarkRun::factory()->create(['suite' => 'prosebench']);
SoftbenchResult::factory()->create(['benchmark_run_id' => $softRun->id, 'task' => 'soft-task']);
ProsebenchResult::factory()->create(['benchmark_run_id' => $proseRun->id, 'task' => 'prose-task']);
Volt::test('results.index', ['filters' => ['search' => null, 'suite' => 'softbench', 'level' => null, 'model' => null, 'result' => null]])
->assertSee('soft-task')
->assertDontSee('prose-task');
});
test('run detail page shows metadata and suite-tailored results', function () {
$run = BenchmarkRun::factory()->create(['model_id' => 'detail/model', 'engine' => 'vllm', 'suite' => 'prosebench']);
ProsebenchResult::factory()->create(['benchmark_run_id' => $run->id, 'task' => 'visible-task', 'checks_passed' => 6, 'checks_total' => 6]);
$this->get(route('runs.show', $run->run_id))->assertOk()
->assertSee('detail/model')
->assertSee('visible-task')
->assertSee('vllm')
->assertSee('6/6');
});
test('private runs are hidden from guests on the detail page', function () {
$run = BenchmarkRun::factory()->private()->create();
$this->get(route('runs.show', $run->run_id))->assertNotFound();
});
test('owners can edit notes from the run detail page', function () {
$me = User::factory()->create();
$run = BenchmarkRun::factory()->create(['user_id' => $me->id]);
$this->actingAs($me);
Volt::test('runs.show', ['run' => $run->run_id])
->set('notes', 'ran on the spare GPU while idle')
->call('saveNotes');
expect($run->fresh()->notes)->toBe('ran on the spare GPU while idle');
});
test('non-owners cannot edit notes', function () {
$intruder = User::factory()->create();
$run = BenchmarkRun::factory()->create(['user_id' => User::factory()->create()->id]);
$this->actingAs($intruder);
Volt::test('runs.show', ['run' => $run->run_id])
->set('notes', 'nice try')
->call('saveNotes');
expect($run->fresh()->notes)->toBeNull();
});
test('owner can toggle visibility from run detail page', function () {
$me = User::factory()->create();
$run = BenchmarkRun::factory()->create(['user_id' => $me->id]);
$this->actingAs($me);
Volt::test('runs.show', ['run' => $run->run_id])->call('toggleVisibility');
expect($run->fresh()->visibility)->toBe('private');
});
test('my runs page lists only owned runs with counts', function () {
$me = User::factory()->create();
$run = BenchmarkRun::factory()->create(['user_id' => $me->id, 'model_id' => 'mine/model', 'suite' => 'softbench']);
SoftbenchResult::factory()->count(4)->create(['benchmark_run_id' => $run->id]);
BenchmarkRun::factory()->create(['user_id' => User::factory()->create()->id, 'model_id' => 'theirs/model', 'suite' => 'softbench']);
$this->actingAs($me);
$this->get(route('my-runs'))->assertOk()
->assertSee('mine/model')
->assertDontSee('theirs/model')
->assertSee('4');
});