makeBaselineCompareMatrixFixture(); $readonlyTenant = Tenant::factory()->create([ 'workspace_id' => (int) $fixture['workspace']->getKey(), 'name' => 'Readonly Contoso', ]); $fixture['user']->tenants()->syncWithoutDetaching([ (int) $readonlyTenant->getKey() => ['role' => 'readonly'], ]); $this->assignTenantToBaselineProfile($fixture['profile'], $readonlyTenant); $service = app(BaselineCompareService::class); $existingRunResult = $service->startCompareForProfile( $fixture['profile'], $fixture['visibleTenantTwo'], $fixture['user'], ); expect($existingRunResult['ok'] ?? false)->toBeTrue(); $result = $service->startCompareForVisibleAssignments($fixture['profile'], $fixture['user']); expect($result['visibleAssignedTenantCount'])->toBe(3) ->and($result['queuedCount'])->toBe(1) ->and($result['alreadyQueuedCount'])->toBe(1) ->and($result['blockedCount'])->toBe(1); $launchStates = collect($result['targets']) ->mapWithKeys(static fn (array $target): array => [(int) $target['tenantId'] => (string) $target['launchState']]) ->all(); expect($launchStates[(int) $fixture['visibleTenant']->getKey()] ?? null)->toBe('queued') ->and($launchStates[(int) $fixture['visibleTenantTwo']->getKey()] ?? null)->toBe('already_queued') ->and($launchStates[(int) $readonlyTenant->getKey()] ?? null)->toBe('blocked'); Queue::assertPushed(CompareBaselineToTenantJob::class); $activeRuns = OperationRun::query() ->where('workspace_id', (int) $fixture['workspace']->getKey()) ->where('type', 'baseline_compare') ->get(); expect($activeRuns)->toHaveCount(2) ->and($activeRuns->every(static fn (OperationRun $run): bool => $run->tenant_id !== null))->toBeTrue() ->and($activeRuns->every(static fn (OperationRun $run): bool => (string) $run->status === OperationRunStatus::Queued->value))->toBeTrue() ->and($activeRuns->every(static fn (OperationRun $run): bool => (string) $run->outcome === OperationRunOutcome::Pending->value))->toBeTrue() ->and(OperationRun::query()->whereNull('tenant_id')->where('type', 'baseline_compare')->count())->toBe(0); }); it('runs compare assigned tenants from the matrix page and keeps feedback on tenant-owned runs', function (): void { Queue::fake(); $fixture = $this->makeBaselineCompareMatrixFixture(); $this->setAdminWorkspaceContext($fixture['user'], $fixture['workspace']); Livewire::actingAs($fixture['user']) ->test(BaselineCompareMatrix::class, ['record' => $fixture['profile']->getKey()]) ->assertActionVisible('compareAssignedTenants') ->assertActionEnabled('compareAssignedTenants') ->callAction('compareAssignedTenants') ->assertStatus(200); Queue::assertPushed(CompareBaselineToTenantJob::class, 2); expect(OperationRun::query() ->where('workspace_id', (int) $fixture['workspace']->getKey()) ->where('type', 'baseline_compare') ->whereNull('tenant_id') ->count())->toBe(0); });