create(); $user = User::factory()->create(); WorkspaceMembership::factory()->create([ 'workspace_id' => (int) $workspace->getKey(), 'user_id' => (int) $user->getKey(), 'role' => 'readonly', ]); $run = OperationRun::factory()->tenantlessForWorkspace($workspace)->create([ 'type' => 'tenant.review.compose', ]); expect(Gate::forUser($user)->allows('view', $run))->toBeTrue(); }); it('denies environment-bound operation runs outside explicit scope as not found', function (): void { $workspace = Workspace::factory()->create(); $allowedTenant = ManagedEnvironment::factory()->active()->create([ 'workspace_id' => (int) $workspace->getKey(), ]); $deniedTenant = ManagedEnvironment::factory()->active()->create([ 'workspace_id' => (int) $workspace->getKey(), ]); $user = User::factory()->create(); WorkspaceMembership::factory()->create([ 'workspace_id' => (int) $workspace->getKey(), 'user_id' => (int) $user->getKey(), 'role' => 'operator', ]); ManagedEnvironmentMembership::query()->create([ 'managed_environment_id' => (int) $allowedTenant->getKey(), 'user_id' => (int) $user->getKey(), 'role' => 'operator', 'source' => 'manual', ]); app(ManagedEnvironmentAccessScopeResolver::class)->clearCache(); $run = OperationRun::factory()->forTenant($deniedTenant)->create([ 'type' => 'provider.connection.check', ]); $response = Gate::forUser($user)->inspect('view', $run); expect($response->denied())->toBeTrue() ->and($response->status())->toBe(404); }); it('keeps in-scope operation capability denials distinct from scope boundaries', function (): void { $workspace = Workspace::factory()->create(); $tenant = ManagedEnvironment::factory()->active()->create([ 'workspace_id' => (int) $workspace->getKey(), ]); $user = User::factory()->create(); WorkspaceMembership::factory()->create([ 'workspace_id' => (int) $workspace->getKey(), 'user_id' => (int) $user->getKey(), 'role' => 'readonly', ]); $run = OperationRun::factory()->forTenant($tenant)->create([ 'type' => 'inventory.sync', ]); $response = Gate::forUser($user)->inspect('view', $run); expect($response->denied())->toBeTrue() ->and($response->status())->not->toBe(404); });