Compare commits
103
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38206b90e4 | ||
|
|
de3c68fc0e | ||
|
|
7158e00b97 | ||
|
|
ad15f15e3c | ||
|
|
aba217f89b | ||
|
|
1e9c3444fa | ||
|
|
2e9d108c6f | ||
|
|
7dc32138e4 | ||
|
|
26288d364c | ||
|
|
97a36ea22f | ||
|
|
dc9e64e98e | ||
|
|
065cc46553 | ||
|
|
664317212d | ||
|
|
62de2e6011 | ||
|
|
edd653eaaf | ||
|
|
15d7bc9234 | ||
|
|
bea0e0e429 | ||
|
|
b7d496600e | ||
|
|
8b2fd305ca | ||
|
|
1e8d9a27be | ||
|
|
1c66905b4a | ||
|
|
4319c161cb | ||
|
|
5ec4dd7f6e | ||
|
|
718f0d1209 | ||
|
|
e9d257e203 | ||
|
|
af16f987f1 | ||
|
|
f4d6f9176c | ||
|
|
ab329aa126 | ||
|
|
9d84d5c5c4 | ||
|
|
dbb8ff4d4e | ||
|
|
364fc60116 | ||
|
|
e02115bd71 | ||
|
|
7ec78ac182 | ||
|
|
94728d81ff | ||
|
|
7960f14b5b | ||
|
|
f9b29d8d14 | ||
|
|
e7e8c24d05 | ||
|
|
8b56618e62 | ||
|
|
dcad1da1da | ||
|
|
8bb8fb0cd9 | ||
|
|
a23276f0b8 | ||
|
|
54cb078d1a | ||
|
|
1822004f3d | ||
|
|
c15f7768e4 | ||
|
|
024087d051 | ||
|
|
297ae7550a | ||
|
|
e44f49708a | ||
|
|
3e7d758782 | ||
|
|
185f3f9706 | ||
|
|
aed278629b | ||
|
|
d273de3506 | ||
|
|
fa876e1e38 | ||
|
|
306d6e3056 | ||
|
|
978351dff2 | ||
|
|
553a01217a | ||
|
|
cc74b7b8db | ||
|
|
2acd9431e0 | ||
|
|
4855bc7c8d | ||
|
|
6e19639b19 | ||
|
|
7662cca9e6 | ||
|
|
0682bbcc2c | ||
|
|
1c02dcb217 | ||
|
|
7bb22e3525 | ||
|
|
869543e992 | ||
|
|
c8ffde7d96 | ||
|
|
ed662c3a3a | ||
|
|
8a881419db | ||
|
|
b4f3c6d419 | ||
|
|
fc7a83fbd7 | ||
|
|
22fe5dd1d8 | ||
|
|
9d97b2e84a | ||
|
|
502fcb30f5 | ||
|
|
b541c707fc | ||
|
|
b40a44fc45 | ||
|
|
d1adbe72d6 | ||
|
|
d6e6cf2e67 | ||
|
|
53706f18ab | ||
|
|
f0be3a44a6 | ||
|
|
b753cdd922 | ||
|
|
400534f446 | ||
|
|
a43ecac94b | ||
|
|
d6993c40fb | ||
|
|
966116e5ee | ||
|
|
d4ddac07ab | ||
|
|
b6684bb7ba | ||
|
|
07f5770aa8 | ||
|
|
f3876d359d | ||
|
|
e5b9833096 | ||
|
|
ae98564d9b | ||
|
|
b85fe4a0a3 | ||
|
|
a9becd079f | ||
|
|
99750d44f5 | ||
|
|
e4d0cc9115 | ||
|
|
77f22f3cd5 | ||
|
|
fde3ba21ca | ||
|
|
8cb92c6858 | ||
|
|
3e7a6c81fc | ||
|
|
084c0b5732 | ||
|
|
c73fbf8379 | ||
|
|
b47ed5d86e | ||
|
|
f0f415c65d | ||
|
|
2102b0e5da | ||
|
|
050390d6f6 |
No files matched your search
+13
-10
@@ -7,12 +7,15 @@ on:
|
||||
branches: [main]
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-python@v5
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
|
||||
with: { python-version: "3.11" }
|
||||
- run: pip install -r requirements.txt
|
||||
- run: pip install -r requirements-audit.txt
|
||||
@@ -23,7 +26,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
needs: lint
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
- name: Build deterministic release bundle
|
||||
run: |
|
||||
SOURCE_DATE_EPOCH="$(git show -s --format=%ct "$GITHUB_SHA")"
|
||||
@@ -33,7 +36,7 @@ jobs:
|
||||
--commit "$GITHUB_SHA" \
|
||||
--source-date-epoch "$SOURCE_DATE_EPOCH"
|
||||
- name: Upload tested release bundle
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
|
||||
with:
|
||||
name: release-bundle
|
||||
path: dist/
|
||||
@@ -44,11 +47,11 @@ jobs:
|
||||
env:
|
||||
STACKCHAIN_RUN_RELEASE_E2E: "1"
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-python@v5
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
|
||||
with: { python-version: "3.11" }
|
||||
- name: Download assembled release bundle
|
||||
uses: actions/download-artifact@v3
|
||||
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
|
||||
with:
|
||||
name: release-bundle
|
||||
path: dist
|
||||
@@ -57,7 +60,7 @@ jobs:
|
||||
pip install -r requirements-e2e.txt
|
||||
python3 -m playwright install --with-deps chromium
|
||||
- name: Exercise packaged mobile work journeys
|
||||
run: python3 -m pytest tests/e2e/test_mobile_offline_issue_release.py tests/e2e/test_mobile_search_preview_navigation.py tests/e2e/test_mobile_search_week_plan.py tests/e2e/test_mobile_find_work_release.py tests/e2e/test_mobile_home_bootstrap_release.py tests/e2e/test_mobile_sign_out_release.py tests/e2e/test_mobile_today_handoff_release.py tests/e2e/test_mobile_today_wrap_up_release.py tests/e2e/test_mobile_today_summary_release.py tests/e2e/test_mobile_tomorrow_conflict_release.py tests/e2e/test_mobile_week_ahead_release.py tests/e2e/test_mobile_today_week_reschedule_release.py tests/e2e/test_mobile_wrap_up_handoff_release.py tests/e2e/test_mobile_following_release.py tests/e2e/test_mobile_detail_watch_release.py tests/e2e/test_mobile_pull_reviewer_status_release.py tests/e2e/test_mobile_pull_reviewer_feedback_release.py -q tests/e2e/test_mobile_address_review_feedback_release.py tests/e2e/test_mobile_cancel_pull_review_request_release.py tests/e2e/test_mobile_authored_pull_queue_release.py
|
||||
run: python3 -m pytest tests/e2e -q
|
||||
|
||||
release-candidate:
|
||||
runs-on: ubuntu-latest
|
||||
@@ -66,9 +69,9 @@ jobs:
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
- name: Download tested release bundle
|
||||
uses: actions/download-artifact@v3
|
||||
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
|
||||
with:
|
||||
name: release-bundle
|
||||
path: dist
|
||||
|
||||
@@ -18,7 +18,20 @@ token that can read dashboard data, update the authenticated user's notification
|
||||
threads, create and self-assign issues, discover, claim, and release issue assignments,
|
||||
list repository labels and open milestones, set or clear due dates on assigned issues, create issue comments, close assigned issues,
|
||||
inspect/comment on assigned pull
|
||||
requests, merge assigned pull requests, and submit pull-request reviews.
|
||||
requests, merge assigned pull requests, and submit pull-request reviews. For authored
|
||||
pulls, up to eight non-overlapping one-line reviewer suggestions across bounded UTF-8
|
||||
files can be staged during the mobile feedback pass, reviewed in a path-grouped manifest,
|
||||
and committed as one atomic branch update. The batch preserves every original blob
|
||||
identity, applies same-file replacements from the bottom up, rejects overlapping or stale
|
||||
lines, and verifies the advanced pull head and every final file before reporting success.
|
||||
The server uses Gitea's multi-file contents mutation so a cross-file implementation-and-test
|
||||
fix cannot be partially committed.
|
||||
After an exact merged commit fails release checks, its mobile release receipt can load the
|
||||
failed job evidence and prepare a draft rollback pull request. The server revalidates the
|
||||
operator's participation and push access, reverses only bounded UTF-8 files whose current
|
||||
default-branch content still matches the failed merge, and creates one atomic commit on a
|
||||
stable operator-owned branch. Conflicts, renames, binary files, and oversized changes fail
|
||||
closed; retrying converges on the same draft PR, which opens in the existing review workspace.
|
||||
Assigned-issue, assigned-pull-request, and unread-update conversation composers accept an ordered bundle of up to five PNG, JPEG, or WebP photos. Repeated camera captures append to the bundle, the gallery picker accepts multiple images, and each composer automatically optimizes oversized screenshots on-device to fit the 2 MB upload boundary. Before sending, the selected conversation photo can use the same touch editor as New issue evidence to crop, privacy-redact, highlight, or add an arrow; Apply replaces only that flattened derivative while preserving its caption and bundle position, and Cancel leaves the original unchanged.
|
||||
For online delivery, every photo uploads before the comment is posted to the exact conversation target, producing one ordered Markdown comment or reply; validation or upload failures keep the typed text and removable preview available for retry. Offline photo conversations admit every image Blob to IndexedDB before confirmation, keep only bounded metadata in localStorage, and checkpoint each upload separately so reconnect resumes at the first unconfirmed photo without duplicating an upload, comment, reply, or reply-and-read transition. The mobile **New issue** capture-first stage accepts an ordered evidence bundle of up to
|
||||
five PNG, JPEG, or WebP screenshots before a repository is chosen, optimizing each image independently
|
||||
@@ -838,3 +851,20 @@ Checkpoint replacement uses writer-unique, flushed temporary files and an
|
||||
atomic rename, preventing concurrent writers from colliding or exposing partial
|
||||
JSON. Full behavior and safety gates are documented in
|
||||
[`docs/release-engine-spec.md`](docs/release-engine-spec.md).
|
||||
|
||||
## Human Gates inbox
|
||||
|
||||
Authenticated release producers use `POST /api/v1/human-gates/intake` with an
|
||||
`Idempotency-Key` and an immutable `"candidate_hash"`; durable account-bound
|
||||
SQLite storage is configured by `STACKCHAIN_HUMAN_GATE_DB`. Account isolation
|
||||
binds each queue to the upstream principal ID and login, including its offline
|
||||
browser cache. Review decisions carry `expected_revision`, a stable idempotency
|
||||
key across network retries, and return durable receipts. If producer evidence
|
||||
changes after a release or hold, the update reopens the exact hash for a new
|
||||
revision-checked decision instead of silently retaining the old outcome.
|
||||
New hashes mark older pending candidates `superseded` without removing their audit
|
||||
history. See [`docs/human-gates.md`](docs/human-gates.md) for the complete
|
||||
producer body, decision API, and **Telegram coalescing contract**. Lock-screen
|
||||
and Telegram notifications expose count and route only, using
|
||||
`#/my-work/human-gates`; they never expose project, title, candidate hash,
|
||||
artifacts, checks, provenance, reasons, or receipts.
|
||||
@@ -0,0 +1,43 @@
|
||||
# Human Gates producer and notification contract
|
||||
|
||||
Human Gates is an account-bound release-candidate inbox. The canonical mobile route is `#/my-work/human-gates`. Reads may use the last account-scoped browser cache, but Release/Hold decisions require a live authenticated identity and an online server round trip.
|
||||
|
||||
A cold open of the canonical route confirms the account and opens Human Gates from the core browser runtime while optional Today and Planning bundles continue hydrating or recovering. The full workspace adopts that controller and fixed review snapshot without a second queue request or duplicate decision handlers.
|
||||
|
||||
## Producer intake
|
||||
|
||||
Authenticated producers submit `POST /api/v1/human-gates/intake` with a unique `Idempotency-Key` header and JSON such as:
|
||||
|
||||
```json
|
||||
{
|
||||
"source": "release-bot",
|
||||
"project": "stackchain/dashboard",
|
||||
"candidate_hash": "abc123",
|
||||
"title": "Dashboard candidate",
|
||||
"priority": 7,
|
||||
"artifacts": [{"name": "manifest", "url": "https://forge.example/artifacts/manifest.json"}],
|
||||
"links": [{"label": "change", "url": "https://forge.example/pulls/1415"}],
|
||||
"checks": [{"name": "browser", "state": "success", "required": true}],
|
||||
"score": {"value": 92, "provenance": "release-evaluator/v2"},
|
||||
"provenance": {"producer": "release-bot", "run_id": "run-9"}
|
||||
}
|
||||
```
|
||||
|
||||
The immutable identity is authenticated account + `source` + `project` + `candidate_hash`. Retrying the same key and body returns the same gate. Reusing a key for different facts, or redefining an existing candidate hash, returns 409. A newer hash from the same source/project atomically marks older pending candidates `superseded`; detail history remains available for audit. Configure durable storage with `STACKCHAIN_HUMAN_GATE_DB` (default: `$STACKCHAIN_STATE_DIR/human-gates.sqlite3`).
|
||||
|
||||
Consumers list `GET /api/v1/human-gates`, inspect `GET /api/v1/human-gates/{id}`, and submit `POST /api/v1/human-gates/{id}/decision` with a new `Idempotency-Key`, `expected_revision`, and either `release` or `hold`. Hold requires a reason. Release requires all three checklist confirmations; if any required check is not successful it also requires an explicit override reason. Durable receipts are available at `GET /api/v1/human-gate-receipts/{receipt_id}`. All endpoints are authenticated, account-bound, and `Cache-Control: no-store`.
|
||||
|
||||
## Privacy-safe notification contract
|
||||
|
||||
Web Push is opt-in per authenticated device under **My Work → Settings → Notify me when release decisions are waiting**. The preference is stored with that device's push subscription; revoked sessions are removed before delivery. The poller honors the device's routine-alert quiet hours, coalesces unchanged pending counts, and routes a notification tap to `#/my-work/human-gates`.
|
||||
|
||||
Web Push, Telegram, and other lock-screen adapters MUST expose **count and route only**:
|
||||
|
||||
```json
|
||||
{
|
||||
"pending_count": 3,
|
||||
"route": "#/my-work/human-gates"
|
||||
}
|
||||
```
|
||||
|
||||
The notification text may say “3 Human Gates pending” and provide the route. It MUST NOT include project names, candidate hash values, titles, artifact/link URLs, checks, scores, provenance, decision history, superseded candidate facts, reasons, or receipts. Multiple intake/supersession events before delivery replace the pending notification with the latest count rather than emitting one message per candidate. A transition to zero clears the outstanding notification; it does not send candidate detail. Producers and adapters must fetch current state after authenticated route open rather than treating notification delivery as an action authorization.
|
||||
@@ -1,4 +1,8 @@
|
||||
function createCommentActions({ fetchJson, getLogin, confirmDelete = () => false }) {
|
||||
const reactionLabels = {
|
||||
'+1': 'Thumbs up', '-1': 'Thumbs down', laugh: 'Laugh', hooray: 'Hooray',
|
||||
confused: 'Confused', heart: 'Heart', rocket: 'Rocket', eyes: 'Eyes',
|
||||
};
|
||||
const encodedRepository = repository => String(repository || '').split('/')
|
||||
.map(encodeURIComponent).join('/');
|
||||
|
||||
@@ -14,6 +18,12 @@ function createCommentActions({ fetchJson, getLogin, confirmDelete = () => false
|
||||
'/comments/' + encodeURIComponent(commentId);
|
||||
}
|
||||
|
||||
function reactionPath(context, commentId, content = '') {
|
||||
return pathFor(context, commentId) + '/reactions' +
|
||||
(content ? '/' + encodeURIComponent(content) : '');
|
||||
}
|
||||
|
||||
const pendingReactions = new Set();
|
||||
const controller = {
|
||||
isOwned(comment) {
|
||||
const login = String(getLogin() || '').trim();
|
||||
@@ -41,15 +51,98 @@ function createCommentActions({ fetchJson, getLogin, confirmDelete = () => false
|
||||
pager.remove(commentId);
|
||||
return pager.snapshot();
|
||||
},
|
||||
async loadReactions(context, commentId) {
|
||||
return fetchJson(reactionPath(context, commentId), {
|
||||
headers: { Accept: 'application/json' },
|
||||
});
|
||||
},
|
||||
async setReaction(context, commentId, content, active) {
|
||||
return fetchJson(reactionPath(context, commentId, content), {
|
||||
method: 'PUT',
|
||||
headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ active: Boolean(active) }),
|
||||
});
|
||||
},
|
||||
reactionHtml(state) {
|
||||
const current = new Map((state?.reactions || []).map(item => [item.content, item]));
|
||||
return Object.entries(reactionLabels).map(([content, label]) => {
|
||||
const item = current.get(content) || {};
|
||||
const count = Number.isInteger(item.count) && item.count > 0 ? item.count : 0;
|
||||
const selected = item.selected === true;
|
||||
return '<button type="button" data-comment-reaction="' + content + '" ' +
|
||||
'aria-pressed="' + selected + '" aria-label="' + label + ' ' + count + '">' +
|
||||
label + ' ' + count + '</button>';
|
||||
}).join('') + '<button type="button" data-comment-reactions-close>Cancel</button>';
|
||||
},
|
||||
actionHtml(comment) {
|
||||
return controller.isOwned(comment) ?
|
||||
const owned = controller.isOwned(comment) ?
|
||||
'<div class="comment-owned-actions" aria-label="Your comment actions">' +
|
||||
'<button type="button" data-comment-action="edit">Edit</button>' +
|
||||
'<button type="button" data-comment-action="delete">Delete</button></div>' : '';
|
||||
return owned + '<div class="comment-reactions" aria-label="Comment reactions">' +
|
||||
'<button type="button" data-comment-reactions-open aria-expanded="false" ' +
|
||||
'aria-label="React to this comment">React</button>' +
|
||||
'<div class="comment-reaction-menu" data-comment-reaction-menu hidden></div></div>';
|
||||
},
|
||||
wire({ root, getSurface, isOffline, escapeHtml }) {
|
||||
root.addEventListener('click', async event => {
|
||||
const button = event.target.closest('[data-comment-action]');
|
||||
const actionButton = event.target.closest('[data-comment-action]');
|
||||
const reactionClose = actionButton ? null : event.target.closest('[data-comment-reactions-close]');
|
||||
const reactionButton = actionButton ? null : event.target.closest('[data-comment-reaction]');
|
||||
const reactionTrigger = actionButton ? null : event.target.closest('[data-comment-reactions-open]');
|
||||
if (reactionClose) {
|
||||
const card = reactionClose.closest('.issue-comment');
|
||||
const menu = card?.querySelector('[data-comment-reaction-menu]');
|
||||
const trigger = card?.querySelector('[data-comment-reactions-open]');
|
||||
if (menu && trigger) {
|
||||
menu.hidden = true;
|
||||
trigger.setAttribute('aria-expanded', 'false');
|
||||
trigger.focus();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (reactionButton || reactionTrigger) {
|
||||
const control = reactionButton || reactionTrigger;
|
||||
const card = control.closest('.issue-comment');
|
||||
const commentId = Number(card?.dataset.commentId);
|
||||
const surface = getSurface();
|
||||
const menu = card?.querySelector('[data-comment-reaction-menu]');
|
||||
const trigger = card?.querySelector('[data-comment-reactions-open]');
|
||||
if (!commentId || !menu || !trigger) return;
|
||||
if (isOffline()) {
|
||||
surface.status.textContent = 'Reconnect to react.';
|
||||
return;
|
||||
}
|
||||
if (pendingReactions.has(commentId)) return;
|
||||
pendingReactions.add(commentId);
|
||||
control.disabled = true;
|
||||
try {
|
||||
if (reactionButton) {
|
||||
const content = reactionButton.dataset.commentReaction;
|
||||
const active = reactionButton.getAttribute('aria-pressed') !== 'true';
|
||||
const state = await controller.setReaction(surface.context, commentId, content, active);
|
||||
menu.innerHTML = controller.reactionHtml(state);
|
||||
menu.hidden = true;
|
||||
trigger.setAttribute('aria-expanded', 'false');
|
||||
trigger.focus();
|
||||
surface.status.textContent = 'Reaction updated.';
|
||||
} else {
|
||||
surface.status.textContent = 'Loading reactions…';
|
||||
const state = await controller.loadReactions(surface.context, commentId);
|
||||
menu.innerHTML = controller.reactionHtml(state);
|
||||
menu.hidden = false;
|
||||
trigger.setAttribute('aria-expanded', 'true');
|
||||
surface.status.textContent = '';
|
||||
}
|
||||
} catch (error) {
|
||||
surface.status.textContent = error.message || 'Reactions are unavailable. Please retry.';
|
||||
} finally {
|
||||
pendingReactions.delete(commentId);
|
||||
control.disabled = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
const button = actionButton;
|
||||
if (!button) return;
|
||||
const card = button.closest('.issue-comment');
|
||||
const commentId = Number(card?.dataset.commentId);
|
||||
|
||||
@@ -44,9 +44,14 @@ function createContextPoller({
|
||||
const freshness = snapshot && snapshot.freshness;
|
||||
const sections = freshness && freshness.sections;
|
||||
const sectionValues = sections && Object.values(sections);
|
||||
const degradedRetrySeconds = (sectionValues || [])
|
||||
.filter(section => section.degraded)
|
||||
.map(section => Number(section.retry_in_seconds ?? freshness.retry_in_seconds))
|
||||
.filter(seconds => Number.isFinite(seconds) && seconds > 0);
|
||||
const failedSectionDelay = degradedRetrySeconds.length ?
|
||||
Math.min(...degradedRetrySeconds) * 1000 : null;
|
||||
if (sectionValues && sectionValues.length && sectionValues.every(section => section.degraded)) {
|
||||
const retrySeconds = Number(freshness.retry_in_seconds);
|
||||
if (Number.isFinite(retrySeconds) && retrySeconds > 0) return retrySeconds * 1000;
|
||||
return failedSectionDelay || intervalMs;
|
||||
}
|
||||
const freshForSeconds = Number(freshness && freshness.fresh_for_seconds);
|
||||
const healthyDeadlines = (sectionValues || [])
|
||||
@@ -55,10 +60,10 @@ function createContextPoller({
|
||||
.filter(seconds => Number.isFinite(seconds));
|
||||
if (Number.isFinite(freshForSeconds) && freshForSeconds > 0 && healthyDeadlines.length) {
|
||||
const earliestDeadline = Math.min(...healthyDeadlines);
|
||||
if (earliestDeadline <= 0 && sectionValues.some(section => !section.degraded && section.revalidating)) {
|
||||
return intervalMs;
|
||||
}
|
||||
return Math.max(0, earliestDeadline) * 1000;
|
||||
const healthyDelay = earliestDeadline <= 0 &&
|
||||
sectionValues.some(section => !section.degraded && section.revalidating) ?
|
||||
intervalMs : Math.max(0, earliestDeadline) * 1000;
|
||||
return failedSectionDelay === null ? healthyDelay : Math.min(healthyDelay, failedSectionDelay);
|
||||
}
|
||||
return intervalMs;
|
||||
}
|
||||
@@ -166,9 +171,47 @@ function createContextPoller({
|
||||
return refresh({ force: true });
|
||||
}
|
||||
|
||||
function adopt(snapshot) {
|
||||
if (
|
||||
stopped || activeRequest || retainedSnapshot || !snapshot ||
|
||||
typeof snapshot !== 'object' ||
|
||||
!Object.prototype.hasOwnProperty.call(snapshot, 'context')
|
||||
) return false;
|
||||
retainedSnapshot = { ...snapshot };
|
||||
revisions = { ...(snapshot.revisions || {}) };
|
||||
failureStreak = 0;
|
||||
lastSuccessAt = Date.now();
|
||||
nextDelayMs = snapshotDelay(snapshot);
|
||||
const changedSections = ['context', 'events', 'notifications'].filter(
|
||||
section => Object.prototype.hasOwnProperty.call(snapshot, section)
|
||||
);
|
||||
onSnapshot(retainedSnapshot, changedSections);
|
||||
schedule(nextDelayMs);
|
||||
return true;
|
||||
}
|
||||
|
||||
async function adoptPending(snapshotPromise) {
|
||||
if (!snapshotPromise || typeof snapshotPromise.then !== 'function') return false;
|
||||
let deadline = null;
|
||||
const timeout = new Promise(resolve => {
|
||||
deadline = setDeadlineTimer(() => resolve(null), timeoutMs);
|
||||
});
|
||||
try {
|
||||
const snapshot = await Promise.race([
|
||||
Promise.resolve(snapshotPromise).catch(() => null),
|
||||
timeout,
|
||||
]);
|
||||
return adopt(snapshot);
|
||||
} finally {
|
||||
clearDeadlineTimer(deadline);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
start: refresh,
|
||||
refresh,
|
||||
adopt,
|
||||
adoptPending,
|
||||
setVisible,
|
||||
getState() {
|
||||
return {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
})(typeof globalThis !== 'undefined' ? globalThis : this, function () {
|
||||
'use strict';
|
||||
|
||||
return function createConversationPhotoDrafts({ store, lanes }) {
|
||||
return function createConversationPhotoDrafts({ store, lanes, onChange = () => {} }) {
|
||||
const states = {};
|
||||
Object.entries(lanes || {}).forEach(([kind, lane]) => {
|
||||
states[kind] = { ...lane, target:null, generation:0, restoring:false, pending:Promise.resolve() };
|
||||
@@ -24,7 +24,11 @@
|
||||
const attachments = await current.controller.serialize();
|
||||
const save = current.pending.then(() => store.save(target, attachments));
|
||||
current.pending = save.catch(() => null);
|
||||
try { return await save; }
|
||||
try {
|
||||
const saved = await save;
|
||||
onChange();
|
||||
return saved;
|
||||
}
|
||||
catch (error) { current.onError?.(error); throw error; }
|
||||
}
|
||||
|
||||
@@ -67,6 +71,7 @@
|
||||
const target = { ...current.target };
|
||||
await current.pending;
|
||||
await store.remove(target);
|
||||
onChange();
|
||||
current.restoring = true;
|
||||
try { current.controller.clear(); }
|
||||
finally {
|
||||
|
||||
@@ -33,10 +33,11 @@
|
||||
}
|
||||
return async (operation, key, value) => {
|
||||
const db = await database();
|
||||
const transaction = db.transaction(storeName, operation === 'get' ? 'readonly' : 'readwrite');
|
||||
const transaction = db.transaction(storeName, ['get', 'list'].includes(operation) ? 'readonly' : 'readwrite');
|
||||
const records = transaction.objectStore(storeName);
|
||||
if (operation === 'put') return requestResult(records.put(value));
|
||||
if (operation === 'delete') return requestResult(records.delete(key));
|
||||
if (operation === 'list') return requestResult(records.getAll());
|
||||
return requestResult(records.get(key));
|
||||
};
|
||||
}
|
||||
@@ -97,7 +98,10 @@
|
||||
const { id, ownerLogin, scope:recordScope, target:normalized } = identity(target);
|
||||
const list = (Array.isArray(values) ? values : [values]).filter(Boolean).slice(0, 5).map(attachment);
|
||||
if (!list.length) { await transact('delete', id); return null; }
|
||||
await transact('put', id, { id, version:1, ownerLogin, scope:recordScope, ...normalized, attachments:list });
|
||||
await transact('put', id, {
|
||||
id, version:1, ownerLogin, scope:recordScope, ...normalized,
|
||||
updatedAt:Date.now(), attachments:list,
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -122,6 +126,38 @@
|
||||
return true;
|
||||
}
|
||||
|
||||
return { save, load, remove };
|
||||
async function list() {
|
||||
if (!transact || draftScope !== 'conversation') return [];
|
||||
const ownerLogin = String(getOwnerLogin() || '').trim();
|
||||
if (!ownerLogin) return [];
|
||||
const records = await transact('list');
|
||||
return (Array.isArray(records) ? records : []).flatMap(record => {
|
||||
if (record?.version !== 1 || record.ownerLogin !== ownerLogin ||
|
||||
(record.scope && record.scope !== 'conversation') ||
|
||||
!Array.isArray(record.attachments) || !record.attachments.length) return [];
|
||||
const updatedAt = Number(record.updatedAt || 0);
|
||||
if (record.kind === 'update') {
|
||||
const notificationId = Number(record.notificationId || 0);
|
||||
if (!Number.isInteger(notificationId) || notificationId < 1) return [];
|
||||
return [{
|
||||
id:record.id, kind:'photo-reply', label:'Update photos', title:'Update #' + notificationId,
|
||||
photo_count:record.attachments.length, updated_at:updatedAt,
|
||||
route:{ kind:'update', notification_id:notificationId }, photo_store:'conversation',
|
||||
}];
|
||||
}
|
||||
const repository = String(record.repository || '');
|
||||
const number = Number(record.number || 0);
|
||||
if (!['issue', 'pull'].includes(record.kind) || !repository ||
|
||||
!Number.isInteger(number) || number < 1) return [];
|
||||
const label = record.kind === 'issue' ? 'Issue photos' : 'PR photos';
|
||||
return [{
|
||||
id:record.id, kind:'photo-reply', label, repository, number,
|
||||
title:repository + '#' + number, photo_count:record.attachments.length, updated_at:updatedAt,
|
||||
route:{ kind:record.kind, repository, number }, photo_store:'conversation',
|
||||
}];
|
||||
}).sort((left, right) => Number(right.updated_at) - Number(left.updated_at) || left.id.localeCompare(right.id));
|
||||
}
|
||||
|
||||
return { save, load, remove, list };
|
||||
};
|
||||
});
|
||||
@@ -81,4 +81,37 @@ function createConversationPager({ loadPage }) {
|
||||
};
|
||||
}
|
||||
|
||||
function renderConversationComment(comment, controller, escapeHtml, formatTime, renderMarkdown) {
|
||||
const actions = controller?.actionHtml?.(comment) || '';
|
||||
return '<div class="issue-comment" data-comment-id="' + Number(comment.id || 0) + '"><div class="small">' +
|
||||
escapeHtml(comment.author || 'Unknown author') +
|
||||
(comment.created_at ? ' · ' + escapeHtml(formatTime(comment.created_at)) : '') +
|
||||
'</div>' + actions + '<div class="issue-sheet-content markdown-content">' +
|
||||
renderMarkdown(comment.body || 'No comment body provided.') + '</div></div>';
|
||||
}
|
||||
|
||||
function createConversationRenderers({qs,renderComment,updateReadPosition,getSelectedUpdate}) {
|
||||
function status(kind, comments, total) {
|
||||
qs('#' + kind + '-conversation-status').textContent = comments.length ?
|
||||
comments.length + ' of ' + Math.max(total || 0, comments.length) + ' messages loaded.' : 'No comments yet.';
|
||||
}
|
||||
function paint(kind, state, controller) {
|
||||
const comments = state?.comments || [];
|
||||
qs('#' + kind + '-comments').innerHTML = comments.length ? comments.map(comment =>
|
||||
kind === 'pull' ? '<div class="pull-comment-card">' + renderComment(comment,controller) + '</div>' :
|
||||
renderComment(comment,controller)).join('') : '<div class="muted">No comments yet.</div>';
|
||||
qs('#load-older-' + kind + '-comments').hidden = !Number.isInteger(state?.older_page);
|
||||
status(kind,comments,state?.total);
|
||||
if (kind === 'update') {
|
||||
const newest = qs('#update-comments .issue-comment:last-child');
|
||||
updateReadPosition.ready(String(getSelectedUpdate()?.notification_id || ''),newest);
|
||||
}
|
||||
}
|
||||
return {
|
||||
paintIssueConversation:(state,controller)=>paint('issue',state,controller),
|
||||
paintPullConversation:(state,controller)=>paint('pull',state,controller),
|
||||
paintUpdateConversation:(state,controller)=>paint('update',state,controller),
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof module !== 'undefined' && module.exports) module.exports = createConversationPager;
|
||||
@@ -0,0 +1,203 @@
|
||||
function createController({request, storage, login, createId = () => globalThis.crypto?.randomUUID?.() || String(Date.now())}) {
|
||||
const storageKey = 'stackchain.create-pull.v1.' + String(login || '').toLowerCase();
|
||||
let operationId = createId();
|
||||
let current = {
|
||||
repository:'', branches:[], head:'', base:'', expected_head_sha:'',
|
||||
title:'', body:'', draft:true,
|
||||
};
|
||||
try {
|
||||
const saved = JSON.parse(storage?.getItem?.(storageKey) || 'null');
|
||||
if (saved && typeof saved === 'object') {
|
||||
for (const field of ['repository', 'head', 'base', 'title', 'body']) {
|
||||
if (typeof saved[field] === 'string') current[field] = saved[field];
|
||||
}
|
||||
if (typeof saved.draft === 'boolean') current.draft = saved.draft;
|
||||
}
|
||||
} catch (_) {}
|
||||
|
||||
function snapshot() {
|
||||
return JSON.parse(JSON.stringify(current));
|
||||
}
|
||||
|
||||
function persist() {
|
||||
storage?.setItem?.(storageKey, JSON.stringify({
|
||||
repository:current.repository, head:current.head, base:current.base,
|
||||
title:current.title, body:current.body, draft:current.draft,
|
||||
}));
|
||||
}
|
||||
|
||||
async function selectRepository(repository) {
|
||||
const options = await request('api/v1/repos/' + repository + '/pull-creation-options');
|
||||
const branches = Array.isArray(options?.branches) ? options.branches : [];
|
||||
const base = branches.some(branch => branch.name === options.default_branch) ? options.default_branch : (branches[0]?.name || '');
|
||||
const headBranch = branches.find(branch => branch.name !== base) || branches[0] || {};
|
||||
current = {
|
||||
...current, repository, branches, base,
|
||||
head:headBranch.name || '', expected_head_sha:headBranch.sha || '',
|
||||
};
|
||||
persist();
|
||||
return snapshot();
|
||||
}
|
||||
|
||||
function update(values) {
|
||||
current = {...current, ...values};
|
||||
if (Object.prototype.hasOwnProperty.call(values, 'head')) {
|
||||
current.expected_head_sha = current.branches.find(branch => branch.name === values.head)?.sha || '';
|
||||
}
|
||||
persist();
|
||||
return snapshot();
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
const result = await request('api/v1/repos/' + current.repository + '/pulls', {
|
||||
method:'POST',
|
||||
headers:{'Idempotency-Key':operationId},
|
||||
body:{
|
||||
head:current.head, base:current.base, title:current.title, body:current.body,
|
||||
draft:current.draft, expected_head_sha:current.expected_head_sha,
|
||||
},
|
||||
});
|
||||
operationId = createId();
|
||||
return result;
|
||||
}
|
||||
|
||||
return {
|
||||
state:snapshot,
|
||||
selectRepository,
|
||||
update,
|
||||
submit,
|
||||
};
|
||||
}
|
||||
|
||||
function createBinding({controller, render, status, onCreated}) {
|
||||
return {
|
||||
async repositoryChanged(repository) {
|
||||
status('Loading branches…');
|
||||
try {
|
||||
const state = await controller.selectRepository(repository);
|
||||
render(state);
|
||||
status(state.branches.length ? 'Choose the source and base branches.' : 'No branches are available.');
|
||||
return state;
|
||||
} catch (error) {
|
||||
status(error.message || 'Branches could not be loaded.');
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
changed(values) {
|
||||
const state = controller.update(values);
|
||||
render(state);
|
||||
return state;
|
||||
},
|
||||
async submit() {
|
||||
status('Creating pull request…');
|
||||
try {
|
||||
const result = await controller.submit();
|
||||
status(result.existing ? `Pull request #${result.number} is already open.` : `Pull request #${result.number} created.`);
|
||||
onCreated(result);
|
||||
return result;
|
||||
} catch (error) {
|
||||
status(error.message || 'The pull request could not be created. Your draft is safe.');
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async function bindDashboard() {
|
||||
const qs = selector => document.querySelector(selector);
|
||||
const switchButton = qs('#switch-to-create-pull');
|
||||
switchButton.disabled = true;
|
||||
const identityResponse = await fetch('api/v1/background-identity').catch(()=>null);
|
||||
const identity = await identityResponse?.json().catch(()=>({}));
|
||||
if (!identityResponse?.ok || !identity?.login) {
|
||||
switchButton.title = 'Account identity is unavailable.';
|
||||
return null;
|
||||
}
|
||||
const login = identity.login;
|
||||
const root = qs('#create-pull-sheet');
|
||||
const repository = qs('#create-pull-repository');
|
||||
const head = qs('#create-pull-head');
|
||||
const base = qs('#create-pull-base');
|
||||
const title = qs('#create-pull-title');
|
||||
const body = qs('#create-pull-body');
|
||||
const submit = qs('#submit-create-pull');
|
||||
const request = async (url, options) => {
|
||||
const response = await fetch(url, options ? {
|
||||
method:options.method,
|
||||
headers:{'Content-Type':'application/json', ...options.headers},
|
||||
body:JSON.stringify(options.body),
|
||||
} : undefined);
|
||||
const payload = await response.json().catch(()=>({}));
|
||||
if (!response.ok) throw new Error(payload.error || payload.detail || 'Request failed.');
|
||||
return payload;
|
||||
};
|
||||
const controller = createController({request, storage:localStorage, login});
|
||||
const setOptions = (select, branches) => {
|
||||
select.replaceChildren(...branches.map(branch => {
|
||||
const option = document.createElement('option');
|
||||
option.value = option.textContent = branch.name;
|
||||
return option;
|
||||
}));
|
||||
};
|
||||
const render = state => {
|
||||
setOptions(head, state.branches);
|
||||
setOptions(base, state.branches);
|
||||
head.value = state.head;
|
||||
base.value = state.base;
|
||||
head.disabled = base.disabled = !state.branches.length;
|
||||
qs('#create-pull-head-receipt').textContent = state.expected_head_sha ? 'Source at ' + state.expected_head_sha.slice(0, 12) : '';
|
||||
submit.disabled = !(state.repository && state.head && state.base && state.head !== state.base && title.value.trim());
|
||||
};
|
||||
const binding = createBinding({
|
||||
controller, render,
|
||||
status:message=>{ qs('#create-pull-status').textContent = message; },
|
||||
onCreated:result=>{
|
||||
root.hidden = true;
|
||||
qs('main').inert = false;
|
||||
location.hash = '#/my-work/pull/' + result.repository + '/' + result.number;
|
||||
location.reload();
|
||||
},
|
||||
});
|
||||
const update = () => binding.changed({
|
||||
head:head.value, base:base.value, title:title.value, body:body.value,
|
||||
draft:document.querySelector('input[name="create-pull-mode"]:checked')?.value !== 'ready',
|
||||
});
|
||||
repository.addEventListener('change', () => binding.repositoryChanged(repository.value).catch(()=>{}));
|
||||
[head,base,title,body].forEach(field => field.addEventListener('input', update));
|
||||
document.querySelectorAll('input[name="create-pull-mode"]').forEach(field => field.addEventListener('change', () => {
|
||||
update();
|
||||
submit.textContent = field.value === 'ready' && field.checked ? 'Create ready pull request' : 'Create draft pull request';
|
||||
}));
|
||||
qs('#create-pull-form').addEventListener('submit', event => {
|
||||
event.preventDefault();
|
||||
update();
|
||||
binding.submit().catch(()=>{});
|
||||
});
|
||||
const close = () => {
|
||||
root.hidden = true;
|
||||
qs('main').inert = false;
|
||||
qs('#new-issue').focus();
|
||||
};
|
||||
qs('#cancel-create-pull').addEventListener('click', close);
|
||||
switchButton.addEventListener('click', () => {
|
||||
qs('#cancel-new-issue').click();
|
||||
repository.replaceChildren(...Array.from(qs('#create-issue-repository').options).map(source => {
|
||||
const option = document.createElement('option');
|
||||
option.value = source.value;
|
||||
option.textContent = source.textContent;
|
||||
return option;
|
||||
}));
|
||||
root.hidden = false;
|
||||
qs('main').inert = true;
|
||||
qs('#cancel-create-pull').focus();
|
||||
});
|
||||
root.addEventListener('keydown', event => {
|
||||
if (event.key === 'Escape') { event.preventDefault(); close(); }
|
||||
});
|
||||
switchButton.disabled = false;
|
||||
return binding;
|
||||
}
|
||||
|
||||
const cp = {createController, createBinding, b:bindDashboard};
|
||||
if (typeof module !== 'undefined') module.exports = cp;
|
||||
else cp.b();
|
||||
+108
-5
@@ -35,7 +35,20 @@ header { position: sticky; top: 0; z-index: 20; padding: 12px 16px; display:flex
|
||||
.release-watchlist-item { display:grid; grid-template-columns:minmax(0,1fr) auto; align-items:center; gap:10px; padding:10px; border:1px solid #334155; border-radius:10px; }
|
||||
.release-watchlist-item > div { display:grid; min-width:0; gap:3px; overflow-wrap:anywhere; }
|
||||
.release-watchlist-item > button { width:auto; min-width:88px; }
|
||||
@media (max-width:359px) { .release-receipt-actions { grid-template-columns:1fr; } }
|
||||
.release-watchlist-actions { display:grid; grid-template-columns:1fr 1fr; gap:8px; min-width:min(240px,46vw); }
|
||||
.release-watchlist-actions > button { min-height:44px; width:100%; }
|
||||
.release-branch-cleanup-status { color:#cbd5e1; }
|
||||
.release-failure-summary { display:grid; gap:8px; min-width:0; margin-top:8px; padding-top:8px; border-top:1px solid #334155; overflow-x:hidden; }
|
||||
.release-failure-summary > button { min-height:44px; }
|
||||
.release-failure-recovery { display:grid; gap:8px; min-width:0; padding:10px; border:1px solid #7f1d1d; border-radius:8px; background:#180f17; overflow-x:hidden; }
|
||||
.release-failure-recovery pre { box-sizing:border-box; max-width:100%; max-height:32dvh; margin:0; padding:10px; overflow:auto; white-space:pre-wrap; overflow-wrap:anywhere; background:#07101d; }
|
||||
.release-failure-actions { display:grid; grid-template-columns:1fr 1fr; gap:8px; min-width:0; }
|
||||
.release-failure-actions > button, .release-failure-actions > a { min-height:44px; width:100%; }
|
||||
@media (max-width:359px) {
|
||||
.release-receipt-actions, .release-watchlist-actions, .release-failure-actions { grid-template-columns:1fr; }
|
||||
.release-watchlist-item { grid-template-columns:1fr; }
|
||||
.release-watchlist-actions { min-width:0; width:100%; }
|
||||
}
|
||||
.issue-filing-receipt-panel { box-sizing:border-box; width:min(560px,100%); max-height:100dvh; overflow:auto; overflow-x:hidden; padding:18px; padding-bottom:calc(18px + env(safe-area-inset-bottom)); border:1px solid #4ade80; border-radius:18px 18px 0 0; background:#0b1526; overflow-wrap:anywhere; }
|
||||
.issue-filing-receipt-panel h2, .issue-filing-receipt-panel h3 { margin:.25rem 0; }
|
||||
.issue-filing-receipt-actions { display:grid; grid-template-columns:1fr 1fr; gap:8px; margin-top:16px; }
|
||||
@@ -133,6 +146,12 @@ button:hover { filter: brightness(1.15); }
|
||||
.issue-comment { min-width:0; overflow-wrap:anywhere; }
|
||||
.comment-owned-actions { display:flex; gap:8px; flex-wrap:wrap; margin:8px 0; }
|
||||
.comment-owned-actions button { min-height:44px; min-width:72px; }
|
||||
.comment-reactions { display:flex; gap:8px; flex-wrap:wrap; align-items:center; margin:8px 0; min-width:0; }
|
||||
.comment-reactions > button { min-height:44px; min-width:72px; }
|
||||
.comment-reaction-menu { display:flex; gap:8px; flex-wrap:wrap; width:100%; min-width:0; }
|
||||
.comment-reaction-menu[hidden] { display:none; }
|
||||
.comment-reaction-menu button { min-height:44px; min-width:88px; flex:1 1 104px; overflow-wrap:anywhere; }
|
||||
.comment-reaction-menu button[aria-pressed="true"] { border-color:#4ade80; background:#123c2b; color:#dcfce7; }
|
||||
.comment-edit-textarea { box-sizing:border-box; display:block; width:100%; max-width:100%; min-height:132px; resize:vertical; overflow-wrap:anywhere; }
|
||||
.panel { border: 1px solid #1b2d45; border-radius: 14px; padding: 12px; background: rgba(11,21,38,.92); }
|
||||
.panel > summary { cursor: pointer; list-style-position: inside; }
|
||||
@@ -245,6 +264,9 @@ textarea { resize: vertical; min-height: 120px; }
|
||||
.app-badge-control { min-height:44px; }
|
||||
.push-update-control { min-height:44px; }
|
||||
.offline-work-controls input { width:20px; height:20px; }
|
||||
.push-quiet-hours-times { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:10px; width:100%; }
|
||||
.push-quiet-hours-times label { min-width:0; }
|
||||
.offline-work-controls .push-quiet-hours-times input { box-sizing:border-box; width:100%; min-width:0; height:44px; }
|
||||
.offline-work-controls button { min-height:44px; }
|
||||
.offline-today-readiness { display:flex; gap:8px; align-items:center; flex-wrap:wrap; }
|
||||
.offline-today-readiness[hidden] { display:none; }
|
||||
@@ -258,6 +280,15 @@ textarea { resize: vertical; min-height: 120px; }
|
||||
.event { padding: 8px 0; border-bottom: 1px solid #1b2d45; }
|
||||
.event:last-child { border-bottom: 0; }
|
||||
.my-work { grid-column: 1 / -1; }
|
||||
.progressive-work-detail { position:fixed; inset:0; z-index:120; display:flex; align-items:flex-end; justify-content:center; background:rgba(5,12,21,.82); backdrop-filter:blur(4px); }
|
||||
.progressive-work-detail[hidden] { display:none; }
|
||||
.progressive-work-detail-panel { box-sizing:border-box; width:min(560px,100%); max-height:100dvh; overflow:auto; overflow-x:hidden; padding:calc(18px + env(safe-area-inset-top)) 18px calc(18px + env(safe-area-inset-bottom)); border:1px solid #55d6be; border-radius:18px 18px 0 0; background:#0b1526; overflow-wrap:anywhere; }
|
||||
.progressive-work-detail-panel header { display:flex; align-items:flex-start; justify-content:space-between; gap:12px; }
|
||||
.progressive-work-detail-panel h2, .progressive-work-detail-panel p { margin-top:0; }
|
||||
.progressive-work-detail-panel button, .progressive-work-detail-panel .button-link { box-sizing:border-box; min-height:44px; }
|
||||
.progressive-work-detail-panel .button-link { display:flex; align-items:center; justify-content:center; width:100%; }
|
||||
@media(max-width:320px) { .progressive-work-detail-panel { width:100%; padding-inline:14px; } }
|
||||
|
||||
.plan-today-sheet { position:fixed; inset:0; z-index:75; display:flex; justify-content:flex-end; background:rgba(5,12,21,.78); backdrop-filter:blur(4px); }
|
||||
.plan-today-sheet[hidden] { display:none; }
|
||||
.plan-today-panel { box-sizing:border-box; width:min(620px,100%); height:100%; overflow:auto; overflow-x:hidden; padding:18px; background:#0b1526; border-left:1px solid #2a496e; }
|
||||
@@ -746,6 +777,21 @@ textarea { resize: vertical; min-height: 120px; }
|
||||
.review-feedback { display:grid; gap:8px; }
|
||||
.review-feedback label { display:grid; gap:6px; }
|
||||
.review-feedback select { min-height:44px; padding:8px; border-radius:8px; border:1px solid #1f3a5f; background:#0b1526; color:#e5e7eb; }
|
||||
.pull-feedback-code-actions, .pull-feedback-file-actions { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:8px; }
|
||||
.pull-feedback-code-actions button, .pull-feedback-file-actions button { min-height:44px; }
|
||||
.pull-feedback-suggestion-preview { min-width:0; display:grid; gap:10px; margin:10px 0; padding:10px; border:1px solid #31577f; border-radius:10px; background:#07101e; }
|
||||
.pull-feedback-suggestion-preview[hidden] { display:none; }
|
||||
.pull-feedback-suggestion-preview h5 { margin:0; }
|
||||
.pull-feedback-suggestion-change { display:grid; gap:8px; min-width:0; }
|
||||
.pull-feedback-suggestion-change > div { min-width:0; }
|
||||
.pull-feedback-suggestion-change pre { box-sizing:border-box; max-width:100%; max-height:160px; white-space:pre-wrap; overflow-wrap:anywhere; word-break:break-word; }
|
||||
.pull-feedback-suggestion-preview input { box-sizing:border-box; width:100%; min-height:44px; }
|
||||
.pull-feedback-batch-review { min-width:0; display:grid; gap:10px; margin:10px 0; padding:10px; border:1px solid #3b82f6; border-radius:10px; background:#07101e; }
|
||||
.pull-feedback-batch-review[hidden] { display:none; }
|
||||
.pull-feedback-batch-review h5 { margin:0; }
|
||||
.pull-feedback-batch-review ul { min-width:0; margin:0; padding-left:20px; overflow-wrap:anywhere; }
|
||||
.pull-feedback-batch-review input { box-sizing:border-box; width:100%; min-width:0; min-height:44px; }
|
||||
#review-pull-feedback-batch { position:sticky; bottom:calc(8px + env(safe-area-inset-bottom)); z-index:4; width:100%; min-height:44px; }
|
||||
.review-handoff { position:sticky; bottom:0; z-index:3; display:grid; gap:8px; padding:10px 4px; padding-bottom:calc(10px + env(safe-area-inset-bottom)); background:rgba(11,21,38,.98); border-top:1px solid #2a496e; }
|
||||
.review-handoff button { min-height:44px; }
|
||||
.review-handoff-link { min-height:44px; display:flex; align-items:center; justify-content:center; border:1px solid #60a5fa; border-radius:8px; color:#bfdbfe; font-weight:700; text-decoration:none; }
|
||||
@@ -792,6 +838,17 @@ textarea { resize: vertical; min-height: 120px; }
|
||||
.ci-check-copy { min-width:0; display:grid; gap:3px; overflow-wrap:anywhere; }
|
||||
.ci-check-copy strong, .ci-check-copy span { min-width:0; overflow-wrap:anywhere; }
|
||||
.ci-check-link { min-height:44px; display:flex; align-items:center; justify-content:center; padding:0 10px; border:1px solid #60a5fa; border-radius:8px; white-space:nowrap; }
|
||||
.ci-check-actions { display:flex; flex-wrap:wrap; align-items:center; justify-content:flex-end; gap:6px; min-height:44px; }
|
||||
.ci-check-inspect { min-height:44px; white-space:nowrap; }
|
||||
.ci-check-recovery { max-width:100%; min-width:0; margin:0 8px 8px; padding:10px; border:1px solid #dc2626; border-radius:8px; background:#101b2e; }
|
||||
.ci-check-recovery[hidden] { display:none; }
|
||||
.ci-check-recovery h3 { margin:0 0 6px; overflow-wrap:anywhere; }
|
||||
.ci-check-log { max-width:100%; max-height:42vh; margin:8px 0; padding:10px; overflow-x:auto; overflow-y:auto; border:1px solid #2a496e; border-radius:6px; background:#07101d; color:#dbeafe; font-size:.78rem; white-space:pre; }
|
||||
.ci-check-recovery-actions { position:sticky; bottom:0; display:grid; grid-template-columns:1fr 1fr; gap:8px; padding-top:6px; background:#101b2e; }
|
||||
.ci-check-recovery-actions button { min-height:44px; }
|
||||
.pull-branch-update { max-width:100%; min-width:0; margin:10px 0; padding:12px; border:1px solid #60a5fa; border-radius:10px; overflow-wrap:anywhere; }
|
||||
.pull-branch-update h3 { margin:0 0 6px; }
|
||||
.pull-branch-update button { width:100%; min-height:44px; }
|
||||
.update-sheet { position:fixed; inset:0; z-index:55; display:none; justify-content:flex-end; background:rgba(5,12,21,.72); backdrop-filter:blur(4px); }
|
||||
.update-sheet.open { display:flex; }
|
||||
.update-sheet-panel { width:min(560px,100%); height:100%; overflow:auto; padding:18px; background:#0b1526; border-left:1px solid #2a496e; }
|
||||
@@ -958,8 +1015,13 @@ textarea { resize: vertical; min-height: 120px; }
|
||||
.issue-sheet-actions #watch-issue-detail, .pull-sheet-actions #watch-pull-detail { min-width:0; min-height:44px; }
|
||||
.detail-watch-status:not(:empty) { margin-top:8px; overflow-wrap:anywhere; }
|
||||
.issue-sheet-actions a { border:1px solid #60a5fa; border-radius:10px; font-weight:700; }
|
||||
.issue-handoff, .pull-ownership, .pull-review-request { margin-top:14px; padding:12px; border:1px solid #2a496e; border-radius:12px; }
|
||||
.issue-handoff > div, .pull-ownership > div, .pull-review-request > div { display:grid; gap:8px; margin-top:10px; }
|
||||
.issue-handoff, .pull-ownership, .pull-review-request, .pull-lifecycle { margin-top:14px; padding:12px; border:1px solid #2a496e; border-radius:12px; }
|
||||
.issue-handoff > div, .pull-ownership > div, .pull-review-request > div, .pull-lifecycle > div { display:grid; gap:8px; margin-top:10px; }
|
||||
.pull-lifecycle { border-color:#b45353; }
|
||||
.pull-lifecycle button { min-height:44px; border-color:#ef4444; background:#5f1d24; color:#fff; }
|
||||
.pull-close-receipt { margin-top:14px; padding:12px; border:1px solid #4ade80; border-radius:12px; background:#10291e; }
|
||||
.pull-close-receipt h3 { margin-top:0; }
|
||||
.pull-close-receipt button { width:100%; min-height:44px; border-color:#4ade80; }
|
||||
.issue-handoff select, .pull-ownership select, .pull-review-request select { width:100%; max-width:100%; padding:8px; border:1px solid #1f3a5f; border-radius:8px; background:#0b1526; color:var(--text); }
|
||||
.issue-handoff select, .issue-handoff button { min-height:44px; }
|
||||
.pull-ownership select, .pull-ownership button { min-height:44px; }
|
||||
@@ -1150,6 +1212,12 @@ textarea { resize: vertical; min-height: 120px; }
|
||||
.voice-conversation-review textarea { box-sizing:border-box; width:100%; min-height:96px; resize:vertical; }
|
||||
.create-issue-capture-actions { position:sticky; bottom:0; display:grid; grid-template-columns:1fr 1fr; gap:8px; padding:10px 0; padding-bottom:calc(10px + env(safe-area-inset-bottom)); background:#0b1526; }
|
||||
.create-issue-capture-actions[hidden] { display:none; }
|
||||
.create-issue-sheet.progressive-capture .mobile-create-issue-nav,
|
||||
.create-issue-sheet.progressive-capture .create-issue-attachment,
|
||||
.create-issue-sheet.progressive-capture .create-issue-filing,
|
||||
.create-issue-sheet.progressive-capture #switch-to-create-pull,
|
||||
.create-issue-sheet.progressive-capture .today-capture-interruption,
|
||||
.create-issue-sheet.progressive-capture .shared-content-conflict { display:none; }
|
||||
.create-issue-filing { display:grid; gap:12px; min-width:0; }
|
||||
.create-issue-filing[hidden] { display:none; }
|
||||
.create-issue-attachment { display:grid; gap:8px; min-width:0; }
|
||||
@@ -1281,6 +1349,14 @@ textarea { resize: vertical; min-height: 120px; }
|
||||
.pull-feedback-pass-heading h4 { margin:2px 0 8px; }
|
||||
.pull-feedback-pass p { white-space:pre-wrap; }
|
||||
.pull-feedback-pass textarea { width:100%; min-height:88px; box-sizing:border-box; }
|
||||
#make-pull-feedback-fix { width:100%; margin-top:8px; border-color:#4ade80; }
|
||||
.pull-feedback-file-editor { display:grid; min-width:0; gap:8px; margin-top:10px; padding:10px; border:1px solid #4ade80; border-radius:10px; overflow-x:hidden; }
|
||||
.pull-feedback-file-editor[hidden] { display:none; }
|
||||
.pull-feedback-file-editor h5 { margin:0; overflow-wrap:anywhere; }
|
||||
#pull-feedback-file-content { min-height:36dvh; resize:vertical; font:13px/1.45 ui-monospace, SFMono-Regular, Consolas, monospace; tab-size:2; white-space:pre; overflow:auto; }
|
||||
#pull-feedback-commit-message { box-sizing:border-box; width:100%; min-width:0; }
|
||||
.pull-feedback-file-actions { display:grid; grid-template-columns:1fr 1fr; gap:8px; min-width:0; }
|
||||
@media (max-width:359px) { .pull-feedback-file-actions { grid-template-columns:1fr; } }
|
||||
.pull-feedback-dispositions { display:grid; grid-template-columns:1fr; gap:6px; margin:10px 0; padding:8px; }
|
||||
.pull-feedback-dispositions button[aria-pressed="true"] { border-color:#60a5fa; background:#173b63; }
|
||||
.pull-feedback-navigation { display:grid; grid-template-columns:1fr 1fr; gap:8px; margin-top:8px; }
|
||||
@@ -1420,7 +1496,7 @@ textarea { resize: vertical; min-height: 120px; }
|
||||
.composer-keyboard-active .review-inline-composer,
|
||||
.composer-keyboard-active .update-reply { scroll-margin-block:12px; padding-bottom:env(safe-area-inset-bottom); }
|
||||
.mobile-task-dock { position:fixed; inset:auto 0 0; z-index:45; display:grid; grid-template-columns:repeat(5,minmax(0,1fr)); gap:2px; padding:6px 8px; padding-bottom:env(safe-area-inset-bottom); border-top:1px solid #2a496e; background:rgba(11,21,38,.98); backdrop-filter:blur(12px); }
|
||||
.mobile-queue-sheet { width:100%; max-width:none; margin:auto 0 0; padding:0; border:0; border-radius:18px 18px 0 0; color:var(--text); background:#102641; }
|
||||
.mobile-queue-sheet { box-sizing:border-box; width:100%; max-width:none; max-height:100dvh; margin:auto 0 0; padding:0; border:0; border-radius:18px 18px 0 0; color:var(--text); background:#102641; }
|
||||
.following-sheet { width:100%; max-width:none; border:0; border-radius:18px 18px 0 0; }
|
||||
|
||||
.mobile-first-task { box-sizing:border-box; width:100%; max-width:none; max-height:100dvh; margin:auto 0 0; padding:0; border:0; border-radius:18px 18px 0 0; color:var(--text); background:#102641; }
|
||||
@@ -1433,9 +1509,19 @@ textarea { resize: vertical; min-height: 120px; }
|
||||
.mobile-first-task-actions button:disabled { opacity:.55; }
|
||||
|
||||
.mobile-queue-sheet::backdrop { background:rgba(3,9,18,.7); }
|
||||
.mobile-queue-panel { padding:16px; padding-bottom:calc(16px + env(safe-area-inset-bottom)); }
|
||||
.mobile-queue-panel { box-sizing:border-box; max-height:100dvh; overflow-y:auto; overscroll-behavior:contain; padding:16px; padding-bottom:calc(16px + env(safe-area-inset-bottom)); }
|
||||
.mobile-queue-panel header { display:flex; align-items:center; justify-content:space-between; gap:12px; }
|
||||
.mobile-queue-panel h2 { margin:0; }
|
||||
.mobile-queue-next { display:grid; gap:6px; margin-top:12px; padding:12px; border:1px solid #60a5fa; border-radius:14px; background:#122f50; }
|
||||
.mobile-queue-next p, .mobile-queue-group h3 { margin:0; }
|
||||
.mobile-queue-next button { min-height:48px; width:100%; text-align:center; font-weight:800; }
|
||||
.mobile-queue-group { margin-top:16px; }
|
||||
.mobile-queue-group h3 { font-size:1rem; }
|
||||
.mobile-queue-all { margin-top:16px; }
|
||||
.mobile-queue-all summary { min-height:44px; display:flex; align-items:center; cursor:pointer; font-weight:700; }
|
||||
.mobile-queue-list [data-unavailable="true"] { border-color:#f59e0b; }
|
||||
.mobile-queue-list [data-unavailable="true"]::after { content:'Sync unavailable · open to retry'; color:#fbbf24; font-size:.75rem; }
|
||||
.mobile-queue-list [data-progressive-loading="true"]::after { content:'Still loading · available after workspace starts'; }
|
||||
.mobile-delivery-recovery { box-sizing:border-box; width:100%; max-width:none; max-height:100dvh; margin:auto 0 0; padding:0; border:0; border-radius:18px 18px 0 0; color:var(--text); background:#102641; }
|
||||
.mobile-delivery-recovery::backdrop { background:rgba(3,9,18,.78); }
|
||||
.mobile-delivery-recovery-panel { box-sizing:border-box; display:grid; gap:12px; width:100%; padding:18px; padding-bottom:calc(18px + env(safe-area-inset-bottom)); overflow-wrap:anywhere; }
|
||||
@@ -1523,3 +1609,20 @@ textarea { resize: vertical; min-height: 120px; }
|
||||
transition: transform 120ms ease, border-color 120ms ease;
|
||||
}
|
||||
}
|
||||
|
||||
.create-pull-sheet{position:fixed;inset:0;z-index:75;background:rgba(3,7,18,.72);display:grid;place-items:end center;padding:16px}
|
||||
.create-pull-sheet[hidden]{display:none}
|
||||
.create-pull-panel{width:min(100%,680px);max-height:calc(100dvh - 32px);overflow:auto;background:var(--panel);border:1px solid var(--border);border-radius:20px;padding:20px;padding-bottom:max(20px,env(safe-area-inset-bottom))}
|
||||
.create-pull-header{display:flex;align-items:center;justify-content:space-between;gap:12px}
|
||||
.create-pull-header h3{margin:2px 0 0}
|
||||
.create-pull-panel form,.create-pull-panel label{display:grid;gap:6px}
|
||||
.create-pull-panel form{gap:14px}
|
||||
.create-pull-branches{display:grid;grid-template-columns:1fr 1fr;gap:12px}
|
||||
.create-pull-mode{display:flex;gap:18px;border:1px solid var(--border);border-radius:12px;padding:10px 12px}
|
||||
.create-pull-mode label{display:flex;align-items:center;gap:7px}
|
||||
.create-pull-panel button,.create-pull-panel select,.create-pull-panel input{min-height:44px}
|
||||
@media(max-width:600px){.create-pull-sheet{padding:0}.create-pull-panel{width:100%;max-height:100dvh;border-radius:18px 18px 0 0}.create-pull-branches{grid-template-columns:1fr}}
|
||||
|
||||
.human-gates{position:fixed;inset:0;z-index:72;background:var(--bg);overflow:auto;padding:18px max(16px,env(safe-area-inset-right)) max(24px,env(safe-area-inset-bottom)) max(16px,env(safe-area-inset-left))}
|
||||
.human-gates[hidden]{display:none}.human-gates-header{display:flex;align-items:flex-start;justify-content:space-between;gap:12px;max-width:760px;margin:0 auto 14px}.human-gates-header h3{margin:0}.human-gates-list,.human-gate-detail-host{display:grid;gap:10px;max-width:760px;margin:0 auto 14px}.human-gate-card{display:grid;grid-template-columns:1fr auto;text-align:left;gap:6px 12px;min-height:58px;padding:12px;border:1px solid var(--border);border-radius:14px;background:var(--panel)}.human-gate-card span{grid-column:1/-1;color:var(--muted)}.human-gate-detail{display:grid;gap:12px;padding:16px;border:1px solid var(--border);border-radius:16px;background:var(--panel)}.human-gate-detail h3,.human-gate-detail h4,.human-gate-detail p{margin:0}.human-gate-detail label{display:grid;gap:6px}.human-gate-detail label:has(input[type=checkbox]){grid-template-columns:auto 1fr;align-items:center}.human-gate-detail textarea{min-height:78px}.human-gate-detail>div{display:grid;grid-template-columns:1fr 1fr;gap:10px}.human-gates-zero{display:grid;gap:6px;text-align:center;padding:32px 16px;border:1px dashed var(--border);border-radius:16px}.human-gates-launcher span{display:inline-grid;place-items:center;min-width:22px;border-radius:999px;background:var(--accent);color:#06101f}
|
||||
@media(min-width:761px){.human-gates{inset:8% max(8%,80px);border:1px solid var(--border);border-radius:20px;box-shadow:0 24px 80px rgba(0,0,0,.4)}}
|
||||
+204
-74
@@ -1,5 +1,12 @@
|
||||
(async function(){
|
||||
const workspaceLifecycle = await loadWorkspace({ document, window });
|
||||
const workspaceLifecycle = await (window.stackchainWorkspaceLifecycle || loadWorkspace({ document, window }));
|
||||
await workspaceLifecycle.optionalReady;
|
||||
const progressiveCaptureHandoff = window.stackchainProgressiveCapture?.handoff?.();
|
||||
const progressiveWorkHandoff = window.stackchainProgressiveMyWork?.handoff?.();
|
||||
const progressiveHumanGatesHandoff = window.stackchainProgressiveHumanGates?.handoff?.();
|
||||
const progressiveMobileDockHandoff = window.stackchainProgressiveMobileDock?.handoff?.();
|
||||
window.stackchainProgressiveMobileDock?.stop?.();
|
||||
window.stackchainProgressiveMyWork?.stop();
|
||||
const qs = (s, el=document) => el.querySelector(s);
|
||||
const announceWork = message => qs('#my-work-action-status').textContent = message;
|
||||
const fmt = (d) => new Date(d).toLocaleString();
|
||||
@@ -105,6 +112,7 @@
|
||||
}
|
||||
let queueCounts = {};
|
||||
let preparationItems = {};
|
||||
let renderMobileQueuePresentation = () => {};
|
||||
const followingQueue = attachFollowing(item => {
|
||||
searchPreviewReturnKind = 'following';
|
||||
return searchPreview.open(item);
|
||||
@@ -114,11 +122,13 @@
|
||||
queueCounts.following = count;
|
||||
queueCounts.followingUnavailable = false;
|
||||
preparationItems.following = items.filter(item => item.has_unseen_change === true);
|
||||
renderMobileQueuePresentation();
|
||||
mobileStartDay.render();
|
||||
},
|
||||
onStatus:status => {
|
||||
if (status === 'loading') return;
|
||||
queueCounts.followingUnavailable = status === 'error';
|
||||
renderMobileQueuePresentation();
|
||||
mobileStartDay.render();
|
||||
},
|
||||
onReviewComplete:() => mobileStartDay.completePhase('following'),
|
||||
@@ -159,6 +169,7 @@
|
||||
}
|
||||
const mobileQueueLauncher = createMobileQueueLauncher({
|
||||
openDelivery: () => mobileDeliveryRecovery.open(),
|
||||
openHumanGates: () => openHumanGates(),
|
||||
openToday: () => mobileWorkEntry.open(),
|
||||
openAgenda: openAgendaSession,
|
||||
openUpdates: openUpdateTriage,
|
||||
@@ -169,7 +180,18 @@
|
||||
announce: announceWork,
|
||||
getCounts: () => queueCounts,
|
||||
openFindWork: () => qs('#find-work').click(),
|
||||
rows: Object.fromEntries(
|
||||
Array.from(document.querySelectorAll('[data-mobile-queue]')).map(button => [button.dataset.mobileQueue, button])
|
||||
),
|
||||
nextAction: qs('#mobile-queue-next-action'),
|
||||
activeList: qs('#mobile-queue-active-list'),
|
||||
planningList: qs('#mobile-queue-planning-list'),
|
||||
allList: qs('#mobile-queue-all-list'),
|
||||
activeSection: qs('#mobile-queue-active-list').parentElement,
|
||||
});
|
||||
renderMobileQueuePresentation = () => mobileQueueLauncher.renderPresentation();
|
||||
renderMobileQueuePresentation();
|
||||
qs('#mobile-queue-next-action').addEventListener('click', () => mobileQueueLauncher.continueWork());
|
||||
function openMobileStartDay() {
|
||||
followingQueue.load().catch(() => {});
|
||||
const state = mobileStartDay.state();
|
||||
@@ -287,6 +309,12 @@
|
||||
},
|
||||
});
|
||||
mobileTaskDock.start();
|
||||
if (['work', 'queues'].includes(progressiveMobileDockHandoff?.lastTask)) {
|
||||
mobileTaskDock.select(progressiveMobileDockHandoff.lastTask);
|
||||
}
|
||||
if (progressiveMobileDockHandoff?.queueSheetOpen && !qs('#mobile-queue-sheet').open) {
|
||||
qs('#mobile-queue-sheet').showModal();
|
||||
}
|
||||
const mobileTodayActions = qs('#mobile-today-actions');
|
||||
createMobileTodayCommandBar({
|
||||
more:qs('[data-mobile-today-more]'),
|
||||
@@ -320,15 +348,17 @@
|
||||
let offlineWorkMode = false;
|
||||
const WORK_FILTER_KEY = 'stackchain.my-work-filter.v1';
|
||||
const WORK_MILESTONE_KEY = 'stackchain.my-work-milestone.v1';
|
||||
let selectedWorkFilter = 'all';
|
||||
const WORK_FILTERS = ['all', 'today', 'agenda', 'attention', 'filed', 'authored', 'issue', 'pull', 'review', 'update', 'later', 'draft'];
|
||||
const hasProgressiveWorkFilter = WORK_FILTERS.includes(progressiveWorkHandoff?.selectedFilter);
|
||||
let selectedWorkFilter = hasProgressiveWorkFilter ? progressiveWorkHandoff.selectedFilter : 'all';
|
||||
let selectedFiledView = 'needs-review';
|
||||
let selectedWorkMilestone = 'all';
|
||||
let queueFindQuery = '';
|
||||
let savedWorkFilter = null;
|
||||
let launchFilterResolved = false;
|
||||
let launchFilterResolved = hasProgressiveWorkFilter;
|
||||
try {
|
||||
const savedFilter = sessionStorage.getItem(WORK_FILTER_KEY);
|
||||
if (['all', 'today', 'agenda', 'attention', 'filed', 'authored', 'issue', 'pull', 'review', 'update', 'later', 'draft'].includes(savedFilter)) {
|
||||
if (!hasProgressiveWorkFilter && ['all', 'today', 'agenda', 'attention', 'filed', 'authored', 'issue', 'pull', 'review', 'update', 'later', 'draft'].includes(savedFilter)) {
|
||||
selectedWorkFilter = savedFilter;
|
||||
savedWorkFilter = savedFilter;
|
||||
launchFilterResolved = true;
|
||||
@@ -368,6 +398,7 @@
|
||||
let selectedPullDetail = null;
|
||||
let pullConversation = null;
|
||||
let pullReviewState = null;
|
||||
|
||||
let creatingIssue = false;
|
||||
let createAndStartRequested = false;
|
||||
let pendingIssueFilingIntent = 'create-and-assign';
|
||||
@@ -385,24 +416,26 @@
|
||||
let editingOutboxId = null;
|
||||
let confirmedOwnerLogin = '';
|
||||
let planningOwnerLogin = '';
|
||||
let planningOwnerAccountKey = '';
|
||||
let activeFlushLogin = '';
|
||||
let releaseReceipt = null;
|
||||
function attachReleaseReceipt() {
|
||||
if (releaseReceipt) return releaseReceipt;
|
||||
releaseReceipt = createReleaseReceipt({
|
||||
let rR = null;
|
||||
function rRC() {
|
||||
if (rR) return rR;
|
||||
rR = createReleaseReceipt({
|
||||
storage:localStorage, getLogin:()=>confirmedOwnerLogin, fetchJson:fetchReviewJson,
|
||||
launcher:qs('#release-receipt-launcher'), dialog:qs('#release-receipt-sheet'),
|
||||
statusNode:qs('#release-receipt-status'), checksNode:qs('#release-receipt-checks'),
|
||||
releaseNode:qs('#release-receipt-link'),
|
||||
listNode:qs('#release-watchlist'),
|
||||
openPull:openPullSheet,
|
||||
});
|
||||
releaseReceipt.bind();
|
||||
rR.bind();
|
||||
qs('#close-release-receipt').addEventListener('click', () => qs('#release-receipt-sheet').close());
|
||||
qs('#refresh-release-receipt').addEventListener('click', () => releaseReceipt.refresh().catch(error => {
|
||||
qs('#refresh-release-receipt').addEventListener('click', () => rR.refresh().catch(error => {
|
||||
qs('#release-receipt-status').textContent = error.message + ' Retry when connected.';
|
||||
}));
|
||||
qs('#dismiss-release-receipt').addEventListener('click', () => releaseReceipt.dismiss());
|
||||
return releaseReceipt;
|
||||
qs('#dismiss-release-receipt').addEventListener('click', () => rR.dismiss());
|
||||
return rR;
|
||||
}
|
||||
const completedFiledReview = createCompletedFiledReview({
|
||||
storage: localStorage,
|
||||
@@ -626,6 +659,60 @@
|
||||
return payload;
|
||||
}
|
||||
|
||||
const humanGatesOnChange = (snapshot, state)=>{
|
||||
queueCounts.gate = snapshot.pending_count;
|
||||
appBadge.reconcile('human-gates', snapshot.pending_count, state.authoritative === true);
|
||||
queueCounts.gateUnavailable = state.available === false;
|
||||
preparationItems.gate = snapshot.items;
|
||||
mobileTaskDock.updateQueues(queueCounts);
|
||||
if (state.authoritative) mobileStartDay.reconcile({authoritative:true, authoritativePhases:['gate']});
|
||||
mobileStartDay.render();
|
||||
};
|
||||
const humanGates = progressiveHumanGatesHandoff?.controller || createHumanGates({
|
||||
storage:localStorage,
|
||||
getLogin:()=>planningOwnerLogin,
|
||||
getAccountKey:()=>planningOwnerAccountKey,
|
||||
isOnline:()=>navigator.onLine,
|
||||
location:window.location,
|
||||
fetchJson:fetchReviewJson,
|
||||
onChange:humanGatesOnChange,
|
||||
nodes:{
|
||||
count:qs('#human-gates-count'), list:qs('#human-gates-list'),
|
||||
status:qs('#human-gates-status'), panel:qs('#human-gates'),
|
||||
detail:qs('#human-gate-detail'),
|
||||
},
|
||||
});
|
||||
progressiveHumanGatesHandoff?.adoptIdentity(planningOwnerLogin, planningOwnerAccountKey);
|
||||
humanGates.setOnChange?.(humanGatesOnChange);
|
||||
const openHumanGates = () => humanGates.open().catch(error => {
|
||||
qs('#human-gates-status').textContent = error.message || 'Human Gates are unavailable.';
|
||||
});
|
||||
if (!progressiveHumanGatesHandoff) {
|
||||
qs('#open-human-gates').addEventListener('click', openHumanGates);
|
||||
qs('#close-human-gates').addEventListener('click', () => {
|
||||
qs('#human-gates').hidden = true;
|
||||
if (window.location.hash === '#/my-work/human-gates') window.history.replaceState({}, '', '#/my-work');
|
||||
});
|
||||
qs('#human-gates-list').addEventListener('click', event => {
|
||||
const card = event.target.closest('[data-human-gate-id]');
|
||||
if (!card) return;
|
||||
humanGates.select(card.dataset.humanGateId);
|
||||
});
|
||||
qs('#human-gate-detail').addEventListener('click', event => {
|
||||
const decision = event.target.closest('[data-gate-decision]')?.dataset.gateDecision;
|
||||
if (!decision) return;
|
||||
const detail = qs('#human-gate-detail');
|
||||
const checklist = Object.fromEntries(Array.from(detail.querySelectorAll('[data-gate-checklist]')).map(input => [input.dataset.gateChecklist, input.checked]));
|
||||
humanGates.decideAndNext(decision, {
|
||||
checklist,
|
||||
reason:detail.querySelector('[data-gate-reason]')?.value || '',
|
||||
override_reason:detail.querySelector('[data-gate-override]')?.value || '',
|
||||
}).catch(error => { qs('#human-gates-status').textContent = error.message; });
|
||||
});
|
||||
}
|
||||
if (!progressiveHumanGatesHandoff?.started) humanGates.load().catch(() => {});
|
||||
if (window.location.hash === '#/my-work/human-gates' && !progressiveHumanGatesHandoff?.started) openHumanGates();
|
||||
|
||||
function syncCompletedFiledReviews() {
|
||||
if (!planningOwnerLogin) return Promise.resolve(false);
|
||||
if (completedFiledSyncFlight) return completedFiledSyncFlight;
|
||||
@@ -775,6 +862,7 @@
|
||||
try {
|
||||
const attachments = await searchReplyAttachmentController.serialize();
|
||||
await searchReplyDraftStore.save(target, attachments);
|
||||
void refreshPhotoDraftInbox();
|
||||
} catch (error) {
|
||||
qs('#search-preview-reply-status').textContent = error?.message ||
|
||||
'Photos could not be saved. They remain in this preview; retry before leaving.';
|
||||
@@ -1000,6 +1088,7 @@
|
||||
} });
|
||||
const conversationPhotoDrafts = createConversationPhotoDrafts({
|
||||
store:conversationPhotoDraftStore,
|
||||
onChange:() => { void refreshPhotoDraftInbox(); },
|
||||
lanes:{
|
||||
issue:photoDraftLane(issueAttachmentController, '#issue-comment-status'),
|
||||
pull:photoDraftLane(pullAttachmentController, '#pull-comment-status'),
|
||||
@@ -1279,7 +1368,7 @@
|
||||
trigger, status: qs('#my-work-action-status'), retryLabel:'Tap the work card to retry.',
|
||||
}, () => {
|
||||
if (!pullController) {
|
||||
pullController = createPullSheet({ fetchJson: fetchReviewJson, storage: localStorage });
|
||||
pullController = createPullSheet({ fetchJson: fetchReviewJson, storage: localStorage, onState:refreshMyWorkView });
|
||||
createPullSheet.bindOwnershipControls(document, pullController, () => selectedPull, async item => {
|
||||
const continuing = workSession.checkpointed(item);
|
||||
lastContextSnapshot = createPullSheet.removeFromSnapshot(lastContextSnapshot, item);
|
||||
@@ -1288,9 +1377,8 @@
|
||||
paintMyWork(lastContextSnapshot);
|
||||
return false;
|
||||
}, ()=>selectedPullDetail, ()=>confirmedOwnerLogin);
|
||||
|
||||
}
|
||||
attachReleaseReceipt();
|
||||
rRC();
|
||||
if (!reviewController) reviewController = createReviewController({ fetchJson: fetchReviewJson, storage: localStorage });
|
||||
if (!wrapPreference) {
|
||||
wrapPreference = createReviewController.createWrapPreference({
|
||||
@@ -1306,9 +1394,13 @@
|
||||
try {
|
||||
if (!localStorage.getItem('stackchain.release-receipt.v1:' + account)) return;
|
||||
} catch (_error) { return; }
|
||||
ensurePullWorkflow().then(() => releaseReceipt.restore()).catch(() => {});
|
||||
ensurePullWorkflow().then(() => rR.restore()).catch(() => {});
|
||||
}
|
||||
const draftInbox = createDraftInbox({ storage: localStorage, getCurrentLogin: () => activeFlushLogin });
|
||||
const photoDraftInbox = createPhotoDraftInbox({
|
||||
conversation:conversationPhotoDraftStore,
|
||||
search:searchReplyDraftStore,
|
||||
});
|
||||
outboxCoordinator.subscribe(() => refreshMyWorkView());
|
||||
const offlineWorkStore = createOfflineWorkStore({ storage: localStorage, indexedDB:window.indexedDB });
|
||||
let offlineStorageReady = await offlineWorkStore.ready();
|
||||
@@ -3400,12 +3492,17 @@
|
||||
ownership:item.quarantined ? 'Saved by ' + item.ownerLogin +
|
||||
(activeFlushLogin ? ' — current account is ' + activeFlushLogin : ' — reconnect to confirm this account') : '',
|
||||
}));
|
||||
return draftInbox.list().concat(unfiled).sort((left, right) =>
|
||||
return draftInbox.list().concat(photoDraftInbox.list(), unfiled).sort((left, right) =>
|
||||
Number(right.updated_at || 0) - Number(left.updated_at || 0)
|
||||
);
|
||||
}
|
||||
|
||||
function refreshMyWorkView({ reconcileSession = true } = {}) {
|
||||
async function refreshPhotoDraftInbox() {
|
||||
try { await photoDraftInbox.refresh(draftInbox.list()); refreshMyWorkView({ reconcileSession:false, refreshFirstTask:false }); }
|
||||
catch (_error) { /* Local photo inventory must not break My Work. */ }
|
||||
}
|
||||
|
||||
function refreshMyWorkView({ reconcileSession = true, refreshFirstTask = true } = {}) {
|
||||
lastDrafts = listDrafts();
|
||||
const actionableMyWork = filedHistoryTabs.prepare(lastMyWork);
|
||||
const partitioned = laterWork.partition(actionableMyWork, {
|
||||
@@ -3431,8 +3528,11 @@
|
||||
counts.later = laterMyWork.length;
|
||||
counts.draft = lastDrafts.length;
|
||||
counts.delivery = draftInbox.partition(lastDrafts).actionable;
|
||||
counts.gate = queueCounts.gate;
|
||||
counts.gateUnavailable = queueCounts.gateUnavailable;
|
||||
preparationItems = {
|
||||
delivery:draftInbox.partition(lastDrafts).deliveries,
|
||||
gate:preparationItems.gate || [],
|
||||
agenda:agendaMyWork(activeMyWork),
|
||||
attention:activeMyWork.filter(item => item.needs_attention),
|
||||
update:activeMyWork.filter(item => item.has_update),
|
||||
@@ -3453,13 +3553,14 @@
|
||||
if (element) element.textContent = count;
|
||||
});
|
||||
queueCounts = counts;
|
||||
mobileQueueLauncher.renderPresentation();
|
||||
mobileStartDay.reconcile({
|
||||
authoritative:authoritativeMyWorkRefresh,
|
||||
authoritativePhases:['delivery'],
|
||||
});
|
||||
mobileStartDay.render();
|
||||
mobileTaskDock.updateQueues(counts);
|
||||
mobileFirstTask.refresh();
|
||||
if (refreshFirstTask) mobileFirstTask.refresh();
|
||||
mobileTaskDock.updateWork(mobileWorkEntry.mode());
|
||||
mobileTaskDock.updateAttention(countMyWork(activeMyWork).attention);
|
||||
const activeQueue = qs('[data-work-filter="' + selectedWorkFilter + '"]');
|
||||
@@ -3578,7 +3679,7 @@
|
||||
return '<article class="my-work-card draft-card"' + captureTarget + '>' +
|
||||
'<span class="small">' + escapeHtml([item.label, item.repository, item.details].filter(Boolean).join(' · ')) + '</span>' +
|
||||
'<span class="my-work-card-title">' + escapeHtml(item.title) + '</span>' +
|
||||
'<span class="draft-preview">' + escapeHtml(item.preview || 'Unfinished draft') + '</span>' + state + attempt +
|
||||
'<span class="draft-preview">' + escapeHtml(photoDraftInbox.description(item)) + '</span>' + state + attempt +
|
||||
'<span class="small">Saved ' + escapeHtml(fmt(item.updated_at)) + '</span>' +
|
||||
'<div class="draft-actions">' + outboxActions + '</div></article>';
|
||||
};
|
||||
@@ -3617,6 +3718,9 @@
|
||||
await dFS.open(item.capture_id, item.ready ? button : null);
|
||||
} catch (error) { qs('#my-work-action-status').textContent = error.message; }
|
||||
} else if (item.kind === 'new-issue') openCreateIssueSheet();
|
||||
else if (item.kind === 'photo-reply' && item.route?.kind === 'search') {
|
||||
taskOverlayHistory.open('search-preview', { preview:photoDraftInbox.searchTarget(item) });
|
||||
}
|
||||
else if (item.route) workRoute.open(item.route);
|
||||
};
|
||||
});
|
||||
@@ -3735,6 +3839,7 @@
|
||||
}
|
||||
else if (item?.kind === 'issue-outbox') issueOutbox.discard(item.outbox_id);
|
||||
else if (item?.kind === 'authored-outbox') authoredOutbox.discard(item.outbox_id);
|
||||
else if (item?.kind === 'photo-reply') await photoDraftInbox.discard(item);
|
||||
else if (item) draftInbox.discard(item.id);
|
||||
lastDrafts = listDrafts();
|
||||
const count = qs('[data-work-count="draft"]');
|
||||
@@ -4096,46 +4201,17 @@
|
||||
toggle?.focus();
|
||||
}
|
||||
|
||||
function renderIssueComment(comment, controller = commentActions) {
|
||||
const actions = controller?.actionHtml?.(comment) || '';
|
||||
return '<div class="issue-comment" data-comment-id="' + Number(comment.id || 0) + '"><div class="small">' +
|
||||
escapeHtml(comment.author || 'Unknown author') +
|
||||
(comment.created_at ? ' · ' + escapeHtml(fmt(comment.created_at)) : '') +
|
||||
'</div>' + actions + '<div class="issue-sheet-content markdown-content">' +
|
||||
renderMarkdown(comment.body || 'No comment body provided.') + '</div></div>';
|
||||
}
|
||||
|
||||
function paintIssueConversation(state, controller) {
|
||||
const comments = state?.comments || [];
|
||||
qs('#issue-comments').innerHTML = comments.length ?
|
||||
comments.map(comment => renderIssueComment(comment, controller)).join('') : '<div class="muted">No comments yet.</div>';
|
||||
qs('#load-older-issue-comments').hidden = !Number.isInteger(state?.older_page);
|
||||
qs('#issue-conversation-status').textContent = comments.length ?
|
||||
comments.length + ' of ' + Math.max(state.total || 0, comments.length) + ' messages loaded.' : 'No comments yet.';
|
||||
}
|
||||
|
||||
function paintUpdateConversation(state, controller) {
|
||||
const comments = state?.comments || [];
|
||||
qs('#update-comments').innerHTML = comments.length ?
|
||||
comments.map(comment => renderIssueComment(comment, controller)).join('') : '<div class="muted">No comments yet.</div>';
|
||||
qs('#load-older-update-comments').hidden = !Number.isInteger(state?.older_page);
|
||||
qs('#update-conversation-status').textContent = comments.length ?
|
||||
comments.length + ' of ' + Math.max(state.total || 0, comments.length) + ' messages loaded.' : 'No comments yet.';
|
||||
const newest = qs('#update-comments .issue-comment:last-child');
|
||||
updateReadPosition.ready(String(selectedUpdate?.notification_id || ''), newest);
|
||||
}
|
||||
|
||||
function paintPullConversation(state, controller) {
|
||||
const comments = state?.comments || [];
|
||||
qs('#pull-comments').innerHTML = comments.length ? comments.map(comment =>
|
||||
'<div class="pull-comment-card">' + renderIssueComment(comment, controller) + '</div>'
|
||||
).join('') : '<div class="muted">No comments yet.</div>';
|
||||
qs('#load-older-pull-comments').hidden = !Number.isInteger(state?.older_page);
|
||||
qs('#pull-conversation-status').textContent = comments.length ?
|
||||
comments.length + ' of ' + Math.max(state.total || 0, comments.length) + ' messages loaded.' : 'No comments yet.';
|
||||
}
|
||||
const {paintIssueConversation,paintPullConversation,paintUpdateConversation}=createConversationRenderers({
|
||||
qs,renderComment:(comment,controller)=>renderConversationComment(
|
||||
comment,controller,escapeHtml,fmt,renderMarkdown),
|
||||
updateReadPosition,getSelectedUpdate:()=>selectedUpdate,
|
||||
});
|
||||
|
||||
function commentSurface(selector) {
|
||||
if (selector === '#search-preview-comments') return {
|
||||
context:{kind:searchPreviewDetail.kind,item:searchPreviewDetail}, pager:searchPreview.commentPager(),
|
||||
render:state=>showSearchConversationWithActions(state), status:qs('#search-preview-conversation-status'),
|
||||
};
|
||||
if (selector === '#issue-comments') return {
|
||||
context:{kind:'issue',item:selectedIssue}, pager:issueConversation,
|
||||
render:renderIssueConversation, status:qs('#issue-sheet-status'),
|
||||
@@ -4605,6 +4681,7 @@
|
||||
async function openPullSheet(item, trigger, offlineDetail = null) {
|
||||
if (!item) return;
|
||||
if (!await ensurePullWorkflow(trigger)) return;
|
||||
|
||||
pullDetailPosition.open(workDetailIdentity('pull', item));
|
||||
qs('#pull-review').inert = false;
|
||||
qs('#pull-ownership').inert = false;
|
||||
@@ -5520,6 +5597,7 @@
|
||||
activeFlushLogin = contextIdentityFresh ? String(snapshot.context.user?.login || '').trim() : '';
|
||||
if (activeFlushLogin) {
|
||||
confirmedOwnerLogin = activeFlushLogin;
|
||||
void refreshPhotoDraftInbox();
|
||||
timerView.restore(todaySync.flush());
|
||||
restoreReleaseReceipt();
|
||||
updateDeliveryReceiptControls();
|
||||
@@ -5531,6 +5609,9 @@
|
||||
const retainedPlanningLogin = !snapshot.context.error ?
|
||||
String(snapshot.context.user?.login || '').trim() : '';
|
||||
planningOwnerLogin = retainedPlanningLogin;
|
||||
planningOwnerAccountKey = retainedPlanningLogin && snapshot.context.user?.id ?
|
||||
String(snapshot.context.user.id) + ':' + retainedPlanningLogin : '';
|
||||
timerView.render();
|
||||
updatePlanningAvailability();
|
||||
if (planningOwnerLogin) {
|
||||
syncPendingTomorrow();
|
||||
@@ -5662,8 +5743,14 @@
|
||||
commandSearch.setScope(scope);
|
||||
}
|
||||
let searchPreviewDetail = null;
|
||||
const renderSearchConversation = conversation =>
|
||||
renderSearchPreviewConversation(conversation, document, escapeHtml, fmt, renderMarkdown);
|
||||
const showSearchConversationWithActions = createSearchPreviewConversationActions({
|
||||
hydrator:actionHydrator, rootNode:qs('#search-preview-comments'),
|
||||
retry:qs('#retry-search-preview-comment-actions'),
|
||||
paint:(conversation,controller)=>renderSearchPreviewConversation(
|
||||
conversation,document,escapeHtml,fmt,renderMarkdown,controller),
|
||||
wire:controller=>wireCommentActions('#search-preview-comments',controller),
|
||||
});
|
||||
const renderSearchConversation = conversation => { void showSearchConversationWithActions(conversation); };
|
||||
function renderSearchPreview(state) {
|
||||
followingQueue.preview(state);
|
||||
const sheet = qs('#search-preview');
|
||||
@@ -5745,11 +5832,7 @@
|
||||
planButton.hidden = !searchWeekPlan.eligible(detail);
|
||||
planButton.textContent = detail.assigned_to_me ? 'Plan ahead' : 'Assign & plan ahead';
|
||||
planButton.disabled = searchWeekPlan.pending();
|
||||
startButton.hidden = !(detail.reviewable || (detail.kind === 'issue' &&
|
||||
(detail.reopenable || (detail.state === 'open' && (detail.claimable || detail.assigned_to_me)))));
|
||||
startButton.textContent = detail.reviewable ? 'Review now' : detail.reopenable ? 'Reopen & resume' :
|
||||
(detail.assigned_to_me ? 'Start in Today' : 'Assign & start');
|
||||
startButton.disabled = state.status === 'claiming' || state.status === 'reopening';
|
||||
renderSearchPreviewStart(detail, state, startButton);
|
||||
renderSearchPreviewWatch(detail, state, watchButton);
|
||||
followingQueue.preview(state);
|
||||
const shareStatus = {
|
||||
@@ -5771,9 +5854,7 @@
|
||||
fetchJson:searchSubscription.preview,
|
||||
fetchConversation:(item,page)=>fetchReviewJson(searchPreviewConversationPath(item,page)),
|
||||
fetchReview:searchSubscription.review,
|
||||
mutate:(detail,action)=>fetchReviewJson(
|
||||
searchPreviewPath(detail).replace(/\?.*$/, '') + '/' + action, {method:'PATCH'}
|
||||
),
|
||||
mutate:searchPreviewMutation(fetchReviewJson),
|
||||
watch:(detail,watching) => searchSubscription.watch(detail, watching).then(result =>
|
||||
followingQueue.load().catch(() => {}).then(() => result)),
|
||||
...searchPreviewReplyOptions(fetchReviewJson, localStorage, globalThis.crypto),
|
||||
@@ -5867,6 +5948,14 @@
|
||||
}
|
||||
const searchAssignAndStart = createSearchStart(detail => searchPreview.claim(detail));
|
||||
const searchReopenAndStart = createSearchStart(detail => searchPreview.reopen(detail));
|
||||
const recoverSearchPull = createSearchAuthoredPullRecovery({
|
||||
confirm,
|
||||
reopen:detail => searchPreview.reopenPull(detail),
|
||||
refresh:load,
|
||||
find:detail => lastMyWork.find(item => item.key === detail.repository + '#' + detail.number),
|
||||
open:item => openRoutedWork(item, qs('#start-search-result')),
|
||||
unavailable:message => qs('#search-preview-status').textContent = message,
|
||||
});
|
||||
const mobileSearchViewport = createMobileSearchViewport({
|
||||
palette: qs('#cmd-palette'),
|
||||
results: qs('#cmd-results'),
|
||||
@@ -5874,6 +5963,7 @@
|
||||
mediaQuery: window.matchMedia('(max-width: 600px)'),
|
||||
schedule: callback => requestAnimationFrame(callback),
|
||||
});
|
||||
const searchModal = createMobileSearchModal({document});
|
||||
function closeSearchPreview(navigate = true) {
|
||||
if (searchPreviewReturnKind === 'following') {
|
||||
searchPreview.close();
|
||||
@@ -5889,7 +5979,7 @@
|
||||
qs('#cmd-palette').classList.add('open');
|
||||
qs('#cmd-input').setAttribute('aria-expanded', 'true');
|
||||
renderCommands(qs('#cmd-input').value);
|
||||
qs('#cmd-input').focus();
|
||||
searchModal.transition(qs('#cmd-palette'), { initialFocus:qs('#cmd-input') });
|
||||
}
|
||||
const next = searchPreview.next;
|
||||
async function openPreviewWorkInMyWork(detail) {
|
||||
@@ -5911,6 +6001,7 @@
|
||||
mobileSearchViewport.rememberScroll();
|
||||
searchPreviewReturnKind = 'search';
|
||||
searchPreview.open(item.result).catch(() => {});
|
||||
searchModal.transition(qs('#search-preview'), { initialFocus:qs('#close-search-preview') });
|
||||
taskOverlayHistory.open('search-preview', {
|
||||
query:qs('#cmd-input').value, scope:currentSearchScope(), preview:item.result,
|
||||
});
|
||||
@@ -5957,7 +6048,10 @@
|
||||
mobileSearchViewport.open();
|
||||
mobileSearchViewport.restoreScroll();
|
||||
qs('#cmd-input').setAttribute('aria-expanded', 'true');
|
||||
qs('#cmd-input').focus();
|
||||
searchModal.activate(qs('#cmd-palette'), {
|
||||
opener:document.activeElement,
|
||||
initialFocus:qs('#cmd-input'),
|
||||
});
|
||||
commandSelection = -1;
|
||||
renderCommands(qs('#cmd-input').value);
|
||||
}
|
||||
@@ -5976,6 +6070,7 @@
|
||||
else {
|
||||
searchPreview.close();
|
||||
mobileSearchViewport.close();
|
||||
searchModal.deactivate();
|
||||
}
|
||||
searchPreviewReturnKind = null;
|
||||
}
|
||||
@@ -5983,7 +6078,7 @@
|
||||
qs('#cmd-palette').classList.remove('open');
|
||||
qs('#cmd-input').setAttribute('aria-expanded', 'false');
|
||||
mobileSearchViewport.close();
|
||||
qs('#open-palette').focus();
|
||||
searchModal.deactivate();
|
||||
}
|
||||
if (previous === 'plan-today-preview' && kind !== 'plan-today-preview') {
|
||||
if (addPlanPreviewOnReturn && addPlanPreviewOverride) planTodayPreview.close({ add:true, override:true });
|
||||
@@ -6011,6 +6106,10 @@
|
||||
if (detail?.scope) applySearchScope(detail.scope);
|
||||
if (detail?.query !== undefined) qs('#cmd-input').value = detail.query;
|
||||
searchPreviewReturnKind = 'search';
|
||||
searchModal.activate(qs('#search-preview'), {
|
||||
opener:document.activeElement,
|
||||
initialFocus:qs('#close-search-preview'),
|
||||
});
|
||||
searchPreview.open(detail.preview).catch(() => taskOverlayHistory.close());
|
||||
}
|
||||
if (kind === 'plan-today' && previous !== 'plan-today' && previous !== 'plan-today-preview') openPlanToday(planTodayTrigger, false);
|
||||
@@ -6215,6 +6314,14 @@
|
||||
});
|
||||
qs('#start-search-result').addEventListener('click', async () => {
|
||||
const detail = searchPreviewDetail;
|
||||
if (detail?.authored_pull_reopenable) {
|
||||
try {
|
||||
await recoverSearchPull(detail);
|
||||
} catch (error) {
|
||||
qs('#search-preview-status').textContent = error.message + ' Retry.';
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (detail?.reviewable) {
|
||||
taskOverlayHistory.leave();
|
||||
detail.kind = 'review';
|
||||
@@ -6406,6 +6513,12 @@
|
||||
if (selector === '#create-issue-title') scheduleIssueDuplicateCheck();
|
||||
})
|
||||
);
|
||||
if (progressiveCaptureHandoff?.open && await ensureIssueCapture()) {
|
||||
issueCapture.saveDraft({repository:'', labelIds:[],
|
||||
title:progressiveCaptureHandoff.title, body:progressiveCaptureHandoff.body});
|
||||
progressiveCaptureHandoff.complete?.();
|
||||
await openCreateIssueSheet(false);
|
||||
}
|
||||
qs('#create-issue-repository').addEventListener('change', event => {
|
||||
issueTemplatePicker.changeRepository(currentIssueCaptureDraft());
|
||||
issueOwnerPicker.reset(event.target.value);
|
||||
@@ -7357,7 +7470,7 @@
|
||||
qs('#pull-sheet-status').textContent = 'Merging pull request…';
|
||||
try {
|
||||
const mergeResult = await pullController.merge(selectedPull, selectedPullDetail.head_sha);
|
||||
releaseReceipt.capture(merging, mergeResult);
|
||||
rR.capture(merging, mergeResult);
|
||||
closePullSheet();
|
||||
lastMyWork = lastMyWork.filter(item =>
|
||||
!(item.kind === 'pull' && item.repository === merging.repository && item.number === merging.number)
|
||||
@@ -7816,6 +7929,8 @@
|
||||
confirmedOwnerLogin = String(saved.user?.login || '').trim();
|
||||
restoreReleaseReceipt();
|
||||
planningOwnerLogin = confirmedOwnerLogin;
|
||||
planningOwnerAccountKey = confirmedOwnerLogin && saved.user?.id ?
|
||||
String(saved.user.id) + ':' + confirmedOwnerLogin : '';
|
||||
interruptionPrompt.restore();
|
||||
updatePlanningAvailability();
|
||||
syncPendingTomorrow();
|
||||
@@ -8319,6 +8434,8 @@
|
||||
startDayHour:qs('#push-start-day-hour'),
|
||||
followingControl:qs('#push-following'),
|
||||
followingStatus:qs('#push-following-status'),
|
||||
humanGateControl:qs('#push-human-gates'),
|
||||
humanGateStatus:qs('#push-human-gates-status'),
|
||||
deadlineSnooze:qs('#deadline-snooze'),
|
||||
deadlineSnoozeStatus:qs('#deadline-snooze-status'),
|
||||
deadlineSnoozeReview:qs('#review-snoozed-deadlines'),
|
||||
@@ -8421,9 +8538,22 @@
|
||||
if (!deviceSetup) await (await ensureDeviceSetup()).open(event);
|
||||
});
|
||||
pushControllerReady.then(ensureDeviceSetup).catch(console.warn);
|
||||
await load();
|
||||
let adoptedProgressiveSnapshot = contextPoller.adopt(progressiveWorkHandoff?.liveSnapshot);
|
||||
if (!adoptedProgressiveSnapshot && progressiveWorkHandoff?.liveSnapshotPromise) {
|
||||
adoptedProgressiveSnapshot = await contextPoller.adoptPending(progressiveWorkHandoff.liveSnapshotPromise);
|
||||
}
|
||||
if (!adoptedProgressiveSnapshot) await load();
|
||||
if (progressiveWorkHandoff?.openWork) {
|
||||
const progressiveItem = lastMyWork.find(item =>
|
||||
item.repository === progressiveWorkHandoff.openWork.repository &&
|
||||
Number(item.number) === Number(progressiveWorkHandoff.openWork.number));
|
||||
if (progressiveItem) {
|
||||
openRoutedWork(progressiveItem, null);
|
||||
qs('#progressive-work-detail').hidden = true;
|
||||
}
|
||||
}
|
||||
|
||||
await appShortcut.run();
|
||||
contextPoller.start();
|
||||
document.addEventListener('visibilitychange', () => {
|
||||
contextPoller.setVisible(!document.hidden);
|
||||
if (!document.hidden) deviceSetup?.render();
|
||||
|
||||
@@ -0,0 +1,271 @@
|
||||
function createHumanGates(options = {}) {
|
||||
const storage = options.storage || window.localStorage;
|
||||
const getLogin = options.getLogin || (() => '');
|
||||
const getAccountKey = options.getAccountKey || getLogin;
|
||||
const isOnline = options.isOnline || (() => navigator.onLine);
|
||||
const location = options.location || window.location;
|
||||
const fetchJson = options.fetchJson;
|
||||
const nodes = options.nodes || {};
|
||||
let queue = { pending_count: 0, items: [] };
|
||||
let reviewSnapshot = [];
|
||||
let reviewIndex = -1;
|
||||
let loadedAccountKey = '';
|
||||
let loadEpoch = 0;
|
||||
const decisionKeys = new Map();
|
||||
let decisionFlight = null;
|
||||
let openFlight = null;
|
||||
let onChange = options.onChange;
|
||||
|
||||
const escape = value => String(value ?? '').replace(/[&<>"']/g, character => ({
|
||||
'&': '&', '<': '<', '>': '>', '"': '"', "'": ''',
|
||||
})[character]);
|
||||
const cacheKey = () => 'stackchain.human-gates.v1:' + String(getAccountKey() || '').trim().toLowerCase();
|
||||
const progressKey = item => 'stackchain.human-gate-review.v1:' +
|
||||
String(getAccountKey() || '').trim().toLowerCase() + ':' + item.id + ':' + item.revision;
|
||||
const setText = (node, value) => { if (node) node.textContent = value; };
|
||||
const setHtml = (node, value) => { if (node) node.innerHTML = value; };
|
||||
const publish = state => onChange?.(JSON.parse(JSON.stringify(queue)), state);
|
||||
|
||||
function validSnapshot(value) {
|
||||
return value && Number.isInteger(value.pending_count) && Array.isArray(value.items) ? value : null;
|
||||
}
|
||||
|
||||
function restore() {
|
||||
if (!getLogin()) return null;
|
||||
try { return validSnapshot(JSON.parse(storage.getItem(cacheKey()) || 'null')); } catch (_) { return null; }
|
||||
}
|
||||
|
||||
function save(value) {
|
||||
if (!getLogin()) return;
|
||||
try { storage.setItem(cacheKey(), JSON.stringify(value)); } catch (_) {}
|
||||
}
|
||||
|
||||
function restoreProgress(item) {
|
||||
if (!getLogin() || !item) return null;
|
||||
try {
|
||||
const value = JSON.parse(storage.getItem(progressKey(item)) || 'null');
|
||||
if (!value || value.gate_id !== item.id || value.revision !== item.revision) return null;
|
||||
return value;
|
||||
} catch (_) { return null; }
|
||||
}
|
||||
|
||||
function saveProgress(values = {}) {
|
||||
const item = current();
|
||||
if (!getLogin() || !item) return false;
|
||||
const checklist = values.checklist || {};
|
||||
const progress = {
|
||||
gate_id:item.id, revision:item.revision,
|
||||
checklist:Object.fromEntries(['exact_hash', 'artifacts_reviewed', 'provenance_reviewed'].map(key => [key, checklist[key] === true])),
|
||||
reason:String(values.reason || ''), override_reason:String(values.override_reason || ''),
|
||||
};
|
||||
try { storage.setItem(progressKey(item), JSON.stringify(progress)); return true; } catch (_) { return false; }
|
||||
}
|
||||
|
||||
function captureProgress() {
|
||||
if (!nodes.detail?.querySelectorAll) return false;
|
||||
const checklist = Object.fromEntries(Array.from(nodes.detail.querySelectorAll('[data-gate-checklist]')).map(input => [input.dataset.gateChecklist, input.checked]));
|
||||
return saveProgress({
|
||||
checklist,
|
||||
reason:nodes.detail.querySelector?.('[data-gate-reason]')?.value || '',
|
||||
override_reason:nodes.detail.querySelector?.('[data-gate-override]')?.value || '',
|
||||
});
|
||||
}
|
||||
|
||||
nodes.detail?.addEventListener?.('input', captureProgress);
|
||||
nodes.detail?.addEventListener?.('change', captureProgress);
|
||||
|
||||
function render() {
|
||||
setText(nodes.count, String(queue.pending_count));
|
||||
if (!queue.pending_count) {
|
||||
setHtml(nodes.list, '<div class="human-gates-zero"><strong>Inbox zero</strong><span>No release candidates need your decision.</span></div>');
|
||||
setText(nodes.status, 'Human Gates inbox zero.');
|
||||
return;
|
||||
}
|
||||
setText(nodes.status, queue.pending_count + (queue.pending_count === 1 ? ' gate pending.' : ' gates pending.'));
|
||||
setHtml(nodes.list, queue.items.map(item =>
|
||||
'<button class="human-gate-card" type="button" data-human-gate-id="' + escape(item.id) + '">' +
|
||||
'<strong>' + escape(item.title) + '</strong><code>' + escape(item.candidate_hash) + '</code>' +
|
||||
'<span>Priority ' + escape(item.priority ?? 0) + '</span></button>'
|
||||
).join(''));
|
||||
}
|
||||
|
||||
function renderDetail(item) {
|
||||
if (!item) {
|
||||
setHtml(nodes.detail, '<div class="human-gates-zero"><strong>Inbox zero</strong><span>Fixed review snapshot complete.</span></div>');
|
||||
return;
|
||||
}
|
||||
const progress = restoreProgress(item) || {checklist:{}, reason:'', override_reason:''};
|
||||
const checked = key => progress.checklist?.[key] === true ? ' checked' : '';
|
||||
const checks = (item.checks || []).map(check =>
|
||||
'<li class="gate-check gate-check-' + escape(check.state) + '"><strong>' + escape(check.name) + '</strong> · ' + escape(check.state) + (check.required ? ' · required' : '') + '</li>'
|
||||
).join('');
|
||||
const artifacts = (item.artifacts || []).map(artifact => '<li><a href="' + escape(artifact.url) + '" target="_blank" rel="noreferrer noopener">' + escape(artifact.name) + '</a></li>').join('');
|
||||
const links = (item.links || []).map(link => '<li><a href="' + escape(link.url) + '" target="_blank" rel="noreferrer noopener">' + escape(link.label) + '</a></li>').join('');
|
||||
const provenance = Object.entries(item.provenance || {}).map(([key, value]) => '<li><strong>' + escape(key) + '</strong> · ' + escape(value) + '</li>').join('');
|
||||
const history = (item.history || []).map(event => '<li><strong>' + escape(event.action) + '</strong> · ' + escape(event.at) + '</li>').join('');
|
||||
setHtml(nodes.detail,
|
||||
'<article class="human-gate-detail"><h3>' + escape(item.title) + '</h3>' +
|
||||
'<p>Project <strong>' + escape(item.project) + '</strong></p>' +
|
||||
'<p>Exact candidate <code>' + escape(item.candidate_hash) + '</code></p>' +
|
||||
'<p>Score ' + escape(item.score?.value ?? 'not supplied') + ' · ' + escape(item.score?.provenance || '') + '</p>' +
|
||||
'<h4>Artifacts</h4><ul>' + artifacts + '</ul><h4>Links</h4><ul>' + links + '</ul>' +
|
||||
'<h4>Checks</h4><ul>' + checks + '</ul><h4>Provenance</h4><ul>' + provenance + '</ul>' +
|
||||
'<h4>History</h4><ul>' + history + '</ul>' +
|
||||
'<label><input type="checkbox" data-gate-checklist="exact_hash"' + checked('exact_hash') + '> Exact hash reviewed</label>' +
|
||||
'<label><input type="checkbox" data-gate-checklist="artifacts_reviewed"' + checked('artifacts_reviewed') + '> Artifacts reviewed</label>' +
|
||||
'<label><input type="checkbox" data-gate-checklist="provenance_reviewed"' + checked('provenance_reviewed') + '> Provenance reviewed</label>' +
|
||||
'<label>Hold reason<textarea data-gate-reason>' + escape(progress.reason) + '</textarea></label>' +
|
||||
'<label>Override reason<textarea data-gate-override>' + escape(progress.override_reason) + '</textarea></label>' +
|
||||
'<div><button type="button" data-gate-decision="release">Release & next</button>' +
|
||||
'<button type="button" data-gate-decision="hold">Hold & next</button></div></article>'
|
||||
);
|
||||
}
|
||||
|
||||
async function load() {
|
||||
const epoch = ++loadEpoch;
|
||||
const accountKey = String(getAccountKey() || '').trim().toLowerCase();
|
||||
if (accountKey !== loadedAccountKey) {
|
||||
loadedAccountKey = accountKey;
|
||||
queue = { pending_count: 0, items: [] };
|
||||
reviewSnapshot = [];
|
||||
reviewIndex = -1;
|
||||
render();
|
||||
}
|
||||
const cached = restore();
|
||||
if (cached) {
|
||||
queue = cached;
|
||||
render();
|
||||
publish({available:true, authoritative:false, cached:true});
|
||||
}
|
||||
try {
|
||||
const live = validSnapshot(await fetchJson('api/v1/human-gates'));
|
||||
if (epoch !== loadEpoch || accountKey !== loadedAccountKey) return queue;
|
||||
if (!live) throw new Error('Human Gates response is invalid.');
|
||||
queue = { pending_count: live.pending_count, items: live.items.slice() };
|
||||
save(queue);
|
||||
render();
|
||||
publish({available:true, authoritative:true});
|
||||
return queue;
|
||||
} catch (error) {
|
||||
if (epoch !== loadEpoch || accountKey !== loadedAccountKey) return queue;
|
||||
if (!cached) {
|
||||
publish({available:false, authoritative:false});
|
||||
throw error;
|
||||
}
|
||||
setText(nodes.status, 'Offline cached gate list · reconnect before deciding.');
|
||||
return queue;
|
||||
}
|
||||
}
|
||||
|
||||
function reviewNext() {
|
||||
if (reviewIndex < 0) {
|
||||
reviewSnapshot = queue.items.slice();
|
||||
reviewIndex = 0;
|
||||
}
|
||||
const item = reviewSnapshot[reviewIndex] || null;
|
||||
renderDetail(item);
|
||||
if (item) {
|
||||
const index = reviewIndex;
|
||||
fetchJson('api/v1/human-gates/' + encodeURIComponent(item.id)).then(detail => {
|
||||
if (!detail || detail.id !== item.id) throw new Error('Gate detail is invalid.');
|
||||
if (reviewIndex !== index || reviewSnapshot[index]?.id !== item.id) return;
|
||||
reviewSnapshot[index] = detail;
|
||||
renderDetail(detail);
|
||||
}).catch(() => { setText(nodes.status, 'Gate detail is unavailable. Retry while online.'); });
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
function select(gateId) {
|
||||
if (reviewIndex < 0) reviewSnapshot = queue.items.slice();
|
||||
const index = reviewSnapshot.findIndex(item => item.id === gateId);
|
||||
if (index < 0) throw new Error('Gate is not in the current review snapshot.');
|
||||
reviewIndex = index;
|
||||
return reviewNext();
|
||||
}
|
||||
|
||||
function current() { return reviewIndex < 0 ? null : (reviewSnapshot[reviewIndex] || null); }
|
||||
function idempotencyKey(item, decision, payload) {
|
||||
const operation = item.id + ':' + item.revision + ':' + decision + ':' + JSON.stringify(payload);
|
||||
if (decisionKeys.has(operation)) return { operation, key: decisionKeys.get(operation) };
|
||||
const nonce = globalThis.crypto?.randomUUID?.() || (Date.now().toString(36) + '-' + Math.random().toString(36).slice(2));
|
||||
const key = 'human-gate:' + item.id + ':' + item.revision + ':' + decision + ':' + nonce;
|
||||
decisionKeys.set(operation, key);
|
||||
return { operation, key };
|
||||
}
|
||||
|
||||
async function decideAndNext(decision, values = {}) {
|
||||
const item = current();
|
||||
if (!item) throw new Error('No gate is selected.');
|
||||
if (!isOnline()) throw new Error('Human Gate decisions require an online connection.');
|
||||
if (!String(getLogin() || '').trim()) throw new Error('Authenticated account identity is required.');
|
||||
const checklist = values.checklist || {};
|
||||
const complete = ['exact_hash', 'artifacts_reviewed', 'provenance_reviewed'].every(key => checklist[key] === true);
|
||||
if (decision === 'release' && !complete) throw new Error('Complete the release checklist before deciding.');
|
||||
const unmet = (item.checks || []).filter(check => check.required && check.state !== 'success');
|
||||
if (decision === 'release' && unmet.length && !String(values.override_reason || '').trim()) {
|
||||
throw new Error('An explicit override reason is required for unmet required checks.');
|
||||
}
|
||||
if (decision === 'hold' && !String(values.reason || '').trim()) throw new Error('A hold reason is required.');
|
||||
const payload = {
|
||||
expected_revision: item.revision, decision,
|
||||
reason: String(values.reason || '').trim(),
|
||||
override_reason: String(values.override_reason || '').trim(), checklist,
|
||||
};
|
||||
if (decisionFlight) return decisionFlight;
|
||||
const operation = (async () => {
|
||||
const decisionKey = idempotencyKey(item, decision, payload);
|
||||
const receipt = await fetchJson('api/v1/human-gates/' + encodeURIComponent(item.id) + '/decision', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', 'Idempotency-Key': decisionKey.key },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
decisionKeys.delete(decisionKey.operation);
|
||||
try { storage.removeItem?.(progressKey(item)); } catch (_) {}
|
||||
queue.items = queue.items.filter(candidate => candidate.id !== item.id);
|
||||
queue.pending_count = Math.max(0, queue.pending_count - 1);
|
||||
save(queue); render();
|
||||
publish({available:true, authoritative:true, decision:true});
|
||||
reviewIndex += 1;
|
||||
const next = current();
|
||||
if (next) reviewNext(); else renderDetail(null);
|
||||
setText(nodes.status, next ? (decision === 'release' ? 'Released. Reviewing next gate.' : 'Held. Reviewing next gate.') : 'Decision saved. Human Gates review snapshot complete.');
|
||||
return { receipt, next };
|
||||
})();
|
||||
decisionFlight = operation;
|
||||
try {
|
||||
return await operation;
|
||||
} finally {
|
||||
if (decisionFlight === operation) decisionFlight = null;
|
||||
}
|
||||
}
|
||||
|
||||
function open() {
|
||||
location.hash = '#/my-work/human-gates';
|
||||
if (nodes.panel) nodes.panel.hidden = false;
|
||||
if (openFlight) return openFlight;
|
||||
const operation = (async () => {
|
||||
await load();
|
||||
reviewSnapshot = queue.items.slice();
|
||||
reviewIndex = 0;
|
||||
return reviewNext();
|
||||
})();
|
||||
openFlight = operation;
|
||||
const clearFlight = () => {
|
||||
if (openFlight === operation) openFlight = null;
|
||||
};
|
||||
operation.then(clearFlight, clearFlight);
|
||||
return operation;
|
||||
}
|
||||
|
||||
return {
|
||||
load, open, reviewNext, select, decideAndNext, current, saveProgress,
|
||||
setOnChange(callback) { onChange = callback; },
|
||||
restoreCached: restore,
|
||||
snapshot: () => JSON.parse(JSON.stringify(queue)),
|
||||
route: () => location.hash,
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof module !== 'undefined') module.exports = createHumanGates;
|
||||
if (typeof window !== 'undefined') window.createHumanGates = createHumanGates;
|
||||
+171
-17
@@ -187,7 +187,16 @@
|
||||
<button class="end-today-session" id="end-today-session" type="button" hidden>End session</button>
|
||||
<button class="find-work-action" id="find-work" type="button">Find work</button>
|
||||
<button class="new-issue" id="new-issue" type="button">New issue</button>
|
||||
<button class="human-gates-launcher" id="open-human-gates" type="button">Review next <span id="human-gates-count">0</span></button>
|
||||
</div>
|
||||
<section id="human-gates" class="human-gates" aria-labelledby="human-gates-heading" hidden>
|
||||
<div class="human-gates-header">
|
||||
<div><h3 id="human-gates-heading">Human Gates</h3><p id="human-gates-status" class="small" role="status" aria-live="polite"></p></div>
|
||||
<button id="close-human-gates" type="button">Close</button>
|
||||
</div>
|
||||
<div id="human-gates-list" class="human-gates-list"></div>
|
||||
<div id="human-gate-detail" class="human-gate-detail-host"></div>
|
||||
</section>
|
||||
<details class="work-settings">
|
||||
<summary id="work-settings-toggle">Queue & settings · <span id="active-work-queue">All</span></summary>
|
||||
<div class="work-settings-panel">
|
||||
@@ -224,6 +233,14 @@
|
||||
<button class="secondary" id="push-test" type="button" hidden>Send test notification</button>
|
||||
<label class="push-update-control" for="push-following"><input id="push-following" type="checkbox" /> Notify me when Following changes</label>
|
||||
<span class="small" id="push-following-status" role="status" aria-live="polite"></span>
|
||||
<label class="push-update-control" for="push-human-gates"><input id="push-human-gates" type="checkbox" /> Notify me when release decisions are waiting</label>
|
||||
<span class="small" id="push-human-gates-status" role="status" aria-live="polite"></span>
|
||||
<label class="push-update-control" for="push-quiet-hours"><input id="push-quiet-hours" type="checkbox" /> Pause routine alerts on a schedule</label>
|
||||
<div class="push-quiet-hours-times">
|
||||
<label for="push-quiet-start">From <input id="push-quiet-start" type="time" value="22:00" /></label>
|
||||
<label for="push-quiet-end">Until <input id="push-quiet-end" type="time" value="07:00" /></label>
|
||||
</div>
|
||||
<span class="small" id="push-quiet-status" role="status" aria-live="polite"></span>
|
||||
<label class="push-update-control" for="push-deadlines"><input id="push-deadlines" type="checkbox" /> Notify me about deadlines</label>
|
||||
<label for="push-deadline-hour">Reminder hour <select id="push-deadline-hour" aria-label="Deadline reminder local hour"></select></label>
|
||||
<label for="push-deadline-days">Warn me <select id="push-deadline-days" aria-label="Deadline reminder horizon"><option value="0">Due today</option><option value="2" selected>Next 2 days</option><option value="7">Next 7 days</option></select></label>
|
||||
@@ -369,6 +386,19 @@
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section class="progressive-work-detail" id="progressive-work-detail" role="dialog" aria-modal="true" aria-labelledby="progressive-work-detail-title" hidden>
|
||||
<div class="progressive-work-detail-panel">
|
||||
<header>
|
||||
<div><p class="small muted">My Work</p><h2 id="progressive-work-detail-title">Work item</h2></div>
|
||||
<button id="close-progressive-work-detail" type="button">Close</button>
|
||||
</header>
|
||||
<p class="small" id="progressive-work-detail-meta"></p>
|
||||
<p id="progressive-work-detail-reason"></p>
|
||||
<p class="muted">The full workspace is still loading. You can read this assignment now or open it in Gitea.</p>
|
||||
<a class="button-link" id="open-progressive-work-gitea" href="" hidden>Open in Gitea</a>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<dialog class="release-receipt-sheet" id="release-receipt-sheet" aria-labelledby="release-receipt-title">
|
||||
<section class="release-receipt-panel">
|
||||
<header><div><p class="small muted">Exact merge evidence</p><h2 id="release-receipt-title">Release watchlist</h2></div><button id="close-release-receipt" type="button">Close</button></header>
|
||||
@@ -780,7 +810,7 @@
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<div id="cmd-palette" role="dialog" aria-label="Command palette">
|
||||
<div id="cmd-palette" role="dialog" aria-modal="true" aria-label="Command palette">
|
||||
<div class="cmd-palette-header">
|
||||
<strong>Search work</strong>
|
||||
<div class="cmd-palette-header-actions">
|
||||
@@ -901,6 +931,7 @@
|
||||
<div id="search-preview-comments"></div>
|
||||
<div id="search-preview-conversation-status" class="small" aria-live="polite"></div>
|
||||
<button id="retry-search-preview-conversation" type="button" hidden>Retry conversation</button>
|
||||
<button class="conversation-actions-retry" id="retry-search-preview-comment-actions" type="button" hidden>Retry comment tools</button>
|
||||
<button id="load-older-search-preview-comments" type="button" hidden>Load older messages</button>
|
||||
</section>
|
||||
<section id="search-preview-review" class="search-preview-review" aria-labelledby="search-preview-review-title" hidden>
|
||||
@@ -1281,6 +1312,7 @@
|
||||
<section class="create-issue-panel">
|
||||
<div class="create-issue-header">
|
||||
<h3 id="create-issue-heading">Capture work</h3>
|
||||
<button id="switch-to-create-pull" type="button">Pull request</button>
|
||||
<button id="cancel-new-issue" type="button">Cancel</button>
|
||||
</div>
|
||||
<aside class="today-capture-interruption" id="today-capture-interruption" role="status" hidden>
|
||||
@@ -1722,6 +1754,11 @@
|
||||
<div id="pull-review-status" class="small" aria-live="polite">Expand to load changed files and merge readiness.</div>
|
||||
<button class="pull-retry" id="pull-review-retry" type="button" hidden>Retry review data</button>
|
||||
<div class="row"><span class="pill" id="pull-ci-state">CI unknown</span><span class="pill" id="pull-merge-state">Review data not loaded</span></div>
|
||||
<section class="pull-branch-update" id="pull-branch-update" aria-labelledby="pull-branch-update-heading" hidden>
|
||||
<h3 id="pull-branch-update-heading">Bring branch up to date</h3>
|
||||
<p class="small" id="pull-branch-update-status" role="status" aria-live="assertive"></p>
|
||||
<button id="update-pull-branch" type="button">Update branch</button>
|
||||
</section>
|
||||
<section class="pull-reviewer-summary" aria-labelledby="pull-reviewer-heading">
|
||||
<h3 id="pull-reviewer-heading">Reviewer status</h3>
|
||||
<div id="pull-reviewer-status" class="small" aria-live="polite">Reviewer status not loaded.</div>
|
||||
@@ -1735,6 +1772,46 @@
|
||||
<p class="small" id="pull-feedback-location"></p>
|
||||
<p id="pull-feedback-body"></p>
|
||||
<div class="small" id="pull-feedback-context" aria-live="polite"></div>
|
||||
<div class="pull-feedback-code-actions">
|
||||
<button id="review-pull-feedback-suggestion" type="button" hidden>Review suggested change</button>
|
||||
<button id="make-pull-feedback-fix" type="button" hidden>Edit full file</button>
|
||||
</div>
|
||||
<section class="pull-feedback-suggestion-preview" id="pull-feedback-suggestion-preview" aria-labelledby="pull-feedback-suggestion-heading" hidden>
|
||||
<h5 id="pull-feedback-suggestion-heading">Suggested change</h5>
|
||||
<div class="pull-feedback-suggestion-change">
|
||||
<div><span class="small">Current line</span><pre id="pull-feedback-suggestion-before"></pre></div>
|
||||
<div><span class="small">Suggested replacement</span><pre id="pull-feedback-suggestion-after"></pre></div>
|
||||
</div>
|
||||
<label for="pull-feedback-suggestion-message">Commit message</label>
|
||||
<input id="pull-feedback-suggestion-message" maxlength="120" value="fix: apply review suggestion">
|
||||
<div class="pull-feedback-file-actions">
|
||||
<button id="cancel-pull-feedback-suggestion" type="button" hidden>Cancel suggestion</button>
|
||||
<button id="stage-pull-feedback-suggestion" type="button" hidden>Add to fix batch</button>
|
||||
<button id="apply-pull-feedback-suggestion" type="button" hidden>Commit suggested change</button>
|
||||
</div>
|
||||
</section>
|
||||
<section class="pull-feedback-batch-review" id="pull-feedback-batch-review" aria-labelledby="pull-feedback-batch-heading" hidden>
|
||||
<h5 id="pull-feedback-batch-heading">Review fixes</h5>
|
||||
<ul id="pull-feedback-batch-items"></ul>
|
||||
<label for="pull-feedback-batch-message">Commit message</label>
|
||||
<input id="pull-feedback-batch-message" maxlength="120" value="fix: apply review suggestions">
|
||||
<div class="pull-feedback-file-actions">
|
||||
<button id="cancel-pull-feedback-batch" type="button" hidden>Keep reviewing</button>
|
||||
<button id="commit-pull-feedback-batch" type="button" hidden>Commit all fixes</button>
|
||||
</div>
|
||||
</section>
|
||||
<button id="review-pull-feedback-batch" type="button" hidden>Review fixes (0)</button>
|
||||
<section class="pull-feedback-file-editor" id="pull-feedback-file-editor" hidden>
|
||||
<h5>Edit <span id="pull-feedback-file-path"></span></h5>
|
||||
<label for="pull-feedback-file-content">File content</label>
|
||||
<textarea id="pull-feedback-file-content" spellcheck="false" maxlength="131072"></textarea>
|
||||
<label for="pull-feedback-commit-message">Commit message</label>
|
||||
<input id="pull-feedback-commit-message" maxlength="120" placeholder="fix: address review feedback">
|
||||
<div class="pull-feedback-file-actions">
|
||||
<button id="cancel-pull-feedback-fix" type="button" hidden>Cancel change</button>
|
||||
<button id="commit-pull-feedback-fix" type="button" hidden>Commit to pull branch</button>
|
||||
</div>
|
||||
</section>
|
||||
<fieldset class="pull-feedback-dispositions">
|
||||
<legend>Disposition</legend>
|
||||
<button type="button" data-feedback-disposition="addressed">Addressed</button>
|
||||
@@ -1756,6 +1833,15 @@
|
||||
<summary><span>Checks</span><span class="small" id="pull-checks-summary">Not loaded</span></summary>
|
||||
<button class="ci-check-refresh" id="refresh-pull-checks" type="button">Refresh checks</button>
|
||||
<div class="ci-check-list" id="pull-check-list"></div>
|
||||
<section class="ci-check-recovery" id="pull-check-recovery" aria-labelledby="pull-check-recovery-title" hidden>
|
||||
<h3 id="pull-check-recovery-title" tabindex="-1">Failed check</h3>
|
||||
<div id="pull-check-recovery-status" class="small" role="status" aria-live="assertive"></div>
|
||||
<pre class="ci-check-log" id="pull-check-log" tabindex="0"></pre>
|
||||
<div class="ci-check-recovery-actions">
|
||||
<button id="retry-pull-check" type="button" disabled>Retry failed job</button>
|
||||
<button id="close-pull-check-recovery" type="button">Close details</button>
|
||||
</div>
|
||||
</section>
|
||||
</details>
|
||||
<div class="pull-review-tools"><span id="pull-review-progress" class="small" aria-live="polite">Review progress unavailable.</span><button id="next-unreviewed-pull-file" type="button" disabled>Next unreviewed</button></div>
|
||||
<div id="pull-files"></div>
|
||||
@@ -1783,6 +1869,20 @@
|
||||
<div id="pull-handoff-status" class="small" aria-live="assertive">Load teammates to transfer ownership.</div>
|
||||
</div>
|
||||
</details>
|
||||
<details class="pull-lifecycle" id="pull-lifecycle" hidden>
|
||||
<summary>Close pull request</summary>
|
||||
<div>
|
||||
<p class="small">Close an obsolete pull request without deleting its branch or discussion.</p>
|
||||
<button id="close-authored-pull" type="button" hidden>Close pull request</button>
|
||||
<div id="pull-lifecycle-status" class="small" role="status" aria-live="assertive"></div>
|
||||
</div>
|
||||
</details>
|
||||
<section class="pull-close-receipt" id="pull-close-receipt" aria-labelledby="pull-close-receipt-title" hidden>
|
||||
<h3 id="pull-close-receipt-title" tabindex="-1">Pull request closed.</h3>
|
||||
<p class="small">This pull request was removed from active work. Reopen it if the close was accidental.</p>
|
||||
<button id="reopen-authored-pull" type="button">Reopen pull request</button>
|
||||
<div id="pull-reopen-status" class="small" role="status" aria-live="assertive"></div>
|
||||
</section>
|
||||
<div class="pull-sheet-actions">
|
||||
<button class="share-work-route" type="button">Share</button>
|
||||
<button id="watch-pull-detail" type="button">Watch pull request</button>
|
||||
@@ -2076,22 +2176,39 @@
|
||||
<button class="mobile-start-day-action" id="mobile-start-day-action" type="button">Prepare Today</button>
|
||||
<button class="mobile-start-day-finish" id="finish-mobile-start-day" type="button" hidden>Finish for now</button>
|
||||
</section>
|
||||
<div class="mobile-queue-list">
|
||||
<button data-mobile-queue="today" type="button"><span><strong>Today</strong><small>Planned work</small></span><span data-mobile-queue-count="today">0</span></button>
|
||||
<button data-mobile-queue="tomorrow" type="button"><span><strong>Tomorrow</strong><small id="mobile-tomorrow-summary" aria-live="polite">Nothing planned</small></span></button>
|
||||
<button data-mobile-queue="week" type="button"><span><strong>Week Ahead</strong><small id="mobile-week-summary" aria-live="polite">Nothing planned</small></span></button>
|
||||
<button data-mobile-queue="agenda" type="button"><span><strong>Agenda</strong><small>Upcoming deadlines</small></span><span data-mobile-queue-count="agenda">0</span></button>
|
||||
<button data-mobile-queue="delivery" type="button"><span><strong>Delivery</strong><small>Needs recovery</small></span><span data-mobile-queue-count="delivery">0</span></button>
|
||||
<button data-mobile-queue="attention" type="button"><span><strong>Attention</strong><small>Needs a response</small></span><span data-mobile-queue-count="attention">0</span></button>
|
||||
<button data-mobile-queue="update" type="button" aria-label="Updates, 0 unread conversations"><span><strong>Updates</strong><small>Unread conversations</small></span><span data-mobile-queue-count="update">0</span></button>
|
||||
<button data-mobile-queue="following" type="button" aria-label="Following, 0 unseen changes"><span><strong>Following</strong><small>Issues and pull requests you watch</small></span><span data-mobile-queue-count="following">0</span></button>
|
||||
<button data-mobile-queue="filed" type="button"><span><strong>Filed</strong><small>Issues you delegated</small></span><span data-mobile-queue-count="filed">0</span></button>
|
||||
<button data-mobile-queue="authored" type="button"><span><strong>My PRs</strong><small>Pull requests you authored</small></span><span data-mobile-queue-count="authored">0</span></button>
|
||||
<button data-mobile-queue="later" type="button"><span><strong>Later</strong><small>Deferred work</small></span><span data-mobile-queue-count="later">0</span></button>
|
||||
<button data-mobile-queue="draft" type="button"><span><strong>Drafts</strong><small>Unfiled captures</small></span><span data-mobile-queue-count="draft">0</span></button>
|
||||
<button data-mobile-queue="find" type="button"><span><strong>Find Work</strong><small>Claim something new</small></span></button>
|
||||
<button data-mobile-queue="recaps" type="button"><span><strong>Recaps</strong><small>History</small></span></button>
|
||||
</div>
|
||||
<section class="mobile-queue-next" aria-labelledby="mobile-queue-next-heading">
|
||||
<p class="small muted" id="mobile-queue-next-heading">Next up</p>
|
||||
<button id="mobile-queue-next-action" type="button">Find Work</button>
|
||||
</section>
|
||||
<section class="mobile-queue-group" aria-labelledby="mobile-queue-active-heading" hidden>
|
||||
<h3 id="mobile-queue-active-heading">Active now</h3>
|
||||
<div class="mobile-queue-list" id="mobile-queue-active-list"></div>
|
||||
</section>
|
||||
<section class="mobile-queue-group" aria-labelledby="mobile-queue-planning-heading">
|
||||
<h3 id="mobile-queue-planning-heading">Plan & organize</h3>
|
||||
<div class="mobile-queue-list" id="mobile-queue-planning-list">
|
||||
<button data-mobile-queue="today" type="button"><span><strong>Today</strong><small>Planned work</small></span><span data-mobile-queue-count="today">0</span></button>
|
||||
<button data-mobile-queue="tomorrow" type="button"><span><strong>Tomorrow</strong><small id="mobile-tomorrow-summary" aria-live="polite">Nothing planned</small></span></button>
|
||||
<button data-mobile-queue="week" type="button"><span><strong>Week Ahead</strong><small id="mobile-week-summary" aria-live="polite">Nothing planned</small></span></button>
|
||||
</div>
|
||||
</section>
|
||||
<details class="mobile-queue-all">
|
||||
<summary>All queues</summary>
|
||||
<div class="mobile-queue-list" id="mobile-queue-all-list">
|
||||
<button data-mobile-queue="agenda" type="button"><span><strong>Agenda</strong><small>Upcoming deadlines</small></span><span data-mobile-queue-count="agenda">0</span></button>
|
||||
<button data-mobile-queue="delivery" type="button"><span><strong>Delivery</strong><small>Needs recovery</small></span><span data-mobile-queue-count="delivery">0</span></button>
|
||||
<button data-mobile-queue="gate" type="button"><span><strong>Human Gates</strong><small>Release decisions</small></span><span data-mobile-queue-count="gate">0</span></button>
|
||||
<button data-mobile-queue="attention" type="button"><span><strong>Attention</strong><small>Needs a response</small></span><span data-mobile-queue-count="attention">0</span></button>
|
||||
<button data-mobile-queue="update" type="button" aria-label="Updates, 0 unread conversations"><span><strong>Updates</strong><small>Unread conversations</small></span><span data-mobile-queue-count="update">0</span></button>
|
||||
<button data-mobile-queue="following" type="button" aria-label="Following, 0 unseen changes"><span><strong>Following</strong><small>Issues and pull requests you watch</small></span><span data-mobile-queue-count="following">0</span></button>
|
||||
<button data-mobile-queue="filed" type="button"><span><strong>Filed</strong><small>Issues you delegated</small></span><span data-mobile-queue-count="filed">0</span></button>
|
||||
<button data-mobile-queue="authored" type="button"><span><strong>My PRs</strong><small>Pull requests you authored</small></span><span data-mobile-queue-count="authored">0</span></button>
|
||||
<button data-mobile-queue="later" type="button"><span><strong>Later</strong><small>Deferred work</small></span><span data-mobile-queue-count="later">0</span></button>
|
||||
<button data-mobile-queue="draft" type="button"><span><strong>Drafts</strong><small>Unfiled captures</small></span><span data-mobile-queue-count="draft">0</span></button>
|
||||
<button data-mobile-queue="find" type="button"><span><strong>Find Work</strong><small>Claim something new</small></span></button>
|
||||
<button data-mobile-queue="recaps" type="button"><span><strong>Recaps</strong><small>History</small></span></button>
|
||||
</div>
|
||||
</details>
|
||||
</section>
|
||||
</dialog>
|
||||
|
||||
@@ -2143,6 +2260,34 @@
|
||||
<button class="mobile-task-action" data-mobile-task="queues" type="button" aria-label="Queues: no active queues; no upcoming deadlines"><span>Queues <span class="mobile-task-count" id="mobile-queue-count" hidden>0 active</span></span><span class="mobile-task-deadline" id="mobile-deadline-count" hidden>0 due</span></button>
|
||||
</nav>
|
||||
|
||||
<div class="create-pull-sheet" id="create-pull-sheet" role="dialog" aria-modal="true" aria-labelledby="create-pull-heading" hidden>
|
||||
<section class="create-pull-panel">
|
||||
<header class="create-pull-header">
|
||||
<div><span class="eyebrow">New</span><h3 id="create-pull-heading">Pull request</h3></div>
|
||||
<button id="cancel-create-pull" type="button">Cancel</button>
|
||||
</header>
|
||||
<p class="small">Open a pull request from a branch already pushed to Gitea.</p>
|
||||
<form id="create-pull-form">
|
||||
<label for="create-pull-repository">Repository
|
||||
<select id="create-pull-repository" required><option value="">Choose repository</option></select>
|
||||
</label>
|
||||
<div class="create-pull-branches">
|
||||
<label for="create-pull-head">Source branch<select id="create-pull-head" required disabled></select></label>
|
||||
<label for="create-pull-base">Base branch<select id="create-pull-base" required disabled></select></label>
|
||||
</div>
|
||||
<output id="create-pull-head-receipt" class="small" aria-live="polite"></output>
|
||||
<label for="create-pull-title">Title<input id="create-pull-title" maxlength="255" required autocomplete="off" /></label>
|
||||
<label for="create-pull-body">Context <span class="small">Optional · Markdown</span><textarea id="create-pull-body" maxlength="10000" rows="5"></textarea></label>
|
||||
<fieldset class="create-pull-mode"><legend>Start as</legend>
|
||||
<label><input type="radio" name="create-pull-mode" value="draft" checked /> Draft</label>
|
||||
<label><input type="radio" name="create-pull-mode" value="ready" /> Ready for review</label>
|
||||
</fieldset>
|
||||
<p id="create-pull-status" role="status" aria-live="polite"></p>
|
||||
<button id="submit-create-pull" type="submit" disabled>Create draft pull request</button>
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<div class="footer">Creative AI-imbued UI • stackchain-dashboard</div>
|
||||
|
||||
<script src="static/private-data-registry.js"></script>
|
||||
@@ -2160,6 +2305,7 @@
|
||||
<script src="static/search-reply-draft-store.js"></script>
|
||||
<script src="static/conversation-reply-draft-store.js"></script>
|
||||
<script src="static/conversation-photo-drafts.js"></script>
|
||||
<script src="static/photo-draft-inbox.js"></script>
|
||||
<script src="static/search-defer.js"></script>
|
||||
<script src="static/widgets.js"></script>
|
||||
<script src="static/drafts.js"></script>
|
||||
@@ -2179,6 +2325,10 @@
|
||||
<script src="static/offline-work.js"></script>
|
||||
<script src="static/offline-today.js"></script>
|
||||
<script src="static/my-work.js"></script>
|
||||
<script src="static/progressive-live-snapshot.js"></script>
|
||||
<script src="static/progressive-my-work.js"></script>
|
||||
<script src="static/progressive-mobile-dock.js"></script>
|
||||
<script src="static/progressive-capture.js"></script>
|
||||
<script src="static/agenda-replan.js"></script>
|
||||
<script src="static/agenda-calendar.js"></script>
|
||||
<script src="static/protect-today.js"></script>
|
||||
@@ -2231,6 +2381,7 @@
|
||||
<script src="static/voice-issue-capture.js"></script>
|
||||
<script src="static/voice-conversation-capture.js"></script>
|
||||
<script src="static/create-issue-sheet.js"></script>
|
||||
<script src="static/create-pull-sheet.js"></script>
|
||||
<script src="static/mobile-create-issue-nav.js"></script>
|
||||
<script src="static/create-and-start.js"></script>
|
||||
<script src="static/assign-and-start.js"></script>
|
||||
@@ -2268,6 +2419,7 @@
|
||||
<script src="static/device-storage.js"></script>
|
||||
<script src="static/mobile-device-setup.js"></script>
|
||||
<script src="static/mobile-search-viewport.js"></script>
|
||||
<script src="static/mobile-search-modal.js"></script>
|
||||
<script src="static/mobile-composer-viewport.js"></script>
|
||||
<script src="static/mention-composer.js"></script>
|
||||
<script src="static/push-notifications.js"></script>
|
||||
@@ -2279,6 +2431,8 @@
|
||||
<script src="static/mobile-plan-today-nav.js"></script>
|
||||
<script src="static/mobile-find-work-nav.js"></script>
|
||||
<script src="static/workspace-bootstrap.js"></script>
|
||||
<script src="static/human-gates.js"></script>
|
||||
<script src="static/progressive-human-gates.js"></script>
|
||||
<script src="static/dashboard.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
+1
-1
@@ -119,7 +119,7 @@
|
||||
return;
|
||||
}
|
||||
if (reason === 'session-idle') {
|
||||
status.textContent = 'Stackchain locked after inactivity. Your drafts and queued work are still on this device. Sign in to resume.';
|
||||
status.textContent = 'Stackchain locked. Your drafts and queued work are still on this device. Sign in to resume.';
|
||||
return;
|
||||
}
|
||||
if (reason !== 'session-revoked') return;
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
}) {
|
||||
const ENABLED_KEY = 'stackchain.app-badge.enabled.v1';
|
||||
let enabled = false;
|
||||
const confirmedCounts = {updates:0, following:0};
|
||||
const confirmedCounts = {updates:0, following:0, 'human-gates':0};
|
||||
let renderedCount = null;
|
||||
|
||||
|
||||
@@ -39,7 +39,9 @@
|
||||
}
|
||||
|
||||
async function render() {
|
||||
const confirmedCount = Math.min(9999, confirmedCounts.updates + confirmedCounts.following);
|
||||
const confirmedCount = Math.min(
|
||||
9999, confirmedCounts.updates + confirmedCounts.following + confirmedCounts['human-gates']
|
||||
);
|
||||
if (!enabled || !available() || renderedCount === confirmedCount) return true;
|
||||
try {
|
||||
if (confirmedCount > 0) await navigator.setAppBadge(confirmedCount);
|
||||
@@ -61,10 +63,12 @@
|
||||
if (enabled) {
|
||||
if (confirmedCounts.updates > 0) await syncCount('updates', confirmedCounts.updates);
|
||||
if (confirmedCounts.following > 0) await syncCount('following', confirmedCounts.following);
|
||||
if (confirmedCounts['human-gates'] > 0) await syncCount('human-gates', confirmedCounts['human-gates']);
|
||||
}
|
||||
if (!enabled && available()) {
|
||||
confirmedCounts.updates = 0;
|
||||
confirmedCounts.following = 0;
|
||||
confirmedCounts['human-gates'] = 0;
|
||||
try {
|
||||
await navigator.clearAppBadge();
|
||||
renderedCount = null;
|
||||
|
||||
@@ -8,12 +8,25 @@
|
||||
let active = false;
|
||||
let previous = '#/my-work';
|
||||
let retries = 0;
|
||||
let backgroundInert = null;
|
||||
|
||||
function attr(element, name, value) {
|
||||
if (value === null) element.removeAttribute(name);
|
||||
else element.setAttribute(name, value);
|
||||
}
|
||||
|
||||
function containBackground() {
|
||||
if (backgroundInert) return;
|
||||
backgroundInert = new Map(o.backgrounds.map(element => [element, element.inert]));
|
||||
backgroundInert.forEach((_wasInert, element) => { element.inert = true; });
|
||||
}
|
||||
|
||||
function releaseBackground() {
|
||||
if (!backgroundInert) return;
|
||||
backgroundInert.forEach((wasInert, element) => { element.inert = wasInert; });
|
||||
backgroundInert = null;
|
||||
}
|
||||
|
||||
function render(open, focus = false) {
|
||||
const wasActive = active;
|
||||
active = Boolean(open && o.mediaQuery.matches);
|
||||
@@ -28,7 +41,8 @@
|
||||
attr(o.root, 'aria-modal', active ? 'true' : null);
|
||||
attr(o.root, 'aria-hidden', active || !o.mediaQuery.matches ? null : 'true');
|
||||
o.root.inert = !active && o.mediaQuery.matches;
|
||||
o.backgrounds.forEach(element => { element.inert = active; });
|
||||
if (active) containBackground();
|
||||
else releaseBackground();
|
||||
o.dock.hidden = active;
|
||||
attr(o.hud, 'data-overlay-hidden', active ? 'true' : null);
|
||||
if (active) o.closeButton.focus();
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
};
|
||||
const continuation = [
|
||||
['delivery', 'Recover Delivery'],
|
||||
['gate', 'Review Human Gates'],
|
||||
['attention', 'Start Attention'],
|
||||
['today', 'Continue Today'],
|
||||
['update', 'Resume Updates'],
|
||||
@@ -18,6 +19,11 @@
|
||||
['later', 'Start Later'],
|
||||
['draft', 'Open Drafts'],
|
||||
];
|
||||
const activeQueueNames = continuation.map(([name]) => name).concat(['following', 'authored']);
|
||||
const allQueues = [
|
||||
'today', 'tomorrow', 'week', 'agenda', 'delivery', 'gate', 'attention',
|
||||
'update', 'following', 'filed', 'authored', 'later', 'draft', 'find', 'recaps',
|
||||
];
|
||||
|
||||
function recommend() {
|
||||
const counts = options.getCounts ? options.getCounts() : {};
|
||||
@@ -28,8 +34,59 @@
|
||||
return {name, count, label: label + ' (' + count + ')'};
|
||||
}
|
||||
|
||||
function presentation() {
|
||||
const counts = options.getCounts ? options.getCounts() : {};
|
||||
const active = activeQueueNames
|
||||
.map(name => ({name, count: Math.max(0, Number(counts[name]) || 0)}))
|
||||
.filter(item => item.count > 0);
|
||||
activeQueueNames.forEach(name => {
|
||||
if (counts[name + 'Unavailable'] && !active.some(item => item.name === name)) {
|
||||
active.push({name, unavailable: true});
|
||||
}
|
||||
});
|
||||
return {
|
||||
nextUp: recommend(),
|
||||
active,
|
||||
planning: ['today', 'tomorrow', 'week'],
|
||||
all: allQueues.slice(),
|
||||
};
|
||||
}
|
||||
|
||||
function renderPresentation() {
|
||||
const view = presentation();
|
||||
const planning = new Set(view.planning);
|
||||
const active = view.active.filter(item => !planning.has(item.name));
|
||||
const activeNames = new Set(active.map(item => item.name));
|
||||
if (options.nextAction) {
|
||||
options.nextAction.textContent = view.nextUp.label;
|
||||
options.nextAction.dataset.queue = view.nextUp.name;
|
||||
options.nextAction.setAttribute('aria-label', 'Next up: ' + view.nextUp.label);
|
||||
}
|
||||
active.forEach(item => {
|
||||
const row = options.rows?.[item.name];
|
||||
if (!row) return;
|
||||
if (item.unavailable) row.setAttribute('data-unavailable', 'true');
|
||||
else row.removeAttribute('data-unavailable');
|
||||
options.activeList?.append(row);
|
||||
});
|
||||
view.planning.forEach(name => {
|
||||
const row = options.rows?.[name];
|
||||
if (row) options.planningList?.append(row);
|
||||
});
|
||||
view.all.forEach(name => {
|
||||
if (planning.has(name) || activeNames.has(name)) return;
|
||||
const row = options.rows?.[name];
|
||||
if (!row) return;
|
||||
row.removeAttribute('data-unavailable');
|
||||
options.allList?.append(row);
|
||||
});
|
||||
if (options.activeSection) options.activeSection.hidden = active.length === 0;
|
||||
return view;
|
||||
}
|
||||
|
||||
function open(name) {
|
||||
if (name === 'delivery' && options.openDelivery) return options.openDelivery();
|
||||
if (name === 'gate' && options.openHumanGates) return options.openHumanGates();
|
||||
if (name === 'today') return options.openToday();
|
||||
if (name === 'agenda') return options.openAgenda();
|
||||
if (name === 'update' && options.openUpdates) return options.openUpdates();
|
||||
@@ -54,5 +111,5 @@
|
||||
return open(next.name);
|
||||
}
|
||||
|
||||
return { open, recommend, continueWork };
|
||||
return { open, recommend, presentation, renderPresentation, continueWork };
|
||||
});
|
||||
@@ -0,0 +1,83 @@
|
||||
(function (root, factory) {
|
||||
const createMobileSearchModal = factory();
|
||||
if (typeof module !== 'undefined' && module.exports) module.exports = createMobileSearchModal;
|
||||
else root.createMobileSearchModal = createMobileSearchModal;
|
||||
})(typeof globalThis !== 'undefined' ? globalThis : this, function () {
|
||||
const FOCUSABLE = [
|
||||
'a[href]', 'button', 'input', 'select', 'textarea',
|
||||
'[tabindex]:not([tabindex="-1"])', '[contenteditable="true"]',
|
||||
].join(',');
|
||||
|
||||
return function createMobileSearchModal(options) {
|
||||
const documentRef = options.document;
|
||||
const backgrounds = Array.from(options.backgrounds || [
|
||||
documentRef.querySelector?.('body > header'),
|
||||
documentRef.querySelector?.('main'),
|
||||
documentRef.querySelector?.('#mobile-task-dock'),
|
||||
]).filter(Boolean);
|
||||
let surface = null;
|
||||
let opener = null;
|
||||
let priorInert = null;
|
||||
|
||||
function focusable() {
|
||||
if (!surface || typeof surface.querySelectorAll !== 'function') return [];
|
||||
return Array.from(surface.querySelectorAll(FOCUSABLE)).filter(element =>
|
||||
!element.disabled && !element.hidden && element.getAttribute?.('aria-hidden') !== 'true' &&
|
||||
(typeof element.matches !== 'function' || element.matches(':not([hidden])')) &&
|
||||
(typeof element.getClientRects !== 'function' || element.getClientRects().length > 0)
|
||||
);
|
||||
}
|
||||
|
||||
function focus(element) {
|
||||
if (element?.isConnected !== false && typeof element?.focus === 'function') element.focus();
|
||||
}
|
||||
|
||||
function onKeydown(event) {
|
||||
if (!surface || event.key !== 'Tab') return;
|
||||
const controls = focusable();
|
||||
if (!controls.length) {
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
const first = controls[0];
|
||||
const last = controls[controls.length - 1];
|
||||
if (event.shiftKey && documentRef.activeElement === first) {
|
||||
event.preventDefault();
|
||||
focus(last);
|
||||
} else if (!event.shiftKey && documentRef.activeElement === last) {
|
||||
event.preventDefault();
|
||||
focus(first);
|
||||
} else if (!controls.includes(documentRef.activeElement)) {
|
||||
event.preventDefault();
|
||||
focus(event.shiftKey ? last : first);
|
||||
}
|
||||
}
|
||||
|
||||
function transition(nextSurface, transitionOptions = {}) {
|
||||
surface = nextSurface;
|
||||
focus(transitionOptions.initialFocus || focusable()[0]);
|
||||
}
|
||||
|
||||
function activate(nextSurface, activateOptions = {}) {
|
||||
if (!surface) {
|
||||
opener = activateOptions.opener || documentRef.activeElement || null;
|
||||
priorInert = backgrounds.map(element => element.inert === true);
|
||||
backgrounds.forEach(element => { element.inert = true; });
|
||||
}
|
||||
transition(nextSurface, activateOptions);
|
||||
}
|
||||
|
||||
function deactivate() {
|
||||
if (!surface) return;
|
||||
backgrounds.forEach((element, index) => { element.inert = priorInert[index]; });
|
||||
surface = null;
|
||||
priorInert = null;
|
||||
const restore = opener;
|
||||
opener = null;
|
||||
focus(restore);
|
||||
}
|
||||
|
||||
documentRef.addEventListener('keydown', onKeydown);
|
||||
return { activate, transition, deactivate, current: () => surface };
|
||||
};
|
||||
});
|
||||
@@ -6,6 +6,7 @@
|
||||
const storage = options.storage || (typeof localStorage !== 'undefined' ? localStorage : null);
|
||||
const reviewOrder = [
|
||||
['delivery', 'Delivery recovery'],
|
||||
['gate', 'Human Gates'],
|
||||
['agenda', 'Agenda'],
|
||||
['attention', 'Attention'],
|
||||
['update', 'Updates'],
|
||||
@@ -104,6 +105,12 @@
|
||||
function briefing() {
|
||||
const counts = options.getCounts ? options.getCounts() : {};
|
||||
let phases = reviewPhases(counts);
|
||||
const gateUnavailable = counts.gateUnavailable === true;
|
||||
if (gateUnavailable) {
|
||||
phases = phases.filter(phase => phase.name !== 'gate');
|
||||
const afterDelivery = phases[0]?.name === 'delivery' ? 1 : 0;
|
||||
phases.splice(afterDelivery, 0, {name:'gate', label:'Human Gates unavailable · retry', count:count(counts.gate)});
|
||||
}
|
||||
const followingUnavailable = counts.followingUnavailable === true;
|
||||
if (followingUnavailable) {
|
||||
phases = phases.filter(phase => phase.name !== 'following');
|
||||
@@ -115,14 +122,17 @@
|
||||
const other = total - delivery;
|
||||
const next = phases.length ? phases[0].name : (today ? 'today' : 'find');
|
||||
const nextLabel = next === 'delivery' ? 'Review Delivery' :
|
||||
(next === 'gate' && gateUnavailable ? 'Retry Human Gates' :
|
||||
(next === 'following' && followingUnavailable ? 'Retry Following' :
|
||||
(phases.length ? 'Review ' + phases[0].label : (today ? 'Continue Today' : 'Find Work')));
|
||||
(phases.length ? 'Review ' + phases[0].label : (today ? 'Continue Today' : 'Find Work'))));
|
||||
const gateRetry = next === 'gate' && gateUnavailable;
|
||||
const followingRetry = next === 'following' && followingUnavailable;
|
||||
return {
|
||||
total,
|
||||
next,
|
||||
label: nextLabel,
|
||||
summary: followingRetry ? 'Following needs retry before Today · ' + today + ' planned' :
|
||||
summary: gateRetry ? 'Human Gates need retry before Today · ' + today + ' planned' :
|
||||
followingRetry ? 'Following needs retry before Today · ' + today + ' planned' :
|
||||
delivery ? delivery + (delivery === 1 ? ' delivery needs' : ' deliveries need') +
|
||||
' action before Today' + (other ? ' · ' + other + ' other ' + (other === 1 ? 'item' : 'items') : '') +
|
||||
' · ' + today + ' planned' :
|
||||
|
||||
@@ -97,9 +97,9 @@
|
||||
}
|
||||
|
||||
function updateQueues(counts) {
|
||||
const names = 'today agenda delivery attention update filed later draft'.split(' ');
|
||||
const names = 'today agenda delivery gate attention update filed later draft'.split(' ');
|
||||
const normalized = Object.fromEntries(names.map(name => [name, Math.max(0, Number(counts?.[name]) || 0)]));
|
||||
const actionableNames = ['today', 'delivery', 'attention', 'update', 'filed', 'later', 'draft'];
|
||||
const actionableNames = ['today', 'delivery', 'gate', 'attention', 'update', 'filed', 'later', 'draft'];
|
||||
const active = actionableNames.reduce((total, name) => total + (normalized[name] > 0 ? 1 : 0), 0);
|
||||
Object.entries(options.queueCounts || {}).forEach(([name, element]) => {
|
||||
element.textContent = String(normalized[name] || 0);
|
||||
@@ -124,6 +124,7 @@
|
||||
: 'Queues: Today ' + normalized.today
|
||||
+ ', Agenda ' + normalized.agenda + ' due'
|
||||
+ ', Delivery ' + normalized.delivery
|
||||
+ ', Human Gates ' + normalized.gate
|
||||
+ ', Attention ' + normalized.attention
|
||||
+ ', Updates ' + normalized.update
|
||||
+ ', Filed ' + normalized.filed
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
(function (root, factory) {
|
||||
const createPhotoDraftInbox = factory();
|
||||
if (typeof module === 'object' && module.exports) module.exports = createPhotoDraftInbox;
|
||||
else root.createPhotoDraftInbox = createPhotoDraftInbox;
|
||||
})(typeof globalThis !== 'undefined' ? globalThis : this, function () {
|
||||
'use strict';
|
||||
|
||||
function targetKey(route) {
|
||||
if (route?.kind === 'update') {
|
||||
const notificationId = Number(route.notification_id || 0);
|
||||
return notificationId > 0 ? 'update:' + notificationId : '';
|
||||
}
|
||||
const kind = route?.kind === 'search' ? route.target_kind : route?.kind;
|
||||
const repository = String(route?.repository || '');
|
||||
const number = Number(route?.number || 0);
|
||||
return ['issue', 'pull'].includes(kind) && repository && number > 0 ?
|
||||
kind + ':' + repository.toLowerCase() + '#' + number : '';
|
||||
}
|
||||
|
||||
function removeTarget(item) {
|
||||
const route = item?.route || {};
|
||||
if (route.kind === 'update') return { kind:'update', notificationId:Number(route.notification_id) };
|
||||
return {
|
||||
kind:route.kind === 'search' ? route.target_kind : route.kind,
|
||||
repository:route.repository,
|
||||
number:Number(route.number),
|
||||
};
|
||||
}
|
||||
|
||||
return function createPhotoDraftInbox({ conversation, search }) {
|
||||
let items = [];
|
||||
|
||||
async function refresh(existing = []) {
|
||||
const occupied = new Set(existing.map(item => targetKey(item?.route)).filter(Boolean));
|
||||
const results = await Promise.allSettled([
|
||||
conversation?.list?.() || [],
|
||||
search?.list?.() || [],
|
||||
]);
|
||||
items = results.flatMap(result => result.status === 'fulfilled' && Array.isArray(result.value) ? result.value : [])
|
||||
.filter(item => {
|
||||
const key = targetKey(item?.route);
|
||||
if (!key || occupied.has(key)) return false;
|
||||
occupied.add(key);
|
||||
return true;
|
||||
})
|
||||
.sort((left, right) => Number(right.updated_at || 0) - Number(left.updated_at || 0) ||
|
||||
String(left.id || '').localeCompare(String(right.id || '')));
|
||||
return items.slice();
|
||||
}
|
||||
|
||||
function list() { return items.slice(); }
|
||||
|
||||
async function discard(item) {
|
||||
if (!item || !items.some(candidate => candidate.id === item.id && candidate.photo_store === item.photo_store)) {
|
||||
return false;
|
||||
}
|
||||
const store = item.photo_store === 'search' ? search : conversation;
|
||||
if (!store?.remove) return false;
|
||||
await store.remove(removeTarget(item));
|
||||
items = items.filter(candidate => !(candidate.id === item.id && candidate.photo_store === item.photo_store));
|
||||
return true;
|
||||
}
|
||||
|
||||
function description(item) {
|
||||
return item?.kind === 'photo-reply' ?
|
||||
Number(item.photo_count || 0) + (Number(item.photo_count) === 1 ? ' saved photo' : ' saved photos') :
|
||||
(item?.preview || 'Unfinished draft');
|
||||
}
|
||||
|
||||
function searchTarget(item) {
|
||||
const route = item?.route || {};
|
||||
return {
|
||||
kind:route.target_kind, repository:route.repository,
|
||||
number:route.number, title:item?.title,
|
||||
};
|
||||
}
|
||||
|
||||
return { refresh, list, discard, description, searchTarget };
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,182 @@
|
||||
function createProgressiveCapture({
|
||||
document,
|
||||
storage,
|
||||
getLogin = () => '',
|
||||
createCaptures = globalThis.createUnfiledCaptures,
|
||||
requestFullWorkspace = async () => {
|
||||
const lifecycle = await globalThis.stackchainWorkspaceLifecycle;
|
||||
return lifecycle?.optionalReady;
|
||||
},
|
||||
createId,
|
||||
now,
|
||||
}) {
|
||||
const button = document.querySelector('[data-mobile-task="new"]');
|
||||
const root = document.querySelector('#create-issue-sheet');
|
||||
const title = document.querySelector('#create-issue-title');
|
||||
const body = document.querySelector('#create-issue-body');
|
||||
const heading = document.querySelector('#create-issue-heading');
|
||||
const save = document.querySelector('#save-unfiled-issue');
|
||||
const file = document.querySelector('#file-new-issue');
|
||||
const cancel = document.querySelector('#cancel-new-issue');
|
||||
const status = document.querySelector('#my-work-action-status');
|
||||
const captures = createCaptures({
|
||||
storage,
|
||||
getCaptureLogin:getLogin,
|
||||
getCurrentLogin:getLogin,
|
||||
...(createId ? {createId} : {}),
|
||||
...(now ? {now} : {}),
|
||||
});
|
||||
const listeners = [];
|
||||
let started = false;
|
||||
let saving = null;
|
||||
let saved = false;
|
||||
let handedOff = false;
|
||||
const checkpointKey = 'stackchain.progressive-capture.v1';
|
||||
|
||||
function listen(element, name, callback) {
|
||||
element?.addEventListener?.(name, callback);
|
||||
listeners.push([element, name, callback]);
|
||||
}
|
||||
|
||||
function close() {
|
||||
root?.classList.remove('open');
|
||||
}
|
||||
|
||||
function readCheckpoints() {
|
||||
try {
|
||||
const record = JSON.parse(storage?.getItem(checkpointKey) || 'null');
|
||||
if (record?.version !== 1 || !Array.isArray(record.items)) return [];
|
||||
return record.items.filter(item => item && typeof item.ownerLogin === 'string' &&
|
||||
typeof item.title === 'string' && typeof item.body === 'string');
|
||||
} catch (_error) { return []; }
|
||||
}
|
||||
|
||||
function readCheckpoint() {
|
||||
const login = String(getLogin() || '').trim();
|
||||
if (!login) return null;
|
||||
return readCheckpoints().find(item => item.ownerLogin === login) || null;
|
||||
}
|
||||
|
||||
function checkpoint() {
|
||||
const ownerLogin = String(getLogin() || '').trim();
|
||||
if (!ownerLogin) return false;
|
||||
try {
|
||||
const items = readCheckpoints().filter(item => item.ownerLogin !== ownerLogin);
|
||||
items.push({
|
||||
ownerLogin,
|
||||
title:String(title?.value || '').slice(0, 255),
|
||||
body:String(body?.value || '').slice(0, 10000),
|
||||
});
|
||||
storage?.setItem(checkpointKey, JSON.stringify({
|
||||
version:1, items,
|
||||
}));
|
||||
return true;
|
||||
} catch (_error) { return false; }
|
||||
}
|
||||
|
||||
function clearCheckpoint(expected) {
|
||||
const current = readCheckpoint();
|
||||
if (!current || current.title !== expected.title || current.body !== expected.body) return false;
|
||||
try {
|
||||
const ownerLogin = String(getLogin() || '').trim();
|
||||
const items = readCheckpoints().filter(item => item.ownerLogin !== ownerLogin);
|
||||
if (items.length) storage?.setItem(checkpointKey, JSON.stringify({version:1, items}));
|
||||
else storage?.removeItem(checkpointKey);
|
||||
return true;
|
||||
} catch (_error) { return false; }
|
||||
}
|
||||
|
||||
function open(event) {
|
||||
saved = false;
|
||||
const recovered = readCheckpoint();
|
||||
if (recovered) {
|
||||
if (title) title.value = recovered.title;
|
||||
if (body) body.value = recovered.body;
|
||||
if (status) status.textContent = 'Unfinished capture restored from this phone.';
|
||||
}
|
||||
if (heading) heading.textContent = 'Capture work';
|
||||
root?.classList.add('open');
|
||||
title?.focus?.();
|
||||
}
|
||||
|
||||
async function saveDraft() {
|
||||
if (saved || saving) return saving;
|
||||
save.disabled = true;
|
||||
const draft = {title:title?.value || '', body:body?.value || ''};
|
||||
saving = Promise.resolve().then(() => captures.save(draft)).then(() => {
|
||||
saved = true;
|
||||
clearCheckpoint(draft);
|
||||
if (title) title.value = '';
|
||||
if (body) body.value = '';
|
||||
close();
|
||||
if (status) status.textContent = 'Saved to Drafts. Choose a repository when you’re ready to file it.';
|
||||
return true;
|
||||
}).catch(error => {
|
||||
if (status) status.textContent = error.message;
|
||||
title?.focus?.();
|
||||
return false;
|
||||
}).finally(() => {
|
||||
save.disabled = false;
|
||||
saving = null;
|
||||
});
|
||||
return saving;
|
||||
}
|
||||
|
||||
async function fileNow() {
|
||||
if (file.disabled) return false;
|
||||
file.disabled = true;
|
||||
if (status) status.textContent = 'Loading filing tools…';
|
||||
try {
|
||||
await requestFullWorkspace();
|
||||
return true;
|
||||
} catch (_error) {
|
||||
file.disabled = false;
|
||||
if (status) status.textContent = 'Filing tools unavailable. Your capture is still editable; retry when connected.';
|
||||
title?.focus?.();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function start() {
|
||||
if (started) return false;
|
||||
started = true;
|
||||
root?.classList.add('progressive-capture');
|
||||
listen(button, 'click', open);
|
||||
listen(save, 'click', saveDraft);
|
||||
listen(file, 'click', fileNow);
|
||||
listen(cancel, 'click', close);
|
||||
listen(title, 'input', checkpoint);
|
||||
listen(body, 'input', checkpoint);
|
||||
return true;
|
||||
}
|
||||
|
||||
function handoff() {
|
||||
if (handedOff) return null;
|
||||
handedOff = true;
|
||||
const state = {
|
||||
open:Boolean(root?.classList.contains('open')),
|
||||
title:title?.value || '', body:body?.value || '',
|
||||
};
|
||||
state.complete = () => clearCheckpoint(state);
|
||||
root?.classList.remove('progressive-capture');
|
||||
file.disabled = false;
|
||||
listeners.forEach(([element, name, callback]) => element?.removeEventListener?.(name, callback));
|
||||
listeners.length = 0;
|
||||
return state;
|
||||
}
|
||||
|
||||
return {start, handoff};
|
||||
}
|
||||
|
||||
if (typeof window !== 'undefined' && typeof document !== 'undefined' &&
|
||||
typeof createUnfiledCaptures === 'function' &&
|
||||
window.matchMedia?.('(max-width: 600px)').matches === true) {
|
||||
window.stackchainProgressiveCapture = createProgressiveCapture({
|
||||
document,
|
||||
storage:window.localStorage,
|
||||
getLogin:() => window.stackchainProgressiveMyWork?.login?.() || '',
|
||||
});
|
||||
window.stackchainProgressiveCapture.start();
|
||||
}
|
||||
|
||||
if (typeof module !== 'undefined' && module.exports) module.exports = createProgressiveCapture;
|
||||
@@ -0,0 +1,101 @@
|
||||
function createProgressiveHumanGates(options = {}) {
|
||||
const document = options.document || globalThis.document;
|
||||
const location = options.location || globalThis.location;
|
||||
const history = options.history || globalThis.history;
|
||||
const storage = options.storage || globalThis.localStorage;
|
||||
const isOnline = options.isOnline || (() => globalThis.navigator?.onLine !== false);
|
||||
const fetchJson = options.fetchJson || (async (path, requestOptions = {}) => {
|
||||
const response = await fetch(path, requestOptions);
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
if (!response.ok) throw new Error(payload.error || payload.detail?.message || payload.detail || 'Review request failed.');
|
||||
return payload;
|
||||
});
|
||||
const liveSnapshot = options.liveSnapshot || null;
|
||||
const getIdentity = options.getIdentity || (async () => {
|
||||
const response = liveSnapshot ? await liveSnapshot.acquire({requireIdentity:true}) :
|
||||
await fetchJson('api/v1/live', {headers:{Accept:'application/json'}});
|
||||
const user = response?.context?.user || {};
|
||||
const login = String(user.login || '').trim();
|
||||
return {login, accountKey:login && user.id ? String(user.id) + ':' + login : login};
|
||||
});
|
||||
const query = selector => document.querySelector(selector);
|
||||
const nodes = {
|
||||
count:query('#human-gates-count'), list:query('#human-gates-list'),
|
||||
status:query('#human-gates-status'), panel:query('#human-gates'),
|
||||
detail:query('#human-gate-detail'),
|
||||
};
|
||||
let login = '';
|
||||
let accountKey = '';
|
||||
let started = false;
|
||||
let startFlight = null;
|
||||
|
||||
const controller = createHumanGates({
|
||||
storage, isOnline, location, fetchJson,
|
||||
getLogin:() => login, getAccountKey:() => accountKey, nodes,
|
||||
});
|
||||
|
||||
const showError = error => {
|
||||
if (nodes.status) nodes.status.textContent = error?.message || 'Human Gates are unavailable.';
|
||||
};
|
||||
const open = () => start(true).catch(showError);
|
||||
query('#open-human-gates')?.addEventListener?.('click', open);
|
||||
query('#close-human-gates')?.addEventListener?.('click', () => {
|
||||
if (nodes.panel) nodes.panel.hidden = true;
|
||||
if (location.hash === '#/my-work/human-gates') history.replaceState({}, '', '#/my-work');
|
||||
});
|
||||
nodes.list?.addEventListener?.('click', event => {
|
||||
const card = event.target?.closest?.('[data-human-gate-id]');
|
||||
if (card) controller.select(card.dataset.humanGateId);
|
||||
});
|
||||
nodes.detail?.addEventListener?.('click', event => {
|
||||
const decision = event.target?.closest?.('[data-gate-decision]')?.dataset.gateDecision;
|
||||
if (!decision) return;
|
||||
const checklist = Object.fromEntries(Array.from(nodes.detail.querySelectorAll('[data-gate-checklist]')).map(input => [input.dataset.gateChecklist, input.checked]));
|
||||
controller.decideAndNext(decision, {
|
||||
checklist,
|
||||
reason:nodes.detail.querySelector?.('[data-gate-reason]')?.value || '',
|
||||
override_reason:nodes.detail.querySelector?.('[data-gate-override]')?.value || '',
|
||||
}).catch(showError);
|
||||
});
|
||||
|
||||
async function start(force = false) {
|
||||
if (!force && location.hash !== '#/my-work/human-gates') return false;
|
||||
if (started) return controller.open().then(() => true);
|
||||
if (startFlight) return startFlight;
|
||||
startFlight = (async () => {
|
||||
const identity = await getIdentity();
|
||||
login = String(identity?.login || '').trim();
|
||||
accountKey = String(identity?.accountKey || login).trim();
|
||||
if (!login) throw new Error('Authenticated account identity is required.');
|
||||
await controller.open();
|
||||
started = true;
|
||||
return true;
|
||||
})();
|
||||
try { return await startFlight; }
|
||||
finally { startFlight = null; }
|
||||
}
|
||||
|
||||
return {
|
||||
start,
|
||||
handoff() {
|
||||
return {
|
||||
controller, started,
|
||||
adoptIdentity(nextLogin, nextAccountKey) {
|
||||
login = String(nextLogin || '').trim();
|
||||
accountKey = String(nextAccountKey || login).trim();
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
|
||||
window.stackchainProgressiveHumanGates = createProgressiveHumanGates({
|
||||
document, liveSnapshot:window.stackchainProgressiveLiveSnapshot,
|
||||
});
|
||||
void window.stackchainProgressiveHumanGates.start().catch(() => {});
|
||||
}
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
globalThis.createHumanGates = globalThis.createHumanGates || require('./human-gates.js');
|
||||
module.exports = createProgressiveHumanGates;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
function createProgressiveLiveSnapshot({fetchSnapshot}) {
|
||||
let value = null;
|
||||
let flight = null;
|
||||
|
||||
const hasIdentity = snapshot => {
|
||||
const user = snapshot?.context?.user || {};
|
||||
return Boolean(String(user.login || '').trim());
|
||||
};
|
||||
const requireUsable = (snapshot, options) => {
|
||||
if (!options?.requireIdentity || hasIdentity(snapshot)) return snapshot;
|
||||
if (value === snapshot) value = null;
|
||||
throw new Error('Authenticated account identity is unavailable.');
|
||||
};
|
||||
const acquire = (options = {}) => {
|
||||
if (value) return Promise.resolve().then(() => requireUsable(value, options));
|
||||
if (flight) return flight.then(snapshot => requireUsable(snapshot, options));
|
||||
flight = Promise.resolve().then(() => fetchSnapshot()).then(snapshot => {
|
||||
value = snapshot;
|
||||
flight = null;
|
||||
return snapshot;
|
||||
}, error => {
|
||||
flight = null;
|
||||
throw error;
|
||||
});
|
||||
return flight.then(snapshot => requireUsable(snapshot, options));
|
||||
};
|
||||
|
||||
return {
|
||||
acquire,
|
||||
snapshot:() => value,
|
||||
pending:() => flight,
|
||||
identity() {
|
||||
const user = value?.context?.user || {};
|
||||
const login = String(user.login || '').trim();
|
||||
return {login, accountKey:login && user.id ? String(user.id) + ':' + login : login};
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
window.stackchainProgressiveLiveSnapshot = createProgressiveLiveSnapshot({
|
||||
fetchSnapshot:async () => {
|
||||
const response = await fetch('api/v1/live', {headers:{Accept:'application/json'}});
|
||||
if (!response.ok) throw new Error('HTTP ' + response.status);
|
||||
return response.json();
|
||||
},
|
||||
});
|
||||
}
|
||||
if (typeof module !== 'undefined' && module.exports) module.exports = createProgressiveLiveSnapshot;
|
||||
@@ -0,0 +1,119 @@
|
||||
(function (root, factory) {
|
||||
if (typeof module === 'object' && module.exports) module.exports = factory;
|
||||
else root.createProgressiveMobileDock = factory;
|
||||
})(typeof self !== 'undefined' ? self : this, function createProgressiveMobileDock(options) {
|
||||
const document = options.document;
|
||||
const myWork = options.myWork;
|
||||
const work = document.querySelector('[data-mobile-task="work"]');
|
||||
const queues = document.querySelector('[data-mobile-task="queues"]');
|
||||
const sheet = document.querySelector('#mobile-queue-sheet');
|
||||
const close = document.querySelector('#close-mobile-queues');
|
||||
const next = document.querySelector('#mobile-queue-next-action');
|
||||
const rows = Object.fromEntries(Array.from(document.querySelectorAll('[data-mobile-queue]'))
|
||||
.map(row => [row.dataset.mobileQueue, row]));
|
||||
const countElements = Object.fromEntries(Array.from(document.querySelectorAll('[data-mobile-queue-count]'))
|
||||
.map(element => [element.dataset.mobileQueueCount, element]));
|
||||
const originalDescriptions = Object.fromEntries(Object.entries(rows)
|
||||
.map(([name, row]) => [name, row.querySelector?.('small')?.textContent || '']));
|
||||
const originalCounts = Object.fromEntries(Object.entries(countElements)
|
||||
.map(([name, element]) => [name, element.textContent]));
|
||||
const supported = new Set(['all', 'attention', 'filed', 'authored', 'issue', 'pull', 'review', 'update']);
|
||||
const listeners = [];
|
||||
let started = false;
|
||||
let lastTask = null;
|
||||
let unsubscribe = null;
|
||||
|
||||
function listen(element, name, listener) {
|
||||
if (!element) return;
|
||||
element.addEventListener(name, listener);
|
||||
listeners.push([element, name, listener]);
|
||||
}
|
||||
|
||||
function render() {
|
||||
const counts = myWork?.counts?.() || {};
|
||||
Object.entries(rows).forEach(([name, row]) => {
|
||||
const count = Math.max(0, Number(counts[name]) || 0);
|
||||
const countElement = countElements[name];
|
||||
if (supported.has(name)) {
|
||||
row.removeAttribute('data-unavailable');
|
||||
row.removeAttribute('data-progressive-loading');
|
||||
if (countElement) countElement.textContent = String(count);
|
||||
return;
|
||||
}
|
||||
row.setAttribute('data-unavailable', 'true');
|
||||
row.setAttribute('data-progressive-loading', 'true');
|
||||
const description = row.querySelector?.('small');
|
||||
if (description) description.textContent = 'Still loading';
|
||||
if (countElement) countElement.textContent = '…';
|
||||
});
|
||||
const actionable = ['attention', 'filed', 'authored', 'review', 'update']
|
||||
.find(name => Number(counts[name]) > 0);
|
||||
if (next) {
|
||||
if (actionable) {
|
||||
next.textContent = 'Open ' + (actionable === 'authored' ? 'My PRs' : actionable[0].toUpperCase() + actionable.slice(1))
|
||||
+ ' (' + counts[actionable] + ')';
|
||||
next.dataset.queue = actionable;
|
||||
next.removeAttribute('data-unavailable');
|
||||
} else {
|
||||
next.textContent = Number(counts.all) > 0 ? 'Open assigned work (' + counts.all + ')' : 'Assigned work is still loading';
|
||||
next.dataset.queue = 'all';
|
||||
if (!Number(counts.all)) next.setAttribute('data-unavailable', 'true');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function openSheet() {
|
||||
lastTask = 'queues';
|
||||
render();
|
||||
if (sheet && !sheet.open) sheet.showModal();
|
||||
}
|
||||
|
||||
function openQueue(name) {
|
||||
if (!supported.has(name)) return false;
|
||||
lastTask = 'work';
|
||||
if (sheet?.open) sheet.close();
|
||||
myWork?.selectQueue?.(name, {openFirst:true});
|
||||
return true;
|
||||
}
|
||||
|
||||
function start() {
|
||||
if (started) return false;
|
||||
started = true;
|
||||
listen(work, 'click', () => { lastTask = 'work'; myWork?.openFirst?.(); });
|
||||
listen(queues, 'click', openSheet);
|
||||
listen(close, 'click', () => sheet?.open && sheet.close());
|
||||
Object.entries(rows).forEach(([name, row]) => listen(row, 'click', () => openQueue(name)));
|
||||
listen(next, 'click', () => openQueue(next.dataset.queue || 'all'));
|
||||
unsubscribe = myWork?.subscribe?.(render) || null;
|
||||
render();
|
||||
return true;
|
||||
}
|
||||
|
||||
function handoff() {
|
||||
return {queueSheetOpen:Boolean(sheet?.open), lastTask};
|
||||
}
|
||||
|
||||
function stop() {
|
||||
listeners.splice(0).forEach(([element, name, listener]) => element.removeEventListener(name, listener));
|
||||
unsubscribe?.();
|
||||
unsubscribe = null;
|
||||
Object.entries(rows).forEach(([name, row]) => {
|
||||
row.removeAttribute('data-unavailable');
|
||||
row.removeAttribute('data-progressive-loading');
|
||||
const description = row.querySelector?.('small');
|
||||
if (description) description.textContent = originalDescriptions[name];
|
||||
if (countElements[name]) countElements[name].textContent = originalCounts[name];
|
||||
});
|
||||
started = false;
|
||||
}
|
||||
|
||||
return {start, stop, handoff, render, openQueue};
|
||||
});
|
||||
|
||||
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
|
||||
window.stackchainProgressiveMobileDock = createProgressiveMobileDock({
|
||||
document,
|
||||
myWork:window.stackchainProgressiveMyWork,
|
||||
});
|
||||
window.stackchainProgressiveMobileDock.start();
|
||||
}
|
||||
@@ -0,0 +1,278 @@
|
||||
function createProgressiveMyWork({
|
||||
document, fetchSnapshot, liveSnapshot: snapshotBroker = null,
|
||||
pollerOptions = {}, lifecycleTarget = globalThis,
|
||||
}) {
|
||||
const list = document.querySelector('#my-work-list');
|
||||
const status = document.querySelector('#my-work-status');
|
||||
const detail = document.querySelector('#progressive-work-detail');
|
||||
const detailTitle = document.querySelector('#progressive-work-detail-title');
|
||||
const detailMeta = document.querySelector('#progressive-work-detail-meta');
|
||||
const detailReason = document.querySelector('#progressive-work-detail-reason');
|
||||
const closeDetail = document.querySelector('#close-progressive-work-detail');
|
||||
const openGitea = document.querySelector('#open-progressive-work-gitea');
|
||||
const filters = Array.from(document.querySelectorAll('[data-work-filter]'));
|
||||
const listeners = [];
|
||||
const lifecycleListeners = [];
|
||||
const subscribers = new Set();
|
||||
let items = [];
|
||||
let active = 'all';
|
||||
let stopped = false;
|
||||
let selectedByUser = false;
|
||||
let liveSnapshot = null;
|
||||
let liveSnapshotPromise = null;
|
||||
let confirmedLogin = '';
|
||||
let poller = null;
|
||||
let detailTrigger = null;
|
||||
let openWork = null;
|
||||
let contextUnavailable = false;
|
||||
const deferredQueues = {
|
||||
today:'Today', agenda:'Agenda', later:'Later', draft:'Drafts',
|
||||
};
|
||||
const fetchProgressiveSnapshot = (revisions = {}, options = {}) =>
|
||||
snapshotBroker && Object.keys(revisions || {}).length === 0 ?
|
||||
snapshotBroker.acquire() : fetchSnapshot(revisions, options);
|
||||
|
||||
const escapeHtml = value => String(value || '').replace(/[&<>"']/g, character => ({
|
||||
'&':'&', '<':'<', '>':'>', '"':'"', "'":''',
|
||||
})[character]);
|
||||
const safeUrl = value => {
|
||||
try {
|
||||
const url = new URL(String(value || ''), globalThis.location?.href || 'https://invalid.example/');
|
||||
return ['http:', 'https:'].includes(url.protocol) ? url.href : '';
|
||||
} catch (_error) { return ''; }
|
||||
};
|
||||
const matches = (item, filter) =>
|
||||
filter === 'review' ? item.is_review :
|
||||
filter === 'update' ? item.has_update :
|
||||
filter === 'attention' ? item.needs_attention :
|
||||
filter === 'filed' ? item.is_filed :
|
||||
filter === 'authored' ? item.is_authored :
|
||||
filter === 'pull' ? item.kind === 'pull' && !item.is_review : item.kind === filter;
|
||||
const visibleItems = () => active === 'all' ? items : items.filter(item => matches(item, active));
|
||||
const notify = () => subscribers.forEach(subscriber => subscriber());
|
||||
const queueCounts = () => ({
|
||||
all:items.length,
|
||||
filed:items.filter(item => matches(item, 'filed')).length,
|
||||
authored:items.filter(item => matches(item, 'authored')).length,
|
||||
attention:items.filter(item => matches(item, 'attention')).length,
|
||||
update:items.filter(item => matches(item, 'update')).length,
|
||||
review:items.filter(item => matches(item, 'review')).length,
|
||||
});
|
||||
const closeProgressiveDetail = ({ restoreFocus = true } = {}) => {
|
||||
if (!detail || detail.hidden) return;
|
||||
detail.hidden = true;
|
||||
if (restoreFocus) detailTrigger?.focus?.();
|
||||
detailTrigger = null;
|
||||
openWork = null;
|
||||
};
|
||||
const openProgressiveDetail = (item, trigger) => {
|
||||
if (!detail || !item) return;
|
||||
detailTrigger = trigger;
|
||||
openWork = item;
|
||||
detailTitle.textContent = item.title || item.key || 'Untitled work';
|
||||
detailMeta.textContent = (item.key || 'Unknown work item') + ' · ' +
|
||||
(item.kind === 'pull' ? 'Pull request' : 'Issue');
|
||||
detailReason.textContent = item.reason || 'Assigned to you';
|
||||
const href = safeUrl(item.url);
|
||||
openGitea.hidden = !href;
|
||||
if (href) openGitea.href = href;
|
||||
else openGitea.removeAttribute?.('href');
|
||||
detail.hidden = false;
|
||||
closeDetail?.focus?.();
|
||||
};
|
||||
const updateCounts = () => {
|
||||
['all','attention','filed','authored','issue','pull','review','update'].forEach(filter => {
|
||||
const count = filter === 'all' ? items.length : items.filter(item => matches(item, filter)).length;
|
||||
const element = document.querySelector('[data-work-count="' + filter + '"]');
|
||||
if (element) element.textContent = String(count);
|
||||
});
|
||||
};
|
||||
const render = () => {
|
||||
if (stopped || !list) return;
|
||||
const visible = visibleItems();
|
||||
list.innerHTML = contextUnavailable && !items.length ?
|
||||
'<div class="muted">Assigned work is reconnecting…</div>' : deferredQueues[active] ?
|
||||
'<div class="muted">' + deferredQueues[active] + ' is still loading…</div>' : visible.length ? visible.map((item, index) => {
|
||||
const title = escapeHtml(item.title || item.key || 'Untitled work');
|
||||
const context = escapeHtml(item.key || '');
|
||||
const reason = escapeHtml(item.reason || 'Assigned to you');
|
||||
return '<article class="my-work-card progressive-my-work-card">' +
|
||||
'<button class="my-work-card-main" type="button" data-progressive-work-index="' + index + '">' +
|
||||
'<strong>' + title + '</strong><span class="small">' + context + ' · ' + reason + '</span>' +
|
||||
'</button></article>';
|
||||
}).join('') : '<div class="muted">No work in this queue.</div>';
|
||||
filters.forEach(button => button.setAttribute('aria-pressed', String(button.dataset.workFilter === active)));
|
||||
};
|
||||
filters.forEach(button => {
|
||||
const listener = () => { active = button.dataset.workFilter || 'all'; selectedByUser = true; render(); };
|
||||
button.addEventListener('click', listener);
|
||||
listeners.push([button, listener]);
|
||||
});
|
||||
const openListener = event => {
|
||||
const trigger = event.target?.closest?.('[data-progressive-work-index]');
|
||||
if (!trigger) return;
|
||||
const item = visibleItems()[Number(trigger.dataset.progressiveWorkIndex)];
|
||||
if (!item) return;
|
||||
event.preventDefault?.();
|
||||
openProgressiveDetail(item, trigger);
|
||||
};
|
||||
const closeListener = () => closeProgressiveDetail();
|
||||
const keyListener = event => {
|
||||
if (event.key !== 'Escape' || detail?.hidden) return;
|
||||
event.preventDefault?.();
|
||||
closeProgressiveDetail();
|
||||
};
|
||||
list?.addEventListener?.('click', openListener);
|
||||
closeDetail?.addEventListener?.('click', closeListener);
|
||||
lifecycleTarget.addEventListener?.('keydown', keyListener);
|
||||
|
||||
const applySnapshot = snapshot => {
|
||||
if (stopped) return false;
|
||||
const transferable = snapshot && typeof snapshot === 'object' &&
|
||||
Object.prototype.hasOwnProperty.call(snapshot, 'context');
|
||||
const contextDegraded = transferable && (
|
||||
!snapshot.context || snapshot.freshness?.sections?.context?.degraded
|
||||
);
|
||||
if (contextDegraded) {
|
||||
contextUnavailable = true;
|
||||
render();
|
||||
notify();
|
||||
if (status) status.textContent = 'Assigned work is reconnecting…';
|
||||
return false;
|
||||
}
|
||||
contextUnavailable = false;
|
||||
if (transferable) liveSnapshot = snapshot;
|
||||
const context = snapshot?.context || snapshot || {};
|
||||
confirmedLogin = String(context.user?.login || '').trim();
|
||||
items = buildMyWork({ ...context, notifications:snapshot?.notifications || context.notifications || [] });
|
||||
updateCounts();
|
||||
render();
|
||||
notify();
|
||||
const assigned = items.filter(item => item.is_assigned).length;
|
||||
if (status) status.textContent = assigned + ' assigned work item' + (assigned === 1 ? '' : 's') + ' ready.';
|
||||
return true;
|
||||
};
|
||||
|
||||
if (typeof createContextPoller === 'function') {
|
||||
poller = createContextPoller({
|
||||
...pollerOptions,
|
||||
fetchContext: fetchProgressiveSnapshot,
|
||||
onSnapshot: applySnapshot,
|
||||
onError: () => {
|
||||
if (status && !stopped) status.textContent = 'Assigned work is reconnecting…';
|
||||
},
|
||||
isHidden: pollerOptions.isHidden || (() => Boolean(document.hidden)),
|
||||
});
|
||||
const recover = () => {
|
||||
if (!document.hidden) void poller.refresh();
|
||||
};
|
||||
['online', 'visibilitychange'].forEach(eventName => {
|
||||
lifecycleTarget.addEventListener?.(eventName, recover);
|
||||
lifecycleListeners.push([eventName, recover]);
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
login() { return confirmedLogin; },
|
||||
counts() { return queueCounts(); },
|
||||
subscribe(subscriber) {
|
||||
subscribers.add(subscriber);
|
||||
return () => subscribers.delete(subscriber);
|
||||
},
|
||||
openFirst() {
|
||||
const item = visibleItems()[0];
|
||||
if (!item) return deferredQueues[active] ? 'loading' : 'empty';
|
||||
const trigger = list?.querySelector?.('[data-progressive-work-index="0"]') || null;
|
||||
openProgressiveDetail(item, trigger);
|
||||
return 'opened';
|
||||
},
|
||||
selectQueue(name, {openFirst = false} = {}) {
|
||||
const allowed = new Set(['all','attention','filed','authored','issue','pull','review','update','today','agenda','later','draft']);
|
||||
if (!allowed.has(name)) return 'unsupported';
|
||||
active = name;
|
||||
selectedByUser = true;
|
||||
render();
|
||||
notify();
|
||||
return openFirst ? this.openFirst() : 'selected';
|
||||
},
|
||||
handoff() {
|
||||
const state = { selectedFilter:selectedByUser ? active : null };
|
||||
if (openWork) {
|
||||
state.openWork = {
|
||||
kind:openWork.kind, key:openWork.key, number:openWork.number,
|
||||
repository:openWork.repository,
|
||||
};
|
||||
openWork = null;
|
||||
}
|
||||
if (liveSnapshot) {
|
||||
state.liveSnapshot = liveSnapshot;
|
||||
liveSnapshot = null;
|
||||
liveSnapshotPromise = null;
|
||||
} else if (liveSnapshotPromise) {
|
||||
state.liveSnapshotPromise = liveSnapshotPromise;
|
||||
liveSnapshotPromise = null;
|
||||
}
|
||||
return state;
|
||||
},
|
||||
async start() {
|
||||
if (status) status.textContent = 'Loading assigned work…';
|
||||
if (poller) {
|
||||
const request = poller.start();
|
||||
liveSnapshotPromise = request.then(snapshot => (
|
||||
snapshot && typeof snapshot === 'object' &&
|
||||
Object.prototype.hasOwnProperty.call(snapshot, 'context') ? snapshot : null
|
||||
));
|
||||
return Boolean(await request);
|
||||
}
|
||||
const request = Promise.resolve().then(() => fetchProgressiveSnapshot());
|
||||
liveSnapshotPromise = request.then(snapshot => (
|
||||
snapshot && typeof snapshot === 'object' &&
|
||||
Object.prototype.hasOwnProperty.call(snapshot, 'context') ? snapshot : null
|
||||
), () => null);
|
||||
try {
|
||||
const snapshot = await request;
|
||||
if (stopped) return false;
|
||||
const applied = applySnapshot(snapshot);
|
||||
if (!liveSnapshot) liveSnapshotPromise = null;
|
||||
return applied;
|
||||
} catch (_error) {
|
||||
if (status && !stopped) status.textContent = 'Assigned work is reconnecting…';
|
||||
return false;
|
||||
}
|
||||
},
|
||||
stop() {
|
||||
stopped = true;
|
||||
poller?.stop();
|
||||
listeners.forEach(([button, listener]) => button.removeEventListener?.('click', listener));
|
||||
list?.removeEventListener?.('click', openListener);
|
||||
closeDetail?.removeEventListener?.('click', closeListener);
|
||||
lifecycleTarget.removeEventListener?.('keydown', keyListener);
|
||||
lifecycleListeners.forEach(([eventName, listener]) =>
|
||||
lifecycleTarget.removeEventListener?.(eventName, listener));
|
||||
subscribers.clear();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
|
||||
window.stackchainProgressiveMyWork = createProgressiveMyWork({
|
||||
document,
|
||||
lifecycleTarget: window,
|
||||
liveSnapshot:window.stackchainProgressiveLiveSnapshot,
|
||||
fetchSnapshot: async (revisions = {}, { signal } = {}) => {
|
||||
const query = createContextPoller.buildRevisionQuery(revisions);
|
||||
const response = await fetch('api/v1/live' + (query ? '?' + query : ''), {
|
||||
headers:{Accept:'application/json'}, signal,
|
||||
});
|
||||
if (!response.ok) {
|
||||
const error = new Error('HTTP ' + response.status);
|
||||
error.retryAfterMs = createContextPoller.retryAfterMs(response.headers.get('Retry-After'));
|
||||
throw error;
|
||||
}
|
||||
return response.json();
|
||||
},
|
||||
});
|
||||
void window.stackchainProgressiveMyWork.start();
|
||||
}
|
||||
|
||||
if (typeof module !== 'undefined' && module.exports) module.exports = createProgressiveMyWork;
|
||||
+596
-6
@@ -187,17 +187,28 @@ function ownershipExitMessage(item, action, transitionResult) {
|
||||
'. Next work item opened.' : '. Choose the next ready Today item.');
|
||||
}
|
||||
|
||||
function resetOwnershipControls(doc, item, checkpointed) {
|
||||
function applyOwnershipCapabilities(doc, capabilities = null) {
|
||||
const ownership = doc.querySelector('#pull-ownership');
|
||||
const assigned = capabilities?.assigned !== false;
|
||||
ownership.hidden = !assigned;
|
||||
ownership.inert = !assigned;
|
||||
return assigned;
|
||||
}
|
||||
|
||||
function resetOwnershipControls(doc, item, checkpointed, capabilities = null) {
|
||||
const qs = selector => doc.querySelector(selector);
|
||||
const assigned = applyOwnershipCapabilities(doc, capabilities);
|
||||
resetLifecycleControls(doc, null);
|
||||
qs('#pull-ownership').open = false;
|
||||
qs('#pull-handoff-recipient').innerHTML = '<option value="">Select a teammate</option>';
|
||||
qs('#pull-handoff-recipient').disabled = true;
|
||||
qs('#confirm-pull-handoff').disabled = true;
|
||||
qs('#confirm-pull-handoff').textContent = checkpointed(item) ? 'Hand off & next' : 'Confirm handoff';
|
||||
qs('#load-pull-handoff').disabled = false;
|
||||
qs('#release-pull').disabled = false;
|
||||
qs('#load-pull-handoff').disabled = !assigned;
|
||||
qs('#release-pull').disabled = !assigned;
|
||||
qs('#release-pull').textContent = checkpointed(item) ? 'Release & next' : 'Release assignment';
|
||||
qs('#pull-handoff-status').textContent = 'Load teammates to transfer ownership.';
|
||||
qs('#pull-handoff-status').textContent = assigned ?
|
||||
'Load teammates to transfer ownership.' : 'Assignment controls are not available for this pull request.';
|
||||
qs('#edit-pull-content').hidden = true;
|
||||
qs('#pull-edit-form').hidden = true;
|
||||
qs('#pull-edit-status').textContent = '';
|
||||
@@ -220,6 +231,46 @@ function resetReviewRequestControls(doc, detail) {
|
||||
qs('#pull-feedback-status').textContent = '';
|
||||
}
|
||||
|
||||
function resetBranchUpdateControls(doc, detail) {
|
||||
const panel = doc.querySelector('#pull-branch-update');
|
||||
if (!panel) return;
|
||||
const eligible = detail?.capabilities?.authored === true && detail?.state === 'open' &&
|
||||
detail?.draft !== true && detail?.merged !== true && detail?.mergeable === false && detail?.head_sha;
|
||||
panel.hidden = !eligible;
|
||||
doc.querySelector('#update-pull-branch').disabled = false;
|
||||
doc.querySelector('#pull-branch-update-status').textContent = eligible ?
|
||||
'Merge the latest base branch into this pull request. Reviews and checks may run again.' : '';
|
||||
}
|
||||
|
||||
function bindBranchUpdateControls(doc, controller, getSelected, getDetail) {
|
||||
const button = doc.querySelector('#update-pull-branch');
|
||||
if (!button || button.dataset.bound === 'true') return;
|
||||
button.dataset.bound = 'true';
|
||||
button.addEventListener('click', async () => {
|
||||
const item = getSelected?.();
|
||||
const detail = getDetail?.();
|
||||
if (!item || !detail?.head_sha || detail?.capabilities?.authored !== true ||
|
||||
!globalThis.confirm('Update ' + item.key + ' with the latest base branch? Reviews and checks may run again.')) return;
|
||||
button.disabled = true;
|
||||
const status = doc.querySelector('#pull-branch-update-status');
|
||||
status.textContent = 'Updating branch…';
|
||||
try {
|
||||
const result = await controller.updateBranch(item, detail.head_sha);
|
||||
if (getSelected?.() !== item || getDetail?.() !== detail) return;
|
||||
Object.assign(detail, result, { mergeable:null, ci_state:'pending', reviewers:[] });
|
||||
status.textContent = 'Branch updated. Refreshing checks and review state…';
|
||||
doc.querySelector('#pull-review-retry')?.click();
|
||||
status.textContent = 'Branch updated to ' + result.head_sha.slice(0, 8) + '. Review the refreshed checks before merging.';
|
||||
button.hidden = true;
|
||||
doc.querySelector('#refresh-pull-checks')?.focus();
|
||||
} catch (error) {
|
||||
status.textContent = error.message + ' Reload the latest pull request state before retrying.';
|
||||
button.disabled = false;
|
||||
button.focus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function bindReviewRequestControls(doc, controller, getSelected, getDetail, getLogin) {
|
||||
const qs = selector => doc.querySelector(selector);
|
||||
const load = qs('#load-pull-reviewers');
|
||||
@@ -227,6 +278,9 @@ function bindReviewRequestControls(doc, controller, getSelected, getDetail, getL
|
||||
load.dataset.reviewRequestBound = 'true';
|
||||
controller.setReviewDetail = detail => {
|
||||
resetReviewRequestControls(doc, detail);
|
||||
resetBranchUpdateControls(doc, detail);
|
||||
applyOwnershipCapabilities(doc, detail?.capabilities);
|
||||
resetLifecycleControls(doc, detail?.saved_at ? null : detail);
|
||||
controller.edit?.setDetail(detail, Boolean(detail?.saved_at));
|
||||
const publishable = detail?.state === 'open' && detail?.draft === true &&
|
||||
detail?.author === getLogin?.() && detail?.head_sha;
|
||||
@@ -359,11 +413,49 @@ function bindFeedbackControls(doc, controller, getSelected, getDetail, getLogin)
|
||||
const save = () => {
|
||||
if (active) controller.saveFeedbackPass(active.item, active.detail, active.reviewer, active.login, active.state);
|
||||
};
|
||||
const clearSuggestion = () => {
|
||||
qs('#pull-feedback-suggestion-preview').hidden = true;
|
||||
qs('#cancel-pull-feedback-suggestion').hidden = true;
|
||||
qs('#stage-pull-feedback-suggestion').hidden = true;
|
||||
qs('#apply-pull-feedback-suggestion').hidden = true;
|
||||
if (active) active.suggestion = null;
|
||||
};
|
||||
const suggestedFile = (file, suggestion) => {
|
||||
const line = Number(suggestion?.line);
|
||||
if (!Number.isInteger(line) || line < 1 || typeof suggestion?.content !== 'string') return null;
|
||||
const trailingNewline = file.content.endsWith('\n');
|
||||
const lines = file.content.split('\n');
|
||||
if (trailingNewline) lines.pop();
|
||||
if (line > lines.length) return null;
|
||||
const before = lines[line - 1];
|
||||
lines.splice(line - 1, 1, ...suggestion.content.split('\n'));
|
||||
return { before, after:suggestion.content, content:lines.join('\n') + (trailingNewline ? '\n' : '') };
|
||||
};
|
||||
const renderBatchButton = () => {
|
||||
const count = active?.batch ? Object.values(active.batch)
|
||||
.reduce((total, file) => total + file.suggestions.length, 0) : 0;
|
||||
const button = qs('#review-pull-feedback-batch');
|
||||
button.hidden = count < 2;
|
||||
button.textContent = 'Review fixes (' + count + ')';
|
||||
};
|
||||
const rebuildBatchFile = entry => {
|
||||
const trailingNewline = entry.file.content.endsWith('\n');
|
||||
const lines = entry.file.content.split('\n');
|
||||
if (trailingNewline) lines.pop();
|
||||
const ordered = [...entry.suggestions].sort((left, right) => right.line - left.line);
|
||||
if (new Set(ordered.map(item => item.line)).size !== ordered.length) return null;
|
||||
for (const suggestion of ordered) {
|
||||
if (suggestion.line < 1 || suggestion.line > lines.length) return null;
|
||||
lines.splice(suggestion.line - 1, 1, ...suggestion.content.split('\n'));
|
||||
}
|
||||
return lines.join('\n') + (trailingNewline ? '\n' : '');
|
||||
};
|
||||
const render = () => {
|
||||
if (!active) return;
|
||||
const items = comments();
|
||||
active.state.index = Math.max(0, Math.min(Number(active.state.index) || 0, items.length - 1));
|
||||
const comment = current();
|
||||
if (active.suggestion && active.suggestion.commentId !== comment.id) clearSuggestion();
|
||||
const response = active.state.responses[String(comment.id)] || {};
|
||||
qs('#pull-feedback-progress').textContent = 'Comment ' + (active.state.index + 1) + ' of ' + items.length;
|
||||
qs('#pull-feedback-heading').textContent = 'Address @' + active.reviewer.login + '’s feedback';
|
||||
@@ -378,6 +470,16 @@ function bindFeedbackControls(doc, controller, getSelected, getDetail, getLogin)
|
||||
qs('#finish-pull-feedback').disabled = active.state.posted === true ||
|
||||
items.some(item => !active.state.responses[String(item.id)]?.disposition);
|
||||
qs('#request-feedback-review').hidden = active.state.posted !== true;
|
||||
qs('#make-pull-feedback-fix').hidden = active.detail?.capabilities?.authored !== true ||
|
||||
active.detail?.state !== 'open' || active.detail?.merged === true || !comment.path;
|
||||
const canSuggest = active.detail?.capabilities?.authored === true && active.detail?.state === 'open' &&
|
||||
active.detail?.merged !== true && active.reviewer?.head_sha === active.detail?.head_sha &&
|
||||
comment.suggestion?.line === comment.line && typeof comment.suggestion?.content === 'string';
|
||||
qs('#review-pull-feedback-suggestion').hidden = !canSuggest;
|
||||
qs('#review-pull-feedback-suggestion').disabled = canSuggest && globalThis.navigator?.onLine === false;
|
||||
if (canSuggest && globalThis.navigator?.onLine === false) {
|
||||
qs('#pull-feedback-status').textContent = 'Reconnect to apply suggestion.';
|
||||
}
|
||||
const found = focusPullFile(doc, comment.path);
|
||||
qs('#pull-feedback-context').textContent = found ?
|
||||
'Matching change opened below.' : 'Matching change is unavailable in this preview.';
|
||||
@@ -418,13 +520,235 @@ function bindFeedbackControls(doc, controller, getSelected, getDetail, getLogin)
|
||||
const reviewer = (detail?.reviewers || []).find(candidate => candidate.review_id === reviewId);
|
||||
if (!detail || !item || !reviewer) return;
|
||||
const login = getLogin?.() || '';
|
||||
active = { item, detail, reviewer, login,
|
||||
active = { item, detail, reviewer, login, batch:{},
|
||||
state:controller.loadFeedbackPass(item, detail, reviewer, login) };
|
||||
panel.hidden = false;
|
||||
qs('#pull-feedback-file-editor').hidden = true;
|
||||
qs('#pull-feedback-suggestion-preview').hidden = true;
|
||||
qs('#pull-feedback-batch-review').hidden = true;
|
||||
qs('#cancel-pull-feedback-fix').hidden = true;
|
||||
qs('#commit-pull-feedback-fix').hidden = true;
|
||||
active.file = null;
|
||||
active.suggestion = null;
|
||||
renderBatchButton();
|
||||
qs('#pull-feedback-status').textContent = active.state.posted ?
|
||||
'Response already posted. You can request an updated review.' : 'Progress saves on this device.';
|
||||
render();
|
||||
});
|
||||
qs('#review-pull-feedback-suggestion').addEventListener('click', async () => {
|
||||
const comment = current();
|
||||
if (!active || !comment?.suggestion || globalThis.navigator?.onLine === false) {
|
||||
qs('#pull-feedback-status').textContent = 'Reconnect to apply suggestion.';
|
||||
return;
|
||||
}
|
||||
const button = qs('#review-pull-feedback-suggestion');
|
||||
button.disabled = true;
|
||||
qs('#pull-feedback-status').textContent = 'Loading the current line for review…';
|
||||
try {
|
||||
const file = await controller.loadFeedbackFile(active.item, comment.path, active.detail.head_sha);
|
||||
if (!active || file.head_sha !== active.detail.head_sha || file.path !== comment.path) return;
|
||||
const change = suggestedFile(file, comment.suggestion);
|
||||
if (!change) throw new Error('The suggested line is no longer available.');
|
||||
active.suggestion = { file, content:change.content, commentId:comment.id };
|
||||
qs('#pull-feedback-suggestion-before').textContent = change.before;
|
||||
qs('#pull-feedback-suggestion-after').textContent = change.after;
|
||||
qs('#pull-feedback-suggestion-message').value = 'fix: apply review suggestion';
|
||||
qs('#pull-feedback-file-editor').hidden = true;
|
||||
qs('#pull-feedback-suggestion-preview').hidden = false;
|
||||
qs('#cancel-pull-feedback-suggestion').hidden = false;
|
||||
qs('#stage-pull-feedback-suggestion').hidden = false;
|
||||
qs('#apply-pull-feedback-suggestion').hidden = false;
|
||||
qs('#pull-feedback-status').textContent = 'Review the bounded replacement before committing.';
|
||||
qs('#apply-pull-feedback-suggestion').focus();
|
||||
} catch (error) {
|
||||
qs('#pull-feedback-status').textContent = error.message + ' Use the full-file editor if needed.';
|
||||
button.focus();
|
||||
} finally {
|
||||
button.disabled = false;
|
||||
}
|
||||
});
|
||||
qs('#cancel-pull-feedback-suggestion').addEventListener('click', () => {
|
||||
clearSuggestion();
|
||||
qs('#review-pull-feedback-suggestion').focus();
|
||||
});
|
||||
qs('#stage-pull-feedback-suggestion').addEventListener('click', () => {
|
||||
if (!active?.suggestion) return;
|
||||
const pending = active.suggestion;
|
||||
const path = pending.file.path;
|
||||
const stagedCount = Object.values(active.batch)
|
||||
.reduce((total, file) => total + file.suggestions.length, 0);
|
||||
if (stagedCount >= 8) {
|
||||
qs('#pull-feedback-status').textContent = 'Commit this bounded batch before staging more suggestions.';
|
||||
return;
|
||||
}
|
||||
const entry = active.batch[path] || {file:pending.file, suggestions:[]};
|
||||
if (entry.file.blob_sha !== pending.file.blob_sha ||
|
||||
entry.suggestions.some(item => item.commentId === pending.commentId)) return;
|
||||
const comment = current();
|
||||
entry.suggestions.push({
|
||||
line:Number(comment.suggestion.line), content:comment.suggestion.content,
|
||||
commentId:pending.commentId,
|
||||
});
|
||||
entry.content = rebuildBatchFile(entry);
|
||||
if (entry.content === null) {
|
||||
entry.suggestions.pop();
|
||||
qs('#pull-feedback-status').textContent = 'This suggestion overlaps a staged fix. Keep one of the conflicting changes.';
|
||||
return;
|
||||
}
|
||||
active.batch[path] = entry;
|
||||
clearSuggestion();
|
||||
renderBatchButton();
|
||||
qs('#pull-feedback-status').textContent = 'Suggestion added to the fix batch. Keep reviewing this feedback.';
|
||||
qs('#next-pull-feedback').focus();
|
||||
});
|
||||
qs('#review-pull-feedback-batch').addEventListener('click', () => {
|
||||
if (!active?.batch) return;
|
||||
const list = qs('#pull-feedback-batch-items');
|
||||
list.replaceChildren(...Object.values(active.batch).map(entry => {
|
||||
const item = doc.createElement('li');
|
||||
item.textContent = entry.file.path + ' · ' + entry.suggestions.length +
|
||||
(entry.suggestions.length === 1 ? ' suggestion' : ' suggestions');
|
||||
return item;
|
||||
}));
|
||||
qs('#pull-feedback-batch-review').hidden = false;
|
||||
qs('#cancel-pull-feedback-batch').hidden = false;
|
||||
qs('#commit-pull-feedback-batch').hidden = false;
|
||||
qs('#pull-feedback-batch-review').scrollIntoView({block:'center', behavior:'smooth'});
|
||||
qs('#commit-pull-feedback-batch').focus();
|
||||
});
|
||||
qs('#cancel-pull-feedback-batch').addEventListener('click', () => {
|
||||
qs('#pull-feedback-batch-review').hidden = true;
|
||||
qs('#cancel-pull-feedback-batch').hidden = true;
|
||||
qs('#commit-pull-feedback-batch').hidden = true;
|
||||
qs('#review-pull-feedback-batch').focus();
|
||||
});
|
||||
qs('#commit-pull-feedback-batch').addEventListener('click', async () => {
|
||||
if (!active?.batch) return;
|
||||
const entries = Object.values(active.batch);
|
||||
const count = entries.reduce((total, entry) => total + entry.suggestions.length, 0);
|
||||
const message = qs('#pull-feedback-batch-message').value.trim();
|
||||
if (count < 2 || !message) return;
|
||||
if (!globalThis.confirm('Commit ' + count + ' suggested changes to ' + active.item.key + '?')) return;
|
||||
const button = qs('#commit-pull-feedback-batch');
|
||||
button.disabled = true;
|
||||
qs('#pull-feedback-status').textContent = 'Committing and verifying all suggested changes…';
|
||||
try {
|
||||
const result = await controller.commitFeedbackBatch(active.item, {
|
||||
files:entries.map(entry => ({
|
||||
path:entry.file.path, content:entry.content,
|
||||
expectedBlobSha:entry.file.blob_sha,
|
||||
})),
|
||||
suggestionCount:count, message, expectedHeadSha:active.detail.head_sha,
|
||||
});
|
||||
active.detail.head_sha = result.head_sha;
|
||||
active.state.headSha = result.head_sha;
|
||||
active.batch = {};
|
||||
save();
|
||||
qs('#pull-feedback-batch-review').hidden = true;
|
||||
qs('#cancel-pull-feedback-batch').hidden = true;
|
||||
qs('#commit-pull-feedback-batch').hidden = true;
|
||||
renderBatchButton();
|
||||
qs('#pull-feedback-status').textContent = count + ' suggested changes committed. Mark each comment Addressed when satisfied.';
|
||||
render();
|
||||
} catch (error) {
|
||||
qs('#pull-feedback-status').textContent = error.message + ' Batch kept; reload if the branch changed, or retry.';
|
||||
button.disabled = false;
|
||||
button.focus();
|
||||
}
|
||||
});
|
||||
qs('#apply-pull-feedback-suggestion').addEventListener('click', async () => {
|
||||
if (!active?.suggestion) return;
|
||||
const message = qs('#pull-feedback-suggestion-message').value.trim();
|
||||
if (!message) {
|
||||
qs('#pull-feedback-status').textContent = 'Enter a commit message before committing.';
|
||||
return;
|
||||
}
|
||||
if (!globalThis.confirm('Commit this suggested change to ' + active.item.key + '?')) return;
|
||||
const button = qs('#apply-pull-feedback-suggestion');
|
||||
button.disabled = true;
|
||||
const pending = active.suggestion;
|
||||
qs('#pull-feedback-status').textContent = 'Committing and verifying the suggested change…';
|
||||
try {
|
||||
const result = await controller.commitFeedbackFix(active.item, {
|
||||
path:pending.file.path, content:pending.content, message,
|
||||
expectedHeadSha:pending.file.head_sha, expectedBlobSha:pending.file.blob_sha,
|
||||
});
|
||||
active.detail.head_sha = result.head_sha;
|
||||
active.state.headSha = result.head_sha;
|
||||
clearSuggestion();
|
||||
save();
|
||||
qs('#pull-feedback-status').textContent = 'Suggested change committed. Mark the comment Addressed when satisfied.';
|
||||
render();
|
||||
} catch (error) {
|
||||
qs('#pull-feedback-status').textContent = error.message + ' Preview kept; reload if the branch changed, or retry.';
|
||||
button.disabled = false;
|
||||
button.focus();
|
||||
}
|
||||
});
|
||||
qs('#make-pull-feedback-fix').addEventListener('click', async () => {
|
||||
const comment = current();
|
||||
if (!active || !comment?.path || active.detail?.capabilities?.authored !== true) return;
|
||||
const button = qs('#make-pull-feedback-fix');
|
||||
button.disabled = true;
|
||||
qs('#pull-feedback-status').textContent = 'Loading the current pull file…';
|
||||
try {
|
||||
const file = await controller.loadFeedbackFile(active.item, comment.path, active.detail.head_sha);
|
||||
if (!active || file.head_sha !== active.detail.head_sha || file.path !== comment.path) return;
|
||||
active.file = file;
|
||||
clearSuggestion();
|
||||
qs('#pull-feedback-file-path').textContent = file.path;
|
||||
qs('#pull-feedback-file-content').value = file.content;
|
||||
qs('#pull-feedback-commit-message').value = 'fix: address review feedback';
|
||||
qs('#pull-feedback-file-editor').hidden = false;
|
||||
qs('#cancel-pull-feedback-fix').hidden = false;
|
||||
qs('#commit-pull-feedback-fix').hidden = false;
|
||||
qs('#pull-feedback-status').textContent = 'Edit the bounded file, then commit it to this pull branch.';
|
||||
qs('#pull-feedback-file-content').focus();
|
||||
} catch (error) {
|
||||
qs('#pull-feedback-status').textContent = error.message + ' Retry without losing your feedback progress.';
|
||||
} finally {
|
||||
button.disabled = false;
|
||||
}
|
||||
});
|
||||
qs('#cancel-pull-feedback-fix').addEventListener('click', () => {
|
||||
qs('#pull-feedback-file-editor').hidden = true;
|
||||
qs('#cancel-pull-feedback-fix').hidden = true;
|
||||
qs('#commit-pull-feedback-fix').hidden = true;
|
||||
active.file = null;
|
||||
qs('#make-pull-feedback-fix').focus();
|
||||
});
|
||||
qs('#commit-pull-feedback-fix').addEventListener('click', async () => {
|
||||
if (!active?.file) return;
|
||||
const content = qs('#pull-feedback-file-content').value;
|
||||
const message = qs('#pull-feedback-commit-message').value.trim();
|
||||
if (!message || content === active.file.content) {
|
||||
qs('#pull-feedback-status').textContent = 'Change the file and enter a commit message before committing.';
|
||||
return;
|
||||
}
|
||||
if (!globalThis.confirm('Commit this change to ' + active.item.key + '?')) return;
|
||||
const button = qs('#commit-pull-feedback-fix');
|
||||
button.disabled = true;
|
||||
qs('#pull-feedback-status').textContent = 'Committing and verifying the new pull head…';
|
||||
try {
|
||||
const result = await controller.commitFeedbackFix(active.item, {
|
||||
path:active.file.path, content, message,
|
||||
expectedHeadSha:active.file.head_sha, expectedBlobSha:active.file.blob_sha,
|
||||
});
|
||||
active.detail.head_sha = result.head_sha;
|
||||
active.state.headSha = result.head_sha;
|
||||
active.file = null;
|
||||
save();
|
||||
qs('#pull-feedback-file-editor').hidden = true;
|
||||
qs('#cancel-pull-feedback-fix').hidden = true;
|
||||
qs('#commit-pull-feedback-fix').hidden = true;
|
||||
qs('#pull-feedback-status').textContent = 'Code change committed. Mark the comment Addressed when satisfied.';
|
||||
render();
|
||||
} catch (error) {
|
||||
qs('#pull-feedback-status').textContent = error.message + ' Draft kept; reload if the branch changed, or retry.';
|
||||
button.disabled = false;
|
||||
button.focus();
|
||||
}
|
||||
});
|
||||
panel.querySelector('.pull-feedback-dispositions').addEventListener('click', event => {
|
||||
const disposition = event.target.dataset?.feedbackDisposition;
|
||||
const comment = current();
|
||||
@@ -564,7 +888,10 @@ function bindContextEditor(doc, controller, getSelected, getDetail, getLogin) {
|
||||
|
||||
function bindOwnershipControls(doc, controller, getSelected, finish, getDetail, getLogin) {
|
||||
bindReviewRequestControls(doc, controller, getSelected, getDetail, getLogin);
|
||||
bindBranchUpdateControls(doc, controller, getSelected, getDetail);
|
||||
bindFeedbackControls(doc, controller, getSelected, getDetail, getLogin);
|
||||
bindCheckRecovery(doc, controller, getSelected, getDetail);
|
||||
bindLifecycleControls(doc, controller, getSelected, getDetail, result => controller.onState?.(result));
|
||||
controller.edit = bindContextEditor(doc, controller, getSelected, getDetail, getLogin);
|
||||
const qs = selector => doc.querySelector(selector);
|
||||
const load = qs('#load-pull-handoff');
|
||||
@@ -630,18 +957,21 @@ function bindOwnershipControls(doc, controller, getSelected, finish, getDetail,
|
||||
});
|
||||
}
|
||||
|
||||
function createPullSheet({ fetchJson, storage, createConversationPager = globalThis.createConversationPager, createOperationId = () => globalThis.crypto?.randomUUID?.() || String(Date.now()) + '-' + Math.random() }) {
|
||||
function createPullSheet({ fetchJson, storage, onState, createConversationPager = globalThis.createConversationPager, createOperationId = () => globalThis.crypto?.randomUUID?.() || String(Date.now()) + '-' + Math.random() }) {
|
||||
let commentRequest = null;
|
||||
let mergeRequest = null;
|
||||
let checkRequest = null;
|
||||
let ownershipRequest = null;
|
||||
let branchUpdateRequest = null;
|
||||
let candidateRequest = null;
|
||||
let reviewCandidateRequest = null;
|
||||
let reviewRequestMutation = null;
|
||||
let reviewCancelMutation = null;
|
||||
let readyMutation = null;
|
||||
let lifecycleMutation = null;
|
||||
let editRequest = null;
|
||||
let feedbackRequest = null;
|
||||
let feedbackFixRequest = null;
|
||||
const reviewRequests = new Map();
|
||||
const reviewCache = new Map();
|
||||
const feedbackRequests = new Map();
|
||||
@@ -668,6 +998,7 @@ function createPullSheet({ fetchJson, storage, createConversationPager = globalT
|
||||
}
|
||||
|
||||
return {
|
||||
onState,
|
||||
load(item) {
|
||||
return fetchJson(pathFor(item) + '/detail', { headers: { Accept: 'application/json' } });
|
||||
},
|
||||
@@ -704,6 +1035,55 @@ function createPullSheet({ fetchJson, storage, createConversationPager = globalT
|
||||
feedbackRequests.set(key, request);
|
||||
return request;
|
||||
},
|
||||
loadFeedbackFile(item, path, expectedHeadSha) {
|
||||
return fetchJson(pathFor(item) + '/feedback-file?path=' + encodeURIComponent(path) +
|
||||
'&expected_head_sha=' + encodeURIComponent(expectedHeadSha), {
|
||||
headers:{ Accept:'application/json' },
|
||||
});
|
||||
},
|
||||
commitFeedbackFix(item, draft) {
|
||||
if (feedbackFixRequest) return feedbackFixRequest;
|
||||
feedbackFixRequest = fetchJson(pathFor(item) + '/feedback-file', {
|
||||
method:'PATCH',
|
||||
headers:{ Accept:'application/json', 'Content-Type':'application/json' },
|
||||
body:JSON.stringify({
|
||||
path:draft.path, content:draft.content, message:draft.message,
|
||||
expected_head_sha:draft.expectedHeadSha,
|
||||
expected_blob_sha:draft.expectedBlobSha,
|
||||
}),
|
||||
}).then(result => {
|
||||
if (!result?.head_sha || result.head_sha === draft.expectedHeadSha || result.path !== draft.path) {
|
||||
throw new Error('The feedback fix was not confirmed.');
|
||||
}
|
||||
return result;
|
||||
}).finally(() => { feedbackFixRequest = null; });
|
||||
return feedbackFixRequest;
|
||||
},
|
||||
commitFeedbackBatch(item, draft) {
|
||||
if (feedbackFixRequest) return feedbackFixRequest;
|
||||
feedbackFixRequest = fetchJson(pathFor(item) + '/feedback-batch', {
|
||||
method:'POST',
|
||||
headers:{ Accept:'application/json', 'Content-Type':'application/json' },
|
||||
body:JSON.stringify({
|
||||
files:draft.files.map(file => ({
|
||||
path:file.path, content:file.content,
|
||||
expected_blob_sha:file.expectedBlobSha,
|
||||
})),
|
||||
suggestion_count:draft.suggestionCount,
|
||||
message:draft.message, expected_head_sha:draft.expectedHeadSha,
|
||||
}),
|
||||
}).then(result => {
|
||||
const expectedPaths = draft.files.map(file => file.path);
|
||||
if (!result?.head_sha || result.head_sha === draft.expectedHeadSha ||
|
||||
!Array.isArray(result.paths) || result.paths.length !== expectedPaths.length ||
|
||||
result.paths.some((path, index) => path !== expectedPaths[index]) ||
|
||||
result.suggestion_count !== draft.suggestionCount) {
|
||||
throw new Error('The suggestion batch was not confirmed.');
|
||||
}
|
||||
return result;
|
||||
}).finally(() => { feedbackFixRequest = null; });
|
||||
return feedbackFixRequest;
|
||||
},
|
||||
loadChecks(item) {
|
||||
if (checkRequest) return checkRequest;
|
||||
checkRequest = fetchJson(pathFor(item) + '/checks', {
|
||||
@@ -711,6 +1091,21 @@ function createPullSheet({ fetchJson, storage, createConversationPager = globalT
|
||||
}).finally(() => { checkRequest = null; });
|
||||
return checkRequest;
|
||||
},
|
||||
loadCheckFailure(item, expectedHeadSha, runId, jobIndex) {
|
||||
return fetchJson(pathFor(item) + '/checks/' + encodeURIComponent(runId) +
|
||||
'/jobs/' + encodeURIComponent(jobIndex) + '/failure?expected_head_sha=' +
|
||||
encodeURIComponent(expectedHeadSha), {
|
||||
headers: { Accept: 'application/json' },
|
||||
});
|
||||
},
|
||||
retryCheck(item, expectedHeadSha, runId, jobIndex) {
|
||||
return fetchJson(pathFor(item) + '/checks/' + encodeURIComponent(runId) +
|
||||
'/jobs/' + encodeURIComponent(jobIndex) + '/retry', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
|
||||
body: JSON.stringify({ expected_head_sha: expectedHeadSha }),
|
||||
});
|
||||
},
|
||||
loadHandoffCandidates(item) {
|
||||
if (candidateRequest) return candidateRequest;
|
||||
candidateRequest = fetchJson(pathFor(item) + '/handoff-candidates', {
|
||||
@@ -764,6 +1159,22 @@ function createPullSheet({ fetchJson, storage, createConversationPager = globalT
|
||||
}).finally(() => { readyMutation = null; });
|
||||
return readyMutation;
|
||||
},
|
||||
transition(item, expectedHeadSha, action) {
|
||||
if (lifecycleMutation) return lifecycleMutation;
|
||||
lifecycleMutation = fetchJson(pathFor(item) + '/' + action, {
|
||||
method:'PATCH',
|
||||
headers:{ Accept:'application/json', 'Content-Type':'application/json' },
|
||||
body:JSON.stringify({ expected_head_sha:expectedHeadSha }),
|
||||
}).then(result => {
|
||||
const expectedState = action === 'close' ? 'closed' : 'open';
|
||||
if (result?.number !== item.number || result?.head_sha !== expectedHeadSha ||
|
||||
result?.state !== expectedState || result?.merged === true) {
|
||||
throw new Error('Pull request state change was not confirmed.');
|
||||
}
|
||||
return result;
|
||||
}).finally(() => { lifecycleMutation = null; });
|
||||
return lifecycleMutation;
|
||||
},
|
||||
loadEditDraft(item) {
|
||||
try {
|
||||
const value = JSON.parse(storage?.getItem(editDraftKey(item)) || 'null');
|
||||
@@ -927,9 +1338,185 @@ function createPullSheet({ fetchJson, storage, createConversationPager = globalT
|
||||
}).finally(() => { mergeRequest = null; });
|
||||
return mergeRequest;
|
||||
},
|
||||
updateBranch(item, expectedHeadSha) {
|
||||
if (branchUpdateRequest) return branchUpdateRequest;
|
||||
branchUpdateRequest = fetchJson(pathFor(item) + '/update-branch', {
|
||||
method: 'POST',
|
||||
headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ expected_head_sha: expectedHeadSha }),
|
||||
}).then(result => {
|
||||
if (!result?.head_sha || result.head_sha === expectedHeadSha) {
|
||||
throw new Error('Branch update was not confirmed.');
|
||||
}
|
||||
return result;
|
||||
}).finally(() => { branchUpdateRequest = null; });
|
||||
return branchUpdateRequest;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function resetLifecycleControls(doc, detail) {
|
||||
const authored = detail?.capabilities?.authored === true;
|
||||
const lifecycle = doc.querySelector('#pull-lifecycle');
|
||||
if (!lifecycle) return;
|
||||
lifecycle.hidden = !authored || detail?.state !== 'open' || detail?.merged === true;
|
||||
doc.querySelector('#close-authored-pull').hidden = !authored || detail?.state !== 'open' || detail?.merged === true;
|
||||
doc.querySelector('#pull-close-receipt').hidden = true;
|
||||
doc.querySelector('#pull-lifecycle-status').textContent = '';
|
||||
doc.querySelector('#pull-reopen-status').textContent = '';
|
||||
}
|
||||
|
||||
function bindLifecycleControls(doc, controller, selectedPull, selectedDetail, applyResult) {
|
||||
const close = doc.querySelector('#close-authored-pull');
|
||||
const reopen = doc.querySelector('#reopen-authored-pull');
|
||||
close.addEventListener('click', async () => {
|
||||
const item = selectedPull();
|
||||
const detail = selectedDetail();
|
||||
if (!item || !detail?.head_sha || detail?.capabilities?.authored !== true ||
|
||||
!globalThis.confirm('Close ' + item.key + ' at head ' + detail.head_sha.slice(0, 12) + '?')) return;
|
||||
close.disabled = true;
|
||||
doc.querySelector('#pull-lifecycle-status').textContent = 'Closing pull request…';
|
||||
try {
|
||||
const result = await controller.transition(item, detail.head_sha, 'close');
|
||||
Object.assign(detail, result);
|
||||
applyResult(result);
|
||||
doc.querySelector('#pull-lifecycle').hidden = true;
|
||||
doc.querySelector('#pull-close-receipt').hidden = false;
|
||||
doc.querySelector('#pull-lifecycle-status').textContent = '';
|
||||
doc.querySelector('#pull-close-receipt-title').focus();
|
||||
} catch (error) {
|
||||
doc.querySelector('#pull-lifecycle-status').textContent = error.message + ' The pull request remains open; reload and retry.';
|
||||
close.disabled = false;
|
||||
close.focus();
|
||||
}
|
||||
});
|
||||
reopen.addEventListener('click', async () => {
|
||||
const item = selectedPull();
|
||||
const detail = selectedDetail();
|
||||
if (!item || !detail?.head_sha) return;
|
||||
reopen.disabled = true;
|
||||
doc.querySelector('#pull-reopen-status').textContent = 'Reopening pull request…';
|
||||
try {
|
||||
const result = await controller.transition(item, detail.head_sha, 'reopen');
|
||||
Object.assign(detail, result);
|
||||
applyResult(result);
|
||||
doc.querySelector('#pull-close-receipt').hidden = true;
|
||||
doc.querySelector('#pull-lifecycle').hidden = false;
|
||||
close.hidden = false;
|
||||
close.disabled = false;
|
||||
doc.querySelector('#pull-lifecycle-status').textContent = 'Pull request reopened.';
|
||||
doc.querySelector('#pull-reopen-status').textContent = '';
|
||||
close.focus();
|
||||
} catch (error) {
|
||||
doc.querySelector('#pull-reopen-status').textContent = error.message + ' The pull request remains closed; reload and retry.';
|
||||
reopen.disabled = false;
|
||||
reopen.focus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function bindCheckRecovery(
|
||||
doc, controller, selectedPull, selectedDetail,
|
||||
confirmRetry = message => globalThis.confirm(message)
|
||||
) {
|
||||
let current = null;
|
||||
const get = selector => doc.querySelector(selector);
|
||||
function reset({ restoreFocus = true } = {}) {
|
||||
const recovery = current;
|
||||
current = null;
|
||||
get('#pull-check-recovery').hidden = true;
|
||||
get('#pull-check-log').textContent = '';
|
||||
get('#pull-check-recovery-status').textContent = '';
|
||||
get('#retry-pull-check').disabled = true;
|
||||
if (restoreFocus) (recovery?.trigger?.isConnected ? recovery.trigger : get('#refresh-pull-checks'))?.focus();
|
||||
}
|
||||
async function poll(recovery, attempt = 0) {
|
||||
if (current !== recovery || selectedPull() !== recovery.item) return;
|
||||
if (attempt >= 12) {
|
||||
get('#pull-check-recovery-status').textContent = 'Retry is still queued. Use Refresh checks to continue monitoring.';
|
||||
return;
|
||||
}
|
||||
await new Promise(resolve => setTimeout(resolve, 1500));
|
||||
if (current !== recovery || selectedPull() !== recovery.item) return;
|
||||
try {
|
||||
const status = await controller.loadChecks(recovery.item);
|
||||
if (current !== recovery || selectedPull() !== recovery.item) return;
|
||||
if (status.head_sha !== recovery.headSha) {
|
||||
get('#pull-check-recovery-status').textContent = 'New commits arrived. Reload the pull request before retrying again.';
|
||||
return;
|
||||
}
|
||||
const check = (status.checks || []).find(candidate =>
|
||||
candidate?.recovery?.run_id === recovery.runId && candidate?.recovery?.job_index === recovery.jobIndex
|
||||
);
|
||||
if (!check || !['failure', 'error', 'pending'].includes(check.state)) {
|
||||
get('#refresh-pull-checks').click();
|
||||
get('#pull-check-recovery-status').textContent = 'Retried check completed. Merge readiness refreshed.';
|
||||
return;
|
||||
}
|
||||
get('#pull-check-recovery-status').textContent = check.state === 'pending'
|
||||
? 'Retried check is running…' : 'Retry queued; waiting for a fresh run…';
|
||||
} catch (_error) {
|
||||
get('#pull-check-recovery-status').textContent = 'Waiting for check status…';
|
||||
}
|
||||
return poll(recovery, attempt + 1);
|
||||
}
|
||||
get('#pull-check-list').addEventListener('click', async event => {
|
||||
const trigger = event.target.closest('.ci-check-inspect');
|
||||
const item = selectedPull();
|
||||
const detail = selectedDetail();
|
||||
if (!trigger || !item || !detail?.head_sha) return;
|
||||
const runId = Number(trigger.dataset.runId);
|
||||
const jobIndex = Number(trigger.dataset.jobIndex);
|
||||
if (!Number.isInteger(runId) || !Number.isInteger(jobIndex)) return;
|
||||
const recovery = {
|
||||
item, headSha: detail.head_sha, runId, jobIndex, trigger,
|
||||
name: trigger.closest('.ci-check')?.querySelector('strong')?.textContent || 'Failed check',
|
||||
};
|
||||
current = recovery;
|
||||
get('#pull-check-recovery').hidden = false;
|
||||
get('#pull-check-recovery-title').textContent = recovery.name;
|
||||
get('#pull-check-log').textContent = 'Loading failure details…';
|
||||
get('#pull-check-recovery-status').textContent = 'Loading failure details…';
|
||||
get('#retry-pull-check').disabled = true;
|
||||
get('#pull-check-recovery-title').focus();
|
||||
try {
|
||||
const result = await controller.loadCheckFailure(item, recovery.headSha, runId, jobIndex);
|
||||
if (current !== recovery || selectedPull() !== item) return;
|
||||
get('#pull-check-log').textContent = result.excerpt || 'No failure output was reported.';
|
||||
get('#pull-check-recovery-status').textContent = 'Failure details loaded.';
|
||||
get('#retry-pull-check').disabled = false;
|
||||
} catch (error) {
|
||||
if (current !== recovery || selectedPull() !== item) return;
|
||||
get('#pull-check-log').textContent = '';
|
||||
get('#pull-check-recovery-status').textContent = error.message;
|
||||
}
|
||||
});
|
||||
get('#close-pull-check-recovery').addEventListener('click', () => reset());
|
||||
get('#pull-checks').addEventListener('toggle', () => {
|
||||
if (current && selectedPull() !== current.item) reset({ restoreFocus: false });
|
||||
});
|
||||
get('#retry-pull-check').addEventListener('click', async () => {
|
||||
const recovery = current;
|
||||
if (!recovery || selectedPull() !== recovery.item) return;
|
||||
if (!confirmRetry('Retry ' + recovery.name + ' for head ' + recovery.headSha.slice(0, 12) + '?')) return;
|
||||
const button = get('#retry-pull-check');
|
||||
button.disabled = true;
|
||||
get('#pull-check-recovery-status').textContent = 'Queueing retry…';
|
||||
try {
|
||||
await controller.retryCheck(recovery.item, recovery.headSha, recovery.runId, recovery.jobIndex);
|
||||
if (current !== recovery) return;
|
||||
get('#pull-check-recovery-status').textContent = 'Retry queued; waiting for a fresh run…';
|
||||
poll(recovery);
|
||||
} catch (error) {
|
||||
if (current !== recovery) return;
|
||||
get('#pull-check-recovery-status').textContent = error.message;
|
||||
button.disabled = false;
|
||||
button.focus();
|
||||
}
|
||||
});
|
||||
return { reset };
|
||||
}
|
||||
|
||||
createPullSheet.mergeEligibility = mergeEligibility;
|
||||
createPullSheet.review = reviewEligibility;
|
||||
createPullSheet.renderReviewerStatuses = renderReviewerStatuses;
|
||||
@@ -937,6 +1524,8 @@ createPullSheet.renderFile = renderFile;
|
||||
createPullSheet.focusNextUnreviewed = focusNextUnreviewed;
|
||||
createPullSheet.removeFromSnapshot = removeFromSnapshot;
|
||||
createPullSheet.sameTarget = sameTarget;
|
||||
createPullSheet.bindLifecycleControls = bindLifecycleControls;
|
||||
createPullSheet.resetLifecycleControls = resetLifecycleControls;
|
||||
createPullSheet.ownershipSelectors = ownershipSelectors;
|
||||
createPullSheet.renderHandoffCandidates = renderHandoffCandidates;
|
||||
createPullSheet.ownershipExitMessage = ownershipExitMessage;
|
||||
@@ -946,4 +1535,5 @@ createPullSheet.bindContextEditor = bindContextEditor;
|
||||
createPullSheet.resetReviewRequestControls = resetReviewRequestControls;
|
||||
createPullSheet.bindReviewRequestControls = bindReviewRequestControls;
|
||||
createPullSheet.bindFeedbackControls = bindFeedbackControls;
|
||||
createPullSheet.bindCheckRecovery = bindCheckRecovery;
|
||||
if (typeof module !== 'undefined' && module.exports) module.exports = createPullSheet;
|
||||
@@ -5,6 +5,11 @@
|
||||
control, status, testControl, deadlineControl, deadlineStatus, deadlineHour, deadlineDays,
|
||||
startDayControl, startDayStatus, startDayHour,
|
||||
followingControl, followingStatus,
|
||||
humanGateControl, humanGateStatus,
|
||||
quietControl = globalThis.document?.querySelector('#push-quiet-hours'),
|
||||
quietStart = globalThis.document?.querySelector('#push-quiet-start'),
|
||||
quietEnd = globalThis.document?.querySelector('#push-quiet-end'),
|
||||
quietStatus = globalThis.document?.querySelector('#push-quiet-status'),
|
||||
deadlineSnooze, deadlineSnoozeStatus, deadlineSnoozeReview, onReviewDeadlines,
|
||||
notification, serviceWorker, fetchJson,
|
||||
}) {
|
||||
@@ -131,14 +136,17 @@
|
||||
if (deadlineControl) deadlineControl.checked = false;
|
||||
if (startDayControl) startDayControl.checked = false;
|
||||
if (followingControl) followingControl.checked = false;
|
||||
if (humanGateControl) humanGateControl.checked = false;
|
||||
configuration.subscribed = false;
|
||||
configuration.deadline_enabled = false;
|
||||
configuration.start_day_enabled = false;
|
||||
configuration.following_enabled = false;
|
||||
configuration.human_gates_enabled = false;
|
||||
pendingIntent = null;
|
||||
status.textContent = 'New update notifications are off for this device.';
|
||||
if (deadlineStatus) deadlineStatus.textContent = 'Deadline reminders are off for this device.';
|
||||
if (followingStatus) followingStatus.textContent = 'Following change alerts are off for this device.';
|
||||
if (humanGateStatus) humanGateStatus.textContent = 'Human Gate decision alerts are off for this device.';
|
||||
}
|
||||
|
||||
async function ensureSubscription() {
|
||||
@@ -302,13 +310,75 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function changeHumanGates() {
|
||||
humanGateControl.disabled = true;
|
||||
try {
|
||||
const registration = await serviceWorker.ready;
|
||||
let subscription = await registration.pushManager.getSubscription();
|
||||
if (humanGateControl.checked) pendingIntent = 'human-gates';
|
||||
if (humanGateControl.checked && !subscription) subscription = await ensureSubscription();
|
||||
if (humanGateControl.checked && !subscription) {
|
||||
humanGateControl.checked = false;
|
||||
humanGateStatus.textContent = status.textContent;
|
||||
return false;
|
||||
}
|
||||
await fetchJson('api/v1/push-subscription/human-gates', {
|
||||
method:'PUT',
|
||||
headers:{'Content-Type':'application/json'},
|
||||
body:JSON.stringify({enabled:humanGateControl.checked}),
|
||||
});
|
||||
configuration.human_gates_enabled = humanGateControl.checked;
|
||||
pendingIntent = null;
|
||||
humanGateStatus.textContent = humanGateControl.checked
|
||||
? 'Human Gate decision alerts enabled for this device.'
|
||||
: 'Human Gate decision alerts are off for this device.';
|
||||
return true;
|
||||
} catch (_error) {
|
||||
humanGateControl.checked = !humanGateControl.checked;
|
||||
humanGateStatus.textContent = 'Could not change Human Gate alerts. Check your connection and try again.';
|
||||
return false;
|
||||
} finally {
|
||||
humanGateControl.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function changeQuietHours() {
|
||||
if (!quietControl) return false;
|
||||
for (const item of [quietControl, quietStart, quietEnd]) if (item) item.disabled = true;
|
||||
try {
|
||||
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC';
|
||||
await fetchJson('api/v1/push-subscription/quiet-hours', {
|
||||
method:'PUT',
|
||||
headers:{'Content-Type':'application/json'},
|
||||
body:JSON.stringify({
|
||||
enabled:quietControl.checked,
|
||||
start:quietStart?.value || '22:00',
|
||||
end:quietEnd?.value || '07:00',
|
||||
timezone,
|
||||
}),
|
||||
});
|
||||
configuration.quiet_hours_enabled = quietControl.checked;
|
||||
configuration.quiet_hours_start = quietStart?.value || '22:00';
|
||||
configuration.quiet_hours_end = quietEnd?.value || '07:00';
|
||||
quietStatus.textContent = quietControl.checked
|
||||
? `Routine alerts paused from ${configuration.quiet_hours_start} to ${configuration.quiet_hours_end} local time.`
|
||||
: 'Routine alert quiet hours are off for this device.';
|
||||
return true;
|
||||
} catch (_error) {
|
||||
quietStatus.textContent = 'Could not save quiet hours. Check your connection and try again.';
|
||||
return false;
|
||||
} finally {
|
||||
for (const item of [quietControl, quietStart, quietEnd]) if (item) item.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function enableDeadline() {
|
||||
deadlineControl.checked = true;
|
||||
return changeDeadline();
|
||||
}
|
||||
|
||||
async function recoverPermission(intent = null) {
|
||||
if (!pendingIntent && ['updates', 'deadline', 'start-day', 'following'].includes(intent)) pendingIntent = intent;
|
||||
if (!pendingIntent && ['updates', 'deadline', 'start-day', 'following', 'human-gates'].includes(intent)) pendingIntent = intent;
|
||||
if (!pendingIntent || notification.permission !== 'granted') return false;
|
||||
if (recoveryPromise) return recoveryPromise;
|
||||
recoveryPromise = (async () => {
|
||||
@@ -324,6 +394,10 @@
|
||||
followingControl.checked = true;
|
||||
return changeFollowing();
|
||||
}
|
||||
if (pendingIntent === 'human-gates') {
|
||||
humanGateControl.checked = true;
|
||||
return changeHumanGates();
|
||||
}
|
||||
return Boolean(await enable());
|
||||
})();
|
||||
try {
|
||||
@@ -340,6 +414,10 @@
|
||||
deadlineControl?.addEventListener('change', changeDeadline);
|
||||
startDayControl?.addEventListener('change', changeStartDay);
|
||||
followingControl?.addEventListener('change', changeFollowing);
|
||||
humanGateControl?.addEventListener('change', changeHumanGates);
|
||||
quietControl?.addEventListener('change', changeQuietHours);
|
||||
quietStart?.addEventListener('change', changeQuietHours);
|
||||
quietEnd?.addEventListener('change', changeQuietHours);
|
||||
deadlineSnoozeReview?.addEventListener('click', reviewSnoozedDeadlines);
|
||||
configuration = await fetchJson('api/v1/push-subscription');
|
||||
if (!configuration.available) {
|
||||
@@ -347,6 +425,8 @@
|
||||
if (deadlineControl) deadlineControl.disabled = true;
|
||||
if (startDayControl) startDayControl.disabled = true;
|
||||
if (followingControl) followingControl.disabled = true;
|
||||
if (humanGateControl) humanGateControl.disabled = true;
|
||||
if (quietControl) quietControl.disabled = true;
|
||||
status.textContent = 'New update notifications are not available on this server.';
|
||||
return;
|
||||
}
|
||||
@@ -354,6 +434,10 @@
|
||||
if (deadlineControl) deadlineControl.checked = Boolean(configuration.deadline_enabled);
|
||||
if (startDayControl) startDayControl.checked = Boolean(configuration.start_day_enabled);
|
||||
if (followingControl) followingControl.checked = Boolean(configuration.following_enabled);
|
||||
if (humanGateControl) humanGateControl.checked = Boolean(configuration.human_gates_enabled);
|
||||
if (quietControl) quietControl.checked = Boolean(configuration.quiet_hours_enabled);
|
||||
if (quietStart) quietStart.value = configuration.quiet_hours_start || '22:00';
|
||||
if (quietEnd) quietEnd.value = configuration.quiet_hours_end || '07:00';
|
||||
if (deadlineHour) deadlineHour.value = String(configuration.reminder_hour ?? 9);
|
||||
if (deadlineDays) deadlineDays.value = String(configuration.reminder_days ?? 2);
|
||||
if (startDayHour) startDayHour.value = String(configuration.start_day_reminder_hour ?? 9);
|
||||
@@ -367,8 +451,14 @@
|
||||
if (followingStatus) followingStatus.textContent = configuration.following_enabled
|
||||
? 'Following change alerts enabled for this device.'
|
||||
: 'Following change alerts are off for this device.';
|
||||
if (humanGateStatus) humanGateStatus.textContent = configuration.human_gates_enabled
|
||||
? 'Human Gate decision alerts enabled for this device.'
|
||||
: 'Human Gate decision alerts are off for this device.';
|
||||
if (quietStatus) quietStatus.textContent = configuration.quiet_hours_enabled
|
||||
? `Routine alerts paused from ${quietStart.value} to ${quietEnd.value} local time.`
|
||||
: 'Routine alert quiet hours are off for this device.';
|
||||
renderDeadlineSnooze();
|
||||
}
|
||||
|
||||
return {init, change, changeDeadline, changeStartDay, changeFollowing, enableDeadline, deadlineReadiness, notificationReadiness, recoverPermission};
|
||||
return {init, change, changeDeadline, changeStartDay, changeFollowing, changeHumanGates, changeQuietHours, enableDeadline, deadlineReadiness, notificationReadiness, recoverPermission};
|
||||
});
|
||||
+268
-5
@@ -1,8 +1,11 @@
|
||||
function createReleaseReceipt({ storage, getLogin, fetchJson, launcher = null, dialog = null, statusNode = null, checksNode = null, releaseNode = null, listNode = null, documentRef = null, windowRef = null, setTimer = setTimeout, clearTimer = clearTimeout, pollMs = 30000 }) {
|
||||
function createReleaseReceipt({ storage, getLogin, fetchJson, launcher = null, dialog = null, statusNode = null, checksNode = null, releaseNode = null, listNode = null, documentRef = null, windowRef = null, confirmAction = null, openPull = null, setTimer = setTimeout, clearTimer = clearTimeout, pollMs = 30000 }) {
|
||||
const prefix = 'stackchain.release-receipt.v1:';
|
||||
const limit = 12;
|
||||
let entries = [];
|
||||
let refreshing = null;
|
||||
const recoveries = new Map();
|
||||
const retrying = new Map();
|
||||
const rollingBack = new Map();
|
||||
let timer = null;
|
||||
let bound = false;
|
||||
documentRef ||= typeof document !== 'undefined' ? document : null;
|
||||
@@ -62,6 +65,17 @@ function createReleaseReceipt({ storage, getLogin, fetchJson, launcher = null, d
|
||||
number: Number(item.number),
|
||||
key: item.key || item.repository + '#' + item.number,
|
||||
commit_sha: commitSha,
|
||||
...(
|
||||
mergeResult?.source_repository === item.repository
|
||||
&& mergeResult?.source_branch
|
||||
&& mergeResult?.source_head_sha
|
||||
? {
|
||||
source_branch: String(mergeResult.source_branch),
|
||||
source_head_sha: String(mergeResult.source_head_sha),
|
||||
cleanup: { state: 'available', message: 'Merged branch retained.' },
|
||||
}
|
||||
: {}
|
||||
),
|
||||
status: null,
|
||||
captured_at: new Date().toISOString(),
|
||||
};
|
||||
@@ -81,10 +95,17 @@ function createReleaseReceipt({ storage, getLogin, fetchJson, launcher = null, d
|
||||
|
||||
function summarize(payload) {
|
||||
const checks = Array.isArray(payload?.checks) ? payload.checks : [];
|
||||
const failing = checks.filter(check => ['failure', 'error'].includes(check.state)).map(check => check.name).filter(Boolean);
|
||||
const failedChecks = checks.filter(check => ['failure', 'error'].includes(check.state));
|
||||
const failing = failedChecks.map(check => check.name).filter(Boolean);
|
||||
const failures = failedChecks.filter(check => check?.recovery).map(check => ({
|
||||
name: check.name || 'Failed check',
|
||||
description: check.description || '',
|
||||
url: check.url || '',
|
||||
recovery: check.recovery,
|
||||
}));
|
||||
const pending = checks.filter(check => check.state === 'pending').map(check => check.name).filter(Boolean);
|
||||
if (payload?.release) return { ...payload, label: 'Released · ' + payload.release.tag, checks: [] };
|
||||
if (failing.length) return { ...payload, label: 'Checks failed', checks: failing };
|
||||
if (failing.length) return { ...payload, label: 'Checks failed', checks: failing, failures };
|
||||
if (payload?.ci_state === 'success') return { ...payload, label: 'Checks passed · waiting for release', checks: [] };
|
||||
return { ...payload, label: 'Checks running', checks: pending };
|
||||
}
|
||||
@@ -121,18 +142,117 @@ function createReleaseReceipt({ storage, getLogin, fetchJson, launcher = null, d
|
||||
state.className = 'small';
|
||||
state.textContent = entry.status?.label || 'Checking the exact merge commit…';
|
||||
copy.append(title, state);
|
||||
if (entry.source_branch && entry.source_head_sha) {
|
||||
const branch = document.createElement('span');
|
||||
branch.className = 'small release-branch-cleanup-status';
|
||||
branch.textContent = entry.cleanup?.state === 'deleted'
|
||||
? 'Branch ' + entry.source_branch + ' · deleted'
|
||||
: 'Branch ' + entry.source_branch + ' · ' + entry.source_head_sha.slice(0, 8);
|
||||
copy.append(branch);
|
||||
}
|
||||
if (entry.rollback?.state === 'prepared') {
|
||||
const rollbackStatus = document.createElement('span');
|
||||
rollbackStatus.className = 'small release-rollback-status';
|
||||
rollbackStatus.textContent = entry.rollback.message;
|
||||
copy.append(rollbackStatus);
|
||||
}
|
||||
if (entry.status?.release?.url) {
|
||||
const link = document.createElement('a');
|
||||
link.href = entry.status.release.url;
|
||||
link.textContent = 'Open release ' + entry.status.release.tag;
|
||||
copy.append(link);
|
||||
}
|
||||
for (const failure of (entry.status?.failures || [])) {
|
||||
const runId = failure.recovery?.run_id;
|
||||
const jobIndex = failure.recovery?.job_index;
|
||||
if (!Number.isInteger(runId) || !Number.isInteger(jobIndex)) continue;
|
||||
const key = identity(entry) + '@' + runId + ':' + jobIndex;
|
||||
const summary = document.createElement('section');
|
||||
summary.className = 'release-failure-summary';
|
||||
const failureName = document.createElement('span');
|
||||
failureName.className = 'small';
|
||||
failureName.textContent = failure.name + (failure.description ? ' · ' + failure.description : '');
|
||||
const review = document.createElement('button');
|
||||
review.type = 'button';
|
||||
review.textContent = 'Review failure';
|
||||
review.setAttribute('aria-label', 'Review failed check ' + failure.name + ' for ' + entry.commit_sha.slice(0, 8));
|
||||
review.addEventListener('click', () => reviewFailure(
|
||||
entry.repository, entry.commit_sha, runId, jobIndex
|
||||
).catch(error => {
|
||||
if (statusNode) statusNode.textContent = String(error?.message || error) + ' Release evidence retained.';
|
||||
}));
|
||||
summary.append(failureName, review);
|
||||
const detail = recoveries.get(key);
|
||||
if (detail) {
|
||||
const recovery = document.createElement('div');
|
||||
recovery.className = 'release-failure-recovery';
|
||||
const sha = document.createElement('strong');
|
||||
sha.textContent = 'Merge ' + entry.commit_sha.slice(0, 8);
|
||||
const excerpt = document.createElement('pre');
|
||||
excerpt.textContent = detail.excerpt || 'No log excerpt was returned.';
|
||||
const actions = document.createElement('div');
|
||||
actions.className = 'release-failure-actions';
|
||||
if (failure.url) {
|
||||
const job = document.createElement('a');
|
||||
job.href = failure.url;
|
||||
job.textContent = 'Open job';
|
||||
actions.append(job);
|
||||
}
|
||||
const retry = document.createElement('button');
|
||||
retry.type = 'button';
|
||||
retry.textContent = retrying.has(key) ? 'Retrying…' : 'Retry failed check';
|
||||
retry.disabled = retrying.has(key);
|
||||
retry.addEventListener('click', () => retryFailure(
|
||||
entry.repository, entry.commit_sha, runId, jobIndex
|
||||
).catch(error => {
|
||||
if (statusNode) statusNode.textContent = String(error?.message || error) + ' Release evidence retained.';
|
||||
render();
|
||||
}));
|
||||
actions.append(retry);
|
||||
const rollback = document.createElement('button');
|
||||
rollback.type = 'button';
|
||||
rollback.textContent = entry.rollback?.state === 'prepared'
|
||||
? 'Open rollback #' + entry.rollback.number
|
||||
: (rollingBack.has(identity(entry)) ? 'Preparing rollback…' : 'Prepare rollback PR');
|
||||
rollback.disabled = rollingBack.has(identity(entry));
|
||||
rollback.setAttribute(
|
||||
'aria-label',
|
||||
'Prepare rollback pull request for ' + entry.key + ' at ' + entry.commit_sha.slice(0, 8),
|
||||
);
|
||||
rollback.addEventListener('click', () => prepareRollback(entry.repository, entry.commit_sha).catch(error => {
|
||||
if (statusNode) statusNode.textContent = String(error?.message || error) + ' Release evidence retained.';
|
||||
render();
|
||||
}));
|
||||
actions.append(rollback);
|
||||
recovery.append(sha, excerpt, actions);
|
||||
summary.append(recovery);
|
||||
}
|
||||
copy.append(summary);
|
||||
}
|
||||
const button = document.createElement('button');
|
||||
button.type = 'button';
|
||||
button.textContent = 'Dismiss';
|
||||
button.setAttribute('aria-label', 'Dismiss ' + entry.key + ' from release tracking');
|
||||
button.addEventListener('click', () => dismiss(entry.repository, entry.commit_sha));
|
||||
row.append(copy, button);
|
||||
if (entry.source_branch && entry.cleanup?.state !== 'deleted') {
|
||||
const actions = document.createElement('div');
|
||||
actions.className = 'release-watchlist-actions';
|
||||
const cleanup = document.createElement('button');
|
||||
cleanup.type = 'button';
|
||||
cleanup.textContent = entry.cleanup?.state === 'deleting' ? 'Deleting…' : 'Delete source branch';
|
||||
cleanup.disabled = entry.cleanup?.state === 'deleting' || entry.cleanup?.state === 'advanced';
|
||||
cleanup.setAttribute(
|
||||
'aria-label',
|
||||
'Delete merged source branch ' + entry.source_branch + ' at ' + entry.source_head_sha.slice(0, 8),
|
||||
);
|
||||
cleanup.addEventListener('click', () => deleteBranch(entry.repository, entry.commit_sha).catch(error => {
|
||||
if (statusNode) statusNode.textContent = String(error?.message || error);
|
||||
}));
|
||||
actions.append(cleanup, button);
|
||||
row.append(copy, actions);
|
||||
} else {
|
||||
row.append(copy, button);
|
||||
}
|
||||
return row;
|
||||
});
|
||||
listNode.replaceChildren(...rows);
|
||||
@@ -168,6 +288,149 @@ function createReleaseReceipt({ storage, getLogin, fetchJson, launcher = null, d
|
||||
finally { refreshing = null; }
|
||||
}
|
||||
|
||||
function recoveryPath(entry, runId, jobIndex) {
|
||||
return 'api/v1/repos/' + entry.repository.split('/').map(encodeURIComponent).join('/')
|
||||
+ '/pulls/' + encodeURIComponent(entry.number)
|
||||
+ '/release-receipt/' + encodeURIComponent(entry.commit_sha)
|
||||
+ '/checks/' + encodeURIComponent(runId) + '/jobs/' + encodeURIComponent(jobIndex);
|
||||
}
|
||||
|
||||
async function reviewFailure(repository, commitSha, runId, jobIndex) {
|
||||
const entry = entries.find(value => identity(value) === repository + '@' + commitSha);
|
||||
if (!entry) throw new Error('Tracked release is unavailable.');
|
||||
const key = identity(entry) + '@' + runId + ':' + jobIndex;
|
||||
const detail = await fetchJson(recoveryPath(entry, runId, jobIndex) + '/failure', {
|
||||
headers: { Accept: 'application/json' },
|
||||
});
|
||||
if (detail?.commit_sha !== entry.commit_sha) {
|
||||
throw new Error('Release failure evidence did not match the merged commit.');
|
||||
}
|
||||
recoveries.set(key, detail);
|
||||
render();
|
||||
return detail;
|
||||
}
|
||||
|
||||
function retryFailure(repository, commitSha, runId, jobIndex) {
|
||||
const entry = entries.find(value => identity(value) === repository + '@' + commitSha);
|
||||
if (!entry) return Promise.reject(new Error('Tracked release is unavailable.'));
|
||||
const key = identity(entry) + '@' + runId + ':' + jobIndex;
|
||||
if (retrying.has(key)) return retrying.get(key);
|
||||
const approve = confirmAction || (windowRef?.confirm ? message => windowRef.confirm(message) : () => false);
|
||||
const failure = entry.status?.failures?.find(value =>
|
||||
value.recovery?.run_id === runId && value.recovery?.job_index === jobIndex
|
||||
);
|
||||
if (!approve('Retry ' + (failure?.name || 'failed release check') + ' for ' + commitSha.slice(0, 8) + '?')) {
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
const operation = fetchJson(recoveryPath(entry, runId, jobIndex) + '/retry', {
|
||||
method: 'POST',
|
||||
headers: { Accept: 'application/json' },
|
||||
}).then(result => {
|
||||
if (result?.commit_sha !== entry.commit_sha) {
|
||||
throw new Error('Release retry did not match the merged commit.');
|
||||
}
|
||||
entry.status = { ...entry.status, ci_state: 'pending', label: 'Checks running', checks: [], failures: [] };
|
||||
recoveries.delete(key);
|
||||
persist();
|
||||
render();
|
||||
schedule(0);
|
||||
return true;
|
||||
}).finally(() => retrying.delete(key));
|
||||
retrying.set(key, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
function prepareRollback(repository, commitSha) {
|
||||
const entry = entries.find(value => identity(value) === repository + '@' + commitSha);
|
||||
if (!entry) return Promise.reject(new Error('Tracked release is unavailable.'));
|
||||
if (entry.rollback?.state === 'prepared') {
|
||||
openPull?.(entry.rollback.pull);
|
||||
return Promise.resolve(entry.rollback.pull);
|
||||
}
|
||||
const key = identity(entry);
|
||||
if (rollingBack.has(key)) return rollingBack.get(key);
|
||||
const approve = confirmAction || (windowRef?.confirm ? message => windowRef.confirm(message) : () => false);
|
||||
if (!approve('Prepare a draft rollback PR for ' + entry.key + ' at ' + commitSha.slice(0, 8) + '?')) {
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
const operation = fetchJson(
|
||||
'api/v1/repos/' + entry.repository.split('/').map(encodeURIComponent).join('/')
|
||||
+ '/pulls/' + encodeURIComponent(entry.number)
|
||||
+ '/release-receipt/' + encodeURIComponent(entry.commit_sha) + '/rollback',
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Idempotency-Key': 'release-rollback-' + entry.number + '-' + entry.commit_sha,
|
||||
},
|
||||
},
|
||||
).then(result => {
|
||||
if (result?.rollback_of !== entry.commit_sha || !Number.isInteger(result?.number)) {
|
||||
throw new Error('Rollback preparation did not match the failed release.');
|
||||
}
|
||||
const pull = {
|
||||
...result,
|
||||
kind: 'pull',
|
||||
key: result.repository + '#' + result.number,
|
||||
state: 'open',
|
||||
};
|
||||
entry.rollback = {
|
||||
state: 'prepared',
|
||||
number: result.number,
|
||||
message: 'Draft rollback #' + result.number + ' is ready for review.',
|
||||
pull,
|
||||
};
|
||||
persist();
|
||||
render();
|
||||
if (dialog?.open) dialog.close();
|
||||
openPull?.(pull);
|
||||
return result;
|
||||
}).finally(() => rollingBack.delete(key));
|
||||
rollingBack.set(key, operation);
|
||||
render();
|
||||
return operation;
|
||||
}
|
||||
|
||||
async function deleteBranch(repository, commitSha) {
|
||||
const entry = entries.find(value => identity(value) === repository + '@' + commitSha);
|
||||
if (!entry?.source_branch || !entry?.source_head_sha || entry.cleanup?.state === 'deleted') {
|
||||
throw new Error('Source branch cleanup is unavailable.');
|
||||
}
|
||||
const approve = confirmAction || (windowRef?.confirm ? message => windowRef.confirm(message) : () => false);
|
||||
if (!approve('Delete ' + entry.source_branch + ' at ' + entry.source_head_sha.slice(0, 8) + '?')) return false;
|
||||
entry.cleanup = { state: 'deleting', message: 'Deleting source branch…' };
|
||||
persist();
|
||||
render();
|
||||
try {
|
||||
await fetchJson(
|
||||
'api/v1/repos/' + entry.repository.split('/').map(encodeURIComponent).join('/')
|
||||
+ '/pulls/' + encodeURIComponent(entry.number) + '/source-branch',
|
||||
{
|
||||
method: 'DELETE',
|
||||
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
|
||||
body: JSON.stringify({
|
||||
source_branch: entry.source_branch,
|
||||
expected_head_sha: entry.source_head_sha,
|
||||
}),
|
||||
},
|
||||
);
|
||||
entry.cleanup = { state: 'deleted', message: 'Source branch deleted.' };
|
||||
persist();
|
||||
render();
|
||||
return true;
|
||||
} catch (error) {
|
||||
entry.cleanup = {
|
||||
state: error?.status === 409 ? 'advanced' : 'available',
|
||||
message: error?.status === 409
|
||||
? 'Source branch has newer commits and was retained.'
|
||||
: 'Branch retained. Retry when connected.',
|
||||
};
|
||||
persist();
|
||||
render();
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
function dismiss(repository, commitSha) {
|
||||
if (repository && commitSha) entries = entries.filter(entry => identity(entry) !== repository + '@' + commitSha);
|
||||
else entries = [];
|
||||
@@ -195,7 +458,7 @@ function createReleaseReceipt({ storage, getLogin, fetchJson, launcher = null, d
|
||||
schedule();
|
||||
}
|
||||
|
||||
return { capture, restore, refresh, dismiss, bind, fetchJson };
|
||||
return { capture, restore, refresh, reviewFailure, retryFailure, prepareRollback, deleteBranch, dismiss, bind, fetchJson };
|
||||
}
|
||||
|
||||
if (typeof module !== 'undefined' && module.exports) module.exports = createReleaseReceipt;
|
||||
@@ -384,10 +384,20 @@ function renderChecks(checks, escapeHtml, { offline = false } = {}) {
|
||||
const url = typeof check.url === 'string' ? check.url : '';
|
||||
const link = url ? '<a class="ci-check-link" href="' + escapeHtml(url) +
|
||||
'" target="_blank" rel="noopener noreferrer">Open job</a>' : '';
|
||||
const recovery = check.recovery;
|
||||
const inspect = !offline && ['failure', 'error'].includes(check.state) &&
|
||||
Number.isInteger(recovery?.run_id) && recovery.run_id > 0 &&
|
||||
Number.isInteger(recovery?.job_index) && recovery.job_index >= 0
|
||||
? '<button type="button" class="ci-check-inspect" data-run-id="' + recovery.run_id +
|
||||
'" data-job-index="' + recovery.job_index + '">Inspect failure</button>'
|
||||
: '';
|
||||
const actions = inspect || link
|
||||
? '<div class="ci-check-actions">' + inspect + link + '</div>'
|
||||
: '';
|
||||
return '<article class="ci-check ci-check-' + escapeHtml(check.state || 'unknown') + '">' +
|
||||
'<div class="ci-check-copy"><strong>' + escapeHtml(check.name) + '</strong>' +
|
||||
'<span class="small">' + escapeHtml(check.state || 'unknown') +
|
||||
(check.description ? ' · ' + escapeHtml(check.description) : '') + '</span></div>' + link + '</article>';
|
||||
(check.description ? ' · ' + escapeHtml(check.description) : '') + '</span></div>' + actions + '</article>';
|
||||
}).join('');
|
||||
return { summary, html, expanded: failed > 0 };
|
||||
}
|
||||
|
||||
@@ -36,6 +36,16 @@
|
||||
};
|
||||
root.searchPreviewReplyPath = item => root.searchPreviewPath(item).replace(/\?.*$/, '') +
|
||||
'/comments?kind=' + encodeURIComponent(item.kind);
|
||||
root.searchPreviewMutation = fetchJson => (detail, action) => {
|
||||
if (action === 'reopen-pull') {
|
||||
const path = root.searchPreviewPath(detail).replace('/issues/', '/pulls/').replace(/\/preview.*$/, '/reopen');
|
||||
return fetchJson(path, {
|
||||
method:'PATCH', headers:{'Content-Type':'application/json'},
|
||||
body:JSON.stringify({expected_head_sha:detail.head_sha}),
|
||||
});
|
||||
}
|
||||
return fetchJson(root.searchPreviewPath(detail).replace(/\?.*$/, '') + '/' + action, {method:'PATCH'});
|
||||
};
|
||||
root.searchPreviewSubscriptionPath = item => root.searchPreviewPath(item).replace(/\?.*$/, '') +
|
||||
'/subscription?kind=' + encodeURIComponent(item.kind);
|
||||
root.searchPreviewSubscriptionOptions = fetchJson => {
|
||||
@@ -102,6 +112,30 @@
|
||||
(detail.watching ? 'Stop watching' : 'Watch ' + (detail.kind === 'pull' ? 'pull request' : 'issue'));
|
||||
button.disabled = state.status === 'watching' || state.status === 'unwatching';
|
||||
};
|
||||
root.renderSearchPreviewStart = (detail, state, button) => {
|
||||
const pull = detail.kind === 'pull' && detail.state === 'closed' &&
|
||||
detail.authored_pull_reopenable === true;
|
||||
const issue = detail.kind === 'issue' &&
|
||||
(detail.reopenable || (detail.state === 'open' && (detail.claimable || detail.assigned_to_me)));
|
||||
button.hidden = !(detail.reviewable || pull || issue);
|
||||
button.textContent = detail.reviewable ? 'Review now' : pull ? 'Reopen in My Work' :
|
||||
detail.reopenable ? 'Reopen & resume' :
|
||||
(detail.assigned_to_me ? 'Start in Today' : 'Assign & start');
|
||||
button.disabled = state.status === 'claiming' || state.status === 'reopening';
|
||||
};
|
||||
root.createSearchAuthoredPullRecovery = o =>
|
||||
async d => {
|
||||
if (!o.confirm('Reopen ' + d.repository + ' #' + d.number + '?')) return 'canceled';
|
||||
await o.reopen(d);
|
||||
await o.refresh();
|
||||
const item = o.find(d);
|
||||
if (!item) {
|
||||
o.unavailable('Reopened. Refresh My Work.');
|
||||
return 'unavailable';
|
||||
}
|
||||
o.open(item);
|
||||
return 'opened';
|
||||
};
|
||||
root.wireSearchPreviewWatch = (button, preview, getDetail) => button.addEventListener('click', () => {
|
||||
const detail = getDetail();
|
||||
if (detail) preview.setWatching(detail.watching !== true).catch(() => {});
|
||||
@@ -114,7 +148,7 @@
|
||||
body:JSON.stringify({body}),
|
||||
}),
|
||||
});
|
||||
root.renderSearchPreviewConversation = (conversation, document, escapeHtml, formatTime, renderMarkdown) => {
|
||||
root.renderSearchPreviewConversation = (conversation, document, escapeHtml, formatTime, renderMarkdown, actions) => {
|
||||
const comments = document.querySelector('#search-preview-comments');
|
||||
const status = document.querySelector('#search-preview-conversation-status');
|
||||
const retry = document.querySelector('#retry-search-preview-conversation');
|
||||
@@ -128,11 +162,12 @@
|
||||
new Date(comment.created_at).getTime() > new Date(conversation.reviewedAt).getTime());
|
||||
const newCount = (conversation.comments || []).filter(isNew).length;
|
||||
comments.innerHTML = (conversation.comments || []).map(comment =>
|
||||
'<article class="search-preview-comment' + (isNew(comment) ? ' new-since-review' : '') +
|
||||
'<article class="search-preview-comment issue-comment' + (isNew(comment) ? ' new-since-review' : '') +
|
||||
'" data-comment-id="' + Number(comment.id || 0) + '">' +
|
||||
'<div class="small">' + escapeHtml(comment.author || 'Unknown author') +
|
||||
(comment.created_at ? ' · ' + escapeHtml(formatTime(comment.created_at)) : '') +
|
||||
(isNew(comment) ? ' · <strong>New since last review</strong>' : '') + '</div>' +
|
||||
(actions?.actionHtml?.(comment) || '') +
|
||||
'<div class="markdown-content">' + renderMarkdown(comment.body || '') + '</div></article>'
|
||||
).join('');
|
||||
retry.hidden = conversation.status !== 'error';
|
||||
@@ -147,6 +182,19 @@
|
||||
(conversation.comments.length === 1 ? ' message' : ' messages') +
|
||||
(newCount ? ' · ' + newCount + ' new since last review' : '') + '.';
|
||||
};
|
||||
root.createSearchPreviewConversationActions = ({hydrator,rootNode,retry,paint,wire}) => {
|
||||
let latest = null;
|
||||
const show = conversation => {
|
||||
latest = conversation;
|
||||
if (!conversation) {
|
||||
paint(null, null);
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
return hydrator.show({root:rootNode,state:conversation,paint,retry,wire});
|
||||
};
|
||||
retry.addEventListener('click', () => { if (latest) void show(latest); });
|
||||
return show;
|
||||
};
|
||||
root.renderSearchPreviewReply = (state, detail, preview, document) => {
|
||||
const section = document.querySelector('.search-preview-reply');
|
||||
const input = document.querySelector('#search-preview-reply');
|
||||
@@ -383,7 +431,27 @@
|
||||
}
|
||||
}
|
||||
|
||||
const conversationPager = {
|
||||
snapshot() {
|
||||
return {...(conversation || {}), comments:(conversation?.comments || []).map(comment => ({...comment}))};
|
||||
},
|
||||
replace(comment) {
|
||||
if (!comment || !Number.isInteger(comment.id) || !conversation) return conversationPager.snapshot();
|
||||
conversation = {...conversation, comments:(conversation.comments || []).map(existing =>
|
||||
existing.id === comment.id ? {...comment} : existing)};
|
||||
publish({status:'ready', item:current, detail:current, conversation});
|
||||
return conversationPager.snapshot();
|
||||
},
|
||||
remove(commentId) {
|
||||
if (!conversation) return conversationPager.snapshot();
|
||||
conversation = {...conversation, comments:(conversation.comments || []).filter(comment => comment.id !== commentId)};
|
||||
publish({status:'ready', item:current, detail:current, conversation});
|
||||
return conversationPager.snapshot();
|
||||
},
|
||||
};
|
||||
|
||||
const api = {
|
||||
commentPager() { return conversationPager; },
|
||||
hasReplyAttachments() {
|
||||
return Boolean(hasAttachments?.());
|
||||
},
|
||||
@@ -548,6 +616,9 @@
|
||||
reopen(detail) {
|
||||
return run('reopen', 'reopening', 'reopened', detail);
|
||||
},
|
||||
reopenPull(detail) {
|
||||
return run('reopen-pull', 'reopening', 'reopened', detail);
|
||||
},
|
||||
setWatching(watching) {
|
||||
if (watchRequest) return watchRequest;
|
||||
if (!current || typeof watch !== 'function') {
|
||||
|
||||
@@ -33,10 +33,11 @@
|
||||
}
|
||||
return async (operation, key, value) => {
|
||||
const db = await database();
|
||||
const transaction = db.transaction(storeName, operation === 'get' ? 'readonly' : 'readwrite');
|
||||
const transaction = db.transaction(storeName, ['get', 'list'].includes(operation) ? 'readonly' : 'readwrite');
|
||||
const records = transaction.objectStore(storeName);
|
||||
if (operation === 'put') return requestResult(records.put(value));
|
||||
if (operation === 'delete') return requestResult(records.delete(key));
|
||||
if (operation === 'list') return requestResult(records.getAll());
|
||||
return requestResult(records.get(key));
|
||||
};
|
||||
}
|
||||
@@ -95,7 +96,9 @@
|
||||
await transact('delete', id);
|
||||
return null;
|
||||
}
|
||||
await transact('put', id, { id, version:1, ownerLogin, ...normalized, attachments:list });
|
||||
await transact('put', id, {
|
||||
id, version:1, ownerLogin, ...normalized, updatedAt:Date.now(), attachments:list,
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -116,6 +119,28 @@
|
||||
return true;
|
||||
}
|
||||
|
||||
return { save, load, remove };
|
||||
async function list() {
|
||||
if (!transact) return [];
|
||||
const ownerLogin = String(getOwnerLogin() || '').trim();
|
||||
if (!ownerLogin) return [];
|
||||
const records = await transact('list');
|
||||
return (Array.isArray(records) ? records : []).flatMap(record => {
|
||||
const repository = String(record?.repository || '');
|
||||
const number = Number(record?.number || 0);
|
||||
if (record?.version !== 1 || record.ownerLogin !== ownerLogin ||
|
||||
!['issue', 'pull'].includes(record.kind) || !repository ||
|
||||
!Number.isInteger(number) || number < 1 ||
|
||||
!Array.isArray(record.attachments) || !record.attachments.length) return [];
|
||||
return [{
|
||||
id:record.id, kind:'photo-reply',
|
||||
label:'Search ' + (record.kind === 'pull' ? 'PR' : 'issue') + ' photos',
|
||||
repository, number, title:repository + '#' + number,
|
||||
photo_count:record.attachments.length, updated_at:Number(record.updatedAt || 0),
|
||||
route:{ kind:'search', target_kind:record.kind, repository, number }, photo_store:'search',
|
||||
}];
|
||||
}).sort((left, right) => Number(right.updated_at) - Number(left.updated_at) || left.id.localeCompare(right.id));
|
||||
}
|
||||
|
||||
return { save, load, remove, list };
|
||||
};
|
||||
});
|
||||
@@ -231,6 +231,8 @@
|
||||
passkey_counter_anomaly: 'Passkey counter anomaly',
|
||||
device_revoked: 'Device access revoked', all_sessions_revoked: 'All device access revoked',
|
||||
issue_closed: 'Issue closed', pull_merged: 'Pull request merged',
|
||||
source_branch_deleted: 'Source branch deleted',
|
||||
release_rollback_prepared: 'Release rollback prepared',
|
||||
comment_deleted: 'Comment deleted',
|
||||
pull_review_approved: 'Pull request approved',
|
||||
pull_review_changes_requested: 'Changes requested', gitea_time_logged: 'Gitea time logged',
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const BASE = new URL('./', self.location.href).pathname;
|
||||
importScripts(BASE + 'static/private-data-registry.js');
|
||||
importScripts(BASE + 'static/background-issue-sync.js');
|
||||
const CACHE = 'stackchain-dashboard-shell-v138';
|
||||
const CACHE = 'stackchain-dashboard-shell-v146';
|
||||
const OFFLINE_LEASE_URL = new URL(BASE + '__offline-session-lease', self.location.origin).href;
|
||||
const OUTAGE_STATUSES = new Set([500, 502, 503, 504]);
|
||||
const NAVIGATION_TIMEOUT_MS = self.__STACKCHAIN_NAVIGATION_TIMEOUT_MS || 4000;
|
||||
@@ -43,7 +43,7 @@ function createAppBadgePreference() {
|
||||
async getCounts() {
|
||||
const database = await open();
|
||||
const counts = {};
|
||||
for (const channel of ['updates', 'following']) {
|
||||
for (const channel of ['updates', 'following', 'human-gates']) {
|
||||
counts[channel] = await new Promise((resolve, reject) => {
|
||||
const request = database.transaction(storeName, 'readonly').objectStore(storeName).get('count:' + channel);
|
||||
request.onsuccess = () => resolve(Number.isSafeInteger(request.result) ? request.result : 0);
|
||||
@@ -67,6 +67,7 @@ function createAppBadgePreference() {
|
||||
async clearCounts() {
|
||||
await this.setCount('updates', 0);
|
||||
await this.setCount('following', 0);
|
||||
await this.setCount('human-gates', 0);
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -74,7 +75,7 @@ const appBadgePreference = self.__STACKCHAIN_APP_BADGE_PREFERENCE || createAppBa
|
||||
let renderedBackgroundBadgeCount = null;
|
||||
|
||||
async function reconcileBackgroundAppBadge(channel, count) {
|
||||
if (!['updates', 'following'].includes(channel)
|
||||
if (!['updates', 'following', 'human-gates'].includes(channel)
|
||||
|| !Number.isSafeInteger(count) || count < 0 || count > 9999
|
||||
|| typeof self.registration.setAppBadge !== 'function'
|
||||
|| typeof self.registration.clearAppBadge !== 'function') return false;
|
||||
@@ -84,7 +85,7 @@ async function reconcileBackgroundAppBadge(channel, count) {
|
||||
try {
|
||||
await appBadgePreference.setCount(channel, count);
|
||||
const counts = await appBadgePreference.getCounts();
|
||||
const total = Math.min(9999, counts.updates + counts.following);
|
||||
const total = Math.min(9999, counts.updates + counts.following + counts['human-gates']);
|
||||
if (renderedBackgroundBadgeCount === total) return false;
|
||||
if (total > 0) await self.registration.setAppBadge(total);
|
||||
else await self.registration.clearAppBadge();
|
||||
@@ -151,6 +152,8 @@ const SHELL = [
|
||||
BASE + 'manifest.webmanifest',
|
||||
BASE + 'static/dashboard.css',
|
||||
BASE + 'static/dashboard.js',
|
||||
BASE + 'static/human-gates.js',
|
||||
BASE + 'static/progressive-human-gates.js',
|
||||
BASE + 'static/icons/stackchain-192.png',
|
||||
BASE + 'static/icons/stackchain-512.png',
|
||||
BASE + 'static/session.js',
|
||||
@@ -167,6 +170,7 @@ const SHELL = [
|
||||
BASE + 'static/search-reply-draft-store.js',
|
||||
BASE + 'static/conversation-reply-draft-store.js',
|
||||
BASE + 'static/conversation-photo-drafts.js',
|
||||
BASE + 'static/photo-draft-inbox.js',
|
||||
BASE + 'static/search-defer.js',
|
||||
BASE + 'static/widgets.js',
|
||||
BASE + 'static/drafts.js',
|
||||
@@ -185,6 +189,10 @@ const SHELL = [
|
||||
BASE + 'static/offline-work.js',
|
||||
BASE + 'static/offline-today.js',
|
||||
BASE + 'static/my-work.js',
|
||||
BASE + 'static/progressive-live-snapshot.js',
|
||||
BASE + 'static/progressive-my-work.js',
|
||||
BASE + 'static/progressive-mobile-dock.js',
|
||||
BASE + 'static/progressive-capture.js',
|
||||
BASE + 'static/agenda-replan.js',
|
||||
BASE + 'static/agenda-calendar.js',
|
||||
BASE + 'static/protect-today.js',
|
||||
@@ -245,6 +253,7 @@ const SHELL = [
|
||||
BASE + 'static/voice-issue-capture.js',
|
||||
BASE + 'static/voice-conversation-capture.js',
|
||||
BASE + 'static/create-issue-sheet.js',
|
||||
BASE + 'static/create-pull-sheet.js',
|
||||
BASE + 'static/mobile-create-issue-nav.js',
|
||||
BASE + 'static/create-and-start.js',
|
||||
BASE + 'static/assign-and-start.js',
|
||||
@@ -282,6 +291,7 @@ const SHELL = [
|
||||
BASE + 'static/device-storage.js',
|
||||
BASE + 'static/mobile-device-setup.js',
|
||||
BASE + 'static/mobile-search-viewport.js',
|
||||
BASE + 'static/mobile-search-modal.js',
|
||||
BASE + 'static/mobile-composer-viewport.js',
|
||||
BASE + 'static/mention-composer.js',
|
||||
BASE + 'static/push-notifications.js',
|
||||
@@ -614,7 +624,7 @@ self.addEventListener('message', event => {
|
||||
if (!String(event.source?.url || '').startsWith(self.location.origin + BASE)) return;
|
||||
const channel = event.data.channel;
|
||||
const count = event.data.count;
|
||||
if (!['updates', 'following'].includes(channel)
|
||||
if (!['updates', 'following', 'human-gates'].includes(channel)
|
||||
|| !Number.isSafeInteger(count) || count < 0 || count > 9999) return;
|
||||
try {
|
||||
if (await appBadgePreference.get()) {
|
||||
@@ -699,6 +709,7 @@ self.addEventListener('push', event => {
|
||||
const unreadCount = typeof payload.unread_count === 'number' ? payload.unread_count : NaN;
|
||||
const deadlineCount = Number(payload.deadline_count);
|
||||
const followingCount = Number(payload.following_count);
|
||||
const humanGateCount = Number(payload.human_gate_count);
|
||||
const planDate = String(payload.plan_date || '');
|
||||
if (
|
||||
route === '#/my-work/start-day'
|
||||
@@ -735,6 +746,25 @@ self.addEventListener('push', event => {
|
||||
));
|
||||
return;
|
||||
}
|
||||
if (
|
||||
route === '#/my-work/human-gates'
|
||||
&& tag === 'stackchain-human-gates-' + humanGateCount
|
||||
&& Number.isSafeInteger(humanGateCount)
|
||||
&& humanGateCount > 0
|
||||
&& humanGateCount <= 50
|
||||
) {
|
||||
event.waitUntil(Promise.all([
|
||||
reconcileBackgroundAppBadge('human-gates', humanGateCount),
|
||||
self.registration.showNotification(
|
||||
humanGateCount + ' release decision' + (humanGateCount === 1 ? ' is' : 's are') + ' waiting', {
|
||||
body: 'Open Human Gates to review ' + (humanGateCount === 1 ? 'it.' : 'them.'),
|
||||
tag,
|
||||
data: {route},
|
||||
}
|
||||
),
|
||||
]));
|
||||
return;
|
||||
}
|
||||
if (
|
||||
route === '#/my-work/following'
|
||||
&& /^stackchain-following-[0-9a-f]{16}$/.test(tag)
|
||||
|
||||
@@ -117,16 +117,17 @@ function createTodayTimer({ storage, getLogin, now = () => Date.now(), onChange
|
||||
}
|
||||
if (!ledger[identity] || ledger[identity].elapsed_ms !== Math.floor(Number(elapsedMs))) return false;
|
||||
const state = read();
|
||||
const keepBreak = validBreak(state)?.identity === identity;
|
||||
state.active_identity = identity;
|
||||
state.entries = ledger;
|
||||
state.entries[identity].started_at = running ? now() : null;
|
||||
state.entries[identity].running = Boolean(running);
|
||||
state.entries[identity].started_at = running && !keepBreak ? now() : null;
|
||||
state.entries[identity].running = Boolean(running) && !keepBreak;
|
||||
state.away_at = null;
|
||||
state.pending_interruption = null;
|
||||
state.attention_interruption = null;
|
||||
state.search_interruption = null;
|
||||
state.detour_interruption = null;
|
||||
if(running || validBreak(state)?.identity !== identity) state.timed_break=null;
|
||||
if (!keepBreak) state.timed_break = null;
|
||||
return write(state);
|
||||
},
|
||||
activate(identity) {
|
||||
|
||||
@@ -337,10 +337,9 @@ function mountTodayWeekReschedule({
|
||||
dialog.addEventListener('cancel',event=>{event.preventDefault();close();});
|
||||
confirm.addEventListener('click',async()=>{
|
||||
if(!selectedDate)return;
|
||||
confirm.disabled=true;status.textContent='Moving Today into Week Ahead…';
|
||||
confirm.disabled=true;status.textContent='Moving Today into Week Ahead…';dialog.close();
|
||||
try{
|
||||
const result=await controller.confirm(selectedDate,Number(estimate.value),{allowOverload});
|
||||
dialog.close();
|
||||
if(result.sync_pending){
|
||||
announce('Moved locally. Saved on this device · sync pending.');warm();
|
||||
}else{
|
||||
@@ -348,6 +347,7 @@ function mountTodayWeekReschedule({
|
||||
}
|
||||
await continueToday();
|
||||
}catch(error){
|
||||
if(!dialog.open)dialog.showModal();
|
||||
const overload=error.message.includes('Confirm overload');allowOverload=overload;
|
||||
status.textContent=error.message;
|
||||
confirm.textContent=overload?'Confirm overload & continue':'Move to Week Ahead & continue';
|
||||
|
||||
@@ -2,76 +2,110 @@ async function loadWorkspace({
|
||||
document,
|
||||
window = null,
|
||||
createLoader = createFeatureLoader,
|
||||
schedule = callback => setTimeout(callback,750),
|
||||
schedule = callback => setTimeout(callback, 750),
|
||||
}) {
|
||||
let cameOnline = false;
|
||||
let replayed = false;
|
||||
let retryInFlight = null;
|
||||
const captureOnline = () => { cameOnline = true; };
|
||||
window?.addEventListener('online', captureOnline);
|
||||
|
||||
const status = document.querySelector('#my-work-action-status');
|
||||
const retryButton = document.querySelector('#retry-workspace');
|
||||
const urls = Object.fromEntries(['today-timer', 'planning'].map(name => [name,
|
||||
const names = ['work-core', 'today-timer', 'planning'];
|
||||
const urls = Object.fromEntries(names.map(name => [name,
|
||||
document.querySelector(`meta[name="stackchain-feature-${name}"]`)?.content || ''
|
||||
]));
|
||||
const originalUrls = {...urls};
|
||||
const loader = createLoader({document, urls});
|
||||
const attempts = Object.fromEntries(names.map(name => [name, 0]));
|
||||
const failed = new Set();
|
||||
const recoveries = new Map();
|
||||
let retryInFlight = null;
|
||||
|
||||
let attempts = 0;
|
||||
const load = () => {
|
||||
if (attempts++) Object.keys(urls).forEach(name => {
|
||||
urls[name] = originalUrls[name] + '?retry=' + attempts;
|
||||
});
|
||||
return Promise.all(Object.keys(urls).map(name => loader.load(name)));
|
||||
const loadFeature = name => {
|
||||
attempts[name] += 1;
|
||||
urls[name] = originalUrls[name] + (attempts[name] > 1 ? '?retry=' + attempts[name] : '');
|
||||
return loader.load(name);
|
||||
};
|
||||
const waitForRecovery = () => new Promise(resolve => {
|
||||
if (status) status.textContent = 'Workspace unavailable. Reconnect or retry.';
|
||||
if (retryButton) {
|
||||
retryButton.hidden = retryButton.disabled = false;
|
||||
const retryOnce = async name => {
|
||||
try { return await loadFeature(name); }
|
||||
catch (_error) {
|
||||
await new Promise(resolve => schedule(resolve));
|
||||
return loadFeature(name);
|
||||
}
|
||||
|
||||
const recover = () => {
|
||||
if (retryInFlight) return retryInFlight;
|
||||
if (retryButton) retryButton.disabled = true;
|
||||
retryInFlight = load().then(() => {
|
||||
window?.removeEventListener('online', recover);
|
||||
resolve();
|
||||
}).catch(() => {
|
||||
if (status) status.textContent = 'Workspace unavailable. Reconnect or retry.';
|
||||
if (retryButton) retryButton.disabled = false;
|
||||
}).finally(() => {
|
||||
retryInFlight = null;
|
||||
});
|
||||
return retryInFlight;
|
||||
};
|
||||
|
||||
window?.removeEventListener('online', captureOnline);
|
||||
window?.addEventListener('online', recover);
|
||||
retryButton?.addEventListener('click', recover);
|
||||
});
|
||||
};
|
||||
const showRecovery = () => {
|
||||
if (status) status.textContent = failed.has('work-core') ?
|
||||
'Workspace unavailable. Reconnect or retry.' :
|
||||
'Today or planning tools unavailable. My Work is ready; reconnect or retry.';
|
||||
if (retryButton) retryButton.hidden = retryButton.disabled = false;
|
||||
};
|
||||
const hideRecovery = () => {
|
||||
if (failed.size) return;
|
||||
if (retryButton) retryButton.hidden = true;
|
||||
if (status) status.textContent = '';
|
||||
};
|
||||
const retryFailed = () => {
|
||||
if (retryInFlight) return retryInFlight;
|
||||
if (retryButton) retryButton.disabled = true;
|
||||
const pending = Array.from(failed);
|
||||
retryInFlight = Promise.all(pending.map(async name => {
|
||||
try {
|
||||
await loadFeature(name);
|
||||
failed.delete(name);
|
||||
recoveries.get(name)?.resolve(true);
|
||||
recoveries.delete(name);
|
||||
} catch (_error) {}
|
||||
})).then(() => {
|
||||
if (failed.size) showRecovery();
|
||||
else hideRecovery();
|
||||
}).finally(() => { retryInFlight = null; });
|
||||
return retryInFlight;
|
||||
};
|
||||
retryButton?.addEventListener?.('click', retryFailed);
|
||||
const handleOnline = () => { cameOnline = true; void retryFailed(); };
|
||||
window?.addEventListener('online', handleOnline);
|
||||
|
||||
try {
|
||||
await load();
|
||||
} catch {
|
||||
await new Promise(resolve => schedule(resolve));
|
||||
try {
|
||||
await load();
|
||||
} catch {
|
||||
await waitForRecovery();
|
||||
}
|
||||
await retryOnce('work-core');
|
||||
} catch (_error) {
|
||||
failed.add('work-core');
|
||||
showRecovery();
|
||||
await new Promise(resolve => recoveries.set('work-core', {resolve}));
|
||||
}
|
||||
hideRecovery();
|
||||
|
||||
const optional = ['today-timer', 'planning'].map(async name => {
|
||||
try {
|
||||
await retryOnce(name);
|
||||
return true;
|
||||
} catch (_error) {
|
||||
failed.add(name);
|
||||
showRecovery();
|
||||
return new Promise(resolve => recoveries.set(name, {resolve}));
|
||||
}
|
||||
});
|
||||
const optionalReady = Promise.all(optional).then(() => {
|
||||
hideRecovery();
|
||||
return true;
|
||||
});
|
||||
|
||||
window?.removeEventListener('online', captureOnline);
|
||||
if (retryButton) retryButton.hidden = true;
|
||||
if (status) status.textContent = '';
|
||||
return {
|
||||
optionalReady,
|
||||
retryFeature(name) {
|
||||
if (!failed.has(name)) return Promise.resolve(true);
|
||||
return retryFailed().then(() => !failed.has(name));
|
||||
},
|
||||
replayOnline(callback) {
|
||||
if (replayed) return;
|
||||
replayed = true;
|
||||
window?.removeEventListener('online', captureOnline);
|
||||
window?.removeEventListener('online', handleOnline);
|
||||
if (cameOnline) callback();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof window !== 'undefined' && typeof document !== 'undefined' &&
|
||||
typeof createFeatureLoader === 'function') {
|
||||
window.stackchainWorkspaceLifecycle = loadWorkspace({document, window});
|
||||
}
|
||||
|
||||
if (typeof module !== 'undefined' && module.exports) module.exports = loadWorkspace;
|
||||
+15
-4
@@ -32,6 +32,8 @@ class Session:
|
||||
csrf: str
|
||||
expires_at: int
|
||||
idle_expires_at: int | None = None
|
||||
principal_id: int | None = None
|
||||
principal_login: str | None = None
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -145,6 +147,8 @@ def issue_session(
|
||||
*,
|
||||
device_label: str = "This device",
|
||||
management_id: str | None = None,
|
||||
principal_id: int | None = None,
|
||||
principal_login: str | None = None,
|
||||
) -> tuple[str, Session]:
|
||||
issued_at = int(time.time() if now is None else now)
|
||||
ttl = int(os.getenv("STACKCHAIN_DASHBOARD_SESSION_TTL_SECONDS", str(DEFAULT_TTL_SECONDS)))
|
||||
@@ -165,6 +169,8 @@ def issue_session(
|
||||
session.expires_at,
|
||||
device_label=device_label,
|
||||
management_id=management_id,
|
||||
principal_id=principal_id,
|
||||
principal_login=principal_login,
|
||||
)
|
||||
return f"{encoded}.{signature}", session
|
||||
|
||||
@@ -211,6 +217,8 @@ def verify_session_with_reason(
|
||||
csrf=session.csrf,
|
||||
expires_at=session.expires_at,
|
||||
idle_expires_at=getattr(status, "idle_expires_at", None),
|
||||
principal_id=getattr(status, "principal_id", None),
|
||||
principal_login=getattr(status, "principal_login", None),
|
||||
)
|
||||
)
|
||||
|
||||
@@ -244,11 +252,14 @@ async def managed_session_active(management_id: str) -> bool:
|
||||
return status == "active"
|
||||
|
||||
|
||||
async def managed_session_statuses(management_ids) -> dict[str, str]:
|
||||
async def managed_session_statuses(
|
||||
management_ids, *, expected_principal_id: int | None = None
|
||||
) -> dict[str, str]:
|
||||
options = {"idle_timeout_seconds": idle_timeout_seconds()}
|
||||
if expected_principal_id is not None:
|
||||
options["expected_principal_id"] = expected_principal_id
|
||||
return await asyncio.to_thread(
|
||||
_session_store().managed_statuses,
|
||||
management_ids,
|
||||
idle_timeout_seconds=idle_timeout_seconds(),
|
||||
_session_store().managed_statuses, management_ids, **options
|
||||
)
|
||||
|
||||
|
||||
|
||||
+11
-7
@@ -21,9 +21,13 @@ COMMONJS_BROWSER_BRANCH = re.compile(
|
||||
)
|
||||
WORKER_RUNTIME_SOURCE = "static/background-issue-sync.js"
|
||||
FEATURE_SOURCES = {
|
||||
"work-core": (
|
||||
"static/my-work.js", "static/progressive-my-work.js", "static/progressive-mobile-dock.js",
|
||||
"static/unfiled-captures.js", "static/progressive-capture.js",
|
||||
),
|
||||
"comment-actions": ("static/comment-actions.js",),
|
||||
"issue-capture": (
|
||||
"static/voice-transcript-store.js", "static/voice-issue-capture.js", "static/create-issue-sheet.js", "static/mobile-create-issue-nav.js", "static/update-follow-up.js", "static/shared-image-capture.js",
|
||||
"static/voice-transcript-store.js", "static/voice-issue-capture.js", "static/create-issue-sheet.js", "static/create-pull-sheet.js", "static/mobile-create-issue-nav.js", "static/update-follow-up.js", "static/shared-image-capture.js",
|
||||
),
|
||||
"pull-workflow": ("static/pull-sheet.js", "static/review-sheet.js", "static/release-receipt.js"),
|
||||
"push-notifications": ("static/push-notifications.js",),
|
||||
@@ -35,18 +39,18 @@ FEATURE_SOURCES = {
|
||||
"security-center": ("static/security-center.js",),
|
||||
"planning": (
|
||||
"static/plan-today.js", "static/plan-today-readiness.js",
|
||||
"static/plan-today-preview.js", "static/today-rollover.js", "static/today-readiness.js", "static/following.js",
|
||||
"static/plan-today-preview.js", "static/today-rollover.js", "static/today-readiness.js", "static/following.js", "static/search-preview.js",
|
||||
"static/tomorrow-plan.js", "static/week-calendar.js", "static/week-calendar-import.js", "static/week-plan.js", "static/today-week-reschedule.js", "static/search-week-plan.js", "static/search-batch-plan.js", "static/agenda-session-launcher.js", "static/mobile-plan-today-nav.js",
|
||||
),
|
||||
"today-timer": (
|
||||
"static/mobile-app-badge.js", "static/conversation.js", "static/widgets.js", "static/voice-transcript-store.js", "static/voice-conversation-capture.js", "static/mobile-launch.js", "static/mobile-insights.js", "static/mobile-app-shortcuts.js", "static/mobile-find-work-nav.js", "static/mobile-pull-refresh.js", "static/live-data-status.js", "static/mobile-composer-viewport.js",
|
||||
"static/today-completion.js", "static/card-planning.js", "static/work-detail-position.js", "static/work-route.js", "static/commands.js", "static/saved-searches.js", "static/task-overlay-history.js", "static/search-preview.js", "static/mobile-search-preview-nav.js", "static/search-reply-draft-store.js", "static/conversation-reply-draft-store.js", "static/conversation-photo-drafts.js", "static/search-defer.js", "static/mobile-search-viewport.js", "static/agenda-replan.js", "static/agenda-calendar.js", "static/my-work.js", "static/protect-today.js", "static/mobile-today-command-bar.js", "static/mobile-task-dock.js", "static/mobile-first-task.js", "static/mobile-work-entry.js", "static/mobile-queue-launcher.js", "static/mobile-delivery-recovery.js", "static/mobile-start-day.js", "static/update-triage-session.js", "static/update-review-handoff.js", "static/update-triage-launcher.js", "static/update-triage-gesture.js", "static/notification-undo.js", "static/today-timer.js", "static/today-break.js", "static/today-progress.js", "static/today-lock-screen.js", "static/today-session-sync.js", "static/today-recap.js", "static/today-wrap-up.js", "static/today-summary.js", "static/today-handoff.js",
|
||||
"static/later-work.js", "static/detail-defer.js", "static/later-picker.js", "static/drafts.js", "static/unfiled-captures.js", "static/unfiled-draft-sync.js",
|
||||
"static/mobile-app-badge.js", "static/conversation.js", "static/widgets.js", "static/voice-transcript-store.js", "static/voice-conversation-capture.js", "static/mobile-launch.js", "static/mobile-insights.js", "static/mobile-app-shortcuts.js", "static/mobile-find-work-nav.js", "static/mobile-pull-refresh.js", "static/live-data-status.js", "static/mobile-search-modal.js", "static/mobile-composer-viewport.js",
|
||||
"static/today-completion.js", "static/card-planning.js", "static/work-detail-position.js", "static/work-route.js", "static/commands.js", "static/saved-searches.js", "static/task-overlay-history.js", "static/mobile-search-preview-nav.js", "static/search-reply-draft-store.js", "static/conversation-reply-draft-store.js", "static/conversation-photo-drafts.js", "static/search-defer.js", "static/mobile-search-viewport.js", "static/agenda-replan.js", "static/agenda-calendar.js", "static/protect-today.js", "static/mobile-today-command-bar.js", "static/mobile-task-dock.js", "static/mobile-first-task.js", "static/mobile-work-entry.js", "static/mobile-queue-launcher.js", "static/mobile-delivery-recovery.js", "static/mobile-start-day.js", "static/update-triage-session.js", "static/update-review-handoff.js", "static/update-triage-launcher.js", "static/update-triage-gesture.js", "static/notification-undo.js", "static/today-timer.js", "static/today-break.js", "static/today-progress.js", "static/today-lock-screen.js", "static/today-session-sync.js", "static/today-recap.js", "static/today-wrap-up.js", "static/today-summary.js", "static/today-handoff.js",
|
||||
"static/later-work.js", "static/detail-defer.js", "static/later-picker.js", "static/drafts.js", "static/photo-draft-inbox.js", "static/unfiled-draft-sync.js",
|
||||
"static/assign-and-start.js", "static/filed-claim.js", "static/queue-today.js", "static/create-and-start.js",
|
||||
"static/draft-filing-session.js", "static/draft-capacity-dialog.js", "static/work-selection.js",
|
||||
"static/today-work.js", "static/today-sync.js", "static/pick-work.js", "static/batch-find-work.js",
|
||||
"static/mention-composer.js", "static/issue-evidence-review.js", "static/issue-evidence-editor.js",
|
||||
"static/issue-attachment.js", "static/checklist-conflict.js", "static/issue-outbox.js", "static/authored-outbox.js", "static/issue-sheet.js", "static/mobile-issue-detail-nav.js", "static/issue-filing-review.js", "static/issue-filing-receipt.js",
|
||||
"static/issue-attachment.js", "static/checklist-conflict.js", "static/issue-outbox.js", "static/authored-outbox.js", "static/issue-sheet.js", "static/mobile-issue-detail-nav.js", "static/mobile-update-detail-nav.js", "static/issue-filing-review.js", "static/issue-filing-receipt.js", "static/dashboard.js",
|
||||
),
|
||||
}
|
||||
CACHE_DECLARATION = re.compile(
|
||||
@@ -122,7 +126,7 @@ def build_frontend(frontend_dir: Path) -> FrontendBuild:
|
||||
)
|
||||
workspace_preload = (
|
||||
f'<link rel="preload" as="script" '
|
||||
f'href="{feature_bundles["today-timer"].runtime_name}">'
|
||||
f'href="{feature_bundles["work-core"].runtime_name}">'
|
||||
)
|
||||
dashboard_html = dashboard_html.replace(
|
||||
"</head>", feature_metadata + "\n" + workspace_preload + "\n</head>"
|
||||
|
||||
+1153
-15
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,330 @@
|
||||
"""Durable, account-bound human release gate inbox."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import re
|
||||
import sqlite3
|
||||
import uuid
|
||||
from pathlib import Path
|
||||
from typing import Callable
|
||||
|
||||
from src.private_state import connect_private_sqlite
|
||||
|
||||
|
||||
_HASH = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._:-]{1,127}$")
|
||||
_PROJECT = re.compile(r"^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$")
|
||||
_STATES = {"pending", "released", "held", "superseded"}
|
||||
_CHECKLIST = {"exact_hash", "artifacts_reviewed", "provenance_reviewed"}
|
||||
|
||||
|
||||
class GateConflict(RuntimeError):
|
||||
"""The gate or idempotency revision no longer matches."""
|
||||
|
||||
|
||||
class GateValidationError(ValueError):
|
||||
"""The producer or reviewer payload is not safe to persist."""
|
||||
|
||||
|
||||
class GateNotFound(LookupError):
|
||||
"""No gate exists for this account."""
|
||||
|
||||
|
||||
def _canonical(value: object) -> str:
|
||||
return json.dumps(value, sort_keys=True, separators=(",", ":"), ensure_ascii=False)
|
||||
|
||||
|
||||
def _fingerprint(value: object) -> str:
|
||||
return hashlib.sha256(_canonical(value).encode()).hexdigest()
|
||||
|
||||
|
||||
class HumanGateStore:
|
||||
def __init__(self, path: str | Path, *, clock: Callable[[], float]):
|
||||
self.path = Path(path)
|
||||
self.clock = clock
|
||||
self._initialize()
|
||||
|
||||
def _connect(self) -> sqlite3.Connection:
|
||||
connection = connect_private_sqlite(self.path, timeout=2.0)
|
||||
connection.row_factory = sqlite3.Row
|
||||
return connection
|
||||
|
||||
def _initialize(self) -> None:
|
||||
with self._connect() as connection:
|
||||
connection.execute("PRAGMA journal_mode=WAL")
|
||||
connection.executescript(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS human_gates (
|
||||
id TEXT PRIMARY KEY, login TEXT NOT NULL, source TEXT NOT NULL,
|
||||
project TEXT NOT NULL, candidate_hash TEXT NOT NULL,
|
||||
title TEXT NOT NULL, priority INTEGER NOT NULL,
|
||||
payload_json TEXT NOT NULL, state TEXT NOT NULL,
|
||||
revision INTEGER NOT NULL, created_at REAL NOT NULL,
|
||||
updated_at REAL NOT NULL, superseded_by TEXT,
|
||||
decision_reason TEXT NOT NULL DEFAULT '',
|
||||
override_reason TEXT NOT NULL DEFAULT '',
|
||||
checklist_json TEXT NOT NULL DEFAULT '{}',
|
||||
UNIQUE(login, source, project, candidate_hash)
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS human_gates_queue
|
||||
ON human_gates(login, state, priority DESC, created_at, id);
|
||||
CREATE TABLE IF NOT EXISTS human_gate_intake_keys (
|
||||
login TEXT NOT NULL, idempotency_key TEXT NOT NULL,
|
||||
fingerprint TEXT NOT NULL, gate_id TEXT NOT NULL,
|
||||
PRIMARY KEY(login, idempotency_key)
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS human_gate_history (
|
||||
sequence INTEGER PRIMARY KEY AUTOINCREMENT, gate_id TEXT NOT NULL,
|
||||
action TEXT NOT NULL, at REAL NOT NULL, details_json TEXT NOT NULL
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS human_gate_receipts (
|
||||
receipt_id TEXT PRIMARY KEY, login TEXT NOT NULL,
|
||||
idempotency_key TEXT NOT NULL, fingerprint TEXT NOT NULL,
|
||||
gate_id TEXT NOT NULL, receipt_json TEXT NOT NULL,
|
||||
UNIQUE(login, idempotency_key)
|
||||
);
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _login(value: str) -> str:
|
||||
value = str(value).strip().lower()
|
||||
if not value or len(value) > 255:
|
||||
raise GateValidationError("login is required")
|
||||
return value
|
||||
|
||||
@staticmethod
|
||||
def _key(value: str) -> str:
|
||||
value = str(value).strip()
|
||||
if not value or len(value) > 128:
|
||||
raise GateValidationError("Idempotency key is required")
|
||||
return value
|
||||
|
||||
@staticmethod
|
||||
def _candidate(raw: dict) -> dict:
|
||||
if not isinstance(raw, dict):
|
||||
raise GateValidationError("Candidate must be an object")
|
||||
source = str(raw.get("source", "")).strip()
|
||||
project = str(raw.get("project", "")).strip()
|
||||
candidate_hash = str(raw.get("candidate_hash", "")).strip()
|
||||
title = " ".join(str(raw.get("title", "")).split())
|
||||
priority = raw.get("priority", 0)
|
||||
if not source or len(source) > 128:
|
||||
raise GateValidationError("source is invalid")
|
||||
if not _PROJECT.fullmatch(project):
|
||||
raise GateValidationError("project is invalid")
|
||||
if not _HASH.fullmatch(candidate_hash):
|
||||
raise GateValidationError("candidate hash is invalid")
|
||||
if not title or len(title) > 300:
|
||||
raise GateValidationError("title is invalid")
|
||||
if isinstance(priority, bool) or not isinstance(priority, int) or not 0 <= priority <= 100:
|
||||
raise GateValidationError("priority is invalid")
|
||||
normalized = {
|
||||
"source": source, "project": project, "candidate_hash": candidate_hash,
|
||||
"title": title, "priority": priority,
|
||||
"artifacts": HumanGateStore._references(raw.get("artifacts", []), "name"),
|
||||
"links": HumanGateStore._references(raw.get("links", []), "label"),
|
||||
"checks": HumanGateStore._checks(raw.get("checks", [])),
|
||||
"score": raw.get("score") if isinstance(raw.get("score"), dict) else {},
|
||||
"provenance": raw.get("provenance") if isinstance(raw.get("provenance"), dict) else {},
|
||||
}
|
||||
if len(_canonical(normalized)) > 100_000:
|
||||
raise GateValidationError("Candidate payload is too large")
|
||||
return normalized
|
||||
|
||||
@staticmethod
|
||||
def _references(raw: object, label: str) -> list[dict]:
|
||||
if not isinstance(raw, list) or len(raw) > 50:
|
||||
raise GateValidationError("references are invalid")
|
||||
result = []
|
||||
for item in raw:
|
||||
if not isinstance(item, dict):
|
||||
raise GateValidationError("reference is invalid")
|
||||
name, url = str(item.get(label, "")).strip(), str(item.get("url", "")).strip()
|
||||
if not name or len(name) > 200 or not url.startswith("https://") or len(url) > 2048:
|
||||
raise GateValidationError("reference is invalid")
|
||||
result.append({label: name, "url": url})
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def _checks(raw: object) -> list[dict]:
|
||||
if not isinstance(raw, list) or len(raw) > 100:
|
||||
raise GateValidationError("checks are invalid")
|
||||
result = []
|
||||
for item in raw:
|
||||
if not isinstance(item, dict):
|
||||
raise GateValidationError("check is invalid")
|
||||
name, state = str(item.get("name", "")).strip(), item.get("state")
|
||||
if not name or len(name) > 200 or state not in {"success", "failure", "pending", "skipped"}:
|
||||
raise GateValidationError("check is invalid")
|
||||
result.append({"name": name, "state": state, "required": bool(item.get("required", True))})
|
||||
return result
|
||||
|
||||
def _history(self, connection: sqlite3.Connection, gate_id: str) -> list[dict]:
|
||||
return [
|
||||
{"sequence": row[0], "action": row[1], "at": row[2], **json.loads(row[3])}
|
||||
for row in connection.execute(
|
||||
"SELECT sequence, action, at, details_json FROM human_gate_history WHERE gate_id=? ORDER BY sequence",
|
||||
(gate_id,),
|
||||
)
|
||||
]
|
||||
|
||||
def _present(self, connection: sqlite3.Connection, row: sqlite3.Row, *, history: bool = False) -> dict:
|
||||
payload = json.loads(row["payload_json"])
|
||||
item = {
|
||||
"id": row["id"], **payload, "state": row["state"], "revision": row["revision"],
|
||||
"created_at": row["created_at"], "updated_at": row["updated_at"],
|
||||
"superseded_by": row["superseded_by"],
|
||||
}
|
||||
if row["state"] in {"released", "held"}:
|
||||
item.update({
|
||||
"reason": row["decision_reason"], "override_reason": row["override_reason"],
|
||||
"checklist": json.loads(row["checklist_json"]),
|
||||
})
|
||||
if history:
|
||||
item["history"] = self._history(connection, row["id"])
|
||||
return item
|
||||
|
||||
def has_intake_key(self, login: str, idempotency_key: str) -> bool:
|
||||
with self._connect() as connection:
|
||||
return connection.execute(
|
||||
"SELECT 1 FROM human_gate_intake_keys WHERE login=? AND idempotency_key=?",
|
||||
(self._login(login), self._key(idempotency_key)),
|
||||
).fetchone() is not None
|
||||
|
||||
def intake(self, login: str, raw: dict, *, idempotency_key: str) -> dict:
|
||||
login, key, payload = self._login(login), self._key(idempotency_key), self._candidate(raw)
|
||||
fingerprint = _fingerprint(payload)
|
||||
with self._connect() as connection:
|
||||
connection.execute("BEGIN IMMEDIATE")
|
||||
prior = connection.execute(
|
||||
"SELECT fingerprint, gate_id FROM human_gate_intake_keys WHERE login=? AND idempotency_key=?",
|
||||
(login, key),
|
||||
).fetchone()
|
||||
if prior:
|
||||
if prior["fingerprint"] != fingerprint:
|
||||
raise GateConflict("Idempotency key was already used for another candidate")
|
||||
row = connection.execute("SELECT * FROM human_gates WHERE id=? AND login=?", (prior["gate_id"], login)).fetchone()
|
||||
return self._present(connection, row, history=True)
|
||||
existing = connection.execute(
|
||||
"SELECT * FROM human_gates WHERE login=? AND source=? AND project=? AND candidate_hash=?",
|
||||
(login, payload["source"], payload["project"], payload["candidate_hash"]),
|
||||
).fetchone()
|
||||
if existing:
|
||||
old_payload = json.loads(existing["payload_json"])
|
||||
immutable_old = {key: value for key, value in old_payload.items() if key != "checks"}
|
||||
immutable_new = {key: value for key, value in payload.items() if key != "checks"}
|
||||
if immutable_old != immutable_new:
|
||||
raise GateConflict("Candidate hash is already bound to different facts")
|
||||
if old_payload != payload:
|
||||
if existing["state"] == "superseded":
|
||||
raise GateConflict("Candidate hash was superseded by a newer candidate")
|
||||
now = float(self.clock())
|
||||
revision = existing["revision"] + 1
|
||||
reopened = existing["state"] in {"released", "held"}
|
||||
state = "pending" if reopened else existing["state"]
|
||||
action = "reopened" if reopened else "updated"
|
||||
connection.execute(
|
||||
"UPDATE human_gates SET payload_json=?, state=?, revision=?, updated_at=?, decision_reason='', override_reason='', checklist_json='{}' WHERE id=?",
|
||||
(_canonical(payload), state, revision, now, existing["id"]),
|
||||
)
|
||||
connection.execute(
|
||||
"INSERT INTO human_gate_history(gate_id,action,at,details_json) VALUES (?,?,?,?)",
|
||||
(existing["id"], action, now, _canonical({"candidate_hash": payload["candidate_hash"]})),
|
||||
)
|
||||
existing = connection.execute(
|
||||
"SELECT * FROM human_gates WHERE id=? AND login=?",
|
||||
(existing["id"], login),
|
||||
).fetchone()
|
||||
connection.execute("INSERT INTO human_gate_intake_keys VALUES (?,?,?,?)", (login, key, fingerprint, existing["id"]))
|
||||
return self._present(connection, existing, history=True)
|
||||
now, gate_id = float(self.clock()), str(uuid.uuid4())
|
||||
old_rows = connection.execute(
|
||||
"SELECT id, revision FROM human_gates WHERE login=? AND source=? AND project=? AND state='pending'",
|
||||
(login, payload["source"], payload["project"]),
|
||||
).fetchall()
|
||||
connection.execute(
|
||||
"INSERT INTO human_gates(id,login,source,project,candidate_hash,title,priority,payload_json,state,revision,created_at,updated_at) VALUES (?,?,?,?,?,?,?,?, 'pending',1,?,?)",
|
||||
(gate_id, login, payload["source"], payload["project"], payload["candidate_hash"], payload["title"], payload["priority"], _canonical(payload), now, now),
|
||||
)
|
||||
connection.execute("INSERT INTO human_gate_history(gate_id,action,at,details_json) VALUES (?,?,?,?)", (gate_id, "intake", now, _canonical({"candidate_hash": payload["candidate_hash"]})))
|
||||
for old in old_rows:
|
||||
connection.execute("UPDATE human_gates SET state='superseded', revision=?, updated_at=?, superseded_by=? WHERE id=? AND state='pending'", (old["revision"] + 1, now, gate_id, old["id"]))
|
||||
connection.execute("INSERT INTO human_gate_history(gate_id,action,at,details_json) VALUES (?,?,?,?)", (old["id"], "superseded", now, _canonical({"superseded_by": gate_id, "candidate_hash": payload["candidate_hash"]})))
|
||||
connection.execute("INSERT INTO human_gate_intake_keys VALUES (?,?,?,?)", (login, key, fingerprint, gate_id))
|
||||
row = connection.execute("SELECT * FROM human_gates WHERE id=?", (gate_id,)).fetchone()
|
||||
return self._present(connection, row, history=True)
|
||||
|
||||
def list(self, login: str, *, state: str = "pending", limit: int = 100) -> dict:
|
||||
login = self._login(login)
|
||||
if state not in _STATES and state != "all":
|
||||
raise GateValidationError("state is invalid")
|
||||
limit = min(max(int(limit), 1), 100)
|
||||
with self._connect() as connection:
|
||||
pending_count = connection.execute("SELECT COUNT(*) FROM human_gates WHERE login=? AND state='pending'", (login,)).fetchone()[0]
|
||||
where, args = ("login=?", [login]) if state == "all" else ("login=? AND state=?", [login, state])
|
||||
rows = connection.execute(f"SELECT * FROM human_gates WHERE {where} ORDER BY CASE WHEN state='pending' THEN 0 ELSE 1 END, priority DESC, created_at, id LIMIT ?", (*args, limit)).fetchall()
|
||||
return {"pending_count": pending_count, "items": [self._present(connection, row) for row in rows]}
|
||||
|
||||
def detail(self, login: str, gate_id: str) -> dict:
|
||||
with self._connect() as connection:
|
||||
row = connection.execute("SELECT * FROM human_gates WHERE login=? AND id=?", (self._login(login), gate_id)).fetchone()
|
||||
if row is None:
|
||||
raise GateNotFound("Gate not found")
|
||||
return self._present(connection, row, history=True)
|
||||
|
||||
def decide(self, login: str, gate_id: str, *, expected_revision: int, decision: str, reason: str, override_reason: str, checklist: dict, idempotency_key: str) -> dict:
|
||||
login, key = self._login(login), self._key(idempotency_key)
|
||||
reason, override_reason = str(reason).strip(), str(override_reason).strip()
|
||||
if decision not in {"release", "hold"}:
|
||||
raise GateValidationError("decision is invalid")
|
||||
if decision == "hold" and not reason:
|
||||
raise GateValidationError("Hold reason is required")
|
||||
if decision == "release" and (
|
||||
not isinstance(checklist, dict)
|
||||
or set(checklist) != _CHECKLIST
|
||||
or not all(value is True for value in checklist.values())
|
||||
):
|
||||
raise GateValidationError("A complete release checklist is required")
|
||||
if decision == "hold":
|
||||
checklist = {}
|
||||
request = {"gate_id": gate_id, "expected_revision": expected_revision, "decision": decision, "reason": reason, "override_reason": override_reason, "checklist": checklist}
|
||||
fingerprint = _fingerprint(request)
|
||||
with self._connect() as connection:
|
||||
connection.execute("BEGIN IMMEDIATE")
|
||||
prior = connection.execute("SELECT fingerprint, receipt_json FROM human_gate_receipts WHERE login=? AND idempotency_key=?", (login, key)).fetchone()
|
||||
if prior:
|
||||
if prior["fingerprint"] != fingerprint:
|
||||
raise GateConflict("Idempotency key was already used for another decision")
|
||||
return json.loads(prior["receipt_json"])
|
||||
row = connection.execute("SELECT * FROM human_gates WHERE login=? AND id=?", (login, gate_id)).fetchone()
|
||||
if row is None:
|
||||
raise GateNotFound("Gate not found")
|
||||
if row["state"] != "pending" or row["revision"] != expected_revision:
|
||||
raise GateConflict("Gate revision is stale")
|
||||
payload = json.loads(row["payload_json"])
|
||||
unmet = [check["name"] for check in payload["checks"] if check["required"] and check["state"] != "success"]
|
||||
if decision == "release" and unmet and not override_reason:
|
||||
raise GateValidationError("An explicit override reason is required for unmet checks")
|
||||
now, receipt_id, revision = float(self.clock()), str(uuid.uuid4()), row["revision"] + 1
|
||||
state = "released" if decision == "release" else "held"
|
||||
connection.execute("UPDATE human_gates SET state=?,revision=?,updated_at=?,decision_reason=?,override_reason=?,checklist_json=? WHERE id=?", (state, revision, now, reason, override_reason, _canonical(checklist), gate_id))
|
||||
receipt = {"receipt_id": receipt_id, "gate_id": gate_id, "candidate_hash": row["candidate_hash"], "state": state, "revision": revision, "decided_at": now, "reason": reason, "override_reason": override_reason, "checklist": checklist, "unmet_required_checks": unmet}
|
||||
connection.execute("INSERT INTO human_gate_history(gate_id,action,at,details_json) VALUES (?,?,?,?)", (gate_id, state, now, _canonical({"receipt_id": receipt_id, "reason": reason, "override_reason": override_reason, "unmet_required_checks": unmet})))
|
||||
connection.execute("INSERT INTO human_gate_receipts VALUES (?,?,?,?,?,?)", (receipt_id, login, key, fingerprint, gate_id, _canonical(receipt)))
|
||||
return receipt
|
||||
|
||||
def has_receipt_key(self, login: str, idempotency_key: str) -> bool:
|
||||
with self._connect() as connection:
|
||||
return connection.execute(
|
||||
"SELECT 1 FROM human_gate_receipts WHERE login=? AND idempotency_key=?",
|
||||
(self._login(login), self._key(idempotency_key)),
|
||||
).fetchone() is not None
|
||||
|
||||
def receipt(self, login: str, receipt_id: str) -> dict:
|
||||
with self._connect() as connection:
|
||||
row = connection.execute("SELECT receipt_json FROM human_gate_receipts WHERE login=? AND receipt_id=?", (self._login(login), receipt_id)).fetchone()
|
||||
if row is None:
|
||||
raise GateNotFound("Receipt not found")
|
||||
return json.loads(row[0])
|
||||
+1265
-46
File diff suppressed because it is too large.
Load diff
+140
-16
@@ -110,6 +110,7 @@ async def dispatch_following_changes(
|
||||
lease_seconds: float = 60.0,
|
||||
send_timeout_seconds: float = 10.0,
|
||||
max_concurrency: int = 8,
|
||||
now: float | None = None,
|
||||
) -> int:
|
||||
"""Notify opted-in devices once for each privacy-safe Following change set."""
|
||||
if not configuration.enabled:
|
||||
@@ -119,13 +120,15 @@ async def dispatch_following_changes(
|
||||
store.acquire_dispatch_lease,
|
||||
owner,
|
||||
channel="following",
|
||||
now=time.time(),
|
||||
now=time.time() if now is None else now,
|
||||
lease_seconds=max(15.0, lease_seconds, send_timeout_seconds + 5.0),
|
||||
)
|
||||
if not acquired:
|
||||
return 0
|
||||
try:
|
||||
devices = await asyncio.to_thread(store.following_notification_devices)
|
||||
devices = await asyncio.to_thread(
|
||||
store.following_notification_devices, now=now
|
||||
)
|
||||
if not devices:
|
||||
return 0
|
||||
snapshot = await following()
|
||||
@@ -174,17 +177,25 @@ async def dispatch_following_changes(
|
||||
device for device in pending if statuses.get(device.session_id) == "active"
|
||||
]
|
||||
count = min(len(changed), 50)
|
||||
payload = json.dumps({
|
||||
"title": f"{count} watched item{'s' if count != 1 else ''} changed",
|
||||
"body": "Open Following to review the latest activity.",
|
||||
"route": "#/my-work/following",
|
||||
"tag": f"stackchain-following-{fingerprint[:16]}",
|
||||
"following_count": count,
|
||||
}, separators=(",", ":"))
|
||||
semaphore = asyncio.Semaphore(max(1, max_concurrency))
|
||||
|
||||
async def dispatch_device(device) -> int:
|
||||
async with semaphore:
|
||||
payload = json.dumps({
|
||||
"title": (
|
||||
f"{count} watched update{'s' if count != 1 else ''} while alerts were paused"
|
||||
if device.catch_up
|
||||
else f"{count} watched item{'s' if count != 1 else ''} changed"
|
||||
),
|
||||
"body": "Open Following to review the latest activity.",
|
||||
"route": "#/my-work/following",
|
||||
"tag": (
|
||||
"stackchain-following-catch-up"
|
||||
if device.catch_up
|
||||
else f"stackchain-following-{fingerprint[:16]}"
|
||||
),
|
||||
"following_count": count,
|
||||
}, separators=(",", ":"))
|
||||
still_owner = await asyncio.to_thread(
|
||||
store.acquire_dispatch_lease,
|
||||
owner,
|
||||
@@ -229,6 +240,104 @@ async def dispatch_following_changes(
|
||||
await asyncio.to_thread(store.release_dispatch_lease, owner, channel="following")
|
||||
|
||||
|
||||
async def dispatch_human_gate_changes(
|
||||
store: PushSubscriptionStore,
|
||||
configuration: PushConfiguration,
|
||||
pending_gates: Callable[[], Awaitable[dict]],
|
||||
send: Callable[[dict, str], Awaitable[None]] | None = None,
|
||||
*,
|
||||
session_statuses: Callable[[list[str]], Awaitable[dict[str, str]]] | None = None,
|
||||
lease_seconds: float = 60.0,
|
||||
send_timeout_seconds: float = 10.0,
|
||||
max_concurrency: int = 8,
|
||||
now: float | None = None,
|
||||
) -> int:
|
||||
"""Notify opted-in active devices when the pending Human Gate count changes."""
|
||||
if not configuration.enabled:
|
||||
return 0
|
||||
owner = secrets.token_urlsafe(18)
|
||||
acquired = await asyncio.to_thread(
|
||||
store.acquire_dispatch_lease,
|
||||
owner,
|
||||
channel="human-gates",
|
||||
now=time.time() if now is None else now,
|
||||
lease_seconds=max(15.0, lease_seconds, send_timeout_seconds + 5.0),
|
||||
)
|
||||
if not acquired:
|
||||
return 0
|
||||
try:
|
||||
devices = await asyncio.to_thread(store.human_gate_notification_devices, now=now)
|
||||
if not devices:
|
||||
return 0
|
||||
snapshot = await pending_gates()
|
||||
if not isinstance(snapshot, dict) or snapshot.get("complete") is False:
|
||||
return 0
|
||||
count = snapshot.get("count")
|
||||
if not isinstance(count, int) or isinstance(count, bool) or count < 0:
|
||||
return 0
|
||||
count = min(count, 50)
|
||||
pending = [device for device in devices if device.delivered_count != count]
|
||||
if not pending:
|
||||
return 0
|
||||
if session_statuses is not None:
|
||||
try:
|
||||
statuses = await session_statuses([device.session_id for device in pending])
|
||||
except Exception:
|
||||
return 0
|
||||
for device in pending:
|
||||
if statuses.get(device.session_id) != "active":
|
||||
await asyncio.to_thread(store.delete_session, device.session_id)
|
||||
pending = [device for device in pending if statuses.get(device.session_id) == "active"]
|
||||
if count == 0:
|
||||
await asyncio.gather(*(
|
||||
asyncio.to_thread(store.mark_human_gate_delivered, device.session_id, 0)
|
||||
for device in pending
|
||||
))
|
||||
return 0
|
||||
semaphore = asyncio.Semaphore(max(1, max_concurrency))
|
||||
|
||||
async def dispatch_device(device) -> int:
|
||||
async with semaphore:
|
||||
payload = json.dumps({
|
||||
"title": f"{count} release decision{' is' if count == 1 else 's are'} waiting",
|
||||
"body": f"Open Human Gates to review {'it' if count == 1 else 'them'}.",
|
||||
"route": "#/my-work/human-gates",
|
||||
"tag": f"stackchain-human-gates-{count}",
|
||||
"human_gate_count": count,
|
||||
}, separators=(",", ":"))
|
||||
try:
|
||||
operation = (
|
||||
send(device.subscription, payload)
|
||||
if send is not None
|
||||
else send_web_push(device.subscription, payload, configuration)
|
||||
)
|
||||
await asyncio.wait_for(operation, timeout=send_timeout_seconds)
|
||||
except Exception as error:
|
||||
status = getattr(getattr(error, "response", None), "status_code", None)
|
||||
if isinstance(error, UnsafePushEndpoint) or status in {404, 410}:
|
||||
await asyncio.to_thread(store.delete_session, device.session_id)
|
||||
else:
|
||||
await asyncio.to_thread(
|
||||
store.mark_delivery_failed, device.session_id, "human-gates",
|
||||
_delivery_failure_reason(error),
|
||||
)
|
||||
return 0
|
||||
await asyncio.to_thread(
|
||||
store.mark_delivery_succeeded, device.session_id, "human-gates"
|
||||
)
|
||||
await asyncio.to_thread(
|
||||
store.mark_human_gate_delivered, device.session_id, count
|
||||
)
|
||||
return 1
|
||||
|
||||
results = await asyncio.gather(
|
||||
*(dispatch_device(device) for device in pending), return_exceptions=True
|
||||
)
|
||||
return sum(result for result in results if isinstance(result, int))
|
||||
finally:
|
||||
await asyncio.to_thread(store.release_dispatch_lease, owner, channel="human-gates")
|
||||
|
||||
|
||||
async def dispatch_unread_updates(
|
||||
store: PushSubscriptionStore,
|
||||
configuration: PushConfiguration,
|
||||
@@ -241,6 +350,7 @@ async def dispatch_unread_updates(
|
||||
max_concurrency: int = 8,
|
||||
max_individual_notifications: int = 3,
|
||||
endpoint_validator: Callable[[str], Awaitable[str]] | None = None,
|
||||
now: float | None = None,
|
||||
) -> int:
|
||||
if not configuration.enabled:
|
||||
return 0
|
||||
@@ -249,7 +359,7 @@ async def dispatch_unread_updates(
|
||||
store.acquire_dispatch_lease,
|
||||
owner,
|
||||
channel="unread",
|
||||
now=time.time(),
|
||||
now=time.time() if now is None else now,
|
||||
lease_seconds=lease_seconds,
|
||||
)
|
||||
if not acquired:
|
||||
@@ -265,7 +375,9 @@ async def dispatch_unread_updates(
|
||||
}
|
||||
unread_count = min(len(thread_revisions), 9999)
|
||||
await asyncio.to_thread(store.reconcile_unread, thread_revisions)
|
||||
deliveries = await asyncio.to_thread(store.claim_unseen, thread_revisions)
|
||||
deliveries = await asyncio.to_thread(
|
||||
store.claim_unseen, thread_revisions, now=now
|
||||
)
|
||||
if session_statuses is not None:
|
||||
try:
|
||||
statuses = await session_statuses(
|
||||
@@ -306,10 +418,10 @@ async def dispatch_unread_updates(
|
||||
for thread_revision in delivery.thread_revisions
|
||||
if thread_revision not in digest_pending
|
||||
)
|
||||
individual_revisions = new_revisions[
|
||||
individual_revisions = () if delivery.catch_up else new_revisions[
|
||||
:max(0, max_individual_notifications)
|
||||
]
|
||||
overflow_revisions = (
|
||||
overflow_revisions = delivery.thread_revisions if delivery.catch_up else (
|
||||
delivery.digest_revisions
|
||||
+ new_revisions[len(individual_revisions):]
|
||||
)
|
||||
@@ -385,10 +497,22 @@ async def dispatch_unread_updates(
|
||||
return count
|
||||
payload = json.dumps(
|
||||
{
|
||||
"title": f"{len(overflow_revisions)} new work updates",
|
||||
"body": "Tap to review them in Stackchain.",
|
||||
"title": (
|
||||
f"{len(overflow_revisions)} updates while alerts were paused"
|
||||
if delivery.catch_up
|
||||
else f"{len(overflow_revisions)} new work updates"
|
||||
),
|
||||
"body": (
|
||||
"Open Updates to catch up in Stackchain."
|
||||
if delivery.catch_up
|
||||
else "Tap to review them in Stackchain."
|
||||
),
|
||||
"route": "#/my-work/updates",
|
||||
"tag": "stackchain-update-digest",
|
||||
"tag": (
|
||||
"stackchain-update-catch-up"
|
||||
if delivery.catch_up
|
||||
else "stackchain-update-digest"
|
||||
),
|
||||
"update_count": len(overflow_revisions),
|
||||
"unread_count": unread_count,
|
||||
},
|
||||
|
||||
+194
-11
@@ -7,7 +7,9 @@ import sqlite3
|
||||
import time
|
||||
from collections.abc import Iterable, Mapping
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime, timezone as datetime_timezone
|
||||
from pathlib import Path
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
from src.private_state import connect_private_sqlite
|
||||
from src.state_encryption import (
|
||||
@@ -22,6 +24,7 @@ class PushDelivery:
|
||||
subscription: dict
|
||||
thread_revisions: tuple[tuple[int, str], ...]
|
||||
digest_revisions: tuple[tuple[int, str], ...] = ()
|
||||
catch_up: bool = False
|
||||
|
||||
@property
|
||||
def thread_ids(self) -> tuple[int, ...]:
|
||||
@@ -57,6 +60,15 @@ class FollowingNotificationDevice:
|
||||
session_id: str
|
||||
subscription: dict
|
||||
delivered_fingerprint: str | None
|
||||
catch_up: bool = False
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class HumanGateNotificationDevice:
|
||||
session_id: str
|
||||
subscription: dict
|
||||
delivered_count: int
|
||||
catch_up: bool = False
|
||||
|
||||
|
||||
class DisabledPushSubscriptionStore:
|
||||
@@ -91,10 +103,19 @@ class DisabledPushSubscriptionStore:
|
||||
def following_preferences(self, session_id: str) -> dict:
|
||||
return {"enabled": False}
|
||||
|
||||
def following_notification_devices(self) -> list[FollowingNotificationDevice]:
|
||||
def human_gate_preferences(self, session_id: str) -> dict:
|
||||
return {"enabled": False}
|
||||
|
||||
def quiet_hours(self, session_id: str) -> dict:
|
||||
return {"enabled": False, "start": "22:00", "end": "07:00", "timezone": "UTC"}
|
||||
|
||||
def following_notification_devices(self, *, now: float | None = None) -> list[FollowingNotificationDevice]:
|
||||
return []
|
||||
|
||||
def claim_unseen(self, thread_revisions) -> list[PushDelivery]:
|
||||
def human_gate_notification_devices(self, *, now: float | None = None) -> list[HumanGateNotificationDevice]:
|
||||
return []
|
||||
|
||||
def claim_unseen(self, thread_revisions, *, now: float | None = None) -> list[PushDelivery]:
|
||||
return []
|
||||
|
||||
def acquire_dispatch_lease(self, *args, **kwargs) -> bool:
|
||||
@@ -133,9 +154,18 @@ class DisabledPushSubscriptionStore:
|
||||
def set_following_preferences(self, *args, **kwargs) -> None:
|
||||
return None
|
||||
|
||||
def set_human_gate_preferences(self, *args, **kwargs) -> None:
|
||||
return None
|
||||
|
||||
def set_quiet_hours(self, *args, **kwargs) -> None:
|
||||
return None
|
||||
|
||||
def mark_following_delivered(self, *args, **kwargs) -> None:
|
||||
return None
|
||||
|
||||
def mark_human_gate_delivered(self, *args, **kwargs) -> None:
|
||||
return None
|
||||
|
||||
def reconcile_unread(self, *args, **kwargs) -> None:
|
||||
return None
|
||||
|
||||
@@ -183,6 +213,16 @@ def _revisions(
|
||||
return tuple(sorted(normalized.items()))
|
||||
|
||||
|
||||
def _inside_quiet_hours(*, now: float, start: str, end: str, timezone: str) -> bool:
|
||||
local = datetime.fromtimestamp(now, tz=datetime_timezone.utc).astimezone(ZoneInfo(timezone))
|
||||
minute = local.hour * 60 + local.minute
|
||||
start_minute = int(start[:2]) * 60 + int(start[3:])
|
||||
end_minute = int(end[:2]) * 60 + int(end[3:])
|
||||
if start_minute < end_minute:
|
||||
return start_minute <= minute < end_minute
|
||||
return minute >= start_minute or minute < end_minute
|
||||
|
||||
|
||||
class PushSubscriptionStore:
|
||||
"""Durable, device-bound Web Push subscriptions and delivery deduplication."""
|
||||
|
||||
@@ -262,6 +302,23 @@ class PushSubscriptionStore:
|
||||
FOREIGN KEY (session_id) REFERENCES push_subscriptions(session_id)
|
||||
ON DELETE CASCADE
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS push_human_gate_preferences (
|
||||
session_id TEXT PRIMARY KEY,
|
||||
enabled INTEGER NOT NULL DEFAULT 0,
|
||||
delivered_count INTEGER NOT NULL DEFAULT 0,
|
||||
FOREIGN KEY (session_id) REFERENCES push_subscriptions(session_id)
|
||||
ON DELETE CASCADE
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS push_quiet_hours (
|
||||
session_id TEXT PRIMARY KEY,
|
||||
enabled INTEGER NOT NULL DEFAULT 0,
|
||||
start_time TEXT NOT NULL DEFAULT '22:00',
|
||||
end_time TEXT NOT NULL DEFAULT '07:00',
|
||||
timezone TEXT NOT NULL DEFAULT 'UTC',
|
||||
suppressed INTEGER NOT NULL DEFAULT 0,
|
||||
FOREIGN KEY (session_id) REFERENCES push_subscriptions(session_id)
|
||||
ON DELETE CASCADE
|
||||
);
|
||||
"""
|
||||
)
|
||||
delivery_columns = {
|
||||
@@ -612,20 +669,81 @@ class PushSubscriptionStore:
|
||||
).fetchone()
|
||||
return {"enabled": bool(row[0]) if row else False}
|
||||
|
||||
def following_notification_devices(self) -> list[FollowingNotificationDevice]:
|
||||
def set_human_gate_preferences(self, session_id: str, *, enabled: bool) -> None:
|
||||
with self._connect() as connection:
|
||||
connection.execute(
|
||||
"""INSERT INTO push_human_gate_preferences(session_id, enabled)
|
||||
VALUES (?, ?)
|
||||
ON CONFLICT(session_id) DO UPDATE SET enabled = excluded.enabled""",
|
||||
(session_id, int(enabled)),
|
||||
)
|
||||
|
||||
def human_gate_preferences(self, session_id: str) -> dict:
|
||||
with self._connect() as connection:
|
||||
row = connection.execute(
|
||||
"SELECT enabled FROM push_human_gate_preferences WHERE session_id = ?",
|
||||
(session_id,),
|
||||
).fetchone()
|
||||
return {"enabled": bool(row[0]) if row else False}
|
||||
|
||||
def set_quiet_hours(
|
||||
self, session_id: str, *, enabled: bool, start: str, end: str, timezone: str
|
||||
) -> None:
|
||||
with self._connect() as connection:
|
||||
connection.execute(
|
||||
"""INSERT INTO push_quiet_hours(
|
||||
session_id, enabled, start_time, end_time, timezone
|
||||
) VALUES (?, ?, ?, ?, ?)
|
||||
ON CONFLICT(session_id) DO UPDATE SET
|
||||
enabled = excluded.enabled,
|
||||
start_time = excluded.start_time,
|
||||
end_time = excluded.end_time,
|
||||
timezone = excluded.timezone,
|
||||
suppressed = CASE WHEN excluded.enabled = 1 THEN suppressed ELSE 0 END""",
|
||||
(session_id, int(enabled), start, end, timezone),
|
||||
)
|
||||
|
||||
def quiet_hours(self, session_id: str) -> dict:
|
||||
with self._connect() as connection:
|
||||
row = connection.execute(
|
||||
"""SELECT enabled, start_time, end_time, timezone
|
||||
FROM push_quiet_hours WHERE session_id = ?""",
|
||||
(session_id,),
|
||||
).fetchone()
|
||||
return {
|
||||
"enabled": bool(row[0]) if row else False,
|
||||
"start": row[1] if row else "22:00",
|
||||
"end": row[2] if row else "07:00",
|
||||
"timezone": row[3] if row else "UTC",
|
||||
}
|
||||
|
||||
def following_notification_devices(
|
||||
self, *, now: float | None = None
|
||||
) -> list[FollowingNotificationDevice]:
|
||||
checked_at = time.time() if now is None else now
|
||||
with self._connect() as connection:
|
||||
rows = connection.execute(
|
||||
"""SELECT s.session_id, s.subscription_json, p.delivered_fingerprint
|
||||
"""SELECT s.session_id, s.subscription_json, p.delivered_fingerprint,
|
||||
q.enabled, q.start_time, q.end_time, q.timezone, q.suppressed
|
||||
FROM push_subscriptions s
|
||||
JOIN push_following_preferences p ON p.session_id = s.session_id
|
||||
LEFT JOIN push_quiet_hours q ON q.session_id = s.session_id
|
||||
WHERE p.enabled = 1 ORDER BY s.session_id"""
|
||||
).fetchall()
|
||||
return [
|
||||
FollowingNotificationDevice(
|
||||
row[0], self._open_subscription(row[0], row[1]), row[2]
|
||||
)
|
||||
for row in rows
|
||||
]
|
||||
devices = []
|
||||
for row in rows:
|
||||
if row[3] and _inside_quiet_hours(
|
||||
now=checked_at, start=row[4], end=row[5], timezone=row[6]
|
||||
):
|
||||
connection.execute(
|
||||
"UPDATE push_quiet_hours SET suppressed = 1 WHERE session_id = ?",
|
||||
(row[0],),
|
||||
)
|
||||
continue
|
||||
devices.append(FollowingNotificationDevice(
|
||||
row[0], self._open_subscription(row[0], row[1]), row[2], bool(row[7])
|
||||
))
|
||||
return devices
|
||||
|
||||
def mark_following_delivered(self, session_id: str, fingerprint: str) -> None:
|
||||
with self._connect() as connection:
|
||||
@@ -634,9 +752,54 @@ class PushSubscriptionStore:
|
||||
WHERE session_id = ? AND enabled = 1""",
|
||||
(fingerprint, session_id),
|
||||
)
|
||||
connection.execute(
|
||||
"UPDATE push_quiet_hours SET suppressed = 0 WHERE session_id = ?",
|
||||
(session_id,),
|
||||
)
|
||||
|
||||
def human_gate_notification_devices(
|
||||
self, *, now: float | None = None
|
||||
) -> list[HumanGateNotificationDevice]:
|
||||
checked_at = time.time() if now is None else now
|
||||
with self._connect() as connection:
|
||||
rows = connection.execute(
|
||||
"""SELECT s.session_id, s.subscription_json, p.delivered_count,
|
||||
q.enabled, q.start_time, q.end_time, q.timezone, q.suppressed
|
||||
FROM push_subscriptions s
|
||||
JOIN push_human_gate_preferences p ON p.session_id = s.session_id
|
||||
LEFT JOIN push_quiet_hours q ON q.session_id = s.session_id
|
||||
WHERE p.enabled = 1 ORDER BY s.session_id"""
|
||||
).fetchall()
|
||||
devices = []
|
||||
for row in rows:
|
||||
if row[3] and _inside_quiet_hours(
|
||||
now=checked_at, start=row[4], end=row[5], timezone=row[6]
|
||||
):
|
||||
connection.execute(
|
||||
"UPDATE push_quiet_hours SET suppressed = 1 WHERE session_id = ?",
|
||||
(row[0],),
|
||||
)
|
||||
continue
|
||||
devices.append(HumanGateNotificationDevice(
|
||||
row[0], self._open_subscription(row[0], row[1]), row[2], bool(row[7])
|
||||
))
|
||||
return devices
|
||||
|
||||
def mark_human_gate_delivered(self, session_id: str, count: int) -> None:
|
||||
with self._connect() as connection:
|
||||
connection.execute(
|
||||
"""UPDATE push_human_gate_preferences SET delivered_count = ?
|
||||
WHERE session_id = ? AND enabled = 1""",
|
||||
(count, session_id),
|
||||
)
|
||||
connection.execute(
|
||||
"UPDATE push_quiet_hours SET suppressed = 0 WHERE session_id = ?",
|
||||
(session_id,),
|
||||
)
|
||||
|
||||
def claim_unseen(
|
||||
self, thread_revisions: Mapping[int, str] | Iterable[int | tuple[int, str]]
|
||||
self, thread_revisions: Mapping[int, str] | Iterable[int | tuple[int, str]],
|
||||
*, now: float | None = None,
|
||||
) -> list[PushDelivery]:
|
||||
candidates = _revisions(thread_revisions)
|
||||
if not candidates:
|
||||
@@ -647,6 +810,21 @@ class PushSubscriptionStore:
|
||||
).fetchall()
|
||||
deliveries = []
|
||||
for session_id, encoded in rows:
|
||||
quiet = connection.execute(
|
||||
"""SELECT enabled, start_time, end_time, timezone, suppressed
|
||||
FROM push_quiet_hours WHERE session_id = ?""",
|
||||
(session_id,),
|
||||
).fetchone()
|
||||
catch_up = bool(quiet and quiet[4])
|
||||
if quiet and quiet[0] and _inside_quiet_hours(
|
||||
now=time.time() if now is None else now,
|
||||
start=quiet[1], end=quiet[2], timezone=quiet[3],
|
||||
):
|
||||
connection.execute(
|
||||
"UPDATE push_quiet_hours SET suppressed = 1 WHERE session_id = ?",
|
||||
(session_id,),
|
||||
)
|
||||
continue
|
||||
delivered = {
|
||||
row[0]: row[1]
|
||||
for row in connection.execute(
|
||||
@@ -700,6 +878,7 @@ class PushSubscriptionStore:
|
||||
self._open_subscription(session_id, encoded),
|
||||
unseen,
|
||||
tuple(digest_revisions),
|
||||
catch_up,
|
||||
)
|
||||
)
|
||||
return deliveries
|
||||
@@ -770,3 +949,7 @@ class PushSubscriptionStore:
|
||||
"DELETE FROM push_digest_pending WHERE session_id = ? AND thread_id = ?",
|
||||
((session_id, thread_id) for thread_id, _revision in values),
|
||||
)
|
||||
connection.execute(
|
||||
"UPDATE push_quiet_hours SET suppressed = 0 WHERE session_id = ?",
|
||||
(session_id,),
|
||||
)
|
||||
@@ -8,7 +8,7 @@ API_MUTATION_BODY_LIMIT = 64 * 1024
|
||||
ISSUE_ATTACHMENT_BODY_LIMIT = 2 * 1024 * 1024 + 64 * 1024
|
||||
LEGACY_JSON_ATTACHMENT_BODY_LIMIT = 3 * 1024 * 1024
|
||||
UNFILED_DRAFT_SYNC_BODY_LIMIT = 17 * 1024 * 1024
|
||||
MUTATION_METHODS = frozenset({"POST", "PUT", "PATCH"})
|
||||
MUTATION_METHODS = frozenset({"POST", "PUT", "PATCH", "DELETE"})
|
||||
|
||||
|
||||
def request_body_limit(method: str, path: str) -> int | None:
|
||||
|
||||
+39
-9
@@ -18,10 +18,20 @@ class SessionStatus(str):
|
||||
"""String-compatible status carrying the server-confirmed idle deadline."""
|
||||
|
||||
idle_expires_at: int | None
|
||||
principal_id: int | None
|
||||
principal_login: str | None
|
||||
|
||||
def __new__(cls, value: str, idle_expires_at: int | None = None):
|
||||
def __new__(
|
||||
cls,
|
||||
value: str,
|
||||
idle_expires_at: int | None = None,
|
||||
principal_id: int | None = None,
|
||||
principal_login: str | None = None,
|
||||
):
|
||||
instance = super().__new__(cls, value)
|
||||
instance.idle_expires_at = idle_expires_at
|
||||
instance.principal_id = principal_id
|
||||
instance.principal_login = principal_login
|
||||
return instance
|
||||
|
||||
|
||||
@@ -71,7 +81,9 @@ class SessionStore:
|
||||
management_id TEXT,
|
||||
device_label TEXT,
|
||||
created_at INTEGER,
|
||||
last_active_at INTEGER
|
||||
last_active_at INTEGER,
|
||||
principal_id INTEGER,
|
||||
principal_login TEXT
|
||||
)
|
||||
"""
|
||||
)
|
||||
@@ -98,6 +110,8 @@ class SessionStore:
|
||||
"device_label": "TEXT",
|
||||
"created_at": "INTEGER",
|
||||
"last_active_at": "INTEGER",
|
||||
"principal_id": "INTEGER",
|
||||
"principal_login": "TEXT",
|
||||
}
|
||||
for name, column_type in additions.items():
|
||||
if name not in columns:
|
||||
@@ -135,6 +149,8 @@ class SessionStore:
|
||||
*,
|
||||
device_label: str = "This device",
|
||||
management_id: str | None = None,
|
||||
principal_id: int | None = None,
|
||||
principal_login: str | None = None,
|
||||
) -> None:
|
||||
label = " ".join(str(device_label).split())[:64] or "This device"
|
||||
now = int(self.clock())
|
||||
@@ -145,8 +161,9 @@ class SessionStore:
|
||||
)
|
||||
connection.execute(
|
||||
"INSERT INTO active_sessions("
|
||||
"session_hash, expires_at, management_id, device_label, created_at, last_active_at"
|
||||
") VALUES (?, ?, ?, ?, ?, ?)",
|
||||
"session_hash, expires_at, management_id, device_label, created_at, last_active_at, "
|
||||
"principal_id, principal_login"
|
||||
") VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
(
|
||||
self._digest(session_id),
|
||||
expires_at,
|
||||
@@ -154,6 +171,8 @@ class SessionStore:
|
||||
label,
|
||||
now,
|
||||
now,
|
||||
principal_id,
|
||||
principal_login,
|
||||
),
|
||||
)
|
||||
except (OSError, sqlite3.Error) as exc:
|
||||
@@ -176,7 +195,8 @@ class SessionStore:
|
||||
) -> str:
|
||||
now = int(self.clock())
|
||||
query = (
|
||||
"SELECT expires_at, last_active_at FROM active_sessions "
|
||||
"SELECT expires_at, last_active_at, principal_id, principal_login "
|
||||
"FROM active_sessions "
|
||||
"WHERE session_hash = ?"
|
||||
)
|
||||
parameters = (self._digest(session_id),)
|
||||
@@ -185,7 +205,11 @@ class SessionStore:
|
||||
with self._connect() as connection:
|
||||
row = connection.execute(query, parameters).fetchone()
|
||||
except sqlite3.OperationalError as exc:
|
||||
if "no such column: last_active_at" not in str(exc):
|
||||
missing_migrated_column = any(
|
||||
f"no such column: {name}" in str(exc)
|
||||
for name in ("last_active_at", "principal_id", "principal_login")
|
||||
)
|
||||
if not missing_migrated_column:
|
||||
raise
|
||||
with self._connect(initialize=True) as connection:
|
||||
row = connection.execute(query, parameters).fetchone()
|
||||
@@ -196,7 +220,7 @@ class SessionStore:
|
||||
idle_expires_at = min(row[0], row[1] + max(1, idle_timeout_seconds))
|
||||
if idle_expires_at <= now:
|
||||
return SessionStatus("idle", idle_expires_at)
|
||||
return SessionStatus("active", idle_expires_at)
|
||||
return SessionStatus("active", idle_expires_at, row[2], row[3])
|
||||
|
||||
def touch(
|
||||
self, session_id: str, expires_at: int, *, idle_timeout_seconds: int
|
||||
@@ -279,7 +303,11 @@ class SessionStore:
|
||||
)[management_id]
|
||||
|
||||
def managed_statuses(
|
||||
self, management_ids, *, idle_timeout_seconds: int
|
||||
self,
|
||||
management_ids,
|
||||
*,
|
||||
idle_timeout_seconds: int,
|
||||
expected_principal_id: int | None = None,
|
||||
) -> dict[str, str]:
|
||||
"""Return authorization states for durable device identifiers in one read."""
|
||||
requested = set(management_ids)
|
||||
@@ -290,7 +318,7 @@ class SessionStore:
|
||||
with self._connect() as connection:
|
||||
placeholders = ",".join("?" for _ in requested)
|
||||
rows = connection.execute(
|
||||
"SELECT management_id, expires_at, last_active_at "
|
||||
"SELECT management_id, expires_at, last_active_at, principal_id "
|
||||
f"FROM active_sessions WHERE management_id IN ({placeholders})",
|
||||
tuple(requested),
|
||||
).fetchall()
|
||||
@@ -305,6 +333,8 @@ class SessionStore:
|
||||
statuses[management_id] = "revoked"
|
||||
elif row[1] + idle_timeout <= now:
|
||||
statuses[management_id] = "idle"
|
||||
elif expected_principal_id is not None and row[2] != expected_principal_id:
|
||||
statuses[management_id] = "principal_mismatch"
|
||||
else:
|
||||
statuses[management_id] = "active"
|
||||
return statuses
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
if os.getenv("STACKCHAIN_RUN_RELEASE_E2E") != "1":
|
||||
pytest.skip("packaged adaptive Queues journey runs only in its gated CI job", allow_module_level=True)
|
||||
pytest.importorskip("playwright.sync_api")
|
||||
from playwright.sync_api import expect, sync_playwright
|
||||
|
||||
|
||||
ROOT = Path(__file__).parents[2]
|
||||
FRONTEND = ROOT / "frontend"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("viewport", [
|
||||
{"width": 320, "height": 568},
|
||||
{"width": 375, "height": 667},
|
||||
{"width": 430, "height": 932},
|
||||
])
|
||||
def test_adaptive_queues_put_truthful_next_action_above_the_fold(viewport):
|
||||
with sync_playwright() as playwright:
|
||||
browser = playwright.chromium.launch(headless=True)
|
||||
page = browser.new_page(viewport=viewport)
|
||||
page.set_content((FRONTEND / "index.html").read_text())
|
||||
page.add_style_tag(path=FRONTEND / "dashboard.css")
|
||||
page.add_script_tag(path=FRONTEND / "mobile-queue-launcher.js")
|
||||
page.evaluate("""() => {
|
||||
const rows = Object.fromEntries(Array.from(document.querySelectorAll('[data-mobile-queue]'))
|
||||
.map(row => [row.dataset.mobileQueue, row]));
|
||||
window.adaptiveQueueLauncher = createMobileQueueLauncher({
|
||||
getCounts:() => ({delivery:1, gate:2, today:3, attentionUnavailable:true}),
|
||||
rows,
|
||||
nextAction:document.querySelector('#mobile-queue-next-action'),
|
||||
activeList:document.querySelector('#mobile-queue-active-list'),
|
||||
planningList:document.querySelector('#mobile-queue-planning-list'),
|
||||
allList:document.querySelector('#mobile-queue-all-list'),
|
||||
activeSection:document.querySelector('#mobile-queue-active-list').parentElement,
|
||||
});
|
||||
window.adaptiveQueueLauncher.renderPresentation();
|
||||
document.querySelector('#mobile-queue-sheet').showModal();
|
||||
}""")
|
||||
|
||||
next_action = page.locator("#mobile-queue-next-action")
|
||||
expect(next_action).to_be_visible()
|
||||
expect(next_action).to_have_text("Recover Delivery (1)")
|
||||
bounds = next_action.bounding_box()
|
||||
assert bounds and bounds["height"] >= 44
|
||||
assert bounds["x"] >= 0 and bounds["x"] + bounds["width"] <= viewport["width"]
|
||||
assert bounds["y"] + bounds["height"] <= viewport["height"]
|
||||
|
||||
assert page.locator("#mobile-queue-active-list [data-mobile-queue]").evaluate_all(
|
||||
"rows => rows.map(row => row.dataset.mobileQueue)"
|
||||
) == ["delivery", "gate", "attention"]
|
||||
expect(page.locator('[data-mobile-queue="attention"]')).to_have_attribute("data-unavailable", "true")
|
||||
assert page.locator("#mobile-queue-planning-list [data-mobile-queue]").evaluate_all(
|
||||
"rows => rows.map(row => row.dataset.mobileQueue)"
|
||||
) == ["today", "tomorrow", "week"]
|
||||
expect(page.locator(".mobile-queue-all")).not_to_have_attribute("open", "")
|
||||
assert page.evaluate("document.documentElement.scrollWidth <= window.innerWidth")
|
||||
browser.close()
|
||||
@@ -0,0 +1,130 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import threading
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
if os.getenv("STACKCHAIN_RUN_RELEASE_E2E") != "1":
|
||||
pytest.skip("packaged Human Gates journey runs only in its gated CI job", allow_module_level=True)
|
||||
pytest.importorskip("playwright.sync_api")
|
||||
from playwright.sync_api import expect, sync_playwright
|
||||
|
||||
from fake_gitea import FakeGiteaServer
|
||||
from test_mobile_offline_issue_release import ACCESS_TOKEN, ROOT, release_server
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("width", "height"), [(320, 568), (390, 844)])
|
||||
def test_release_artifact_reopens_human_gates_with_one_fresh_mobile_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"
|
||||
|
||||
fake = FakeGiteaServer(("127.0.0.1", 0))
|
||||
fake_thread = threading.Thread(target=fake.serve_forever, daemon=True)
|
||||
fake_thread.start()
|
||||
current = {"gate": "g1"}
|
||||
evidence_url = {"value": "/evidence/manifest"}
|
||||
list_requests: list[str] = []
|
||||
browser_errors: list[str] = []
|
||||
|
||||
def gate(gate_id: str) -> dict:
|
||||
return {
|
||||
"id": gate_id,
|
||||
"title": "First candidate" if gate_id == "g1" else "Fresh candidate",
|
||||
"project": "stackchain/stackchain-dashboard",
|
||||
"candidate_hash": "a1" if gate_id == "g1" else "b2",
|
||||
"revision": 1,
|
||||
"priority": 5,
|
||||
"checks": [],
|
||||
"artifacts": [{"name": "Signed manifest", "url": evidence_url["value"]}],
|
||||
"links": [],
|
||||
"provenance": {},
|
||||
"history": [],
|
||||
}
|
||||
|
||||
try:
|
||||
with release_server(
|
||||
archives[0], tmp_path, f"http://127.0.0.1:{fake.server_port}"
|
||||
) as origin, sync_playwright() as playwright:
|
||||
evidence_url["value"] = origin + "/evidence/manifest"
|
||||
browser = playwright.chromium.launch(args=["--ignore-certificate-errors"])
|
||||
context = browser.new_context(
|
||||
viewport={"width": width, "height": height}, ignore_https_errors=True
|
||||
)
|
||||
page = context.new_page()
|
||||
page.on("pageerror", lambda error: browser_errors.append(error.stack or str(error)))
|
||||
|
||||
def human_gates_route(route):
|
||||
path = route.request.url.split("?", 1)[0]
|
||||
if route.request.method == "POST":
|
||||
payload = {"receipt_id": "receipt-1", "state": "released"}
|
||||
elif path.endswith("/api/v1/human-gates"):
|
||||
list_requests.append(current["gate"])
|
||||
payload = {"pending_count": 1, "items": [gate(current["gate"])]}
|
||||
else:
|
||||
payload = gate(path.rsplit("/", 1)[-1])
|
||||
route.fulfill(status=200, content_type="application/json", body=json.dumps(payload))
|
||||
|
||||
page.route("**/api/v1/human-gates**", human_gates_route)
|
||||
page.route("**/api/v1/human-gates/**", human_gates_route)
|
||||
page.goto(origin + "/", wait_until="networkidle")
|
||||
page.locator('input[name="device_label"]').fill("Human Gates 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.evaluate("document.querySelector('#open-human-gates').click()")
|
||||
expect(page.locator("#human-gates")).to_be_visible()
|
||||
expect(page.locator("#human-gate-detail")).to_contain_text("First candidate")
|
||||
|
||||
page.locator('[data-gate-checklist="exact_hash"]').check()
|
||||
page.locator('[data-gate-checklist="artifacts_reviewed"]').check()
|
||||
page.locator('[data-gate-checklist="provenance_reviewed"]').check()
|
||||
page.locator("[data-gate-reason]").fill("Awaiting final approval")
|
||||
with page.expect_popup() as popup_info:
|
||||
page.get_by_role("link", name="Signed manifest").click()
|
||||
popup = popup_info.value
|
||||
popup.wait_for_load_state("domcontentloaded")
|
||||
assert not page.url.endswith("/evidence/manifest")
|
||||
expect(page.locator("#human-gates")).to_be_visible()
|
||||
expect(page.locator("#human-gate-detail")).to_contain_text("First candidate")
|
||||
popup.close()
|
||||
|
||||
page.reload(wait_until="networkidle")
|
||||
page.evaluate("document.querySelector('#open-human-gates').click()")
|
||||
expect(page.locator("#human-gates")).to_be_visible()
|
||||
expect(page.locator('[data-gate-checklist="exact_hash"]')).to_be_checked()
|
||||
expect(page.locator('[data-gate-checklist="artifacts_reviewed"]')).to_be_checked()
|
||||
expect(page.locator('[data-gate-checklist="provenance_reviewed"]')).to_be_checked()
|
||||
expect(page.locator("[data-gate-reason]")).to_have_value("Awaiting final approval")
|
||||
progress_key = page.evaluate(
|
||||
"Object.keys(localStorage).find(key => key.startsWith('stackchain.human-gate-review.v1:'))"
|
||||
)
|
||||
assert progress_key and progress_key.endswith(":g1:1")
|
||||
assert page.evaluate("key => localStorage.getItem(key) !== null", progress_key)
|
||||
page.locator('[data-gate-decision="release"]').click()
|
||||
expect(page.locator("#human-gates-status")).to_contain_text("Decision saved")
|
||||
assert not page.evaluate("key => localStorage.getItem(key) !== null", progress_key)
|
||||
|
||||
page.evaluate("document.querySelector('#close-human-gates').click()")
|
||||
|
||||
before_reopen = len(list_requests)
|
||||
current["gate"] = "g2"
|
||||
page.evaluate("document.querySelector('#open-human-gates').click()")
|
||||
expect(page.locator("#human-gate-detail")).to_contain_text("Fresh candidate")
|
||||
expect(page.locator("#human-gates-list")).to_contain_text("Fresh candidate")
|
||||
assert len(list_requests) == before_reopen + 1
|
||||
assert page.evaluate("window.innerWidth") == width
|
||||
assert page.evaluate("document.documentElement.scrollWidth <= window.innerWidth")
|
||||
bounds = page.locator('[data-human-gate-id="g2"]').bounding_box()
|
||||
assert bounds and bounds["height"] >= 44
|
||||
assert not browser_errors
|
||||
browser.close()
|
||||
finally:
|
||||
fake.shutdown()
|
||||
fake.server_close()
|
||||
fake_thread.join(timeout=5)
|
||||
@@ -0,0 +1,85 @@
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
ROOT = Path(__file__).parents[2]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("viewport", [(320, 568), (390, 844)])
|
||||
def test_mobile_author_commits_one_review_feedback_fix(viewport):
|
||||
playwright = pytest.importorskip("playwright.sync_api")
|
||||
html = (ROOT / "frontend" / "index.html").read_text()
|
||||
detail = {
|
||||
"state": "open", "merged": False, "head_sha": "abc1234",
|
||||
"capabilities": {"authored": True},
|
||||
"reviewers": [{
|
||||
"review_id": 42, "login": "sam", "status": "changes_requested",
|
||||
"head_sha": "abc1234", "blocking": True, "feedback_state": "loaded",
|
||||
"comments": [{"id": 99, "path": "src/api.py", "body": "Handle empty state.", "line": 12}],
|
||||
}],
|
||||
"files": [{"filename": "src/api.py", "status": "modified", "diff_available": True,
|
||||
"diff_lines": ["@@ -12 +12 @@", "+return empty"]}],
|
||||
}
|
||||
|
||||
with playwright.sync_playwright() as runtime:
|
||||
try:
|
||||
browser = runtime.chromium.launch(headless=True)
|
||||
except Exception as error:
|
||||
pytest.skip(f"Chromium is not installed: {error}")
|
||||
page = browser.new_page(viewport={"width": viewport[0], "height": viewport[1]})
|
||||
page.set_content(html, wait_until="domcontentloaded")
|
||||
page.add_style_tag(path=ROOT / "frontend" / "dashboard.css")
|
||||
page.add_script_tag(path=ROOT / "frontend" / "pull-sheet.js")
|
||||
page.evaluate(
|
||||
"""detail => {
|
||||
globalThis.confirm = () => true;
|
||||
globalThis.fixCalls = [];
|
||||
globalThis.fixItem = {repository:'stackchain/api', number:7, key:'stackchain/api#7'};
|
||||
globalThis.fixDetail = detail;
|
||||
globalThis.fixController = createPullSheet({fetchJson: async (path, options = {}) => {
|
||||
fixCalls.push({path, options});
|
||||
if ((options.method || 'GET') === 'GET') return {
|
||||
path:'src/api.py', head_sha:'abc1234', blob_sha:'blob123', content:'return empty\\n'
|
||||
};
|
||||
return {path:'src/api.py', previous_head_sha:'abc1234', head_sha:'def5678', blob_sha:'blob456'};
|
||||
}});
|
||||
document.querySelector('#pull-sheet').classList.add('open');
|
||||
document.querySelector('#pull-review').open = true;
|
||||
document.querySelector('#pull-files').innerHTML = detail.files.map((file, index) =>
|
||||
createPullSheet.renderFile(file, index, false, value => String(value))
|
||||
).join('');
|
||||
createPullSheet.bindFeedbackControls(document, fixController,
|
||||
() => fixItem, () => fixDetail, () => 'alex');
|
||||
createPullSheet.review(detail, null, document);
|
||||
}""",
|
||||
detail,
|
||||
)
|
||||
|
||||
page.locator(".pull-review-feedback summary").click()
|
||||
page.locator('[data-address-review-feedback="42"]').click()
|
||||
page.locator("#make-pull-feedback-fix").click()
|
||||
page.locator("#pull-feedback-file-content").fill("return handled\n")
|
||||
page.locator("#pull-feedback-commit-message").fill("fix: handle empty state")
|
||||
page.locator("#commit-pull-feedback-fix").click()
|
||||
page.wait_for_function("fixCalls.length === 2")
|
||||
result = page.evaluate("""() => ({
|
||||
calls:fixCalls, head:fixDetail.head_sha,
|
||||
editorHidden:document.querySelector('#pull-feedback-file-editor').hidden,
|
||||
status:document.querySelector('#pull-feedback-status').textContent,
|
||||
scrollWidth:document.documentElement.scrollWidth,
|
||||
clientWidth:document.documentElement.clientWidth,
|
||||
heights:Array.from(document.querySelectorAll('#pull-feedback-pass button'))
|
||||
.filter(button => button.getClientRects().length > 0).map(button => button.getBoundingClientRect().height),
|
||||
})""")
|
||||
browser.close()
|
||||
|
||||
assert result["scrollWidth"] <= result["clientWidth"]
|
||||
assert min(result["heights"]) >= 44
|
||||
assert result["head"] == "def5678"
|
||||
assert result["editorHidden"] is True
|
||||
assert "committed" in result["status"].lower()
|
||||
assert "path=src%2Fapi.py" in result["calls"][0]["path"]
|
||||
body = result["calls"][1]["options"]["body"]
|
||||
assert '"expected_blob_sha":"blob123"' in body
|
||||
assert '"content":"return handled\\n"' in body
|
||||
@@ -0,0 +1,113 @@
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
ROOT = Path(__file__).parents[2]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("viewport", [(320, 568), (390, 844)])
|
||||
def test_mobile_author_stages_and_commits_cross_file_suggestions_atomically(viewport):
|
||||
playwright = pytest.importorskip("playwright.sync_api")
|
||||
html = (ROOT / "frontend" / "index.html").read_text()
|
||||
detail = {
|
||||
"state": "open", "merged": False, "head_sha": "abc1234",
|
||||
"capabilities": {"authored": True},
|
||||
"reviewers": [{
|
||||
"review_id": 42, "login": "sam", "status": "changes_requested",
|
||||
"head_sha": "abc1234", "blocking": True, "feedback_state": "loaded",
|
||||
"comments": [
|
||||
{"id": 99, "path": "src/api.py", "line": 2, "body": "Use the typed empty result.",
|
||||
"suggestion": {"line": 2, "content": " return empty_result()"}},
|
||||
{"id": 100, "path": "tests/test_api.py", "line": 2, "body": "Prove the typed result.",
|
||||
"suggestion": {"line": 2, "content": " assert lookup() == empty_result()"}},
|
||||
],
|
||||
}],
|
||||
"files": [
|
||||
{"filename": "src/api.py", "status": "modified", "diff_available": True,
|
||||
"diff_lines": ["@@ -2 +2 @@", "+ return None"]},
|
||||
{"filename": "tests/test_api.py", "status": "modified", "diff_available": True,
|
||||
"diff_lines": ["@@ -2 +2 @@", "+ assert lookup() is None"]},
|
||||
],
|
||||
}
|
||||
|
||||
with playwright.sync_playwright() as runtime:
|
||||
try:
|
||||
browser = runtime.chromium.launch(headless=True)
|
||||
except Exception as error:
|
||||
pytest.skip(f"Chromium is not installed: {error}")
|
||||
page = browser.new_page(viewport={"width": viewport[0], "height": viewport[1]})
|
||||
page.set_content(html, wait_until="domcontentloaded")
|
||||
page.add_style_tag(path=ROOT / "frontend" / "dashboard.css")
|
||||
page.add_script_tag(path=ROOT / "frontend" / "pull-sheet.js")
|
||||
page.evaluate(
|
||||
"""detail => {
|
||||
globalThis.confirm = () => true;
|
||||
globalThis.batchCalls = [];
|
||||
globalThis.batchItem = {repository:'stackchain/api', number:7, key:'stackchain/api#7'};
|
||||
globalThis.batchDetail = detail;
|
||||
globalThis.batchController = createPullSheet({fetchJson: async (path, options = {}) => {
|
||||
batchCalls.push({path, options});
|
||||
if ((options.method || 'GET') === 'GET') {
|
||||
if (batchCalls.length === 1) return {path:'src/api.py', head_sha:'abc1234', blob_sha:'blob1',
|
||||
content:'def lookup():\\n return None\\n'};
|
||||
return {path:'tests/test_api.py', head_sha:'abc1234', blob_sha:'blob2',
|
||||
content:'def test_lookup():\\n assert lookup() is None\\n'};
|
||||
}
|
||||
return {paths:['src/api.py','tests/test_api.py'], suggestion_count:2,
|
||||
previous_head_sha:'abc1234', head_sha:'def5678'};
|
||||
}});
|
||||
document.querySelector('#pull-sheet').classList.add('open');
|
||||
document.querySelector('#pull-review').open = true;
|
||||
document.querySelector('#pull-files').innerHTML = detail.files.map((file, index) =>
|
||||
createPullSheet.renderFile(file, index, false, value => String(value))
|
||||
).join('');
|
||||
createPullSheet.bindFeedbackControls(document, batchController,
|
||||
() => batchItem, () => batchDetail, () => 'alex');
|
||||
createPullSheet.review(detail, null, document);
|
||||
}""",
|
||||
detail,
|
||||
)
|
||||
|
||||
page.locator(".pull-review-feedback summary").click()
|
||||
page.locator('[data-address-review-feedback="42"]').click()
|
||||
page.locator("#review-pull-feedback-suggestion").click()
|
||||
page.wait_for_function("batchCalls.length === 1")
|
||||
page.locator("#stage-pull-feedback-suggestion").click()
|
||||
assert page.locator("#review-pull-feedback-batch").text_content() == "Review fixes (1)"
|
||||
page.locator("#next-pull-feedback").click()
|
||||
page.locator("#review-pull-feedback-suggestion").click()
|
||||
page.wait_for_function("batchCalls.length === 2")
|
||||
page.locator("#stage-pull-feedback-suggestion").click()
|
||||
assert page.locator("#review-pull-feedback-batch").text_content() == "Review fixes (2)"
|
||||
page.locator("#review-pull-feedback-batch").click()
|
||||
assert page.locator("#pull-feedback-batch-review").is_visible()
|
||||
assert page.locator("#pull-feedback-batch-items li").count() == 2
|
||||
page.locator("#commit-pull-feedback-batch").click()
|
||||
page.wait_for_function("batchCalls.length === 3")
|
||||
result = page.evaluate("""() => ({
|
||||
calls:batchCalls, head:batchDetail.head_sha,
|
||||
reviewHidden:document.querySelector('#pull-feedback-batch-review').hidden,
|
||||
status:document.querySelector('#pull-feedback-status').textContent,
|
||||
scrollWidth:document.documentElement.scrollWidth,
|
||||
clientWidth:document.documentElement.clientWidth,
|
||||
heights:Array.from(document.querySelectorAll('#pull-feedback-pass button'))
|
||||
.filter(button => button.getClientRects().length > 0).map(button => button.getBoundingClientRect().height),
|
||||
})""")
|
||||
browser.close()
|
||||
|
||||
assert result["scrollWidth"] <= result["clientWidth"]
|
||||
assert min(result["heights"]) >= 44
|
||||
assert result["head"] == "def5678"
|
||||
assert result["reviewHidden"] is True
|
||||
assert "2 suggested changes committed" in result["status"].lower()
|
||||
request = result["calls"][2]
|
||||
assert request["path"].endswith("/feedback-batch")
|
||||
assert request["options"]["method"] == "POST"
|
||||
body = request["options"]["body"]
|
||||
assert '"expected_head_sha":"abc1234"' in body
|
||||
assert '"files":[{"path":"src/api.py"' in body
|
||||
assert '"path":"tests/test_api.py"' in body
|
||||
assert '"suggestion_count":2' in body
|
||||
assert 'return empty_result()' in body
|
||||
assert 'assert lookup() == empty_result()' in body
|
||||
@@ -0,0 +1,103 @@
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
ROOT = Path(__file__).parents[2]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("viewport", [(320, 568), (390, 844)])
|
||||
def test_mobile_author_previews_and_applies_review_suggestion(viewport):
|
||||
playwright = pytest.importorskip("playwright.sync_api")
|
||||
html = (ROOT / "frontend" / "index.html").read_text()
|
||||
detail = {
|
||||
"state": "open", "merged": False, "head_sha": "abc1234",
|
||||
"capabilities": {"authored": True},
|
||||
"reviewers": [{
|
||||
"review_id": 42, "login": "sam", "status": "changes_requested",
|
||||
"head_sha": "abc1234", "blocking": True, "feedback_state": "loaded",
|
||||
"comments": [{
|
||||
"id": 99, "path": "src/api.py", "line": 2,
|
||||
"body": "Return the typed empty result.\n```suggestion\n return empty_result()\n```",
|
||||
"suggestion": {"line": 2, "content": " return empty_result()"},
|
||||
}, {
|
||||
"id": 100, "path": "src/api.py", "line": 3,
|
||||
"body": "Keep the result typed.",
|
||||
}],
|
||||
}],
|
||||
"files": [{"filename": "src/api.py", "status": "modified", "diff_available": True,
|
||||
"diff_lines": ["@@ -2 +2 @@", "+ return None"]}],
|
||||
}
|
||||
|
||||
with playwright.sync_playwright() as runtime:
|
||||
try:
|
||||
browser = runtime.chromium.launch(headless=True)
|
||||
except Exception as error:
|
||||
pytest.skip(f"Chromium is not installed: {error}")
|
||||
page = browser.new_page(viewport={"width": viewport[0], "height": viewport[1]})
|
||||
page.set_content(html, wait_until="domcontentloaded")
|
||||
page.add_style_tag(path=ROOT / "frontend" / "dashboard.css")
|
||||
page.add_script_tag(path=ROOT / "frontend" / "pull-sheet.js")
|
||||
page.evaluate(
|
||||
"""detail => {
|
||||
globalThis.confirm = () => true;
|
||||
globalThis.suggestionCalls = [];
|
||||
globalThis.suggestionItem = {repository:'stackchain/api', number:7, key:'stackchain/api#7'};
|
||||
globalThis.suggestionDetail = detail;
|
||||
globalThis.suggestionController = createPullSheet({fetchJson: async (path, options = {}) => {
|
||||
suggestionCalls.push({path, options});
|
||||
if ((options.method || 'GET') === 'GET') return {
|
||||
path:'src/api.py', head_sha:'abc1234', blob_sha:'blob123',
|
||||
content:'def lookup():\\n return None\\n'
|
||||
};
|
||||
return {path:'src/api.py', previous_head_sha:'abc1234', head_sha:'def5678', blob_sha:'blob456'};
|
||||
}});
|
||||
document.querySelector('#pull-sheet').classList.add('open');
|
||||
document.querySelector('#pull-review').open = true;
|
||||
document.querySelector('#pull-files').innerHTML = detail.files.map((file, index) =>
|
||||
createPullSheet.renderFile(file, index, false, value => String(value))
|
||||
).join('');
|
||||
createPullSheet.bindFeedbackControls(document, suggestionController,
|
||||
() => suggestionItem, () => suggestionDetail, () => 'alex');
|
||||
createPullSheet.review(detail, null, document);
|
||||
}""",
|
||||
detail,
|
||||
)
|
||||
|
||||
page.locator(".pull-review-feedback summary").click()
|
||||
page.locator('[data-address-review-feedback="42"]').click()
|
||||
assert page.locator("#pull-feedback-file-editor").is_hidden()
|
||||
assert page.locator("#review-pull-feedback-suggestion").is_visible()
|
||||
page.locator("#review-pull-feedback-suggestion").click()
|
||||
page.wait_for_function("suggestionCalls.length === 1")
|
||||
assert page.locator("#pull-feedback-suggestion-preview").is_visible()
|
||||
assert page.locator("#pull-feedback-suggestion-before").text_content() == " return None"
|
||||
assert page.locator("#pull-feedback-suggestion-after").text_content() == " return empty_result()"
|
||||
assert page.locator("#pull-feedback-file-editor").is_hidden()
|
||||
page.locator("#next-pull-feedback").click()
|
||||
assert page.locator("#pull-feedback-suggestion-preview").is_hidden()
|
||||
assert page.locator("#review-pull-feedback-suggestion").is_hidden()
|
||||
page.locator("#previous-pull-feedback").click()
|
||||
page.locator("#review-pull-feedback-suggestion").click()
|
||||
page.wait_for_function("suggestionCalls.length === 2")
|
||||
page.locator("#apply-pull-feedback-suggestion").click()
|
||||
page.wait_for_function("suggestionCalls.length === 3")
|
||||
result = page.evaluate("""() => ({
|
||||
calls:suggestionCalls, head:suggestionDetail.head_sha,
|
||||
previewHidden:document.querySelector('#pull-feedback-suggestion-preview').hidden,
|
||||
status:document.querySelector('#pull-feedback-status').textContent,
|
||||
scrollWidth:document.documentElement.scrollWidth,
|
||||
clientWidth:document.documentElement.clientWidth,
|
||||
heights:Array.from(document.querySelectorAll('#pull-feedback-pass button'))
|
||||
.filter(button => button.getClientRects().length > 0).map(button => button.getBoundingClientRect().height),
|
||||
})""")
|
||||
browser.close()
|
||||
|
||||
assert result["scrollWidth"] <= result["clientWidth"]
|
||||
assert min(result["heights"]) >= 44
|
||||
assert result["head"] == "def5678"
|
||||
assert result["previewHidden"] is True
|
||||
assert "suggested change committed" in result["status"].lower()
|
||||
body = result["calls"][2]["options"]["body"]
|
||||
assert '"expected_blob_sha":"blob123"' in body
|
||||
assert '"content":"def lookup():\\n return empty_result()\\n"' in body
|
||||
@@ -26,7 +26,9 @@ def test_authored_pull_queue_is_phone_usable_and_opens_the_existing_pull_route(v
|
||||
page.add_script_tag(path=FRONTEND / "my-work.js")
|
||||
page.add_script_tag(path=FRONTEND / "work-route.js")
|
||||
page.add_script_tag(path=FRONTEND / "mobile-queue-launcher.js")
|
||||
page.add_script_tag(path=FRONTEND / "pull-sheet.js")
|
||||
page.evaluate("document.querySelector('#mobile-queue-sheet').showModal()")
|
||||
page.locator(".mobile-queue-all summary").click()
|
||||
|
||||
row = page.locator('[data-mobile-queue="authored"]')
|
||||
expect(row).to_have_count(1)
|
||||
@@ -63,6 +65,25 @@ def test_authored_pull_queue_is_phone_usable_and_opens_the_existing_pull_route(v
|
||||
"opened": "opened",
|
||||
"count": 1,
|
||||
}
|
||||
capabilities = page.evaluate("""() => {
|
||||
const item = {key:'stackchain/dashboard#41'};
|
||||
createPullSheet.resetOwnershipControls(
|
||||
document, item, () => false, {authored:true, assigned:false}
|
||||
);
|
||||
const ownership = document.querySelector('#pull-ownership');
|
||||
return {
|
||||
hidden: ownership.hidden,
|
||||
inert: ownership.inert,
|
||||
releaseDisabled: document.querySelector('#release-pull').disabled,
|
||||
handoffDisabled: document.querySelector('#load-pull-handoff').disabled,
|
||||
};
|
||||
}""")
|
||||
assert capabilities == {
|
||||
"hidden": True,
|
||||
"inert": True,
|
||||
"releaseDisabled": True,
|
||||
"handoffDisabled": True,
|
||||
}
|
||||
assert page.evaluate(
|
||||
"document.documentElement.scrollWidth > document.documentElement.clientWidth"
|
||||
) is False
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
ROOT = Path(__file__).parents[2]
|
||||
pytestmark = pytest.mark.skipif(
|
||||
os.environ.get("STACKCHAIN_RUN_RELEASE_E2E") != "1",
|
||||
reason="release browser journey is opt-in",
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("viewport", [(320, 568), (390, 844)])
|
||||
def test_mobile_author_closes_obsolete_pull_then_recovers_it(viewport):
|
||||
playwright = pytest.importorskip("playwright.sync_api")
|
||||
html = (ROOT / "frontend" / "index.html").read_text()
|
||||
|
||||
with playwright.sync_playwright() as runtime:
|
||||
try:
|
||||
browser = runtime.chromium.launch(headless=True)
|
||||
except Exception as error:
|
||||
pytest.skip(f"Chromium is not installed: {error}")
|
||||
page = browser.new_page(viewport={"width": viewport[0], "height": viewport[1]})
|
||||
page.on("dialog", lambda dialog: dialog.accept())
|
||||
page.set_content(html, wait_until="domcontentloaded")
|
||||
page.add_style_tag(path=ROOT / "frontend" / "dashboard.css")
|
||||
page.add_script_tag(path=ROOT / "frontend" / "pull-sheet.js")
|
||||
page.evaluate(
|
||||
"""() => {
|
||||
window.lifecycleCalls = [];
|
||||
window.lifecycleItem = {repository:'stackchain/api', number:7, key:'stackchain/api#7'};
|
||||
window.lifecycleDetail = {
|
||||
number:7, title:'Obsolete experiment', author:'timmy', state:'open',
|
||||
merged:false, head_sha:'abc1234', capabilities:{authored:true, assigned:false},
|
||||
};
|
||||
const controller = createPullSheet({
|
||||
storage:null,
|
||||
fetchJson:async (path, options) => {
|
||||
lifecycleCalls.push({path, method:options.method, body:JSON.parse(options.body)});
|
||||
const state = path.endsWith('/close') ? 'closed' : 'open';
|
||||
return {repository:'stackchain/api', number:7, title:'Obsolete experiment',
|
||||
head_sha:'abc1234', state, merged:false};
|
||||
},
|
||||
});
|
||||
createPullSheet.bindLifecycleControls(
|
||||
document, controller, () => lifecycleItem, () => lifecycleDetail,
|
||||
result => { lifecycleDetail = {...lifecycleDetail, ...result}; }
|
||||
);
|
||||
createPullSheet.resetLifecycleControls(document, lifecycleDetail);
|
||||
document.querySelector('#pull-sheet').classList.add('open');
|
||||
}"""
|
||||
)
|
||||
|
||||
page.locator("#pull-lifecycle summary").click()
|
||||
close = page.get_by_role("button", name="Close pull request")
|
||||
before = close.evaluate("button => ({height:button.getBoundingClientRect().height, hidden:button.hidden})")
|
||||
close.click()
|
||||
page.get_by_text("Pull request closed.").wait_for()
|
||||
reopen = page.get_by_role("button", name="Reopen pull request")
|
||||
receipt = reopen.evaluate("button => ({height:button.getBoundingClientRect().height, hidden:button.closest('[hidden]') !== null})")
|
||||
reopen.click()
|
||||
page.get_by_text("Pull request reopened.").wait_for()
|
||||
metrics = page.evaluate(
|
||||
"""() => ({
|
||||
calls:lifecycleCalls,
|
||||
state:lifecycleDetail.state,
|
||||
closeHidden:document.querySelector('#close-authored-pull').hidden,
|
||||
receiptHidden:document.querySelector('#pull-close-receipt').hidden,
|
||||
focused:document.activeElement === document.querySelector('#close-authored-pull'),
|
||||
scrollWidth:document.documentElement.scrollWidth,
|
||||
clientWidth:document.documentElement.clientWidth,
|
||||
})"""
|
||||
)
|
||||
browser.close()
|
||||
|
||||
assert before["hidden"] is False
|
||||
assert before["height"] >= 44
|
||||
assert receipt["height"] >= 44
|
||||
assert receipt["hidden"] is False
|
||||
assert [call["path"].rsplit("/", 1)[-1] for call in metrics["calls"]] == ["close", "reopen"]
|
||||
assert all(call["body"] == {"expected_head_sha": "abc1234"} for call in metrics["calls"])
|
||||
assert metrics["state"] == "open"
|
||||
assert metrics["closeHidden"] is False
|
||||
assert metrics["receiptHidden"] is True
|
||||
assert metrics["focused"] is True
|
||||
assert metrics["scrollWidth"] <= metrics["clientWidth"]
|
||||
@@ -0,0 +1,115 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
if os.getenv("STACKCHAIN_RUN_RELEASE_E2E") != "1":
|
||||
pytest.skip(
|
||||
"packaged mobile comment-reaction journey runs only in its gated CI job",
|
||||
allow_module_level=True,
|
||||
)
|
||||
pytest.importorskip("playwright.sync_api")
|
||||
from playwright.sync_api import expect, sync_playwright
|
||||
|
||||
|
||||
ROOT = Path(__file__).parents[2]
|
||||
FRONTEND = ROOT / "frontend"
|
||||
|
||||
|
||||
def test_comment_reactions_are_touch_safe_and_focus_preserving_at_320px():
|
||||
with sync_playwright() as playwright:
|
||||
browser = playwright.chromium.launch(headless=True)
|
||||
page = browser.new_page(viewport={"width": 320, "height": 568})
|
||||
page.set_content(
|
||||
'<main><div id="status" aria-live="polite"></div>'
|
||||
'<div id="comments"><article class="issue-comment" data-comment-id="91">'
|
||||
'<p>Ship feedback</p><div id="actions"></div></article></div></main>'
|
||||
)
|
||||
page.add_style_tag(path=FRONTEND / "dashboard.css")
|
||||
page.add_script_tag(path=FRONTEND / "comment-actions.js")
|
||||
page.evaluate(
|
||||
"""
|
||||
window.reactionCalls = [];
|
||||
window.offline = false;
|
||||
const controller = createCommentActions({
|
||||
getLogin: () => 'timmy',
|
||||
fetchJson: async (path, options = {}) => {
|
||||
reactionCalls.push([path, options.method || 'GET']);
|
||||
return {
|
||||
comment_id: 91,
|
||||
reactions: [{content: 'heart', count: options.method === 'PUT' ? 2 : 1,
|
||||
selected: options.method === 'PUT'}],
|
||||
};
|
||||
},
|
||||
});
|
||||
document.querySelector('#actions').innerHTML = controller.actionHtml({id: 91, author: 'alex'});
|
||||
controller.wire({
|
||||
root: document.querySelector('#comments'),
|
||||
getSurface: () => ({
|
||||
context: {kind: 'issue', item: {repository: 'stackchain/api', number: 7}},
|
||||
status: document.querySelector('#status'),
|
||||
}),
|
||||
isOffline: () => window.offline,
|
||||
escapeHtml: value => String(value),
|
||||
});
|
||||
"""
|
||||
)
|
||||
|
||||
trigger = page.get_by_role("button", name="React to this comment")
|
||||
trigger.click()
|
||||
menu = page.locator("[data-comment-reaction-menu]")
|
||||
expect(menu).to_be_visible()
|
||||
for control in menu.get_by_role("button").all():
|
||||
box = control.bounding_box()
|
||||
assert box is not None and box["height"] >= 44
|
||||
|
||||
page.get_by_role("button", name="Heart 1").click()
|
||||
expect(menu).to_be_hidden()
|
||||
expect(trigger).to_be_focused()
|
||||
expect(page.locator("#status")).to_have_text("Reaction updated.")
|
||||
assert page.evaluate(
|
||||
"document.documentElement.scrollWidth > document.documentElement.clientWidth"
|
||||
) is False
|
||||
assert page.evaluate("window.reactionCalls") == [
|
||||
["api/v1/repos/stackchain/api/issues/7/comments/91/reactions", "GET"],
|
||||
["api/v1/repos/stackchain/api/issues/7/comments/91/reactions/heart", "PUT"],
|
||||
]
|
||||
browser.close()
|
||||
|
||||
|
||||
def test_search_following_conversation_actions_are_touch_safe_at_320px():
|
||||
with sync_playwright() as playwright:
|
||||
browser = playwright.chromium.launch(headless=True)
|
||||
page = browser.new_page(viewport={"width": 320, "height": 568})
|
||||
page.set_content(
|
||||
'<main><section id="search-preview-conversation" class="search-preview-conversation">'
|
||||
'<div id="search-preview-comments"></div>'
|
||||
'<div id="search-preview-conversation-status"></div>'
|
||||
'<button id="retry-search-preview-conversation" hidden></button>'
|
||||
'<button id="load-older-search-preview-comments" hidden></button>'
|
||||
'</section></main>'
|
||||
)
|
||||
page.add_style_tag(path=FRONTEND / "dashboard.css")
|
||||
page.add_script_tag(path=FRONTEND / "search-preview.js")
|
||||
page.add_script_tag(path=FRONTEND / "comment-actions.js")
|
||||
page.evaluate(
|
||||
"""
|
||||
const actions=createCommentActions({fetchJson:async()=>({}),getLogin:()=> 'timmy'});
|
||||
renderSearchPreviewConversation({status:'ready',comments:[
|
||||
{id:41,author:'timmy',body:'Correct this from Following'},
|
||||
{id:42,author:'alexander',body:'React without leaving Search'},
|
||||
]},document,value=>String(value),value=>String(value),value=>String(value),actions);
|
||||
"""
|
||||
)
|
||||
|
||||
expect(page.locator(".search-preview-comment.issue-comment")).to_have_count(2)
|
||||
expect(page.get_by_role("button", name="Edit")).to_have_count(1)
|
||||
expect(page.get_by_role("button", name="Delete")).to_have_count(1)
|
||||
expect(page.get_by_role("button", name="React to this comment")).to_have_count(2)
|
||||
for control in page.locator("[data-comment-action], [data-comment-reactions-open]").all():
|
||||
box = control.bounding_box()
|
||||
assert box is not None and box["height"] >= 44
|
||||
assert page.evaluate(
|
||||
"document.documentElement.scrollWidth > document.documentElement.clientWidth"
|
||||
) is False
|
||||
browser.close()
|
||||
@@ -169,7 +169,7 @@ def test_release_artifact_bootstraps_mobile_home_and_returns_from_insights(
|
||||
workspace_requests.append(request.url),
|
||||
launch_transfer_events.append("workspace-requested"),
|
||||
)
|
||||
if "feature-today-timer-" in request.url else None,
|
||||
if "feature-work-core-" in request.url else None,
|
||||
)
|
||||
page.on(
|
||||
"requestfinished",
|
||||
@@ -186,6 +186,7 @@ def test_release_artifact_bootstraps_mobile_home_and_returns_from_insights(
|
||||
page.goto(origin + "/", wait_until="networkidle")
|
||||
page.locator('input[name="device_label"]').fill("Home bootstrap release phone")
|
||||
page.locator('input[name="access_token"]').fill(ACCESS_TOKEN)
|
||||
live_requests.clear()
|
||||
page.locator("#submit-sign-in").click()
|
||||
page.wait_for_url(origin + "/", wait_until="networkidle")
|
||||
assert launch_transfer_events.index("workspace-requested") < (
|
||||
@@ -193,6 +194,8 @@ def test_release_artifact_bootstraps_mobile_home_and_returns_from_insights(
|
||||
), launch_transfer_events
|
||||
|
||||
expect(page.locator("#my-work-status")).to_contain_text("2")
|
||||
revisionless_live_requests = [url for url in live_requests if "?" not in url]
|
||||
assert len(revisionless_live_requests) == 1, live_requests
|
||||
initial_live_requests = len(live_requests)
|
||||
page.evaluate(
|
||||
"""
|
||||
@@ -236,6 +239,7 @@ def test_release_artifact_bootstraps_mobile_home_and_returns_from_insights(
|
||||
page.locator("#cancel-plan-today").click()
|
||||
|
||||
page.locator('[data-mobile-task="queues"]').click()
|
||||
page.locator(".mobile-queue-all summary").click()
|
||||
delivery_queue = page.locator('[data-mobile-queue="delivery"]')
|
||||
expect(delivery_queue).to_be_visible()
|
||||
expect(delivery_queue).to_contain_text("Delivery")
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
if os.getenv("STACKCHAIN_RUN_RELEASE_E2E") != "1":
|
||||
pytest.skip("rendered mobile quiet-hours checks run only in the browser gate", allow_module_level=True)
|
||||
pytest.importorskip("playwright.sync_api")
|
||||
from playwright.sync_api import expect, sync_playwright
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
FRONTEND = ROOT / "frontend"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("viewport", [
|
||||
{"width": 320, "height": 568},
|
||||
{"width": 390, "height": 844},
|
||||
])
|
||||
def test_notification_quiet_hours_are_phone_usable_without_horizontal_scroll(viewport):
|
||||
html = re.sub(r'<script src="static/[^"]+"></script>', "", (FRONTEND / "index.html").read_text())
|
||||
with sync_playwright() as playwright:
|
||||
browser = playwright.chromium.launch(headless=True)
|
||||
page = browser.new_page(viewport=viewport)
|
||||
page.set_content(html)
|
||||
page.add_style_tag(path=FRONTEND / "dashboard.css")
|
||||
page.locator("#work-settings-toggle").click()
|
||||
|
||||
toggle = page.locator('label[for="push-quiet-hours"]')
|
||||
start = page.locator("#push-quiet-start")
|
||||
end = page.locator("#push-quiet-end")
|
||||
expect(toggle).to_be_visible()
|
||||
expect(start).to_be_visible()
|
||||
expect(end).to_be_visible()
|
||||
expect(start).to_have_value("22:00")
|
||||
expect(end).to_have_value("07:00")
|
||||
for control in (toggle, start, end):
|
||||
bounds = control.bounding_box()
|
||||
assert bounds and bounds["height"] >= 44
|
||||
assert page.evaluate("document.documentElement.scrollWidth <= window.innerWidth")
|
||||
browser.close()
|
||||
@@ -0,0 +1,99 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import threading
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
if os.getenv("STACKCHAIN_RUN_RELEASE_E2E") != "1":
|
||||
pytest.skip("packaged mobile photo-draft journey runs only in its gated CI job", allow_module_level=True)
|
||||
pytest.importorskip("playwright.sync_api")
|
||||
from playwright.sync_api import expect, sync_playwright
|
||||
|
||||
from fake_gitea import FakeGiteaServer
|
||||
from test_mobile_offline_issue_release import ACCESS_TOKEN, ROOT, release_server
|
||||
|
||||
|
||||
def test_release_artifact_finds_and_reopens_photo_only_reply_from_mobile_my_work(tmp_path: Path):
|
||||
archives = sorted((ROOT / "dist").glob("stackchain-dashboard-*.tar.gz"))
|
||||
assert len(archives) == 1, "browser job must provide exactly one assembled release archive"
|
||||
|
||||
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}"
|
||||
|
||||
try:
|
||||
with release_server(archives[0], tmp_path, fake_url) as origin, sync_playwright() as playwright:
|
||||
browser = playwright.chromium.launch(args=["--ignore-certificate-errors"])
|
||||
context = browser.new_context(viewport={"width": 390, "height": 844}, ignore_https_errors=True)
|
||||
page = context.new_page()
|
||||
page.goto(origin + "/", wait_until="networkidle")
|
||||
page.locator('input[name="device_label"]').fill("Photo draft 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.evaluate(
|
||||
"""() => new Promise((resolve, reject) => {
|
||||
const request=indexedDB.open('stackchain-conversation-reply-drafts-v1',1);
|
||||
request.onerror=()=>reject(request.error);
|
||||
request.onupgradeneeded=()=>{
|
||||
if (!request.result.objectStoreNames.contains('drafts')) {
|
||||
request.result.createObjectStore('drafts',{keyPath:'id'});
|
||||
}
|
||||
};
|
||||
request.onsuccess=()=>{
|
||||
const transaction=request.result.transaction('drafts','readwrite');
|
||||
transaction.objectStore('drafts').put({
|
||||
id:'timmy:issue:acme%2Fmobile%3A41', version:1, ownerLogin:'timmy',
|
||||
scope:'conversation', kind:'issue', repository:'acme/mobile', number:41,
|
||||
updatedAt:Date.now(), attachments:[{
|
||||
filename:'rack-label.jpg', contentType:'image/jpeg',
|
||||
blob:new Blob(['field evidence'],{type:'image/jpeg'}), note:'Rack label',
|
||||
}],
|
||||
});
|
||||
transaction.oncomplete=resolve;
|
||||
transaction.onerror=()=>reject(transaction.error);
|
||||
};
|
||||
})"""
|
||||
)
|
||||
page.reload(wait_until="networkidle")
|
||||
stored = page.evaluate(
|
||||
"""() => new Promise((resolve,reject)=>{
|
||||
const request=indexedDB.open('stackchain-conversation-reply-drafts-v1',1);
|
||||
request.onerror=()=>reject(request.error);
|
||||
request.onsuccess=()=>{
|
||||
const values=request.result.transaction('drafts','readonly').objectStore('drafts').getAll();
|
||||
values.onsuccess=()=>resolve(values.result.map(item=>({ownerLogin:item.ownerLogin,kind:item.kind,number:item.number})));
|
||||
values.onerror=()=>reject(values.error);
|
||||
};
|
||||
})"""
|
||||
)
|
||||
assert stored == [{"ownerLogin": "timmy", "kind": "issue", "number": 41}]
|
||||
inventory = page.evaluate(
|
||||
"""() => createConversationReplyDraftStore({indexedDB,getOwnerLogin:()=> 'timmy'}).list()"""
|
||||
)
|
||||
assert len(inventory) == 1
|
||||
expect(page.locator('[data-work-count="draft"]')).to_have_text("1", timeout=10_000)
|
||||
page.locator('[data-mobile-task="queues"]').click()
|
||||
page.locator('[data-mobile-queue="draft"]').click()
|
||||
|
||||
card = page.locator(".draft-card", has_text="acme/mobile#41")
|
||||
expect(card).to_contain_text("1 saved photo")
|
||||
resume = card.get_by_role("button", name="Resume draft")
|
||||
bounds = resume.bounding_box()
|
||||
assert bounds and bounds["height"] >= 44
|
||||
assert page.evaluate("document.documentElement.scrollWidth <= window.innerWidth")
|
||||
|
||||
resume.dispatch_event("click")
|
||||
expect(page.locator("#issue-sheet")).to_be_visible()
|
||||
expect(page.locator("#issue-attachment-preview")).to_be_visible()
|
||||
expect(page.locator("#issue-attachment-meta")).to_contain_text("rack-label.jpg")
|
||||
assert page.evaluate("document.documentElement.scrollWidth <= window.innerWidth")
|
||||
browser.close()
|
||||
finally:
|
||||
fake.shutdown()
|
||||
fake.server_close()
|
||||
fake_thread.join(timeout=5)
|
||||
@@ -0,0 +1,135 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
if os.getenv("STACKCHAIN_RUN_RELEASE_E2E") != "1":
|
||||
pytest.skip("packaged release-failure recovery runs only in the browser gate", allow_module_level=True)
|
||||
pytest.importorskip("playwright.sync_api")
|
||||
from playwright.sync_api import expect, sync_playwright
|
||||
|
||||
|
||||
ROOT = Path(__file__).parents[2]
|
||||
FRONTEND = ROOT / "frontend"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("viewport", [
|
||||
{"width": 320, "height": 568},
|
||||
{"width": 390, "height": 844},
|
||||
])
|
||||
def test_failed_release_check_is_diagnosable_and_retryable_on_phone(viewport):
|
||||
with sync_playwright() as playwright:
|
||||
browser = playwright.chromium.launch(headless=True)
|
||||
page = browser.new_page(viewport=viewport)
|
||||
page.set_content((FRONTEND / "index.html").read_text())
|
||||
page.add_style_tag(path=FRONTEND / "dashboard.css")
|
||||
page.add_script_tag(path=FRONTEND / "release-receipt.js")
|
||||
result = page.evaluate("""async () => {
|
||||
const calls=[];
|
||||
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 receipt=createReleaseReceipt({
|
||||
storage,
|
||||
getLogin:()=> 'timmy',
|
||||
listNode:document.querySelector('#release-watchlist'),
|
||||
confirmAction:()=>true,
|
||||
fetchJson:async(path, options={})=>{
|
||||
calls.push({path, method:options.method || 'GET'});
|
||||
if (path.endsWith('/failure')) return {
|
||||
commit_sha:'abc1234', run_id:91, job_index:3,
|
||||
name:'CI / browser', excerpt:'AssertionError: mobile viewport overflow',
|
||||
};
|
||||
if (path.endsWith('/retry')) return {commit_sha:'abc1234', status:'queued'};
|
||||
return {
|
||||
commit_sha:'abc1234', ci_state:'failure', release:null,
|
||||
checks:[{
|
||||
name:'CI / browser with a deliberately long workflow name',
|
||||
state:'failure', description:'Playwright failed at the narrow viewport',
|
||||
url:'https://forge.example/git/stackchain/api/actions/runs/91/jobs/3',
|
||||
recovery:{run_id:91, job_index:3},
|
||||
}],
|
||||
};
|
||||
},
|
||||
});
|
||||
receipt.capture(
|
||||
{repository:'stackchain/api-with-a-long-mobile-name', number:7, key:'stackchain/api-with-a-long-mobile-name#7'},
|
||||
{merge_commit_sha:'abc1234'},
|
||||
);
|
||||
document.querySelector('#release-receipt-sheet').showModal();
|
||||
await receipt.refresh();
|
||||
const review=document.querySelector('.release-failure-summary button');
|
||||
const reviewHeight=review.getBoundingClientRect().height;
|
||||
review.click();
|
||||
await new Promise(resolve=>setTimeout(resolve, 0));
|
||||
const recovery=document.querySelector('.release-failure-recovery');
|
||||
const retry=recovery.querySelector('button');
|
||||
const retryHeight=retry.getBoundingClientRect().height;
|
||||
const excerpt=recovery.querySelector('pre').textContent;
|
||||
const sha=recovery.querySelector('strong').textContent;
|
||||
const job=recovery.querySelector('a').href;
|
||||
const overflow=document.documentElement.scrollWidth > document.documentElement.clientWidth;
|
||||
retry.click();
|
||||
await new Promise(resolve=>setTimeout(resolve, 0));
|
||||
return {
|
||||
calls, reviewHeight, retryHeight, excerpt, sha, job, overflow,
|
||||
state:receipt.restore()[0].status.label,
|
||||
};
|
||||
}""")
|
||||
expect(page.locator("#release-receipt-sheet")).to_be_visible()
|
||||
assert result["reviewHeight"] >= 44
|
||||
assert result["retryHeight"] >= 44
|
||||
assert result["excerpt"] == "AssertionError: mobile viewport overflow"
|
||||
assert result["sha"] == "Merge abc1234"
|
||||
assert result["job"].endswith("/actions/runs/91/jobs/3")
|
||||
assert result["overflow"] is False
|
||||
assert result["state"] == "Checks running"
|
||||
assert [call["method"] for call in result["calls"]] == ["GET", "GET", "POST"]
|
||||
browser.close()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("viewport", [
|
||||
{"width": 320, "height": 568},
|
||||
{"width": 390, "height": 844},
|
||||
])
|
||||
def test_failed_release_prepares_a_visible_draft_rollback_receipt_on_phone(viewport):
|
||||
with sync_playwright() as playwright:
|
||||
browser = playwright.chromium.launch(headless=True)
|
||||
page = browser.new_page(viewport=viewport)
|
||||
page.set_content((FRONTEND / "index.html").read_text())
|
||||
page.add_style_tag(path=FRONTEND / "dashboard.css")
|
||||
page.add_script_tag(path=FRONTEND / "release-receipt.js")
|
||||
result = page.evaluate("""async () => {
|
||||
const values=new Map(), calls=[], opened=[];
|
||||
const receipt=createReleaseReceipt({
|
||||
storage:{getItem:key=>values.get(key)||null,setItem:(key,value)=>values.set(key,value),removeItem:key=>values.delete(key)},
|
||||
getLogin:()=> 'timmy', listNode:document.querySelector('#release-watchlist'),
|
||||
confirmAction:()=>true, openPull:pull=>opened.push(pull),
|
||||
fetchJson:async(path, options={})=>{
|
||||
calls.push({path,method:options.method||'GET'});
|
||||
if(path.endsWith('/failure')) return {commit_sha:'abc1234',run_id:91,job_index:3,name:'CI / browser',excerpt:'failed'};
|
||||
if(path.endsWith('/rollback')) return {repository:'stackchain/api',number:9,draft:true,rollback_of:'abc1234',url:'https://forge.example/git/stackchain/api/pulls/9'};
|
||||
return {commit_sha:'abc1234',ci_state:'failure',release:null,checks:[{name:'CI / browser',state:'failure',recovery:{run_id:91,job_index:3}}]};
|
||||
},
|
||||
});
|
||||
receipt.capture({repository:'stackchain/api',number:7,key:'stackchain/api#7'},{merge_commit_sha:'abc1234'});
|
||||
document.querySelector('#release-receipt-sheet').showModal();
|
||||
await receipt.refresh();
|
||||
document.querySelector('.release-failure-summary button').click();
|
||||
await new Promise(resolve=>setTimeout(resolve,0));
|
||||
const rollback=[...document.querySelectorAll('.release-failure-actions button')].find(button=>button.textContent==='Prepare rollback PR');
|
||||
const actionHeight=rollback.getBoundingClientRect().height;
|
||||
rollback.click();
|
||||
await new Promise(resolve=>setTimeout(resolve,0));
|
||||
const status=document.querySelector('.release-rollback-status');
|
||||
return {calls,opened,actionHeight,status:status?.textContent||'',overflow:document.documentElement.scrollWidth>document.documentElement.clientWidth};
|
||||
}""")
|
||||
assert result["actionHeight"] >= 44
|
||||
assert result["status"] == "Draft rollback #9 is ready for review."
|
||||
assert result["opened"][0]["number"] == 9
|
||||
assert result["calls"][-1]["path"].endswith("/release-receipt/abc1234/rollback")
|
||||
assert result["overflow"] is False
|
||||
browser.close()
|
||||
@@ -0,0 +1,79 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
if os.getenv("STACKCHAIN_RUN_RELEASE_E2E") != "1":
|
||||
pytest.skip("rendered authored-pull recovery checks run only in the browser gate", allow_module_level=True)
|
||||
pytest.importorskip("playwright.sync_api")
|
||||
from playwright.sync_api import expect, sync_playwright
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
FRONTEND = ROOT / "frontend"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("width", "height"), [(320, 568), (390, 844)])
|
||||
def test_mobile_search_reopens_closed_authored_pull_into_my_work(width, height):
|
||||
html = re.sub(r'<script src="static/[^"]+"></script>', "", (FRONTEND / "index.html").read_text())
|
||||
|
||||
with sync_playwright() as playwright:
|
||||
browser = playwright.chromium.launch()
|
||||
page = browser.new_page(viewport={"width": width, "height": height})
|
||||
page.set_content(html)
|
||||
page.add_style_tag(path=FRONTEND / "dashboard.css")
|
||||
page.add_script_tag(path=FRONTEND / "search-preview.js")
|
||||
page.locator("#search-preview").evaluate("node => node.classList.add('open')")
|
||||
page.evaluate("""() => {
|
||||
const detail = {
|
||||
repository:'stackchain/web', number:9, kind:'pull', state:'closed',
|
||||
authored_pull_reopenable:true, head_sha:'abc1234',
|
||||
};
|
||||
const button = document.querySelector('#start-search-result');
|
||||
globalThis.renderSearchPreviewStart(detail, {status:'ready'}, button);
|
||||
globalThis.recoveryMetrics = {calls:[], history:['search']};
|
||||
const mutate = globalThis.searchPreviewMutation((path, options) => {
|
||||
globalThis.recoveryMetrics.calls.push({path, body:JSON.parse(options.body)});
|
||||
return Promise.resolve({...detail, state:'open'});
|
||||
});
|
||||
const preview = globalThis.createSearchPreview({
|
||||
fetchJson:async () => detail,
|
||||
mutate,
|
||||
onState:() => {},
|
||||
});
|
||||
preview.open(detail);
|
||||
const recover = globalThis.createSearchAuthoredPullRecovery({
|
||||
confirm:message => window.confirm(message),
|
||||
reopen:target => preview.reopenPull(target),
|
||||
refresh:async () => { globalThis.recoveryMetrics.refreshed = true; },
|
||||
find:() => ({repository:'stackchain/web',number:9,kind:'pull',key:'stackchain/web#9'}),
|
||||
open:item => globalThis.recoveryMetrics.history.push(item.kind),
|
||||
unavailable:message => { globalThis.recoveryMetrics.unavailable = message; },
|
||||
});
|
||||
button.addEventListener('click', () => recover(detail));
|
||||
}""")
|
||||
|
||||
action = page.locator("#start-search-result")
|
||||
expect(action).to_be_visible()
|
||||
expect(action).to_have_text("Reopen in My Work")
|
||||
bounds = action.bounding_box()
|
||||
assert bounds and bounds["height"] >= 44
|
||||
assert page.evaluate("document.documentElement.scrollWidth <= window.innerWidth")
|
||||
|
||||
page.once("dialog", lambda dialog: dialog.accept())
|
||||
action.click()
|
||||
page.wait_for_function("globalThis.recoveryMetrics.history.length === 2")
|
||||
metrics = page.evaluate("globalThis.recoveryMetrics")
|
||||
|
||||
assert metrics["calls"] == [{
|
||||
"path": "api/v1/repos/stackchain/web/pulls/9/reopen",
|
||||
"body": {"expected_head_sha": "abc1234"},
|
||||
}]
|
||||
assert metrics["refreshed"] is True
|
||||
assert metrics["history"] == ["search", "pull"]
|
||||
assert "unavailable" not in metrics
|
||||
browser.close()
|
||||
@@ -88,3 +88,62 @@ def test_rendered_mobile_search_preview_navigation_preserves_reading_space_and_d
|
||||
page.set_viewport_size({"width": 800, "height": 700})
|
||||
expect(navigation).to_be_hidden()
|
||||
browser.close()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("width", "height"), [(320, 568), (390, 844)])
|
||||
def test_rendered_search_to_preview_journey_contains_focus_until_final_close(width, height):
|
||||
html = re.sub(r'<script src="static/[^"]+"></script>', "", (FRONTEND / "index.html").read_text())
|
||||
|
||||
with sync_playwright() as playwright:
|
||||
browser = playwright.chromium.launch()
|
||||
page = browser.new_page(viewport={"width": width, "height": height})
|
||||
page.set_content(html)
|
||||
page.add_style_tag(path=FRONTEND / "dashboard.css")
|
||||
page.add_script_tag(path=FRONTEND / "mobile-search-modal.js")
|
||||
page.evaluate("""() => {
|
||||
const palette = document.querySelector('#cmd-palette');
|
||||
const preview = document.querySelector('#search-preview');
|
||||
palette.classList.add('open');
|
||||
window.searchModalTest = createMobileSearchModal({document});
|
||||
window.searchModalTest.activate(palette, {
|
||||
opener:document.querySelector('[data-mobile-task="search"]'),
|
||||
initialFocus:document.querySelector('#cmd-input'),
|
||||
});
|
||||
preview.append(Object.assign(document.createElement('button'), {id:'dynamic-preview-action', textContent:'Dynamic action'}));
|
||||
}""")
|
||||
|
||||
expect(page.locator("#cmd-input")).to_be_focused()
|
||||
expect(page.locator("#cmd-palette")).to_have_attribute("aria-modal", "true")
|
||||
assert page.locator("body > header").evaluate("node => node.inert") is True
|
||||
assert page.locator("main").evaluate("node => node.inert") is True
|
||||
assert page.locator("#mobile-task-dock").evaluate("node => node.inert") is True
|
||||
|
||||
page.evaluate("""() => {
|
||||
document.querySelector('#cmd-palette').classList.remove('open');
|
||||
document.querySelector('#search-preview').classList.add('open');
|
||||
searchModalTest.transition(document.querySelector('#search-preview'), {
|
||||
initialFocus:document.querySelector('#close-search-preview'),
|
||||
});
|
||||
document.querySelector('#dynamic-preview-action').focus();
|
||||
}""")
|
||||
page.keyboard.press("Tab")
|
||||
expect(page.locator("#close-search-preview")).to_be_focused()
|
||||
assert page.locator("main").evaluate("node => node.inert") is True
|
||||
|
||||
page.evaluate("""() => {
|
||||
document.querySelector('#search-preview').classList.remove('open');
|
||||
document.querySelector('#cmd-palette').classList.add('open');
|
||||
searchModalTest.transition(document.querySelector('#cmd-palette'), {
|
||||
initialFocus:document.querySelector('#cmd-input'),
|
||||
});
|
||||
}""")
|
||||
expect(page.locator("#cmd-input")).to_be_focused()
|
||||
assert page.locator("main").evaluate("node => node.inert") is True
|
||||
assert page.evaluate("document.documentElement.scrollWidth <= window.innerWidth")
|
||||
|
||||
page.evaluate("searchModalTest.deactivate()")
|
||||
expect(page.locator('[data-mobile-task="search"]')).to_be_focused()
|
||||
assert page.locator("body > header").evaluate("node => node.inert") is False
|
||||
assert page.locator("main").evaluate("node => node.inert") is False
|
||||
assert page.locator("#mobile-task-dock").evaluate("node => node.inert") is False
|
||||
browser.close()
|
||||
@@ -0,0 +1,67 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
if os.getenv("STACKCHAIN_RUN_RELEASE_E2E") != "1":
|
||||
pytest.skip("packaged branch-cleanup journey runs only in the browser gate", allow_module_level=True)
|
||||
pytest.importorskip("playwright.sync_api")
|
||||
from playwright.sync_api import expect, sync_playwright
|
||||
|
||||
|
||||
ROOT = Path(__file__).parents[2]
|
||||
FRONTEND = ROOT / "frontend"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("viewport", [
|
||||
{"width": 320, "height": 568},
|
||||
{"width": 390, "height": 844},
|
||||
])
|
||||
def test_merged_source_branch_cleanup_is_phone_openable_and_exact(viewport):
|
||||
with sync_playwright() as playwright:
|
||||
browser = playwright.chromium.launch(headless=True)
|
||||
page = browser.new_page(viewport=viewport)
|
||||
page.set_content((FRONTEND / "index.html").read_text())
|
||||
page.add_style_tag(path=FRONTEND / "dashboard.css")
|
||||
page.add_script_tag(path=FRONTEND / "release-receipt.js")
|
||||
result = page.evaluate("""async () => {
|
||||
const calls=[];
|
||||
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 receipt=createReleaseReceipt({
|
||||
storage,
|
||||
getLogin:()=> 'timmy',
|
||||
listNode:document.querySelector('#release-watchlist'),
|
||||
confirmAction:()=>true,
|
||||
fetchJson:async(path, options={})=>{
|
||||
calls.push({path, method:options.method, body:options.body});
|
||||
return {deleted:true, source_branch:'timmy/feature', source_head_sha:'abc1234'};
|
||||
},
|
||||
});
|
||||
receipt.capture(
|
||||
{repository:'stackchain/api', number:7, key:'stackchain/api#7'},
|
||||
{merge_commit_sha:'merge456', source_branch:'timmy/feature', source_head_sha:'abc1234', source_repository:'stackchain/api'},
|
||||
);
|
||||
document.querySelector('#release-receipt-sheet').showModal();
|
||||
const button=document.querySelector('.release-watchlist-actions button');
|
||||
const box=button.getBoundingClientRect();
|
||||
const label=button.getAttribute('aria-label');
|
||||
button.click();
|
||||
await new Promise(resolve=>setTimeout(resolve, 0));
|
||||
return {
|
||||
calls, label, height:box.height,
|
||||
branch:document.querySelector('.release-branch-cleanup-status').textContent,
|
||||
overflow:document.documentElement.scrollWidth > document.documentElement.clientWidth,
|
||||
};
|
||||
}""")
|
||||
expect(page.locator("#release-receipt-sheet")).to_be_visible()
|
||||
assert result["height"] >= 44
|
||||
assert result["label"] == "Delete merged source branch timmy/feature at abc1234"
|
||||
assert result["calls"][0]["method"] == "DELETE"
|
||||
assert result["branch"] == "Branch timmy/feature · deleted"
|
||||
assert result["overflow"] is False
|
||||
browser.close()
|
||||
@@ -416,6 +416,7 @@ def test_release_artifact_pauses_today_across_mobile_work_and_insights_detours(t
|
||||
queue_pause = page.locator("#mobile-queue-sheet [data-today-detour]")
|
||||
expect(queue_pause).to_be_visible()
|
||||
expect(queue_pause).to_contain_text("Today paused · Ship mobile capture")
|
||||
page.locator(".mobile-queue-all summary").click()
|
||||
page.locator('[data-mobile-queue="later"]').click()
|
||||
persistent_pause = page.locator("#my-work > [data-today-detour]")
|
||||
expect(persistent_pause).to_be_visible()
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
if os.getenv("STACKCHAIN_RUN_RELEASE_E2E") != "1":
|
||||
pytest.skip("progressive mobile dock checks run only in the browser gate", allow_module_level=True)
|
||||
pytest.importorskip("playwright.sync_api")
|
||||
from playwright.sync_api import expect, sync_playwright
|
||||
|
||||
|
||||
ROOT = Path(__file__).parents[2]
|
||||
FRONTEND = ROOT / "frontend"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("viewport", [{"width": 320, "height": 568}, {"width": 390, "height": 844}])
|
||||
def test_mobile_work_and_queues_are_usable_before_optional_hydration(viewport):
|
||||
with sync_playwright() as playwright:
|
||||
browser = playwright.chromium.launch()
|
||||
page = browser.new_page(viewport=viewport)
|
||||
page.set_content((FRONTEND / "index.html").read_text())
|
||||
page.add_style_tag(path=FRONTEND / "dashboard.css")
|
||||
page.add_script_tag(path=FRONTEND / "my-work.js")
|
||||
page.add_script_tag(path=FRONTEND / "context-poller.js")
|
||||
page.evaluate(
|
||||
"""() => {
|
||||
window.fetch = async () => ({
|
||||
ok:true, headers:{get:()=>null}, json:async()=>({
|
||||
context:{
|
||||
user:{login:'timmy'},
|
||||
issues:[{
|
||||
number:1427,title:'Progressive mobile dock',repository:'stackchain/stackchain-dashboard',
|
||||
assignees:['timmy'],work_reasons:['created_by_me'],url:'https://forge.example/issues/1427',
|
||||
}],
|
||||
pull_requests:[],
|
||||
},
|
||||
events:[],notifications:[],
|
||||
}),
|
||||
});
|
||||
}"""
|
||||
)
|
||||
page.add_script_tag(path=FRONTEND / "progressive-my-work.js")
|
||||
expect(page.locator("#my-work-status")).to_contain_text("1 assigned work item")
|
||||
page.add_script_tag(path=FRONTEND / "progressive-mobile-dock.js")
|
||||
|
||||
page.locator('[data-mobile-task="queues"]').click()
|
||||
expect(page.locator("#mobile-queue-sheet")).to_be_visible()
|
||||
expect(page.locator('[data-mobile-queue="filed"] [data-mobile-queue-count]')).to_have_text("1")
|
||||
page.locator(".mobile-queue-all summary").click()
|
||||
expect(page.locator('[data-mobile-queue="delivery"]')).to_contain_text("Still loading")
|
||||
next_action = page.locator("#mobile-queue-next-action")
|
||||
bounds = next_action.bounding_box()
|
||||
assert bounds and bounds["height"] >= 44
|
||||
assert page.evaluate("document.documentElement.scrollWidth <= window.innerWidth")
|
||||
|
||||
page.locator('[data-mobile-queue="filed"]').click()
|
||||
expect(page.locator("#progressive-work-detail")).to_be_visible()
|
||||
expect(page.locator("#progressive-work-detail-title")).to_have_text("Progressive mobile dock")
|
||||
page.locator("#close-progressive-work-detail").click()
|
||||
|
||||
page.locator('[data-mobile-task="work"]').click()
|
||||
expect(page.locator("#progressive-work-detail")).to_be_visible()
|
||||
expect(page.locator("#progressive-work-detail-title")).to_have_text("Progressive mobile dock")
|
||||
assert page.evaluate("document.documentElement.scrollWidth <= window.innerWidth")
|
||||
browser.close()
|
||||
+37
-45
@@ -1,13 +1,44 @@
|
||||
from pathlib import Path
|
||||
import re
|
||||
|
||||
|
||||
WORKFLOW = Path(".gitea/workflows/ci.yml")
|
||||
ACTION_REFERENCE = re.compile(
|
||||
r"^\s*- uses: (?P<action>[^\s@]+)@(?P<revision>[^\s#]+)\s+# (?P<version>v\d+(?:\.\d+){1,2})$",
|
||||
re.MULTILINE,
|
||||
)
|
||||
DOWNLOAD_ARTIFACT = (
|
||||
"actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2"
|
||||
)
|
||||
|
||||
|
||||
def test_ci_uses_gitea_compatible_artifact_action():
|
||||
text = WORKFLOW.read_text()
|
||||
assert "actions/upload-artifact@v4" not in text
|
||||
assert "actions/upload-artifact@v3" in text
|
||||
assert re.search(
|
||||
r"actions/upload-artifact@[0-9a-f]{40}\s+# v3\.\d+\.\d+", text
|
||||
)
|
||||
|
||||
|
||||
def test_ci_pins_every_external_action_to_a_reviewable_commit():
|
||||
text = WORKFLOW.read_text()
|
||||
uses_lines = [line for line in text.splitlines() if line.lstrip().startswith("- uses:")]
|
||||
references = list(ACTION_REFERENCE.finditer(text))
|
||||
|
||||
assert len(references) == len(uses_lines)
|
||||
assert references
|
||||
for reference in references:
|
||||
assert re.fullmatch(r"[0-9a-f]{40}", reference["revision"])
|
||||
|
||||
|
||||
def test_ci_grants_repository_write_access_only_to_release_job():
|
||||
text = WORKFLOW.read_text()
|
||||
jobs = text[text.index("jobs:") :]
|
||||
before_release, release = jobs.split(" release-candidate:", 1)
|
||||
|
||||
assert "permissions:\n contents: read" in text[: text.index("jobs:")]
|
||||
assert "contents: write" not in before_release
|
||||
assert "permissions:\n contents: write" in release
|
||||
|
||||
|
||||
def test_ci_installs_declared_requirements_before_tests():
|
||||
@@ -40,7 +71,7 @@ def test_release_promotion_waits_for_tests_and_bundle():
|
||||
|
||||
assert "needs: [lint, build-release, browser-journey]" in release
|
||||
assert "github.event_name == 'push'" in release
|
||||
assert "actions/download-artifact@v3" in release
|
||||
assert DOWNLOAD_ARTIFACT in release
|
||||
assert (
|
||||
'python3 scripts/verify_release.py --input-dir dist --commit "$TARGET" --repository .'
|
||||
in release
|
||||
@@ -48,55 +79,16 @@ def test_release_promotion_waits_for_tests_and_bundle():
|
||||
assert release.index("sha256sum -c") < release.index("curl --fail-with-body")
|
||||
|
||||
|
||||
def test_release_promotion_waits_for_packaged_mobile_journeys():
|
||||
def test_release_promotion_waits_for_every_packaged_mobile_journey():
|
||||
text = WORKFLOW.read_text()
|
||||
browser = text[text.index(" browser-journey:") : text.index(" release-candidate:")]
|
||||
release = text[text.index(" release-candidate:") :]
|
||||
|
||||
assert "needs: build-release" in browser
|
||||
assert "actions/download-artifact@v3" in browser
|
||||
assert DOWNLOAD_ARTIFACT in browser
|
||||
assert "pip install -r requirements-e2e.txt" in browser
|
||||
assert "python3 -m playwright install --with-deps chromium" in browser
|
||||
assert 'STACKCHAIN_RUN_RELEASE_E2E: "1"' in browser
|
||||
assert (
|
||||
"python3 -m pytest tests/e2e/test_mobile_offline_issue_release.py "
|
||||
"tests/e2e/test_mobile_search_preview_navigation.py "
|
||||
"tests/e2e/test_mobile_search_week_plan.py "
|
||||
"tests/e2e/test_mobile_find_work_release.py "
|
||||
"tests/e2e/test_mobile_home_bootstrap_release.py "
|
||||
"tests/e2e/test_mobile_sign_out_release.py "
|
||||
"tests/e2e/test_mobile_today_handoff_release.py "
|
||||
"tests/e2e/test_mobile_today_wrap_up_release.py "
|
||||
"tests/e2e/test_mobile_today_summary_release.py "
|
||||
"tests/e2e/test_mobile_tomorrow_conflict_release.py "
|
||||
"tests/e2e/test_mobile_week_ahead_release.py "
|
||||
"tests/e2e/test_mobile_today_week_reschedule_release.py "
|
||||
"tests/e2e/test_mobile_wrap_up_handoff_release.py "
|
||||
"tests/e2e/test_mobile_following_release.py "
|
||||
"tests/e2e/test_mobile_detail_watch_release.py "
|
||||
"tests/e2e/test_mobile_pull_reviewer_status_release.py "
|
||||
"tests/e2e/test_mobile_pull_reviewer_feedback_release.py -q"
|
||||
) in browser
|
||||
assert "python3 -m pytest tests/e2e -q" in browser
|
||||
assert "test_mobile_" not in browser
|
||||
assert "needs: [lint, build-release, browser-journey]" in release
|
||||
|
||||
|
||||
def test_browser_job_runs_packaged_today_week_reschedule_journey():
|
||||
text = WORKFLOW.read_text()
|
||||
browser = text[text.index(" browser-journey:") : text.index(" release-candidate:")]
|
||||
|
||||
assert "tests/e2e/test_mobile_today_week_reschedule_release.py" in browser
|
||||
|
||||
|
||||
def test_browser_job_gates_latest_pull_review_mobile_journeys():
|
||||
text = WORKFLOW.read_text()
|
||||
browser = text[text.index(" browser-journey:") : text.index(" release-candidate:")]
|
||||
|
||||
assert "tests/e2e/test_mobile_address_review_feedback_release.py" in browser
|
||||
assert "tests/e2e/test_mobile_cancel_pull_review_request_release.py" in browser
|
||||
|
||||
|
||||
def test_browser_job_gates_authored_pull_queue_journey():
|
||||
text = WORKFLOW.read_text()
|
||||
browser = text[text.index(" browser-journey:") : text.index(" release-candidate:")]
|
||||
|
||||
assert "tests/e2e/test_mobile_authored_pull_queue_release.py" in browser
|
||||
@@ -827,6 +827,143 @@ if (!states.some(state => state.status === 'reopened')) throw new Error('reopen
|
||||
subprocess.run(["node", "-e", script], check=True, capture_output=True, text=True)
|
||||
|
||||
|
||||
def test_search_preview_closed_authored_pull_reopen_sends_head_guard_to_pull_api():
|
||||
script = f"""
|
||||
require({json.dumps(str(SEARCH_PREVIEW))});
|
||||
(async () => {{
|
||||
const calls = [];
|
||||
const mutate = globalThis.searchPreviewMutation(async (path, options) => {{
|
||||
calls.push({{path, options}});
|
||||
return {{repository:'stackchain/web',number:9,state:'open',head_sha:'abc1234'}};
|
||||
}});
|
||||
const detail = {{
|
||||
repository:'stackchain/web',number:9,kind:'pull',state:'closed',
|
||||
authored_pull_reopenable:true,head_sha:'abc1234',
|
||||
}};
|
||||
const result = await mutate(detail, 'reopen-pull');
|
||||
process.stdout.write(JSON.stringify({{calls,result}}));
|
||||
}})().catch(error => {{ console.error(error); process.exit(1); }});
|
||||
"""
|
||||
result = subprocess.run(["node", "-e", script], capture_output=True, text=True)
|
||||
|
||||
assert result.returncode == 0, result.stderr
|
||||
assert json.loads(result.stdout) == {
|
||||
"calls": [{
|
||||
"path": "api/v1/repos/stackchain/web/pulls/9/reopen",
|
||||
"options": {
|
||||
"method": "PATCH",
|
||||
"headers": {"Content-Type": "application/json"},
|
||||
"body": '{"expected_head_sha":"abc1234"}',
|
||||
},
|
||||
}],
|
||||
"result": {
|
||||
"repository": "stackchain/web",
|
||||
"number": 9,
|
||||
"state": "open",
|
||||
"head_sha": "abc1234",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_search_preview_closed_authored_pull_exposes_reopen_in_my_work_action():
|
||||
script = f"""
|
||||
require({json.dumps(str(SEARCH_PREVIEW))});
|
||||
const detail = {{
|
||||
repository:'stackchain/web',number:9,kind:'pull',state:'closed',
|
||||
authored_pull_reopenable:true,head_sha:'abc1234',
|
||||
}};
|
||||
const ready = {{hidden:true,textContent:'',disabled:false}};
|
||||
globalThis.renderSearchPreviewStart(detail, {{status:'ready'}}, ready);
|
||||
const pending = {{hidden:true,textContent:'',disabled:false}};
|
||||
globalThis.renderSearchPreviewStart(detail, {{status:'reopening'}}, pending);
|
||||
process.stdout.write(JSON.stringify({{ready,pending}}));
|
||||
"""
|
||||
result = subprocess.run(["node", "-e", script], capture_output=True, text=True)
|
||||
|
||||
assert result.returncode == 0, result.stderr
|
||||
assert json.loads(result.stdout) == {
|
||||
"ready": {
|
||||
"hidden": False,
|
||||
"textContent": "Reopen in My Work",
|
||||
"disabled": False,
|
||||
},
|
||||
"pending": {
|
||||
"hidden": False,
|
||||
"textContent": "Reopen in My Work",
|
||||
"disabled": True,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_search_preview_closed_authored_pull_reopen_is_single_flight():
|
||||
script = f"""
|
||||
const createSearchPreview = require({json.dumps(str(SEARCH_PREVIEW))});
|
||||
(async () => {{
|
||||
let calls = 0;
|
||||
let resolveMutation;
|
||||
const states = [];
|
||||
const detail = {{
|
||||
repository:'stackchain/web',number:9,kind:'pull',state:'closed',
|
||||
authored_pull_reopenable:true,head_sha:'abc1234',
|
||||
}};
|
||||
const preview = createSearchPreview({{
|
||||
fetchJson:async () => detail,
|
||||
mutate:(_detail, action) => {{
|
||||
if (action !== 'reopen-pull') throw new Error('wrong action');
|
||||
calls += 1;
|
||||
return new Promise(resolve => {{ resolveMutation = resolve; }});
|
||||
}},
|
||||
onState:state => states.push(state),
|
||||
}});
|
||||
await preview.open(detail);
|
||||
const first = preview.reopenPull(detail);
|
||||
const second = preview.reopenPull(detail);
|
||||
if (first !== second || calls !== 1) throw new Error('pull recovery was not single-flight');
|
||||
resolveMutation({{...detail,state:'open'}});
|
||||
await first;
|
||||
process.stdout.write(JSON.stringify({{calls,status:states.at(-1).status}}));
|
||||
}})().catch(error => {{ console.error(error); process.exit(1); }});
|
||||
"""
|
||||
result = subprocess.run(["node", "-e", script], capture_output=True, text=True)
|
||||
|
||||
assert result.returncode == 0, result.stderr
|
||||
assert json.loads(result.stdout) == {"calls": 1, "status": "reopened"}
|
||||
|
||||
|
||||
def test_authored_pull_recovery_confirms_refreshes_and_opens_above_search_history():
|
||||
script = f"""
|
||||
require({json.dumps(str(SEARCH_PREVIEW))});
|
||||
(async () => {{
|
||||
const events = [];
|
||||
const history = ['search'];
|
||||
const detail = {{repository:'stackchain/web',number:9,kind:'pull',head_sha:'abc1234'}};
|
||||
const item = {{repository:'stackchain/web',number:9,kind:'pull',key:'stackchain/web#9'}};
|
||||
const recover = globalThis.createSearchAuthoredPullRecovery({{
|
||||
confirm:message => {{ events.push(['confirm',message]); return true; }},
|
||||
reopen:target => {{ events.push(['reopen',target.head_sha]); return Promise.resolve({{...target,state:'open'}}); }},
|
||||
refresh:() => {{ events.push(['refresh']); return Promise.resolve(); }},
|
||||
find:target => target.number === 9 ? item : null,
|
||||
open:opened => {{ events.push(['open',opened.key]); history.push('pull'); }},
|
||||
unavailable:message => events.push(['unavailable',message]),
|
||||
}});
|
||||
const outcome = await recover(detail);
|
||||
process.stdout.write(JSON.stringify({{events,history,outcome}}));
|
||||
}})().catch(error => {{ console.error(error); process.exit(1); }});
|
||||
"""
|
||||
result = subprocess.run(["node", "-e", script], capture_output=True, text=True)
|
||||
|
||||
assert result.returncode == 0, result.stderr
|
||||
payload = json.loads(result.stdout)
|
||||
assert payload["events"] == [
|
||||
["confirm", "Reopen stackchain/web #9?"],
|
||||
["reopen", "abc1234"],
|
||||
["refresh"],
|
||||
["open", "stackchain/web#9"],
|
||||
]
|
||||
assert payload["history"] == ["search", "pull"]
|
||||
assert payload["outcome"] == "opened"
|
||||
|
||||
|
||||
def test_search_preview_watch_is_single_flight_and_keeps_visible_context_on_failure():
|
||||
script = f"""
|
||||
const createSearchPreview = require({json.dumps(str(SEARCH_PREVIEW))});
|
||||
@@ -1159,9 +1296,11 @@ def test_assigned_pull_preview_hands_off_to_existing_my_work_sheet_without_claim
|
||||
def test_requested_pull_preview_opens_native_review_without_assignment_mutation():
|
||||
html = dashboard_bundle_text()
|
||||
css = (FRONTEND / "dashboard.css").read_text()
|
||||
preview = SEARCH_PREVIEW.read_text()
|
||||
|
||||
assert "startButton.hidden = !(detail.reviewable" in html
|
||||
assert "detail.reviewable ? 'Review now'" in html
|
||||
assert "renderSearchPreviewStart(detail, state, startButton)" in html
|
||||
assert "button.hidden = !(detail.reviewable" in preview
|
||||
assert "detail.reviewable ? 'Review now'" in preview
|
||||
handler = html.split(
|
||||
"qs('#start-search-result').addEventListener('click'", 1
|
||||
)[1].split("qs('#close-whiteboard')", 1)[0]
|
||||
@@ -1176,9 +1315,10 @@ def test_requested_pull_preview_opens_native_review_without_assignment_mutation(
|
||||
def test_search_preview_offers_assign_and_start_for_eligible_issues():
|
||||
html = dashboard_bundle_text()
|
||||
css = (FRONTEND / "dashboard.css").read_text()
|
||||
preview = SEARCH_PREVIEW.read_text()
|
||||
|
||||
assert 'id="start-search-result"' in html
|
||||
assert "(detail.assigned_to_me ? 'Start in Today' : 'Assign & start')" in html
|
||||
assert "(detail.assigned_to_me ? 'Start in Today' : 'Assign & start')" in preview
|
||||
assert "const searchAssignAndStart = createSearchStart(detail => searchPreview.claim(detail))" in html
|
||||
assert "searchAssignAndStart.run(detail, { alreadyOwned: detail.assigned_to_me })" in html
|
||||
assert ".search-preview-primary-actions" in css
|
||||
@@ -1332,9 +1472,10 @@ process.stdout.write(JSON.stringify({{outcome, refreshes, messages}}));
|
||||
|
||||
def test_closed_issue_preview_reopens_then_resumes_through_capacity_guard():
|
||||
html = dashboard_bundle_text()
|
||||
preview = SEARCH_PREVIEW.read_text()
|
||||
|
||||
assert "detail.reopenable ? 'Reopen & resume'" in html
|
||||
assert "mutate:(detail,action)=>fetchReviewJson(" in html
|
||||
assert "detail.reopenable ? 'Reopen & resume'" in preview
|
||||
assert "mutate:searchPreviewMutation(fetchReviewJson)" in html
|
||||
handler = html.split("qs('#start-search-result').addEventListener('click'", 1)[1].split(
|
||||
"qs('#close-whiteboard')", 1
|
||||
)[0]
|
||||
|
||||
@@ -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-v138" in worker
|
||||
assert "stackchain-dashboard-shell-v146" in worker
|
||||
@@ -0,0 +1,308 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
|
||||
from src import gitea_proxy, main
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_comment_reactions_are_bound_to_conversation_and_aggregate_operator_state(monkeypatch):
|
||||
calls = []
|
||||
|
||||
async def fake_fetch(path):
|
||||
calls.append(("fetch", path))
|
||||
if path == "user":
|
||||
return {"login": "timmy"}
|
||||
if path == "repos/stackchain/api/issues/comments/91":
|
||||
return {
|
||||
"issue_url": "https://forge.example/api/v1/repos/stackchain/api/issues/7",
|
||||
}
|
||||
raise AssertionError(path)
|
||||
|
||||
class Response:
|
||||
def raise_for_status(self):
|
||||
return None
|
||||
|
||||
def json(self):
|
||||
return [
|
||||
{"content": "heart", "user": {"login": "alex"}},
|
||||
{"content": "heart", "user": {"login": "timmy"}},
|
||||
{"content": "+1", "user": {"login": "alex"}},
|
||||
{"content": "unsupported", "user": {"login": "alex"}},
|
||||
{"content": "heart", "user": {}},
|
||||
]
|
||||
|
||||
class Client:
|
||||
async def get(self, path, headers):
|
||||
calls.append(("get", path))
|
||||
return Response()
|
||||
|
||||
monkeypatch.setattr(gitea_proxy, "GITEA_URL", "https://forge.example")
|
||||
monkeypatch.setattr(gitea_proxy, "fetch", fake_fetch)
|
||||
monkeypatch.setattr(gitea_proxy, "_get_client", lambda: Client())
|
||||
monkeypatch.setattr(gitea_proxy, "_auth", lambda: {"Authorization": "token test"})
|
||||
|
||||
result = await gitea_proxy.comment_reactions("stackchain/api", 7, 91)
|
||||
|
||||
assert result == {
|
||||
"comment_id": 91,
|
||||
"reactions": [
|
||||
{"content": "+1", "count": 1, "selected": False},
|
||||
{"content": "heart", "count": 2, "selected": True},
|
||||
],
|
||||
}
|
||||
assert calls == [
|
||||
("fetch", "user"),
|
||||
("fetch", "repos/stackchain/api/issues/comments/91"),
|
||||
("get", "/api/v1/repos/stackchain/api/issues/comments/91/reactions"),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_comment_binding_accepts_gitea_ui_issue_url_shape(monkeypatch):
|
||||
async def fake_fetch(path):
|
||||
if path == "user":
|
||||
return {"login": "timmy"}
|
||||
return {
|
||||
"issue_url": "https://forge.example/git/stackchain/api/issues/7",
|
||||
}
|
||||
|
||||
class Response:
|
||||
def raise_for_status(self):
|
||||
return None
|
||||
|
||||
def json(self):
|
||||
return []
|
||||
|
||||
class Client:
|
||||
async def get(self, path, headers):
|
||||
return Response()
|
||||
|
||||
monkeypatch.setattr(gitea_proxy, "GITEA_URL", "https://forge.example")
|
||||
monkeypatch.setattr(gitea_proxy, "fetch", fake_fetch)
|
||||
monkeypatch.setattr(gitea_proxy, "_get_client", lambda: Client())
|
||||
|
||||
result = await gitea_proxy.comment_reactions("stackchain/api", 7, 91)
|
||||
|
||||
assert result == {"comment_id": 91, "reactions": []}
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_comment_reaction_mutation_is_idempotent_and_returns_confirmed_state(monkeypatch):
|
||||
payloads = [[], [{"content": "heart", "user": {"login": "timmy"}}]]
|
||||
mutations = []
|
||||
|
||||
async def fake_fetch(path):
|
||||
if path == "user":
|
||||
return {"login": "timmy"}
|
||||
return {"issue_url": "https://forge.example/api/v1/repos/stackchain/api/issues/7"}
|
||||
|
||||
class Response:
|
||||
def __init__(self, payload=None):
|
||||
self.payload = payload
|
||||
|
||||
def raise_for_status(self):
|
||||
return None
|
||||
|
||||
def json(self):
|
||||
return self.payload
|
||||
|
||||
class Client:
|
||||
async def get(self, path, headers):
|
||||
return Response(payloads.pop(0))
|
||||
|
||||
async def post(self, path, headers, json):
|
||||
mutations.append(("post", path, json))
|
||||
return Response()
|
||||
|
||||
async def delete(self, path, headers, json):
|
||||
mutations.append(("delete", path, json))
|
||||
return Response()
|
||||
|
||||
monkeypatch.setattr(gitea_proxy, "GITEA_URL", "https://forge.example")
|
||||
monkeypatch.setattr(gitea_proxy, "fetch", fake_fetch)
|
||||
monkeypatch.setattr(gitea_proxy, "_get_client", lambda: Client())
|
||||
monkeypatch.setattr(gitea_proxy, "_auth", lambda: {"Authorization": "token test"})
|
||||
|
||||
result = await gitea_proxy.set_comment_reaction("stackchain/api", 7, 91, "heart", True)
|
||||
|
||||
path = "/api/v1/repos/stackchain/api/issues/comments/91/reactions"
|
||||
assert mutations == [("post", path, {"content": "heart"})]
|
||||
assert result == {
|
||||
"comment_id": 91,
|
||||
"reactions": [{"content": "heart", "count": 1, "selected": True}],
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_reaction_api_authorizes_issue_pull_and_notification_contexts(monkeypatch):
|
||||
reads = []
|
||||
writes = []
|
||||
|
||||
async def assigned(repository, number):
|
||||
return (repository, number) == ("stackchain/api", 7)
|
||||
|
||||
async def pull_capabilities(repository, number):
|
||||
return {"can_open": (repository, number) == ("stackchain/api", 8)}
|
||||
|
||||
async def notification_target(thread_id):
|
||||
assert thread_id == 42
|
||||
return "stackchain/api", 9
|
||||
|
||||
async def reactions(repository, number, comment_id):
|
||||
reads.append((repository, number, comment_id))
|
||||
return {"comment_id": comment_id, "reactions": []}
|
||||
|
||||
async def set_reaction(repository, number, comment_id, content, active):
|
||||
writes.append((repository, number, comment_id, content, active))
|
||||
return {
|
||||
"comment_id": comment_id,
|
||||
"reactions": [{"content": content, "count": 1, "selected": active}],
|
||||
}
|
||||
|
||||
monkeypatch.setattr(main.gitea_proxy, "is_assigned_issue", assigned)
|
||||
monkeypatch.setattr(main, "_pull_workspace_capabilities", pull_capabilities)
|
||||
monkeypatch.setattr(main, "_has_pull_workspace_access", lambda value: value.get("can_open") is True)
|
||||
monkeypatch.setattr(main.gitea_proxy, "notification_conversation_target", notification_target)
|
||||
monkeypatch.setattr(main.gitea_proxy, "comment_reactions", reactions, raising=False)
|
||||
monkeypatch.setattr(main.gitea_proxy, "set_comment_reaction", set_reaction, raising=False)
|
||||
|
||||
transport = httpx.ASGITransport(app=main.app)
|
||||
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
|
||||
issue = await client.get("/api/v1/repos/stackchain/api/issues/7/comments/91/reactions")
|
||||
pull = await client.get("/api/v1/repos/stackchain/api/pulls/8/comments/92/reactions")
|
||||
update = await client.get("/api/v1/notifications/42/comments/93/reactions")
|
||||
changed = await client.put(
|
||||
"/api/v1/notifications/42/comments/93/reactions/heart",
|
||||
json={"active": True},
|
||||
)
|
||||
|
||||
assert [issue.status_code, pull.status_code, update.status_code, changed.status_code] == [200, 200, 200, 200]
|
||||
assert reads == [
|
||||
("stackchain/api", 7, 91),
|
||||
("stackchain/api", 8, 92),
|
||||
("stackchain/api", 9, 93),
|
||||
]
|
||||
assert writes == [("stackchain/api", 9, 93, "heart", True)]
|
||||
assert changed.json()["reactions"][0]["selected"] is True
|
||||
|
||||
|
||||
def run_node(script: str) -> dict:
|
||||
import subprocess
|
||||
|
||||
result = subprocess.run(
|
||||
["node", "-e", script], cwd=ROOT, text=True, capture_output=True, check=True
|
||||
)
|
||||
return json.loads(result.stdout)
|
||||
|
||||
|
||||
def test_comment_action_controller_loads_and_toggles_authoritative_reactions():
|
||||
module = json.dumps(str(ROOT / "frontend" / "comment-actions.js"))
|
||||
script = f"""
|
||||
const createActions=require({module});
|
||||
const calls=[];
|
||||
const actions=createActions({{
|
||||
fetchJson:async (path, options={{}})=>{{
|
||||
calls.push([path, options.method || 'GET', options.body || null]);
|
||||
return options.method === 'PUT'
|
||||
? {{comment_id:91,reactions:[{{content:'heart',count:2,selected:true}}]}}
|
||||
: {{comment_id:91,reactions:[{{content:'heart',count:1,selected:false}}]}};
|
||||
}},
|
||||
getLogin:()=> 'timmy',
|
||||
}});
|
||||
(async()=>{{
|
||||
const context={{kind:'issue',item:{{repository:'stackchain/api',number:7}}}};
|
||||
const loaded=await actions.loadReactions(context,91);
|
||||
const changed=await actions.setReaction(context,91,'heart',true);
|
||||
process.stdout.write(JSON.stringify({{loaded,changed,calls,html:actions.actionHtml({{id:91,author:'alex'}})}}));
|
||||
}})().catch(error=>{{console.error(error);process.exit(1);}});
|
||||
"""
|
||||
output = run_node(script)
|
||||
base = "api/v1/repos/stackchain/api/issues/7/comments/91/reactions"
|
||||
assert output["calls"] == [
|
||||
[base, "GET", None],
|
||||
[base + "/heart", "PUT", '{"active":true}'],
|
||||
]
|
||||
assert output["loaded"]["reactions"][0]["count"] == 1
|
||||
assert output["changed"]["reactions"][0]["selected"] is True
|
||||
assert 'data-comment-reactions-open' in output["html"]
|
||||
assert 'aria-label="React to this comment"' in output["html"]
|
||||
|
||||
|
||||
def test_comment_reaction_menu_renders_mobile_safe_counts_and_selection():
|
||||
module = json.dumps(str(ROOT / "frontend" / "comment-actions.js"))
|
||||
script = f"""
|
||||
const createActions=require({module});
|
||||
const actions=createActions({{fetchJson:async()=>{{}},getLogin:()=> 'timmy'}});
|
||||
process.stdout.write(JSON.stringify({{html:actions.reactionHtml({{
|
||||
comment_id:91,
|
||||
reactions:[{{content:'heart',count:2,selected:true}},{{content:'+1',count:1,selected:false}}],
|
||||
}})}}));
|
||||
"""
|
||||
html = run_node(script)["html"]
|
||||
assert 'data-comment-reaction="heart"' in html
|
||||
assert 'aria-pressed="true"' in html
|
||||
assert "Heart 2" in html
|
||||
assert 'data-comment-reaction="rocket"' in html
|
||||
assert "Rocket 0" in html
|
||||
assert 'data-comment-reactions-close' in html
|
||||
|
||||
css = (ROOT / "frontend" / "dashboard.css").read_text()
|
||||
assert ".comment-reactions" in css
|
||||
assert "flex-wrap:wrap" in css
|
||||
assert ".comment-reaction-menu button" in css
|
||||
assert "min-height:44px" in css
|
||||
|
||||
|
||||
def test_comment_reaction_wire_loads_menu_and_returns_focus_after_toggle():
|
||||
module = json.dumps(str(ROOT / "frontend" / "comment-actions.js"))
|
||||
script = f"""
|
||||
const createActions=require({module});
|
||||
const calls=[];
|
||||
const menu={{hidden:true,innerHTML:''}};
|
||||
const trigger={{disabled:false,expanded:'false',focused:0,setAttribute:(n,v)=>trigger.expanded=v,focus:()=>trigger.focused++,closest:s=>s==='[data-comment-reactions-open]'?trigger:(s==='.issue-comment'?card:null)}};
|
||||
const reaction={{disabled:false,dataset:{{commentReaction:'heart'}},getAttribute:()=> 'false',closest:s=>s==='[data-comment-reaction]'?reaction:(s==='.issue-comment'?card:null)}};
|
||||
const card={{dataset:{{commentId:'91'}},querySelector:s=>s==='[data-comment-reaction-menu]'?menu:trigger}};
|
||||
const root={{listeners:{{}},addEventListener:(n,fn)=>root.listeners[n]=fn}};
|
||||
const status={{textContent:''}};
|
||||
const surface={{context:{{kind:'update',item:{{notification_id:42}}}},status}};
|
||||
const actions=createActions({{
|
||||
fetchJson:async (path,options={{}})=>{{calls.push([path,options.method||'GET']);return {{comment_id:91,reactions:[{{content:'heart',count:1,selected:options.method==='PUT'}}]}};}},
|
||||
getLogin:()=> 'timmy',
|
||||
}});
|
||||
actions.wire({{root,getSurface:()=>surface,isOffline:()=>false,escapeHtml:String}});
|
||||
(async()=>{{
|
||||
await root.listeners.click({{target:trigger}});
|
||||
await root.listeners.click({{target:reaction}});
|
||||
process.stdout.write(JSON.stringify({{calls,hidden:menu.hidden,html:menu.innerHTML,expanded:trigger.expanded,focused:trigger.focused,status:status.textContent}}));
|
||||
}})().catch(error=>{{console.error(error);process.exit(1);}});
|
||||
"""
|
||||
output = run_node(script)
|
||||
base = "api/v1/notifications/42/comments/91/reactions"
|
||||
assert output["calls"] == [[base, "GET"], [base + "/heart", "PUT"]]
|
||||
assert output["hidden"] is True
|
||||
assert output["expanded"] == "false"
|
||||
assert output["focused"] == 1
|
||||
assert output["status"] == "Reaction updated."
|
||||
|
||||
|
||||
def test_comment_reaction_wire_blocks_offline_mutation_with_reconnect_guidance():
|
||||
module = json.dumps(str(ROOT / "frontend" / "comment-actions.js"))
|
||||
script = f"""
|
||||
const createActions=require({module});
|
||||
let calls=0;
|
||||
const menu={{hidden:true,innerHTML:''}};
|
||||
const card={{dataset:{{commentId:'91'}},querySelector:s=>s.includes('menu')?menu:trigger}};
|
||||
const trigger={{disabled:false,closest:s=>s==='[data-comment-reactions-open]'?trigger:(s==='.issue-comment'?card:null)}};
|
||||
const root={{listeners:{{}},addEventListener:(n,fn)=>root.listeners[n]=fn}};
|
||||
const status={{textContent:''}};
|
||||
const actions=createActions({{fetchJson:async()=>{{calls++;}},getLogin:()=> 'timmy'}});
|
||||
actions.wire({{root,getSurface:()=>({{context:{{kind:'issue',item:{{repository:'stackchain/api',number:7}}}},status}}),isOffline:()=>true,escapeHtml:String}});
|
||||
(async()=>{{await root.listeners.click({{target:trigger}});process.stdout.write(JSON.stringify({{calls,status:status.textContent}}));}})();
|
||||
"""
|
||||
assert run_node(script) == {"calls": 0, "status": "Reconnect to react."}
|
||||
@@ -117,6 +117,125 @@ const poller = createContextPoller({{
|
||||
}
|
||||
|
||||
|
||||
def test_context_poller_adopts_progressive_snapshot_before_revision_conditional_refresh():
|
||||
script = f"""
|
||||
const createContextPoller = require({json.dumps(str(POLLER))});
|
||||
const requested = [];
|
||||
const rendered = [];
|
||||
const timers = [];
|
||||
const seed = {{
|
||||
context:{{user:{{login:'timmy'}}}}, events:[{{id:7}}], notifications:[],
|
||||
revisions:{{context:'0123456789abcdef.1',events:'fedcba9876543210.2',notifications:'0011223344556677.3'}},
|
||||
freshness:{{fresh_for_seconds:8,sections:{{
|
||||
context:{{degraded:false,age_seconds:2}},events:{{degraded:false,age_seconds:5}},notifications:{{degraded:false,age_seconds:1}},
|
||||
}}}},
|
||||
}};
|
||||
const poller = createContextPoller({{
|
||||
fetchContext: revisions => {{
|
||||
requested.push({{...revisions}});
|
||||
return Promise.resolve({{revisions:{{...revisions}},freshness:seed.freshness}});
|
||||
}},
|
||||
onSnapshot: (snapshot, changed) => rendered.push({{login:snapshot.context.user.login,changed}}),
|
||||
onError: error => {{ throw error; }},
|
||||
setTimer: (callback, delay) => {{ const timer={{callback,delay}}; timers.push(timer); return timer; }},
|
||||
clearTimer: () => {{}},
|
||||
intervalMs:8000,
|
||||
}});
|
||||
(async()=>{{
|
||||
const adopted=poller.adopt(seed);
|
||||
const before={{adopted,requests:requested.length,rendered:[...rendered],delay:timers[0].delay}};
|
||||
timers[0].callback();
|
||||
await new Promise(resolve=>setImmediate(resolve));
|
||||
process.stdout.write(JSON.stringify({{before,requested}}));
|
||||
}})();
|
||||
"""
|
||||
|
||||
assert run_node(script) == {
|
||||
"before": {
|
||||
"adopted": True,
|
||||
"requests": 0,
|
||||
"rendered": [{
|
||||
"login": "timmy",
|
||||
"changed": ["context", "events", "notifications"],
|
||||
}],
|
||||
"delay": 3000,
|
||||
},
|
||||
"requested": [{
|
||||
"context": "0123456789abcdef.1",
|
||||
"events": "fedcba9876543210.2",
|
||||
"notifications": "0011223344556677.3",
|
||||
}],
|
||||
}
|
||||
|
||||
|
||||
def test_context_poller_adopts_inflight_progressive_snapshot_without_fetching():
|
||||
script = f"""
|
||||
const createContextPoller = require({json.dumps(str(POLLER))});
|
||||
let calls=0; const rendered=[]; const timers=[];
|
||||
const snapshot={{context:{{user:{{login:'timmy'}}}},events:[],notifications:[]}};
|
||||
const poller=createContextPoller({{
|
||||
fetchContext:()=>{{calls+=1;return Promise.resolve(snapshot);}},
|
||||
onSnapshot:value=>rendered.push(value.context.user.login),
|
||||
onError:error=>{{throw error;}},
|
||||
setTimer:(callback,delay)=>{{const timer={{callback,delay}};timers.push(timer);return timer;}},
|
||||
clearTimer:()=>{{}}, setDeadlineTimer:()=>1, clearDeadlineTimer:()=>{{}}, intervalMs:8000,
|
||||
}});
|
||||
(async()=>{{
|
||||
const adopted=await poller.adoptPending(Promise.resolve(snapshot));
|
||||
process.stdout.write(JSON.stringify({{adopted,calls,rendered,delay:timers[0].delay}}));
|
||||
}})();
|
||||
"""
|
||||
|
||||
assert run_node(script) == {
|
||||
"adopted": True,
|
||||
"calls": 0,
|
||||
"rendered": ["timmy"],
|
||||
"delay": 8000,
|
||||
}
|
||||
|
||||
|
||||
def test_dashboard_adopts_progressive_snapshot_or_falls_back_to_immediate_load():
|
||||
source = DASHBOARD.read_text()
|
||||
|
||||
assert "let adoptedProgressiveSnapshot = contextPoller.adopt(progressiveWorkHandoff?.liveSnapshot);" in source
|
||||
assert "contextPoller.adoptPending(progressiveWorkHandoff.liveSnapshotPromise)" in source
|
||||
assert "if (!adoptedProgressiveSnapshot) await load();" in source
|
||||
|
||||
|
||||
def test_context_poller_uses_failed_section_retry_before_healthy_freshness_deadline():
|
||||
script = f"""
|
||||
const createContextPoller = require({json.dumps(str(POLLER))});
|
||||
const delays = [];
|
||||
const poller = createContextPoller({{
|
||||
fetchContext: () => Promise.resolve({{
|
||||
context: null, events: [], notifications: [],
|
||||
freshness: {{
|
||||
fresh_for_seconds: 8,
|
||||
retry_in_seconds: 5,
|
||||
sections: {{
|
||||
context: {{ degraded: true, retry_in_seconds: 5, age_seconds: 12 }},
|
||||
events: {{ degraded: false, age_seconds: 0 }},
|
||||
notifications: {{ degraded: false, age_seconds: 0 }},
|
||||
}},
|
||||
}},
|
||||
}}),
|
||||
onSnapshot: () => {{}},
|
||||
onError: error => {{ throw error; }},
|
||||
setTimer: (_callback, delay) => {{ delays.push(delay); return delays.length; }},
|
||||
clearTimer: () => {{}},
|
||||
setDeadlineTimer: () => 1,
|
||||
clearDeadlineTimer: () => {{}},
|
||||
intervalMs: 8000,
|
||||
}});
|
||||
(async () => {{
|
||||
await poller.refresh();
|
||||
process.stdout.write(JSON.stringify({{delays}}));
|
||||
}})();
|
||||
"""
|
||||
|
||||
assert run_node(script) == {"delays": [5000]}
|
||||
|
||||
|
||||
def test_context_poller_waits_for_server_cooldown_when_every_section_is_degraded():
|
||||
script = f"""
|
||||
const createContextPoller = require({json.dumps(str(POLLER))});
|
||||
|
||||
@@ -133,3 +133,75 @@ def test_comment_action_retry_is_a_phone_sized_inline_control():
|
||||
rule = css.split(".conversation-actions-retry", 1)[1].split("}", 1)[0]
|
||||
assert "min-height:44px" in rule
|
||||
assert "max-width:100%" in rule
|
||||
|
||||
|
||||
def test_search_and_following_preview_hydrates_owned_comment_actions_lazily():
|
||||
preview = FRONTEND / "search-preview.js"
|
||||
script = f"""
|
||||
require({json.dumps(str(preview))});
|
||||
const nodes = {{
|
||||
'#search-preview-comments': {{innerHTML:'',textContent:''}},
|
||||
'#search-preview-conversation-status': {{textContent:''}},
|
||||
'#retry-search-preview-conversation': {{hidden:true}},
|
||||
'#load-older-search-preview-comments': {{hidden:true,disabled:false}},
|
||||
}};
|
||||
const document = {{querySelector: selector => nodes[selector]}};
|
||||
const actions = {{actionHtml: comment => comment.author === 'timmy'
|
||||
? '<button data-comment-action="edit">Edit</button><button data-comment-reactions-open>React</button>'
|
||||
: '<button data-comment-reactions-open>React</button>'}};
|
||||
renderSearchPreviewConversation({{
|
||||
status:'ready', reviewedAt:'2026-08-25T08:00:00Z',
|
||||
comments:[
|
||||
{{id:41,author:'timmy',body:'Mine',created_at:'2026-08-25T09:00:00Z'}},
|
||||
{{id:42,author:'alexander',body:'Theirs',created_at:'2026-08-25T07:00:00Z'}},
|
||||
],
|
||||
}}, document, String, String, String, actions);
|
||||
process.stdout.write(JSON.stringify({{html:nodes['#search-preview-comments'].innerHTML}}));
|
||||
"""
|
||||
output = run_node(script)["html"]
|
||||
|
||||
assert output.count('class="search-preview-comment issue-comment') == 2
|
||||
assert output.count("data-comment-reactions-open") == 2
|
||||
assert output.count('data-comment-action="edit"') == 1
|
||||
assert 'data-comment-id="41"' in output
|
||||
assert "new-since-review" in output
|
||||
|
||||
html = (FRONTEND / "index.html").read_text()
|
||||
javascript = (FRONTEND / "dashboard.js").read_text()
|
||||
assert 'id="retry-search-preview-comment-actions"' in html
|
||||
assert "showSearchConversationWithActions" in javascript
|
||||
assert "context:{kind:searchPreviewDetail.kind,item:searchPreviewDetail}" in javascript
|
||||
|
||||
|
||||
def test_search_preview_comment_pager_updates_exact_visible_comment_in_place():
|
||||
preview = FRONTEND / "search-preview.js"
|
||||
script = f"""
|
||||
const createSearchPreview = require({json.dumps(str(preview))});
|
||||
(async () => {{
|
||||
const states=[];
|
||||
const controller=createSearchPreview({{
|
||||
fetchJson:async item=>({{...item,title:'Visible'}}),
|
||||
fetchConversation:async()=>({{comments:[
|
||||
{{id:41,author:'timmy',body:'Old'}},{{id:42,author:'alexander',body:'Keep'}},
|
||||
],older_page:null}}),
|
||||
mutate:async()=>({{}}), onState:state=>states.push(state),
|
||||
}});
|
||||
await controller.open({{repository:'stackchain/api',number:9,kind:'pull'}});
|
||||
await new Promise(resolve=>setTimeout(resolve,0));
|
||||
const pager=controller.commentPager();
|
||||
pager.replace({{id:41,author:'timmy',body:'Corrected'}});
|
||||
const replaced=pager.snapshot().comments;
|
||||
pager.remove(41);
|
||||
process.stdout.write(JSON.stringify({{
|
||||
replaced:replaced.map(comment=>[comment.id,comment.body]),
|
||||
remaining:pager.snapshot().comments.map(comment=>comment.id),
|
||||
published:states.at(-1).conversation.comments.map(comment=>comment.id),
|
||||
}}));
|
||||
}})().catch(error=>{{console.error(error);process.exit(1);}});
|
||||
"""
|
||||
|
||||
assert run_node(script) == {
|
||||
"replaced": [[41, "Corrected"], [42, "Keep"]],
|
||||
"remaining": [42],
|
||||
"published": [42],
|
||||
}
|
||||
@@ -79,6 +79,50 @@ const photos = [
|
||||
}
|
||||
|
||||
|
||||
def test_store_lists_only_confirmed_accounts_conversation_photo_drafts_without_blobs():
|
||||
script = f"""
|
||||
const createStore = require({json.dumps(str(STORE))});
|
||||
const records = new Map([
|
||||
['timmy:issue:stackchain%2Fdashboard%3A7', {{id:'a',version:1,ownerLogin:'timmy',scope:'conversation',kind:'issue',repository:'stackchain/dashboard',number:7,updatedAt:100,attachments:[{{filename:'rack.jpg',blob:new Blob(['secret'])}},{{filename:'label.jpg',blob:new Blob(['secret'])}}]}},],
|
||||
['timmy:update:8', {{id:'b',version:1,ownerLogin:'timmy',scope:'conversation',kind:'update',notificationId:8,updatedAt:200,attachments:[{{filename:'alert.jpg',blob:new Blob(['secret'])}}]}},],
|
||||
['alexander:pull:o%2Fr%3A9', {{id:'c',version:1,ownerLogin:'alexander',scope:'conversation',kind:'pull',repository:'o/r',number:9,updatedAt:300,attachments:[{{filename:'private.jpg',blob:new Blob(['private'])}}]}},],
|
||||
['broken', {{id:'broken',version:1,ownerLogin:'timmy',scope:'conversation',kind:'issue',repository:'',number:0,updatedAt:400,attachments:[{{filename:'bad.jpg',blob:new Blob(['bad'])}}]}},],
|
||||
]);
|
||||
const transaction = async (operation, key, value) => {{
|
||||
if (operation === 'list') return Array.from(records.values()).map(value => structuredClone(value));
|
||||
}};
|
||||
const store = createStore({{transaction,getOwnerLogin:()=> 'timmy'}});
|
||||
(async()=>{{
|
||||
const drafts=await store.list();
|
||||
process.stdout.write(JSON.stringify(drafts));
|
||||
}})().catch(error=>{{console.error(error);process.exit(1);}});
|
||||
"""
|
||||
assert json.loads(run_node(script)) == [
|
||||
{
|
||||
"id": "b",
|
||||
"kind": "photo-reply",
|
||||
"label": "Update photos",
|
||||
"title": "Update #8",
|
||||
"photo_count": 1,
|
||||
"updated_at": 200,
|
||||
"route": {"kind": "update", "notification_id": 8},
|
||||
"photo_store": "conversation",
|
||||
},
|
||||
{
|
||||
"id": "a",
|
||||
"kind": "photo-reply",
|
||||
"label": "Issue photos",
|
||||
"repository": "stackchain/dashboard",
|
||||
"number": 7,
|
||||
"title": "stackchain/dashboard#7",
|
||||
"photo_count": 2,
|
||||
"updated_at": 100,
|
||||
"route": {"kind": "issue", "repository": "stackchain/dashboard", "number": 7},
|
||||
"photo_store": "conversation",
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def test_store_isolates_today_progress_photos_from_conversation_photos():
|
||||
script = f"""
|
||||
const createStore = require({json.dumps(str(STORE))});
|
||||
@@ -109,6 +153,24 @@ const target={{kind:'issue',repository:'stackchain/dashboard',number:1054}};
|
||||
}
|
||||
|
||||
|
||||
def test_coordinator_notifies_inventory_after_checkpoint_and_completion():
|
||||
script = f"""
|
||||
const createCoordinator = require({json.dumps(str(COORDINATOR))});
|
||||
const changes=[];
|
||||
let current=[{{filename:'proof.jpg',blob:new Blob(['proof'])}}];
|
||||
const store={{save:async()=>null,load:async()=>null,remove:async()=>null}};
|
||||
const controller={{serialize:async()=>current,restore:()=>{{}},clear:()=>{{current=[];}}}};
|
||||
const drafts=createCoordinator({{store,lanes:{{issue:{{controller}}}},onChange:()=>changes.push('changed')}});
|
||||
(async()=>{{
|
||||
await drafts.open('issue',{{kind:'issue',repository:'o/r',number:7}});
|
||||
await drafts.checkpoint('issue');
|
||||
await drafts.complete('issue');
|
||||
process.stdout.write(JSON.stringify(changes));
|
||||
}})().catch(error=>{{console.error(error);process.exit(1);}});
|
||||
"""
|
||||
assert json.loads(run_node(script)) == ["changed", "changed"]
|
||||
|
||||
|
||||
def test_coordinator_ignores_stale_restores_and_clears_only_after_durable_completion():
|
||||
script = f"""
|
||||
const createCoordinator = require({json.dumps(str(COORDINATOR))});
|
||||
|
||||
@@ -0,0 +1,203 @@
|
||||
import httpx
|
||||
import pytest
|
||||
|
||||
from src import gitea_proxy
|
||||
from src import main
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def clear_pull_creation_operations():
|
||||
main._authored_action_operations.clear()
|
||||
main._idempotency_ledger.clear()
|
||||
yield
|
||||
main._authored_action_operations.clear()
|
||||
main._idempotency_ledger.clear()
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_pull_creation_options_return_visible_repository_branches(monkeypatch):
|
||||
async def access(repository):
|
||||
assert repository == "stackchain/api"
|
||||
return {"full_name": repository, "default_branch": "main", "permissions": {"push": True}}
|
||||
|
||||
async def branches(repository):
|
||||
assert repository == "stackchain/api"
|
||||
return [
|
||||
{"name": "feature/mobile", "commit": {"id": "abc1234"}},
|
||||
{"name": "main", "commit": {"id": "def5678"}},
|
||||
]
|
||||
|
||||
monkeypatch.setattr(main.gitea_proxy, "repository_access", access)
|
||||
monkeypatch.setattr(main.gitea_proxy, "repo_branches", branches, raising=False)
|
||||
|
||||
transport = httpx.ASGITransport(app=main.app)
|
||||
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
|
||||
response = await client.get("/api/v1/repos/stackchain/api/pull-creation-options")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.headers["cache-control"] == "no-store"
|
||||
assert response.json() == {
|
||||
"default_branch": "main",
|
||||
"branches": [
|
||||
{"name": "feature/mobile", "sha": "abc1234"},
|
||||
{"name": "main", "sha": "def5678"},
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_create_pull_endpoint_returns_confirmed_mobile_pull(monkeypatch):
|
||||
calls = []
|
||||
|
||||
async def access(repository):
|
||||
return {"full_name": repository, "permissions": {"push": True}}
|
||||
|
||||
async def create(repository, *, head, base, title, body, draft, expected_head_sha):
|
||||
calls.append((repository, head, base, title, body, draft, expected_head_sha))
|
||||
return {
|
||||
"number": 42,
|
||||
"repository": repository,
|
||||
"title": title,
|
||||
"body": body,
|
||||
"head": {"ref": head, "sha": expected_head_sha},
|
||||
"base": {"ref": base},
|
||||
"draft": draft,
|
||||
"state": "open",
|
||||
"url": "https://forge.example/stackchain/api/pulls/42",
|
||||
"existing": False,
|
||||
}
|
||||
|
||||
monkeypatch.setattr(main.gitea_proxy, "repository_access", access)
|
||||
monkeypatch.setattr(main.gitea_proxy, "create_pull", create, raising=False)
|
||||
|
||||
transport = httpx.ASGITransport(app=main.app)
|
||||
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
|
||||
response = await client.post(
|
||||
"/api/v1/repos/stackchain/api/pulls",
|
||||
headers={"Idempotency-Key": "mobile-create-42"},
|
||||
json={
|
||||
"head": "feature/mobile",
|
||||
"base": "main",
|
||||
"title": " Ship mobile create ",
|
||||
"body": " Context ",
|
||||
"draft": True,
|
||||
"expected_head_sha": "abc1234",
|
||||
},
|
||||
)
|
||||
|
||||
assert response.status_code == 201
|
||||
assert response.headers["cache-control"] == "no-store"
|
||||
assert response.json()["number"] == 42
|
||||
assert calls == [
|
||||
("stackchain/api", "feature/mobile", "main", "Ship mobile create", "Context", True, "abc1234")
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_gitea_create_pull_revalidates_head_and_confirms_created_pull():
|
||||
requests = []
|
||||
|
||||
async def handler(request):
|
||||
requests.append(request)
|
||||
if request.method == "GET" and request.url.path.endswith("/branches/feature/mobile"):
|
||||
return httpx.Response(200, json={"name": "feature/mobile", "commit": {"id": "abc1234"}})
|
||||
if request.method == "GET" and request.url.path.endswith("/pulls"):
|
||||
return httpx.Response(200, json=[])
|
||||
if request.method == "POST" and request.url.path.endswith("/pulls"):
|
||||
return httpx.Response(201, json={
|
||||
"number": 42,
|
||||
"title": "Ship mobile create",
|
||||
"body": "Context",
|
||||
"state": "open",
|
||||
"draft": True,
|
||||
"head": {"ref": "feature/mobile", "sha": "abc1234"},
|
||||
"base": {"ref": "main"},
|
||||
"user": {"login": "timmy"},
|
||||
"html_url": "https://forge.alexanderwhitestone.com/git/stackchain/api/pulls/42",
|
||||
})
|
||||
return httpx.Response(404)
|
||||
|
||||
gitea_proxy.start_client(transport=httpx.MockTransport(handler))
|
||||
try:
|
||||
result = await gitea_proxy.create_pull(
|
||||
"stackchain/api",
|
||||
head="feature/mobile",
|
||||
base="main",
|
||||
title="Ship mobile create",
|
||||
body="Context",
|
||||
draft=True,
|
||||
expected_head_sha="abc1234",
|
||||
)
|
||||
finally:
|
||||
await gitea_proxy.stop_client()
|
||||
|
||||
assert result["number"] == 42
|
||||
assert result["head"] == {"ref": "feature/mobile", "sha": "abc1234"}
|
||||
assert result["author"] == "timmy"
|
||||
assert result["existing"] is False
|
||||
mutation = next(request for request in requests if request.method == "POST")
|
||||
assert mutation.read() == b'{"head":"feature/mobile","base":"main","title":"Ship mobile create","body":"Context","draft":true}'
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_gitea_create_pull_returns_existing_source_base_without_mutation():
|
||||
requests = []
|
||||
existing = {
|
||||
"number": 41,
|
||||
"title": "Already open",
|
||||
"body": "Existing context",
|
||||
"state": "open",
|
||||
"draft": False,
|
||||
"head": {"ref": "feature/mobile", "sha": "abc1234"},
|
||||
"base": {"ref": "main"},
|
||||
"user": {"login": "timmy"},
|
||||
"html_url": "https://forge.alexanderwhitestone.com/git/stackchain/api/pulls/41",
|
||||
}
|
||||
|
||||
async def handler(request):
|
||||
requests.append(request)
|
||||
if "/branches/" in request.url.path:
|
||||
return httpx.Response(200, json={"name": "feature/mobile", "commit": {"id": "abc1234"}})
|
||||
if request.method == "GET" and request.url.path.endswith("/pulls"):
|
||||
return httpx.Response(200, json=[existing])
|
||||
return httpx.Response(500)
|
||||
|
||||
gitea_proxy.start_client(transport=httpx.MockTransport(handler))
|
||||
try:
|
||||
result = await gitea_proxy.create_pull(
|
||||
"stackchain/api", head="feature/mobile", base="main",
|
||||
title="Duplicate attempt", body="", draft=True,
|
||||
expected_head_sha="abc1234",
|
||||
)
|
||||
finally:
|
||||
await gitea_proxy.stop_client()
|
||||
|
||||
assert result["number"] == 41
|
||||
assert result["existing"] is True
|
||||
assert all(request.method != "POST" for request in requests)
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_create_pull_endpoint_reports_stale_source_without_retrying(monkeypatch):
|
||||
async def access(repository):
|
||||
return {"full_name": repository, "permissions": {"push": True}}
|
||||
|
||||
async def stale(*args, **kwargs):
|
||||
raise gitea_proxy.PullCreateConflictError("Source branch changed before pull creation")
|
||||
|
||||
monkeypatch.setattr(main.gitea_proxy, "repository_access", access)
|
||||
monkeypatch.setattr(main.gitea_proxy, "create_pull", stale)
|
||||
transport = httpx.ASGITransport(app=main.app)
|
||||
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
|
||||
response = await client.post(
|
||||
"/api/v1/repos/stackchain/api/pulls",
|
||||
json={
|
||||
"head": "feature/mobile", "base": "main", "title": "Ship it",
|
||||
"expected_head_sha": "abc1234",
|
||||
},
|
||||
)
|
||||
|
||||
assert response.status_code == 409
|
||||
assert response.json() == {
|
||||
"error": "The source branch changed. Refresh branches before creating the pull request."
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
import json
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
ROOT = Path(__file__).parents[1]
|
||||
MODULE = ROOT / "frontend" / "create-pull-sheet.js"
|
||||
|
||||
|
||||
def run_node(scenario: str) -> dict:
|
||||
script = f"""
|
||||
const createPullSheet = require({json.dumps(str(MODULE))});
|
||||
{scenario}
|
||||
"""
|
||||
result = subprocess.run(["node", "-e", script], text=True, capture_output=True, cwd=ROOT)
|
||||
assert result.returncode == 0, result.stderr
|
||||
return json.loads(result.stdout)
|
||||
|
||||
|
||||
def test_create_pull_controller_loads_branches_and_defaults_base():
|
||||
result = run_node("""
|
||||
const calls=[];
|
||||
const controller=createPullSheet.createController({
|
||||
request:async (url) => {
|
||||
calls.push(url);
|
||||
return {default_branch:'main',branches:[
|
||||
{name:'feature/mobile',sha:'abc1234'},
|
||||
{name:'main',sha:'def5678'}
|
||||
]};
|
||||
},
|
||||
storage:{getItem:()=>null,setItem:()=>{}},
|
||||
login:'timmy'
|
||||
});
|
||||
controller.selectRepository('stackchain/api').then(value => {
|
||||
process.stdout.write(JSON.stringify({value,calls,state:controller.state()}));
|
||||
}).catch(error=>{console.error(error);process.exit(1)});
|
||||
""")
|
||||
assert result["calls"] == ["api/v1/repos/stackchain/api/pull-creation-options"]
|
||||
assert result["state"]["base"] == "main"
|
||||
assert result["state"]["head"] == "feature/mobile"
|
||||
assert result["state"]["expected_head_sha"] == "abc1234"
|
||||
|
||||
|
||||
def test_create_pull_controller_submits_idempotently_and_keeps_draft_on_failure():
|
||||
result = run_node("""
|
||||
const calls=[]; const saved=[]; let fail=true;
|
||||
const controller=createPullSheet.createController({
|
||||
request:async (url, options) => {
|
||||
calls.push([url,options]);
|
||||
if (!options) return {default_branch:'main',branches:[{name:'topic',sha:'abc1234'},{name:'main',sha:'def5678'}]};
|
||||
if (fail) { fail=false; throw new Error('offline'); }
|
||||
return {number:9,repository:'acme/app',head:{ref:'topic',sha:'abc1234'},base:{ref:'main'},draft:true};
|
||||
},
|
||||
storage:{getItem:()=>null,setItem:(key,value)=>saved.push([key,JSON.parse(value)])},
|
||||
login:'timmy', createId:()=> 'stable-id'
|
||||
});
|
||||
(async()=>{
|
||||
await controller.selectRepository('acme/app');
|
||||
controller.update({title:'Ship it',body:'Context'});
|
||||
let error=''; try { await controller.submit(); } catch (caught) { error=caught.message; }
|
||||
const retained=controller.state();
|
||||
const confirmed=await controller.submit();
|
||||
process.stdout.write(JSON.stringify({calls,error,retained,confirmed,saved}));
|
||||
})().catch(error=>{console.error(error);process.exit(1)});
|
||||
""")
|
||||
assert result["error"] == "offline"
|
||||
assert result["retained"]["title"] == "Ship it"
|
||||
posts = [call for call in result["calls"] if call[1]]
|
||||
assert len(posts) == 2
|
||||
assert posts[0][1]["headers"]["Idempotency-Key"] == "stable-id"
|
||||
assert posts[1][1]["headers"]["Idempotency-Key"] == "stable-id"
|
||||
assert posts[0][1]["body"]["expected_head_sha"] == "abc1234"
|
||||
assert result["confirmed"]["number"] == 9
|
||||
|
||||
|
||||
def test_create_pull_controller_restores_only_the_current_accounts_draft():
|
||||
result = run_node("""
|
||||
const values={
|
||||
'stackchain.create-pull.v1.timmy':JSON.stringify({repository:'acme/app',head:'topic',base:'main',title:'Saved title',body:'Saved body',draft:false}),
|
||||
'stackchain.create-pull.v1.alexander':JSON.stringify({repository:'private/repo',title:'Other account'})
|
||||
};
|
||||
const controller=createPullSheet.createController({
|
||||
request:async()=>({}), storage:{getItem:key=>values[key] || null,setItem:()=>{}}, login:'Timmy'
|
||||
});
|
||||
process.stdout.write(JSON.stringify(controller.state()));
|
||||
""")
|
||||
assert result == {
|
||||
"repository": "acme/app",
|
||||
"branches": [],
|
||||
"head": "topic",
|
||||
"base": "main",
|
||||
"expected_head_sha": "",
|
||||
"title": "Saved title",
|
||||
"body": "Saved body",
|
||||
"draft": False,
|
||||
}
|
||||
|
||||
|
||||
def test_mobile_pull_creation_sheet_is_packaged_and_touch_safe():
|
||||
html = (ROOT / "frontend" / "index.html").read_text()
|
||||
css = (ROOT / "frontend" / "dashboard.css").read_text()
|
||||
bundle = (ROOT / "src" / "frontend_bundle.py").read_text()
|
||||
|
||||
assert 'id="create-pull-sheet" role="dialog" aria-modal="true"' in html
|
||||
assert 'id="create-pull-form"' in html
|
||||
assert 'id="create-pull-repository"' in html
|
||||
assert 'id="create-pull-head"' in html
|
||||
assert 'id="create-pull-base"' in html
|
||||
assert 'id="submit-create-pull"' in html
|
||||
assert 'static/create-pull-sheet.js' in bundle
|
||||
assert ".create-pull-panel button" in css
|
||||
assert "min-height:44px" in css.replace(" ", "")
|
||||
|
||||
|
||||
def test_create_pull_binding_renders_branch_receipt_and_created_pull():
|
||||
result = run_node("""
|
||||
const rendered=[]; const statuses=[]; const opened=[];
|
||||
const controller={
|
||||
selectRepository:async repository=>({repository,branches:[{name:'topic',sha:'abc1234'},{name:'main',sha:'def5678'}],head:'topic',base:'main',expected_head_sha:'abc1234'}),
|
||||
update:values=>values,
|
||||
submit:async()=>({number:12,repository:'acme/app',existing:false})
|
||||
};
|
||||
const binding=createPullSheet.createBinding({controller,
|
||||
render:state=>rendered.push(state), status:value=>statuses.push(value),
|
||||
onCreated:value=>opened.push(value)
|
||||
});
|
||||
(async()=>{
|
||||
await binding.repositoryChanged('acme/app');
|
||||
await binding.submit();
|
||||
process.stdout.write(JSON.stringify({rendered,statuses,opened}));
|
||||
})().catch(error=>{console.error(error);process.exit(1)});
|
||||
""")
|
||||
assert result["rendered"][0]["expected_head_sha"] == "abc1234"
|
||||
assert result["statuses"][-1] == "Pull request #12 created."
|
||||
assert result["opened"][0]["number"] == 12
|
||||
|
||||
|
||||
def test_dashboard_wires_create_pull_inside_lazy_issue_capture_chunk():
|
||||
dashboard = (ROOT / "frontend" / "dashboard.js").read_text()
|
||||
module = MODULE.read_text()
|
||||
assert "cp.b();" not in dashboard
|
||||
assert "else cp.b();" in module
|
||||
@@ -2,6 +2,7 @@ import asyncio
|
||||
import sqlite3
|
||||
import threading
|
||||
import time
|
||||
from typing import get_args
|
||||
from urllib.parse import parse_qs, urlsplit
|
||||
|
||||
import httpx
|
||||
@@ -9,10 +10,14 @@ import pytest
|
||||
from fastapi import Request
|
||||
|
||||
from src import main
|
||||
from src.session_store import SessionStoreError
|
||||
from src.session_store import SessionStatus, SessionStoreError
|
||||
from src.views import FRONTEND_BUILD
|
||||
|
||||
|
||||
def test_release_rollback_is_a_supported_step_up_action():
|
||||
assert "prepare_release_rollback" in get_args(main.StepUpAction)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def access_control(monkeypatch, tmp_path):
|
||||
monkeypatch.setenv("STACKCHAIN_DASHBOARD_AUTH_MODE", "operator")
|
||||
@@ -24,6 +29,83 @@ def access_control(monkeypatch, tmp_path):
|
||||
monkeypatch.setenv("STACKCHAIN_LOGIN_ATTEMPT_DB", str(tmp_path / "login-attempts.sqlite3"))
|
||||
monkeypatch.setenv("STACKCHAIN_LOGIN_MAX_FAILURES", "3")
|
||||
monkeypatch.setenv("STACKCHAIN_LOGIN_WINDOW_SECONDS", "60")
|
||||
async def upstream_user():
|
||||
return {"id": 42, "login": "timmy"}
|
||||
|
||||
monkeypatch.setattr(main, "current_user", upstream_user)
|
||||
|
||||
|
||||
def test_signed_session_carries_bound_upstream_identity(access_control):
|
||||
signed, _ = main.dashboard_auth.issue_session(
|
||||
now=1_000,
|
||||
principal_id=42,
|
||||
principal_login="timmy",
|
||||
)
|
||||
|
||||
verification = main.dashboard_auth.verify_session_with_reason(signed, now=1_001)
|
||||
|
||||
assert verification.session is not None
|
||||
assert verification.session.principal_id == 42
|
||||
assert verification.session.principal_login == "timmy"
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_session_is_blocked_when_upstream_account_changes(
|
||||
access_control, monkeypatch
|
||||
):
|
||||
identity = {"id": 42, "login": "timmy"}
|
||||
|
||||
async def upstream_user():
|
||||
return dict(identity)
|
||||
|
||||
monkeypatch.setattr(main, "current_user", upstream_user)
|
||||
transport = httpx.ASGITransport(app=main.app)
|
||||
async with httpx.AsyncClient(transport=transport, base_url="https://test") as client:
|
||||
signed_in = await client.post(
|
||||
"/api/v1/session",
|
||||
json={"access_token": "correct horse battery staple"},
|
||||
)
|
||||
identity.update(login="renamed-timmy")
|
||||
same_principal = await client.get("/api/v1/security-events")
|
||||
identity.update(id=84, login="other-operator")
|
||||
protected = await client.get("/api/v1/security-events")
|
||||
|
||||
assert signed_in.status_code == 200
|
||||
assert same_principal.status_code == 200
|
||||
assert protected.status_code == 401
|
||||
assert protected.json() == {
|
||||
"detail": "Connected Gitea account changed; sign in again",
|
||||
"code": "session_idle",
|
||||
"reason": "upstream_identity_changed",
|
||||
"previous_login": "timmy",
|
||||
"current_login": "other-operator",
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_session_identity_lookup_outage_is_retryable(access_control, monkeypatch):
|
||||
available = True
|
||||
|
||||
async def upstream_user():
|
||||
if not available:
|
||||
raise RuntimeError("credential lookup details")
|
||||
return {"id": 42, "login": "timmy"}
|
||||
|
||||
monkeypatch.setattr(main, "current_user", upstream_user)
|
||||
transport = httpx.ASGITransport(app=main.app)
|
||||
async with httpx.AsyncClient(transport=transport, base_url="https://test") as client:
|
||||
signed_in = await client.post(
|
||||
"/api/v1/session",
|
||||
json={"access_token": "correct horse battery staple"},
|
||||
)
|
||||
available = False
|
||||
protected = await client.get("/api/v1/security-events")
|
||||
|
||||
assert signed_in.status_code == 200
|
||||
assert protected.status_code == 503
|
||||
assert protected.json() == {"detail": "Gitea identity is temporarily unavailable"}
|
||||
assert protected.headers["retry-after"] == "5"
|
||||
assert "credential lookup" not in protected.text
|
||||
|
||||
|
||||
async def fresh_grant(client, action: str, target: str) -> str:
|
||||
@@ -43,6 +125,84 @@ async def fresh_grant(client, action: str, target: str) -> str:
|
||||
return response.json()["grant"]
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_source_branch_deletion_accepts_exact_one_time_fresh_authorization(
|
||||
access_control, monkeypatch
|
||||
):
|
||||
lifecycle = []
|
||||
|
||||
class Journal:
|
||||
def record(self, *_args, **_kwargs):
|
||||
pass
|
||||
|
||||
def reserve(self, kind, *, target):
|
||||
lifecycle.append(("reserve", kind, target))
|
||||
return "cleanup-operation"
|
||||
|
||||
def finalize(self, operation_id):
|
||||
lifecycle.append(("finalize", operation_id))
|
||||
|
||||
def discard(self, operation_id):
|
||||
lifecycle.append(("discard", operation_id))
|
||||
|
||||
async def cleanup(repository, number, source_branch, expected_head_sha):
|
||||
lifecycle.append(
|
||||
("delete", repository, number, source_branch, expected_head_sha)
|
||||
)
|
||||
return {"number": number, "deleted": True}
|
||||
|
||||
monkeypatch.setattr(main, "_security_event_store", lambda: Journal())
|
||||
monkeypatch.setattr(main.gitea_proxy, "delete_merged_source_branch", cleanup)
|
||||
transport = httpx.ASGITransport(app=main.app)
|
||||
async with httpx.AsyncClient(transport=transport, base_url="https://test") as client:
|
||||
signed_in = await client.post(
|
||||
"/api/v1/session",
|
||||
json={"access_token": "correct horse battery staple", "device_label": "Phone"},
|
||||
)
|
||||
assert signed_in.status_code == 200
|
||||
headers = {
|
||||
"Origin": "https://test",
|
||||
"X-CSRF-Token": client.cookies["stackchain_csrf"],
|
||||
}
|
||||
request = {
|
||||
"source_branch": "timmy/feature",
|
||||
"expected_head_sha": "abc1234",
|
||||
}
|
||||
path = "/api/v1/repos/stackchain/api/pulls/7/source-branch"
|
||||
|
||||
challenged = await client.request("DELETE", path, json=request, headers=headers)
|
||||
grant = await fresh_grant(
|
||||
client, "delete_source_branch", "stackchain/api#7@abc1234"
|
||||
)
|
||||
deleted = await client.request(
|
||||
"DELETE",
|
||||
path,
|
||||
json=request,
|
||||
headers={**headers, "X-Step-Up-Grant": grant},
|
||||
)
|
||||
replayed = await client.request(
|
||||
"DELETE",
|
||||
path,
|
||||
json=request,
|
||||
headers={**headers, "X-Step-Up-Grant": grant},
|
||||
)
|
||||
|
||||
assert challenged.status_code == 428
|
||||
assert challenged.json()["detail"] == {
|
||||
"detail": "Fresh authorization required",
|
||||
"code": "step_up_required",
|
||||
"action": "delete_source_branch",
|
||||
"target": "stackchain/api#7@abc1234",
|
||||
}
|
||||
assert deleted.status_code == 200
|
||||
assert replayed.status_code == 428
|
||||
assert lifecycle == [
|
||||
("reserve", "source_branch_deleted", "stackchain/api#7@abc1234"),
|
||||
("delete", "stackchain/api", 7, "timmy/feature", "abc1234"),
|
||||
("finalize", "cleanup-operation"),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_passkey_enrollment_options_require_fresh_authorization_and_are_one_time(
|
||||
access_control,
|
||||
@@ -1821,7 +1981,7 @@ async def test_logout_revokes_a_captured_cookie_before_gitea(access_control, mon
|
||||
assert before.status_code == 200
|
||||
assert after.status_code == 401
|
||||
assert after.headers["cache-control"] == "no-store"
|
||||
assert calls == 1
|
||||
assert calls == 4
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
@@ -1835,7 +1995,9 @@ async def test_session_registry_latency_does_not_block_the_event_loop(access_con
|
||||
class SlowStore:
|
||||
def status(self, session_id, expires_at, *, idle_timeout_seconds):
|
||||
time.sleep(0.15)
|
||||
return "active"
|
||||
return SessionStatus(
|
||||
"active", principal_id=42, principal_login="timmy"
|
||||
)
|
||||
|
||||
monkeypatch.setattr(main.dashboard_auth, "_session_store", lambda now=None: SlowStore())
|
||||
private_request = asyncio.create_task(client.get("/api/v1/session"))
|
||||
@@ -2001,7 +2163,9 @@ async def test_single_session_revocation_does_not_block_the_event_loop(
|
||||
class SlowStore:
|
||||
def status(self, session_id, expires_at, *, idle_timeout_seconds):
|
||||
time.sleep(0.02)
|
||||
return "active"
|
||||
return SessionStatus(
|
||||
"active", principal_id=42, principal_login="timmy"
|
||||
)
|
||||
|
||||
def revoke(self, session_id):
|
||||
time.sleep(0.15)
|
||||
@@ -2043,6 +2207,7 @@ async def test_session_registry_read_failure_fails_closed_before_gitea(
|
||||
await client.post(
|
||||
"/api/v1/session", json={"access_token": "correct horse battery staple"}
|
||||
)
|
||||
called = False
|
||||
|
||||
class BrokenStore:
|
||||
def status(self, session_id, expires_at, *, idle_timeout_seconds):
|
||||
@@ -2091,7 +2256,9 @@ async def test_logout_registry_failure_does_not_claim_revocation(access_control,
|
||||
|
||||
class BrokenStore:
|
||||
def status(self, session_id, expires_at, *, idle_timeout_seconds):
|
||||
return "active"
|
||||
return SessionStatus(
|
||||
"active", principal_id=42, principal_login="timmy"
|
||||
)
|
||||
|
||||
def revoke(self, session_id):
|
||||
raise SessionStoreError("database path and secret details")
|
||||
|
||||
@@ -558,6 +558,28 @@ process.stdout.write(JSON.stringify(state));
|
||||
assert result["replacedAfterDeletion"] is True
|
||||
|
||||
|
||||
def test_upstream_identity_change_preserves_private_work_and_requires_sign_in():
|
||||
result = run_session_scenario(
|
||||
"""
|
||||
state.responseStatus = 401;
|
||||
state.responsePayload = {
|
||||
detail:'Connected Gitea account changed; sign in again',
|
||||
code:'session_idle', reason:'upstream_identity_changed',
|
||||
previous_login:'timmy', current_login:'other-operator',
|
||||
};
|
||||
await boundary.fetch('/dashboard/api/v1/live');
|
||||
state.remaining = Array.from(storage.values.keys());
|
||||
process.stdout.write(JSON.stringify(state));
|
||||
"""
|
||||
)
|
||||
|
||||
assert result["remaining"] == ["stackchain.private", "gitea.preference"]
|
||||
assert result["deletedDatabases"] == []
|
||||
assert result["deletedCaches"] == []
|
||||
assert result["workerMessages"] == []
|
||||
assert result["replaced"] == ["/dashboard/login?reason=session-idle"]
|
||||
|
||||
|
||||
def test_idle_response_locks_without_clearing_private_queued_work():
|
||||
result = run_session_scenario(
|
||||
"""
|
||||
|
||||
@@ -130,7 +130,8 @@ def test_detail_watch_is_wired_into_both_mobile_work_details_and_bundle():
|
||||
assert 'pullDetailWatch.open(item)' in dashboard
|
||||
assert '#watch-issue-detail' in css
|
||||
assert '#watch-pull-detail' in css
|
||||
assert 'tests/e2e/test_mobile_detail_watch_release.py' in workflow
|
||||
assert "python3 -m pytest tests/e2e -q" in workflow
|
||||
assert (ROOT / "tests/e2e/test_mobile_detail_watch_release.py").is_file()
|
||||
|
||||
|
||||
def test_detail_watch_ignores_a_late_subscription_response_for_the_previous_item():
|
||||
|
||||
@@ -593,7 +593,7 @@ process.stdout.write(JSON.stringify({{
|
||||
assert ".following-disposition-mode" in css
|
||||
assert "if (searchPreviewReturnKind === 'following')" in dashboard
|
||||
assert "e.key === 'Escape' && searchPreviewReturnKind === 'following'" in dashboard
|
||||
assert "stackchain-dashboard-shell-v138" in service_worker
|
||||
assert "stackchain-dashboard-shell-v146" in service_worker
|
||||
|
||||
|
||||
def test_prepare_today_lazily_refreshes_and_directly_reviews_following():
|
||||
|
||||
@@ -50,7 +50,7 @@ def test_product_workflows_are_stable_lazy_feature_chunks(tmp_path):
|
||||
|
||||
assert set(first.feature_bundles) == {
|
||||
"comment-actions", "issue-capture", "pull-workflow", "push-notifications", "sign-out", "device-setup",
|
||||
"today-timer", "security-center", "planning",
|
||||
"work-core", "today-timer", "security-center", "planning",
|
||||
}
|
||||
assert first.dashboard_html.count("<script src=") == 1
|
||||
assert f'<script src="{first.runtime_name}"></script>' in first.dashboard_html
|
||||
@@ -95,7 +95,6 @@ def test_product_workflows_are_stable_lazy_feature_chunks(tmp_path):
|
||||
assert f"BASE + '{pull_workflow.runtime_name}'" in first.service_worker_source
|
||||
assert f'name="stackchain-feature-security-center" content="{security_center.runtime_name}"' in first.dashboard_html
|
||||
assert f"BASE + '{security_center.runtime_name}'" in first.service_worker_source
|
||||
|
||||
shell_block, optional_block = first.service_worker_source.split(
|
||||
"const OPTIONAL_FEATURES = [", 1
|
||||
)
|
||||
@@ -127,14 +126,33 @@ def test_product_workflows_are_stable_lazy_feature_chunks(tmp_path):
|
||||
assert security_changed.feature_bundles["security-center"].runtime_name != security_center.runtime_name
|
||||
|
||||
|
||||
def test_my_work_has_a_small_blocking_bundle_before_optional_workspace_hydration():
|
||||
build = build_frontend(FRONTEND)
|
||||
work_core = build.feature_bundles["work-core"]
|
||||
today = build.feature_bundles["today-timer"]
|
||||
|
||||
assert b"function buildMyWork" in work_core.runtime_bytes
|
||||
assert b"function createProgressiveMyWork" in work_core.runtime_bytes
|
||||
assert b"function createProgressiveCapture" in work_core.runtime_bytes
|
||||
assert b"function createUnfiledCaptures" in work_core.runtime_bytes
|
||||
assert b"function buildMyWork" not in today.runtime_bytes
|
||||
assert b"function createProgressiveCapture" not in today.runtime_bytes
|
||||
assert b"function createUnfiledCaptures" not in today.runtime_bytes
|
||||
assert b"loadWorkspace({document,window})" in build.runtime_bytes
|
||||
assert b"const workspaceLifecycle" not in build.runtime_bytes
|
||||
assert b"const workspaceLifecycle" in today.runtime_bytes
|
||||
assert SCRIPT_PRELOAD.findall(build.dashboard_html) == [work_core.runtime_name]
|
||||
assert len(build.runtime_gzip_bytes) + len(work_core.runtime_gzip_bytes) <= 150 * 1024
|
||||
|
||||
|
||||
def test_mandatory_workspace_fetch_is_preloaded_without_blocking_launch():
|
||||
build = build_frontend(FRONTEND)
|
||||
workspace = build.feature_bundles["today-timer"]
|
||||
workspace = build.feature_bundles["work-core"]
|
||||
|
||||
assert SCRIPT_PRELOAD.findall(build.dashboard_html) == [workspace.runtime_name]
|
||||
assert build.dashboard_html.count(f'<script src="{workspace.runtime_name}"></script>') == 0
|
||||
assert len(build.runtime_gzip_bytes) <= 100 * 1024
|
||||
assert len(workspace.runtime_gzip_bytes) <= 111 * 1024
|
||||
assert len(build.runtime_gzip_bytes) + len(workspace.runtime_gzip_bytes) <= 150 * 1024
|
||||
|
||||
shell_block = build.service_worker_source.split("const OPTIONAL_FEATURES = [", 1)[0]
|
||||
assert f"BASE + '{workspace.runtime_name}'" not in shell_block
|
||||
|
||||
@@ -875,6 +875,108 @@ async def test_work_preview_marks_authoritative_requested_pull_review_actionable
|
||||
assert "/api/v1/repos/stackchain/web/pulls/9" in requested_paths
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_work_preview_offers_closed_authored_unmerged_pull_recovery_with_head_guard():
|
||||
requested_paths = []
|
||||
|
||||
async def handler(request):
|
||||
requested_paths.append(request.url.path)
|
||||
if request.url.path.endswith("/user"):
|
||||
return httpx.Response(200, json={"login": "timmy"})
|
||||
if request.url.path.endswith("/pulls/9"):
|
||||
return httpx.Response(200, json={
|
||||
"number": 9,
|
||||
"state": "closed",
|
||||
"merged": False,
|
||||
"user": {"login": "timmy"},
|
||||
"head": {"sha": "abc1234"},
|
||||
"requested_reviewers": [],
|
||||
})
|
||||
return httpx.Response(200, json={
|
||||
"number": 9,
|
||||
"title": "Recover mobile flow",
|
||||
"state": "closed",
|
||||
"html_url": "http://127.0.0.1:3000/stackchain/web/pulls/9",
|
||||
"user": {"login": "timmy"},
|
||||
"pull_request": {"merged": False},
|
||||
"assignees": [],
|
||||
})
|
||||
|
||||
gitea_proxy.start_client(transport=httpx.MockTransport(handler))
|
||||
try:
|
||||
preview = await gitea_proxy.work_preview("stackchain/web", "pull", 9)
|
||||
finally:
|
||||
await gitea_proxy.stop_client()
|
||||
|
||||
assert preview["authored_pull_reopenable"] is True
|
||||
assert preview["head_sha"] == "abc1234"
|
||||
assert "/api/v1/repos/stackchain/web/pulls/9" in requested_paths
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_work_preview_does_not_offer_closed_pull_recovery_to_non_author():
|
||||
async def handler(request):
|
||||
if request.url.path.endswith("/user"):
|
||||
return httpx.Response(200, json={"login": "timmy"})
|
||||
if request.url.path.endswith("/pulls/9"):
|
||||
return httpx.Response(200, json={
|
||||
"number": 9,
|
||||
"state": "closed",
|
||||
"merged": False,
|
||||
"user": {"login": "alexander"},
|
||||
"head": {"sha": "abc1234"},
|
||||
})
|
||||
return httpx.Response(200, json={
|
||||
"number": 9,
|
||||
"title": "Foreign pull",
|
||||
"state": "closed",
|
||||
"html_url": "http://127.0.0.1:3000/stackchain/web/pulls/9",
|
||||
"user": {"login": "alexander"},
|
||||
"pull_request": {"merged": False},
|
||||
"assignees": [],
|
||||
})
|
||||
|
||||
gitea_proxy.start_client(transport=httpx.MockTransport(handler))
|
||||
try:
|
||||
preview = await gitea_proxy.work_preview("stackchain/web", "pull", 9)
|
||||
finally:
|
||||
await gitea_proxy.stop_client()
|
||||
|
||||
assert preview["authored_pull_reopenable"] is False
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_work_preview_does_not_offer_recovery_for_merged_pull():
|
||||
async def handler(request):
|
||||
if request.url.path.endswith("/user"):
|
||||
return httpx.Response(200, json={"login": "timmy"})
|
||||
if request.url.path.endswith("/pulls/9"):
|
||||
return httpx.Response(200, json={
|
||||
"number": 9,
|
||||
"state": "closed",
|
||||
"merged": True,
|
||||
"user": {"login": "timmy"},
|
||||
"head": {"sha": "abc1234"},
|
||||
})
|
||||
return httpx.Response(200, json={
|
||||
"number": 9,
|
||||
"title": "Merged pull",
|
||||
"state": "closed",
|
||||
"html_url": "http://127.0.0.1:3000/stackchain/web/pulls/9",
|
||||
"user": {"login": "timmy"},
|
||||
"pull_request": {"merged": True},
|
||||
"assignees": [],
|
||||
})
|
||||
|
||||
gitea_proxy.start_client(transport=httpx.MockTransport(handler))
|
||||
try:
|
||||
preview = await gitea_proxy.work_preview("stackchain/web", "pull", 9)
|
||||
finally:
|
||||
await gitea_proxy.stop_client()
|
||||
|
||||
assert preview["authored_pull_reopenable"] is False
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_work_preview_offers_reopen_only_for_closed_issues():
|
||||
async def handler(request):
|
||||
|
||||
@@ -0,0 +1,280 @@
|
||||
import sqlite3
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
|
||||
from src import main
|
||||
from src.human_gate_store import HumanGateStore
|
||||
from src.security_event_store import SecurityEventStore, SecurityEventStoreError
|
||||
|
||||
|
||||
CANDIDATE = {
|
||||
"source": "release-bot", "project": "stackchain/dashboard", "candidate_hash": "abc123",
|
||||
"title": "Release candidate", "priority": 7,
|
||||
"artifacts": [{"name": "manifest", "url": "https://forge.example/manifest"}],
|
||||
"links": [{"label": "pull", "url": "https://forge.example/pulls/1"}],
|
||||
"checks": [{"name": "unit", "state": "success", "required": True}],
|
||||
"score": {"value": 98, "provenance": "eval/v1"},
|
||||
"provenance": {"run": "9"},
|
||||
}
|
||||
CHECKLIST = {"exact_hash": True, "artifacts_reviewed": True, "provenance_reviewed": True}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def gate_api(monkeypatch, tmp_path):
|
||||
ticks = iter(range(100, 120))
|
||||
store = HumanGateStore(tmp_path / "gates.sqlite3", clock=lambda: next(ticks))
|
||||
monkeypatch.setattr(main, "_human_gate_store", lambda: store, raising=False)
|
||||
|
||||
async def identity():
|
||||
return {"id": 1, "login": "timmy"}
|
||||
|
||||
monkeypatch.setattr(main, "current_user", identity)
|
||||
return store
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_intake_list_and_detail_are_account_bound_and_no_store(gate_api):
|
||||
transport = httpx.ASGITransport(app=main.app)
|
||||
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
|
||||
created = await client.post("/api/v1/human-gates/intake", json=CANDIDATE, headers={"Idempotency-Key": "run-9"})
|
||||
repeated = await client.post("/api/v1/human-gates/intake", json=CANDIDATE, headers={"Idempotency-Key": "run-9"})
|
||||
listing = await client.get("/api/v1/human-gates")
|
||||
detail = await client.get(f"/api/v1/human-gates/{created.json()['id']}")
|
||||
|
||||
assert created.status_code == 201
|
||||
assert repeated.status_code == 200
|
||||
assert repeated.json()["id"] == created.json()["id"]
|
||||
assert listing.json()["pending_count"] == 1
|
||||
assert detail.json()["candidate_hash"] == "abc123"
|
||||
assert detail.json()["history"][0]["action"] == "intake"
|
||||
assert all(response.headers["cache-control"] == "no-store" for response in (created, repeated, listing, detail))
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_decision_requires_revision_and_returns_durable_receipt(gate_api):
|
||||
gate = gate_api.intake("1:timmy", CANDIDATE, idempotency_key="run-9")
|
||||
transport = httpx.ASGITransport(app=main.app)
|
||||
payload = {"expected_revision": gate["revision"], "decision": "release", "reason": "", "override_reason": "", "checklist": CHECKLIST}
|
||||
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
|
||||
decided = await client.post(f"/api/v1/human-gates/{gate['id']}/decision", json=payload, headers={"Idempotency-Key": "decision-9"})
|
||||
repeated = await client.post(f"/api/v1/human-gates/{gate['id']}/decision", json=payload, headers={"Idempotency-Key": "decision-9"})
|
||||
receipt = await client.get(f"/api/v1/human-gate-receipts/{decided.json()['receipt_id']}")
|
||||
stale = await client.post(f"/api/v1/human-gates/{gate['id']}/decision", json=payload, headers={"Idempotency-Key": "decision-10"})
|
||||
|
||||
assert decided.status_code == 201
|
||||
assert repeated.status_code == 200
|
||||
assert receipt.json() == decided.json()
|
||||
assert stale.status_code == 409
|
||||
assert all(response.headers["cache-control"] == "no-store" for response in (decided, repeated, receipt, stale))
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_decision_requires_fresh_authorization_bound_to_the_exact_gate(monkeypatch, gate_api):
|
||||
gate = gate_api.intake("1:timmy", CANDIDATE, idempotency_key="run-authorized")
|
||||
authorization_calls = []
|
||||
|
||||
async def require_step_up(request, grant, *, action, target):
|
||||
authorization_calls.append({"grant": grant, "action": action, "target": target})
|
||||
if grant != "one-time-grant":
|
||||
raise main.HTTPException(
|
||||
status_code=428,
|
||||
detail={
|
||||
"detail": "Fresh authorization required",
|
||||
"code": "step_up_required",
|
||||
"action": action,
|
||||
"target": target,
|
||||
},
|
||||
)
|
||||
|
||||
monkeypatch.setattr(main, "_require_step_up", require_step_up)
|
||||
payload = {
|
||||
"expected_revision": gate["revision"],
|
||||
"decision": "hold",
|
||||
"reason": "Needs another browser run",
|
||||
"override_reason": "",
|
||||
"checklist": CHECKLIST,
|
||||
}
|
||||
transport = httpx.ASGITransport(app=main.app)
|
||||
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
|
||||
rejected = await client.post(
|
||||
f"/api/v1/human-gates/{gate['id']}/decision",
|
||||
json=payload,
|
||||
headers={"Idempotency-Key": "decision-authorized"},
|
||||
)
|
||||
pending = await client.get(f"/api/v1/human-gates/{gate['id']}")
|
||||
accepted = await client.post(
|
||||
f"/api/v1/human-gates/{gate['id']}/decision",
|
||||
json=payload,
|
||||
headers={
|
||||
"Idempotency-Key": "decision-authorized",
|
||||
"X-Step-Up-Grant": "one-time-grant",
|
||||
},
|
||||
)
|
||||
|
||||
assert rejected.status_code == 428
|
||||
assert pending.json()["state"] == "pending"
|
||||
assert accepted.status_code == 201
|
||||
assert authorization_calls == [
|
||||
{"grant": None, "action": "decide_human_gate", "target": gate["id"]},
|
||||
{"grant": "one-time-grant", "action": "decide_human_gate", "target": gate["id"]},
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_successful_decision_records_one_completed_privacy_safe_security_event(
|
||||
monkeypatch, gate_api, tmp_path
|
||||
):
|
||||
gate = gate_api.intake("1:timmy", CANDIDATE, idempotency_key="run-audited")
|
||||
journal_path = tmp_path / "security.sqlite3"
|
||||
journal = SecurityEventStore(journal_path, clock=lambda: 200)
|
||||
monkeypatch.setattr(main, "_security_event_store", lambda: journal)
|
||||
private_reason = "Private launch context must not enter the security journal"
|
||||
payload = {
|
||||
"expected_revision": gate["revision"],
|
||||
"decision": "hold",
|
||||
"reason": private_reason,
|
||||
"override_reason": "",
|
||||
"checklist": CHECKLIST,
|
||||
}
|
||||
transport = httpx.ASGITransport(app=main.app)
|
||||
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
|
||||
decided = await client.post(
|
||||
f"/api/v1/human-gates/{gate['id']}/decision",
|
||||
json=payload,
|
||||
headers={"Idempotency-Key": "decision-audited"},
|
||||
)
|
||||
|
||||
events = journal.list().events
|
||||
assert decided.status_code == 201
|
||||
assert [
|
||||
{"kind": event.kind, "method": event.method, "target": event.target, "status": event.status}
|
||||
for event in events
|
||||
] == [
|
||||
{
|
||||
"kind": "human_gate_decision",
|
||||
"method": "hold",
|
||||
"target": gate["id"],
|
||||
"status": "completed",
|
||||
}
|
||||
]
|
||||
assert private_reason.encode() not in journal_path.read_bytes()
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_decision_fails_closed_when_security_event_cannot_be_reserved(
|
||||
monkeypatch, gate_api
|
||||
):
|
||||
gate = gate_api.intake("1:timmy", CANDIDATE, idempotency_key="run-no-journal")
|
||||
|
||||
class UnavailableJournal:
|
||||
def reserve(self, *args, **kwargs):
|
||||
raise SecurityEventStoreError("private journal path")
|
||||
|
||||
monkeypatch.setattr(main, "_security_event_store", UnavailableJournal)
|
||||
payload = {
|
||||
"expected_revision": gate["revision"],
|
||||
"decision": "release",
|
||||
"reason": "",
|
||||
"override_reason": "",
|
||||
"checklist": CHECKLIST,
|
||||
}
|
||||
transport = httpx.ASGITransport(app=main.app)
|
||||
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
|
||||
rejected = await client.post(
|
||||
f"/api/v1/human-gates/{gate['id']}/decision",
|
||||
json=payload,
|
||||
headers={"Idempotency-Key": "decision-no-journal"},
|
||||
)
|
||||
pending = await client.get(f"/api/v1/human-gates/{gate['id']}")
|
||||
|
||||
assert rejected.status_code == 503
|
||||
assert rejected.json() == {"detail": "Security activity is temporarily unavailable"}
|
||||
assert pending.json()["state"] == "pending"
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_rejected_decision_discards_its_pending_security_event(
|
||||
monkeypatch, gate_api, tmp_path
|
||||
):
|
||||
gate = gate_api.intake("1:timmy", CANDIDATE, idempotency_key="run-conflict")
|
||||
journal = SecurityEventStore(tmp_path / "security.sqlite3", clock=lambda: 200)
|
||||
monkeypatch.setattr(main, "_security_event_store", lambda: journal)
|
||||
payload = {
|
||||
"expected_revision": gate["revision"] + 1,
|
||||
"decision": "hold",
|
||||
"reason": "Outdated review",
|
||||
"override_reason": "",
|
||||
"checklist": CHECKLIST,
|
||||
}
|
||||
transport = httpx.ASGITransport(app=main.app)
|
||||
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
|
||||
rejected = await client.post(
|
||||
f"/api/v1/human-gates/{gate['id']}/decision",
|
||||
json=payload,
|
||||
headers={"Idempotency-Key": "decision-conflict"},
|
||||
)
|
||||
|
||||
assert rejected.status_code == 409
|
||||
assert journal.list().events == []
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_recycled_login_cannot_read_another_principal_gates(monkeypatch, tmp_path):
|
||||
store = HumanGateStore(tmp_path / "gates.sqlite3", clock=lambda: 100)
|
||||
monkeypatch.setattr(main, "_human_gate_store", lambda: store, raising=False)
|
||||
principal = {"id": 1, "login": "timmy"}
|
||||
|
||||
async def identity():
|
||||
return principal.copy()
|
||||
|
||||
monkeypatch.setattr(main, "current_user", identity)
|
||||
transport = httpx.ASGITransport(app=main.app)
|
||||
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
|
||||
created = await client.post(
|
||||
"/api/v1/human-gates/intake", json=CANDIDATE,
|
||||
headers={"Idempotency-Key": "principal-1"},
|
||||
)
|
||||
principal["id"] = 2
|
||||
listing = await client.get("/api/v1/human-gates")
|
||||
|
||||
assert created.status_code == 201
|
||||
assert listing.json()["pending_count"] == 0
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_gate_store_failure_is_sanitized_no_store(monkeypatch):
|
||||
def unavailable():
|
||||
raise sqlite3.OperationalError("sensitive database path")
|
||||
|
||||
monkeypatch.setattr(main, "_human_gate_store", unavailable)
|
||||
|
||||
async def identity():
|
||||
return {"id": 1, "login": "timmy"}
|
||||
|
||||
monkeypatch.setattr(main, "current_user", identity)
|
||||
transport = httpx.ASGITransport(app=main.app)
|
||||
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
|
||||
response = await client.get("/api/v1/human-gates")
|
||||
|
||||
assert response.status_code == 503
|
||||
assert response.headers["cache-control"] == "no-store"
|
||||
assert response.json() == {"detail": "Human Gates are temporarily unavailable"}
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_gate_mutations_require_idempotency_key_and_validate_override(gate_api):
|
||||
failing = {**CANDIDATE, "candidate_hash": "fail123", "checks": [{"name": "browser", "state": "failure", "required": True}]}
|
||||
gate = gate_api.intake("1:timmy", failing, idempotency_key="run-fail")
|
||||
transport = httpx.ASGITransport(app=main.app)
|
||||
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
|
||||
missing_key = await client.post("/api/v1/human-gates/intake", json=CANDIDATE)
|
||||
no_override = await client.post(
|
||||
f"/api/v1/human-gates/{gate['id']}/decision",
|
||||
json={"expected_revision": 1, "decision": "release", "reason": "", "override_reason": "", "checklist": CHECKLIST},
|
||||
headers={"Idempotency-Key": "decision-fail"},
|
||||
)
|
||||
|
||||
assert missing_key.status_code == 422
|
||||
assert no_override.status_code == 422
|
||||
assert "override reason" in no_override.json()["detail"]
|
||||
@@ -0,0 +1,142 @@
|
||||
import sqlite3
|
||||
|
||||
import pytest
|
||||
|
||||
from src.human_gate_store import GateConflict, GateValidationError, HumanGateStore
|
||||
|
||||
|
||||
def candidate(hash_value="abc123", *, priority=2, check_state="success"):
|
||||
return {
|
||||
"source": "release-bot",
|
||||
"project": "stackchain/dashboard",
|
||||
"candidate_hash": hash_value,
|
||||
"title": "Dashboard candidate",
|
||||
"priority": priority,
|
||||
"artifacts": [{"name": "manifest", "url": "https://forge.example/artifacts/manifest.json"}],
|
||||
"links": [{"label": "change", "url": "https://forge.example/pulls/1415"}],
|
||||
"checks": [{"name": "browser", "state": check_state, "required": True}],
|
||||
"score": {"value": 92, "provenance": "release-evaluator/v2"},
|
||||
"provenance": {"producer": "release-bot", "run_id": "run-9"},
|
||||
}
|
||||
|
||||
|
||||
def checklist():
|
||||
return {"exact_hash": True, "artifacts_reviewed": True, "provenance_reviewed": True}
|
||||
|
||||
|
||||
def test_intake_is_account_bound_idempotent_and_survives_restart(tmp_path):
|
||||
path = tmp_path / "gates.sqlite3"
|
||||
store = HumanGateStore(path, clock=lambda: 100)
|
||||
first = store.intake("timmy", candidate(), idempotency_key="producer-9")
|
||||
repeated = store.intake("timmy", candidate(), idempotency_key="producer-9")
|
||||
|
||||
restarted = HumanGateStore(path, clock=lambda: 101)
|
||||
|
||||
assert repeated == first
|
||||
assert restarted.detail("timmy", first["id"])["candidate_hash"] == "abc123"
|
||||
assert restarted.list("alex")["pending_count"] == 0
|
||||
with sqlite3.connect(path) as connection:
|
||||
assert connection.execute("PRAGMA journal_mode").fetchone()[0] == "wal"
|
||||
|
||||
|
||||
def test_new_hash_supersedes_only_older_pending_candidate_without_losing_audit(tmp_path):
|
||||
store = HumanGateStore(tmp_path / "gates.sqlite3", clock=iter([100, 101]).__next__)
|
||||
old = store.intake("timmy", candidate("abc123"), idempotency_key="run-1")
|
||||
new = store.intake("timmy", candidate("def456"), idempotency_key="run-2")
|
||||
|
||||
old_detail = store.detail("timmy", old["id"])
|
||||
queue = store.list("timmy")
|
||||
|
||||
assert old_detail["state"] == "superseded"
|
||||
assert old_detail["superseded_by"] == new["id"]
|
||||
assert old_detail["history"][-1]["action"] == "superseded"
|
||||
assert queue["pending_count"] == 1
|
||||
assert queue["items"][0]["candidate_hash"] == "def456"
|
||||
|
||||
|
||||
def test_pending_queue_orders_highest_priority_then_oldest(tmp_path):
|
||||
clock = iter([100, 101, 102]).__next__
|
||||
store = HumanGateStore(tmp_path / "gates.sqlite3", clock=clock)
|
||||
low = store.intake("timmy", {**candidate("a1", priority=1), "project": "p/one"}, idempotency_key="1")
|
||||
oldest_high = store.intake("timmy", {**candidate("b2", priority=5), "project": "p/two"}, idempotency_key="2")
|
||||
newest_high = store.intake("timmy", {**candidate("c3", priority=5), "project": "p/three"}, idempotency_key="3")
|
||||
|
||||
assert [item["id"] for item in store.list("timmy")["items"]] == [oldest_high["id"], newest_high["id"], low["id"]]
|
||||
|
||||
|
||||
def test_decision_checks_revision_rules_and_returns_durable_idempotent_receipt(tmp_path):
|
||||
path = tmp_path / "gates.sqlite3"
|
||||
store = HumanGateStore(path, clock=iter([100, 101]).__next__)
|
||||
gate = store.intake("timmy", candidate(), idempotency_key="run-1")
|
||||
|
||||
receipt = store.decide(
|
||||
"timmy", gate["id"], expected_revision=gate["revision"], decision="release",
|
||||
reason="", override_reason="", checklist=checklist(), idempotency_key="decision-1",
|
||||
)
|
||||
repeated = store.decide(
|
||||
"timmy", gate["id"], expected_revision=gate["revision"], decision="release",
|
||||
reason="", override_reason="", checklist=checklist(), idempotency_key="decision-1",
|
||||
)
|
||||
|
||||
assert repeated == receipt
|
||||
assert receipt["state"] == "released"
|
||||
assert receipt["candidate_hash"] == "abc123"
|
||||
assert HumanGateStore(path, clock=lambda: 999).receipt("timmy", receipt["receipt_id"]) == receipt
|
||||
with pytest.raises(GateConflict):
|
||||
store.decide("timmy", gate["id"], expected_revision=gate["revision"], decision="hold", reason="later", override_reason="", checklist=checklist(), idempotency_key="decision-2")
|
||||
|
||||
|
||||
def test_hold_requires_reason_and_release_requires_checklist_and_override_for_unmet_checks(tmp_path):
|
||||
store = HumanGateStore(tmp_path / "gates.sqlite3", clock=lambda: 100)
|
||||
gate = store.intake("timmy", candidate(check_state="failure"), idempotency_key="run-1")
|
||||
|
||||
with pytest.raises(GateValidationError, match="Hold reason"):
|
||||
store.decide("timmy", gate["id"], expected_revision=1, decision="hold", reason="", override_reason="", checklist={}, idempotency_key="d1")
|
||||
with pytest.raises(GateValidationError, match="checklist"):
|
||||
store.decide("timmy", gate["id"], expected_revision=1, decision="release", reason="", override_reason="needed", checklist={"exact_hash": True}, idempotency_key="d2")
|
||||
with pytest.raises(GateValidationError, match="override reason"):
|
||||
store.decide("timmy", gate["id"], expected_revision=1, decision="release", reason="", override_reason="", checklist=checklist(), idempotency_key="d3")
|
||||
|
||||
receipt = store.decide("timmy", gate["id"], expected_revision=1, decision="hold", reason="Awaiting owner", override_reason="", checklist={}, idempotency_key="d4")
|
||||
assert receipt["state"] == "held"
|
||||
assert receipt["checklist"] == {}
|
||||
|
||||
|
||||
def test_same_hash_update_coalesces_one_card_and_preserves_history(tmp_path):
|
||||
store = HumanGateStore(tmp_path / "gates.sqlite3", clock=iter([100, 101]).__next__)
|
||||
original = store.intake("timmy", candidate(check_state="pending"), idempotency_key="run-1")
|
||||
|
||||
updated = store.intake("timmy", candidate(check_state="success"), idempotency_key="run-2")
|
||||
|
||||
assert updated["id"] == original["id"]
|
||||
assert updated["revision"] == 2
|
||||
assert updated["checks"][0]["state"] == "success"
|
||||
assert updated["history"][-1]["action"] == "updated"
|
||||
assert store.list("timmy")["pending_count"] == 1
|
||||
|
||||
|
||||
def test_updated_checks_reopen_a_released_hash_for_review(tmp_path):
|
||||
store = HumanGateStore(tmp_path / "gates.sqlite3", clock=iter([100, 101, 102]).__next__)
|
||||
gate = store.intake("timmy", candidate(), idempotency_key="run-1")
|
||||
store.decide(
|
||||
"timmy", gate["id"], expected_revision=1, decision="release",
|
||||
reason="", override_reason="", checklist=checklist(), idempotency_key="decision-1",
|
||||
)
|
||||
|
||||
reopened = store.intake(
|
||||
"timmy", candidate(check_state="failure"), idempotency_key="run-2",
|
||||
)
|
||||
|
||||
assert reopened["state"] == "pending"
|
||||
assert reopened["revision"] == 3
|
||||
assert reopened["checks"][0]["state"] == "failure"
|
||||
assert reopened["history"][-1]["action"] == "reopened"
|
||||
assert store.list("timmy")["pending_count"] == 1
|
||||
|
||||
|
||||
def test_same_hash_identity_facts_cannot_be_redefined(tmp_path):
|
||||
store = HumanGateStore(tmp_path / "gates.sqlite3", clock=lambda: 100)
|
||||
store.intake("timmy", candidate(), idempotency_key="run-1")
|
||||
|
||||
with pytest.raises(GateConflict, match="hash"):
|
||||
store.intake("timmy", {**candidate(), "title": "Changed facts"}, idempotency_key="run-2")
|
||||
@@ -0,0 +1,591 @@
|
||||
import json
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
MODULE = Path(__file__).parents[1] / "frontend" / "human-gates.js"
|
||||
PROGRESSIVE = Path(__file__).parents[1] / "frontend" / "progressive-human-gates.js"
|
||||
INDEX = Path(__file__).parents[1] / "frontend" / "index.html"
|
||||
DASHBOARD = Path(__file__).parents[1] / "frontend" / "dashboard.js"
|
||||
WORKER = Path(__file__).parents[1] / "frontend" / "service-worker.js"
|
||||
LIVE_SNAPSHOT = Path(__file__).parents[1] / "frontend" / "progressive-live-snapshot.js"
|
||||
PROGRESSIVE_MY_WORK = Path(__file__).parents[1] / "frontend" / "progressive-my-work.js"
|
||||
MY_WORK = Path(__file__).parents[1] / "frontend" / "my-work.js"
|
||||
|
||||
|
||||
def run_node(body):
|
||||
script = f"const createHumanGates=require({json.dumps(str(MODULE))});\n" + body
|
||||
result = subprocess.run(["node", "-e", script], check=True, text=True, capture_output=True)
|
||||
return json.loads(result.stdout)
|
||||
|
||||
|
||||
def test_progressive_my_work_and_human_gates_share_one_cold_live_snapshot():
|
||||
script = f"""
|
||||
const createProgressiveLiveSnapshot=require({json.dumps(str(LIVE_SNAPSHOT))});
|
||||
globalThis.buildMyWork=require({json.dumps(str(MY_WORK))});
|
||||
const createProgressiveMyWork=require({json.dumps(str(PROGRESSIVE_MY_WORK))});
|
||||
const createProgressiveHumanGates=require({json.dumps(str(PROGRESSIVE))});
|
||||
let liveCalls=0, directMyWorkCalls=0, resolveLive;
|
||||
const broker=createProgressiveLiveSnapshot({{fetchSnapshot:()=>{{
|
||||
liveCalls += 1;
|
||||
return new Promise(resolve=>{{resolveLive=resolve;}});
|
||||
}}}});
|
||||
const workDocument={{
|
||||
hidden:false,
|
||||
querySelector:selector=>selector==='#my-work-list'?{{innerHTML:''}}:selector==='#my-work-status'?{{textContent:''}}:null,
|
||||
querySelectorAll:()=>[],
|
||||
}};
|
||||
const work=createProgressiveMyWork({{
|
||||
document:workDocument, liveSnapshot:broker,
|
||||
fetchSnapshot:async()=>{{directMyWorkCalls += 1; return {{}};}},
|
||||
}});
|
||||
const nodes={{
|
||||
'#human-gates-count':{{}}, '#human-gates-list':{{innerHTML:'',addEventListener(){{}}}},
|
||||
'#human-gates-status':{{}}, '#human-gates':{{hidden:true}},
|
||||
'#human-gate-detail':{{innerHTML:'',addEventListener(){{}},querySelectorAll:()=>[]}},
|
||||
'#open-human-gates':{{addEventListener(){{}}}}, '#close-human-gates':{{addEventListener(){{}}}},
|
||||
}};
|
||||
const gates=createProgressiveHumanGates({{
|
||||
document:{{querySelector:selector=>nodes[selector]||null}},
|
||||
location:{{hash:'#/my-work/human-gates'}}, history:{{replaceState(){{}}}},
|
||||
storage:{{getItem:()=>null,setItem(){{}}}}, isOnline:()=>true,
|
||||
liveSnapshot:broker,
|
||||
fetchJson:async path=>({{pending_count:1,items:[{{id:'g1',title:'Shared identity',candidate_hash:'abc',revision:1,checks:[]}}]}}),
|
||||
}});
|
||||
(async()=>{{
|
||||
const workStart=work.start(); const gateStart=gates.start();
|
||||
await Promise.resolve(); await Promise.resolve();
|
||||
const callsWhilePending=liveCalls;
|
||||
resolveLive({{context:{{user:{{id:7,login:'timmy'}},issues:[],pull_requests:[]}},events:[],notifications:[]}});
|
||||
await Promise.all([workStart,gateStart]);
|
||||
process.stdout.write(JSON.stringify({{
|
||||
callsWhilePending,liveCalls,directMyWorkCalls,
|
||||
login:work.login(),gateStarted:gates.handoff().started,
|
||||
}}));
|
||||
}})().catch(error=>{{console.error(error);process.exit(1);}});
|
||||
"""
|
||||
result = subprocess.run(["node", "-e", script], capture_output=True, text=True)
|
||||
|
||||
assert result.returncode == 0, result.stderr
|
||||
assert json.loads(result.stdout) == {
|
||||
"callsWhilePending": 1,
|
||||
"liveCalls": 1,
|
||||
"directMyWorkCalls": 0,
|
||||
"login": "timmy",
|
||||
"gateStarted": True,
|
||||
}
|
||||
|
||||
|
||||
def test_progressive_human_gates_retries_partial_snapshot_identity_without_hydration():
|
||||
script = f"""
|
||||
const createProgressiveLiveSnapshot=require({json.dumps(str(LIVE_SNAPSHOT))});
|
||||
const createProgressiveHumanGates=require({json.dumps(str(PROGRESSIVE))});
|
||||
let liveCalls=0, gateCalls=0;
|
||||
const responses=[
|
||||
{{context:null,events:[],notifications:[]}},
|
||||
{{context:{{user:{{id:7,login:'timmy'}}}},events:[],notifications:[]}},
|
||||
];
|
||||
const broker=createProgressiveLiveSnapshot({{fetchSnapshot:async()=>{{liveCalls+=1;return responses.shift();}}}});
|
||||
const nodes={{
|
||||
'#human-gates-count':{{}}, '#human-gates-list':{{innerHTML:'',addEventListener(){{}}}},
|
||||
'#human-gates-status':{{}}, '#human-gates':{{hidden:true}},
|
||||
'#human-gate-detail':{{innerHTML:'',addEventListener(){{}},querySelectorAll:()=>[]}},
|
||||
'#open-human-gates':{{addEventListener(){{}}}}, '#close-human-gates':{{addEventListener(){{}}}},
|
||||
}};
|
||||
const gates=createProgressiveHumanGates({{
|
||||
document:{{querySelector:selector=>nodes[selector]||null}},
|
||||
location:{{hash:'#/my-work/human-gates'}}, history:{{replaceState(){{}}}},
|
||||
storage:{{getItem:()=>null,setItem(){{}}}}, isOnline:()=>true,
|
||||
liveSnapshot:broker,
|
||||
fetchJson:async()=>{{gateCalls+=1;return {{pending_count:1,items:[{{id:'g1',title:'Recovered',candidate_hash:'abc',revision:1,checks:[]}}]}};}},
|
||||
}});
|
||||
(async()=>{{
|
||||
let firstError='';
|
||||
try{{await gates.start();}}catch(error){{firstError=error.message;}}
|
||||
const recovered=await gates.start();
|
||||
process.stdout.write(JSON.stringify({{
|
||||
firstError,recovered,liveCalls,gateCalls,started:gates.handoff().started,
|
||||
}}));
|
||||
}})().catch(error=>{{console.error(error);process.exit(1);}});
|
||||
"""
|
||||
result = subprocess.run(["node", "-e", script], capture_output=True, text=True)
|
||||
|
||||
assert result.returncode == 0, result.stderr
|
||||
assert json.loads(result.stdout) == {
|
||||
"firstError": "Authenticated account identity is unavailable.",
|
||||
"recovered": True,
|
||||
"liveCalls": 2,
|
||||
"gateCalls": 2,
|
||||
"started": True,
|
||||
}
|
||||
|
||||
|
||||
def test_queue_loads_pending_count_uses_account_cache_and_renders_inbox_zero():
|
||||
output = run_node(r"""
|
||||
const values=new Map(); const storage={getItem:k=>values.get(k)||null,setItem:(k,v)=>values.set(k,v)};
|
||||
let response={pending_count:1,items:[{id:'g1',title:'Candidate',candidate_hash:'abc123',priority:4,state:'pending',revision:1,checks:[]}]};
|
||||
const nodes={count:{textContent:''},list:{innerHTML:''},status:{textContent:''},panel:{hidden:true}};
|
||||
const gates=createHumanGates({storage,getLogin:()=> 'timmy',isOnline:()=>true,nodes,location:{hash:''},fetchJson:async()=>response});
|
||||
(async()=>{ await gates.load(); const first={snapshot:gates.snapshot(),count:nodes.count.textContent,html:nodes.list.innerHTML,keys:[...values.keys()]}; response={pending_count:0,items:[]}; await gates.load(); process.stdout.write(JSON.stringify({first,zero:{snapshot:gates.snapshot(),status:nodes.status.textContent,html:nodes.list.innerHTML}})); })();
|
||||
""")
|
||||
assert output["first"]["count"] == "1"
|
||||
assert "abc123" in output["first"]["html"]
|
||||
assert output["first"]["keys"] == ["stackchain.human-gates.v1:timmy"]
|
||||
assert output["zero"]["snapshot"]["pending_count"] == 0
|
||||
assert "Inbox zero" in output["zero"]["html"]
|
||||
|
||||
|
||||
def test_queue_changes_publish_mobile_counts_and_authoritative_decision_completion():
|
||||
output = run_node(r"""
|
||||
const changes=[];
|
||||
const item={id:'g1',title:'Candidate',candidate_hash:'abc123',revision:1,checks:[]};
|
||||
const gates=createHumanGates({
|
||||
storage:{getItem:()=>null,setItem(){}}, getLogin:()=> 'timmy', isOnline:()=>true,
|
||||
nodes:{count:{},list:{},status:{},panel:{},detail:{}}, location:{hash:''},
|
||||
onChange:(snapshot, state)=>changes.push({count:snapshot.pending_count,...state}),
|
||||
fetchJson:async(path, options={})=>options.method==='POST' ? {receipt_id:'r1'} : {pending_count:1,items:[item]},
|
||||
});
|
||||
(async()=>{await gates.load();gates.reviewNext();await gates.decideAndNext('release',{checklist:{exact_hash:true,artifacts_reviewed:true,provenance_reviewed:true}});process.stdout.write(JSON.stringify(changes));})();
|
||||
""")
|
||||
assert output == [
|
||||
{"count": 1, "available": True, "authoritative": True},
|
||||
{"count": 0, "available": True, "authoritative": True, "decision": True},
|
||||
]
|
||||
|
||||
|
||||
def test_queue_load_failure_distinguishes_cached_read_only_data_from_unavailable():
|
||||
output = run_node(r"""
|
||||
const cached={pending_count:1,items:[{id:'g1',title:'Cached',candidate_hash:'abc'}]};
|
||||
const changes=[];
|
||||
const make=(value,label)=>createHumanGates({
|
||||
storage:{getItem:()=>value ? JSON.stringify(value) : null,setItem(){}},
|
||||
getLogin:()=> 'timmy', isOnline:()=>false, nodes:{count:{},list:{},status:{},panel:{}}, location:{hash:''},
|
||||
onChange:(snapshot,state)=>changes.push({label,count:snapshot.pending_count,...state}),
|
||||
fetchJson:async()=>{throw new Error('network')},
|
||||
});
|
||||
(async()=>{await make(cached,'cached').load();try{await make(null,'empty').load()}catch(_){}process.stdout.write(JSON.stringify(changes));})();
|
||||
""")
|
||||
assert output == [
|
||||
{"label": "cached", "count": 1, "available": True, "authoritative": False, "cached": True},
|
||||
{"label": "empty", "count": 0, "available": False, "authoritative": False},
|
||||
]
|
||||
|
||||
|
||||
def test_review_next_is_a_fixed_snapshot_and_decision_and_next_advances_without_new_arrivals():
|
||||
output = run_node(r"""
|
||||
const calls=[]; const nodes={count:{textContent:''},list:{innerHTML:''},status:{textContent:''},panel:{hidden:true},detail:{innerHTML:''}};
|
||||
const initial={pending_count:2,items:[{id:'old',title:'Old',candidate_hash:'a1',revision:1,checks:[]},{id:'next',title:'Next',candidate_hash:'b2',revision:1,checks:[]}]};
|
||||
const gates=createHumanGates({storage:{getItem:()=>null,setItem(){}},getLogin:()=> 'timmy',isOnline:()=>true,nodes,location:{hash:'#/my-work/human-gates'},fetchJson:async(path,options={})=>{calls.push({path,options}); if(options.method==='POST') return {receipt_id:'r1',state:'released'}; return initial;}});
|
||||
(async()=>{await gates.load(); const reviewed=gates.reviewNext(); initial.items.unshift({id:'new',title:'New arrival',candidate_hash:'c3',revision:1,checks:[]}); const result=await gates.decideAndNext('release',{checklist:{exact_hash:true,artifacts_reviewed:true,provenance_reviewed:true}}); process.stdout.write(JSON.stringify({reviewed,result,current:gates.current(),calls,hash:gates.route()}));})();
|
||||
""")
|
||||
assert output["reviewed"]["id"] == "old"
|
||||
assert output["result"]["receipt"]["receipt_id"] == "r1"
|
||||
assert output["current"]["id"] == "next"
|
||||
assert output["hash"] == "#/my-work/human-gates"
|
||||
post = next(call for call in output["calls"] if call["options"].get("method") == "POST")
|
||||
assert post["path"] == "api/v1/human-gates/old/decision"
|
||||
assert "Idempotency-Key" in post["options"]["headers"]
|
||||
|
||||
|
||||
def test_review_loads_exact_detail_with_links_provenance_and_history():
|
||||
output = run_node(r"""
|
||||
const detail={id:'g1',title:'Candidate',project:'stackchain/dashboard',candidate_hash:'abc123',revision:1,checks:[{name:'unit',state:'success',required:true}],artifacts:[{name:'manifest',url:'https://forge.example/manifest'}],links:[{label:'pull',url:'https://forge.example/pull/1'}],score:{value:98,provenance:'eval/v1'},provenance:{producer:'bot',run_id:'9'},history:[{action:'intake',at:100}]};
|
||||
const nodes={count:{},list:{},status:{},panel:{},detail:{innerHTML:''}};
|
||||
const gates=createHumanGates({storage:{getItem:()=>null,setItem(){}},getLogin:()=> 'timmy',isOnline:()=>true,nodes,location:{hash:''},fetchJson:async path=>path.endsWith('/g1')?detail:{pending_count:1,items:[detail]}});
|
||||
(async()=>{await gates.load();gates.reviewNext();await new Promise(resolve=>setTimeout(resolve,0));process.stdout.write(JSON.stringify({html:nodes.detail.innerHTML}));})();
|
||||
""")
|
||||
assert "stackchain/dashboard" in output["html"]
|
||||
assert "https://forge.example/pull/1" in output["html"]
|
||||
assert output["html"].count('target="_blank"') == 2
|
||||
assert output["html"].count('rel="noreferrer noopener"') == 2
|
||||
assert "bot" in output["html"]
|
||||
assert "intake" in output["html"]
|
||||
|
||||
|
||||
def test_unfinished_review_restores_after_reload_for_same_account_gate_and_revision():
|
||||
output = run_node(r"""
|
||||
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 item={id:'g1',title:'Candidate',project:'stackchain/dashboard',candidate_hash:'abc123',revision:4,checks:[]};
|
||||
const make=()=>{
|
||||
const nodes={count:{},list:{},status:{},panel:{},detail:{innerHTML:'',addEventListener(){}}};
|
||||
return {nodes,gates:createHumanGates({
|
||||
storage,getLogin:()=> 'timmy',getAccountKey:()=> '7:timmy',isOnline:()=>true,nodes,location:{hash:''},
|
||||
fetchJson:async path=>path.endsWith('/g1')?item:{pending_count:1,items:[item]},
|
||||
})};
|
||||
};
|
||||
(async()=>{
|
||||
const first=make(); await first.gates.load(); first.gates.reviewNext();
|
||||
first.gates.saveProgress({
|
||||
checklist:{exact_hash:true,artifacts_reviewed:false,provenance_reviewed:true},
|
||||
reason:'Need the signed manifest',override_reason:'Approved exception',
|
||||
});
|
||||
const reloaded=make(); await reloaded.gates.load(); reloaded.gates.reviewNext();
|
||||
await new Promise(resolve=>setTimeout(resolve,0));
|
||||
process.stdout.write(JSON.stringify({keys:[...values.keys()],html:reloaded.nodes.detail.innerHTML}));
|
||||
})();
|
||||
""")
|
||||
assert "stackchain.human-gate-review.v1:7:timmy:g1:4" in output["keys"]
|
||||
assert 'data-gate-checklist="exact_hash" checked' in output["html"]
|
||||
assert 'data-gate-checklist="artifacts_reviewed" checked' not in output["html"]
|
||||
assert 'data-gate-checklist="provenance_reviewed" checked' in output["html"]
|
||||
assert "Need the signed manifest" in output["html"]
|
||||
assert "Approved exception" in output["html"]
|
||||
|
||||
|
||||
def test_review_form_changes_are_saved_without_a_decision_tap():
|
||||
output = run_node(r"""
|
||||
const values=new Map(), listeners={};
|
||||
const inputs=[
|
||||
{dataset:{gateChecklist:'exact_hash'},checked:true},
|
||||
{dataset:{gateChecklist:'artifacts_reviewed'},checked:true},
|
||||
{dataset:{gateChecklist:'provenance_reviewed'},checked:false},
|
||||
];
|
||||
const reason={value:'Waiting for mobile evidence'}, override={value:'Temporary exception'};
|
||||
const detail={
|
||||
innerHTML:'', addEventListener:(name,listener)=>listeners[name]=listener,
|
||||
querySelectorAll:()=>inputs,
|
||||
querySelector:selector=>selector==='[data-gate-reason]'?reason:override,
|
||||
};
|
||||
const item={id:'g1',title:'Candidate',candidate_hash:'abc',revision:2,checks:[]};
|
||||
const gates=createHumanGates({
|
||||
storage:{getItem:key=>values.get(key)||null,setItem:(key,value)=>values.set(key,value)},
|
||||
getLogin:()=> 'timmy',getAccountKey:()=> '7:timmy',isOnline:()=>true,
|
||||
nodes:{count:{},list:{},status:{},panel:{},detail},location:{hash:''},
|
||||
fetchJson:async()=>({pending_count:1,items:[item]}),
|
||||
});
|
||||
(async()=>{
|
||||
await gates.load(); gates.reviewNext();
|
||||
listeners.input();
|
||||
const saved=JSON.parse(values.get('stackchain.human-gate-review.v1:7:timmy:g1:2'));
|
||||
process.stdout.write(JSON.stringify(saved));
|
||||
})();
|
||||
""")
|
||||
assert output == {
|
||||
"gate_id": "g1",
|
||||
"revision": 2,
|
||||
"checklist": {
|
||||
"exact_hash": True,
|
||||
"artifacts_reviewed": True,
|
||||
"provenance_reviewed": False,
|
||||
},
|
||||
"reason": "Waiting for mobile evidence",
|
||||
"override_reason": "Temporary exception",
|
||||
}
|
||||
|
||||
|
||||
def test_release_requires_override_for_unmet_required_checks_and_decisions_require_online_identity():
|
||||
output = run_node(r"""
|
||||
let online=true, login='timmy', posts=0;
|
||||
const item={id:'g1',title:'Failing',candidate_hash:'a1',revision:1,checks:[{name:'browser',state:'failure',required:true}]};
|
||||
const gates=createHumanGates({storage:{getItem:()=>null,setItem(){}},getLogin:()=>login,isOnline:()=>online,nodes:{count:{},list:{},status:{},panel:{},detail:{}},location:{hash:''},fetchJson:async(path,options={})=>{if(options.method==='POST'){posts++;return {receipt_id:'r1'}};return {pending_count:1,items:[item]};}});
|
||||
(async()=>{await gates.load();gates.reviewNext();let override,offline,identity;try{await gates.decideAndNext('release',{checklist:{exact_hash:true,artifacts_reviewed:true,provenance_reviewed:true}})}catch(e){override=e.message} online=false;try{await gates.decideAndNext('hold',{reason:'wait',checklist:{exact_hash:true,artifacts_reviewed:true,provenance_reviewed:true}})}catch(e){offline=e.message} online=true;login='';try{await gates.decideAndNext('hold',{reason:'wait',checklist:{exact_hash:true,artifacts_reviewed:true,provenance_reviewed:true}})}catch(e){identity=e.message}process.stdout.write(JSON.stringify({override,offline,identity,posts}));})();
|
||||
""")
|
||||
assert "override reason" in output["override"]
|
||||
assert "online" in output["offline"]
|
||||
assert "identity" in output["identity"]
|
||||
assert output["posts"] == 0
|
||||
|
||||
|
||||
def test_offline_cache_is_scoped_to_immutable_account_identity():
|
||||
output = run_node(r"""
|
||||
const values=new Map(); const storage={getItem:k=>values.get(k)||null,setItem:(k,v)=>values.set(k,v)};
|
||||
let account='1:timmy'; const nodes={count:{},list:{},status:{},panel:{}};
|
||||
const gates=createHumanGates({storage,getLogin:()=> 'timmy',getAccountKey:()=>account,isOnline:()=>true,nodes,location:{hash:''},fetchJson:async()=>({pending_count:1,items:[{id:'g1',title:'Private',candidate_hash:'a1'}]})});
|
||||
(async()=>{await gates.load();account='2:timmy';process.stdout.write(JSON.stringify({keys:[...values.keys()],restored:gates.restoreCached()}));})();
|
||||
""")
|
||||
assert output["keys"] == ["stackchain.human-gates.v1:1:timmy"]
|
||||
assert output["restored"] is None
|
||||
|
||||
|
||||
def test_account_switch_clears_in_memory_gate_data_before_failed_load():
|
||||
output = run_node(r"""
|
||||
const values=new Map(); const storage={getItem:k=>values.get(k)||null,setItem:(k,v)=>values.set(k,v)};
|
||||
let account='1:timmy', fail=false; const nodes={count:{},list:{innerHTML:''},status:{},panel:{}};
|
||||
const gates=createHumanGates({storage,getLogin:()=> 'timmy',getAccountKey:()=>account,isOnline:()=>true,nodes,location:{hash:''},fetchJson:async()=>{if(fail)throw new Error('offline');return {pending_count:1,items:[{id:'private-1',title:'Principal 1 private',candidate_hash:'secret'}]}}});
|
||||
(async()=>{await gates.load();account='2:timmy';fail=true;try{await gates.load()}catch(_){}process.stdout.write(JSON.stringify({snapshot:gates.snapshot(),html:nodes.list.innerHTML}));})();
|
||||
""")
|
||||
assert output["snapshot"] == {"pending_count": 0, "items": []}
|
||||
assert "Principal 1 private" not in output["html"]
|
||||
assert "secret" not in output["html"]
|
||||
|
||||
|
||||
def test_stale_account_load_cannot_overwrite_new_account_queue_or_cache():
|
||||
output = run_node(r"""
|
||||
const values=new Map(); const storage={getItem:k=>values.get(k)||null,setItem:(k,v)=>values.set(k,v)};
|
||||
let account='1:timmy', resolveA, resolveB;
|
||||
const responseA=new Promise(resolve=>resolveA=resolve), responseB=new Promise(resolve=>resolveB=resolve);
|
||||
const gates=createHumanGates({storage,getLogin:()=> 'timmy',getAccountKey:()=>account,isOnline:()=>true,nodes:{count:{},list:{innerHTML:''},status:{},panel:{}},location:{hash:''},fetchJson:()=>account.startsWith('1:')?responseA:responseB});
|
||||
(async()=>{const loadA=gates.load();account='2:timmy';const loadB=gates.load();resolveB({pending_count:1,items:[{id:'b',title:'B gate',candidate_hash:'bhash'}]});await loadB;resolveA({pending_count:1,items:[{id:'a-secret',title:'A secret',candidate_hash:'asecret'}]});await loadA;process.stdout.write(JSON.stringify({snapshot:gates.snapshot(),cached:JSON.parse(values.get('stackchain.human-gates.v1:2:timmy'))}));})();
|
||||
""")
|
||||
assert [item["id"] for item in output["snapshot"]["items"]] == ["b"]
|
||||
assert [item["id"] for item in output["cached"]["items"]] == ["b"]
|
||||
|
||||
|
||||
def test_decision_retry_reuses_the_same_idempotency_key():
|
||||
output = run_node(r"""
|
||||
let attempts=0; const keys=[];
|
||||
const item={id:'g1',title:'Candidate',candidate_hash:'a1',revision:1,checks:[]};
|
||||
const gates=createHumanGates({storage:{getItem:()=>null,setItem(){}},getLogin:()=> 'timmy',isOnline:()=>true,nodes:{count:{},list:{},status:{},panel:{},detail:{}},location:{hash:''},fetchJson:async(path,options={})=>{if(options.method==='POST'){keys.push(options.headers['Idempotency-Key']);attempts++;if(attempts===1)throw new Error('network');return {receipt_id:'r1'}};return {pending_count:1,items:[item]};}});
|
||||
(async()=>{await gates.load();gates.reviewNext();const values={reason:'wait',checklist:{}};try{await gates.decideAndNext('hold',values)}catch(_){}await gates.decideAndNext('hold',values);process.stdout.write(JSON.stringify({keys}));})();
|
||||
""")
|
||||
assert len(output["keys"]) == 2
|
||||
assert output["keys"][0] == output["keys"][1]
|
||||
|
||||
|
||||
def test_failed_decision_keeps_review_progress_and_successful_retry_clears_it():
|
||||
output = run_node(r"""
|
||||
const stored=new Map(); let attempts=0;
|
||||
const storage={getItem:key=>stored.get(key)||null,setItem:(key,value)=>stored.set(key,value),removeItem:key=>stored.delete(key)};
|
||||
const item={id:'g1',title:'Candidate',candidate_hash:'a1',revision:3,checks:[]};
|
||||
const gates=createHumanGates({
|
||||
storage,getLogin:()=> 'timmy',getAccountKey:()=> '7:timmy',isOnline:()=>true,
|
||||
nodes:{count:{},list:{},status:{},panel:{},detail:{}},location:{hash:''},
|
||||
fetchJson:async(path,options={})=>{
|
||||
if(options.method==='POST') { attempts += 1; if(attempts===1) throw new Error('offline'); return {receipt_id:'r1'}; }
|
||||
return {pending_count:1,items:[item]};
|
||||
},
|
||||
});
|
||||
(async()=>{
|
||||
await gates.load(); gates.reviewNext();
|
||||
gates.saveProgress({reason:'Awaiting approval',checklist:{}});
|
||||
const key='stackchain.human-gate-review.v1:7:timmy:g1:3';
|
||||
try { await gates.decideAndNext('hold',{reason:'Awaiting approval',checklist:{}}); } catch (_) {}
|
||||
const retained=stored.has(key);
|
||||
await gates.decideAndNext('hold',{reason:'Awaiting approval',checklist:{}});
|
||||
process.stdout.write(JSON.stringify({retained,cleared:!stored.has(key)}));
|
||||
})();
|
||||
""")
|
||||
assert output == {"retained": True, "cleared": True}
|
||||
|
||||
|
||||
def test_concurrent_decision_taps_submit_once_and_advance_once():
|
||||
output = run_node(r"""
|
||||
let posts=0, releasePost; const posted=new Promise(resolve=>releasePost=resolve);
|
||||
const items=[{id:'g1',title:'One',candidate_hash:'a1',revision:1,checks:[]},{id:'g2',title:'Two',candidate_hash:'b2',revision:1,checks:[]}];
|
||||
const gates=createHumanGates({storage:{getItem:()=>null,setItem(){}},getLogin:()=> 'timmy',isOnline:()=>true,nodes:{count:{},list:{},status:{},panel:{},detail:{}},location:{hash:''},fetchJson:async(path,options={})=>{if(options.method==='POST'){posts++;await posted;return {receipt_id:'r1'}};return {pending_count:2,items};}});
|
||||
(async()=>{await gates.load();gates.reviewNext();const values={reason:'wait',checklist:{}};const first=gates.decideAndNext('hold',values);const second=gates.decideAndNext('hold',values);releasePost();await Promise.all([first,second]);process.stdout.write(JSON.stringify({posts,current:gates.current()?.id,snapshot:gates.snapshot()}));})();
|
||||
""")
|
||||
assert output["posts"] == 1
|
||||
assert output["current"] == "g2"
|
||||
assert output["snapshot"]["pending_count"] == 1
|
||||
assert [item["id"] for item in output["snapshot"]["items"]] == ["g2"]
|
||||
|
||||
|
||||
def test_concurrent_reopen_calls_share_one_fresh_list_request():
|
||||
output = run_node(r"""
|
||||
let listCalls=0, releaseList;
|
||||
const pending=new Promise(resolve=>releaseList=resolve);
|
||||
const item={id:'g1',title:'Candidate',candidate_hash:'a1',revision:1,checks:[]};
|
||||
const gates=createHumanGates({
|
||||
storage:{getItem:()=>null,setItem(){}},getLogin:()=> 'timmy',isOnline:()=>true,
|
||||
nodes:{count:{},list:{},status:{},panel:{hidden:true},detail:{}},location:{hash:''},
|
||||
fetchJson:async path=>{
|
||||
if(path.endsWith('/g1')) return item;
|
||||
listCalls += 1;
|
||||
await pending;
|
||||
return {pending_count:1,items:[item]};
|
||||
},
|
||||
});
|
||||
(async()=>{
|
||||
const first=gates.open();
|
||||
const second=gates.open();
|
||||
releaseList();
|
||||
const reviewed=await Promise.all([first,second]);
|
||||
process.stdout.write(JSON.stringify({listCalls,ids:reviewed.map(item=>item.id)}));
|
||||
})();
|
||||
""")
|
||||
assert output == {"listCalls": 1, "ids": ["g1", "g1"]}
|
||||
|
||||
|
||||
def test_failed_reopen_clears_single_flight_and_can_retry():
|
||||
output = run_node(r"""
|
||||
let listCalls=0;
|
||||
const item={id:'g1',title:'Recovered',candidate_hash:'a1',revision:1,checks:[]};
|
||||
const gates=createHumanGates({
|
||||
storage:{getItem:()=>null,setItem(){}},getLogin:()=> 'timmy',isOnline:()=>true,
|
||||
nodes:{count:{},list:{},status:{},panel:{hidden:true},detail:{}},location:{hash:''},
|
||||
fetchJson:async path=>{
|
||||
if(path.endsWith('/g1')) return item;
|
||||
listCalls += 1;
|
||||
if(listCalls === 1) throw new Error('offline');
|
||||
return {pending_count:1,items:[item]};
|
||||
},
|
||||
});
|
||||
(async()=>{
|
||||
let firstError='';
|
||||
try { await gates.open(); } catch(error) { firstError=error.message; }
|
||||
const recovered=await gates.open();
|
||||
process.stdout.write(JSON.stringify({firstError,listCalls,recovered:recovered.id}));
|
||||
})();
|
||||
""")
|
||||
assert output == {"firstError": "offline", "listCalls": 2, "recovered": "g1"}
|
||||
|
||||
|
||||
def test_reopen_refreshes_queue_and_starts_a_fresh_atomic_review_snapshot():
|
||||
output = run_node(r"""
|
||||
const first={id:'g1',title:'First candidate',project:'p/one',candidate_hash:'a1',revision:1,checks:[]};
|
||||
const second={id:'g2',title:'Second candidate',project:'p/two',candidate_hash:'b2',revision:1,checks:[]};
|
||||
let listCalls=0;
|
||||
const nodes={count:{},list:{innerHTML:''},status:{},panel:{hidden:true},detail:{innerHTML:''}};
|
||||
const gates=createHumanGates({
|
||||
storage:{getItem:()=>null,setItem(){}},getLogin:()=> 'timmy',isOnline:()=>true,nodes,location:{hash:''},
|
||||
fetchJson:async path=>{
|
||||
if(path.endsWith('/g1')) return first;
|
||||
if(path.endsWith('/g2')) return second;
|
||||
listCalls += 1;
|
||||
return {pending_count:1,items:[listCalls === 1 ? first : second]};
|
||||
},
|
||||
});
|
||||
(async()=>{
|
||||
await gates.open();
|
||||
await new Promise(resolve=>setTimeout(resolve,0));
|
||||
const before=gates.current().id;
|
||||
await gates.open();
|
||||
const selected=gates.select('g2');
|
||||
await new Promise(resolve=>setTimeout(resolve,0));
|
||||
process.stdout.write(JSON.stringify({
|
||||
before,listCalls,selected:selected.id,current:gates.current().id,
|
||||
listHtml:nodes.list.innerHTML,detailHtml:nodes.detail.innerHTML,
|
||||
}));
|
||||
})();
|
||||
""")
|
||||
assert output["before"] == "g1"
|
||||
assert output["listCalls"] == 2
|
||||
assert output["selected"] == "g2"
|
||||
assert output["current"] == "g2"
|
||||
assert "Second candidate" in output["listHtml"]
|
||||
assert "Second candidate" in output["detailHtml"]
|
||||
|
||||
|
||||
def test_selecting_a_queue_card_opens_that_exact_gate():
|
||||
output = run_node(r"""
|
||||
const details={
|
||||
g1:{id:'g1',title:'First',project:'p/one',candidate_hash:'a1',revision:1,checks:[]},
|
||||
g2:{id:'g2',title:'Second',project:'p/two',candidate_hash:'b2',revision:1,checks:[]},
|
||||
};
|
||||
const nodes={count:{},list:{},status:{},panel:{},detail:{innerHTML:''}};
|
||||
const gates=createHumanGates({storage:{getItem:()=>null,setItem(){}},getLogin:()=> 'timmy',isOnline:()=>true,nodes,location:{hash:''},fetchJson:async path=>path.includes('/g')?details[path.split('/').pop()]:{pending_count:2,items:Object.values(details)}});
|
||||
(async()=>{await gates.load();gates.reviewNext();gates.select('g2');await new Promise(resolve=>setTimeout(resolve,0));process.stdout.write(JSON.stringify({current:gates.current().id,html:nodes.detail.innerHTML}));})();
|
||||
""")
|
||||
assert output["current"] == "g2"
|
||||
assert "Second" in output["html"]
|
||||
assert "p/two" in output["html"]
|
||||
|
||||
|
||||
def test_human_gate_mobile_shell_and_deep_route_are_wired():
|
||||
index = INDEX.read_text()
|
||||
dashboard = DASHBOARD.read_text()
|
||||
assert 'id="human-gates"' in index
|
||||
assert 'id="human-gates-count"' in index
|
||||
assert 'Review next <span id="human-gates-count"' in index
|
||||
assert 'static/human-gates.js' in index
|
||||
assert "#/my-work/human-gates" in dashboard
|
||||
assert "createHumanGates" in dashboard
|
||||
assert "planningOwnerAccountKey = confirmedOwnerLogin && saved.user?.id" in dashboard
|
||||
assert 'data-mobile-queue="gate"' in index
|
||||
assert 'data-mobile-queue-count="gate"' in index
|
||||
assert "openHumanGates: () => openHumanGates()" in dashboard
|
||||
assert "const humanGatesOnChange = (snapshot, state)=>" in dashboard
|
||||
assert "queueCounts.gate = snapshot.pending_count" in dashboard
|
||||
assert "preparationItems.gate = snapshot.items" in dashboard
|
||||
assert "mobileStartDay.reconcile({authoritative:true, authoritativePhases:['gate']})" in dashboard
|
||||
assert "counts.gate = queueCounts.gate" in dashboard
|
||||
assert "gate:preparationItems.gate || []" in dashboard
|
||||
assert "stackchain-dashboard-shell-v146" in WORKER.read_text()
|
||||
|
||||
|
||||
def test_deep_link_opens_human_gates_without_waiting_for_optional_workspace():
|
||||
script = f"""
|
||||
const createProgressiveHumanGates=require({json.dumps(str(PROGRESSIVE))});
|
||||
const listeners={{}}; const requests=[];
|
||||
const nodes={{
|
||||
'#human-gates-count':{{}}, '#human-gates-list':{{innerHTML:''}},
|
||||
'#human-gates-status':{{}}, '#human-gates':{{hidden:true}},
|
||||
'#human-gate-detail':{{innerHTML:'',querySelectorAll:()=>[]}},
|
||||
'#open-human-gates':{{addEventListener:(name,fn)=>listeners.open=fn}},
|
||||
'#close-human-gates':{{addEventListener:(name,fn)=>listeners.close=fn}},
|
||||
}};
|
||||
nodes['#human-gates-list'].addEventListener=(name,fn)=>listeners.list=fn;
|
||||
nodes['#human-gate-detail'].addEventListener=(name,fn)=>listeners.detail=fn;
|
||||
const document={{querySelector:selector=>nodes[selector]||null}};
|
||||
const app=createProgressiveHumanGates({{
|
||||
document, location:{{hash:'#/my-work/human-gates'}},
|
||||
history:{{replaceState(){{}}}}, storage:{{getItem:()=>null,setItem(){{}}}},
|
||||
isOnline:()=>true, getIdentity:async()=>({{login:'timmy',accountKey:'7:timmy'}}),
|
||||
fetchJson:async path=>{{requests.push(path);return {{pending_count:1,items:[{{id:'g1',title:'Ship it',candidate_hash:'abc',revision:1,checks:[]}}]}};}},
|
||||
}});
|
||||
(async()=>{{const started=await app.start();process.stdout.write(JSON.stringify({{
|
||||
started,hidden:nodes['#human-gates'].hidden,html:nodes['#human-gates-list'].innerHTML,
|
||||
requests,listeners:Object.keys(listeners).sort(),handoff:app.handoff().started,
|
||||
}}));}})();
|
||||
"""
|
||||
result = subprocess.run(["node", "-e", script], check=True, text=True, capture_output=True)
|
||||
output = json.loads(result.stdout)
|
||||
assert output == {
|
||||
"started": True,
|
||||
"hidden": False,
|
||||
"html": '<button class="human-gate-card" type="button" data-human-gate-id="g1"><strong>Ship it</strong><code>abc</code><span>Priority 0</span></button>',
|
||||
"requests": ["api/v1/human-gates", "api/v1/human-gates/g1"],
|
||||
"listeners": ["close", "detail", "list", "open"],
|
||||
"handoff": True,
|
||||
}
|
||||
|
||||
|
||||
def test_progressive_reopen_refreshes_the_review_session_before_hydration():
|
||||
script = f"""
|
||||
const createProgressiveHumanGates=require({json.dumps(str(PROGRESSIVE))});
|
||||
const listeners={{}};
|
||||
const nodes={{
|
||||
'#human-gates-count':{{}}, '#human-gates-list':{{innerHTML:'',addEventListener(){{}}}},
|
||||
'#human-gates-status':{{}}, '#human-gates':{{hidden:true}},
|
||||
'#human-gate-detail':{{innerHTML:'',addEventListener(){{}},querySelectorAll:()=>[]}},
|
||||
'#open-human-gates':{{addEventListener:(name,fn)=>listeners.open=fn}},
|
||||
'#close-human-gates':{{addEventListener:(name,fn)=>listeners.close=fn}},
|
||||
}};
|
||||
let listCalls=0;
|
||||
const first={{id:'g1',title:'First',candidate_hash:'a1',revision:1,checks:[]}};
|
||||
const second={{id:'g2',title:'Second',candidate_hash:'b2',revision:1,checks:[]}};
|
||||
const app=createProgressiveHumanGates({{
|
||||
document:{{querySelector:selector=>nodes[selector]||null}},
|
||||
location:{{hash:'#/my-work/human-gates'}}, history:{{replaceState(){{}}}},
|
||||
storage:{{getItem:()=>null,setItem(){{}}}}, isOnline:()=>true,
|
||||
getIdentity:async()=>({{login:'timmy',accountKey:'7:timmy'}}),
|
||||
fetchJson:async path=>{{
|
||||
if(path.endsWith('/g1')) return first;
|
||||
if(path.endsWith('/g2')) return second;
|
||||
listCalls += 1;
|
||||
return {{pending_count:1,items:[listCalls === 1 ? first : second]}};
|
||||
}},
|
||||
}});
|
||||
(async()=>{{
|
||||
await app.start();
|
||||
listeners.close();
|
||||
await listeners.open();
|
||||
await new Promise(resolve=>setTimeout(resolve,0));
|
||||
const controller=app.handoff().controller;
|
||||
process.stdout.write(JSON.stringify({{
|
||||
listCalls,current:controller.current().id,hidden:nodes['#human-gates'].hidden,
|
||||
listHtml:nodes['#human-gates-list'].innerHTML,
|
||||
detailHasSecond:nodes['#human-gate-detail'].innerHTML.includes('Second'),
|
||||
}}));
|
||||
}})().catch(error=>{{console.error(error);process.exit(1);}});
|
||||
"""
|
||||
result = subprocess.run(["node", "-e", script], check=True, text=True, capture_output=True)
|
||||
assert json.loads(result.stdout) == {
|
||||
"listCalls": 2,
|
||||
"current": "g2",
|
||||
"hidden": False,
|
||||
"listHtml": '<button class="human-gate-card" type="button" data-human-gate-id="g2"><strong>Second</strong><code>b2</code><span>Priority 0</span></button>',
|
||||
"detailHasSecond": True,
|
||||
}
|
||||
|
||||
|
||||
def test_dashboard_adopts_progressive_human_gates_without_a_second_list_load():
|
||||
dashboard = DASHBOARD.read_text()
|
||||
index = INDEX.read_text()
|
||||
assert 'static/progressive-human-gates.js' in index
|
||||
assert "window.stackchainProgressiveHumanGates?.handoff?.()" in dashboard
|
||||
assert "progressiveHumanGatesHandoff?.controller || createHumanGates" in dashboard
|
||||
assert "if (!progressiveHumanGatesHandoff?.started) humanGates.load()" in dashboard
|
||||
assert "if (window.location.hash === '#/my-work/human-gates' && !progressiveHumanGatesHandoff?.started) openHumanGates()" in dashboard
|
||||
@@ -0,0 +1,24 @@
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
README = Path(__file__).parents[1] / "README.md"
|
||||
|
||||
|
||||
def test_readme_documents_hash_bound_producer_intake_and_revision_decisions():
|
||||
text = README.read_text()
|
||||
assert "POST /api/v1/human-gates/intake" in text
|
||||
assert "Idempotency-Key" in text
|
||||
assert '"candidate_hash"' in text
|
||||
assert "expected_revision" in text
|
||||
assert "STACKCHAIN_HUMAN_GATE_DB" in text
|
||||
assert "principal ID and login" in text
|
||||
assert "reopens the exact hash" in text
|
||||
|
||||
|
||||
def test_readme_defines_privacy_safe_telegram_coalescing_contract():
|
||||
text = README.read_text()
|
||||
assert "Telegram coalescing contract" in text
|
||||
assert "#/my-work/human-gates" in text
|
||||
assert "count and route only" in text
|
||||
assert "candidate hash" in text
|
||||
assert "superseded" in text
|
||||
@@ -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-v138" in source
|
||||
assert "stackchain-dashboard-shell-v146" in source
|
||||
assert "BASE + 'static/later-sync.js'" in source
|
||||
@@ -103,6 +103,87 @@ async def test_live_snapshot_fetches_user_once_and_updates_work_and_activity(mon
|
||||
assert result["revisions"]["context"].endswith(".1")
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_notification_timeout_preserves_healthy_context_and_events(monkeypatch):
|
||||
async def user():
|
||||
return {"id": 1, "login": "timmy"}
|
||||
|
||||
async def empty():
|
||||
return []
|
||||
|
||||
async def events(_authenticated_user):
|
||||
return [{"type": "push"}]
|
||||
|
||||
async def stalled_notifications():
|
||||
await asyncio.Event().wait()
|
||||
|
||||
monkeypatch.setattr(main, "CONTEXT_TIMEOUT_SECONDS", 0.01)
|
||||
monkeypatch.setattr(main, "current_user", user)
|
||||
monkeypatch.setattr(main, "repos", empty)
|
||||
monkeypatch.setattr(main, "issues", empty)
|
||||
monkeypatch.setattr(main, "pull_requests", empty)
|
||||
monkeypatch.setattr(main, "activity_events", events)
|
||||
monkeypatch.setattr(main, "notifications", stalled_notifications)
|
||||
|
||||
response = await main.live_snapshot()
|
||||
result = payload(response)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert result["context"]["user"]["login"] == "timmy"
|
||||
assert result["events"] == [{"type": "push"}]
|
||||
assert result["notifications"] is None
|
||||
assert result["sections"] == {
|
||||
"context": "fresh",
|
||||
"events": "fresh",
|
||||
"notifications": "temporarily unavailable",
|
||||
}
|
||||
assert result["freshness"]["sections"]["context"]["degraded"] is False
|
||||
assert result["freshness"]["sections"]["events"]["degraded"] is False
|
||||
assert result["freshness"]["sections"]["notifications"]["degraded"] is True
|
||||
assert main._live_section_failure_count == {
|
||||
"context": 0,
|
||||
"events": 0,
|
||||
"notifications": 1,
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_identity_timeout_preserves_independent_notifications(monkeypatch):
|
||||
identity_cancelled = asyncio.Event()
|
||||
|
||||
async def stalled_user():
|
||||
try:
|
||||
await asyncio.Event().wait()
|
||||
finally:
|
||||
identity_cancelled.set()
|
||||
|
||||
async def updates():
|
||||
return [{"id": 42, "title": "Mentioned you"}]
|
||||
|
||||
monkeypatch.setattr(main, "CONTEXT_TIMEOUT_SECONDS", 0.01)
|
||||
monkeypatch.setattr(main, "current_user", stalled_user)
|
||||
monkeypatch.setattr(main, "notifications", updates)
|
||||
|
||||
response = await main.live_snapshot()
|
||||
result = payload(response)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert result["context"] is None
|
||||
assert result["events"] is None
|
||||
assert result["notifications"] == [{"id": 42, "title": "Mentioned you"}]
|
||||
assert result["sections"] == {
|
||||
"context": "temporarily unavailable",
|
||||
"events": "temporarily unavailable",
|
||||
"notifications": "fresh",
|
||||
}
|
||||
assert main._live_section_failure_count == {
|
||||
"context": 1,
|
||||
"events": 1,
|
||||
"notifications": 0,
|
||||
}
|
||||
await asyncio.wait_for(identity_cancelled.wait(), timeout=0.1)
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_live_snapshot_omits_section_bodies_at_known_revisions(monkeypatch):
|
||||
async def user():
|
||||
|
||||
@@ -54,7 +54,7 @@ process.stdout.write(JSON.stringify({{ status: status.textContent }}));
|
||||
)
|
||||
|
||||
assert json.loads(result.stdout)["status"] == (
|
||||
"Stackchain locked after inactivity. Your drafts and queued work are still "
|
||||
"Stackchain locked. Your drafts and queued work are still "
|
||||
"on this device. Sign in to resume."
|
||||
)
|
||||
|
||||
|
||||
@@ -221,7 +221,7 @@ def test_markdown_renderer_allows_only_safe_links_and_keeps_html_inert():
|
||||
|
||||
|
||||
def test_all_read_only_work_bodies_use_the_shared_markdown_renderer():
|
||||
dashboard = (FRONTEND / "dashboard.js").read_text()
|
||||
dashboard = (FRONTEND / "dashboard.js").read_text() + (FRONTEND / "conversation.js").read_text()
|
||||
|
||||
expected_paths = (
|
||||
"renderMarkdown(comment.body || 'No comment body provided.')",
|
||||
@@ -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-v138" in worker
|
||||
assert "stackchain-dashboard-shell-v146" in worker
|
||||
@@ -88,6 +88,27 @@ console.log(JSON.stringify({values, clears}));
|
||||
assert result == {"values": [3, 5, 3, 2, 7], "clears": 1}
|
||||
|
||||
|
||||
def test_app_badge_combines_pending_human_gates_with_other_review_channels():
|
||||
result = run_badge("""
|
||||
const values = [];
|
||||
let clears = 0;
|
||||
const controller = createMobileAppBadge({
|
||||
control:{checked:true, disabled:false, addEventListener() {}},
|
||||
status:{textContent:''}, container:{hidden:false},
|
||||
navigator:{async setAppBadge(value) { values.push(value); }, async clearAppBadge() { clears++; }},
|
||||
storage:{getItem() { return 'true'; }, setItem() {}, removeItem() {}},
|
||||
});
|
||||
controller.start();
|
||||
await controller.reconcile('updates', 3, true);
|
||||
await controller.reconcile('human-gates', 2, true);
|
||||
await controller.reconcile('following', 1, true);
|
||||
await controller.reconcile('human-gates', 0, true);
|
||||
console.log(JSON.stringify({values, clears}));
|
||||
""")
|
||||
|
||||
assert result == {"values": [3, 5, 6, 4], "clears": 0}
|
||||
|
||||
|
||||
def test_app_badge_hides_unsupported_device_control_without_touching_storage():
|
||||
result = run_badge("""
|
||||
const control = {checked:false, disabled:false, addEventListener() { throw new Error('must not wire'); }};
|
||||
|
||||
@@ -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-v138" in worker
|
||||
assert "stackchain-dashboard-shell-v146" in worker
|
||||
|
||||
|
||||
def test_all_conversation_composers_offer_accessible_mobile_mentions():
|
||||
|
||||
@@ -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-v138" in worker
|
||||
assert "stackchain-dashboard-shell-v146" in worker
|
||||
assert ".device-setup-panel" in css
|
||||
assert ".device-readiness-card" in css
|
||||
assert "overflow-x:hidden" in css
|
||||
|
||||
@@ -133,6 +133,37 @@ process.stdout.write(JSON.stringify({{current:controller.current(),hash:location
|
||||
}
|
||||
|
||||
|
||||
def test_late_inactive_route_event_does_not_release_background_owned_by_next_overlay():
|
||||
script = f"""
|
||||
const createInsights = require({json.dumps(str(CONTROLLER))});
|
||||
const listeners = {{}};
|
||||
const element = () => ({{
|
||||
hidden:false, inert:false, attributes:{{}}, focuses:0, listeners:{{}},
|
||||
setAttribute(name,value) {{ this.attributes[name] = String(value); }},
|
||||
removeAttribute(name) {{ delete this.attributes[name]; }},
|
||||
addEventListener(name,fn) {{ this.listeners[name] = fn; }},
|
||||
focus() {{ this.focuses += 1; }},
|
||||
}});
|
||||
const root=element(), launcher=element(), closeButton=element(), dock=element(), hud=element(), header=element();
|
||||
const location={{pathname:'/dashboard/', search:'', hash:'#/insights'}};
|
||||
const history={{state:null, pushState() {{}}, back() {{}}, replaceState(state,unused,url) {{
|
||||
this.state=state; location.hash=url.slice(url.indexOf('#'));
|
||||
}}}};
|
||||
const controller=createInsights({{
|
||||
root,launcher,closeButton,dock,hud,backgrounds:[header],history,location,
|
||||
eventTarget:{{addEventListener(name,fn) {{ listeners[name]=fn; }}}},
|
||||
mediaQuery:{{matches:true,addEventListener() {{}}}},
|
||||
}});
|
||||
controller.start();
|
||||
closeButton.listeners.click();
|
||||
header.inert = true;
|
||||
listeners.hashchange();
|
||||
process.stdout.write(JSON.stringify({{current:controller.current(), headerInert:header.inert}}));
|
||||
"""
|
||||
|
||||
assert run_node(script) == {"current": False, "headerInert": True}
|
||||
|
||||
|
||||
def test_escape_requests_back_navigation_only_while_insights_is_open():
|
||||
script = f"""
|
||||
const createInsights=require({json.dumps(str(CONTROLLER))});
|
||||
@@ -243,5 +274,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-v138" in worker
|
||||
assert "stackchain-dashboard-shell-v146" in worker
|
||||
assert "BASE + 'static/mobile-insights.js'" in worker
|
||||
@@ -96,7 +96,13 @@ async def test_mobile_launch_progressively_discloses_secondary_controls():
|
||||
assert "BASE + 'static/mobile-app-shortcuts.js'" in service_worker
|
||||
bootstrap = (Path(__file__).resolve().parents[1] / "frontend" / "dashboard.js").read_text()
|
||||
assert "mobileAppShortcuts.createController" in bootstrap
|
||||
assert bootstrap.index("await load();\n await appShortcut.run();") < bootstrap.index("contextPoller.start();")
|
||||
adopted = bootstrap.index(
|
||||
"let adoptedProgressiveSnapshot = contextPoller.adopt(progressiveWorkHandoff?.liveSnapshot);"
|
||||
)
|
||||
fallback = bootstrap.index("if (!adoptedProgressiveSnapshot) await load();")
|
||||
shortcuts = bootstrap.index("await appShortcut.run();")
|
||||
assert adopted < fallback < shortcuts
|
||||
assert "contextPoller.start();" not in bootstrap
|
||||
assert "mobileLaunch.chooseFilter" in html
|
||||
assert "agenda: counts.agenda" in html
|
||||
assert "mobileLaunch.createDisclosure" in html
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
import json
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
CONTROLLER = ROOT / "frontend" / "mobile-search-modal.js"
|
||||
|
||||
|
||||
def run_node(script: str) -> dict:
|
||||
completed = subprocess.run(["node", "-e", script], capture_output=True, text=True)
|
||||
assert completed.returncode == 0, completed.stderr
|
||||
return json.loads(completed.stdout)
|
||||
|
||||
|
||||
def test_search_preview_journey_keeps_background_inert_and_restores_prior_state():
|
||||
script = f"""
|
||||
const createModal = require({json.dumps(str(CONTROLLER))});
|
||||
const listeners = {{}};
|
||||
const element = (name) => ({{
|
||||
name, inert:false, isConnected:true, hidden:false, disabled:false, focuses:0,
|
||||
focus() {{ this.focuses += 1; }},
|
||||
matches() {{ return true; }},
|
||||
}});
|
||||
const header=element('header'), main=element('main'), dock=element('dock'); dock.inert=true;
|
||||
const palette=element('palette'), preview=element('preview');
|
||||
const input=element('input'), close=element('close'), opener=element('opener');
|
||||
palette.querySelectorAll=()=>[input]; preview.querySelectorAll=()=>[close];
|
||||
const controller=createModal({{
|
||||
document:{{addEventListener(name,fn){{listeners[name]=fn;}}}},
|
||||
backgrounds:[header,main,dock],
|
||||
}});
|
||||
controller.activate(palette, {{opener, initialFocus:input}});
|
||||
const opened=[header.inert,main.inert,dock.inert,input.focuses];
|
||||
controller.transition(preview, {{initialFocus:close}});
|
||||
const previewed=[header.inert,main.inert,dock.inert,close.focuses,controller.current()===preview];
|
||||
controller.transition(palette, {{initialFocus:input}});
|
||||
const returned=[header.inert,main.inert,dock.inert,input.focuses];
|
||||
controller.deactivate();
|
||||
process.stdout.write(JSON.stringify({{opened,previewed,returned,restored:[header.inert,main.inert,dock.inert,opener.focuses]}}));
|
||||
"""
|
||||
assert run_node(script) == {
|
||||
"opened": [True, True, True, 1],
|
||||
"previewed": [True, True, True, 1, True],
|
||||
"returned": [True, True, True, 2],
|
||||
"restored": [False, False, True, 1],
|
||||
}
|
||||
|
||||
|
||||
def test_tab_and_shift_tab_wrap_dynamic_visible_controls_on_active_surface():
|
||||
script = f"""
|
||||
const createModal = require({json.dumps(str(CONTROLLER))});
|
||||
const listeners={{}};
|
||||
const element=(name)=>({{name,inert:false,isConnected:true,hidden:false,disabled:false,focuses:0,
|
||||
focus(){{this.focuses+=1;}},matches(selector){{return !this.hidden;}}}});
|
||||
const surface=element('surface'), first=element('first'), middle=element('middle'), last=element('last');
|
||||
const hidden=element('hidden'); hidden.hidden=true; const disabled=element('disabled'); disabled.disabled=true;
|
||||
surface.querySelectorAll=()=>[first,hidden,middle,disabled,last];
|
||||
const document={{activeElement:last,addEventListener(name,fn){{listeners[name]=fn;}}}};
|
||||
const controller=createModal({{document,backgrounds:[]}});
|
||||
controller.activate(surface,{{initialFocus:first}});
|
||||
let prevented=0;
|
||||
document.activeElement=last; listeners.keydown({{key:'Tab',shiftKey:false,preventDefault(){{prevented+=1;}}}});
|
||||
document.activeElement=first; listeners.keydown({{key:'Tab',shiftKey:true,preventDefault(){{prevented+=1;}}}});
|
||||
// A newly rendered enabled control becomes the last stop without remounting.
|
||||
const dynamic=element('dynamic'); surface.querySelectorAll=()=>[first,middle,last,dynamic];
|
||||
document.activeElement=dynamic; listeners.keydown({{key:'Tab',shiftKey:false,preventDefault(){{prevented+=1;}}}});
|
||||
process.stdout.write(JSON.stringify({{first:first.focuses,last:last.focuses,prevented}}));
|
||||
"""
|
||||
assert run_node(script) == {"first": 3, "last": 1, "prevented": 3}
|
||||
|
||||
|
||||
def test_disconnected_opener_is_not_focused_on_final_close():
|
||||
script = f"""
|
||||
const createModal=require({json.dumps(str(CONTROLLER))});
|
||||
const surface={{querySelectorAll(){{return[];}}}};
|
||||
const opener={{isConnected:true,focuses:0,focus(){{this.focuses+=1;}}}};
|
||||
const document={{addEventListener(){{}}}};
|
||||
const controller=createModal({{document,backgrounds:[]}});
|
||||
controller.activate(surface,{{opener}}); opener.isConnected=false; controller.deactivate();
|
||||
process.stdout.write(JSON.stringify({{focuses:opener.focuses}}));
|
||||
"""
|
||||
assert run_node(script) == {"focuses": 0}
|
||||
|
||||
|
||||
def test_controls_inside_collapsed_sections_are_excluded_from_tab_order():
|
||||
script = f"""
|
||||
const createModal=require({json.dumps(str(CONTROLLER))});
|
||||
const listeners={{}};
|
||||
const visible={{disabled:false,hidden:false,isConnected:true,focuses:0,matches(){{return true;}},getClientRects(){{return [{{}}];}},focus(){{this.focuses+=1;}}}};
|
||||
const collapsed={{...visible,getClientRects(){{return [];}}}};
|
||||
const surface={{querySelectorAll(){{return [visible,collapsed];}}}};
|
||||
const document={{activeElement:visible,addEventListener(name,fn){{listeners[name]=fn;}}}};
|
||||
const controller=createModal({{document,backgrounds:[]}}); controller.activate(surface);
|
||||
let prevented=0; listeners.keydown({{key:'Tab',shiftKey:false,preventDefault(){{prevented+=1;}}}});
|
||||
process.stdout.write(JSON.stringify({{prevented,focuses:visible.focuses}}));
|
||||
"""
|
||||
assert run_node(script) == {"prevented": 1, "focuses": 2}
|
||||
|
||||
|
||||
def test_search_modal_is_packaged_with_accessible_semantics():
|
||||
html = (ROOT / "frontend" / "index.html").read_text()
|
||||
dashboard = (ROOT / "frontend" / "dashboard.js").read_text()
|
||||
bundle = (ROOT / "src" / "frontend_bundle.py").read_text()
|
||||
|
||||
assert 'id="cmd-palette" role="dialog" aria-modal="true"' in html
|
||||
assert '<script src="static/mobile-search-modal.js"></script>' in html
|
||||
assert '"static/mobile-search-modal.js"' in bundle
|
||||
assert "createMobileSearchModal({" in dashboard
|
||||
assert "searchModal.transition(qs('#search-preview')" in dashboard
|
||||
@@ -110,6 +110,61 @@ process.stdout.write(JSON.stringify({{blocked, handed, opened, handoffs}}));
|
||||
assert output["handoffs"] == ["agenda"]
|
||||
|
||||
|
||||
def test_prepare_today_reviews_human_gates_after_delivery_before_agenda():
|
||||
script = f"""
|
||||
const createStartDay = require({json.dumps(str(START_DAY))});
|
||||
const opened = [];
|
||||
const controller = createStartDay({{
|
||||
getCounts: () => ({{delivery:1, gate:2, agenda:1, today:4}}),
|
||||
openQueue: name => opened.push(name),
|
||||
}});
|
||||
const briefing = controller.briefing();
|
||||
controller.startNext();
|
||||
process.stdout.write(JSON.stringify({{briefing, opened}}));
|
||||
"""
|
||||
|
||||
output = run_node(script)
|
||||
assert output == {
|
||||
"briefing": {
|
||||
"total": 4,
|
||||
"next": "delivery",
|
||||
"label": "Review Delivery",
|
||||
"summary": "1 delivery needs action before Today · 3 other items · 4 planned",
|
||||
"phases": [
|
||||
{"name": "delivery", "label": "Delivery recovery", "count": 1},
|
||||
{"name": "gate", "label": "Human Gates", "count": 2},
|
||||
{"name": "agenda", "label": "Agenda", "count": 1},
|
||||
],
|
||||
},
|
||||
"opened": ["delivery"],
|
||||
}
|
||||
|
||||
|
||||
def test_prepare_today_keeps_unavailable_human_gates_retryable_before_today():
|
||||
script = f"""
|
||||
const createStartDay = require({json.dumps(str(START_DAY))});
|
||||
const opened = [];
|
||||
const controller = createStartDay({{
|
||||
getCounts: () => ({{gateUnavailable:true, today:2}}),
|
||||
openQueue: name => opened.push(name),
|
||||
}});
|
||||
const briefing = controller.briefing();
|
||||
controller.startNext();
|
||||
process.stdout.write(JSON.stringify({{briefing, opened}}));
|
||||
"""
|
||||
|
||||
assert run_node(script) == {
|
||||
"briefing": {
|
||||
"total": 0,
|
||||
"next": "gate",
|
||||
"label": "Retry Human Gates",
|
||||
"summary": "Human Gates need retry before Today · 2 planned",
|
||||
"phases": [{"name": "gate", "label": "Human Gates unavailable · retry", "count": 0}],
|
||||
},
|
||||
"opened": ["gate"],
|
||||
}
|
||||
|
||||
|
||||
def test_prepare_today_counts_each_work_identity_in_only_its_highest_priority_phase():
|
||||
script = f"""
|
||||
const createStartDay = require({json.dumps(str(START_DAY))});
|
||||
@@ -414,7 +469,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-v138" in service_worker
|
||||
assert "stackchain-dashboard-shell-v146" in service_worker
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
|
||||
@@ -279,6 +279,27 @@ process.stdout.write(JSON.stringify({{calls, open:queues.open}}));
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_mobile_queue_sheet_prioritizes_next_active_and_planning_without_duplicate_rows():
|
||||
html = await dashboard()
|
||||
|
||||
assert 'aria-labelledby="mobile-queue-next-heading"' in html
|
||||
assert 'id="mobile-queue-next-action"' in html
|
||||
assert 'aria-labelledby="mobile-queue-active-heading"' in html
|
||||
assert 'id="mobile-queue-active-list"' in html
|
||||
assert 'aria-labelledby="mobile-queue-planning-heading"' in html
|
||||
assert 'id="mobile-queue-planning-list"' in html
|
||||
assert '<details class="mobile-queue-all"' in html
|
||||
assert 'id="mobile-queue-all-list"' in html
|
||||
assert "nextAction: qs('#mobile-queue-next-action')" in html
|
||||
assert "activeList: qs('#mobile-queue-active-list')" in html
|
||||
assert "mobileQueueLauncher.renderPresentation();" in html
|
||||
assert "queueCounts.followingUnavailable = status === 'error';\n renderMobileQueuePresentation();" in html
|
||||
assert "mobileQueueLauncher.continueWork()" in html
|
||||
for name in ("today", "tomorrow", "week", "agenda", "delivery", "gate", "attention", "update", "following", "filed", "authored", "later", "draft", "find", "recaps"):
|
||||
assert html.count(f'<button data-mobile-queue="{name}"') == 1
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_find_and_queue_detours_are_visible_and_wired_to_today_timing():
|
||||
html = await dashboard()
|
||||
@@ -469,7 +490,7 @@ sheet.close = function () {{ this.open = false; this.listeners.close?.(); }};
|
||||
const close = new FakeElement();
|
||||
const badge = new FakeElement();
|
||||
const deadline = new FakeElement();
|
||||
const rows = Object.fromEntries(['today','agenda','delivery','attention','update','filed','later','draft','recaps'].map(name => [name, new FakeElement()]));
|
||||
const rows = Object.fromEntries(['today','agenda','delivery','gate','attention','update','filed','later','draft','recaps'].map(name => [name, new FakeElement()]));
|
||||
const counts = Object.fromEntries(Object.keys(rows).map(name => [name, new FakeElement()]));
|
||||
const selected = [];
|
||||
const utilities = [];
|
||||
@@ -480,7 +501,7 @@ const dock = createDock({{
|
||||
observe() {{}},
|
||||
}});
|
||||
dock.start();
|
||||
dock.updateQueues({{today:2, agenda:5, delivery:1, attention:1, update:5, filed:2, later:3, draft:4}});
|
||||
dock.updateQueues({{today:2, agenda:5, delivery:1, gate:2, attention:1, update:5, filed:2, later:3, draft:4}});
|
||||
queues.click();
|
||||
const opened = sheet.open;
|
||||
rows.update.click();
|
||||
@@ -525,9 +546,9 @@ process.stdout.write(JSON.stringify({{
|
||||
"utilities": ["recaps:trigger"],
|
||||
"badge": "0 active",
|
||||
"populated": {
|
||||
"badge": "7 active",
|
||||
"badge": "8 active",
|
||||
"badgeHidden": False,
|
||||
"badgeLabel": "Queues: Today 2, Agenda 5 due, Delivery 1, Attention 1, Updates 5, Filed 2, Later 3, Drafts 4; 7 active queues",
|
||||
"badgeLabel": "Queues: Today 2, Agenda 5 due, Delivery 1, Human Gates 2, Attention 1, Updates 5, Filed 2, Later 3, Drafts 4; 8 active queues",
|
||||
"deadline": "5 due",
|
||||
"deadlineHidden": False,
|
||||
"agendaDue": "true",
|
||||
@@ -536,13 +557,13 @@ process.stdout.write(JSON.stringify({{
|
||||
"badge": "1 active",
|
||||
"badgeHidden": False,
|
||||
"deadlineHidden": True,
|
||||
"badgeLabel": "Queues: Today 0, Agenda 0 due, Delivery 0, Attention 0, Updates 7, Filed 0, Later 0, Drafts 0; 1 active queue",
|
||||
"badgeLabel": "Queues: Today 0, Agenda 0 due, Delivery 0, Human Gates 0, Attention 0, Updates 7, Filed 0, Later 0, Drafts 0; 1 active queue",
|
||||
},
|
||||
"clearedBadgeHidden": True,
|
||||
"clearedDeadlineHidden": True,
|
||||
"clearedAgendaDue": None,
|
||||
"clearedBadgeLabel": "Queues: no active queues; no upcoming deadlines",
|
||||
"counts": {"today": "0", "agenda": "0", "delivery": "0", "attention": "0", "update": "0", "filed": "0", "later": "0", "draft": "0", "recaps": "0"},
|
||||
"counts": {"today": "0", "agenda": "0", "delivery": "0", "gate": "0", "attention": "0", "update": "0", "filed": "0", "later": "0", "draft": "0", "recaps": "0"},
|
||||
"updateLabel": "Updates, 0 unread conversations",
|
||||
"queueFocuses": 3,
|
||||
"columnState": None,
|
||||
@@ -599,6 +620,27 @@ process.stdout.write(JSON.stringify({{result, calls}}));
|
||||
}
|
||||
|
||||
|
||||
def test_mobile_queue_launcher_uses_existing_human_gate_review_flow():
|
||||
script = f"""
|
||||
const createLauncher = require({json.dumps(str(QUEUE_LAUNCHER))});
|
||||
const calls = [];
|
||||
const launcher = createLauncher({{
|
||||
openHumanGates: () => {{ calls.push('human-gates'); return 'opened-gates'; }},
|
||||
selectFilter: name => calls.push('generic-filter:' + name),
|
||||
firstAction: () => {{ throw new Error('generic card launch must not run'); }},
|
||||
announce: message => calls.push('announce:' + message),
|
||||
}});
|
||||
process.stdout.write(JSON.stringify({{result:launcher.open('gate'), calls}}));
|
||||
"""
|
||||
result = subprocess.run(["node", "-e", script], capture_output=True, text=True)
|
||||
|
||||
assert result.returncode == 0, result.stderr
|
||||
assert json.loads(result.stdout) == {
|
||||
"result": "opened-gates",
|
||||
"calls": ["human-gates"],
|
||||
}
|
||||
|
||||
|
||||
def test_mobile_queue_launcher_uses_dedicated_delivery_recovery_flow():
|
||||
script = f"""
|
||||
const createLauncher = require({json.dumps(str(QUEUE_LAUNCHER))});
|
||||
@@ -621,7 +663,7 @@ def test_mobile_work_prioritizes_and_revalidates_actionable_delivery_recovery():
|
||||
script = f"""
|
||||
const createLauncher = require({json.dumps(str(QUEUE_LAUNCHER))});
|
||||
const calls = [];
|
||||
let counts = {{delivery:2, attention:3, today:1, update:4}};
|
||||
let counts = {{delivery:2, gate:1, attention:3, today:1, update:4}};
|
||||
const launcher = createLauncher({{
|
||||
getCounts: () => counts,
|
||||
openDelivery: () => {{ calls.push('delivery-recovery'); return 'opened-delivery'; }},
|
||||
@@ -633,7 +675,7 @@ const launcher = createLauncher({{
|
||||
}});
|
||||
const delivery = launcher.recommend();
|
||||
const opened = launcher.continueWork();
|
||||
counts = {{delivery:0, attention:0, today:0, update:4}};
|
||||
counts = {{delivery:0, gate:1, attention:0, today:0, update:4}};
|
||||
const afterRecovery = launcher.recommend();
|
||||
process.stdout.write(JSON.stringify({{delivery, opened, afterRecovery, calls}}));
|
||||
"""
|
||||
@@ -643,7 +685,7 @@ process.stdout.write(JSON.stringify({{delivery, opened, afterRecovery, calls}}))
|
||||
assert json.loads(result.stdout) == {
|
||||
"delivery": {"name": "delivery", "count": 2, "label": "Recover Delivery (2)"},
|
||||
"opened": "opened-delivery",
|
||||
"afterRecovery": {"name": "update", "count": 4, "label": "Resume Updates (4)"},
|
||||
"afterRecovery": {"name": "gate", "count": 1, "label": "Review Human Gates (1)"},
|
||||
"calls": ["delivery-recovery"],
|
||||
}
|
||||
|
||||
@@ -710,6 +752,73 @@ process.stdout.write(JSON.stringify({{first, agenda, opened, fallback, calls}}))
|
||||
}
|
||||
|
||||
|
||||
def test_mobile_queue_launcher_builds_truthful_next_up_and_active_sections():
|
||||
script = f"""
|
||||
const createLauncher = require({json.dumps(str(QUEUE_LAUNCHER))});
|
||||
const counts = {{delivery:1, gate:2, today:3, authored:4, update:0, attentionUnavailable:true, followingUnavailable:true}};
|
||||
const launcher = createLauncher({{getCounts:() => counts}});
|
||||
process.stdout.write(JSON.stringify(launcher.presentation()));
|
||||
"""
|
||||
result = subprocess.run(["node", "-e", script], capture_output=True, text=True)
|
||||
|
||||
assert result.returncode == 0, result.stderr
|
||||
assert json.loads(result.stdout) == {
|
||||
"nextUp": {"name": "delivery", "count": 1, "label": "Recover Delivery (1)"},
|
||||
"active": [
|
||||
{"name": "delivery", "count": 1},
|
||||
{"name": "gate", "count": 2},
|
||||
{"name": "today", "count": 3},
|
||||
{"name": "authored", "count": 4},
|
||||
{"name": "attention", "unavailable": True},
|
||||
{"name": "following", "unavailable": True},
|
||||
],
|
||||
"planning": ["today", "tomorrow", "week"],
|
||||
"all": [
|
||||
"today", "tomorrow", "week", "agenda", "delivery", "gate",
|
||||
"attention", "update", "following", "filed", "authored", "later",
|
||||
"draft", "find", "recaps",
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def test_mobile_queue_launcher_renders_one_set_of_rows_into_adaptive_groups():
|
||||
script = f"""
|
||||
const createLauncher = require({json.dumps(str(QUEUE_LAUNCHER))});
|
||||
class Box {{
|
||||
constructor(name) {{ this.name=name; this.children=[]; this.hidden=false; this.attributes={{}}; this.textContent=''; this.dataset={{}}; }}
|
||||
append(row) {{ if (row.parent) row.parent.children=row.parent.children.filter(item => item !== row); this.children.push(row); row.parent=this; }}
|
||||
setAttribute(name, value) {{ this.attributes[name]=value; }}
|
||||
removeAttribute(name) {{ delete this.attributes[name]; }}
|
||||
}}
|
||||
const names=['today','tomorrow','week','agenda','delivery','gate','attention','update','following','filed','authored','later','draft','find','recaps'];
|
||||
const rows=Object.fromEntries(names.map(name => [name,new Box(name)]));
|
||||
const nextAction=new Box('next');
|
||||
const activeList=new Box('active'); const planningList=new Box('planning'); const allList=new Box('all');
|
||||
const activeSection=new Box('active-section');
|
||||
const launcher=createLauncher({{
|
||||
getCounts:()=>({{delivery:1,gate:2,today:3,attentionUnavailable:true}}), rows,
|
||||
nextAction, activeList, planningList, allList, activeSection,
|
||||
}});
|
||||
launcher.renderPresentation();
|
||||
process.stdout.write(JSON.stringify({{
|
||||
next:[nextAction.textContent,nextAction.dataset.queue,nextAction.attributes['aria-label']],
|
||||
active:activeList.children.map(row => [row.name,row.attributes['data-unavailable'] || null]),
|
||||
planning:planningList.children.map(row => row.name),
|
||||
all:allList.children.map(row => row.name), activeHidden:activeSection.hidden,
|
||||
}}));
|
||||
"""
|
||||
result = subprocess.run(["node", "-e", script], capture_output=True, text=True)
|
||||
|
||||
assert result.returncode == 0, result.stderr
|
||||
assert json.loads(result.stdout) == {
|
||||
"next": ["Recover Delivery (1)", "delivery", "Next up: Recover Delivery (1)"],
|
||||
"active": [["delivery", None], ["gate", None], ["attention", "true"]],
|
||||
"planning": ["today", "tomorrow", "week"],
|
||||
"all": ["agenda", "update", "following", "filed", "authored", "later", "draft", "find", "recaps"],
|
||||
"activeHidden": False,
|
||||
}
|
||||
|
||||
|
||||
def test_mobile_queue_launcher_prioritizes_updates_before_agenda_and_resumes_launcher():
|
||||
script = f"""
|
||||
const createLauncher = require({json.dumps(str(QUEUE_LAUNCHER))});
|
||||
|
||||
@@ -122,6 +122,53 @@ process.stdout.write(JSON.stringify(buildMyWork({json.dumps(payload)})));
|
||||
assert result[0]["kind"] == "pull"
|
||||
|
||||
|
||||
def test_authored_pull_branch_update_is_single_flight_and_head_guarded():
|
||||
script = f"""
|
||||
const createPullSheet = require({json.dumps(str(PULL_SHEET))});
|
||||
const calls = [];
|
||||
let resolve;
|
||||
const pending = new Promise(done => {{ resolve = done; }});
|
||||
const controller = createPullSheet({{
|
||||
fetchJson:(url, options) => {{ calls.push([url, options]); return pending; }},
|
||||
storage:{{}},
|
||||
}});
|
||||
const item = {{repository:'stackchain/api', number:7}};
|
||||
const first = controller.updateBranch(item, 'abc1234');
|
||||
const second = controller.updateBranch(item, 'abc1234');
|
||||
resolve({{previous_head_sha:'abc1234', head_sha:'def5678'}});
|
||||
Promise.all([first, second]).then(results => process.stdout.write(JSON.stringify({{
|
||||
same:first === second,
|
||||
calls:calls.map(([url, options]) => [url, options.method, JSON.parse(options.body)]),
|
||||
heads:results.map(result => result.head_sha),
|
||||
}}))).catch(error => {{ console.error(error); process.exit(1); }});
|
||||
"""
|
||||
completed = subprocess.run(["node", "-e", script], text=True, capture_output=True)
|
||||
|
||||
assert completed.returncode == 0, completed.stderr
|
||||
assert json.loads(completed.stdout) == {
|
||||
"same": True,
|
||||
"calls": [[
|
||||
"api/v1/repos/stackchain/api/pulls/7/update-branch",
|
||||
"POST",
|
||||
{"expected_head_sha": "abc1234"},
|
||||
]],
|
||||
"heads": ["def5678", "def5678"],
|
||||
}
|
||||
|
||||
|
||||
def test_mobile_pull_review_exposes_update_branch_recovery():
|
||||
frontend = Path(__file__).parents[1] / "frontend"
|
||||
html = (frontend / "index.html").read_text()
|
||||
source = PULL_SHEET.read_text()
|
||||
css = (frontend / "dashboard.css").read_text()
|
||||
|
||||
assert 'id="update-pull-branch"' in html
|
||||
assert 'id="pull-branch-update-status"' in html
|
||||
assert "controller.updateBranch(item, detail.head_sha)" in source
|
||||
assert "doc.querySelector('#pull-review-retry')?.click()" in source
|
||||
assert ".pull-branch-update button" in css and "min-height:44px" in css
|
||||
|
||||
|
||||
def test_my_prs_filter_and_count_include_only_authored_pulls():
|
||||
script = f"""
|
||||
const buildMyWork = require({json.dumps(str(MY_WORK))});
|
||||
@@ -7642,6 +7689,39 @@ process.stdout.write(JSON.stringify({{
|
||||
assert output["released"] == "stackchain/api#7 released. Choose the next ready Today item."
|
||||
|
||||
|
||||
def test_authored_unassigned_pull_hides_assignment_ownership_controls():
|
||||
script = f"""
|
||||
const createPullSheet = require({json.dumps(str(PULL_SHEET))});
|
||||
const elements = new Map([
|
||||
['#pull-ownership', {{open:true,hidden:false,inert:false}}],
|
||||
['#pull-handoff-recipient', {{innerHTML:'stale',disabled:false}}],
|
||||
['#confirm-pull-handoff', {{disabled:false,textContent:''}}],
|
||||
['#load-pull-handoff', {{disabled:false}}],
|
||||
['#release-pull', {{disabled:false,textContent:''}}],
|
||||
['#pull-handoff-status', {{textContent:''}}],
|
||||
['#edit-pull-content', {{hidden:false}}],
|
||||
['#pull-edit-form', {{hidden:false}}],
|
||||
['#pull-edit-status', {{textContent:'stale'}}],
|
||||
]);
|
||||
const doc = {{querySelector:selector => elements.get(selector)}};
|
||||
createPullSheet.resetOwnershipControls(
|
||||
doc,
|
||||
{{key:'stackchain/api#7'}},
|
||||
() => false,
|
||||
{{authored:true,assigned:false}}
|
||||
);
|
||||
process.stdout.write(JSON.stringify(Object.fromEntries(elements)));
|
||||
"""
|
||||
output = json.loads(subprocess.run(
|
||||
["node", "-e", script], check=True, capture_output=True, text=True
|
||||
).stdout)
|
||||
|
||||
assert output["#pull-ownership"]["hidden"] is True
|
||||
assert output["#pull-ownership"]["inert"] is True
|
||||
assert output["#load-pull-handoff"]["disabled"] is True
|
||||
assert output["#release-pull"]["disabled"] is True
|
||||
|
||||
|
||||
def test_pull_sheet_single_flights_handoff_and_release_ownership_mutations():
|
||||
script = f"""
|
||||
const createPullSheet = require({json.dumps(str(PULL_SHEET))});
|
||||
@@ -8670,6 +8750,76 @@ process.stdout.write(JSON.stringify({{result, offline}}));
|
||||
assert output["offline"]["summary"].startswith("Last known · ")
|
||||
|
||||
|
||||
def test_failed_actions_check_renders_in_app_recovery_control_only_when_supported():
|
||||
script = f"""
|
||||
const reviewSheet = require({json.dumps(str(REVIEW_SHEET))});
|
||||
const escapeHtml = value => String(value)
|
||||
.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"');
|
||||
const supported = reviewSheet.renderChecks([
|
||||
{{name:'CI / lint', state:'failure', url:'https://forge.example/jobs/3', recovery:{{run_id:91, job_index:3}}}},
|
||||
], escapeHtml);
|
||||
const external = reviewSheet.renderChecks([
|
||||
{{name:'Vendor scan', state:'failure', url:'https://forge.example/jobs/4'}},
|
||||
], escapeHtml);
|
||||
process.stdout.write(JSON.stringify({{supported, external}}));
|
||||
"""
|
||||
result = subprocess.run(
|
||||
["node", "-e", script], check=True, capture_output=True, text=True
|
||||
)
|
||||
output = json.loads(result.stdout)
|
||||
|
||||
assert 'class="ci-check-inspect"' in output["supported"]["html"]
|
||||
assert 'data-run-id="91"' in output["supported"]["html"]
|
||||
assert 'data-job-index="3"' in output["supported"]["html"]
|
||||
assert "Inspect failure" in output["supported"]["html"]
|
||||
assert "ci-check-inspect" not in output["external"]["html"]
|
||||
assert "Open job" in output["external"]["html"]
|
||||
|
||||
|
||||
def test_pull_controller_loads_failure_and_retries_exact_head():
|
||||
script = f"""
|
||||
const createPullSheet = require({json.dumps(str(PULL_SHEET))});
|
||||
const calls = [];
|
||||
const controller = createPullSheet({{
|
||||
fetchJson: async (url, options) => {{ calls.push({{url, options}}); return {{status:'queued'}}; }},
|
||||
storage: null,
|
||||
}});
|
||||
const item = {{repository:'stackchain/api', number:7}};
|
||||
controller.loadCheckFailure(item, 'abc1234', 91, 3).then(() =>
|
||||
controller.retryCheck(item, 'abc1234', 91, 3)
|
||||
).then(() => process.stdout.write(JSON.stringify(calls)));
|
||||
"""
|
||||
result = subprocess.run(
|
||||
["node", "-e", script], check=True, capture_output=True, text=True
|
||||
)
|
||||
calls = json.loads(result.stdout)
|
||||
|
||||
assert calls[0]["url"].endswith(
|
||||
"/pulls/7/checks/91/jobs/3/failure?expected_head_sha=abc1234"
|
||||
)
|
||||
assert calls[0]["options"]["headers"]["Accept"] == "application/json"
|
||||
assert calls[1]["url"].endswith("/pulls/7/checks/91/jobs/3/retry")
|
||||
assert calls[1]["options"]["method"] == "POST"
|
||||
assert json.loads(calls[1]["options"]["body"]) == {"expected_head_sha": "abc1234"}
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_mobile_pull_workspace_packages_accessible_ci_recovery_panel():
|
||||
html = await dashboard()
|
||||
|
||||
assert 'id="pull-check-recovery"' in html
|
||||
assert 'id="pull-check-recovery-title"' in html
|
||||
assert 'id="pull-check-log"' in html
|
||||
assert 'id="retry-pull-check"' in html
|
||||
assert 'id="close-pull-check-recovery"' in html
|
||||
assert 'aria-live="assertive"' in html
|
||||
assert "createPullSheet.bindOwnershipControls" in html
|
||||
assert "#pull-check-list" in html and "ci-check-inspect" in html
|
||||
assert ".ci-check-recovery" in html and "max-width:100%" in html
|
||||
assert ".ci-check-log" in html and "overflow-x:auto" in html
|
||||
assert ".ci-check-actions" in html and "min-height:44px" in html
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_mobile_pull_review_sheets_refresh_checks_without_reloading_diffs():
|
||||
html = await dashboard()
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
import json
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
MODULE = Path(__file__).parents[1] / "frontend" / "photo-draft-inbox.js"
|
||||
INDEX = Path(__file__).parents[1] / "frontend" / "index.html"
|
||||
DASHBOARD = Path(__file__).parents[1] / "frontend" / "dashboard.js"
|
||||
WORKER = Path(__file__).parents[1] / "frontend" / "service-worker.js"
|
||||
BUNDLE = Path(__file__).parents[1] / "src" / "frontend_bundle.py"
|
||||
|
||||
|
||||
def run_node(script: str):
|
||||
completed = subprocess.run(["node", "-e", script], check=True, capture_output=True, text=True)
|
||||
return json.loads(completed.stdout)
|
||||
|
||||
|
||||
def test_photo_draft_inbox_combines_stores_without_duplicate_target_cards_and_discards_exact_bundle():
|
||||
script = f"""
|
||||
const createPhotoDraftInbox = require({json.dumps(str(MODULE))});
|
||||
const removed=[];
|
||||
const conversation={{
|
||||
list:async()=>[
|
||||
{{id:'conversation-issue',kind:'photo-reply',photo_store:'conversation',title:'o/r#7',updated_at:30,route:{{kind:'issue',repository:'o/r',number:7}}}},
|
||||
{{id:'conversation-update',kind:'photo-reply',photo_store:'conversation',title:'Update #8',updated_at:20,route:{{kind:'update',notification_id:8}}}},
|
||||
],
|
||||
remove:async target=>removed.push(['conversation',target]),
|
||||
}};
|
||||
const search={{
|
||||
list:async()=>[
|
||||
{{id:'search-pull',kind:'photo-reply',photo_store:'search',title:'o/r#9',updated_at:40,route:{{kind:'search',target_kind:'pull',repository:'o/r',number:9}}}},
|
||||
],
|
||||
remove:async target=>removed.push(['search',target]),
|
||||
}};
|
||||
const inbox=createPhotoDraftInbox({{conversation,search}});
|
||||
(async()=>{{
|
||||
const drafts=await inbox.refresh([{{kind:'issue-comment',route:{{kind:'issue',repository:'o/r',number:7}}}}]);
|
||||
const description=inbox.description({{kind:'photo-reply',photo_count:2}});
|
||||
const searchTarget=inbox.searchTarget(drafts[0]);
|
||||
await inbox.discard(drafts[0]);
|
||||
process.stdout.write(JSON.stringify({{drafts,description,searchTarget,remaining:inbox.list(),removed}}));
|
||||
}})().catch(error=>{{console.error(error);process.exit(1);}});
|
||||
"""
|
||||
assert run_node(script) == {
|
||||
"drafts": [
|
||||
{
|
||||
"id": "search-pull",
|
||||
"kind": "photo-reply",
|
||||
"photo_store": "search",
|
||||
"title": "o/r#9",
|
||||
"updated_at": 40,
|
||||
"route": {"kind": "search", "target_kind": "pull", "repository": "o/r", "number": 9},
|
||||
},
|
||||
{
|
||||
"id": "conversation-update",
|
||||
"kind": "photo-reply",
|
||||
"photo_store": "conversation",
|
||||
"title": "Update #8",
|
||||
"updated_at": 20,
|
||||
"route": {"kind": "update", "notification_id": 8},
|
||||
},
|
||||
],
|
||||
"description": "2 saved photos",
|
||||
"searchTarget": {"kind": "pull", "repository": "o/r", "number": 9, "title": "o/r#9"},
|
||||
"remaining": [
|
||||
{
|
||||
"id": "conversation-update",
|
||||
"kind": "photo-reply",
|
||||
"photo_store": "conversation",
|
||||
"title": "Update #8",
|
||||
"updated_at": 20,
|
||||
"route": {"kind": "update", "notification_id": 8},
|
||||
}
|
||||
],
|
||||
"removed": [["search", {"kind": "pull", "repository": "o/r", "number": 9}]],
|
||||
}
|
||||
|
||||
|
||||
def test_photo_draft_inbox_keeps_available_store_when_other_inventory_fails():
|
||||
script = f"""
|
||||
const createPhotoDraftInbox = require({json.dumps(str(MODULE))});
|
||||
const inbox=createPhotoDraftInbox({{
|
||||
conversation:{{list:async()=>{{throw new Error('IndexedDB unavailable')}}}},
|
||||
search:{{list:async()=>[{{id:'safe',route:{{kind:'search',target_kind:'issue',repository:'o/r',number:2}},updated_at:1}}]}},
|
||||
}});
|
||||
(async()=>process.stdout.write(JSON.stringify(await inbox.refresh([]))))().catch(error=>{{console.error(error);process.exit(1);}});
|
||||
"""
|
||||
assert run_node(script) == [
|
||||
{"id": "safe", "route": {"kind": "search", "target_kind": "issue", "repository": "o/r", "number": 2}, "updated_at": 1}
|
||||
]
|
||||
|
||||
|
||||
def test_mobile_my_work_discovers_reopens_and_discards_photo_only_reply_drafts():
|
||||
index = INDEX.read_text()
|
||||
dashboard = DASHBOARD.read_text()
|
||||
worker = WORKER.read_text()
|
||||
bundle = BUNDLE.read_text()
|
||||
|
||||
assert '<script src="static/photo-draft-inbox.js"></script>' in index
|
||||
assert "BASE + 'static/photo-draft-inbox.js'" in worker
|
||||
assert '"static/photo-draft-inbox.js"' in bundle
|
||||
assert "const photoDraftInbox = createPhotoDraftInbox({" in dashboard
|
||||
assert "draftInbox.list().concat(photoDraftInbox.list(), unfiled)" in dashboard
|
||||
assert "await photoDraftInbox.refresh(draftInbox.list())" in dashboard
|
||||
assert "refreshMyWorkView({ reconcileSession:false, refreshFirstTask:false })" in dashboard
|
||||
assert "void refreshPhotoDraftInbox();" in dashboard
|
||||
assert "onChange:() => { void refreshPhotoDraftInbox(); }" in dashboard
|
||||
assert "await searchReplyDraftStore.save(target, attachments);\n void refreshPhotoDraftInbox();" in dashboard
|
||||
assert "photoDraftInbox.description(item)" in dashboard
|
||||
assert "photoDraftInbox.searchTarget(item)" in dashboard
|
||||
assert "await photoDraftInbox.discard(item)" in dashboard
|
||||
@@ -418,7 +418,7 @@ async def test_starting_saved_today_work_closes_a_concurrent_rollover_planner():
|
||||
def test_plan_today_controller_is_available_in_the_offline_shell():
|
||||
source = SERVICE_WORKER.read_text()
|
||||
|
||||
assert "stackchain-dashboard-shell-v138" in source
|
||||
assert "stackchain-dashboard-shell-v146" 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
|
||||
@@ -0,0 +1,299 @@
|
||||
import json
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
MODULE = Path(__file__).parents[1] / "frontend" / "progressive-capture.js"
|
||||
UNFILED = Path(__file__).parents[1] / "frontend" / "unfiled-captures.js"
|
||||
DASHBOARD = Path(__file__).parents[1] / "frontend" / "dashboard.js"
|
||||
CSS = Path(__file__).parents[1] / "frontend" / "dashboard.css"
|
||||
|
||||
|
||||
def run_capture(scenario: str) -> dict:
|
||||
harness = f"""
|
||||
const createProgressiveCapture = require({json.dumps(str(MODULE))});
|
||||
const createUnfiledCaptures = require({json.dumps(str(UNFILED))});
|
||||
(async()=>{{ {scenario} }})().catch(error=>{{console.error(error);process.exit(1);}});
|
||||
"""
|
||||
completed = subprocess.run(
|
||||
["node", "-e", harness], check=True, capture_output=True, text=True
|
||||
)
|
||||
return json.loads(completed.stdout)
|
||||
|
||||
|
||||
def test_progressive_mobile_new_opens_and_saves_one_account_bound_draft():
|
||||
result = run_capture(r"""
|
||||
const listeners = new Map();
|
||||
const button = {dataset:{mobileTask:'new'}, addEventListener(name, callback){listeners.set('new:'+name, callback);}, removeEventListener(name, callback){if(listeners.get('new:'+name)===callback) listeners.delete('new:'+name);}, setAttribute(){}, removeAttribute(){}};
|
||||
const save = {disabled:false, addEventListener(name, callback){listeners.set('save:'+name, callback);}, removeEventListener(name, callback){if(listeners.get('save:'+name)===callback) listeners.delete('save:'+name);}};
|
||||
const file = {disabled:false, addEventListener(){}, removeEventListener(){}};
|
||||
const cancel = {addEventListener(){}, removeEventListener(){}};
|
||||
const field = name => ({value:'', focused:0, focus(){this.focused++;},
|
||||
addEventListener(event, callback){listeners.set(name+':'+event, callback);},
|
||||
removeEventListener(event, callback){if(listeners.get(name+':'+event)===callback) listeners.delete(name+':'+event);},
|
||||
});
|
||||
const title = field('title');
|
||||
const body = field('body');
|
||||
const heading = {textContent:''};
|
||||
const status = {textContent:''};
|
||||
const classes = new Set();
|
||||
const root = {classList:{add:name=>classes.add(name), remove:name=>classes.delete(name), contains:name=>classes.has(name)}};
|
||||
const nodes = {
|
||||
'#create-issue-sheet':root, '#create-issue-title':title, '#create-issue-body':body,
|
||||
'#create-issue-heading':heading, '#save-unfiled-issue':save, '#file-new-issue':file,
|
||||
'#cancel-new-issue':cancel, '#my-work-action-status':status,
|
||||
};
|
||||
const document = {
|
||||
querySelector(selector){return selector==='[data-mobile-task="new"]'?button:(nodes[selector]||null);},
|
||||
};
|
||||
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 flow = createProgressiveCapture({document, storage, getLogin:()=> 'timmy', createCaptures:createUnfiledCaptures, createId:()=> 'draft-1', now:()=> 42});
|
||||
flow.start();
|
||||
listeners.get('new:click')({currentTarget:button});
|
||||
title.value='Production outage'; listeners.get('title:input')();
|
||||
body.value='Investigate mobile reports'; listeners.get('body:input')();
|
||||
await listeners.get('save:click')();
|
||||
await listeners.get('save:click')();
|
||||
const stored=JSON.parse(values.get('stackchain.unfiled-issues.v1'));
|
||||
console.log(JSON.stringify({open:classes.has('open'),focused:title.focused,heading:heading.textContent,status:status.textContent,items:stored.items,listeners:[...listeners.keys()],checkpoint:values.get('stackchain.progressive-capture.v1')||null}));
|
||||
""")
|
||||
|
||||
assert result == {
|
||||
"open": False,
|
||||
"focused": 1,
|
||||
"heading": "Capture work",
|
||||
"status": "Saved to Drafts. Choose a repository when you’re ready to file it.",
|
||||
"items": [{
|
||||
"id": "draft-1",
|
||||
"ownerLogin": "timmy",
|
||||
"title": "Production outage",
|
||||
"body": "Investigate mobile reports",
|
||||
"savedAt": 42,
|
||||
}],
|
||||
"listeners": ["new:click", "save:click", "title:input", "body:input"],
|
||||
"checkpoint": None,
|
||||
}
|
||||
|
||||
|
||||
def test_failed_progressive_save_keeps_rendered_fields_and_checkpoint_for_retry():
|
||||
result = run_capture(r"""
|
||||
const listeners={};
|
||||
const control=name=>({disabled:false,value:'',addEventListener(event,callback){listeners[name+':'+event]=callback;},removeEventListener(){},focus(){this.focused=true;}});
|
||||
const button=control('new'); const save=control('save'); const file=control('file'); const cancel=control('cancel');
|
||||
const title=control('title'); const body=control('body'); const status={textContent:''}; const classes=new Set();
|
||||
const root={classList:{add:name=>classes.add(name),remove:name=>classes.delete(name),contains:name=>classes.has(name)}};
|
||||
const nodes={'#create-issue-sheet':root,'#create-issue-title':title,'#create-issue-body':body,
|
||||
'#create-issue-heading':{textContent:''},'#save-unfiled-issue':save,'#file-new-issue':file,
|
||||
'#cancel-new-issue':cancel,'#my-work-action-status':status};
|
||||
const document={querySelector:selector=>selector==='[data-mobile-task="new"]'?button:nodes[selector]};
|
||||
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 flow=createProgressiveCapture({document,storage,getLogin:()=>'timmy',createCaptures:()=>({save(){throw new Error('Phone storage is full.');}})});
|
||||
flow.start(); listeners['new:click']();
|
||||
title.value='Keep title'; listeners['title:input'](); body.value='Keep note'; listeners['body:input']();
|
||||
const saved=await listeners['save:click']();
|
||||
console.log(JSON.stringify({saved,open:classes.has('open'),title:title.value,body:body.value,status:status.textContent,
|
||||
checkpoint:JSON.parse(values.get('stackchain.progressive-capture.v1'))}));
|
||||
""")
|
||||
|
||||
assert result == {
|
||||
"saved": False,
|
||||
"open": True,
|
||||
"title": "Keep title",
|
||||
"body": "Keep note",
|
||||
"status": "Phone storage is full.",
|
||||
"checkpoint": {
|
||||
"version": 1,
|
||||
"items": [{
|
||||
"ownerLogin": "timmy",
|
||||
"title": "Keep title",
|
||||
"body": "Keep note",
|
||||
}],
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_progressive_capture_restores_latest_checkpoint_only_for_its_account():
|
||||
result = run_capture(r"""
|
||||
const values = new Map();
|
||||
const storage = {
|
||||
getItem:key=>values.get(key)||null,
|
||||
setItem:(key,value)=>values.set(key,value),
|
||||
removeItem:key=>values.delete(key),
|
||||
};
|
||||
function mount(login) {
|
||||
const listeners = new Map();
|
||||
const control = name => ({disabled:false,value:'',
|
||||
addEventListener(event, callback){listeners.set(name+':'+event, callback);},
|
||||
removeEventListener(){},focus(){},
|
||||
});
|
||||
const button=control('new'); const save=control('save'); const file=control('file');
|
||||
const cancel=control('cancel'); const title=control('title'); const body=control('body');
|
||||
const status={textContent:''}; const classes=new Set();
|
||||
const root={classList:{add:name=>classes.add(name),remove:name=>classes.delete(name),contains:name=>classes.has(name)}};
|
||||
const nodes={'#create-issue-sheet':root,'#create-issue-title':title,'#create-issue-body':body,
|
||||
'#create-issue-heading':{textContent:''},'#save-unfiled-issue':save,'#file-new-issue':file,
|
||||
'#cancel-new-issue':cancel,'#my-work-action-status':status};
|
||||
const document={querySelector:selector=>selector==='[data-mobile-task="new"]'?button:nodes[selector]};
|
||||
const flow=createProgressiveCapture({document,storage,getLogin:()=>login,createCaptures:createUnfiledCaptures});
|
||||
flow.start();
|
||||
return {flow,listeners,title,body,status,button};
|
||||
}
|
||||
const first=mount('timmy'); first.listeners.get('new:click')();
|
||||
first.title.value='Production outage'; first.listeners.get('title:input')?.();
|
||||
first.body.value='Latest phone note'; first.listeners.get('body:input')?.();
|
||||
const restored=mount('timmy'); restored.listeners.get('new:click')();
|
||||
const other=mount('alexander'); other.listeners.get('new:click')();
|
||||
other.title.value='Alexander note'; other.listeners.get('title:input')?.();
|
||||
const timmyAgain=mount('timmy'); timmyAgain.listeners.get('new:click')();
|
||||
console.log(JSON.stringify({
|
||||
restored:{title:restored.title.value,body:restored.body.value,status:restored.status.textContent},
|
||||
other:{title:other.title.value,body:other.body.value,status:other.status.textContent},
|
||||
timmyAgain:{title:timmyAgain.title.value,body:timmyAgain.body.value},
|
||||
checkpoint:JSON.parse(values.get('stackchain.progressive-capture.v1') || 'null'),
|
||||
}));
|
||||
""")
|
||||
|
||||
assert result == {
|
||||
"restored": {
|
||||
"title": "Production outage",
|
||||
"body": "Latest phone note",
|
||||
"status": "Unfinished capture restored from this phone.",
|
||||
},
|
||||
"other": {"title": "Alexander note", "body": "", "status": ""},
|
||||
"timmyAgain": {"title": "Production outage", "body": "Latest phone note"},
|
||||
"checkpoint": {
|
||||
"version": 1,
|
||||
"items": [
|
||||
{"ownerLogin": "timmy", "title": "Production outage", "body": "Latest phone note"},
|
||||
{"ownerLogin": "alexander", "title": "Alexander note", "body": ""},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_hydration_handoff_clears_checkpoint_only_after_explicit_completion():
|
||||
result = run_capture(r"""
|
||||
const listeners={};
|
||||
const control=name=>({disabled:false,value:'',addEventListener(event,callback){listeners[name+':'+event]=callback;},removeEventListener(){},focus(){}});
|
||||
const button=control('new'); const save=control('save'); const file=control('file'); const cancel=control('cancel');
|
||||
const title=control('title'); const body=control('body'); const root={classList:{add(){},remove(){},contains:()=>true}};
|
||||
const nodes={'#create-issue-sheet':root,'#create-issue-title':title,'#create-issue-body':body,
|
||||
'#create-issue-heading':{textContent:''},'#save-unfiled-issue':save,'#file-new-issue':file,
|
||||
'#cancel-new-issue':cancel,'#my-work-action-status':{textContent:''}};
|
||||
const document={querySelector:selector=>selector==='[data-mobile-task="new"]'?button:nodes[selector]};
|
||||
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 flow=createProgressiveCapture({document,storage,getLogin:()=>'timmy',createCaptures:createUnfiledCaptures});
|
||||
flow.start(); title.value='Hand off'; listeners['title:input'](); body.value='Preserve me'; listeners['body:input']();
|
||||
const handoff=flow.handoff();
|
||||
const before=JSON.parse(values.get('stackchain.progressive-capture.v1'));
|
||||
if (typeof handoff.complete === 'function') handoff.complete();
|
||||
console.log(JSON.stringify({before,after:values.get('stackchain.progressive-capture.v1')||null}));
|
||||
""")
|
||||
|
||||
assert result == {
|
||||
"before": {
|
||||
"version": 1,
|
||||
"items": [{
|
||||
"ownerLogin": "timmy",
|
||||
"title": "Hand off",
|
||||
"body": "Preserve me",
|
||||
}],
|
||||
},
|
||||
"after": None,
|
||||
}
|
||||
|
||||
|
||||
def test_progressive_file_now_preserves_capture_on_failure_and_hands_it_off_once():
|
||||
result = run_capture(r"""
|
||||
const listeners = new Map();
|
||||
const control = name => ({disabled:false,
|
||||
addEventListener(event, callback){listeners.set(name+':'+event, callback);},
|
||||
removeEventListener(event, callback){if(listeners.get(name+':'+event)===callback) listeners.delete(name+':'+event);},
|
||||
focus(){this.focused=(this.focused||0)+1;},
|
||||
});
|
||||
const button=control('new'); const save=control('save'); const file=control('file'); const cancel=control('cancel');
|
||||
const title=control('title'); title.value='Keep this'; const body={value:'Do not lose this note'};
|
||||
const status={textContent:''}; const heading={textContent:''}; const classes=new Set();
|
||||
const root={classList:{add:name=>classes.add(name),remove:name=>classes.delete(name),contains:name=>classes.has(name)}};
|
||||
const nodes={'#create-issue-sheet':root,'#create-issue-title':title,'#create-issue-body':body,
|
||||
'#create-issue-heading':heading,'#save-unfiled-issue':save,'#file-new-issue':file,
|
||||
'#cancel-new-issue':cancel,'#my-work-action-status':status};
|
||||
const document={querySelector:selector=>selector==='[data-mobile-task="new"]'?button:(nodes[selector]||null)};
|
||||
let requests=0;
|
||||
const flow=createProgressiveCapture({
|
||||
document,storage:{getItem:()=>null,setItem(){}},getLogin:()=> 'timmy',createCaptures:createUnfiledCaptures,
|
||||
requestFullWorkspace:async()=>{requests++;throw new Error('offline');},
|
||||
});
|
||||
flow.start(); listeners.get('new:click')({currentTarget:button});
|
||||
const filed=await listeners.get('file:click')();
|
||||
const before=Array.from(listeners.keys()).sort();
|
||||
const handoff=flow.handoff(); const second=flow.handoff();
|
||||
console.log(JSON.stringify({filed,requests,open:classes.has('open'),status:status.textContent,
|
||||
fileDisabled:file.disabled,focused:title.focused,title:title.value,body:body.value,before,
|
||||
after:Array.from(listeners.keys()),handoff,second}));
|
||||
""")
|
||||
|
||||
assert result == {
|
||||
"filed": False,
|
||||
"requests": 1,
|
||||
"open": True,
|
||||
"status": "Filing tools unavailable. Your capture is still editable; retry when connected.",
|
||||
"fileDisabled": False,
|
||||
"focused": 2,
|
||||
"title": "Keep this",
|
||||
"body": "Do not lose this note",
|
||||
"before": ["cancel:click", "file:click", "new:click", "save:click", "title:input"],
|
||||
"after": [],
|
||||
"handoff": {"open": True, "title": "Keep this", "body": "Do not lose this note"},
|
||||
"second": None,
|
||||
}
|
||||
|
||||
|
||||
def test_hydrated_dashboard_adopts_open_progressive_capture_without_losing_fields():
|
||||
source = DASHBOARD.read_text()
|
||||
|
||||
assert "const progressiveCaptureHandoff = window.stackchainProgressiveCapture?.handoff?.();" in source
|
||||
assert "issueCapture.saveDraft({repository:'', labelIds:[]," in source
|
||||
assert "title:progressiveCaptureHandoff.title, body:progressiveCaptureHandoff.body" in source
|
||||
assert "progressiveCaptureHandoff.complete?.();" in source
|
||||
assert "await openCreateIssueSheet(false);" in source
|
||||
|
||||
|
||||
def test_progressive_capture_is_mobile_only_and_hides_unhydrated_filing_controls():
|
||||
source = MODULE.read_text()
|
||||
css = CSS.read_text()
|
||||
|
||||
assert "window.matchMedia?.('(max-width: 600px)').matches === true" in source
|
||||
assert "root?.classList.add('progressive-capture')" in source
|
||||
assert "root?.classList.remove('progressive-capture')" in source
|
||||
assert ".create-issue-sheet.progressive-capture .mobile-create-issue-nav" in css
|
||||
assert ".create-issue-sheet.progressive-capture .create-issue-attachment" in css
|
||||
assert ".create-issue-sheet.progressive-capture .create-issue-filing" in css
|
||||
assert ".create-issue-sheet.progressive-capture #switch-to-create-pull" in css
|
||||
|
||||
|
||||
def test_successful_filing_handoff_reenables_the_hydrated_file_control():
|
||||
result = run_capture(r"""
|
||||
const listeners={};
|
||||
const control=name=>({disabled:false,addEventListener(event,callback){listeners[name+event]=callback;},removeEventListener(){},focus(){}});
|
||||
const button=control('new'); const save=control('save'); const file=control('file'); const cancel=control('cancel');
|
||||
const title={value:'Ready to file',focus(){}}; const body={value:'Context'}; const status={textContent:''};
|
||||
const classes=new Set(); const root={classList:{add:name=>classes.add(name),remove:name=>classes.delete(name),contains:name=>classes.has(name)}};
|
||||
const nodes={'#create-issue-sheet':root,'#create-issue-title':title,'#create-issue-body':body,
|
||||
'#create-issue-heading':{textContent:''},'#save-unfiled-issue':save,'#file-new-issue':file,
|
||||
'#cancel-new-issue':cancel,'#my-work-action-status':status};
|
||||
const document={querySelector:selector=>selector==='[data-mobile-task="new"]'?button:nodes[selector]};
|
||||
const flow=createProgressiveCapture({document,storage:{getItem:()=>null,setItem(){}},getLogin:()=>'timmy',
|
||||
createCaptures:createUnfiledCaptures,requestFullWorkspace:async()=>true});
|
||||
flow.start(); listeners.newclick({currentTarget:button});
|
||||
const filed=await listeners.fileclick(); const before=file.disabled; const handoff=flow.handoff();
|
||||
console.log(JSON.stringify({filed,before,after:file.disabled,handoff}));
|
||||
""")
|
||||
|
||||
assert result == {
|
||||
"filed": True,
|
||||
"before": True,
|
||||
"after": False,
|
||||
"handoff": {"open": True, "title": "Ready to file", "body": "Context"},
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
import json
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
ROOT = Path(__file__).parents[1]
|
||||
MODULE = ROOT / "frontend" / "progressive-mobile-dock.js"
|
||||
INDEX = ROOT / "frontend" / "index.html"
|
||||
DASHBOARD = ROOT / "frontend" / "dashboard.js"
|
||||
CSS = ROOT / "frontend" / "dashboard.css"
|
||||
MY_WORK = ROOT / "frontend" / "my-work.js"
|
||||
PROGRESSIVE_MY_WORK = ROOT / "frontend" / "progressive-my-work.js"
|
||||
|
||||
|
||||
def test_progressive_mobile_dock_opens_work_and_truthful_queues_before_hydration():
|
||||
harness = f"""
|
||||
const createDock=require({json.dumps(str(MODULE))});
|
||||
function element(dataset={{}}) {{
|
||||
return {{dataset,attrs:{{}},listeners:{{}},open:false,textContent:'',focusCount:0,
|
||||
addEventListener(name,cb){{this.listeners[name]=cb;}},
|
||||
removeEventListener(name,cb){{if(this.listeners[name]===cb)delete this.listeners[name];}},
|
||||
setAttribute(name,value){{this.attrs[name]=String(value);}},
|
||||
removeAttribute(name){{delete this.attrs[name];}},
|
||||
showModal(){{this.open=true;}},close(){{this.open=false;}},focus(){{this.focusCount+=1;}},
|
||||
}};
|
||||
}}
|
||||
const work=element({{mobileTask:'work'}}); const queues=element({{mobileTask:'queues'}});
|
||||
const sheet=element(); const close=element(); const next=element();
|
||||
const rows=Object.fromEntries(['today','agenda','delivery','gate','attention','update','filed','later','draft','authored']
|
||||
.map(name=>[name,element({{mobileQueue:name}})]));
|
||||
const counts=Object.fromEntries(Object.keys(rows).map(name=>[name,element({{mobileQueueCount:name}})]));
|
||||
const smalls=Object.fromEntries(Object.keys(rows).map(name=>[name,{{textContent:'source label'}}]));
|
||||
Object.keys(rows).forEach(name=>rows[name].querySelector=selector=>selector==='small'?smalls[name]:null);
|
||||
const document={{
|
||||
querySelector(selector){{return {{
|
||||
'#mobile-queue-sheet':sheet,'#close-mobile-queues':close,'#mobile-queue-next-action':next,
|
||||
'[data-mobile-task="work"]':work,'[data-mobile-task="queues"]':queues,
|
||||
}}[selector]||null;}},
|
||||
querySelectorAll(selector){{
|
||||
if(selector==='[data-mobile-queue]')return Object.values(rows);
|
||||
if(selector==='[data-mobile-queue-count]')return Object.values(counts);
|
||||
return [];
|
||||
}},
|
||||
}};
|
||||
const calls=[];
|
||||
const myWork={{
|
||||
counts:()=>({{all:3,filed:1,authored:1,attention:1,update:0}}),
|
||||
openFirst:()=>calls.push(['openFirst']),
|
||||
selectQueue:(name,options)=>calls.push(['selectQueue',name,options]),
|
||||
}};
|
||||
const dock=createDock({{document,myWork}}); dock.start();
|
||||
queues.listeners.click({{currentTarget:queues}});
|
||||
const opened=sheet.open; const initialHandoff=dock.handoff();
|
||||
rows.filed.listeners.click();
|
||||
work.listeners.click({{currentTarget:work}});
|
||||
const known={{filed:counts.filed.textContent,attention:counts.attention.textContent}};
|
||||
const loading={{
|
||||
deferred:{{today:smalls.today.textContent,delivery:smalls.delivery.textContent,gate:smalls.gate.textContent,later:smalls.later.textContent}},
|
||||
unavailable:{{today:rows.today.attrs['data-unavailable'],delivery:rows.delivery.attrs['data-unavailable']}},
|
||||
}};
|
||||
dock.stop();
|
||||
console.log(JSON.stringify({{
|
||||
opened,initialHandoff,calls,loading,known,
|
||||
restored:{{today:smalls.today.textContent,delivery:smalls.delivery.textContent}},
|
||||
cleaned:!('data-unavailable' in rows.today.attrs) && !('data-progressive-loading' in rows.today.attrs),
|
||||
listeners:{{work:Object.keys(work.listeners),queues:Object.keys(queues.listeners),filed:Object.keys(rows.filed.listeners)}},
|
||||
}}));
|
||||
"""
|
||||
result = subprocess.run(["node", "-e", harness], capture_output=True, text=True)
|
||||
|
||||
assert result.returncode == 0, result.stderr
|
||||
assert json.loads(result.stdout) == {
|
||||
"opened": True,
|
||||
"initialHandoff": {"queueSheetOpen": True, "lastTask": "queues"},
|
||||
"calls": [
|
||||
["selectQueue", "filed", {"openFirst": True}],
|
||||
["openFirst"],
|
||||
],
|
||||
"known": {"filed": "1", "attention": "1"},
|
||||
"loading": {
|
||||
"deferred": {
|
||||
"today": "Still loading",
|
||||
"delivery": "Still loading",
|
||||
"gate": "Still loading",
|
||||
"later": "Still loading",
|
||||
},
|
||||
"unavailable": {"today": "true", "delivery": "true"},
|
||||
},
|
||||
"restored": {"today": "source label", "delivery": "source label"},
|
||||
"cleaned": True,
|
||||
"listeners": {"work": [], "queues": [], "filed": []},
|
||||
}
|
||||
|
||||
|
||||
def test_progressive_mobile_dock_refreshes_counts_from_live_work_and_unsubscribes_on_handoff():
|
||||
harness = f"""
|
||||
const createDock=require({json.dumps(str(MODULE))});
|
||||
function element(dataset={{}}) {{return {{dataset,textContent:'',listeners:{{}},attrs:{{}},open:false,
|
||||
addEventListener(name,cb){{this.listeners[name]=cb;}},removeEventListener(name){{delete this.listeners[name];}},
|
||||
setAttribute(name,value){{this.attrs[name]=String(value);}},removeAttribute(name){{delete this.attrs[name];}},
|
||||
querySelector:()=>({{textContent:''}}),showModal(){{this.open=true;}},close(){{this.open=false;}},
|
||||
}};}}
|
||||
const work=element({{mobileTask:'work'}}),queues=element({{mobileTask:'queues'}}),sheet=element(),close=element(),next=element();
|
||||
const filed=element({{mobileQueue:'filed'}}),filedCount=element({{mobileQueueCount:'filed'}});
|
||||
const document={{querySelector:s=>({{
|
||||
'[data-mobile-task="work"]':work,'[data-mobile-task="queues"]':queues,
|
||||
'#mobile-queue-sheet':sheet,'#close-mobile-queues':close,'#mobile-queue-next-action':next,
|
||||
}}[s]||null),querySelectorAll:s=>s==='[data-mobile-queue]'?[filed]:s==='[data-mobile-queue-count]'?[filedCount]:[]}};
|
||||
let counts={{all:0,filed:0}}, subscriber=null, unsubscribed=false;
|
||||
const myWork={{counts:()=>counts,subscribe(cb){{subscriber=cb;return()=>{{unsubscribed=true;subscriber=null;}};}},openFirst(){{}},selectQueue(){{}}}};
|
||||
const dock=createDock({{document,myWork}}); dock.start();
|
||||
const before=filedCount.textContent; counts={{all:2,filed:2}}; subscriber(); const after=filedCount.textContent;
|
||||
dock.stop();
|
||||
console.log(JSON.stringify({{before,after,unsubscribed,subscriber:subscriber===null}}));
|
||||
"""
|
||||
result = subprocess.run(["node", "-e", harness], capture_output=True, text=True)
|
||||
|
||||
assert result.returncode == 0, result.stderr
|
||||
assert json.loads(result.stdout) == {
|
||||
"before": "0", "after": "2", "unsubscribed": True, "subscriber": True,
|
||||
}
|
||||
|
||||
|
||||
def test_progressive_mobile_dock_is_shipped_before_optional_workspace_hydration():
|
||||
index = INDEX.read_text()
|
||||
dashboard = DASHBOARD.read_text()
|
||||
css = CSS.read_text()
|
||||
|
||||
assert '<script src="static/progressive-mobile-dock.js"></script>' in index
|
||||
assert index.index('static/progressive-my-work.js') < index.index('static/progressive-mobile-dock.js')
|
||||
assert index.index('static/progressive-mobile-dock.js') < index.index('static/dashboard.js')
|
||||
assert "window.stackchainProgressiveMobileDock?.handoff?.()" in dashboard
|
||||
assert "window.stackchainProgressiveMobileDock?.stop?.()" in dashboard
|
||||
assert "mobileTaskDock.select(progressiveMobileDockHandoff.lastTask)" in dashboard
|
||||
assert "progressiveMobileDockHandoff?.queueSheetOpen && !qs('#mobile-queue-sheet').open" in dashboard
|
||||
assert '[data-progressive-loading="true"]::after' in css
|
||||
assert "content:'Still loading · available after workspace starts'" in css
|
||||
|
||||
|
||||
def test_progressive_my_work_exposes_counts_and_opens_the_first_selected_queue_item():
|
||||
harness = f"""
|
||||
const fs=require('fs'); const vm=require('vm');
|
||||
function element(extra={{}}) {{return Object.assign({{
|
||||
innerHTML:'',textContent:'',hidden:true,dataset:{{}},listeners:{{}},focusCount:0,
|
||||
addEventListener(name,cb){{this.listeners[name]=cb;}},removeEventListener(){{}},
|
||||
setAttribute(){{}},removeAttribute(){{}},focus(){{this.focusCount+=1;}},
|
||||
}},extra);}}
|
||||
const list=element(); const status=element(); const detail=element();
|
||||
const title=element(); const meta=element(); const reason=element(); const close=element(); const link=element();
|
||||
const elements={{'#my-work-list':list,'#my-work-status':status,'#progressive-work-detail':detail,
|
||||
'#progressive-work-detail-title':title,'#progressive-work-detail-meta':meta,
|
||||
'#progressive-work-detail-reason':reason,'#close-progressive-work-detail':close,
|
||||
'#open-progressive-work-gitea':link}};
|
||||
const buttons=['all','filed','authored','attention'].map(name=>element({{dataset:{{workFilter:name}}}}));
|
||||
const document={{querySelector:s=>elements[s]||null,querySelectorAll:()=>buttons}};
|
||||
const lifecycleTarget=element();
|
||||
const context={{module:{{exports:{{}}}},exports:{{}},console,URL,document}}; vm.createContext(context);
|
||||
vm.runInContext(fs.readFileSync({json.dumps(str(MY_WORK))},'utf8'),context);
|
||||
context.buildMyWork=context.module.exports; context.module={{exports:{{}}}};
|
||||
vm.runInContext(fs.readFileSync({json.dumps(str(PROGRESSIVE_MY_WORK))},'utf8'),context);
|
||||
const flow=context.module.exports({{document,lifecycleTarget,fetchSnapshot:async()=>({{
|
||||
user:{{login:'timmy'}},
|
||||
issues:[{{number:7,title:'Filed issue',repository:'stackchain/dashboard',work_reasons:['created_by_me'],url:'https://forge.example/issues/7'}}],
|
||||
pull_requests:[{{number:8,title:'Authored PR',repository:'stackchain/dashboard',work_reasons:['authored_by_me'],url:'https://forge.example/pulls/8'}}],
|
||||
}})}});
|
||||
(async()=>{{
|
||||
let updates=0; const unsubscribe=flow.subscribe(()=>{{updates+=1;}});
|
||||
await flow.start(); const counts=flow.counts();
|
||||
const selected=flow.selectQueue('filed',{{openFirst:true}}); const handoff=flow.handoff();
|
||||
unsubscribe(); flow.selectQueue('authored');
|
||||
console.log(JSON.stringify({{counts,updates,selected,detailHidden:detail.hidden,title:title.textContent,handoff}}));
|
||||
}})().catch(error=>{{console.error(error);process.exit(1);}});
|
||||
"""
|
||||
result = subprocess.run(["node", "-e", harness], capture_output=True, text=True)
|
||||
|
||||
assert result.returncode == 0, result.stderr
|
||||
state = json.loads(result.stdout)
|
||||
assert state["counts"] == {"all": 2, "filed": 1, "authored": 1, "attention": 0, "update": 0, "review": 0}
|
||||
assert state["updates"] == 2
|
||||
assert state["selected"] == "opened"
|
||||
assert state["detailHidden"] is False
|
||||
assert state["title"] == "Filed issue"
|
||||
assert state["handoff"]["selectedFilter"] == "filed"
|
||||
assert state["handoff"]["openWork"]["key"] == "stackchain/dashboard#7"
|
||||
@@ -0,0 +1,606 @@
|
||||
import json
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
MODULE = Path(__file__).parents[1] / "frontend" / "progressive-my-work.js"
|
||||
LIVE_SNAPSHOT = Path(__file__).parents[1] / "frontend" / "progressive-live-snapshot.js"
|
||||
MY_WORK = Path(__file__).parents[1] / "frontend" / "my-work.js"
|
||||
DASHBOARD = Path(__file__).parents[1] / "frontend" / "dashboard.js"
|
||||
INDEX = Path(__file__).parents[1] / "frontend" / "index.html"
|
||||
CSS = Path(__file__).parents[1] / "frontend" / "dashboard.css"
|
||||
|
||||
|
||||
def test_progressive_live_snapshot_coalesces_concurrent_cold_launch_consumers():
|
||||
harness = f"""
|
||||
const createProgressiveLiveSnapshot=require({json.dumps(str(LIVE_SNAPSHOT))});
|
||||
let calls=0, resolveRequest;
|
||||
const broker=createProgressiveLiveSnapshot({{fetchSnapshot:()=>{{
|
||||
calls += 1;
|
||||
return new Promise(resolve=>{{resolveRequest=resolve;}});
|
||||
}}}});
|
||||
(async()=>{{
|
||||
const myWork=broker.acquire();
|
||||
const humanGates=broker.acquire();
|
||||
await Promise.resolve();
|
||||
const callsWhilePending=calls;
|
||||
const snapshot={{context:{{user:{{id:7,login:'timmy'}}}},events:[],notifications:[]}};
|
||||
resolveRequest(snapshot);
|
||||
const [first,second]=await Promise.all([myWork,humanGates]);
|
||||
const cached=await broker.acquire();
|
||||
process.stdout.write(JSON.stringify({{
|
||||
callsWhilePending,calls,same:first===second && second===cached,
|
||||
identity:broker.identity(),snapshot:broker.snapshot(),
|
||||
}}));
|
||||
}})().catch(error=>{{console.error(error);process.exit(1);}});
|
||||
"""
|
||||
result = subprocess.run(["node", "-e", harness], capture_output=True, text=True)
|
||||
|
||||
assert result.returncode == 0, result.stderr
|
||||
assert json.loads(result.stdout) == {
|
||||
"callsWhilePending": 1,
|
||||
"calls": 1,
|
||||
"same": True,
|
||||
"identity": {"login": "timmy", "accountKey": "7:timmy"},
|
||||
"snapshot": {
|
||||
"context": {"user": {"id": 7, "login": "timmy"}},
|
||||
"events": [],
|
||||
"notifications": [],
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_progressive_live_snapshot_retries_identityless_success_for_identity_consumers():
|
||||
harness = f"""
|
||||
const createProgressiveLiveSnapshot=require({json.dumps(str(LIVE_SNAPSHOT))});
|
||||
let calls=0;
|
||||
const responses=[
|
||||
{{context:null,events:[],notifications:[{{id:1}}]}},
|
||||
{{context:{{user:{{id:7,login:'timmy'}}}},events:[],notifications:[]}},
|
||||
];
|
||||
const broker=createProgressiveLiveSnapshot({{fetchSnapshot:async()=>{{
|
||||
calls += 1;
|
||||
return responses.shift();
|
||||
}}}});
|
||||
(async()=>{{
|
||||
const partial=await broker.acquire();
|
||||
const first=await Promise.allSettled([
|
||||
broker.acquire({{requireIdentity:true}}),
|
||||
broker.acquire({{requireIdentity:true}}),
|
||||
]);
|
||||
const retries=[
|
||||
broker.acquire({{requireIdentity:true}}),
|
||||
broker.acquire({{requireIdentity:true}}),
|
||||
];
|
||||
const recovered=await Promise.all(retries);
|
||||
process.stdout.write(JSON.stringify({{
|
||||
calls,
|
||||
partialNotifications:partial.notifications.length,
|
||||
first:first.map(result=>result.status),
|
||||
same:recovered[0]===recovered[1],
|
||||
identity:broker.identity(),
|
||||
}}));
|
||||
}})().catch(error=>{{console.error(error);process.exit(1);}});
|
||||
"""
|
||||
result = subprocess.run(["node", "-e", harness], capture_output=True, text=True)
|
||||
|
||||
assert result.returncode == 0, result.stderr
|
||||
assert json.loads(result.stdout) == {
|
||||
"calls": 2,
|
||||
"partialNotifications": 1,
|
||||
"first": ["rejected", "rejected"],
|
||||
"same": True,
|
||||
"identity": {"login": "timmy", "accountKey": "7:timmy"},
|
||||
}
|
||||
|
||||
|
||||
def test_progressive_live_snapshot_retries_after_a_failed_shared_flight():
|
||||
harness = f"""
|
||||
const createProgressiveLiveSnapshot=require({json.dumps(str(LIVE_SNAPSHOT))});
|
||||
let calls=0;
|
||||
const snapshot={{context:{{user:{{login:'timmy'}}}},events:[],notifications:[]}};
|
||||
const broker=createProgressiveLiveSnapshot({{fetchSnapshot:async()=>{{
|
||||
calls += 1;
|
||||
if(calls===1) throw new Error('temporary outage');
|
||||
return snapshot;
|
||||
}}}});
|
||||
(async()=>{{
|
||||
const first=await Promise.allSettled([broker.acquire(),broker.acquire()]);
|
||||
const recovered=await broker.acquire();
|
||||
process.stdout.write(JSON.stringify({{
|
||||
calls,first:first.map(result=>result.status),recovered:recovered===snapshot,
|
||||
}}));
|
||||
}})().catch(error=>{{console.error(error);process.exit(1);}});
|
||||
"""
|
||||
result = subprocess.run(["node", "-e", harness], capture_output=True, text=True)
|
||||
|
||||
assert result.returncode == 0, result.stderr
|
||||
assert json.loads(result.stdout) == {
|
||||
"calls": 2,
|
||||
"first": ["rejected", "rejected"],
|
||||
"recovered": True,
|
||||
}
|
||||
|
||||
|
||||
def test_progressive_my_work_reports_reconnecting_for_degraded_context_instead_of_inbox_zero():
|
||||
harness = f"""
|
||||
const fs=require('fs'); const vm=require('vm');
|
||||
const list={{innerHTML:''}}; const status={{textContent:''}};
|
||||
const document={{
|
||||
hidden:false,
|
||||
querySelector:s=>s==='#my-work-list'?list:s==='#my-work-status'?status:null,
|
||||
querySelectorAll:()=>[],
|
||||
}};
|
||||
const context={{module:{{exports:{{}}}},exports:{{}},console,URL,document}}; vm.createContext(context);
|
||||
vm.runInContext(fs.readFileSync({json.dumps(str(MY_WORK))},'utf8'),context);
|
||||
context.buildMyWork=context.module.exports; context.module={{exports:{{}}}};
|
||||
vm.runInContext(fs.readFileSync({json.dumps(str(MODULE))},'utf8'),context);
|
||||
const flow=context.module.exports({{document,fetchSnapshot:async()=>({{
|
||||
context:null,events:[],notifications:[{{id:1}}],
|
||||
freshness:{{retry_in_seconds:5,sections:{{
|
||||
context:{{degraded:true,retry_in_seconds:5}},
|
||||
events:{{degraded:false,age_seconds:1}},notifications:{{degraded:false,age_seconds:1}},
|
||||
}}}},
|
||||
}})}});
|
||||
(async()=>{{
|
||||
const started=await flow.start();
|
||||
process.stdout.write(JSON.stringify({{started,status:status.textContent,html:list.innerHTML,counts:flow.counts()}}));
|
||||
}})().catch(error=>{{console.error(error);process.exit(1);}});
|
||||
"""
|
||||
result = subprocess.run(["node", "-e", harness], capture_output=True, text=True)
|
||||
|
||||
assert result.returncode == 0, result.stderr
|
||||
assert json.loads(result.stdout) == {
|
||||
"started": False,
|
||||
"status": "Assigned work is reconnecting…",
|
||||
"html": '<div class="muted">Assigned work is reconnecting…</div>',
|
||||
"counts": {"all": 0, "filed": 0, "authored": 0, "attention": 0,
|
||||
"update": 0, "review": 0},
|
||||
}
|
||||
|
||||
|
||||
def test_progressive_my_work_renders_and_filters_assigned_work_before_full_workspace():
|
||||
harness = f"""
|
||||
const fs=require('fs'); const vm=require('vm');
|
||||
const buttons=[
|
||||
{{dataset:{{workFilter:'all'}},attrs:{{}},addEventListener(n,cb){{this.cb=cb;}},setAttribute(n,v){{this.attrs[n]=v;}}}},
|
||||
{{dataset:{{workFilter:'issue'}},attrs:{{}},addEventListener(n,cb){{this.cb=cb;}},setAttribute(n,v){{this.attrs[n]=v;}}}},
|
||||
];
|
||||
const list={{innerHTML:''}}; const status={{textContent:''}};
|
||||
const document={{querySelector:s=>s==='#my-work-list'?list:s==='#my-work-status'?status:null,querySelectorAll:()=>buttons}};
|
||||
const context={{module:{{exports:{{}}}},exports:{{}},console,URL,document}}; vm.createContext(context);
|
||||
vm.runInContext(fs.readFileSync({json.dumps(str(MY_WORK))},'utf8'),context);
|
||||
context.buildMyWork=context.module.exports; context.module={{exports:{{}}}};
|
||||
vm.runInContext(fs.readFileSync({json.dumps(str(MODULE))},'utf8'),context);
|
||||
const createProgressiveMyWork=context.module.exports;
|
||||
const flow=createProgressiveMyWork({{document,fetchSnapshot:async()=>({{
|
||||
user:{{login:'timmy'}},issues:[{{number:7,title:'Fix mobile queue',repository:'stackchain/dashboard',assignees:['timmy'],url:'https://forge.example/issues/7'}}],pull_requests:[]
|
||||
}})}});
|
||||
(async()=>{{
|
||||
await flow.start(); const rendered=list.innerHTML;
|
||||
buttons[1].cb();
|
||||
console.log(JSON.stringify({{status:status.textContent,rendered,pressed:buttons.map(b=>b.attrs['aria-pressed'])}}));
|
||||
}})().catch(e=>{{console.error(e);process.exit(1);}});
|
||||
"""
|
||||
result = subprocess.run(["node", "-e", harness], check=True, capture_output=True, text=True)
|
||||
state = json.loads(result.stdout)
|
||||
assert state["status"] == "1 assigned work item ready."
|
||||
assert "Fix mobile queue" in state["rendered"]
|
||||
assert 'data-progressive-work-index="0"' in state["rendered"]
|
||||
assert "href=" not in state["rendered"]
|
||||
assert state["pressed"] == ["false", "true"]
|
||||
|
||||
|
||||
def test_progressive_my_work_keeps_supported_queues_truthful_while_planning_loads():
|
||||
harness = f"""
|
||||
const fs=require('fs'); const vm=require('vm');
|
||||
const names=['all','today','agenda','attention','filed','authored','issue','pull','review','update','later','draft'];
|
||||
const counts=Object.fromEntries(names.map(name=>[name,{{textContent:'0'}}]));
|
||||
const buttons=names.map(name=>({{
|
||||
dataset:{{workFilter:name}},attrs:{{}},
|
||||
addEventListener(_name,cb){{this.cb=cb;}},
|
||||
removeEventListener(){{}},
|
||||
setAttribute(key,value){{this.attrs[key]=value;}},
|
||||
}}));
|
||||
const list={{innerHTML:''}}; const status={{textContent:''}};
|
||||
const document={{
|
||||
querySelector(selector){{
|
||||
if(selector==='#my-work-list')return list;
|
||||
if(selector==='#my-work-status')return status;
|
||||
const match=selector.match(/^\\[data-work-count="(.+)"\\]$/);
|
||||
return match?counts[match[1]]:null;
|
||||
}},
|
||||
querySelectorAll:()=>buttons,
|
||||
}};
|
||||
const context={{module:{{exports:{{}}}},exports:{{}},console,URL,document}}; vm.createContext(context);
|
||||
vm.runInContext(fs.readFileSync({json.dumps(str(MY_WORK))},'utf8'),context);
|
||||
context.buildMyWork=context.module.exports; context.module={{exports:{{}}}};
|
||||
vm.runInContext(fs.readFileSync({json.dumps(str(MODULE))},'utf8'),context);
|
||||
const flow=context.module.exports({{document,fetchSnapshot:async()=>({{
|
||||
user:{{login:'timmy'}},
|
||||
issues:[{{number:7,title:'Filed from phone',repository:'stackchain/dashboard',assignees:[],work_reasons:['created_by_me'],url:'https://forge.example/issues/7'}}],
|
||||
pull_requests:[{{number:8,title:'Authored release',repository:'stackchain/dashboard',assignees:[],work_reasons:['authored_by_me'],url:'https://forge.example/pulls/8'}}],
|
||||
}})}});
|
||||
(async()=>{{
|
||||
await flow.start();
|
||||
buttons[names.indexOf('filed')].cb(); const filed=list.innerHTML;
|
||||
buttons[names.indexOf('authored')].cb(); const authored=list.innerHTML;
|
||||
buttons[names.indexOf('today')].cb(); const today=list.innerHTML;
|
||||
console.log(JSON.stringify({{filed,authored,today,counts:Object.fromEntries(names.map(name=>[name,counts[name].textContent]))}}));
|
||||
}})().catch(error=>{{console.error(error);process.exit(1);}});
|
||||
"""
|
||||
result = subprocess.run(["node", "-e", harness], check=True, capture_output=True, text=True)
|
||||
state = json.loads(result.stdout)
|
||||
assert "Filed from phone" in state["filed"]
|
||||
assert "Authored release" in state["authored"]
|
||||
assert "Today is still loading" in state["today"]
|
||||
assert "No work" not in state["today"]
|
||||
assert state["counts"] == {
|
||||
"all": "2",
|
||||
"today": "0",
|
||||
"agenda": "0",
|
||||
"attention": "0",
|
||||
"filed": "1",
|
||||
"authored": "1",
|
||||
"issue": "1",
|
||||
"pull": "1",
|
||||
"review": "0",
|
||||
"update": "0",
|
||||
"later": "0",
|
||||
"draft": "0",
|
||||
}
|
||||
|
||||
|
||||
def test_progressive_queue_selection_is_handed_to_the_hydrated_workspace():
|
||||
harness = f"""
|
||||
const fs=require('fs'); const vm=require('vm');
|
||||
const buttons=['all','filed'].map(name=>({{
|
||||
dataset:{{workFilter:name}},attrs:{{}},removed:false,
|
||||
addEventListener(_name,cb){{this.cb=cb;}},
|
||||
removeEventListener(_name,cb){{if(cb===this.cb)this.removed=true;}},
|
||||
setAttribute(key,value){{this.attrs[key]=value;}},
|
||||
}}));
|
||||
const document={{
|
||||
querySelector:selector=>selector==='#my-work-list'?{{innerHTML:''}}:selector==='#my-work-status'?{{textContent:''}}:null,
|
||||
querySelectorAll:()=>buttons,
|
||||
}};
|
||||
const context={{module:{{exports:{{}}}},exports:{{}},console,URL,document}}; vm.createContext(context);
|
||||
vm.runInContext(fs.readFileSync({json.dumps(str(MY_WORK))},'utf8'),context);
|
||||
context.buildMyWork=context.module.exports; context.module={{exports:{{}}}};
|
||||
vm.runInContext(fs.readFileSync({json.dumps(str(MODULE))},'utf8'),context);
|
||||
const flow=context.module.exports({{document,fetchSnapshot:async()=>({{user:{{login:'timmy'}},issues:[],pull_requests:[]}})}});
|
||||
(async()=>{{
|
||||
await flow.start(); buttons[1].cb();
|
||||
const before=flow.handoff(); flow.stop(); const after=flow.handoff();
|
||||
console.log(JSON.stringify({{before,after,removed:buttons.map(button=>button.removed)}}));
|
||||
}})().catch(error=>{{console.error(error);process.exit(1);}});
|
||||
"""
|
||||
result = subprocess.run(["node", "-e", harness], check=True, capture_output=True, text=True)
|
||||
state = json.loads(result.stdout)
|
||||
assert state == {
|
||||
"before": {"selectedFilter": "filed"},
|
||||
"after": {"selectedFilter": "filed"},
|
||||
"removed": [True, True],
|
||||
}
|
||||
|
||||
dashboard = DASHBOARD.read_text()
|
||||
assert "const progressiveWorkHandoff = window.stackchainProgressiveMyWork?.handoff?.();" in dashboard
|
||||
assert "progressiveWorkHandoff?.selectedFilter" in dashboard
|
||||
|
||||
|
||||
def test_progressive_live_snapshot_is_handed_to_the_workspace_exactly_once():
|
||||
harness = f"""
|
||||
const fs=require('fs'); const vm=require('vm');
|
||||
const document={{
|
||||
querySelector:selector=>selector==='#my-work-list'?{{innerHTML:''}}:selector==='#my-work-status'?{{textContent:''}}:null,
|
||||
querySelectorAll:()=>[],
|
||||
}};
|
||||
const context={{module:{{exports:{{}}}},exports:{{}},console,URL,document}}; vm.createContext(context);
|
||||
vm.runInContext(fs.readFileSync({json.dumps(str(MY_WORK))},'utf8'),context);
|
||||
context.buildMyWork=context.module.exports; context.module={{exports:{{}}}};
|
||||
vm.runInContext(fs.readFileSync({json.dumps(str(MODULE))},'utf8'),context);
|
||||
const snapshot={{
|
||||
context:{{user:{{login:'timmy'}},issues:[],pull_requests:[]}},
|
||||
events:[{{id:7}}], notifications:[],
|
||||
revisions:{{context:'0123456789abcdef.1',events:'fedcba9876543210.2',notifications:'0011223344556677.3'}},
|
||||
freshness:{{fresh_for_seconds:8,sections:{{
|
||||
context:{{degraded:false,age_seconds:2}},events:{{degraded:false,age_seconds:2}},notifications:{{degraded:false,age_seconds:2}},
|
||||
}}}},
|
||||
}};
|
||||
const flow=context.module.exports({{document,fetchSnapshot:async()=>snapshot}});
|
||||
(async()=>{{
|
||||
await flow.start();
|
||||
const first=flow.handoff(); const second=flow.handoff();
|
||||
console.log(JSON.stringify({{
|
||||
firstSnapshot:first.liveSnapshot,
|
||||
secondHasSnapshot:Object.prototype.hasOwnProperty.call(second,'liveSnapshot'),
|
||||
}}));
|
||||
}})().catch(error=>{{console.error(error);process.exit(1);}});
|
||||
"""
|
||||
result = subprocess.run(["node", "-e", harness], check=True, capture_output=True, text=True)
|
||||
state = json.loads(result.stdout)
|
||||
|
||||
assert state == {"firstSnapshot": {
|
||||
"context": {"user": {"login": "timmy"}, "issues": [], "pull_requests": []},
|
||||
"events": [{"id": 7}],
|
||||
"notifications": [],
|
||||
"revisions": {
|
||||
"context": "0123456789abcdef.1",
|
||||
"events": "fedcba9876543210.2",
|
||||
"notifications": "0011223344556677.3",
|
||||
},
|
||||
"freshness": {
|
||||
"fresh_for_seconds": 8,
|
||||
"sections": {
|
||||
"context": {"degraded": False, "age_seconds": 2},
|
||||
"events": {"degraded": False, "age_seconds": 2},
|
||||
"notifications": {"degraded": False, "age_seconds": 2},
|
||||
},
|
||||
},
|
||||
}, "secondHasSnapshot": False}
|
||||
|
||||
|
||||
def test_progressive_inflight_snapshot_survives_workspace_handoff_and_stop():
|
||||
harness = f"""
|
||||
const fs=require('fs'); const vm=require('vm');
|
||||
const document={{
|
||||
querySelector:selector=>selector==='#my-work-list'?{{innerHTML:''}}:selector==='#my-work-status'?{{textContent:''}}:null,
|
||||
querySelectorAll:()=>[],
|
||||
}};
|
||||
const context={{module:{{exports:{{}}}},exports:{{}},console,URL,document}}; vm.createContext(context);
|
||||
vm.runInContext(fs.readFileSync({json.dumps(str(MY_WORK))},'utf8'),context);
|
||||
context.buildMyWork=context.module.exports; context.module={{exports:{{}}}};
|
||||
vm.runInContext(fs.readFileSync({json.dumps(str(MODULE))},'utf8'),context);
|
||||
let resolveSnapshot;
|
||||
const snapshot={{context:{{user:{{login:'timmy'}},issues:[],pull_requests:[]}},events:[],notifications:[]}};
|
||||
const flow=context.module.exports({{document,fetchSnapshot:()=>new Promise(resolve=>{{resolveSnapshot=resolve;}})}});
|
||||
(async()=>{{
|
||||
const started=flow.start();
|
||||
await Promise.resolve();
|
||||
const handoff=flow.handoff();
|
||||
flow.stop();
|
||||
resolveSnapshot(snapshot);
|
||||
const transferred=await handoff.liveSnapshotPromise;
|
||||
await started;
|
||||
console.log(JSON.stringify({{transferred}}));
|
||||
}})().catch(error=>{{console.error(error);process.exit(1);}});
|
||||
"""
|
||||
result = subprocess.run(["node", "-e", harness], check=True, capture_output=True, text=True)
|
||||
|
||||
assert json.loads(result.stdout) == {"transferred": {
|
||||
"context": {"user": {"login": "timmy"}, "issues": [], "pull_requests": []},
|
||||
"events": [],
|
||||
"notifications": [],
|
||||
}}
|
||||
|
||||
|
||||
def test_progressive_capture_can_read_only_the_confirmed_snapshot_login():
|
||||
harness = f"""
|
||||
const fs=require('fs'); const vm=require('vm');
|
||||
const document={{
|
||||
querySelector:selector=>selector==='#my-work-list'?{{innerHTML:''}}:selector==='#my-work-status'?{{textContent:''}}:null,
|
||||
querySelectorAll:()=>[],
|
||||
}};
|
||||
const context={{module:{{exports:{{}}}},exports:{{}},console,URL,document}}; vm.createContext(context);
|
||||
vm.runInContext(fs.readFileSync({json.dumps(str(MY_WORK))},'utf8'),context);
|
||||
context.buildMyWork=context.module.exports; context.module={{exports:{{}}}};
|
||||
vm.runInContext(fs.readFileSync({json.dumps(str(MODULE))},'utf8'),context);
|
||||
const flow=context.module.exports({{document,fetchSnapshot:async()=>({{
|
||||
context:{{user:{{login:'timmy'}},issues:[],pull_requests:[]}}, events:[], notifications:[],
|
||||
}})}});
|
||||
(async()=>{{
|
||||
const before=flow.login(); await flow.start(); const after=flow.login(); flow.stop();
|
||||
console.log(JSON.stringify({{before,after,stopped:flow.login()}}));
|
||||
}})().catch(error=>{{console.error(error);process.exit(1);}});
|
||||
"""
|
||||
result = subprocess.run(["node", "-e", harness], check=True, capture_output=True, text=True)
|
||||
|
||||
assert json.loads(result.stdout) == {"before": "", "after": "timmy", "stopped": "timmy"}
|
||||
|
||||
|
||||
def test_progressive_my_work_retries_a_failed_snapshot_without_reloading():
|
||||
harness = f"""
|
||||
const fs=require('fs'); const vm=require('vm');
|
||||
const list={{innerHTML:''}}; const status={{textContent:''}};
|
||||
const document={{
|
||||
querySelector:selector=>selector==='#my-work-list'?list:selector==='#my-work-status'?status:null,
|
||||
querySelectorAll:()=>[],
|
||||
}};
|
||||
let timer=null; let attempts=0;
|
||||
const context={{module:{{exports:{{}}}},exports:{{}},console,URL,URLSearchParams,AbortController,document}};
|
||||
vm.createContext(context);
|
||||
vm.runInContext(fs.readFileSync({json.dumps(str(MY_WORK))},'utf8'),context);
|
||||
context.buildMyWork=context.module.exports; context.module={{exports:{{}}}};
|
||||
vm.runInContext(fs.readFileSync({json.dumps(str(Path(__file__).parents[1] / 'frontend' / 'context-poller.js'))},'utf8'),context);
|
||||
context.createContextPoller=context.module.exports; context.module={{exports:{{}}}};
|
||||
vm.runInContext(fs.readFileSync({json.dumps(str(MODULE))},'utf8'),context);
|
||||
const flow=context.module.exports({{
|
||||
document,
|
||||
fetchSnapshot:async()=>{{
|
||||
attempts += 1;
|
||||
if(attempts===1) throw new Error('temporary outage');
|
||||
return {{context:{{user:{{login:'timmy'}},issues:[{{
|
||||
number:9,title:'Recovered assignment',repository:'stackchain/dashboard',
|
||||
assignees:['timmy'],url:'https://forge.example/issues/9',
|
||||
}}],pull_requests:[]}},events:[],notifications:[]}};
|
||||
}},
|
||||
pollerOptions:{{
|
||||
setTimer:callback=>{{timer=callback; return 1;}}, clearTimer:()=>{{timer=null;}},
|
||||
setDeadlineTimer:()=>2, clearDeadlineTimer:()=>{{}}, intervalMs:5,
|
||||
}},
|
||||
}});
|
||||
(async()=>{{
|
||||
const first=await flow.start();
|
||||
const reconnecting=status.textContent;
|
||||
if(!timer) throw new Error('retry was not scheduled');
|
||||
timer(); await Promise.resolve(); await Promise.resolve(); await new Promise(resolve=>setImmediate(resolve));
|
||||
console.log(JSON.stringify({{first,reconnecting,attempts,status:status.textContent,html:list.innerHTML}}));
|
||||
}})().catch(error=>{{console.error(error);process.exit(1);}});
|
||||
"""
|
||||
result = subprocess.run(["node", "-e", harness], check=True, capture_output=True, text=True)
|
||||
|
||||
assert json.loads(result.stdout) == {
|
||||
"first": False,
|
||||
"reconnecting": "Assigned work is reconnecting…",
|
||||
"attempts": 2,
|
||||
"status": "1 assigned work item ready.",
|
||||
"html": '<article class="my-work-card progressive-my-work-card"><button class="my-work-card-main" type="button" data-progressive-work-index="0"><strong>Recovered assignment</strong><span class="small">stackchain/dashboard#9 · Assigned to you</span></button></article>',
|
||||
}
|
||||
|
||||
|
||||
def test_progressive_my_work_refreshes_with_revisions_and_coalesces_lifecycle_recovery():
|
||||
harness = f"""
|
||||
const fs=require('fs'); const vm=require('vm');
|
||||
const list={{innerHTML:''}}; const status={{textContent:''}};
|
||||
const document={{
|
||||
hidden:false,
|
||||
querySelector:selector=>selector==='#my-work-list'?list:selector==='#my-work-status'?status:null,
|
||||
querySelectorAll:()=>[],
|
||||
}};
|
||||
const handlers={{}}; const removed=[];
|
||||
const lifecycleTarget={{
|
||||
addEventListener:(name,callback)=>{{handlers[name]=callback;}},
|
||||
removeEventListener:(name,callback)=>{{if(handlers[name]===callback){{removed.push(name);delete handlers[name];}}}},
|
||||
}};
|
||||
let timer=null; let calls=[]; let resolveRefresh;
|
||||
const initial={{
|
||||
context:{{user:{{login:'timmy'}},issues:[],pull_requests:[]}},events:[],notifications:[],
|
||||
revisions:{{context:'0123456789abcdef.1',events:'fedcba9876543210.2',notifications:'0011223344556677.3'}},
|
||||
freshness:{{fresh_for_seconds:8,sections:{{context:{{degraded:false,age_seconds:2}},events:{{degraded:false,age_seconds:2}},notifications:{{degraded:false,age_seconds:2}}}}}},
|
||||
}};
|
||||
const updated={{...initial,context:{{user:{{login:'timmy'}},issues:[{{number:10,title:'New assignment',repository:'stackchain/dashboard',assignees:['timmy']}}],pull_requests:[]}}}};
|
||||
const context={{module:{{exports:{{}}}},exports:{{}},console,URL,URLSearchParams,AbortController,document}};
|
||||
vm.createContext(context);
|
||||
vm.runInContext(fs.readFileSync({json.dumps(str(MY_WORK))},'utf8'),context);
|
||||
context.buildMyWork=context.module.exports; context.module={{exports:{{}}}};
|
||||
vm.runInContext(fs.readFileSync({json.dumps(str(Path(__file__).parents[1] / 'frontend' / 'context-poller.js'))},'utf8'),context);
|
||||
context.createContextPoller=context.module.exports; context.module={{exports:{{}}}};
|
||||
vm.runInContext(fs.readFileSync({json.dumps(str(MODULE))},'utf8'),context);
|
||||
const flow=context.module.exports({{
|
||||
document,lifecycleTarget,
|
||||
fetchSnapshot:(revisions,options)=>{{
|
||||
calls.push({{revisions,hasSignal:Boolean(options.signal)}});
|
||||
if(calls.length===1)return Promise.resolve(initial);
|
||||
return new Promise(resolve=>{{resolveRefresh=()=>resolve(updated);}});
|
||||
}},
|
||||
pollerOptions:{{
|
||||
setTimer:callback=>{{timer=callback;return 1;}},clearTimer:()=>{{timer=null;}},
|
||||
setDeadlineTimer:()=>2,clearDeadlineTimer:()=>{{}},intervalMs:5,
|
||||
}},
|
||||
}});
|
||||
(async()=>{{
|
||||
await flow.start(); const freshnessTimer=timer; freshnessTimer();
|
||||
handlers.online(); handlers.visibilitychange();
|
||||
await Promise.resolve();
|
||||
const callsWhilePending=calls.length;
|
||||
resolveRefresh(); await Promise.resolve(); await new Promise(resolve=>setImmediate(resolve));
|
||||
const handoff=flow.handoff(); flow.stop();
|
||||
console.log(JSON.stringify({{
|
||||
callsWhilePending,calls,latestTitle:handoff.liveSnapshot.context.issues[0].title,
|
||||
removed:removed.sort(),status:status.textContent,
|
||||
}}));
|
||||
}})().catch(error=>{{console.error(error);process.exit(1);}});
|
||||
"""
|
||||
result = subprocess.run(["node", "-e", harness], check=True, capture_output=True, text=True)
|
||||
state = json.loads(result.stdout)
|
||||
|
||||
assert state["callsWhilePending"] == 2
|
||||
assert state["calls"][0] == {"revisions": {}, "hasSignal": True}
|
||||
assert state["calls"][1] == {
|
||||
"revisions": {
|
||||
"context": "0123456789abcdef.1",
|
||||
"events": "fedcba9876543210.2",
|
||||
"notifications": "0011223344556677.3",
|
||||
},
|
||||
"hasSignal": True,
|
||||
}
|
||||
assert state["latestTitle"] == "New assignment"
|
||||
assert state["removed"] == ["keydown", "online", "visibilitychange"]
|
||||
assert state["status"] == "1 assigned work item ready."
|
||||
|
||||
|
||||
def test_progressive_card_opens_safe_in_app_detail_and_hands_it_off_once():
|
||||
harness = f"""
|
||||
const fs=require('fs'); const vm=require('vm');
|
||||
function element(extra={{}}) {{
|
||||
return Object.assign({{
|
||||
hidden:false,textContent:'',attrs:{{}},listeners:{{}},focusCount:0,
|
||||
addEventListener(name,cb){{this.listeners[name]=cb;}},
|
||||
removeEventListener(name,cb){{if(this.listeners[name]===cb)delete this.listeners[name];}},
|
||||
setAttribute(name,value){{this.attrs[name]=String(value);}},
|
||||
removeAttribute(name){{delete this.attrs[name];}},
|
||||
focus(){{this.focusCount += 1;}},
|
||||
}},extra);
|
||||
}}
|
||||
const list=element({{innerHTML:''}}); const status=element();
|
||||
const sheet=element({{hidden:true}}); const title=element(); const meta=element(); const reason=element();
|
||||
const close=element(); const gitea=element({{hidden:true,href:''}});
|
||||
const elements={{
|
||||
'#my-work-list':list,'#my-work-status':status,'#progressive-work-detail':sheet,
|
||||
'#progressive-work-detail-title':title,'#progressive-work-detail-meta':meta,
|
||||
'#progressive-work-detail-reason':reason,'#close-progressive-work-detail':close,
|
||||
'#open-progressive-work-gitea':gitea,
|
||||
}};
|
||||
const document={{querySelector:s=>elements[s]||null,querySelectorAll:()=>[]}};
|
||||
const lifecycleTarget=element();
|
||||
const context={{module:{{exports:{{}}}},exports:{{}},console,URL,document}}; vm.createContext(context);
|
||||
vm.runInContext(fs.readFileSync({json.dumps(str(MY_WORK))},'utf8'),context);
|
||||
context.buildMyWork=context.module.exports; context.module={{exports:{{}}}};
|
||||
vm.runInContext(fs.readFileSync({json.dumps(str(MODULE))},'utf8'),context);
|
||||
const flow=context.module.exports({{document,lifecycleTarget,fetchSnapshot:async()=>({{
|
||||
user:{{login:'timmy'}},issues:[{{number:7,title:'<img src=x onerror=alert(1)>',repository:'stackchain/dashboard',assignees:['timmy'],url:'https://forge.example/issues/7'}}],pull_requests:[]
|
||||
}})}});
|
||||
(async()=>{{
|
||||
await flow.start();
|
||||
const trigger=element({{dataset:{{progressiveWorkIndex:'0'}},closest:()=>trigger}});
|
||||
list.listeners.click({{target:trigger,preventDefault(){{}}}});
|
||||
const opened={{sheetHidden:sheet.hidden,title:title.textContent,meta:meta.textContent,reason:reason.textContent,giteaHidden:gitea.hidden,giteaHref:gitea.href,html:list.innerHTML}};
|
||||
lifecycleTarget.listeners.keydown({{key:'Escape',preventDefault(){{}}}});
|
||||
list.listeners.click({{target:trigger,preventDefault(){{}}}});
|
||||
const first=flow.handoff(); const second=flow.handoff();
|
||||
console.log(JSON.stringify({{opened,closed:sheet.hidden,focusCount:trigger.focusCount,first,second}}));
|
||||
}})().catch(error=>{{console.error(error);process.exit(1);}});
|
||||
"""
|
||||
result = subprocess.run(["node", "-e", harness], check=True, capture_output=True, text=True)
|
||||
state = json.loads(result.stdout)
|
||||
|
||||
assert state["opened"] == {
|
||||
"sheetHidden": False,
|
||||
"title": "<img src=x onerror=alert(1)>",
|
||||
"meta": "stackchain/dashboard#7 · Issue",
|
||||
"reason": "Assigned to you",
|
||||
"giteaHidden": False,
|
||||
"giteaHref": "https://forge.example/issues/7",
|
||||
"html": '<article class="my-work-card progressive-my-work-card"><button class="my-work-card-main" type="button" data-progressive-work-index="0"><strong><img src=x onerror=alert(1)></strong><span class="small">stackchain/dashboard#7 · Assigned to you</span></button></article>',
|
||||
}
|
||||
assert state["closed"] is False
|
||||
assert state["focusCount"] == 1
|
||||
assert state["first"]["openWork"] == {
|
||||
"kind": "issue",
|
||||
"key": "stackchain/dashboard#7",
|
||||
"number": 7,
|
||||
"repository": "stackchain/dashboard",
|
||||
}
|
||||
assert "openWork" not in state["second"]
|
||||
|
||||
|
||||
def test_progressive_detail_is_mobile_safe_and_adopted_by_hydrated_workspace():
|
||||
html = INDEX.read_text()
|
||||
css = CSS.read_text()
|
||||
dashboard = DASHBOARD.read_text()
|
||||
|
||||
assert 'id="progressive-work-detail" role="dialog" aria-modal="true"' in html
|
||||
assert 'aria-labelledby="progressive-work-detail-title" hidden' in html
|
||||
assert 'id="close-progressive-work-detail"' in html
|
||||
assert 'id="open-progressive-work-gitea"' in html
|
||||
assert ".progressive-work-detail[hidden] { display:none; }" in css
|
||||
assert "max-height:100dvh" in css
|
||||
assert "overflow-x:hidden" in css
|
||||
assert "env(safe-area-inset-top)" in css
|
||||
assert "env(safe-area-inset-bottom)" in css
|
||||
assert ".progressive-work-detail-panel button, .progressive-work-detail-panel .button-link" in css
|
||||
assert "min-height:44px" in css
|
||||
assert "@media(max-width:320px)" in css
|
||||
assert "progressiveWorkHandoff?.openWork" in dashboard
|
||||
assert "openRoutedWork(progressiveItem, null)" in dashboard
|
||||
assert "qs('#progressive-work-detail').hidden = true" in dashboard
|
||||
Loaded 100 of 121 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user