119 lines
4.2 KiB
PHP
119 lines
4.2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
use App\Models\BenchmarkRun;
|
||
|
|
use App\Models\InfrabenchResult;
|
||
|
|
use App\Models\ProsebenchResult;
|
||
|
|
use App\Models\PsychbenchResult;
|
||
|
|
use App\Models\ScenarioRun;
|
||
|
|
use App\Models\SoftbenchResult;
|
||
|
|
use App\Models\User;
|
||
|
|
use App\Support\Suites;
|
||
|
|
|
||
|
|
test('guests see only public runs', function () {
|
||
|
|
$publicRun = BenchmarkRun::factory()->create(['visibility' => 'public']);
|
||
|
|
BenchmarkRun::factory()->create(['visibility' => 'private']);
|
||
|
|
|
||
|
|
$visible = BenchmarkRun::visibleTo(null)->get();
|
||
|
|
|
||
|
|
expect($visible->pluck('id'))->toContain($publicRun->id)
|
||
|
|
->and($visible)->toHaveCount(1);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('authenticated users see public runs plus their own private runs', function () {
|
||
|
|
$me = User::factory()->create();
|
||
|
|
$other = User::factory()->create();
|
||
|
|
|
||
|
|
$publicRun = BenchmarkRun::factory()->create(['visibility' => 'public']);
|
||
|
|
$myPrivate = BenchmarkRun::factory()->create(['visibility' => 'private', 'user_id' => $me->id]);
|
||
|
|
BenchmarkRun::factory()->create(['visibility' => 'private', 'user_id' => $other->id]);
|
||
|
|
|
||
|
|
$visible = BenchmarkRun::visibleTo($me)->get();
|
||
|
|
|
||
|
|
expect($visible->pluck('id'))->toContain($publicRun->id)
|
||
|
|
->and($visible->pluck('id'))->toContain($myPrivate->id)
|
||
|
|
->and($visible)->toHaveCount(2);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('submitted metrics are immutable through fillable updates', function () {
|
||
|
|
$run = BenchmarkRun::factory()->create(['model_id' => 'original/model', 'visibility' => 'public']);
|
||
|
|
|
||
|
|
$run->fill(['notes' => 'my notes', 'visibility' => 'private', 'model_id' => 'hacked/model'])
|
||
|
|
->save();
|
||
|
|
|
||
|
|
expect($run->notes)->toBe('my notes')
|
||
|
|
->and($run->visibility)->toBe('private')
|
||
|
|
->and($run->fresh()->model_id)->toBe('original/model');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('suite result rows are deleted with their run', function () {
|
||
|
|
$run = BenchmarkRun::factory()->create(['suite' => 'softbench']);
|
||
|
|
SoftbenchResult::factory()->count(2)->create(['benchmark_run_id' => $run->id]);
|
||
|
|
|
||
|
|
$run->delete();
|
||
|
|
|
||
|
|
expect(SoftbenchResult::where('benchmark_run_id', $run->id)->exists())->toBeFalse();
|
||
|
|
});
|
||
|
|
|
||
|
|
test('suite results belong to their run and cast payloads', function () {
|
||
|
|
$run = BenchmarkRun::factory()->create(['suite' => 'prosebench']);
|
||
|
|
$result = ProsebenchResult::factory()->create([
|
||
|
|
'benchmark_run_id' => $run->id,
|
||
|
|
'payload' => ['finish' => 'stop'],
|
||
|
|
'checks_passed' => 5,
|
||
|
|
'checks_total' => 6,
|
||
|
|
]);
|
||
|
|
|
||
|
|
expect($result->run->id)->toBe($run->id)
|
||
|
|
->and($result->payload)->toBeArray()
|
||
|
|
->and($result->checks_total)->toBe(6);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('registry resolves models and relations for every suite', function () {
|
||
|
|
foreach (Suites::all() as $suite) {
|
||
|
|
$model = Suites::modelFor($suite);
|
||
|
|
expect($model)->not->toBeNull();
|
||
|
|
|
||
|
|
$run = BenchmarkRun::factory()->create(['suite' => $suite]);
|
||
|
|
$model::factory()->create(['benchmark_run_id' => $run->id]);
|
||
|
|
|
||
|
|
expect($run->suiteResults())->toHaveCount(1)
|
||
|
|
->and(Suites::runRelation($suite))->toBeString();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
test('unregistered suites produce empty suite results', function () {
|
||
|
|
$run = BenchmarkRun::factory()->create(['suite' => 'depthsweep']);
|
||
|
|
|
||
|
|
expect($run->suiteResults())->toBeEmpty();
|
||
|
|
});
|
||
|
|
|
||
|
|
test('scenario runs keep their agentic metrics', function () {
|
||
|
|
$run = BenchmarkRun::factory()->create(['suite' => 'scenariobench']);
|
||
|
|
$scenario = ScenarioRun::factory()->create([
|
||
|
|
'benchmark_run_id' => $run->id,
|
||
|
|
'outcome' => 'passed',
|
||
|
|
'turns' => 68,
|
||
|
|
'submissions' => 1,
|
||
|
|
]);
|
||
|
|
|
||
|
|
expect($scenario->ok)->toBeBool()
|
||
|
|
->and($scenario->turns)->toBe(68)
|
||
|
|
->and($scenario->verdicts)->toBeArray()
|
||
|
|
->and($scenario->run->id)->toBe($run->id);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('infrabench rows carry their kind', function () {
|
||
|
|
$run = BenchmarkRun::factory()->create(['suite' => 'infrabench']);
|
||
|
|
$result = InfrabenchResult::factory()->create(['benchmark_run_id' => $run->id, 'kind' => 'recall']);
|
||
|
|
|
||
|
|
expect($result->kind)->toBe('recall');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('psychbench rows carry their checks', function () {
|
||
|
|
$run = BenchmarkRun::factory()->create(['suite' => 'psychbench']);
|
||
|
|
$result = PsychbenchResult::factory()->create(['benchmark_run_id' => $run->id]);
|
||
|
|
|
||
|
|
expect($result->checks_total)->toBeInt()
|
||
|
|
->and($result->checks_passed)->toBeLessThanOrEqual($result->checks_total);
|
||
|
|
});
|