Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

refactor: use one bounded E2E navigation annotation

Josuéb9aa350483b3
diff --git a/desktop-app/test/e2e-playwright/workflow-snippet-runtime-happy-path.test.ts b/desktop-app/test/e2e-playwright/workflow-snippet-runtime-happy-path.test.ts
index 0a78ef8fd..ec28e5ef6 100644
--- a/desktop-app/test/e2e-playwright/workflow-snippet-runtime-happy-path.test.ts
+++ b/desktop-app/test/e2e-playwright/workflow-snippet-runtime-happy-path.test.ts
@@ -260,7 +260,7 @@ function buildSnippetRecipeManifest(name: string): Record<string, unknown> {
async function controlUiLogin(page: Page): Promise<void> {
const password = requireAdminPassword()
- // E2E_GUARDIAN_ENTRY_POINT: enter the public Control UI root before UI login.
+ // E2E_GUARDIAN_NAVIGATION: root-entry — enter the public Control UI before login
await page.goto('/')
const usernameInput = page.getByLabel('Username')
const passwordInput = page.getByLabel('Password')
diff --git a/tests/e2e/playwright/control-ui/auth.spec.ts b/tests/e2e/playwright/control-ui/auth.spec.ts
index 1f21951df..1602fcd63 100644
--- a/tests/e2e/playwright/control-ui/auth.spec.ts
+++ b/tests/e2e/playwright/control-ui/auth.spec.ts
@@ -25,7 +25,7 @@ test.describe('Control UI — Auth', () => {
test('unauthenticated deep-link to a host detail page shows the login form, not host data', async ({
page,
}) => {
- // Negative route-guard: unauthenticated visit to a protected host detail.
+ // E2E_GUARDIAN_NAVIGATION: negative-route-guard — unauthenticated protected host detail
await page.goto('/hosts/chatllm')
await expect(page.locator(CUI_AUTH.USERNAME_INPUT)).toBeVisible()
await expect(page.locator(CUI_AUTH.SIGN_IN_BUTTON)).toBeVisible()
diff --git a/tests/e2e/playwright/control-ui/codex-subscription-admission.spec.ts b/tests/e2e/playwright/control-ui/codex-subscription-admission.spec.ts
index 553c19a79..25c210b6a 100644
--- a/tests/e2e/playwright/control-ui/codex-subscription-admission.spec.ts
+++ b/tests/e2e/playwright/control-ui/codex-subscription-admission.spec.ts
@@ -6,7 +6,7 @@
* - Unauthenticated `/agents/:name/model` must show login, not credentials.
* - LLM Models is no longer the ChatGPT assignment owner.
*/
-import { expect, test } from '@playwright/test'
+import { type Page, type Response, expect, test } from '@playwright/test'
import {
isSubscriptionAdmissionAuthProbe,
observeProtectedSubscriptionBusinessAccess,
@@ -14,54 +14,62 @@ import {
import { loginControlUiVisible } from '../helpers/visible-login'
test.describe('Codex subscription admission', () => {
- for (const guard of [
- {
- name: 'nested Subscriptions deep link',
- path: '/secrets/llm/subscriptions',
- next: '/secrets/llm/subscriptions',
- },
- {
- name: 'legacy Subscription deep link',
- path: '/secrets/subscription',
- next: '/secrets/llm/subscriptions',
- },
- {
- name: 'agent model deep link',
- path: '/agents/e2e-codex-authoring/model',
- next: '/agents/e2e-codex-authoring/model',
- },
- ]) {
- test(`unauthenticated ${guard.name} is blocked before protected business access`, async ({
- page,
- }) => {
- const attemptedBusiness = observeProtectedSubscriptionBusinessAccess(page)
- const authProbe = page.waitForResponse(response =>
- isSubscriptionAdmissionAuthProbe(response.url(), response.request().method())
- )
- // Negative deep-link guard: direct access is the behavior under test.
- await page.goto(guard.path)
- const authentication = await authProbe
- expect(authentication.status()).toBe(401)
- await expect(page).toHaveURL(
- // The public root owns sign-in; next retains the protected destination.
- url => url.pathname === '/' && url.searchParams.get('next') === guard.next
- )
- await expect(page.getByLabel('Username or email')).toBeVisible()
- await expect(page.getByRole('button', { name: 'Sign in', exact: true })).toBeVisible()
- await expect(page.getByLabel('Main navigation')).toHaveCount(0)
- await expect(page.getByRole('button', { name: 'Add subscription' })).toHaveCount(0)
- await expect(page.getByRole('columnheader', { name: 'Name' })).toHaveCount(0)
- await expect(page.getByLabel('Credential', { exact: true })).toHaveCount(0)
- await expect(page.getByRole('button', { name: 'Sign in with ChatGPT' })).toHaveCount(0)
- // AuthGate has settled after its real 401 probe and visible login render.
- // Assert attempts, not only successful responses: even a denied protected
- // request would reveal a guard bypass in this unauthenticated context.
- expect(attemptedBusiness).toEqual([])
- })
+ function observeUnauthenticatedAccess(page: Page) {
+ const attemptedBusiness = observeProtectedSubscriptionBusinessAccess(page)
+ const authProbe = page.waitForResponse(response =>
+ isSubscriptionAdmissionAuthProbe(response.url(), response.request().method())
+ )
+ return { attemptedBusiness, authProbe }
}
+ async function assertAuthGate(
+ page: Page,
+ next: string,
+ attemptedBusiness: string[],
+ authProbe: Promise<Response>
+ ) {
+ const authentication = await authProbe
+ expect(authentication.status()).toBe(401)
+ await expect(page).toHaveURL(
+ // The public root owns sign-in; next retains the protected destination.
+ url => url.pathname === '/' && url.searchParams.get('next') === next
+ )
+ await expect(page.getByLabel('Username or email')).toBeVisible()
+ await expect(page.getByRole('button', { name: 'Sign in', exact: true })).toBeVisible()
+ await expect(page.getByLabel('Main navigation')).toHaveCount(0)
+ await expect(page.getByRole('button', { name: 'Add subscription' })).toHaveCount(0)
+ await expect(page.getByRole('columnheader', { name: 'Name' })).toHaveCount(0)
+ await expect(page.getByLabel('Credential', { exact: true })).toHaveCount(0)
+ await expect(page.getByRole('button', { name: 'Sign in with ChatGPT' })).toHaveCount(0)
+ // AuthGate has settled after its real 401 probe and visible login render.
+ // Assert attempts, not only successful responses: even a denied protected
+ // request would reveal a guard bypass in this unauthenticated context.
+ expect(attemptedBusiness).toEqual([])
+ }
+
+ test('unauthenticated nested Subscriptions deep link is blocked', async ({ page }) => {
+ const { attemptedBusiness, authProbe } = observeUnauthenticatedAccess(page)
+ // E2E_GUARDIAN_NAVIGATION: negative-route-guard — protected subscriptions must show login
+ await page.goto('/secrets/llm/subscriptions')
+ await assertAuthGate(page, '/secrets/llm/subscriptions', attemptedBusiness, authProbe)
+ })
+
+ test('unauthenticated legacy Subscription deep link redirects safely', async ({ page }) => {
+ const { attemptedBusiness, authProbe } = observeUnauthenticatedAccess(page)
+ // E2E_GUARDIAN_NAVIGATION: negative-route-guard — legacy protected route must show login
+ await page.goto('/secrets/subscription')
+ await assertAuthGate(page, '/secrets/llm/subscriptions', attemptedBusiness, authProbe)
+ })
+
+ test('unauthenticated agent model deep link is blocked', async ({ page }) => {
+ const { attemptedBusiness, authProbe } = observeUnauthenticatedAccess(page)
+ // E2E_GUARDIAN_NAVIGATION: negative-route-guard — protected agent model must show login
+ await page.goto('/agents/e2e-codex-authoring/model')
+ await assertAuthGate(page, '/agents/e2e-codex-authoring/model', attemptedBusiness, authProbe)
+ })
+
test('LLM Models no longer owns Codex assignment', async ({ page }) => {
- // E2E_GUARDIAN_ENTRY_POINT: legitimate root entry for the visible login.
+ // E2E_GUARDIAN_NAVIGATION: root-entry — legitimate root before visible login
await page.goto('/')
await loginControlUiVisible(page)
@@ -72,7 +80,7 @@ test.describe('Codex subscription admission', () => {
})
await test.step('legacy provider URL does not expose Connect', async () => {
- // Negative legacy terminal-route guard: direct access is intentional.
+ // E2E_GUARDIAN_NAVIGATION: negative-route-guard — legacy terminal route stays disabled
await page.goto('/llm-models/providers/codex-subscription')
await expect(page.getByRole('button', { name: 'Sign in with ChatGPT' })).toHaveCount(0)
await expect(page.getByTestId('codex-connection-status')).toHaveCount(0)
diff --git a/tests/e2e/playwright/control-ui/codex-subscription-connection.spec.ts b/tests/e2e/playwright/control-ui/codex-subscription-connection.spec.ts
index fe3b619af..9eb592864 100644
--- a/tests/e2e/playwright/control-ui/codex-subscription-connection.spec.ts
+++ b/tests/e2e/playwright/control-ui/codex-subscription-connection.spec.ts
@@ -78,13 +78,14 @@ test.describe('Codex subscription connection', () => {
})
test('J2 authenticated deep link and legacy redirect; unauth is AuthGate', async ({ page }) => {
- // Negative deep-link guard: this protected page must stay at AuthGate.
+ // E2E_GUARDIAN_NAVIGATION: negative-route-guard — protected page must stay at AuthGate
await page.goto('/secrets/llm/subscriptions')
await expect(page.getByLabel('Username or email')).toBeVisible({ timeout: 20_000 })
await expect(page.getByRole('button', { name: 'Add subscription' })).toHaveCount(0)
await page.goto('/')
await loginControlUiVisible(page)
+ // E2E_GUARDIAN_NAVIGATION: negative-route-guard — legacy route must redirect to canonical view
await page.goto('/secrets/subscription')
await expect(page).toHaveURL(/\/secrets\/llm\/subscriptions$/)
await expect(page.getByRole('tab', { name: 'Subscriptions', selected: true })).toBeVisible()
diff --git a/tests/e2e/playwright/control-ui/codex-subscription-host-workflow.spec.ts b/tests/e2e/playwright/control-ui/codex-subscription-host-workflow.spec.ts
index db6b60f1e..f013d3f1d 100644
--- a/tests/e2e/playwright/control-ui/codex-subscription-host-workflow.spec.ts
+++ b/tests/e2e/playwright/control-ui/codex-subscription-host-workflow.spec.ts
@@ -2,7 +2,7 @@
* Codex subscription — Host authoring journey.
*
* Contract:
- * - Entry point: application root `/` (E2E_GUARDIAN_ENTRY_POINT).
+ * - Entry point: application root `/` before visible login.
* - Actions: visible login, open Agents, start Create agent, choose a ChatGPT grant.
* - Route/state: `/agents/new` Model & Credentials step.
* - UI: mixed Credential select (API key secret or ChatGPT subscription).
@@ -15,7 +15,7 @@ import { loginControlUiVisible } from '../helpers/visible-login'
test.describe('Codex subscription host and workflow authoring', () => {
test('operator can choose a ChatGPT subscription without a Host Secret', async ({ page }) => {
- // E2E_GUARDIAN_ENTRY_POINT
+ // E2E_GUARDIAN_NAVIGATION: root-entry — public application root before login
await page.goto('/')
await loginControlUiVisible(page)
diff --git a/tests/e2e/playwright/control-ui/codex-subscription-workflow-recipe.spec.ts b/tests/e2e/playwright/control-ui/codex-subscription-workflow-recipe.spec.ts
index 3438c6a12..59fe91a23 100644
--- a/tests/e2e/playwright/control-ui/codex-subscription-workflow-recipe.spec.ts
+++ b/tests/e2e/playwright/control-ui/codex-subscription-workflow-recipe.spec.ts
@@ -81,7 +81,7 @@ test.describe('Codex subscription workflow recipe authoring', () => {
await createPlaceholderRecipe(recipeName)
try {
- // E2E_GUARDIAN_ENTRY_POINT
+ // E2E_GUARDIAN_NAVIGATION: root-entry — public application root before login
await page.goto('/')
await loginControlUiVisible(page)
diff --git a/tests/e2e/playwright/desktop/codex-subscription-approved-tools.spec.ts b/tests/e2e/playwright/desktop/codex-subscription-approved-tools.spec.ts
index 911e1846c..838a166ff 100644
--- a/tests/e2e/playwright/desktop/codex-subscription-approved-tools.spec.ts
+++ b/tests/e2e/playwright/desktop/codex-subscription-approved-tools.spec.ts
@@ -3,7 +3,7 @@
* connector -> visible Control UI login/configuration/approval -> isolated
* Desktop login/chat -> persisted MCP receipt -> visible revocation -> denial.
* Every transition checks UI/state and the saved binding or actual MCP result.
- * E2E_GUARDIAN_ENTRY_POINT: Control UI starts at its application root.
+ * Entry contract: Control UI starts at its application root.
* E2E_GUARDIAN_IPC_FLOW: Desktop uses real main-process login and chat IPC.
* Completed messages and MCP evidence replace renderer response waits. Tests
* never inject IPC calls or authentication. Only the external OAuth and model
@@ -153,8 +153,8 @@ async function receiptApproval(page: Page, scenario: Scenario, previousCalls: nu
test('unauthenticated agent route guard prevents connector use', async ({ page }) => {
const scenario = cases[0]!
const before = await readEvidence(scenario)
- // Negative protected-route guard: direct navigation must not open the editor.
- await page.goto(`/agents/${scenario.agentName}/connectors`)
+ // E2E_GUARDIAN_NAVIGATION: negative-route-guard — protected editor must stay unavailable
+ await page.goto('/agents/e2e-codex-authoring/connectors')
await expect(page.getByLabel('Username or email')).toBeVisible()
await expect(page.getByRole('button', { name: 'Sign in', exact: true })).toBeVisible()
await expect(page.getByRole('button', { name: 'Add connector', exact: true })).toHaveCount(0)
diff --git a/tests/e2e/playwright/helpers/approved-tools-workflow.ts b/tests/e2e/playwright/helpers/approved-tools-workflow.ts
index 51e2622bf..6b3d6c84e 100644
--- a/tests/e2e/playwright/helpers/approved-tools-workflow.ts
+++ b/tests/e2e/playwright/helpers/approved-tools-workflow.ts
@@ -1,5 +1,5 @@
/**
- * E2E_GUARDIAN_ENTRY_POINT: root entry, visible configuration and login.
+ * Entry contract: public root, visible configuration and login.
* E2E_GUARDIAN_IPC_FLOW: chat and both approval decisions use genuine Desktop
* IPC. The prepared workflow workload produces a receipt and its JSON artifact;
* this helper only reads receipt evidence after the real workflow executes.
diff --git a/tests/e2e/playwright/package-lock.json b/tests/e2e/playwright/package-lock.json
index 2c505298d..6cbdb34a0 100644
--- a/tests/e2e/playwright/package-lock.json
+++ b/tests/e2e/playwright/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-playwright-tests",
- "version": "0.1.74",
+ "version": "0.1.75",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-playwright-tests",
- "version": "0.1.74",
+ "version": "0.1.75",
"devDependencies": {
"@playwright/test": "^1.50.0",
"@types/node": "^22.0.0",
diff --git a/tests/e2e/playwright/package.json b/tests/e2e/playwright/package.json
index fcef23530..a4b6ab388 100644
--- a/tests/e2e/playwright/package.json
+++ b/tests/e2e/playwright/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-playwright-tests",
- "version": "0.1.74",
+ "version": "0.1.75",
"private": true,
"description": "Playwright E2E tests for Control UI and Desktop App",
"scripts": {
diff --git a/tests/e2e/playwright/profile-ui-recovery/reset-session-hydration.spec.ts b/tests/e2e/playwright/profile-ui-recovery/reset-session-hydration.spec.ts
index f6a9e068e..64979c916 100644
--- a/tests/e2e/playwright/profile-ui-recovery/reset-session-hydration.spec.ts
+++ b/tests/e2e/playwright/profile-ui-recovery/reset-session-hydration.spec.ts
@@ -3,7 +3,7 @@ import { expect, test } from '@playwright/test'
test('retries session hydration after committed reset without resubmitting the reset proof', async ({
page,
}) => {
- // E2E_GUARDIAN_EMAIL_RESET_ENTRY_POINT: the emailed password-reset URL.
+ // E2E_GUARDIAN_NAVIGATION: email-reset-entry — the emailed password-reset URL
await page.goto('/invitations/synthetic-reset-proof')
await expect(page.getByRole('heading', { name: 'Reset password' })).toBeVisible()
diff --git a/tools/e2e_static_audit.py b/tools/e2e_static_audit.py
index 12d567edf..1a5b64ca0 100755
--- a/tools/e2e_static_audit.py
+++ b/tools/e2e_static_audit.py
@@ -23,6 +23,11 @@ RULES: tuple[tuple[str, re.Pattern[str]], ...] = (
)
EMAIL_RESET_ENTRY_PATH = re.compile(r"/invitations/[A-Za-z0-9_-]+")
+SAFE_STATIC_APP_PATH = re.compile(r"/(?:[A-Za-z0-9_-]+(?:/[A-Za-z0-9_-]+)*)?")
+NAVIGATION_ANNOTATION = re.compile(
+ r"\s*//\s*E2E_GUARDIAN_NAVIGATION:\s*"
+ r"(negative-route-guard|root-entry|email-reset-entry)\s+—\s+(\S.*)"
+)
STATIC_GOTO_ARGUMENT = re.compile(r"\s*(['\"])([^'\"\\\r\n]*)\1\s*(?=[,)])")
@@ -69,32 +74,30 @@ def audit_text(text: str, path: Path = Path("<source>")) -> list[str]:
adjacent = _adjacent_line(text, match.start())
after = text[match.end() : match.end() + 160]
root_argument = STATIC_GOTO_ARGUMENT.match(after)
- if root_argument and root_argument.group(2) in {"", "/"}:
+ line = text.count("\n", 0, match.start()) + 1
+ if navigation_counts_by_line.get(line) != 1:
+ findings.append(f"{path}:{line}: navigation annotation must authorize one page.goto")
continue
- if re.fullmatch(
- r"\s*//\s*Negative (?:protected-route guard|route-guard|deep-link guard|"
- r"legacy terminal-route guard):[^\n]*",
- adjacent,
- re.IGNORECASE,
- ):
+
+ annotation = NAVIGATION_ANNOTATION.fullmatch(adjacent)
+ destination = root_argument.group(2) if root_argument else None
+ if destination in {"", "/"}:
+ if annotation is None or annotation.group(1) == "root-entry":
+ continue
+ findings.append(f"{path}:{line}: direct page.goto does not match its navigation annotation")
continue
- root_entry_marker = re.fullmatch(
- r"\s*//\s*E2E_GUARDIAN_ENTRY_POINT(?::[^\n]*)?", adjacent
- )
- if root_entry_marker and root_argument and root_argument.group(2) in {"", "/"}:
+ if not annotation or destination is None:
+ findings.append(f"{path}:{line}: direct page.goto outside an explicit navigation annotation")
continue
- email_reset_marker = re.fullmatch(
- r"\s*//\s*E2E_GUARDIAN_EMAIL_RESET_ENTRY_POINT(?::[^\n]*)?", adjacent
- )
- line = text.count("\n", 0, match.start()) + 1
- if (
- email_reset_marker
- and navigation_counts_by_line.get(line) == 1
- and root_argument
- and EMAIL_RESET_ENTRY_PATH.fullmatch(root_argument.group(2))
- ):
+
+ kind = annotation.group(1)
+ if kind == "root-entry" and destination in {"", "/"}:
+ continue
+ if kind == "email-reset-entry" and EMAIL_RESET_ENTRY_PATH.fullmatch(destination):
+ continue
+ if kind == "negative-route-guard" and SAFE_STATIC_APP_PATH.fullmatch(destination):
continue
- findings.append(f"{path}:{line}: direct page.goto outside an explicit negative guard")
+ findings.append(f"{path}:{line}: direct page.goto does not match its navigation annotation")
return findings
diff --git a/tools/test_e2e_static_audit.py b/tools/test_e2e_static_audit.py
index 9cea67f1d..6895e0f29 100644
--- a/tools/test_e2e_static_audit.py
+++ b/tools/test_e2e_static_audit.py
@@ -13,14 +13,49 @@ class E2EStaticAuditNavigationTests(unittest.TestCase):
Path("recovery.spec.ts"),
)
- def test_adjacent_email_marker_allows_invitation_reset_entry(self) -> None:
- source = "// E2E_GUARDIAN_EMAIL_RESET_ENTRY_POINT: emailed reset link\npage.goto('/invitations/reset-token')"
+ def test_adjacent_email_reset_annotation_allows_invitation_entry(self) -> None:
+ source = "// E2E_GUARDIAN_NAVIGATION: email-reset-entry — emailed reset link\npage.goto('/invitations/reset-token')"
self.assertEqual(self.findings(source), [])
- def test_email_marker_does_not_allow_non_invitation_path(self) -> None:
- source = "// E2E_GUARDIAN_EMAIL_RESET_ENTRY_POINT: emailed reset link\npage.goto('/admin/secret')"
+ def test_email_reset_annotation_does_not_allow_non_invitation_path(self) -> None:
+ source = "// E2E_GUARDIAN_NAVIGATION: email-reset-entry — emailed reset link\npage.goto('/admin/secret')"
self.assertTrue(any("direct page.goto" in finding for finding in self.findings(source)))
+ def test_negative_route_annotation_requires_a_static_local_route(self) -> None:
+ source = "// E2E_GUARDIAN_NAVIGATION: negative-route-guard — verify rejection\npage.goto('/admin/secret')"
+ self.assertEqual(self.findings(source), [])
+ for destination in [
+ "`/admin/${route}`",
+ "'/admin/../secret'",
+ "'/admin/%2e%2e/secret'",
+ "'//outside.invalid/admin'",
+ "'https://outside.invalid/admin'",
+ "'/admin/secret?next=/'",
+ "'/admin/secret#fragment'",
+ ]:
+ with self.subTest(destination=destination):
+ dynamic = (
+ "// E2E_GUARDIAN_NAVIGATION: negative-route-guard — verify rejection\n"
+ f"page.goto({destination})"
+ )
+ self.assertTrue(
+ any("direct page.goto" in finding for finding in self.findings(dynamic))
+ )
+
+ def test_navigation_annotation_requires_a_known_kind_and_reason(self) -> None:
+ for annotation in [
+ "// E2E_GUARDIAN_NAVIGATION: arbitrary — anything",
+ "// E2E_GUARDIAN_NAVIGATION: root-entry — ",
+ "// E2E_GUARDIAN_EMAIL_RESET_ENTRY_POINT: old marker",
+ ]:
+ with self.subTest(annotation=annotation):
+ self.assertTrue(
+ any(
+ "direct page.goto" in finding
+ for finding in self.findings(f"{annotation}\npage.goto('/admin/secret')")
+ )
+ )
+
def test_unrelated_guardian_text_does_not_allow_navigation(self) -> None:
source = "// GUARDIAN documentation describes reset links\npage.goto('/admin/secret')"
self.assertTrue(any("direct page.goto" in finding for finding in self.findings(source)))
diff --git a/tools/test_e2e_static_audit_scope.py b/tools/test_e2e_static_audit_scope.py
index c24df98de..83e816b21 100644
--- a/tools/test_e2e_static_audit_scope.py
+++ b/tools/test_e2e_static_audit_scope.py
@@ -44,7 +44,7 @@ class E2EStaticAuditMarkerScopeTests(unittest.TestCase):
def audit_email_reset_entry(self, argument: str) -> list[str]:
source = (
"const response = page.waitForResponse(() => true)\n"
- "// E2E_GUARDIAN_EMAIL_RESET_ENTRY_POINT: synthetic emailed reset entry\n"
+ "// E2E_GUARDIAN_NAVIGATION: email-reset-entry — synthetic emailed reset entry\n"
f"page.goto({argument})"
)
return audit_text(source, Path("email-reset.spec.ts"))
@@ -145,7 +145,7 @@ class E2EStaticAuditMarkerScopeTests(unittest.TestCase):
def test_explicit_root_marker_remains_scoped_to_static_root(self) -> None:
source = (
"const response = page.waitForResponse(() => true)\n"
- "// E2E_GUARDIAN_ENTRY_POINT\n"
+ "// E2E_GUARDIAN_NAVIGATION: root-entry — public application root\n"
"page.goto('/')"
)
self.assertFalse(
@@ -155,7 +155,7 @@ class E2EStaticAuditMarkerScopeTests(unittest.TestCase):
def test_explicit_negative_route_guard_remains_allowed(self) -> None:
source = (
"const response = page.waitForResponse(() => true)\n"
- "// Negative route-guard: verifies authorization rejection.\n"
+ "// E2E_GUARDIAN_NAVIGATION: negative-route-guard — verifies authorization rejection\n"
"page.goto('/admin/secret')"
)
self.assertFalse(
@@ -166,30 +166,30 @@ class E2EStaticAuditMarkerScopeTests(unittest.TestCase):
)
def test_marker_must_be_adjacent_to_its_navigation(self) -> None:
- source = "// E2E_GUARDIAN_EMAIL_RESET_ENTRY_POINT\n\npage.goto('/invitations/reset-token')"
+ source = "// E2E_GUARDIAN_NAVIGATION: email-reset-entry — emailed entry\n\npage.goto('/invitations/reset-token')"
self.assertTrue(
any("direct page.goto" in finding for finding in audit_text(source, Path("scope.spec.ts")))
)
def test_one_marker_does_not_allow_a_second_navigation(self) -> None:
source = (
- "// E2E_GUARDIAN_EMAIL_RESET_ENTRY_POINT\n"
+ "// E2E_GUARDIAN_NAVIGATION: email-reset-entry — emailed entry\n"
"page.goto('/invitations/reset-token')\n"
"page.goto('/admin/secret')"
)
findings = audit_text(source, Path("scope.spec.ts"))
navigation_findings = [finding for finding in findings if "direct page.goto" in finding]
self.assertEqual(len(navigation_findings), 1)
- self.assertTrue(navigation_findings[0].endswith(":3: direct page.goto outside an explicit negative guard"))
+ self.assertTrue(navigation_findings[0].endswith(":3: direct page.goto outside an explicit navigation annotation"))
def test_one_marker_does_not_allow_two_calls_on_the_same_line(self) -> None:
source = (
"const response = page.waitForResponse(() => true)\n"
- "// E2E_GUARDIAN_EMAIL_RESET_ENTRY_POINT\n"
+ "// E2E_GUARDIAN_NAVIGATION: email-reset-entry — emailed entry\n"
"page.goto('/invitations/reset-token'); page.goto('/admin/secret')"
)
navigation_findings = [
- item for item in audit_text(source, Path("scope.spec.ts")) if "direct page.goto" in item
+ item for item in audit_text(source, Path("scope.spec.ts")) if "navigation annotation" in item
]
self.assertEqual(len(navigation_findings), 2)
@@ -198,7 +198,7 @@ class E2EStaticAuditMarkerScopeTests(unittest.TestCase):
"tests/e2e/playwright/profile-ui-recovery/reset-session-hydration.spec.ts"
).read_text(encoding="utf-8")
without_marker = spec.replace(
- "// E2E_GUARDIAN_EMAIL_RESET_ENTRY_POINT: the emailed password-reset URL.\n", ""
+ "// E2E_GUARDIAN_NAVIGATION: email-reset-entry — the emailed password-reset URL\n", ""
)
self.assertTrue(
any(
@@ -207,6 +207,30 @@ class E2EStaticAuditMarkerScopeTests(unittest.TestCase):
)
)
+ def test_negative_route_annotation_rejects_dynamic_or_unsafe_destinations(self) -> None:
+ prefix = "// E2E_GUARDIAN_NAVIGATION: negative-route-guard — verify auth rejection\n"
+ for destination in [
+ "`/admin/${resource}`",
+ "'/admin/../secret'",
+ "'/admin/%2e%2e/secret'",
+ "'//outside.invalid/admin'",
+ "'https://outside.invalid/admin'",
+ "'/admin/secret?next=/'",
+ "'/admin/secret#fragment'",
+ "'/admin\\\\secret'",
+ ]:
+ with self.subTest(destination=destination):
+ findings = audit_text(prefix + f"page.goto({destination})", Path("guard.spec.ts"))
+ self.assertTrue(any("direct page.goto" in finding for finding in findings))
+
+ def test_root_annotation_cannot_authorize_another_destination(self) -> None:
+ source = (
+ "// E2E_GUARDIAN_NAVIGATION: root-entry — public application root\n"
+ "page.goto('/admin/secret')"
+ )
+ findings = audit_text(source, Path("root.spec.ts"))
+ self.assertTrue(any("does not match" in finding for finding in findings))
+
def run_tests() -> int:
suite = unittest.defaultTestLoader.loadTestsFromModule(sys.modules[__name__])