Skip to content

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

TypeScript

fix(e2e): scope Guardian navigation allowances

Josué5f500b9cc7d1
diff --git a/tests/e2e/playwright/package-lock.json b/tests/e2e/playwright/package-lock.json
index 59ac514a0..02bea0104 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.71",
+ "version": "0.1.72",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-playwright-tests",
- "version": "0.1.71",
+ "version": "0.1.72",
"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 07189128b..c2cc1a0b2 100644
--- a/tests/e2e/playwright/package.json
+++ b/tests/e2e/playwright/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-playwright-tests",
- "version": "0.1.71",
+ "version": "0.1.72",
"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 c78fa6c24..e43e0da51 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,8 +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: this entry represents the URL in
- // the member's password-reset email.
+ // E2E_GUARDIAN_EMAIL_RESET_ENTRY_POINT: 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 faa24327a..0a82e468c 100755
--- a/tools/e2e_static_audit.py
+++ b/tools/e2e_static_audit.py
@@ -25,6 +25,17 @@ RULES: tuple[tuple[str, re.Pattern[str]], ...] = (
def audit_file(path: Path) -> list[str]:
text = path.read_text(encoding="utf-8")
+ return audit_text(text, path)
+
+
+def _adjacent_line(text: str, position: int) -> str:
+ line_start = text.rfind("\n", 0, position) + 1
+ previous_line_end = line_start - 1
+ previous_line_start = text.rfind("\n", 0, previous_line_end) + 1
+ return text[previous_line_start:previous_line_end]
+
+
+def audit_text(text: str, path: Path = Path("<source>")) -> list[str]:
findings: list[str] = []
for label, pattern in RULES:
for match in pattern.finditer(text):
@@ -42,20 +53,30 @@ def audit_file(path: Path) -> list[str]:
):
findings.append(f"{path}: missing critical network-response/request wait")
- # Direct navigation is allowed only in an explicitly negative terminal
- # guard, as the first application-root entry, or as a marked password-reset
- # link delivered by email. Other deep links remain forbidden.
+ # Navigation exceptions must be attached to the specific call. Searching a
+ # broad look-behind for "guard" also matches "GUARDIAN" and lets one marker
+ # bless later calls.
for match in re.finditer(r"\bpage\.goto\s*\(", text):
- before = text[max(0, match.start() - 240) : match.start()]
- after = text[match.end() : match.end() + 80]
- if re.search(r"terminal|deep.?link|foreign|missing|guard", before, re.IGNORECASE):
+ adjacent = _adjacent_line(text, match.start())
+ after = text[match.end() : match.end() + 160]
+ if re.fullmatch(
+ r"\s*//\s*Negative (?:protected-route guard|route-guard|deep-link guard|"
+ r"legacy terminal-route guard):[^\n]*",
+ adjacent,
+ re.IGNORECASE,
+ ):
continue
- if "E2E_GUARDIAN_EMAIL_RESET_ENTRY_POINT" in before and re.match(
- r"\s*['\"]\/invitations\/[^'\"]+['\"]", after
+ if (
+ re.fullmatch(
+ r"\s*//\s*E2E_GUARDIAN_EMAIL_RESET_ENTRY_POINT(?::[^\n]*)?",
+ adjacent,
+ )
+ and re.match(r"\s*['\"]\/invitations\/[^'\"]+['\"]", after)
):
continue
- if "E2E_GUARDIAN_ENTRY_POINT" in text and re.match(
- r"""\s*['\"]/?['\"]""", after
+ if (
+ re.fullmatch(r"\s*//\s*E2E_GUARDIAN_ENTRY_POINT(?::[^\n]*)?", adjacent)
+ and re.match(r"\s*['\"]/?['\"]", after)
):
continue
line = text.count("\n", 0, match.start()) + 1
diff --git a/tools/test_e2e_static_audit.py b/tools/test_e2e_static_audit.py
new file mode 100644
index 000000000..9cea67f1d
--- /dev/null
+++ b/tools/test_e2e_static_audit.py
@@ -0,0 +1,30 @@
+from __future__ import annotations
+
+import unittest
+from pathlib import Path
+
+from tools.e2e_static_audit import audit_text
+
+
+class E2EStaticAuditNavigationTests(unittest.TestCase):
+ def findings(self, source: str) -> list[str]:
+ return audit_text(
+ "const response = page.waitForResponse(() => true)\n" + source,
+ 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')"
+ 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')"
+ self.assertTrue(any("direct page.goto" in finding for finding in self.findings(source)))
+
+ 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)))
+
+
+if __name__ == "__main__":
+ unittest.main()