mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-11-28 16:58:31 +01:00
ProxmoxCephTable now resolves row and drawer status indicators through getClusterIndicator(cluster, staleNotice()) so stale healthy/unknown clusters surface as Stale while live unknown-health clusters still map through HEALTH_INDICATORS[reported] and share statusIndicator={ind()} with ProxmoxCephClusterDrawer. Update test_ceph_unknown_health_exclusion_matches_source to assert those exact markers.
Contract-Neutral: updates Python documentation-parity test marker to match refactored stale-aware indicator helper in ProxmoxCephTable with no contract change.
Change-source: pulse-maintainer
202 lines
11 KiB
Python
202 lines
11 KiB
Python
#!/usr/bin/env python3
|
||
"""Bind the short deployment answers to source and the safer detailed paths.
|
||
|
||
Documentation checks, not an installed port change or environment cutover.
|
||
"""
|
||
|
||
from pathlib import Path
|
||
import unittest
|
||
|
||
|
||
ROOT = Path(__file__).resolve().parents[2]
|
||
|
||
|
||
def faq():
|
||
return (ROOT / "docs/FAQ.md").read_text(encoding="utf-8")
|
||
|
||
|
||
def answer(heading):
|
||
return " ".join(faq().split(f"### {heading}\n", 1)[1].split("\n### ", 1)[0].split())
|
||
|
||
|
||
class FAQDeploymentDocsTest(unittest.TestCase):
|
||
def test_alert_off_is_scoped_and_does_not_promise_universal_overrides(self):
|
||
text = answer("Can I disable alerts for specific metrics?")
|
||
for phrase in ("controls offered in **Alerts → Thresholds**", "save, then reopen",
|
||
"not every default has a per-resource control",
|
||
"rather than treating `-1` as a universal value",
|
||
"does not hide its readings, stop collection",
|
||
"Check both the default and any override",
|
||
"explicit threshold can remain active",
|
||
"warning and critical levels separately"):
|
||
with self.subTest(phrase=phrase):
|
||
self.assertIn(phrase, text)
|
||
runtime = (ROOT / "internal/alerts/config_runtime.go").read_text()
|
||
self.assertIn("if override.Memory != nil", runtime)
|
||
self.assertIn("result.Memory = ensureHysteresisThreshold(cloneThreshold(override.Memory))", runtime)
|
||
|
||
def test_alert_off_does_not_promise_patrol_or_queue_suppression(self):
|
||
text = answer("Can I disable alerts for specific metrics?")
|
||
for phrase in ("Patrol findings are separate from threshold alerts",
|
||
"CPU, memory, guest-disk and storage usage",
|
||
"built-in threshold when the corresponding alert default is Off",
|
||
"Disabling a notification destination is different",
|
||
"Already queued notifications can reflect earlier settings",
|
||
"Do not induce an alert, send another Test or retry the queue"):
|
||
with self.subTest(phrase=phrase):
|
||
self.assertIn(phrase, text)
|
||
adapter = (ROOT / "internal/ai/alert_threshold_adapter.go").read_text()
|
||
self.assertIn("ok && trigger > 0", adapter)
|
||
self.assertIn("return defaultVal", adapter)
|
||
for method in ("GetNodeCPUThreshold", "GetNodeMemoryThreshold", "GetGuestMemoryThreshold",
|
||
"GetGuestDiskThreshold", "GetStorageThreshold"):
|
||
self.assertIn(f"func (a *AlertThresholdAdapter) {method}", adapter)
|
||
|
||
def test_ports_distinguish_listener_mapping_and_server_host(self):
|
||
text = answer("How do I change the port?")
|
||
for phrase in ("`FRONTEND_PORT`", "default **7655**", "`PULSE_AGENT_INGEST_PORT`",
|
||
"`8080:7655`", "`PULSE_PORT`", "inside the Pulse container",
|
||
"not on the Proxmox host", "active Pulse service",
|
||
"service-manager reload", "maintenance window"):
|
||
with self.subTest(phrase=phrase):
|
||
self.assertIn(phrase, text)
|
||
config = (ROOT / "internal/config/config.go").read_text()
|
||
self.assertIn('envconfig:"FRONTEND_PORT" default:"7655"', config)
|
||
self.assertIn('envconfig:"PULSE_AGENT_INGEST_PORT"', config)
|
||
compose = (ROOT / "docker-compose.yml").read_text()
|
||
self.assertIn('${PULSE_PORT:-7655}:7655', compose)
|
||
|
||
def test_existing_deployment_and_security_survive_port_change(self):
|
||
text = answer("How do I change the port?")
|
||
for phrase in ("existing container manager", "recreate/redeploy",
|
||
"preserving the same image, data mount and other settings",
|
||
"`docker restart` does not apply a new port mapping",
|
||
"Do not delete a data volume", "fresh `docker run` command",
|
||
"reverse proxy's upstream port separately",
|
||
"do not expose Pulse directly", "inspections private",
|
||
"TROUBLESHOOTING.md#port-change-didnt-take-effect"):
|
||
with self.subTest(phrase=phrase):
|
||
self.assertIn(phrase, text)
|
||
|
||
def test_override_handover_is_scoped_applied_and_verified(self):
|
||
text = answer("Why can't I change settings in the UI?")
|
||
for phrase in ("warning that names an environment variable", "If it is intentional, keep it",
|
||
"do not remove unrelated authentication or security overrides",
|
||
"remove only its override", "active deployment source",
|
||
"Docker require recreation/redeployment, not `docker restart`",
|
||
"service-manager reload and restart", "Preserve the image, data mount, credentials",
|
||
"does not change the running process's environment",
|
||
"check both the warning and effective value",
|
||
"does not necessarily erase the saved value", "`ALLOWED_ORIGINS`",
|
||
"no environment warning", "Do not post full environment"):
|
||
with self.subTest(phrase=phrase):
|
||
self.assertIn(phrase, text)
|
||
config = (ROOT / "internal/config/config.go").read_text()
|
||
self.assertIn('cfg.EnvOverrides["ALLOWED_ORIGINS"] = true', config)
|
||
form = (ROOT / "frontend-modern/src/components/Settings/DiscoverySettingsForm.tsx").read_text()
|
||
self.assertIn('props.envOverrides().discoveryEnabled || props.savingDiscoverySettings()', form)
|
||
self.assertIn('sectionPresentation().environmentOverrideMessage', form)
|
||
|
||
def test_token_forwarder_keeps_browser_origin_checks(self):
|
||
text = " ".join((ROOT / "docs/TROUBLESHOOTING.md").read_text().split(
|
||
"### CORS errors\n", 1)[1].split("\n---", 1)[0].split())
|
||
for phrase in ("`CSRF origin validation failed`", "different origin",
|
||
"Keep `Origin`, `Referer` and `Sec-Fetch-Site` intact",
|
||
"trusted page's exact origin above, not `*`",
|
||
"authentication alone is not a CSRF check",
|
||
"prevents Pulse from detecting that write"):
|
||
with self.subTest(phrase=phrase):
|
||
self.assertIn(phrase, text)
|
||
self.assertNotIn("authenticates its callers can remove those headers", text)
|
||
|
||
def test_cors_repair_is_shipped_without_weakening_other_boundaries(self):
|
||
source = (ROOT / "docs/TROUBLESHOOTING.md").read_bytes()
|
||
self.assertEqual(source,
|
||
(ROOT / "frontend-modern/public/docs/TROUBLESHOOTING.md").read_bytes())
|
||
text = " ".join(source.decode().split("### CORS errors\n", 1)[1].split(
|
||
"\n---", 1)[0].split())
|
||
for phrase in ("does not replace authentication, CSRF protection or TLS",
|
||
"needs a browser session cookie", "not their trust boundary",
|
||
"Keep cookies, authorization headers, API tokens",
|
||
"not a credential-bearing request or HAR file"):
|
||
with self.subTest(phrase=phrase):
|
||
self.assertIn(phrase, text)
|
||
|
||
def test_saml_registration_and_test_warnings_match_source(self):
|
||
text = answer("Can I use Single Sign-On (SSO)?")
|
||
for phrase in (
|
||
"**Test** checks metadata first",
|
||
"**URL format OK** applies only to manual SSO URL checks",
|
||
"**Metadata read** still reports **Sign-in not tested**",
|
||
"**No signing cert read**",
|
||
"**Expired cert found**",
|
||
"defaults the email attribute to `email`",
|
||
"editing a saved provider keeps an unset email attribute blank",
|
||
"before turning SAML sign-in on",
|
||
"open **Edit** on a saved disabled provider",
|
||
"**SP Metadata** and **ACS URL**",
|
||
"check **Settings → System** public URL and the saved provider settings",
|
||
):
|
||
with self.subTest(phrase=phrase):
|
||
self.assertIn(phrase, text)
|
||
self.assertNotIn("from the saved, enabled provider's card", text)
|
||
|
||
panel = (ROOT / "frontend-modern/src/components/Settings/SSOProvidersPanel.tsx").read_text()
|
||
for marker in (
|
||
"Open Edit to check this provider’s SP Metadata and ACS URLs.",
|
||
"const SamlEditorRegistration",
|
||
"isManual ? 'URL format OK' : isSaml ? 'Metadata read'",
|
||
"'No signing cert read'",
|
||
"'Expired cert found'",
|
||
"'Sign-in not tested'",
|
||
):
|
||
self.assertIn(marker, panel)
|
||
model = (ROOT / "frontend-modern/src/components/Settings/ssoProvidersModel.ts").read_text()
|
||
self.assertIn("samlEmailAttr: 'email'", model)
|
||
self.assertIn("samlEmailAttr: full.saml?.emailAttr ?? ''", model)
|
||
self.assertIn("if (form.samlIdpMetadataUrl.trim()) return 'saml-metadata-url';", model)
|
||
self.assertIn("if (form.samlIdpMetadataXml.trim()) return 'saml-metadata-xml';", model)
|
||
presentation = (ROOT / "frontend-modern/src/utils/ssoProviderPresentation.ts").read_text()
|
||
self.assertIn(
|
||
"Check Settings > System public URL and saved provider settings.",
|
||
presentation,
|
||
)
|
||
|
||
def test_ceph_unknown_health_exclusion_matches_source(self):
|
||
text = answer("Does Pulse monitor Ceph?")
|
||
for phrase in (
|
||
"**Proxmox → Ceph**",
|
||
"without a recognised health verdict",
|
||
"**Unknown** in both the table and cluster drawer",
|
||
"out of the **Healthy** filter",
|
||
"visible under **All**",
|
||
):
|
||
with self.subTest(phrase=phrase):
|
||
self.assertIn(phrase, text)
|
||
|
||
table = (ROOT / "frontend-modern/src/features/proxmox/ProxmoxCephTable.tsx").read_text()
|
||
for marker in (
|
||
"type CephHealth = 'healthy' | 'warning' | 'critical' | 'unknown';",
|
||
"type CephStatusFilter = 'all' | Exclude<CephHealth, 'unknown'>;",
|
||
"unknown: { variant: 'muted', label: 'Unknown', tone: 'text-muted' },",
|
||
"if (want !== 'all' && classify(cluster) !== want) return false;",
|
||
"return HEALTH_INDICATORS[reported];",
|
||
"const ind = () => getClusterIndicator(cluster, staleNotice());",
|
||
"statusIndicator={ind()}",
|
||
):
|
||
self.assertIn(marker, table)
|
||
drawer = (ROOT / "frontend-modern/src/features/proxmox/ProxmoxCephClusterDrawer.tsx").read_text()
|
||
self.assertIn("statusLabel={props.statusIndicator.label}", drawer)
|
||
|
||
def test_shipped_copy_and_detailed_destinations_exist(self):
|
||
self.assertEqual(faq(), (ROOT / "frontend-modern/public/docs/FAQ.md").read_text())
|
||
for guide, heading in (("TROUBLESHOOTING", "### Port change didn't take effect"),
|
||
("TROUBLESHOOTING", "### CORS errors"),
|
||
("CONFIGURATION", "### Common Overrides (Environment Variables)")):
|
||
with self.subTest(guide=guide, heading=heading):
|
||
self.assertIn(heading, (ROOT / "docs" / f"{guide}.md").read_text())
|
||
|
||
|
||
if __name__ == "__main__":
|
||
unittest.main()
|