create(); [$user, $tenant] = createUserWithTenant($tenant, role: 'owner'); Filament::setTenant($tenant, true); $this->actingAs($user) ->withSession([WorkspaceContext::SESSION_KEY => (int) $tenant->workspace_id]) ->get('/admin/operations') ->assertOk(); expect(Filament::getTenant())->toBe($tenant); }); it('renders workspace scope label when no tenant context is active', function (): void { $tenant = Tenant::factory()->create(); [$user, $tenant] = createUserWithTenant($tenant, role: 'owner'); Filament::setTenant(null, true); $this->actingAs($user) ->withSession([WorkspaceContext::SESSION_KEY => (int) $tenant->workspace_id]) ->get('/admin/operations') ->assertOk() ->assertSee('All tenants'); expect(Filament::getTenant())->toBeNull(); }); it('does not mutate remembered tenant context when opening a canonical operation run for another tenant', function (): void { $tenantA = Tenant::factory()->create(); [$user, $tenantA] = createUserWithTenant($tenantA, role: 'owner'); $tenantB = Tenant::factory()->create([ 'workspace_id' => (int) $tenantA->workspace_id, ]); createUserWithTenant(tenant: $tenantB, user: $user, role: 'owner'); $run = OperationRun::factory()->create([ 'tenant_id' => (int) $tenantB->getKey(), 'workspace_id' => (int) $tenantB->workspace_id, 'type' => 'inventory_sync', ]); $lastTenantMap = [ (string) $tenantA->workspace_id => (int) $tenantA->getKey(), ]; Filament::setTenant($tenantA, true); $this->actingAs($user) ->withSession([ WorkspaceContext::SESSION_KEY => (int) $tenantA->workspace_id, WorkspaceContext::LAST_TENANT_IDS_SESSION_KEY => $lastTenantMap, ]) ->get("/admin/operations/{$run->getKey()}") ->assertOk(); expect(session()->get(WorkspaceContext::LAST_TENANT_IDS_SESSION_KEY))->toBe($lastTenantMap); });