Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions templates/dashboard_home.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
.section-grid > section, .section-grid + section { margin-top: 24px; }
.link { margin-top: 12px; }
.project-context { font-size: 14px; }
.historical-entry { margin-top: 22px; padding: 18px; border: 1px solid var(--border); border-left: 4px solid var(--blue); border-radius: 12px; background: var(--panel); }
.historical-entry a { display: inline-block; margin-top: 10px; font-weight: 750; }
@media (max-width: 760px) {
.hero { align-items: flex-start; }
.hero-marker { display: none; }
Expand Down Expand Up @@ -282,6 +284,13 @@ <h3>證據尚不可用,無法顯示結果</h3>
</section>


<section class="historical-entry" id="stage2-history-entry" aria-labelledby="stage2-history-entry-heading">
<div class="eyebrow">STAGE 2 · 歷史證據</div>
<h2 id="stage2-history-entry-heading">真實設備驗證,保留當時的證據與限制</h2>
<p>查看各自獨立的 Lab1/Lab2 唯讀驗證,以及 2026-10-20 人工切換觀察。與上方 Stage-0 Fake Adapter 模擬流程分開;不表示目前設備狀態。</p>
<a href="{{ url_for('reports') }}#stage2-historical-vrrp">查看 Stage 2 VRRP 歷史成果與來源 →</a>
</section>

<details class="project-context">
<summary>平台定位與展示範圍 · 工程師補充說明</summary>
<div lang="en">
Expand Down
95 changes: 95 additions & 0 deletions templates/dashboard_reports.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,44 @@
tr:last-child td { border-bottom: 0; }
th { color: var(--muted); font-weight: 800; white-space: nowrap; }
.empty { color: #7a4d00; font-weight: 700; }
.historical-vrrp { border-top: 4px solid var(--blue); overflow-wrap: anywhere; }
.historical-vrrp h3 { margin-top: 0; }
.historical-vrrp .history-label { color: var(--blue); font-size: 12px; font-weight: 800; letter-spacing: .04em; margin-bottom: 6px; }
.history-card-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; }
.history-boundary { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 8px 0 16px; color: var(--unknown); font-size: 13px; }
.history-boundary span { border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px; background: var(--unknown-bg); }
.history-labs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 18px 0; }
.history-lab { border: 1px solid #bed0eb; border-radius: 12px; background: #f7faff; padding: 18px; }
.history-lab h3 { margin: 0; font-size: 20px; }
.history-card-heading svg { width: 34px; height: 34px; fill: none; stroke: var(--blue); stroke-width: 1.5; }
.historical-vrrp .history-kind { color: #344054; font-size: 12px; font-weight: 750; margin: 12px 0 6px; }
.history-role { color: #183b69; font-size: 30px; font-weight: 850; letter-spacing: -.02em; }
.history-role small { display: block; color: var(--muted); font-size: 13px; font-weight: 500; letter-spacing: 0; }
.history-facts { display: flex; flex-wrap: wrap; gap: 12px 32px; margin: 12px 0; }
.history-facts dt { color: var(--muted); font-size: 13px; }
.history-facts dd { margin: 0; font-size: 22px; font-weight: 800; }
.history-lab .history-baseline { margin: 14px 0 8px; font-size: 12px; }
.history-baseline code { display: block; color: var(--text); }
.history-source-link { display: inline-block; padding: 4px 0; font-size: 14px; }
.history-manual { border-top: 1px solid var(--border); padding-top: 20px; margin-top: 20px; }
.history-manual h3 { margin-bottom: 4px; font-size: 20px; }
.history-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 14px 0; }
.history-metrics > div { padding: 12px; border: 1px solid var(--border); border-radius: 8px; background: #f9fbfd; }
.history-metrics dt { color: var(--muted); font-size: 13px; }
.history-metrics dd { margin: 6px 0 0; color: var(--text); font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.history-metrics .history-loss { background: #fff9ec; border-color: #e7cf93; }
.history-metrics .history-loss dd { color: #805400; }
.history-timing { display: flex; flex-wrap: wrap; gap: 12px 28px; margin: 14px 0; }
.history-timing dt { font-size: 13px; color: var(--muted); }
.history-timing dd { margin: 3px 0 0; color: #805400; font-weight: 750; }
.history-limit { padding: 12px 14px; border-left: 3px solid #bb8b26; background: #fff9ec; color: #614500; font-size: 14px; }
.history-provenance { padding-top: 18px; border-top: 1px solid var(--border); margin-top: 18px; font-size: 13px; }
.history-provenance p:last-child { margin-bottom: 0; }
@media (max-width: 620px) {
.history-labs { grid-template-columns: 1fr; }
.history-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.history-metrics dd { font-size: 24px; }
}
@media (max-width: 820px) {
.count-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
Expand All @@ -159,6 +197,63 @@
<h1>Reports</h1>
<p>Local evidence browser for generated JSON and HTML reports. Result quality is separate from artifact availability, and this GET-only page never starts collection or execution.</p>

<section class="historical-vrrp" id="stage2-historical-vrrp" lang="zh-Hant" aria-labelledby="stage2-historical-vrrp-heading" data-evidence-source="PINNED_PUBLIC_DOCUMENTATION">
<p class="history-label">STAGE 2 · HISTORICAL EVIDENCE</p>
<h2 id="stage2-historical-vrrp-heading">VRRP 歷史真實設備驗證</h2>
<p>兩次不同時間、不同授權的唯讀驗證。以下是固定版本的公開文件摘要,不是目前設備狀態,也不能代表雙機同步健康。</p>
<div class="history-boundary" aria-label="展示與授權邊界">
<span>STAGE2_FORMAL_STATUS = CLOSED</span><span>LIVE_AUTHORIZED = NO</span><span>離線展示 · 不重新採集</span>
</div>
<div class="history-labs">
<article class="history-lab" data-history-lab="lab1">
<div class="history-card-heading"><h3>MikroTik Lab1</h3><svg viewBox="0 0 32 32" aria-hidden="true" focusable="false"><rect x="3" y="9" width="26" height="14" rx="3"/><path d="M7 18h3m3 0h3m3 0h3M8 13h16M10 9V5m12 4V5"/></svg></div>
<p class="history-kind">HISTORICAL_LIVE_PROOF</p>
<div class="history-role" data-history-role="MASTER">MASTER<small>該次驗證的歷史角色</small></div>
<dl class="history-facts"><div><dt>VRID</dt><dd>88</dd></div><div><dt>Priority</dt><dd>150</dd></div></dl>
<p>指定目標、一次授權;成功驗證的固定命令執行 1 次,重試 0 次。Lab1 先前兩次嘗試曾 fail-closed,第三次才通過。</p>
<p class="history-baseline">原驗證基準<code>39da163d80e5d8b2dde215eb6c0979448d0739fd</code></p>
<a class="history-source-link" href="https://github.com/Robinlee0929/Network_Automation_Lab/blob/4b3f139af072d88cb6fc564b5cb37319faefe3f0/docs/automation_readiness/actual_automation_integration_plan.md#historical-lab1-proven-scope-and-result">Lab1 公開紀錄 ↗</a>
</article>
<article class="history-lab" data-history-lab="lab2">
<div class="history-card-heading"><h3>MikroTik Lab2</h3><svg viewBox="0 0 32 32" aria-hidden="true" focusable="false"><rect x="3" y="9" width="26" height="14" rx="3"/><path d="M7 18h3m3 0h3m3 0h3M8 13h16M10 9V5m12 4V5"/></svg></div>
<p class="history-kind">HISTORICAL_LIVE_PROOF</p>
<div class="history-role" data-history-role="BACKUP">BACKUP<small>該次驗證的歷史角色</small></div>
<dl class="history-facts"><div><dt>VRID</dt><dd>88</dd></div><div><dt>Priority</dt><dd>100</dd></div></dl>
<p>另一次獨立授權;固定命令執行 1 次,重試 0 次。這次證明沒有重新驗證 Lab1,授權已消耗,不能再次使用。</p>
<p class="history-baseline">原驗證基準<code>ea73196281e38a01af7bf959cc5e1bc60b0b2499</code></p>
<a class="history-source-link" href="https://github.com/Robinlee0929/Network_Automation_Lab/blob/4b3f139af072d88cb6fc564b5cb37319faefe3f0/docs/automation_readiness/actual_automation_integration_plan.md#later-lab2-proof-and-persistent-startup-closure-evidence">Lab2 公開紀錄 ↗</a>
</article>
</div>
<p>兩次成功證明均限定 <code>mikrotik.vrrp_status</code> 與 <code>/interface vrrp print detail</code>;此處僅列出歷史範圍,不提供執行入口。</p>

<article class="history-manual" id="manual-failover-observation" data-evidence-kind="MANUAL_FAILOVER_OBSERVATION">
<p class="history-kind">MANUAL_FAILOVER_OBSERVATION</p>
<h3>人工 Failover/Recovery 觀察</h3>
<p><time datetime="2026-10-20">2026-10-20</time> · Owner 提供的人工角色觀察與 Ping 統計,與上方兩次 Live Proof 分開。</p>
<dl class="history-metrics">
<div><dt>Ping Replies</dt><dd>205</dd></div>
<div class="history-loss"><dt>Timeouts</dt><dd>2</dd></div>
<div><dt>Total</dt><dd>207</dd></div>
<div class="history-loss"><dt>Packet Loss</dt><dd>0.9662%</dd></div>
</dl>
<dl class="history-timing">
<div><dt>Failover Time</dt><dd>NOT_MEASURED</dd></div>
<div><dt>Recovery Time</dt><dd>NOT_MEASURED</dd></div>
</dl>
<p class="history-limit">有封包遺失,不能宣稱零中斷。缺少逐封包及事件時間戳,不能把兩次逾時分別歸因為切換與恢復,也不能推算收斂時間。Lab2 的 625 ms 僅是單次命令耗時,不是 VRRP Failover Time。</p>
<p>人工紀錄描述 Lab1 LAN 隔離後 Lab2 接手,恢復後回到 Lab1 MASTER/Lab2 BACKUP;這不是雙機同步量測,也不是 NAL 自動 Failover 或 DL-06-02 官方 Live Proof。</p>
<a class="history-source-link" href="https://github.com/Robinlee0929/Network_Automation_Lab/blob/4b3f139af072d88cb6fc564b5cb37319faefe3f0/docs/portfolio/manual_vrrp_failover_20261020.md">閱讀人工觀察摘要與限制 ↗</a>
</article>

<div class="history-provenance">
<h3>固定來源與正式邊界</h3>
<p>來源連結固定於公開 Commit <code>4b3f139af072d88cb6fc564b5cb37319faefe3f0</code>,是文件版本,不是新的設備測試基準。本頁不讀取外部 ZIP、原始設備輸出或私有證據,也不自動檢查外部連結。</p>
<p>人工摘要保留原文件狀態 <code>LOCAL_DOCS_DRAFT_READY_FOR_OWNER_REVIEW</code>;展示不提升其驗收狀態。原始觀察來自 Owner,離線整理不等於獨立重驗設備。</p>
<p>Stage 2 結案範圍為 <code>DOCUMENTATION_ONLY_FIXED_HEAD</code>,原結案 SHA:<code>0f774c47b2529a5f93c0b0abd7c245b85e2d61d2</code>。<a href="https://github.com/Robinlee0929/Network_Automation_Lab/blob/4b3f139af072d88cb6fc564b5cb37319faefe3f0/docs/automation_readiness/stage2_formal_closure.md#decision-summary">閱讀 Formal Closure ↗</a>。CLOSED 不代表部署驗收;任何新 Live 操作仍需另行授權。</p>
<p>上方歷史摘要與 Stage-0 Fake Adapter 模擬證據不同,也不納入下方本機報告計數。Missing/Malformed 報告保持原狀,不以歷史紀錄補成 PASS。</p>
</div>
</section>

<section class="reports-overview" aria-labelledby="reports-overview-heading">
<h2 id="reports-overview-heading">Evidence Review Summary</h2>
<div class="state-panel state-{{ reports_summary.collection_state|lower }}" data-collection-state="{{ reports_summary.collection_state }}" role="status">
Expand Down
175 changes: 175 additions & 0 deletions tests/test_stage2_historical_evidence_presentation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import html
import re
import socket
import subprocess
from pathlib import Path
from unittest.mock import Mock
from urllib.parse import urlsplit

import pytest

import dashboard_app as dashboard
import dashboard_command_runner as runner
import network_lab


ROOT = Path(__file__).resolve().parents[1]
SOURCE_COMMIT = "4b3f139af072d88cb6fc564b5cb37319faefe3f0"
SOURCE_PREFIX = f"/Robinlee0929/Network_Automation_Lab/blob/{SOURCE_COMMIT}/"
PLAN = "docs/automation_readiness/actual_automation_integration_plan.md"
MANUAL = "docs/portfolio/manual_vrrp_failover_20261020.md"
CLOSURE = "docs/automation_readiness/stage2_formal_closure.md"


def _page(client, path):
response = client.get(path)
assert response.status_code == 200
return response.get_data(as_text=True)


def _history(source):
match = re.search(r'<section class="historical-vrrp".*?</section>', source, re.S)
assert match is not None
return match.group(0)


def _facts(source):
return dict(re.findall(r"<dt>([^<]+)</dt><dd>([^<]+)</dd>", source))


@pytest.fixture
def reviewer(tmp_path):
app = dashboard.create_reviewer_app(tmp_path / "reports", tmp_path / "logs")
app.testing = True
return app, app.test_client()


@pytest.mark.parametrize(
("lab", "role", "priority", "baseline"),
[
("lab1", "MASTER", "150", "39da163d80e5d8b2dde215eb6c0979448d0739fd"),
("lab2", "BACKUP", "100", "ea73196281e38a01af7bf959cc5e1bc60b0b2499"),
],
)
def test_each_lab_is_an_independent_historical_record(reviewer, lab, role, priority, baseline):
_, client = reviewer
history = _history(_page(client, "/reports"))
card = re.search(fr'<article class="history-lab" data-history-lab="{lab}">.*?</article>', history, re.S).group(0)
assert "HISTORICAL_LIVE_PROOF" in card
assert f'data-history-role="{role}"' in card
assert _facts(card) == {"VRID": "88", "Priority": priority}
assert baseline in card
assert "1 次" in card and "重試 0 次" in card
assert "不同時間、不同授權" in history
assert "不是目前設備狀態" in history and "不能代表雙機同步健康" in history
assert "CURRENT_STATUS" not in history and "CURRENT_PAIR_HEALTH" not in history
assert "STAGE2_FORMAL_STATUS = CLOSED" in history and "LIVE_AUTHORIZED = NO" in history
assert baseline in (ROOT / PLAN).read_text(encoding="utf-8")


def test_manual_observation_preserves_loss_and_unmeasured_timing(reviewer):
_, client = reviewer
history = _history(_page(client, "/reports"))
manual = re.search(r'<article class="history-manual".*?</article>', history, re.S).group(0)
assert 'data-evidence-kind="MANUAL_FAILOVER_OBSERVATION"' in manual
assert '<time datetime="2026-10-20">' in manual
assert _facts(manual) == {
"Ping Replies": "205", "Timeouts": "2", "Total": "207", "Packet Loss": "0.9662%",
"Failover Time": "NOT_MEASURED", "Recovery Time": "NOT_MEASURED",
}
assert "不能宣稱零中斷" in manual
assert "不能把兩次逾時分別歸因" in manual
assert "625 ms 僅是單次命令耗時,不是 VRRP Failover Time" in manual
document = (ROOT / MANUAL).read_text(encoding="utf-8")
assert "205 replies and 2 timeouts" in document
assert "207 observations: 0.9662%" in document
assert "NOT_MEASURED" in document
assert "LOCAL_DOCS_DRAFT_READY_FOR_OWNER_REVIEW" in document and "LOCAL_DOCS_DRAFT_READY_FOR_OWNER_REVIEW" in history


def test_provenance_links_pin_public_documents_and_preserve_closure_baseline(reviewer):
_, client = reviewer
history = _history(_page(client, "/reports"))
links = [urlsplit(html.unescape(url)) for url in re.findall(r'href="([^"]+)"', history)]
expected = {
(PLAN, "historical-lab1-proven-scope-and-result"),
(PLAN, "later-lab2-proof-and-persistent-startup-closure-evidence"),
(MANUAL, ""), (CLOSURE, "decision-summary"),
}
assert len(links) == len(expected)
assert all(link.scheme == "https" and link.netloc == "github.com" and not link.query for link in links)
assert all(link.path.startswith(SOURCE_PREFIX) for link in links)
assert {(link.path.removeprefix(SOURCE_PREFIX), link.fragment) for link in links} == expected
for document, anchor in expected:
contents = (ROOT / document).read_text(encoding="utf-8")
if anchor:
headings = re.findall(r"^#+ (.+)$", contents, re.M)
assert anchor in [heading.lower().strip().replace(" ", "-") for heading in headings]
closure = (ROOT / CLOSURE).read_text(encoding="utf-8")
for marker in ("DOCUMENTATION_ONLY_FIXED_HEAD", "0f774c47b2529a5f93c0b0abd7c245b85e2d61d2"):
assert marker in history and marker in closure
assert "不是新的設備測試基準" in history
assert "不讀取外部 ZIP" in history and "不自動檢查外部連結" in history


def test_home_entry_keeps_stage0_fake_journey_separate(reviewer):
_, client = reviewer
source = _page(client, "/")
journey = re.search(r'<section class="journey-section".*?</section>', source, re.S).group(0)
assert "Fake Adapter" in journey
assert "HISTORICAL_LIVE_PROOF" not in journey
assert source.index('id="stage2-history-entry"') > source.index(journey) + len(journey)
assert 'href="/reports#stage2-historical-vrrp"' in source
assert "不表示目前設備狀態" in source


@pytest.mark.parametrize("evidence_state", ["MISSING", "MALFORMED"])
def test_history_never_upgrades_missing_or_malformed_local_reports(tmp_path, evidence_state):
reports_dir = tmp_path / "reports"
if evidence_state == "MALFORMED":
artifact = reports_dir / "fixture-router" / "day4_baseline_validation.json"
artifact.parent.mkdir(parents=True)
artifact.write_text("{broken-json", encoding="utf-8")
app = dashboard.create_reviewer_app(reports_dir, tmp_path / "logs")
app.testing = True
client = app.test_client()
source = _page(client, "/reports")
assert f'data-collection-state="{evidence_state}"' in source
assert re.search(r'data-count-field="pass_count"><dt>PASS results</dt><dd>0</dd>', source)
if evidence_state == "MALFORMED":
assert "Result: MALFORMED" in source
history = _history(source)
assert 'data-evidence-source="PINNED_PUBLIC_DOCUMENTATION"' in history
assert "不納入下方本機報告計數" in history
assert "不以歷史紀錄補成 PASS" in history
assert 'class="badge pass"' not in history
assert _history(_page(client, "/reports?status=PASS&mode=live")) == history


@pytest.mark.parametrize("path", ["/", "/reports"])
def test_historical_pages_do_not_execute_write_or_fetch_sources(reviewer, tmp_path, monkeypatch, path):
app, client = reviewer
guards = {name: Mock(side_effect=AssertionError(name)) for name in (
"runner", "subprocess", "execution_log", "report_writer", "file_write", "network",
)}
before = {p.relative_to(tmp_path): p.read_bytes() for p in tmp_path.rglob("*") if p.is_file()}
with monkeypatch.context() as patch:
patch.setattr(dashboard, "execute_registered_command", guards["runner"])
patch.setattr(runner, "execute_command", guards["runner"])
patch.setattr(runner, "_write_log", guards["execution_log"])
patch.setattr(network_lab, "write_report_index_html", guards["report_writer"])
patch.setattr(subprocess, "run", guards["subprocess"])
patch.setattr(subprocess, "Popen", guards["subprocess"])
patch.setattr(socket, "socket", guards["network"])
for method in ("write_text", "write_bytes", "mkdir", "touch"):
patch.setattr(Path, method, guards["file_write"])
source = _page(client, path)
assert client.head(path).status_code == 200
assert set(client.options(path).allow) == {"GET", "HEAD", "OPTIONS"}
for guard in guards.values():
guard.assert_not_called()
assert {p.relative_to(tmp_path): p.read_bytes() for p in tmp_path.rglob("*") if p.is_file()} == before
assert "run_command" not in app.view_functions
assert all(rule.methods <= {"GET", "HEAD", "OPTIONS"} for rule in app.url_map.iter_rules())
for control in ("<form", "<button", "<script", 'method="post"'):
assert control not in source.lower()