feat: export Agenda calendar snapshots (Closes #1088)
CI / lint (pull_request) Successful in 3m3s
CI / build-release (pull_request) Successful in 7s
CI / browser-journey (pull_request) Successful in 3m18s
CI / release-candidate (pull_request) Has been skipped

This commit is contained in:
timmy committed 2026-08-18 17:37:25 +00:00
1 parent 1c6f5c685f
commit 1c17fcf337
9 files changed
+425 -2

No files matched your search

@@ -11,7 +11,7 @@ if os.getenv("STACKCHAIN_RUN_RELEASE_E2E") != "1":
pytest.importorskip("playwright.sync_api")
from playwright.sync_api import expect, sync_playwright
from fake_gitea import FakeGiteaServer
from fake_gitea import AVAILABLE_ISSUES, FakeGiteaServer
from test_mobile_offline_issue_release import ACCESS_TOKEN, ROOT, release_server
@@ -250,3 +250,72 @@ def test_release_artifact_keeps_mobile_delivery_recovery_single_flight(tmp_path:
fake.shutdown()
fake.server_close()
fake_thread.join(timeout=5)
@pytest.mark.parametrize(("width", "height"), [(320, 568), (390, 844)])
def test_release_artifact_reviews_and_downloads_mobile_agenda_snapshot(
tmp_path: Path, width: int, height: int
):
archives = sorted((ROOT / "dist").glob("stackchain-dashboard-*.tar.gz"))
assert len(archives) == 1, "browser job must download exactly one assembled release archive"
original_due_dates = [item.get("due_date") for item in AVAILABLE_ISSUES]
AVAILABLE_ISSUES[0]["due_date"] = "2026-08-19"
AVAILABLE_ISSUES[1]["due_date"] = "2026-08-20"
fake = FakeGiteaServer(("127.0.0.1", 0))
fake_thread = threading.Thread(target=fake.serve_forever, daemon=True)
fake_thread.start()
fake_url = f"http://127.0.0.1:{fake.server_port}"
browser_errors: list[str] = []
failed_responses: list[str] = []
try:
with release_server(archives[0], tmp_path, fake_url) as origin, sync_playwright() as playwright:
browser = playwright.chromium.launch(args=["--ignore-certificate-errors"])
page = browser.new_page(viewport={"width": width, "height": height})
page.on("pageerror", lambda error: browser_errors.append(error.stack or str(error)))
page.on("console", lambda message: browser_errors.append(message.text) if message.type == "error" else None)
page.on("response", lambda response: failed_responses.append(f"{response.status} {response.url}") if response.status >= 400 else None)
page.goto(origin + "/", wait_until="networkidle")
page.locator('input[name="device_label"]').fill("Agenda export release phone")
page.locator('input[name="access_token"]').fill(ACCESS_TOKEN)
page.locator("#submit-sign-in").click()
page.wait_for_url(origin + "/", wait_until="networkidle")
page.locator('[data-mobile-task="queues"]').click()
page.locator('[data-mobile-queue="agenda"]').click()
expect(page.locator("#issue-sheet")).to_be_visible()
page.locator("#close-issue-sheet").click()
expect(page.locator("#issue-sheet")).to_be_hidden()
expect(page.locator("#agenda-export")).to_be_visible()
trigger = page.locator("#open-agenda-export")
expect(trigger).to_be_enabled()
bounds = trigger.bounding_box()
assert bounds and bounds["height"] >= 44
trigger.click()
expect(page.locator("#agenda-export-sheet")).to_be_visible()
expect(page.locator("#agenda-export-items input:checked")).to_have_count(2)
page.locator("#agenda-export-items input").nth(1).uncheck()
expect(page.locator("#agenda-export-status")).to_have_text("1 of 2 deadlines selected.")
assert page.evaluate("document.documentElement.scrollWidth <= window.innerWidth")
with page.expect_download() as pending:
page.locator("#share-agenda-export").click()
download = pending.value
text = Path(download.path()).read_text()
assert download.suggested_filename.startswith("stackchain-agenda-")
assert text.count("BEGIN:VEVENT") == 1
assert "SUMMARY:Ship mobile capture" in text
assert "Polish desktop filters" not in text
expect(trigger).to_be_focused()
assert browser_errors == []
assert failed_responses == []
browser.close()
finally:
for item, due_date in zip(AVAILABLE_ISSUES, original_due_dates):
if due_date is None:
item.pop("due_date", None)
else:
item["due_date"] = due_date
fake.shutdown()
fake.server_close()
fake_thread.join(timeout=5)
+118
View File
@@ -0,0 +1,118 @@
import json
import subprocess
from pathlib import Path
import pytest
from tests.dashboard_bundle import dashboard
AGENDA_CALENDAR = Path(__file__).parents[1] / "frontend" / "agenda-calendar.js"
INDEX = Path(__file__).parents[1] / "frontend" / "index.html"
def run_node(source: str):
completed = subprocess.run(["node", "-e", source], capture_output=True, text=True)
assert completed.returncode == 0, completed.stderr
return json.loads(completed.stdout)
def test_calendar_snapshot_serializes_ordered_all_day_events_with_stable_identity():
items = [
{
"repository": "stackchain/dashboard",
"number": 12,
"title": "Plan, ship; verify\\path\nnext",
"due_date": "2026-08-19T23:00:00-07:00",
"url": "https://forge.example/git/stackchain/dashboard/issues/12",
},
{
"repository": "stackchain/api",
"number": 7,
"title": "API release",
"due_date": "2026-08-20",
"url": "https://forge.example/git/stackchain/api/issues/7",
},
]
source = f"""
const calendar = require({json.dumps(str(AGENDA_CALENDAR))});
const text = calendar.serializeAgendaCalendar({json.dumps(items)}, {{generatedOn:'20260818'}});
process.stdout.write(JSON.stringify({{text}}));
"""
text = run_node(source)["text"]
assert text.startswith("BEGIN:VCALENDAR\r\nVERSION:2.0\r\n")
assert text.endswith("END:VCALENDAR\r\n")
assert text.count("BEGIN:VEVENT") == 2
assert text.index("stackchain/dashboard#12") < text.index("stackchain/api#7")
assert "UID:issue-12@stackchain-dashboard" in text
assert "DTSTART;VALUE=DATE:20260819" in text
assert "SUMMARY:Plan\\, ship\\; verify\\\\path\\nnext" in text
assert "URL:https://forge.example/git/stackchain/dashboard/issues/12" in text
assert "DTSTAMP:20260818T000000Z" in text
assert "\n" not in text.replace("\r\n", "")
def test_calendar_snapshot_folds_utf8_lines_to_rfc_octet_limit_without_splitting_characters():
item = {
"repository": "stackchain/dashboard",
"number": 99,
"title": "Launch 🚀 " + "é" * 60,
"due_date": "2026-08-21",
"url": "https://forge.example/git/stackchain/dashboard/issues/99",
}
source = f"""
const calendar = require({json.dumps(str(AGENDA_CALENDAR))});
const text = calendar.serializeAgendaCalendar([{json.dumps(item)}], {{generatedOn:'20260818'}});
process.stdout.write(JSON.stringify({{text}}));
"""
text = run_node(source)["text"]
physical_lines = text.split("\r\n")
assert all(len(line.encode("utf-8")) <= 75 for line in physical_lines)
assert any(line.startswith(" ") for line in physical_lines)
unfolded = text.replace("\r\n ", "")
assert "SUMMARY:Launch 🚀 " + "é" * 60 in unfolded
def test_calendar_snapshot_prefers_native_file_share_and_falls_back_to_one_download():
source = f"""
const calendar = require({json.dumps(str(AGENDA_CALENDAR))});
class FakeFile {{ constructor(parts, name, options) {{ this.parts=parts; this.name=name; this.type=options.type; }} }}
const shared=[];
const nativeNavigator={{canShare:payload => payload.files[0].name.endsWith('.ics'), share:async payload => shared.push(payload)}};
const clicks=[]; const revoked=[];
const document={{createElement:() => ({{click(){{clicks.push({{download:this.download,href:this.href}})}}}})}};
const urlApi={{createObjectURL:()=>'blob:agenda', revokeObjectURL:value=>revoked.push(value)}};
(async () => {{
const native = await calendar.deliverCalendarSnapshot({{text:'BEGIN:VCALENDAR', filename:'stackchain-agenda.ics', navigator:nativeNavigator, document, urlApi, FileCtor:FakeFile}});
const fallback = await calendar.deliverCalendarSnapshot({{text:'BEGIN:VCALENDAR', filename:'stackchain-agenda.ics', navigator:{{}}, document, urlApi, FileCtor:FakeFile}});
process.stdout.write(JSON.stringify({{native,fallback,shared:shared.length,clicks,revoked}}));
}})();
"""
assert run_node(source) == {
"native": "shared",
"fallback": "downloaded",
"shared": 1,
"clicks": [{"download": "stackchain-agenda.ics", "href": "blob:agenda"}],
"revoked": ["blob:agenda"],
}
@pytest.mark.anyio
async def test_agenda_export_review_requires_selection_and_exposes_snapshot_privacy_boundary():
markup = INDEX.read_text()
source = await dashboard()
feature_source = source + AGENDA_CALENDAR.read_text()
assert 'id="open-agenda-export"' in markup
assert 'id="agenda-export-sheet"' in markup
assert 'id="agenda-export-items"' in markup
assert 'id="share-agenda-export"' in markup
assert "This exports a snapshot" in markup
assert "agendaMyWork(activeMyWork)" in feature_source
assert "checkbox.checked" in feature_source
assert "serializeAgendaCalendar(selected" in feature_source
assert "deliverCalendarSnapshot" in feature_source
assert "agenda-export-empty" in feature_source
+1
View File
@@ -1146,6 +1146,7 @@ def test_install_precaches_complete_subpath_scoped_app_shell():
"/dashboard/static/offline-today.js",
"/dashboard/static/my-work.js",
"/dashboard/static/agenda-replan.js",
"/dashboard/static/agenda-calendar.js",
"/dashboard/static/protect-today.js",
"/dashboard/static/notification-undo.js",
"/dashboard/static/card-planning.js",