feat: reconcile Week Ahead edits per day (Closes #1184)
CI / lint (pull_request) Successful in 3m52s
CI / build-release (pull_request) Successful in 10s
CI / browser-journey (pull_request) Successful in 5m36s
CI / release-candidate (pull_request) Has been skipped

This commit is contained in:
timmy committed 2026-08-20 15:43:35 +00:00
1 parent 43066a0822
commit e0f7c711ed
18 files changed
+344 -52

No files matched your search

@@ -3,6 +3,7 @@ from __future__ import annotations
import json
import os
import threading
from datetime import date, timedelta
from pathlib import Path
import pytest
@@ -77,3 +78,80 @@ def test_release_artifact_plans_seven_touch_safe_mobile_dates(
fake.shutdown()
fake.server_close()
thread.join(timeout=5)
@pytest.mark.parametrize(("width", "height"), [(320, 568), (390, 844)])
def test_release_artifact_reconciles_only_the_week_day_changed_on_both_devices(
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"
fake = FakeGiteaServer(("127.0.0.1", 0))
thread = threading.Thread(target=fake.serve_forever, daemon=True)
thread.start()
puts: list[dict] = []
try:
with release_server(archives[0], tmp_path, f"http://127.0.0.1:{fake.server_port}") as origin, sync_playwright() as playwright:
browser = playwright.chromium.launch(args=["--ignore-certificate-errors"])
page = browser.new_page(viewport={"width": width, "height": height})
page_errors: list[str] = []
page.on("pageerror", lambda error: page_errors.append(str(error)))
def week_route(route):
if route.request.method == "PUT":
body = json.loads(route.request.post_data or "{}")
puts.append(body)
if len(puts) == 1:
route.fulfill(status=409, content_type="application/json", body='{"message":"changed"}')
return
route.fulfill(status=200, content_type="application/json", body=json.dumps({
"revision": 6, "timezone": body["timezone"], "days": body["days"],
}))
return
if puts:
changed_date = puts[0]["days"][0]["plan_date"]
following_date = (date.fromisoformat(changed_date) + timedelta(days=1)).isoformat()
route.fulfill(status=200, content_type="application/json", body=json.dumps({
"revision": 5, "timezone": puts[0]["timezone"], "days": [
{"plan_date": changed_date, "ids": [], "capacity_minutes": 90, "estimates": {}},
{"plan_date": following_date, "ids": [], "capacity_minutes": 30, "estimates": {}},
],
}))
return
route.fulfill(status=200, content_type="application/json", body=json.dumps({
"revision": 4, "timezone": None, "days": [],
}))
page.route("**/api/v1/week", week_route)
page.goto(origin + "/", wait_until="networkidle")
page.locator('input[name="device_label"]').fill("Week conflict 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="week"]').click()
page.locator("#plan-today-available").fill("60")
page.locator("#save-today-plan").click()
page.wait_for_function("() => document.querySelector('#mobile-week-summary').textContent.includes('Conflict')")
page.locator('[data-mobile-task="queues"]').click()
page.locator('[data-mobile-queue="week"]').click()
choices = page.locator("[data-week-conflict-choice]")
expect(choices).to_have_count(2)
for index in range(2):
bounds = choices.nth(index).locator("xpath=..").bounding_box()
assert bounds and bounds["height"] >= 44
page.locator('[data-week-conflict-choice="phone"]').check()
expect(page.locator("#save-merged-week")).to_be_enabled()
page.locator("#save-merged-week").click()
expect(page.locator("#plan-today-sheet")).to_be_hidden()
assert len(puts) == 2
assert [day["capacity_minutes"] for day in puts[-1]["days"]] == [60, 30]
assert not page_errors, f"Week conflict recovery raised: {page_errors}"
assert page.evaluate("document.documentElement.scrollWidth <= window.innerWidth")
browser.close()
finally:
fake.shutdown()
fake.server_close()
thread.join(timeout=5)
+1 -1
View File
@@ -303,4 +303,4 @@ async def test_unread_update_offers_reply_mark_read_and_next_independent_of_toda
assert '.update-reply-actions { display:grid; grid-template-columns:repeat(2,minmax(0,1fr));' in html
assert '.update-reply-actions button { min-height:44px;' in html
worker = (Path(__file__).parents[1] / "frontend" / "service-worker.js").read_text()
assert "stackchain-dashboard-shell-v126" in worker
assert "stackchain-dashboard-shell-v127" in worker
+1 -1
View File
@@ -435,5 +435,5 @@ async def test_dashboard_syncs_every_later_change_and_exposes_account_status():
def test_later_sync_ships_atomically_in_the_offline_shell():
source = (Path(__file__).parents[1] / "frontend" / "service-worker.js").read_text()
assert "stackchain-dashboard-shell-v126" in source
assert "stackchain-dashboard-shell-v127" in source
assert "BASE + 'static/later-sync.js'" in source
+1 -1
View File
@@ -256,4 +256,4 @@ def test_markdown_work_bodies_are_mobile_safe_block_containers():
assert ".markdown-content { min-width:0; max-width:100%; overflow-wrap:anywhere;" in css
assert ".markdown-content pre { max-width:100%; overflow-x:auto;" in css
assert ".markdown-content a { min-height:44px;" in css
assert "stackchain-dashboard-shell-v126" in worker
assert "stackchain-dashboard-shell-v127" in worker
+1 -1
View File
@@ -45,7 +45,7 @@ def test_offline_shell_contains_every_local_dashboard_runtime_asset():
shell_assets = set(re.findall(r"BASE \+ '([^']+)'", worker.split("async function sessionCsrf", 1)[0]))
assert local_assets <= shell_assets, f"Offline shell is missing: {sorted(local_assets - shell_assets)}"
assert "stackchain-dashboard-shell-v126" in worker
assert "stackchain-dashboard-shell-v127" in worker
def test_all_conversation_composers_offer_accessible_mobile_mentions():
+1 -1
View File
@@ -383,7 +383,7 @@ def test_mobile_dashboard_mounts_phone_safe_device_setup_flow():
assert "controller.recoverPermission('deadline')" in dashboard
assert "pushControllerReady.then(ensureDeviceSetup)" in dashboard
assert "BASE + 'static/mobile-device-setup.js'" in worker
assert "stackchain-dashboard-shell-v126" in worker
assert "stackchain-dashboard-shell-v127" in worker
assert ".device-setup-panel" in css
assert ".device-readiness-card" in css
assert "overflow-x:hidden" in css
+1 -1
View File
@@ -243,5 +243,5 @@ async def test_mobile_home_progressively_discloses_secondary_panels_as_insights(
def test_mobile_insights_rolls_into_the_offline_shell():
worker = (CONTROLLER.parent / "service-worker.js").read_text()
assert "stackchain-dashboard-shell-v126" in worker
assert "stackchain-dashboard-shell-v127" in worker
assert "BASE + 'static/mobile-insights.js'" in worker
+1 -1
View File
@@ -358,7 +358,7 @@ async def test_dashboard_wires_thumb_safe_start_day_briefing_into_offline_mobile
assert ".mobile-start-day-finish { min-height:44px;" in html
assert "max-width:100%; overflow-wrap:anywhere;" in html
assert "BASE + 'static/mobile-start-day.js'" in service_worker
assert "stackchain-dashboard-shell-v126" in service_worker
assert "stackchain-dashboard-shell-v127" in service_worker
@pytest.mark.anyio
+1 -1
View File
@@ -410,7 +410,7 @@ async def test_plan_today_wires_cancel_back_and_success_through_overlay_history(
def test_plan_today_controller_is_available_in_the_offline_shell():
source = SERVICE_WORKER.read_text()
assert "stackchain-dashboard-shell-v126" in source
assert "stackchain-dashboard-shell-v127" in source
assert "BASE + 'static/plan-today.js'" in source
assert "BASE + 'static/plan-today-readiness.js'" in source
assert "BASE + 'static/plan-today-preview.js'" in source
+21 -14
View File
@@ -180,13 +180,20 @@ async function dispatchPush(payload) {{
def test_private_today_action_mailbox_rolls_the_offline_shell():
source = WORKER.read_text()
assert "stackchain-dashboard-shell-v126" in source
assert "stackchain-dashboard-shell-v127" in source
def test_per_day_week_conflict_ui_rolls_the_offline_shell():
source = WORKER.read_text()
assert "stackchain-dashboard-shell-v127" in source
assert "BASE + 'static/week-plan.js'" in source
def test_resumable_today_session_ships_in_a_new_offline_shell():
source = WORKER.read_text()
assert "stackchain-dashboard-shell-v126" in source
assert "stackchain-dashboard-shell-v127" in source
assert "BASE + 'static/my-work.js'" in source
assert "BASE + 'static/dashboard.js'" in source
assert "BASE + 'static/dashboard.css'" in source
@@ -195,7 +202,7 @@ def test_resumable_today_session_ships_in_a_new_offline_shell():
def test_mobile_conversation_photo_bundles_roll_the_offline_shell():
source = WORKER.read_text()
assert "stackchain-dashboard-shell-v126" in source
assert "stackchain-dashboard-shell-v127" in source
assert "BASE + 'static/dashboard.js'" in source
assert "BASE + 'static/authored-outbox.js'" in source
assert "BASE + 'static/background-issue-sync.js'" in source
@@ -204,7 +211,7 @@ def test_mobile_conversation_photo_bundles_roll_the_offline_shell():
def test_photo_metadata_sanitizer_rolls_the_cached_optimizer_atomically():
source = WORKER.read_text()
assert "stackchain-dashboard-shell-v126" in source
assert "stackchain-dashboard-shell-v127" in source
assert "BASE + 'static/issue-evidence-review.js'" in source
assert "BASE + 'static/issue-attachment.js'" in source
@@ -212,14 +219,14 @@ def test_photo_metadata_sanitizer_rolls_the_cached_optimizer_atomically():
def test_ownership_exit_runtime_rolls_the_offline_shell_cache():
source = WORKER.read_text()
assert "stackchain-dashboard-shell-v126" in source
assert "stackchain-dashboard-shell-v127" in source
assert "BASE + 'static/dashboard.js'" in source
def test_offline_review_next_ships_today_completion_atomically():
source = WORKER.read_text()
assert "stackchain-dashboard-shell-v126" in source
assert "stackchain-dashboard-shell-v127" in source
assert "BASE + 'static/today-completion.js'" in source
assert "BASE + 'static/dashboard.js'" in source
@@ -227,7 +234,7 @@ def test_offline_review_next_ships_today_completion_atomically():
def test_duplicate_aware_capture_ships_in_a_new_offline_shell():
source = WORKER.read_text()
assert "stackchain-dashboard-shell-v126" in source
assert "stackchain-dashboard-shell-v127" in source
assert "BASE + 'static/create-issue-sheet.js'" in source
assert "BASE + 'static/dashboard.js'" in source
@@ -235,7 +242,7 @@ def test_duplicate_aware_capture_ships_in_a_new_offline_shell():
def test_inline_checklist_step_flow_rolls_the_offline_shell_atomically():
source = WORKER.read_text()
assert "stackchain-dashboard-shell-v126" in source
assert "stackchain-dashboard-shell-v127" in source
assert "BASE + 'static/issue-sheet.js'" in source
assert "BASE + 'static/checklist-conflict.js'" in source
assert "BASE + 'static/dashboard.js'" in source
@@ -245,14 +252,14 @@ def test_inline_checklist_step_flow_rolls_the_offline_shell_atomically():
def test_exact_later_picker_ships_atomically_in_a_new_offline_shell():
source = WORKER.read_text()
assert "stackchain-dashboard-shell-v126" in source
assert "stackchain-dashboard-shell-v127" in source
assert "BASE + 'static/later-picker.js'" in source
def test_navigation_deadline_ships_in_a_new_shell_cache():
source = WORKER.read_text()
assert "stackchain-dashboard-shell-v126" in source
assert "stackchain-dashboard-shell-v127" in source
assert "BASE + 'static/dashboard.css'" in source
assert "BASE + 'static/dashboard.js'" in source
assert "BASE + 'static/install-app.js'" in source
@@ -261,21 +268,21 @@ def test_navigation_deadline_ships_in_a_new_shell_cache():
def test_today_convergence_ships_in_a_new_shell_cache():
source = WORKER.read_text()
assert "stackchain-dashboard-shell-v126" in source
assert "stackchain-dashboard-shell-v127" in source
assert "BASE + 'static/today-sync.js'" in source
def test_mobile_search_viewport_ships_in_a_new_offline_shell():
source = WORKER.read_text()
assert "stackchain-dashboard-shell-v126" in source
assert "stackchain-dashboard-shell-v127" in source
assert "BASE + 'static/mobile-search-viewport.js'" in source
def test_update_ownership_flow_ships_atomically_in_a_new_offline_shell():
source = WORKER.read_text()
assert "stackchain-dashboard-shell-v126" in source
assert "stackchain-dashboard-shell-v127" in source
assert "BASE + 'static/update-ownership.js'" in source
@@ -1245,7 +1252,7 @@ def test_one_session_bound_csrf_proof_is_reused_for_a_background_drain():
def test_queue_today_ships_atomically_in_a_new_offline_shell():
source = WORKER.read_text()
assert "stackchain-dashboard-shell-v126" in source
assert "stackchain-dashboard-shell-v127" in source
assert "BASE + 'static/queue-today.js'" in source
+1 -1
View File
@@ -221,7 +221,7 @@ async def test_today_blocker_opens_existing_preview_and_preserves_readiness_gate
def test_readiness_runtime_is_available_in_offline_shell():
service_worker = SERVICE_WORKER.read_text()
assert "const CACHE = 'stackchain-dashboard-shell-v126';" in service_worker
assert "const CACHE = 'stackchain-dashboard-shell-v127';" in service_worker
assert "BASE + 'static/today-readiness.js'" in service_worker
+1 -1
View File
@@ -343,7 +343,7 @@ listeners['stackchain:first-task-complete']();
def test_inflight_today_drain_ships_in_a_new_offline_shell():
source = (Path(__file__).parents[1] / "frontend" / "service-worker.js").read_text()
assert "stackchain-dashboard-shell-v126" in source
assert "stackchain-dashboard-shell-v127" in source
assert "BASE + 'static/today-sync.js'" in source
+84
View File
@@ -67,6 +67,84 @@ console.log(JSON.stringify({conflict:week.conflict(),state:week.state()}));
assert result["state"]["revision"] == 7
def test_week_controller_automatically_merges_changes_made_to_different_days():
result = run_controller("""
const values=new Map();
const storage={getItem:key=>values.get(key)||null,setItem:(key,value)=>values.set(key,value),removeItem:key=>values.delete(key)};
const requests=[];let puts=0;
const base={revision:7,timezone:'UTC',days:[
{plan_date:'2026-08-21',ids:['tuesday-base'],capacity_minutes:60,estimates:{'tuesday-base':30}},
{plan_date:'2026-08-22',ids:['friday-base'],capacity_minutes:90,estimates:{'friday-base':45}}
]};
const remote={revision:8,timezone:'UTC',days:[
{plan_date:'2026-08-21',ids:['tuesday-account'],capacity_minutes:60,estimates:{'tuesday-account':30}},
{plan_date:'2026-08-22',ids:['friday-base'],capacity_minutes:90,estimates:{'friday-base':45}}
]};
const fetchJson=async(_url,options={})=>{
const body=options.body?JSON.parse(options.body):null;requests.push({method:options.method||'GET',body});
if(options.method==='PUT'&&puts++===0){const error=new Error('changed');error.status=409;throw error;}
if(options.method==='PUT')return {revision:9,timezone:body.timezone,days:body.days};
return remote;
};
const week=createWeekPlan({storage,getLogin:()=> 'timmy',fetchJson,localDate:()=> '2026-08-20',timeZone:()=> 'UTC'});
week.adopt(base);
week.stageDay('2026-08-22',{ids:['friday-phone'],capacity_minutes:90,estimates:{'friday-phone':50}});
const saved=await week.flush();
console.log(JSON.stringify({saved,requests,pending:week.pending(),conflict:week.conflict()}));
""")
assert [request["method"] for request in result["requests"]] == ["PUT", "GET", "PUT"]
assert result["requests"][2]["body"]["base_revision"] == 8
assert result["saved"]["days"] == [
{"plan_date": "2026-08-21", "ids": ["tuesday-account"], "capacity_minutes": 60,
"estimates": {"tuesday-account": 30}},
{"plan_date": "2026-08-22", "ids": ["friday-phone"], "capacity_minutes": 90,
"estimates": {"friday-phone": 50}},
]
assert result["pending"] is False
assert result["conflict"] is None
def test_week_controller_resolves_only_the_same_day_conflict_and_keeps_other_account_changes():
result = run_controller("""
const values=new Map();
const storage={getItem:key=>values.get(key)||null,setItem:(key,value)=>values.set(key,value),removeItem:key=>values.delete(key)};
const requests=[];let puts=0;
const base={revision:4,timezone:'UTC',days:[
{plan_date:'2026-08-21',ids:['same-base'],capacity_minutes:60,estimates:{}},
{plan_date:'2026-08-22',ids:['other-base'],capacity_minutes:60,estimates:{}}
]};
const remote={revision:5,timezone:'UTC',days:[
{plan_date:'2026-08-21',ids:['same-account'],capacity_minutes:60,estimates:{}},
{plan_date:'2026-08-22',ids:['other-account'],capacity_minutes:60,estimates:{}}
]};
const fetchJson=async(_url,options={})=>{
const body=options.body?JSON.parse(options.body):null;requests.push({method:options.method||'GET',body});
if(options.method==='PUT'&&puts++===0){const error=new Error('changed');error.status=409;throw error;}
if(options.method==='PUT')return {revision:6,timezone:body.timezone,days:body.days};
return remote;
};
const week=createWeekPlan({storage,getLogin:()=> 'timmy',fetchJson,localDate:()=> '2026-08-20',timeZone:()=> 'UTC'});
week.adopt(base);
week.stageDay('2026-08-21',{ids:['same-phone'],capacity_minutes:90,estimates:{}});
try { await week.flush(); } catch(_error) {}
const before=week.conflict();
week.chooseDay('2026-08-21','phone');
const selected=JSON.parse(values.get('stackchain.week-sync.v1.timmy'));
const saved=await week.saveMerged();
console.log(JSON.stringify({before,selected,saved,requests,pending:week.pending(),conflict:week.conflict()}));
""")
assert [item["plan_date"] for item in result["before"]["conflicts"]] == ["2026-08-21"]
assert result["before"]["conflicts"][0]["local"]["ids"] == ["same-phone"]
assert result["before"]["conflicts"][0]["remote"]["ids"] == ["same-account"]
assert result["selected"]["resolutions"] == {"2026-08-21": "phone"}
assert result["requests"][2]["body"]["base_revision"] == 5
assert [day["ids"] for day in result["saved"]["days"]] == [["same-phone"], ["other-account"]]
assert result["pending"] is False
assert result["conflict"] is None
def test_week_controller_restores_an_account_bound_week_before_network_delivery():
result = run_controller("""
const values=new Map();
@@ -294,10 +372,16 @@ def test_mobile_week_ahead_exposes_durable_save_and_touch_safe_conflict_choices(
dashboard = (FRONTEND / "dashboard.js").read_text()
assert 'id="week-conflict-review"' in index
assert 'id="week-conflict-days"' in index
assert 'id="save-merged-week"' in index
assert 'id="keep-phone-week"' in index
assert 'id="use-server-week"' in index
assert "storage:localStorage" in dashboard
assert "controller.stageDay" in CONTROLLER.read_text()
assert "weekPlan.flush" in dashboard
assert "week-conflict-mode" in dashboard
assert "controller.chooseDay" in CONTROLLER.read_text()
assert "weekPlan.saveMerged" in dashboard
assert 'data-week-conflict-choice' in CONTROLLER.read_text()
assert ".week-conflict-actions button { min-height:44px;" in css
assert ".week-conflict-choice { min-height:44px;" in css