TenantAtlas/apps/platform/tests/Browser/Spec338ScopeContractSmokeTest.php
ahmido e0c2cdb1f4 feat: enforce workspace and environment scope contract (Spec 338) (#409)
## Summary
- enforce the canonical workspace/environment scope contract for workspace hubs and environment-owned surfaces
- replace first-party Operations deep links that leaked Filament `tableFilters[...]` internals with stable product-level query behavior
- add the sidebar scope indicator and split environment-page navigation into explicit `Workspace-wide` and `Workspace admin` groups
- remove redundant tenantless `All environments` scope badges from workspace-wide pages while preserving explicit environment filter affordances
- include the Spec 338 artifacts, guard tests, and browser smoke coverage for the new contract

## Validation
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/Navigation/Spec338EnvironmentSidebarSeparationTest.php tests/Feature/Navigation/Spec338OperationRunLinksQueryContractTest.php tests/Feature/Navigation/Spec338SidebarScopeIndicatorTest.php tests/Feature/Filament/PanelNavigationSegregationTest.php`
- `cd apps/platform && ./vendor/bin/sail php vendor/bin/pest tests/Browser/Spec338ScopeContractSmokeTest.php --compact`

## Notes
- Livewire v4 compliance unchanged
- Filament provider registration remains in `bootstrap/providers.php`
- no destructive action behavior changed
- no migrations, env var changes, or new Filament asset registration

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #409
2026-05-31 01:36:08 +00:00

59 lines
2.5 KiB
PHP

<?php
declare(strict_types=1);
use App\Filament\Pages\EnvironmentDashboard;
use App\Filament\Resources\EvidenceSnapshotResource;
use Tests\Browser\Support\Spec322WorkspaceEnvironmentBrowserHarness as Spec322Harness;
pest()->browser()->timeout(60_000);
it('Spec338 smokes environment origin operations link contract uses environment_id and avoids Filament internals', function (): void {
$fixture = Spec322Harness::fixture();
Spec322Harness::authenticate($this, $fixture['user'], $fixture['workspace'], $fixture['environmentA']);
$page = visit(EnvironmentDashboard::getUrl(panel: 'admin', tenant: $fixture['environmentA']))
->waitForText($fixture['environmentA']->name)
->assertScript('Array.from(document.querySelectorAll("a[href*=\"/operations\"]")).some((element) => element.href.includes("environment_id=") && !element.href.includes("tableFilters"))', true)
->assertNoJavaScriptErrors()
->assertNoConsoleLogs();
$page->script('(() => {
const link = Array.from(document.querySelectorAll("a[href*=\\"/operations\\"]"))
.find((element) => element.href.includes("environment_id=") && ! element.href.includes("tableFilters"));
if (! link) {
return;
}
window.location.assign(link.href);
})()');
Spec322Harness::assertFilteredWorkspaceHub($page, $fixture['environmentA']);
});
it('Spec338 smokes clearing environment context from environment evidence surface redirects to Evidence Overview hub', function (): void {
$fixture = Spec322Harness::fixture();
Spec322Harness::authenticate($this, $fixture['user'], $fixture['workspace'], $fixture['environmentA']);
$overviewPath = json_encode((string) parse_url(route('admin.evidence.overview'), PHP_URL_PATH), JSON_THROW_ON_ERROR);
$page = visit(EvidenceSnapshotResource::getUrl('index', tenant: $fixture['environmentA'], panel: 'admin'))
->waitForText('Evidence')
->assertNoJavaScriptErrors()
->assertNoConsoleLogs();
$page
->assertScript('document.querySelector(\'form[action*="/admin/clear-environment-context"]\') instanceof HTMLFormElement', true)
->script('document.querySelector(\'form[action*="/admin/clear-environment-context"]\').submit();');
$page
->waitForText('Evidence Overview')
->assertDontSee(__('localization.shell.no_environment_selected'))
->assertScript("window.location.pathname === {$overviewPath}", true)
->assertNoJavaScriptErrors()
->assertNoConsoleLogs();
});