feat: claim work from unread updates (#321)
CI / lint (pull_request) Successful in 32s
CI / build-frontend (pull_request) Successful in 4s

This commit is contained in:
timmy committed 2026-08-08 17:19:13 +00:00
1 parent d6c7a495ed
commit 0ea264a942
11 files changed
+244 -7

No files matched your search

+5 -1
View File
@@ -133,7 +133,10 @@ async def test_notification_detail_loads_subject_and_latest_comment_for_inbox_re
},
})
if request.url.path.endswith("/issues/7"):
return httpx.Response(200, json={"body": "Deploy fails after **three** retries."})
return httpx.Response(200, json={
"number": 7, "state": "open", "assignees": [],
"body": "Deploy fails after **three** retries.",
})
if request.url.path.endswith("/issues/comments/9"):
return httpx.Response(200, json={
"id": 9,
@@ -178,6 +181,7 @@ async def test_notification_detail_loads_subject_and_latest_comment_for_inbox_re
"created_at": "2026-08-06T12:30:00Z",
"url": "https://forge.example/stackchain/api/issues/7#issuecomment-9",
},
"issue": {"number": 7, "assignees": [], "claimable": True},
"conversation": {
"comments": [{
"id": 9,
+1 -1
View File
@@ -915,7 +915,7 @@ async def test_claim_available_issue_endpoint_reports_assignment_race_as_conflic
assert response.status_code == 409
assert response.headers["cache-control"] == "no-store"
assert response.json() == {
"error": "This issue was already claimed or is no longer open. Refresh Find Work."
"error": "This issue was already claimed or is no longer open."
}
+88
View File
@@ -18,6 +18,94 @@ PULL_SHEET = Path(__file__).parents[1] / "frontend" / "pull-sheet.js"
CONVERSATION = Path(__file__).parents[1] / "frontend" / "conversation.js"
PICK_WORK = Path(__file__).parents[1] / "frontend" / "pick-work.js"
WORK_ROUTE = Path(__file__).parents[1] / "frontend" / "work-route.js"
UPDATE_OWNERSHIP = Path(__file__).parents[1] / "frontend" / "update-ownership.js"
def test_unassigned_issue_update_claims_once_and_becomes_today_ready():
script = f"""
const createUpdateOwnership = require({json.dumps(str(UPDATE_OWNERSHIP))});
let claims = 0;
let finishClaim;
const states = [];
const controller = createUpdateOwnership({{
claim: () => {{ claims += 1; return new Promise(resolve => {{ finishClaim = resolve; }}); }},
addToday: () => 'added',
onClaimed: item => states.push({{status:'reconciled', item}}),
onState: state => states.push(state),
}});
controller.open({{
repository:'stackchain/api', title:'Retry deploy',
issue:{{number:7, assignees:[], claimable:true}},
}}, {{notification_id:42, updated_at:'2026-08-08T12:00:00Z'}});
const first = controller.act();
const second = controller.act();
if (first !== second || claims !== 1) throw new Error('claim was not single-flight');
finishClaim({{number:7, title:'Retry deploy', assignees:['timmy'], state:'open'}});
(async () => {{
await first;
const added = await controller.act();
process.stdout.write(JSON.stringify({{claims, added, states}}));
}})().catch(error => {{ console.error(error); process.exit(1); }});
"""
result = subprocess.run(
["node", "-e", script], check=True, capture_output=True, text=True
)
output = json.loads(result.stdout)
assert output["claims"] == 1
assert output["added"] == "added"
assert output["states"][0] == {"action": "claim", "busy": False, "message": ""}
assert {"action": "claim", "busy": True, "message": "Assigning…"} in output["states"]
reconciled = next(state for state in output["states"] if state.get("status") == "reconciled")
assert reconciled["item"]["notification_id"] == 42
assert reconciled["item"]["repository"] == "stackchain/api"
assert reconciled["item"]["kind"] == "issue"
assert output["states"][-1] == {
"action": "today", "busy": False, "message": "Added to Today."
}
def test_update_ownership_conflict_removes_stale_action_without_reconciling():
script = f"""
const createUpdateOwnership = require({json.dumps(str(UPDATE_OWNERSHIP))});
const states = [];
let reconciled = 0;
const conflict = new Error('server wording'); conflict.status = 409;
const controller = createUpdateOwnership({{
claim: () => Promise.reject(conflict), addToday: () => 'added',
onClaimed: () => {{ reconciled += 1; }}, onState: state => states.push(state),
}});
controller.open({{repository:'stackchain/api', issue:{{number:7, claimable:true}}}}, {{notification_id:42}});
(async () => {{
const result = await controller.act();
process.stdout.write(JSON.stringify({{result, reconciled, states}}));
}})().catch(error => {{ console.error(error); process.exit(1); }});
"""
result = subprocess.run(
["node", "-e", script], check=True, capture_output=True, text=True
)
output = json.loads(result.stdout)
assert output["result"] == "conflict"
assert output["reconciled"] == 0
assert output["states"][-1] == {
"action": "hidden",
"busy": False,
"message": "Someone else claimed or closed this issue. The update is still unread.",
}
@pytest.mark.anyio
async def test_mobile_update_sheet_wires_phone_safe_ownership_to_my_work_and_today():
html = await dashboard()
assert '<script src="static/update-ownership.js"></script>' in html
assert 'id="update-ownership-action"' in html
assert 'hidden aria-describedby="update-sheet-status"' in html
assert 'const updateOwnership = createUpdateOwnership({' in html
assert 'updateOwnership.open(detail, selectedUpdate)' in html
assert "qs('#update-ownership-action').addEventListener('click'" in html
assert "lastContextSnapshot.issues" in html
assert "todayWork.add(item)" in html
assert '.update-sheet-actions button, .update-sheet-actions a { min-height:44px;' in html
def test_work_routes_round_trip_all_sheet_kinds_and_reject_unsafe_fragments():
+11 -1
View File
@@ -36,7 +36,12 @@ async def test_notification_detail_opens_the_newest_conversation_page_in_chronol
comments = [comment(i) for i in (range(1, 21) if page == 1 else range(41, 48))]
return httpx.Response(200, json=comments, headers={"X-Total-Count": "47"})
if request.url.path.endswith("/repos/stackchain/api/issues/7"):
return httpx.Response(200, json={"body": "Deploy fails after retries."})
return httpx.Response(200, json={
"number": 7,
"state": "open",
"assignees": [],
"body": "Deploy fails after retries.",
})
if request.url.path.endswith("/repos/stackchain/api/issues/comments/47"):
return httpx.Response(200, json=comment(47))
raise AssertionError(f"unexpected request: {request.url}")
@@ -56,6 +61,11 @@ async def test_notification_detail_opens_the_newest_conversation_page_in_chronol
"older_page": 2,
"total": 47,
}
assert result["issue"] == {
"number": 7,
"assignees": [],
"claimable": True,
}
@pytest.mark.anyio
+10 -2
View File
@@ -97,7 +97,7 @@ async function dispatchNotificationClick(route) {{
def test_share_target_sign_in_fix_ships_in_a_new_shell_cache():
source = WORKER.read_text()
assert "stackchain-dashboard-shell-v34" in source
assert "stackchain-dashboard-shell-v35" in source
assert "BASE + 'static/dashboard.css'" in source
assert "BASE + 'static/dashboard.js'" in source
assert "BASE + 'static/install-app.js'" in source
@@ -106,10 +106,17 @@ def test_share_target_sign_in_fix_ships_in_a_new_shell_cache():
def test_mobile_search_viewport_ships_in_a_new_offline_shell():
source = WORKER.read_text()
assert "stackchain-dashboard-shell-v34" in source
assert "stackchain-dashboard-shell-v35" 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-v35" in source
assert "BASE + 'static/update-ownership.js'" in source
def test_background_sync_event_flushes_closed_app_issue_outbox_only_for_its_tag():
result = run_worker_scenario(
"""
@@ -279,6 +286,7 @@ def test_install_precaches_complete_subpath_scoped_app_shell():
"/dashboard/static/offline-work.js",
"/dashboard/static/my-work.js",
"/dashboard/static/today-work.js",
"/dashboard/static/update-ownership.js",
"/dashboard/static/later-work.js",
"/dashboard/static/detail-defer.js",
"/dashboard/static/pick-work.js",