Implements Spec 096 ops polish bundle: - Persist durable OperationRun.summary_counts for assignment fetch/restore (final attempt wins) - Server-side dedupe for assignment jobs (15-minute cooldown + non-canonical skip) - Track ReconcileAdapterRunsJob via workspace-scoped OperationRun + stable failure codes + overlap prevention - Seed DX: ensure seeded tenants use UUID v4 external_id and seed satisfies workspace_id NOT NULL constraints Verification (local / evidence-based): - `vendor/bin/sail artisan test --compact tests/Feature/Operations/AssignmentRunSummaryCountsTest.php tests/Feature/Operations/AssignmentJobDedupeTest.php tests/Feature/Operations/ReconcileAdapterRunsJobTrackingTest.php tests/Feature/Seed/PoliciesSeederExternalIdTest.php` - `vendor/bin/sail bin pint --dirty` Spec artifacts included under `specs/096-ops-polish-assignment-dedupe-system-tracking/` (spec/plan/tasks/checklists). Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #115
85 lines
2.9 KiB
PHP
85 lines
2.9 KiB
PHP
<?php
|
|
|
|
use App\Jobs\ReconcileAdapterRunsJob;
|
|
use App\Models\OperationRun;
|
|
use App\Models\Workspace;
|
|
use App\Services\AdapterRunReconciler;
|
|
use App\Services\OperationRunService;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Queue\Middleware\WithoutOverlapping;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
test('reconcile adapter runs job tracks successful execution in operation runs', function (): void {
|
|
$workspace = Workspace::factory()->create();
|
|
|
|
$job = new class((int) $workspace->getKey(), '2026-02-15 10:00:00') extends ReconcileAdapterRunsJob
|
|
{
|
|
protected function reconcile(AdapterRunReconciler $reconciler): array
|
|
{
|
|
return [
|
|
'candidates' => 4,
|
|
'reconciled' => 3,
|
|
'skipped' => 1,
|
|
];
|
|
}
|
|
};
|
|
|
|
$job->handle(new AdapterRunReconciler, app(OperationRunService::class));
|
|
|
|
$run = OperationRun::query()
|
|
->where('workspace_id', (int) $workspace->getKey())
|
|
->whereNull('tenant_id')
|
|
->where('type', 'ops.reconcile_adapter_runs')
|
|
->first();
|
|
|
|
expect($run)->not->toBeNull();
|
|
expect($run?->status)->toBe('completed');
|
|
expect($run?->outcome)->toBe('succeeded');
|
|
expect($run?->summary_counts ?? [])->toMatchArray([
|
|
'total' => 4,
|
|
'processed' => 4,
|
|
'failed' => 0,
|
|
]);
|
|
});
|
|
|
|
test('reconcile adapter runs job tracks failure with stable code and sanitized message', function (): void {
|
|
$workspace = Workspace::factory()->create();
|
|
|
|
$job = new class((int) $workspace->getKey(), '2026-02-15 10:30:00') extends ReconcileAdapterRunsJob
|
|
{
|
|
protected function reconcile(AdapterRunReconciler $reconciler): array
|
|
{
|
|
throw new RuntimeException('Authorization: Bearer highly-sensitive-token-for-user@example.com');
|
|
}
|
|
};
|
|
|
|
expect(fn () => $job->handle(new AdapterRunReconciler, app(OperationRunService::class)))
|
|
->toThrow(\RuntimeException::class);
|
|
|
|
$run = OperationRun::query()
|
|
->where('workspace_id', (int) $workspace->getKey())
|
|
->whereNull('tenant_id')
|
|
->where('type', 'ops.reconcile_adapter_runs')
|
|
->first();
|
|
|
|
expect($run)->not->toBeNull();
|
|
expect($run?->status)->toBe('completed');
|
|
expect($run?->outcome)->toBe('failed');
|
|
|
|
$failure = $run?->failure_summary[0] ?? [];
|
|
|
|
expect($failure['code'] ?? null)->toBe('ops.reconcile_adapter_runs.failed');
|
|
expect((string) ($failure['message'] ?? ''))->not->toContain('Bearer');
|
|
expect((string) ($failure['message'] ?? ''))->not->toContain('@example.com');
|
|
});
|
|
|
|
test('reconcile adapter runs job enforces server-side overlap middleware', function (): void {
|
|
$job = new ReconcileAdapterRunsJob;
|
|
|
|
$hasWithoutOverlapping = collect($job->middleware())
|
|
->contains(fn (mixed $middleware): bool => $middleware instanceof WithoutOverlapping);
|
|
|
|
expect($hasWithoutOverlapping)->toBeTrue();
|
|
});
|