fix(observability): polish topbar alert indicator
All checks were successful
CD Pipeline / deploy (push) Successful in 1m33s

This commit is contained in:
OoO
2026-05-05 21:52:45 +08:00
parent 422137efa8
commit d93ad659ba
3 changed files with 71 additions and 13 deletions

View File

@@ -140,6 +140,22 @@ REQUIRED_BASE_SNIPPETS = [
"momo-observability-mode",
"/observability/overview",
"/observability/api/health_indicator",
"momo-obs-link",
"momo-obs-badge",
"classList.add('is-alert')",
]
FORBIDDEN_BASE_PATTERNS = [
Rule(
"inline_obs_badge_style",
re.compile(r"id=\"momo-obs-badge\"[^>]*style=", re.IGNORECASE | re.DOTALL),
"Topbar 觀測台 badge 不得使用 inline style請使用 .momo-obs-badge。",
),
Rule(
"hardcoded_obs_alert_color",
re.compile(r"(#dc3545|link\.style\.color|badge\.style\.display)", re.IGNORECASE),
"Topbar 觀測台告警狀態不得用 JS/inline 硬改色;請切換 is-alert / hidden。",
),
]
@@ -192,6 +208,23 @@ def scan_required_snippets(relative_path: Path, snippets: list[str], label: str)
return findings
def scan_base_topbar() -> list[str]:
path = ROOT / BASE_PATH
if not path.exists():
return [f"{BASE_PATH}: missing required base/topbar file"]
text = path.read_text(encoding="utf-8")
findings = scan_required_snippets(BASE_PATH, REQUIRED_BASE_SNIPPETS, "base/topbar")
for rule in FORBIDDEN_BASE_PATTERNS:
for match in rule.pattern.finditer(text):
line = line_number(text, match.start())
snippet = match.group(0).replace("\n", " ")[:90]
findings.append(
f"{BASE_PATH}:{line}: [{rule.code}] {rule.message} ({snippet})"
)
return findings
def scan_shell() -> list[str]:
path = ROOT / SHELL_PATH
if not path.exists():
@@ -273,7 +306,7 @@ def main() -> int:
findings.extend(scan_file(Path(template_path)))
findings.extend(scan_css())
findings.extend(scan_shell())
findings.extend(scan_required_snippets(BASE_PATH, REQUIRED_BASE_SNIPPETS, "base/topbar"))
findings.extend(scan_base_topbar())
findings.extend(scan_nav_contract())
if findings:
@@ -286,7 +319,7 @@ def main() -> int:
print(f"- templates checked: {len(TEMPLATE_PATHS)}")
print(f"- css guardrails checked: {len(REQUIRED_CSS_SNIPPETS)}")
print(f"- sidebar/nav guardrails checked: {len(REQUIRED_SHELL_SNIPPETS)}")
print(f"- base/topbar guardrails checked: {len(REQUIRED_BASE_SNIPPETS)}")
print(f"- base/topbar guardrails checked: {len(REQUIRED_BASE_SNIPPETS) + len(FORBIDDEN_BASE_PATTERNS)}")
print(f"- nav contract checked: {len(OBSERVABILITY_NAV_ITEMS)} pages")
return 0