TenantAtlas/tests/Feature/OpsUx/FailureSanitizationTest.php
ahmido d56ba85755 Spec 078: Operations tenantless canonical detail (#95)
Implements Spec 078 operations tenantless canonical migration.

Highlights:
- Canonical run detail at `/admin/operations/{run}` renders with standard Filament chrome + sidebar and reuses `OperationRunResource::infolist()` (schema-based, Filament v5).
- Legacy tenant-scoped resource pages removed; legacy URLs return 404 as required.
- Added full spec test pack under `tests/Feature/078/` and updated existing tests.
- Added safe refresh/header actions wiring and KPI header guard when tenant context is null.

Validation:
- `vendor/bin/sail artisan test --compact tests/Feature/078/` (pass)
- `vendor/bin/sail bin pint --dirty` (pass)

Notes:
- Livewire v4+ compliant (Filament v5).
- Panel providers remain registered in `bootstrap/providers.php` (Laravel 11+ standard).

Co-authored-by: Ahmed Darrazi <ahmeddarrazi@MacBookPro.fritz.box>
Reviewed-on: #95
2026-02-07 09:07:26 +00:00

60 lines
1.9 KiB
PHP

<?php
use App\Models\Tenant;
use App\Services\OperationRunService;
use Illuminate\Notifications\DatabaseNotification;
it('sanitizes persisted run failures and terminal notifications', function () {
$tenant = Tenant::factory()->create();
[$user, $tenant] = createUserWithTenant($tenant, role: 'owner');
/** @var OperationRunService $runs */
$runs = app(OperationRunService::class);
$run = $runs->ensureRun(
tenant: $tenant,
type: 'test.sanitize',
inputs: [],
initiator: $user,
);
$rawBearer = 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.'.str_repeat('A', 90);
$runs->updateRun(
$run,
status: 'completed',
outcome: 'failed',
failures: [[
'code' => 'graph_forbidden',
'message' => "Authorization: {$rawBearer} client_secret=supersecret user=test.user@example.com",
]],
);
$run->refresh();
$failureSummaryJson = json_encode($run->failure_summary, JSON_THROW_ON_ERROR);
expect($failureSummaryJson)->not->toContain('client_secret=supersecret');
expect($failureSummaryJson)->not->toContain($rawBearer);
expect($failureSummaryJson)->not->toContain('test.user@example.com');
expect($run->failure_summary[0]['reason_code'] ?? null)->toBe('permission_denied');
$notification = DatabaseNotification::query()
->where('notifiable_id', $user->getKey())
->latest('id')
->first();
expect($notification)->not->toBeNull();
$notificationJson = json_encode($notification?->data, JSON_THROW_ON_ERROR);
expect($notificationJson)->not->toContain('client_secret=supersecret');
expect($notificationJson)->not->toContain($rawBearer);
expect($notificationJson)->not->toContain('test.user@example.com');
$this->actingAs($user)
->get(route('admin.operations.view', ['run' => (int) $run->getKey()]))
->assertSuccessful();
});