Compare commits

...
Author SHA1 Message Date
rockachopa acc60d11e7 Report repo mix context failures (#104)
CI / lint (push) Successful in 9s
Release / release-candidate (push) Successful in 4s
CI / build-frontend (push) Successful in 4s
Closes #103
2026-08-06 12:17:51 +00:00
timmy b055644be9 fix: report repo mix context failures (#103)
CI / lint (pull_request) Successful in 9s
CI / build-frontend (pull_request) Successful in 5s
2026-08-06 12:17:13 +00:00
rockachopa 4602347a80 Merge pull request 'Allow mobile users to zoom the dashboard' (#102) from timmy/101-allow-mobile-dashboard-zoom into main
CI / lint (push) Successful in 8s
Release / release-candidate (push) Successful in 3s
CI / build-frontend (push) Successful in 4s
2026-08-06 11:47:33 +00:00
timmy 64b6ff6c5b fix: allow mobile dashboard zoom (#101)
CI / lint (pull_request) Successful in 9s
CI / build-frontend (pull_request) Successful in 5s
2026-08-06 11:46:46 +00:00
rockachopa 0427b3079e Merge pull request 'Return fallback for malformed Gitea collection payloads' (#100) from timmy/99-return-fallback-malformed-collection-payloads into main
CI / lint (push) Successful in 7s
Release / release-candidate (push) Successful in 4s
CI / build-frontend (push) Successful in 4s
2026-08-06 11:17:42 +00:00
timmy f4e2969fec fix: handle malformed Gitea collections (#99)
CI / lint (pull_request) Successful in 9s
CI / build-frontend (pull_request) Successful in 4s
2026-08-06 11:16:40 +00:00
rockachopa 7d5d1181c0 Merge pull request 'Show degraded status for fallback dashboard context' (#98)
CI / lint (push) Successful in 8s
Release / release-candidate (push) Successful in 4s
CI / build-frontend (push) Successful in 4s
2026-08-06 10:47:58 +00:00
timmy b41d7ad03a fix: expose degraded fallback context status (#97)
CI / lint (pull_request) Successful in 8s
CI / build-frontend (pull_request) Successful in 5s
2026-08-06 10:47:18 +00:00
rockachopa b2de3b7eeb Merge pull request 'Normalize malformed nested Gitea activity metadata' (#96) from timmy/95-normalize-malformed-nested-activity-metadata into main
CI / lint (push) Successful in 8s
Release / release-candidate (push) Successful in 4s
CI / build-frontend (push) Successful in 4s
2026-08-06 10:17:39 +00:00
timmy 1b43116fe6 fix: normalize nested activity metadata (#95)
CI / lint (pull_request) Successful in 8s
CI / build-frontend (pull_request) Successful in 4s
2026-08-06 10:16:51 +00:00
timmy 8f3bbde733 Merge pull request 'Normalize null Gitea activity feed payloads' (#94) from timmy/93-normalize-null-activity-feed into main
CI / lint (push) Successful in 8s
Release / release-candidate (push) Successful in 4s
CI / build-frontend (push) Successful in 4s
2026-08-06 09:47:06 +00:00
timmy 6e24d7db17 fix: normalize null activity feed payloads (#93)
CI / lint (pull_request) Successful in 8s
CI / build-frontend (pull_request) Successful in 5s
2026-08-06 09:46:24 +00:00
rockachopa 43a2804562 Merge pull request 'Return fallback context for incomplete current-user payload' (#92) from timmy/91-return-fallback-incomplete-current-user into main
CI / lint (push) Successful in 8s
Release / release-candidate (push) Successful in 4s
CI / build-frontend (push) Successful in 4s
2026-08-06 09:18:02 +00:00
8 changed files with 155 additions and 21 deletions

No files matched your search

+4 -16
View File
@@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Stackchain Dashboard</title>
<style>
:root { color-scheme: dark; --bg:#050c15; --panel:#0b1526; --line:#1b2d45; --text:#e5e7eb; --accent:#60a5fa; }
@@ -161,6 +161,7 @@ textarea { resize: vertical; min-height: 120px; }
<script src="static/markdown.js"></script>
<script src="static/commands.js"></script>
<script src="static/widgets.js"></script>
<script>
(function(){
const qs = (s, el=document) => el.querySelector(s);
@@ -216,7 +217,7 @@ textarea { resize: vertical; min-height: 120px; }
'<div class="muted">' + escapeHtml(p.state) + ' by ' + escapeHtml(String(p.user || '')) + '</div></div>').join('') : '<div class="muted">No PRs.</div>');
paintDeltas(data.deltas || []);
setStatus('Live · updated just now');
setStatus(data.error ? 'Degraded · ' + data.error : 'Live · updated just now');
setClock();
} catch (e) {
console.error('context failed', e);
@@ -361,20 +362,7 @@ textarea { resize: vertical; min-height: 120px; }
tickWidgets();
/* Widgets */
async function updateRepoMix() {
const el = qs('#repo-mix');
try {
const res = await fetch('api/v1/context', { headers: { Accept: 'application/json' } });
const data = await res.json();
const repos = data.repos || [];
const issues = (data.issues||[]).filter(i=>i.state==='open');
const prs = data.pull_requests || [];
el.innerHTML = '<div class="kv"><div class="label">Repos</div><div class="value">' + repos.length + '</div><div class="label">Open issues</div><div class="value">' + issues.length + '</div><div class="label">Open PRs</div><div class="value">' + prs.length + '</div></div>';
} catch (e) {
el.innerHTML = '<div class="muted">Widget unavailable.</div>';
}
}
updateRepoMix();
updateRepoMix(qs('#repo-mix'), fetch);
function widgetTick() { const el=qs('#widget-clock'); if(el) el.textContent = fmt(new Date()); }
setInterval(widgetTick, 1000);
+19
View File
@@ -0,0 +1,19 @@
async function updateRepoMix(element, fetchContext = fetch) {
try {
const response = await fetchContext('api/v1/context', {
headers: { Accept: 'application/json' },
});
if (!response.ok) throw new Error('HTTP ' + response.status);
const data = await response.json();
const repos = data.repos || [];
const issues = (data.issues || []).filter((issue) => issue.state === 'open');
const pullRequests = data.pull_requests || [];
element.innerHTML = '<div class="kv"><div class="label">Repos</div><div class="value">' + repos.length + '</div><div class="label">Open issues</div><div class="value">' + issues.length + '</div><div class="label">Open PRs</div><div class="value">' + pullRequests.length + '</div></div>';
} catch (error) {
element.innerHTML = '<div class="muted">Widget unavailable.</div>';
}
}
if (typeof module !== 'undefined' && module.exports) {
module.exports = updateRepoMix;
}
+21 -5
View File
@@ -42,11 +42,27 @@ async def activity_events() -> list[dict]:
events = await fetch(f"users/{user['login']}/activities/feeds?limit=20")
return [
{
"type": event.get("op_type", "activity"),
"actor": event.get("act_user") or {},
"repo": event.get("repo") or {},
"created_at": event.get("created", ""),
"type": (
event.get("op_type")
if isinstance(event.get("op_type"), str) and event.get("op_type")
else "activity"
),
"actor": (
event.get("act_user")
if isinstance(event.get("act_user"), dict)
else {}
),
"repo": (
event.get("repo")
if isinstance(event.get("repo"), dict)
else {}
),
"created_at": (
event.get("created")
if isinstance(event.get("created"), str)
else ""
),
}
for event in events
for event in (events or [])
if isinstance(event, dict)
]
+5
View File
@@ -81,6 +81,11 @@ async def context() -> JSONResponse:
raise ValueError("Gitea current-user response was not an object")
if not all(field in user_data for field in ("id", "login")):
raise ValueError("Gitea current-user response did not include id and login")
if any(
data is not None and not isinstance(data, list)
for data in (repo_data, issues_data, prs_data)
):
raise ValueError("Gitea collection response was not a list")
except Exception as e:
error_message = (
f"Gitea context request timed out after {CONTEXT_TIMEOUT_SECONDS:g}s"
+23
View File
@@ -203,6 +203,29 @@ async def test_context_normalizes_null_collection_payloads(monkeypatch):
assert context["pull_requests"] == []
@pytest.mark.anyio
async def test_context_returns_fallback_for_malformed_collection_payloads(monkeypatch):
async def user():
return {"id": 1, "login": "timmy"}
async def malformed_collection():
return {"message": "unexpected upstream shape"}
monkeypatch.setattr(main, "current_user", user)
monkeypatch.setattr(main, "repos", malformed_collection)
monkeypatch.setattr(main, "issues", malformed_collection)
monkeypatch.setattr(main, "pull_requests", malformed_collection)
response = await main.context()
context = json.loads(response.body)
assert response.status_code == 200
assert context["repos"] == []
assert context["issues"] == []
assert context["pull_requests"] == []
assert context["error"] == "Gitea collection response was not a list"
@pytest.mark.anyio
async def test_context_normalizes_nullable_user_profile_fields(monkeypatch):
async def user():
+38
View File
@@ -148,3 +148,41 @@ async def test_activity_events_skips_malformed_feed_entries(monkeypatch):
"repo": {"full_name": "stackchain/stackchain-dashboard"},
"created_at": "2026-08-06T08:00:00Z",
}]
@pytest.mark.anyio
async def test_activity_events_normalizes_null_feed_payload(monkeypatch):
async def fake_current_user():
return {"login": "timmy"}
async def fake_fetch(path):
return None
monkeypatch.setattr(gitea_proxy, "current_user", fake_current_user)
monkeypatch.setattr(gitea_proxy, "fetch", fake_fetch)
assert await gitea_proxy.activity_events() == []
@pytest.mark.anyio
async def test_activity_events_normalizes_malformed_nested_metadata(monkeypatch):
async def fake_current_user():
return {"login": "timmy"}
async def fake_fetch(path):
return [{
"op_type": None,
"act_user": "unknown",
"repo": None,
"created": None,
}]
monkeypatch.setattr(gitea_proxy, "current_user", fake_current_user)
monkeypatch.setattr(gitea_proxy, "fetch", fake_fetch)
assert await gitea_proxy.activity_events() == [{
"type": "activity",
"actor": {},
"repo": {},
"created_at": "",
}]
+9
View File
@@ -10,3 +10,12 @@ async def test_dashboard_renders_outside_repository_working_directory(monkeypatc
html = await dashboard()
assert "Stackchain Dashboard" in html
@pytest.mark.anyio
async def test_dashboard_viewport_allows_mobile_zoom():
html = await dashboard()
assert 'name="viewport"' in html
assert "width=device-width" in html
assert "user-scalable=no" not in html
+36
View File
@@ -1,11 +1,47 @@
import json
import subprocess
from pathlib import Path
import pytest
from src.views import dashboard
WIDGETS = Path(__file__).parents[1] / "frontend" / "widgets.js"
@pytest.mark.anyio
async def test_dashboard_renders_repo_mix_placeholder_before_javascript_runs():
html = await dashboard()
server_rendered_html = html.split("<script>", 1)[0]
assert '<div class="small" id="repo-mix">Loading…</div>' in server_rendered_html
@pytest.mark.anyio
async def test_dashboard_marks_fallback_context_as_degraded_instead_of_live():
html = await dashboard()
assert "data.error ? 'Degraded · ' + data.error : 'Live · updated just now'" in html
def test_repo_mix_reports_unavailable_for_failed_context_response():
script = f"""
const updateRepoMix = require({json.dumps(str(WIDGETS))});
const element = {{ innerHTML: 'stale counts' }};
const failedFetch = async () => ({{
ok: false,
status: 503,
json: async () => ({{ error: 'upstream unavailable' }}),
}});
updateRepoMix(element, failedFetch).then(() => {{
if (!element.innerHTML.includes('Widget unavailable.')) {{
throw new Error(`expected unavailable state, got: ${{element.innerHTML}}`);
}}
}});
"""
subprocess.run(
["node", "-e", script], check=True, capture_output=True, text=True
)