Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Align composed smoke safety checks with reviewed source

pulse-triage[bot]fa5858b2e0cc
diff --git a/scripts/tests/test_repo_docs_link_drift.py b/scripts/tests/test_repo_docs_link_drift.py
index eae0c5f2af..8465b32227 100644
--- a/scripts/tests/test_repo_docs_link_drift.py
+++ b/scripts/tests/test_repo_docs_link_drift.py
@@ -21,6 +21,12 @@ ALLOWED_BRANCH_TIP_DOC_URLS = {
"https://github.com/rcourtman/Pulse/blob/main/docs/AI_TRANSPARENCY.md",
}
+# This GitHub submission template needs the current contribution process, not
+# the process from an installed release. Do not admit that URL in runtime code
+# or broaden the exception to other links in the template.
+TEMPLATE_GUIDANCE_PATH = ".github/PULL_REQUEST_TEMPLATE.md"
+TEMPLATE_GUIDANCE_URL = "https://github.com/rcourtman/Pulse/blob/main/CONTRIBUTING.md#sharing-a-tested-patch"
+
SKIP_DIR_NAMES = {
".claude",
".git",
@@ -68,7 +74,60 @@ def should_skip(rel_path: str) -> bool:
return False
+def link_offenders(rel_path: str, content: str) -> list[str]:
+ for allowed_url in ALLOWED_BRANCH_TIP_DOC_URLS:
+ content = content.replace(allowed_url, "")
+ if rel_path == TEMPLATE_GUIDANCE_PATH:
+ content = re.sub(
+ re.escape(TEMPLATE_GUIDANCE_URL) + r"(?=$|[\s\"')>\]])", "", content
+ )
+ return [
+ f"{rel_path}: {match.group(0)}"
+ for pattern in FORBIDDEN_PATTERNS
+ if (match := pattern.search(content))
+ ]
+
+
class RepoDocsLinkDriftTest(unittest.TestCase):
+ def test_current_contribution_link_is_limited_to_the_submission_template(self) -> None:
+ link = f"[Sharing a tested patch]({TEMPLATE_GUIDANCE_URL})."
+ self.assertEqual(link_offenders(TEMPLATE_GUIDANCE_PATH, link), [])
+ for path in (
+ "frontend-modern/src/utils/help.ts", "install.sh",
+ ".github/ISSUE_TEMPLATE/bug.md", ".github/workflows/helper.js",
+ ):
+ with self.subTest(path=path):
+ self.assertFalse(should_skip(path))
+ self.assertTrue(link_offenders(path, link))
+
+ def test_template_exception_cannot_admit_other_branches_targets_or_anchors(self) -> None:
+ for link in (
+ TEMPLATE_GUIDANCE_URL.replace("/main/", "/master/"),
+ TEMPLATE_GUIDANCE_URL.split("#", 1)[0],
+ TEMPLATE_GUIDANCE_URL.replace("sharing-a-tested-patch", "unrelated-section"),
+ TEMPLATE_GUIDANCE_URL + "-unrelated",
+ TEMPLATE_GUIDANCE_URL.replace("CONTRIBUTING.md#sharing-a-tested-patch", "SECURITY.md"),
+ ):
+ with self.subTest(link=link):
+ self.assertTrue(link_offenders(TEMPLATE_GUIDANCE_PATH, f"[Guide]({link})"))
+
+ def test_current_guidance_does_not_hide_an_additional_drifting_link(self) -> None:
+ content = f"[Patch]({TEMPLATE_GUIDANCE_URL}) [Other](https://github.com/rcourtman/Pulse/blob/main/SECURITY.md)"
+ self.assertTrue(link_offenders(TEMPLATE_GUIDANCE_PATH, content))
+
+ def test_immutable_and_shipped_runtime_docs_remain_valid(self) -> None:
+ for link in (
+ "https://github.com/rcourtman/Pulse/blob/v6.5.0/docs/CONFIGURATION.md",
+ "https://github.com/rcourtman/Pulse/blob/39043470bc9824b35e093aa51ddac11e7f30ef06/docs/CONFIGURATION.md",
+ "/docs/CONFIGURATION.md",
+ ):
+ with self.subTest(link=link):
+ self.assertEqual(link_offenders("frontend-modern/src/utils/help.ts", link), [])
+
+ def test_existing_current_triage_disclosure_exception_is_preserved(self) -> None:
+ for link in ALLOWED_BRANCH_TIP_DOC_URLS:
+ self.assertEqual(link_offenders("scripts/triage.py", link), [])
+
def test_runtime_files_do_not_reference_branch_tip_docs(self) -> None:
offenders: list[str] = []
@@ -85,13 +144,7 @@ class RepoDocsLinkDriftTest(unittest.TestCase):
except UnicodeDecodeError:
continue
- for allowed_url in ALLOWED_BRANCH_TIP_DOC_URLS:
- content = content.replace(allowed_url, "")
-
- for pattern in FORBIDDEN_PATTERNS:
- match = pattern.search(content)
- if match:
- offenders.append(f"{rel_path}: {match.group(0)}")
+ offenders.extend(link_offenders(rel_path, content))
self.assertEqual(
offenders,
diff --git a/scripts/tests/test_vm_disk_diagnostics.py b/scripts/tests/test_vm_disk_diagnostics.py
index a5f12129af..0c6d8ff5fe 100644
--- a/scripts/tests/test_vm_disk_diagnostics.py
+++ b/scripts/tests/test_vm_disk_diagnostics.py
@@ -525,15 +525,42 @@ class ServerLogSafetyDocsTest(unittest.TestCase):
with self.subTest(phrase=phrase):
self.assertTrue(phrase in text, f"Missing safety explanation: {phrase}")
+ def assert_display_only_controls(self, state):
+ # Buffered lines are still browser-local. Follow the complete helper
+ # chain, not just the old one-line toggles, so a backend mutation in a
+ # pending-work helper cannot hide behind unchanged button handlers.
+ expected = {
+ "togglePaused": "if (!isPaused()) flushPendingLogs(); setIsPaused((prev) => !prev);",
+ "clearLogs": "resetPending(); setLogs([]);",
+ "resetPending": (
+ "pendingLogs = []; pendingCount = 0; pendingNext = 0; "
+ "if (renderFrame !== null) { cancelAnimationFrame(renderFrame); renderFrame = null; }"
+ ),
+ "flushPendingLogs": (
+ "if (disposed || pendingCount === 0) return; "
+ "const incoming = Array.from( { length: pendingCount }, "
+ "(_, index) => pendingLogs[(pendingNext - pendingCount + MAX_LOGS + index) % MAX_LOGS], ); "
+ "resetPending(); setLogs((prev) => [ "
+ "...prev.slice(Math.max(0, prev.length + incoming.length - MAX_LOGS)), ...incoming, ]); "
+ "scrollToBottom();"
+ ),
+ "scrollToBottom": "if (logContainer) { logContainer.scrollTop = logContainer.scrollHeight; }",
+ }
+ for name, body in expected.items():
+ marker = f"const {name} = () => {{"
+ self.assertEqual(state.count(marker), 1, name)
+ actual = state.split(marker, 1)[1].split("\n };", 1)[0]
+ actual = " ".join(re.sub(r"//[^\n]*", "", actual).split())
+ self.assertEqual(actual, body, name)
+ self.assertIn("if (disposed || isPaused()) return;", state)
+
def test_log_pause_cannot_substitute_for_the_backup_server_stop(self):
guide = " ".join(DOC.read_text().split("### Pause Pulse", 1)[0].split())
self.contains(guide, "**Pause Stream**", "only pauses the browser display",
"does not stop the Pulse server", "guest-agent requests",
"actual server stop procedure")
state = (ROOT / "frontend-modern/src/components/Settings/useSystemLogsPanelState.ts").read_text()
- toggle = state.split("const togglePaused = () => {", 1)[1].split("\n };", 1)[0]
- self.assertEqual(toggle.strip(), "setIsPaused((prev) => !prev);")
- self.assertIn("if (disposed || isPaused()) return;", state)
+ self.assert_display_only_controls(state)
self.assertIn("toggleTitle: 'Pause Stream'", (ROOT / "frontend-modern/src/utils/systemLogsPresentation.ts").read_text())
def test_log_level_is_server_wide_not_a_browser_filter(self):
@@ -553,8 +580,28 @@ class ServerLogSafetyDocsTest(unittest.TestCase):
"reduce server logging or erase the server's logs",
"VM_DISK_MONITORING.md#backup-safety")
state = (ROOT / "frontend-modern/src/components/Settings/useSystemLogsPanelState.ts").read_text()
- clear = state.split("const clearLogs = () => {", 1)[1].split("\n };", 1)[0]
- self.assertEqual(clear.strip(), "setLogs([]);")
+ self.assert_display_only_controls(state)
+
+ def test_display_only_controls_reject_backend_calls_and_stale_pending_work(self):
+ state = (ROOT / "frontend-modern/src/components/Settings/useSystemLogsPanelState.ts").read_text()
+ for name, operation in (
+ ("togglePaused", "apiFetchJSON('/api/monitoring/stop', { method: 'POST' });"),
+ ("clearLogs", "apiFetchJSON('/api/logs', { method: 'DELETE' });"),
+ ("resetPending", "handleLevelChange('warn');"),
+ ("flushPendingLogs", "handleLevelChange('error');"),
+ ("scrollToBottom", "mutateServer();"),
+ ):
+ marker = f"const {name} = () => {{"
+ mutated = state.replace(marker, marker + "\n " + operation)
+ with self.subTest(control=name), self.assertRaises(AssertionError):
+ self.assert_display_only_controls(mutated)
+ for before, after in (
+ ("const clearLogs = () => {\n resetPending();", "const clearLogs = () => {"),
+ ("if (disposed || isPaused()) return;", "if (disposed) return;"),
+ ("if (!isPaused()) flushPendingLogs();", "flushPendingLogs();"),
+ ):
+ with self.subTest(missing=before), self.assertRaises(AssertionError):
+ self.assert_display_only_controls(state.replace(before, after))
def test_bundle_scope_matches_the_real_export_not_the_visible_lines(self):
self.contains(self.log_help(), "complete configured log file", "retained server log buffer",