dash test runner
This commit is contained in:
@@ -17,6 +17,7 @@ PANELS = [
|
||||
"Usage summary", "Node throughput", "Request history",
|
||||
"Chat / inference",
|
||||
"Console output",
|
||||
"Test run status", "Tests & suites", "Test output",
|
||||
]
|
||||
|
||||
|
||||
@@ -295,3 +296,88 @@ def test_console_node_lifecycle_events_include_model_health():
|
||||
assert expired_event["fields"]["model_health"]["coverage_percentage"] == 0.0
|
||||
finally:
|
||||
tracker.stop()
|
||||
|
||||
|
||||
def _dashboard_html(**kwargs) -> str:
|
||||
tracker = TrackerServer(**kwargs)
|
||||
port = tracker.start()
|
||||
try:
|
||||
return urllib.request.urlopen(
|
||||
f"http://127.0.0.1:{port}/dashboard"
|
||||
).read().decode()
|
||||
finally:
|
||||
tracker.stop()
|
||||
|
||||
|
||||
def test_dashboard_testing_tab_is_admin_only():
|
||||
"""US-002: the Testing tab ships hidden and is only revealed for admins."""
|
||||
html = _dashboard_html()
|
||||
|
||||
# Tab button exists but is hidden until setAdminMode(true) reveals it.
|
||||
assert '<button id="tab-testing" style="display:none"' in html
|
||||
assert "switchDashboardTab('testing')" in html
|
||||
assert '$("tab-testing").style.display = enabled ? "" : "none"' in html
|
||||
|
||||
# Every Testing panel is data-admin-only, so updateSectionVisibility()
|
||||
# (adminOnly && !isAdmin -> hidden) keeps them hidden for non-admins.
|
||||
for panel in ("testing-status", "testing-targets", "testing-log"):
|
||||
assert f'id="{panel}"' in html
|
||||
assert html.count('data-tab="testing" data-admin-only') == 3
|
||||
|
||||
# Selecting the tab without admin rights falls back to overview, and losing
|
||||
# admin rights while on it kicks the user out.
|
||||
assert 'if ((name === "admin" || name === "testing") && !isAdmin) name = "overview";' in html
|
||||
assert 'if (!enabled && (dashboardTab === "admin" || dashboardTab === "testing"))' in html
|
||||
|
||||
|
||||
def test_dashboard_testing_tab_uses_dynamic_api_and_run_controls():
|
||||
"""US-002: targets come from the API, never a hardcoded list."""
|
||||
html = _dashboard_html()
|
||||
|
||||
# Dynamic collection + run + status endpoints from US-001.
|
||||
assert 'apiCall(`/v1/tests${refresh ? "?refresh=1" : ""}`)' in html
|
||||
assert 'apiCall("/v1/tests/run", "POST", { target })' in html
|
||||
assert 'apiCall("/v1/tests/status")' in html
|
||||
assert "fetchTestingTab" in html
|
||||
assert "testing: fetchTestingTab" in html # registered in TAB_FETCHERS
|
||||
|
||||
# Targets are rendered from the API payload (tests + suites), not literals.
|
||||
assert "testCollection.suites" in html
|
||||
assert "testCollection.tests" in html
|
||||
assert "renderTestTargets" in html
|
||||
|
||||
# Run buttons are per-target and delegated; disabled while a run is active.
|
||||
assert 'data-test-target="${esc(t.id)}"' in html
|
||||
assert "const disabled = testRunActive() ? \" disabled\" : \"\";" in html
|
||||
assert "if (testRunActive()) return;" in html # runTest() guards re-entry
|
||||
assert 'button = event.target.closest("[data-test-target]")' in html
|
||||
|
||||
# API errors are surfaced rather than swallowed.
|
||||
assert "showTestingError" in html
|
||||
assert "testingErrorText" in html
|
||||
assert 'id="testing-error"' in html
|
||||
|
||||
|
||||
def test_dashboard_testing_tab_renders_status_and_bounded_log():
|
||||
"""US-002: state, timings, exit code, outcome and an auto-refreshing log."""
|
||||
html = _dashboard_html()
|
||||
|
||||
assert "renderTestRunStatus" in html
|
||||
assert "renderTestLog" in html
|
||||
for field in ("target", "state", "outcome", "started", "ended", "elapsed", "exit code"):
|
||||
assert f'"{field}"' in html
|
||||
assert "testRun.exit_code" in html
|
||||
assert "testRun.started_at" in html
|
||||
assert "testRun.finished_at" in html
|
||||
assert "testRun.elapsed_seconds" in html
|
||||
assert "fmtElapsed" in html
|
||||
|
||||
# Success/failure is derived from the run status, not guessed from the log.
|
||||
assert '<span class="ok">success</span>' in html
|
||||
assert '<span class="bad">failure</span>' in html
|
||||
|
||||
# Bounded log view + auto-refresh while the run is in flight.
|
||||
assert "TEST_LOG_MAX_LINES" in html
|
||||
assert "lines.slice(-TEST_LOG_MAX_LINES)" in html
|
||||
assert "pollTestRunIfActive" in html
|
||||
assert "setInterval(pollTestRunIfActive, TEST_RUN_POLL_MS)" in html
|
||||
|
||||
Reference in New Issue
Block a user