Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

feat(view): give each place its own address [N38,N26]

Corey Olson9c0d6e6cde09
diff --git a/src/cockpit.js b/src/cockpit.js
index 3c3f0df2..149cc6ce 100644
--- a/src/cockpit.js
+++ b/src/cockpit.js
@@ -184,11 +184,13 @@ function homeTab() {
const kept = keep('pb.tab');
return kept && kept !== 'roadmap' ? kept : 'items';
}
-const view = { roadmapOpen: new Map(), root: keep('pb.project'), tab: addressTab() || homeTab(), itemsView: typeof location !== 'undefined' && location.hash === '#items/pipeline' ? 'pipeline' : 'list', seen: {}, code: {}, item: null, adding: false, declining: null, state: 'active', rows: { spec: 'decide', doctrine: 'all' }, row: { spec: null, doctrine: null }, agent: null, allAgents: false, agentsHidden: keep('pb.agents') === 'hidden', statsOpen: false, open: {} };
+const view = { roadmapOpen: new Map(), root: keep('pb.project'), tab: addressTab() || homeTab(), itemsView: typeof location !== 'undefined' && location.hash === '#items/pipeline' ? 'pipeline' : 'list', seen: {}, code: {}, item: null, adding: false, declining: null, state: 'active', rows: { spec: 'decide', doctrine: 'all' }, row: { spec: null, doctrine: null }, agent: null, allAgents: false, agentsHidden: keep('pb.agents') === 'hidden', statsOpen: false, open: {}, addressDetail: null, shout: null, scrollPlace: false };
let switchGeneration = 0;
if (snapshot) view.state = 'all';
let data = null;
let seen = '';
+let addressReady = false;
+const addressedShouts = new Map();
const $ = (id) => document.getElementById(id);
/**
* Draw the page in the theme the person picked, light or dark; with none picked it follows the system, live. The button
@@ -942,11 +944,24 @@ async function refresh() {
// The project this board is, so a switch still loading never reads it as the next one's.
next.root = root;
// Rebuild only when the board changed: a list rebuilt under the pointer can swallow a click.
+ if (!addressReady) {
+ data = next;
+ const place = snapshot ? null : placeAtAddress(next);
+ if (place?.root && place.root !== view.root) {
+ view.root = place.root;
+ keep('pb.project', view.root);
+ return refresh();
+ }
+ if (place) applyPlace(place, globalThis.history?.state);
+ addressReady = true;
+ }
const text = JSON.stringify(next);
if (text !== seen) {
seen = text;
data = next;
render();
+ address(false);
+ void loadAddressedShout();
}
if (snapshot && !snapshotReplay.final && data.project) {
snapshotReplay.final = structuredClone(data.project);
@@ -1456,7 +1471,7 @@ function render() {
$('pipeline').innerHTML = pipeline ? pipelineCard(shown) : '';
// With nothing picked, the detail shows the first row, and keeps it when a refresh reorders the list.
// While another project loads, the item picked there waits for its own board.
- if (data.root === view.root && !view.adding && !p.items.some((i) => i.id === view.item)) view.item = shown.length ? shown[0].id : null;
+ if (data.root === view.root && !view.adding && !(view.tab === 'items' && view.addressDetail !== null && view.addressDetail !== 'pipeline') && !p.items.some((i) => i.id === view.item)) view.item = shown.length ? shown[0].id : null;
// An open item's chip, the same in its row and its detail: gated, its lane held, or unclaimed.
const openChip = (i) => i.blockedBy.length || heldLanes.has(i.lane) ? '<span class="chip gate">' + (i.blockedBy.length ? 'gated' : 'lane held') + '</span>' : chip('open');
$('chain').innerHTML = shown.length ? shown.map((i) => {
@@ -1478,11 +1493,11 @@ function render() {
const item = p.items.find((i) => i.id === view.item);
// The form shows when asked for, or when the project has no item at all, withdrawn ones included.
- const adding = view.adding || !p.items.length;
+ const adding = view.adding || (!p.items.length && !(view.tab === 'items' && view.addressDetail !== null && view.addressDetail !== 'pipeline'));
$('add-form').hidden = !adding;
$('add-cancel').hidden = !p.items.length;
$('detail').hidden = adding;
- if (!item) $('detail').innerHTML = '<div class="empty">Pick an item to see its criterion, verdicts and history.</div>';
+ if (!item) $('detail').innerHTML = '<div class="empty">' + (view.tab === 'items' && view.addressDetail !== null && view.addressDetail !== 'pipeline' ? 'No item #' + esc(view.addressDetail) + ' exists here.' : 'Pick an item to see its criterion, verdicts and history.') + '</div>';
if (item && !view.adding) {
const s = stateOf(item);
const cited = item.specs.map((id) => p.spec.find((r) => r.id === id) || { id, status: 'missing', text: '(not in SPEC.md)' });
@@ -1547,7 +1562,10 @@ function render() {
const lead = (from) => from === 'coordinator';
// Opened from the status bar's unread, the feed is exactly those shouts, the ones after the mark the person had.
const unread = view.unread?.root === view.root ? view.unread : null;
- const heard = unread ? p.shouts.filter((x) => x.shout_id > unread.after) : view.agent ? p.shouts.filter((x) => x.shout_from === view.agent || x.shout_to === view.agent) : p.shouts;
+ const addressed = addressedShouts.get(JSON.stringify([view.root, view.shout]));
+ const feedShouts = addressed?.shout && !p.shouts.some((entry) => entry.shout_id === view.shout) ? [...p.shouts, addressed.shout] : p.shouts;
+ const heard = unread ? feedShouts.filter((x) => x.shout_id > unread.after) : view.agent ? feedShouts.filter((x) => x.shout_from === view.agent || x.shout_to === view.agent) : feedShouts;
+ if (view.tab === 'shouts' && view.shout !== null) openShouts.add(view.shout);
const bar = !unread && !view.agent ? '' : '<div class="feed-bar">' + (unread ? '<span><b>' + heard.length + '</b> unread <button class="link" data-unread type="button">show all</button></span>'
: '<span>Shouts with <b>' + esc(agentName(view.agent)) + '</b> <button class="link" data-agent="" type="button">show all</button></span>') + '</div>';
$('shouts-pane').classList.toggle('bare', view.agentsHidden);
@@ -1565,11 +1583,11 @@ function render() {
};
// One card for a shout, in the feed and among the asks; tail adds what the place needs, such as Answer. Only the
// feed's copy carries the band and the id an answer's link lands on, so an ask shown twice never repeats an id.
- const card = (x, tail = '', inFeed = true) => '<article class="shout h' + hue(x.shout_from) + (lead(x.shout_from) ? ' lead' : '') + (openShouts.has(x.shout_id) ? ' open' : '') + '"' + (inFeed ? ' id="shout-' + x.shout_id + '"' : '') + ' data-shout-id="' + x.shout_id + '">'
- + (lead(x.shout_from) ? '<span class="avatar">' + LEAD + '</span>' : '<span class="avatar' + (initials(x.shout_from).length > 3 ? ' wide' : '') + '" aria-hidden="true">' + esc(initials(x.shout_from)) + '</span>') + '<div class="shout-main"><header><b class="who">' + shoutAgentName(x.shout_from) + '</b><span class="to">→ ' + shoutAgentName(x.shout_to) + '</span>'
+ const card = (x, tail = '', inFeed = true) => '<article class="shout h' + hue(x.shout_from) + (lead(x.shout_from) ? ' lead' : '') + (openShouts.has(x.shout_id) ? ' open' : '') + (inFeed && x.shout_id === view.shout ? ' found' : '') + '"' + (inFeed ? ' id="shout-' + x.shout_id + '"' : '') + ' data-shout-id="' + x.shout_id + '">'
+ + (lead(x.shout_from) ? '<span class="avatar">' + LEAD + '</span>' : '<span class="avatar' + (initials(x.shout_from).length > 3 ? ' wide' : '') + '" aria-hidden="true">' + esc(initials(x.shout_from)) + '</span>') + '<div class="shout-main">' + (inFeed && x.shout_id === view.shout ? '<h2>Shout #' + x.shout_id + '</h2>' : '') + '<header><b class="who">' + shoutAgentName(x.shout_from) + '</b><span class="to">→ ' + shoutAgentName(x.shout_to) + '</span>'
+ (itemOf(x) ? '<span class="item">#' + esc(itemOf(x)) + '</span>' : '') + mark(x) + '<time class="long" data-ago="' + esc(x.shout_at) + '" title="' + esc(when(x.shout_at)) + '">' + agoLong(x.shout_at) + '</time></header>'
+ '<div class="text">' + rich(x.shout_text, titles) + '</div><button class="more" data-more type="button">' + (openShouts.has(x.shout_id) ? 'less' : 'more') + '</button>' + (inFeed ? band(x) + heardBy(x) : '') + evidence(x) + tail + '</div></article>';
- $('feed').innerHTML = bar + (heard.length ? dayRules(heard, (x) => x.shout_at, card) : '<div class="empty">' + (unread ? 'No unread shouts.' : view.agent ? 'No shouts with ' + esc(agentName(view.agent)) + ' among the last forty.' : 'No shouts yet.') + '</div>');
+ $('feed').innerHTML = (view.shout !== null && !feedShouts.some((entry) => entry.shout_id === view.shout) ? '<p class="empty" id="shout-address-status" role="status">' + esc(addressed?.error || 'Loading shout #' + view.shout + '…') + '</p>' : '') + bar + (heard.length ? dayRules(heard, (x) => x.shout_at, card) : '<div class="empty">' + (unread ? 'No unread shouts.' : view.agent ? 'No shouts with ' + esc(agentName(view.agent)) + ' among the last forty.' : 'No shouts yet.') + '</div>');
foldShouts();
// Each ask waits here until it is answered (B21); the answer itself is typed in the form below. The
// person answers the ones passed up to them; the rest wait on whoever holds them (B26).
@@ -1641,7 +1659,7 @@ function render() {
$(kind + '-chips').innerHTML = Object.keys(labels).map((f) => '<button data-rows="' + kind + ':' + f + '" class="' + (filter === f ? 'on' : '') + '" type="button">' + labels[f] + '<b>' + n[f] + '</b></button>').join('');
const shownRows = rows.filter((r) => filter === 'all' || (filter === 'decide' ? undecided(r) : r.status === 'approved'));
// With no row picked, or the pick filtered out, the detail opens on the first row shown, as Items does.
- if (!shownRows.some((r) => r.id === view.row[kind])) view.row[kind] = shownRows[0]?.id ?? null;
+ if (!(view.tab === kind && view.addressDetail !== null) && !shownRows.some((r) => r.id === view.row[kind])) view.row[kind] = shownRows[0]?.id ?? null;
const feedback = view.specFeedback?.kind === kind && view.specFeedback.root === view.root && view.specFeedback.from === 'list' ? view.specFeedback : null;
const feedbackId = feedback && (shownRows.some((r) => r.id === feedback.id) ? feedback.id : shownRows.some((r) => r.id === feedback.next) ? feedback.next : shownRows[0]?.id);
let section = null;
@@ -1674,7 +1692,7 @@ function render() {
const rowDecisionActions = !snapshot && (!readOnly || requests) && row && undecided(row) && (kind === 'spec' || row.origin !== 'standard')
? '<div class="spec-decision-actions detail-decision-actions"><button class="approve-row" data-row-decision="approve" data-row-kind="' + kind + '" data-row-id="' + esc(row.id) + '" title="Approve (A, from the list)" type="button">Approve <kbd>A</kbd></button><button class="decline-row" data-row-decision="decline" data-row-kind="' + kind + '" data-row-id="' + esc(row.id) + '" title="Decline (D, from the list)" type="button">Decline <kbd>D</kbd></button></div>'
: '';
- $(kind + '-detail').innerHTML = row ? '<div class="stack tight"><h2><span>' + esc(row.id) + '</span>' + text + '</h2><div class="meta"><span class="chip ' + tone(row.status) + '">' + esc(rowStatus) + '</span>' + (row.tier ? '<span class="chip">' + esc(row.tier) + '</span>' : '') + source + '</div>' + rowDecisionActions + (kind === 'spec' && view.specFeedback?.kind === kind && view.specFeedback.root === view.root && view.specFeedback.from === 'detail' && view.specFeedback.id === row.id ? specFeedback(view.specFeedback) : '') + '<dl class="kv"><dt>section</dt><dd>' + esc(row.section) + '</dd>' + reason + (row.gate ? '<dt>gate</dt><dd>' + esc(row.gate) + '</dd>' : '') + (row.serves && row.serves.length ? '<dt>serves</dt><dd>' + esc(row.serves.join(', ')) + '</dd>' : '') + '</dl><div><h3>Items that cite it</h3>' + (citing.length ? '<div class="links">' + citing.map((i) => '<div class="links-item" data-item="' + i.id + '"><span>#' + i.id + ' ' + rich(i.title, titles) + '</span></div>').join('') + '</div>' : '<div class="muted">None yet.</div>') + '</div><div class="muted">' + home + '</div></div>' : '<div class="empty">Pick a row to see it, and the items that cite it.</div>';
+ $(kind + '-detail').innerHTML = row ? '<div class="stack tight"><h2><span>' + esc(row.id) + '</span>' + text + '</h2><div class="meta"><span class="chip ' + tone(row.status) + '">' + esc(rowStatus) + '</span>' + (row.tier ? '<span class="chip">' + esc(row.tier) + '</span>' : '') + source + '</div>' + rowDecisionActions + (kind === 'spec' && view.specFeedback?.kind === kind && view.specFeedback.root === view.root && view.specFeedback.from === 'detail' && view.specFeedback.id === row.id ? specFeedback(view.specFeedback) : '') + '<dl class="kv"><dt>section</dt><dd>' + esc(row.section) + '</dd>' + reason + (row.gate ? '<dt>gate</dt><dd>' + esc(row.gate) + '</dd>' : '') + (row.serves && row.serves.length ? '<dt>serves</dt><dd>' + esc(row.serves.join(', ')) + '</dd>' : '') + '</dl><div><h3>Items that cite it</h3>' + (citing.length ? '<div class="links">' + citing.map((i) => '<div class="links-item" data-item="' + i.id + '"><span>#' + i.id + ' ' + rich(i.title, titles) + '</span></div>').join('') + '</div>' : '<div class="muted">None yet.</div>') + '</div><div class="muted">' + home + '</div></div>' : '<div class="empty">' + (view.tab === kind && view.addressDetail !== null ? 'No ' + (kind === 'spec' ? 'Spec' : 'Doctrine') + ' row ' + esc(view.addressDetail) + ' exists here.' : 'Pick a row to see it, and the items that cite it.') + '</div>';
}
if (keep('pb.flow') !== 'hidden') $('flow').innerHTML = flowSvg(p);
@@ -1691,6 +1709,7 @@ function render() {
};
$('activity').innerHTML = p.events.length ? byDay(p.events, (e) => e.event_at, (e) => '<div><time>' + clock(e.event_at) + '</time><div class="act">' + (e.event_kind === 'shout' || e.event_kind === 'answer' ? spoke(e) : '<b>' + esc(agentName(e.event_by)) + '</b> ' + esc(e.event_kind) + (e.item_id ? ' <button class="ref" data-go="item:' + e.item_id + '" type="button">#' + e.item_id + '</button>' + (titles.has(String(e.item_id)) ? ' <span class="what">' + rich(titles.get(String(e.item_id)), titles) + '</span>' : '') : '')) + '</div></div>') : '<div class="empty">No activity yet.</div>';
showTab();
+ revealPlace();
}
/**
@@ -1712,53 +1731,137 @@ function showTab() {
if (view.tab === 'shouts') foldShouts();
}
-/** The address that names a tab: the Roadmap's own, or the board's, keeping the rest as it is. */
+/** Read the selected repo, tab and detail from a path or the hosted page's fragment. */
+function placeAtAddress(page = data) {
+ const tabs = ['items', 'shouts', 'spec', 'doctrine', 'activity', 'roadmap'];
+ const hash = location.hash || '';
+ let path = routed ? location.pathname || '/' : hash.slice(1);
+ if (hash === '#items/pipeline' || hash === '#roadmap') path = hash.slice(1);
+ if (hash.startsWith('#shout-')) path = 'shouts/' + hash.slice(7);
+ let parts;
+ try { parts = path.split('/').filter(Boolean).map(decodeURIComponent); }
+ catch { parts = []; }
+ const repo = page?.projects.find((entry) => entry.ok && entry.name === parts[0]);
+ const group = page?.groups.find((entry) => entry.name === parts[0]);
+ const named = (repo || group) && tabs.includes(parts[1]);
+ const root = named ? repo?.root || group.key : null;
+ if (named) parts.shift();
+ const tab = tabs.includes(parts[0]) ? parts.shift() : (!path && transportModule && globalThis.history?.state?.tab) || homeTab();
+ return { root, tab, detail: parts[0] ?? null };
+}
+
+/** Name each repo even beneath a group; one repo needs no prefix. */
function tabHref(tab) {
- const own = tab === 'roadmap';
- if (tab === 'items' && view.itemsView === 'pipeline') return (routed ? '/' : location.pathname) + location.search + '#items/pipeline';
- return routed ? (own ? '/roadmap' : '/') + location.search : location.pathname + location.search + (own ? '#roadmap' : '');
+ if (snapshot) {
+ if (tab === 'items' && view.itemsView === 'pipeline') return location.pathname + location.search + '#items/pipeline';
+ return location.pathname + location.search + (tab === 'roadmap' ? '#roadmap' : '');
+ }
+ const repo = data?.projects.find((entry) => entry.root === view.root);
+ const group = data?.groups.find((entry) => entry.key === view.root);
+ const name = repo?.name || group?.name;
+ const prefix = (data?.projects.filter((entry) => entry.ok).length || 0) > 1 && name ? '/' + encodeURIComponent(name) : '';
+ const detail = tab === 'items' && view.itemsView === 'pipeline' && (view.addressDetail === null || view.addressDetail === 'pipeline') ? 'pipeline' : view.addressDetail;
+ const path = prefix + '/' + tab + (detail === null ? '' : '/' + encodeURIComponent(String(detail)));
+ return routed ? path + location.search : location.pathname + location.search + '#' + path.slice(1);
}
-/**
- * Keep the address naming what the page shows (N38). Moving between the Roadmap and another tab
- * changes it and adds a history entry, so Back and Forward return there; anything else, or push
- * false, only updates the entry. Each entry carries its project and item too, so returning to one
- * shows that board as it was. A host that refuses the change still shows the tab.
- */
+/** Push one entry per changed place, and retain native fact anchors when restoring an entry. */
function address(push = true) {
- if (typeof history === 'undefined' || typeof location === 'undefined') return;
- const state = { tab: view.tab, root: view.root, item: view.item, itemsView: view.itemsView };
- const href = tabHref(view.tab);
+ if (typeof history === 'undefined' || typeof location === 'undefined' || !addressReady) return;
+ const state = { tab: view.tab, root: view.root, item: view.item, itemsView: view.itemsView, detail: view.addressDetail };
+ let href = tabHref(view.tab);
+ if (!push && routed && location.hash && !['#roadmap', '#items/pipeline'].includes(location.hash)) href += location.hash;
try {
if (push && href !== location.pathname + location.search + (location.hash || '')) history.pushState(state, '', href);
- else history.replaceState(state, '');
- } catch { /* The tab shows all the same. */ }
+ else if (transportModule && !location.hash && view.tab === 'items' && view.addressDetail === null) history.replaceState(state, '');
+ else history.replaceState(state, '', href);
+ } catch { /* A host that refuses history changes still shows the selected place. */ }
+}
+
+/** Apply a parsed selection without recording another history entry. */
+function applyPlace(place, kept = null) {
+ if (place.root) view.root = place.root;
+ view.tab = place.tab;
+ view.addressDetail = place.detail;
+ view.item = place.tab === 'items' && place.detail !== null && place.detail !== 'pipeline' ? Number(place.detail) : null;
+ view.itemsView = place.tab === 'items' && place.detail === 'pipeline' ? 'pipeline' : 'list';
+ if (place.tab === 'items' && kept?.root === view.root && kept.tab === place.tab && kept.detail === place.detail && kept.itemsView === 'pipeline') view.itemsView = 'pipeline';
+ view.shout = place.tab === 'shouts' && place.detail !== null ? Number(place.detail) : null;
+ view.agent = null;
+ view.unread = null;
+ view.roadmapOnly = null;
+ if (place.tab === 'spec' || place.tab === 'doctrine') {
+ view.row[place.tab] = place.detail;
+ if (place.detail !== null) view.rows[place.tab] = 'all';
+ }
+ view.scrollPlace = place.detail !== null;
+ keep('pb.project', view.root);
+ if (place.tab !== 'roadmap') keep('pb.tab', place.tab);
}
-/**
- * Show what a history entry names, on Back, Forward or an edited #roadmap: the tab its address
- * names, or at the board's address the tab the entry kept, and the project and item it kept.
- */
+/** Restore the address on Back and Forward, with a scoped refresh when the repo changes. */
function fromAddress(event) {
- const kept = (event && event.state) || {};
- view.itemsView = location.hash === '#items/pipeline' ? 'pipeline' : kept.itemsView === 'pipeline' && kept.tab !== 'items' ? 'pipeline' : 'list';
- view.tab = addressTab() || (kept.tab && kept.tab !== 'roadmap' ? kept.tab : homeTab());
- if (view.tab !== 'roadmap') keep('pb.tab', view.tab);
- const item = typeof kept.item === 'number' ? kept.item : null;
- if (kept.root && kept.root !== view.root && data && data.projects.some((x) => x.ok && x.root === kept.root)) return switchTo(kept.root, item, false);
- if (item !== null && view.tab === 'items') view.item = item;
+ if (!data) return;
+ if (snapshot) {
+ const kept = event?.state || {};
+ view.tab = addressTab() || kept.tab || homeTab();
+ view.itemsView = location.hash === '#items/pipeline' ? 'pipeline' : 'list';
+ if (typeof kept.item === 'number') view.item = kept.item;
+ if (kept.root && kept.root !== view.root) return switchTo(kept.root, view.item, false);
+ } else {
+ const place = placeAtAddress();
+ // A native timeline anchor keeps its existing DOM target and the browser's own scroll.
+ if ((location.hash || '').startsWith('#fact-') && place.tab === 'items' && (!place.root || place.root === view.root) && (place.detail === null || Number(place.detail) === view.item)) { address(false); return; }
+ const previous = view.root;
+ applyPlace(place, event?.state);
+ if (previous !== view.root) return switchTo(view.root, view.item, false);
+ }
address(false);
- if (data) render();
- else showTab();
+ render();
+ void loadAddressedShout();
}
-/** Pick a tab. The board's address keeps it for next time; the Roadmap has an address of its own. */
-function openTab(tab) {
+/** Pick a tab or an explicit detail and record the complete place once. */
+function openTab(tab, detail = null) {
view.tab = tab;
+ view.addressDetail = detail;
+ view.shout = tab === 'shouts' && detail !== null ? Number(detail) : null;
+ view.scrollPlace = detail !== null;
if (tab !== 'roadmap') keep('pb.tab', tab);
address();
}
+/** Fetch one old shout through the same public read API used by local and relay views. */
+async function loadAddressedShout() {
+ if (!data?.project || view.tab !== 'shouts' || view.shout === null || data.root !== view.root) return;
+ const root = view.root, id = view.shout, key = JSON.stringify([root, id]);
+ if (data.project.shouts.some((entry) => entry.shout_id === id) || addressedShouts.has(key)) return;
+ const entry = { shout: null, error: null };
+ addressedShouts.set(key, entry);
+ try {
+ const reply = await api(boardPath(root) + '/shouts/' + encodeURIComponent(String(id)));
+ entry.shout = reply.shout;
+ } catch (error) {
+ const message = String(error.message || error);
+ entry.error = transportModule && !message.includes('NO_SHOUT')
+ ? 'This shout is older than the relay holds. Open its address in the local project view.'
+ : 'No shout #' + id + ' exists here. ' + message;
+ }
+ if (view.root === root && view.shout === id && view.tab === 'shouts') render();
+}
+
+/** Scroll a newly addressed detail once, after its real content has arrived. */
+function revealPlace() {
+ if (!view.scrollPlace) return;
+ const fact = view.tab === 'items' && (location.hash || '').startsWith('#fact-') ? $(location.hash.slice(1)) : null;
+ const element = fact || (view.tab === 'shouts' ? $('shout-' + view.shout)
+ : view.tab === 'items' ? $('detail')
+ : ['spec', 'doctrine'].includes(view.tab) ? $(view.tab + '-detail') : null);
+ if (!element || (view.tab === 'shouts' && !element.querySelector('h2'))) return;
+ element.scrollIntoView({ block: 'center', behavior: 'instant' });
+ view.scrollPlace = false;
+}
+
/**
* Count on the Shouts tab the shouts that came after the newest one the person has seen in this
* project. Seeing means having the Shouts tab open with the board drawn; a project shown for the
@@ -1858,10 +1961,9 @@ function go(target, root = view.root) {
else if (kind === 'shout') { tab = 'shouts'; view.agent = null; view.unread = null; }
else if (kind === 'tab') tab = id;
else if (kind === 'decide') { tab = 'shouts'; answer(Number(id)); }
- openTab(tab);
- if (kind === 'item') pick(Number(id), root);
- else render();
- if (kind === 'shout') { const card = document.getElementById('shout-' + id); card?.scrollIntoView({ block: 'center' }); card?.classList.add('found'); setTimeout(() => card?.classList.remove('found'), 1600); }
+ if (kind === 'item') { view.tab = 'items'; view.itemsView = 'list'; pick(Number(id), root); }
+ else { openTab(tab, ['spec', 'doctrine', 'shout'].includes(kind) ? id : null); render(); }
+ if (kind === 'shout') void loadAddressedShout();
}
/** An item's state as a word, for a search result. */
@@ -1917,8 +2019,11 @@ function openFound(target) {
function pick(id, root = view.root) {
view.adding = false;
if (root !== view.root) return switchTo(root, id);
+ view.tab = 'items';
+ keep('pb.tab', view.tab);
view.item = id;
- address(false);
+ view.addressDetail = String(id);
+ address();
render();
reveal();
}
@@ -2201,7 +2306,7 @@ function switchTo(root, target = null, record = true) {
view.adding = false;
if (record && view.item !== null) { view.tab = 'items'; keep('pb.tab', view.tab); }
keep('pb.project', root);
- if (record) address(false);
+ if (record) { view.addressDetail = requestedItem === null ? null : String(requestedItem); view.shout = null; address(); }
fold(false);
// The board that arrives is drawn even if it matches the last one seen, so the pick is made from it.
seen = '';
@@ -2242,7 +2347,7 @@ $('shouts-pane').addEventListener('click', (event) => {
// Enter shouts; Shift+Enter starts a new line.
$('shout-text').addEventListener('keydown', (event) => { if (event.key === 'Enter' && !event.shiftKey && !event.isComposing) { event.preventDefault(); $('shout-form').requestSubmit(); } });
document.addEventListener('click', (event) => {
- const t = event.target.closest('[data-status],[data-roadmap-key],[data-roadmap-all],[data-root],[data-tab],[data-go],[data-item],[data-items-view],[data-state],[data-rows],[data-row],[data-row-decision],[data-section-approve],[data-release],[data-shout],[data-new],[data-code],[data-code-all],[data-code-less],[data-stats-toggle],[data-stats-close],#proj-switch,#console');
+ const t = event.target.closest('[data-status],[data-shout-id],[data-roadmap-key],[data-roadmap-all],[data-root],[data-tab],[data-go],[data-item],[data-items-view],[data-state],[data-rows],[data-row],[data-row-decision],[data-section-approve],[data-release],[data-shout],[data-new],[data-code],[data-code-all],[data-code-less],[data-stats-toggle],[data-stats-close],#proj-switch,#console');
if (!event.target.closest('.side')) fold(false);
if (!t) return;
if (t.id === 'proj-switch') { fold(!$('side').classList.contains('open')); return; }
@@ -2260,7 +2365,7 @@ document.addEventListener('click', (event) => {
return;
}
if (t.dataset.status) { statusGo(t.dataset.status); return; }
- if (t.dataset.itemsView) { view.itemsView = t.dataset.itemsView; address(); render(); return; }
+ if (t.dataset.itemsView) { view.itemsView = t.dataset.itemsView; view.addressDetail = null; address(); render(); return; }
if ('roadmapKey' in t.dataset) {
const key = t.dataset.roadmapKey;
view.roadmapOpen.set(JSON.stringify([view.root, key]), t.getAttribute('aria-expanded') !== 'true');
@@ -2270,11 +2375,18 @@ document.addEventListener('click', (event) => {
}
if ('roadmapAll' in t.dataset) { view.roadmapOnly = null; render(); return; }
if (t.dataset.root) switchTo(t.dataset.root, t.dataset.go || '');
- else if (t.dataset.tab) { view.unread = null; view.roadmapOnly = null; openTab(t.dataset.tab); showTab(); }
+ else if (t.dataset.tab) { view.unread = null; view.roadmapOnly = null; openTab(t.dataset.tab); render(); }
else if (t.dataset.go) go(t.dataset.go, t.dataset.board);
else if (t.dataset.item) pick(Number(t.dataset.item));
else if (t.dataset.state) { view.state = t.dataset.state; render(); }
- else if (t.dataset.rows) { const [kind, f] = t.dataset.rows.split(':'); view.rows[kind] = f; render(); }
+ else if (t.dataset.rows) {
+ const [kind, f] = t.dataset.rows.split(':');
+ const addressed = view.addressDetail !== null;
+ view.rows[kind] = f;
+ view.addressDetail = null;
+ render();
+ if (addressed) { view.addressDetail = view.row[kind]; address(); }
+ }
else if (t.dataset.rowDecision) {
const id = t.dataset.rowId, kind = t.dataset.rowKind;
if (t.dataset.rowDecision === 'approve') decideRow(kind, 'spec-approve', { ids: id }, t);
@@ -2285,9 +2397,12 @@ document.addEventListener('click', (event) => {
const ids = data.project.spec.filter((row) => row.section === section && ['pending', 'draft'].includes(row.status) && !row.decision).map((row) => row.id);
if (ids.length && window.confirm('Approve all ' + ids.length + ' undecided rows in “' + section + '”?')) decideRow('spec', 'spec-approve', { ids: ids.join(' ') }, t);
}
+ else if (t.dataset.shoutId && !event.target.closest('button,a,input,textarea,select')) { go('shout:' + t.dataset.shoutId); }
else if (t.dataset.row) {
const [kind, id] = t.dataset.row.split(':');
view.row[kind] = id;
+ view.addressDetail = id;
+ address();
render();
$(kind + '-list').focus({ preventScroll: true });
// Where the list and the detail stack, the picked row's detail, with its buttons, comes into view.
@@ -2327,7 +2442,7 @@ for (const kind of ['spec', 'doctrine']) $(kind + '-list').addEventListener('key
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
event.preventDefault();
const next = ids[Math.min(ids.length - 1, Math.max(0, at + (event.key === 'ArrowDown' ? 1 : -1)))];
- if (next && next !== view.row[kind]) { view.row[kind] = next; render(); event.currentTarget.querySelector('.srow.on')?.scrollIntoView({ block: 'nearest' }); }
+ if (next && next !== view.row[kind]) { view.row[kind] = next; view.addressDetail = next; address(); render(); event.currentTarget.querySelector('.srow.on')?.scrollIntoView({ block: 'nearest' }); }
} else if (event.key === 'Enter' && view.row[kind]) {
event.preventDefault();
$(kind + '-detail').scrollIntoView({ block: 'start', behavior: 'instant' });
diff --git a/src/serve.js b/src/serve.js
index 8e07f14f..c5a45592 100644
--- a/src/serve.js
+++ b/src/serve.js
@@ -352,7 +352,7 @@ export async function serveView({ port = 0, secret = randomBytes(18).toString('b
if (!isOwnHost || given.length !== key.length || !timingSafeEqual(given, key)) return json(res, 403, { error: 'this view needs its own address and secret: open the link pullboard view printed' });
try {
// The board, and the Roadmap at its own address (N38), are the one page.
- if (req.method === 'GET' && (url.pathname === '/' || url.pathname === '/roadmap')) return reply(res, 200, 'text/html; charset=utf-8', cockpitPage(secret, { paths: true }));
+ if (req.method === 'GET' && (url.pathname === '/' || /^\/(?:[^/]+\/)?(?:items|shouts|spec|doctrine|activity|roadmap)(?:\/[^/]+)?$/.test(url.pathname))) return reply(res, 200, 'text/html; charset=utf-8', cockpitPage(secret, { paths: true }));
if (req.method === 'GET' && url.pathname === '/view.css') return reply(res, 200, 'text/css; charset=utf-8', VIEW_CSS);
return json(res, 404, { error: 'no such page' });
} catch (error) {
diff --git a/test/cockpit/addresses.test.js b/test/cockpit/addresses.test.js
new file mode 100644
index 00000000..588c4271
--- /dev/null
+++ b/test/cockpit/addresses.test.js
@@ -0,0 +1,286 @@
+/** Real-input addresses, rendered places and browser history [N38,N26]. */
+import assert from 'node:assert/strict';
+import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { test } from 'node:test';
+import { stableChrome } from './stable.js';
+import { relayClientFixture } from '../relay-client-fixture.js';
+import { startChrome, relayWorkBudgetMs } from '../relay-browser-fixture.js';
+import { SPEC, machine, project, startView, boardOf, chromeExecutable, openSnapshotChrome, closeSnapshotChrome, press, travel, settled } from './fixture.js';
+
+const SCRIPT = "typeof view === 'object' && typeof data === 'object' && !!data?.project && data.root === view.root && !document.body.classList.contains('loading')";
+/** Read the actual rendered place without waiting for the expected answer. */
+async function observed(chrome) {
+ return JSON.parse(await chrome.stable(`JSON.stringify({ address:location.pathname + location.hash, root:view.root, tab:document.querySelector('.tab.on')?.dataset.tab, panes:[...document.querySelectorAll('[data-pane]')].filter(node => !node.hidden).map(node => node.dataset.pane) })`));
+}
+/** Check the address, repo and visible pane independently of internal selection state. */
+async function assertPlace(chrome, address, pane, root) {
+ assert.deepEqual(await observed(chrome), { address, root, tab: pane, panes: [pane] });
+}
+/** Navigate from a blank page and wait for the new document's script before reading its board. */
+async function openAddress(chrome, server, address) {
+ await chrome.send('Page.navigate', { url: 'about:blank' });
+ await settled(chrome, "location.href === 'about:blank'");
+ const target = new URL(address, server.link);
+ target.search = server.link.search;
+ await chrome.send('Page.navigate', { url: target.href });
+ await settled(chrome, SCRIPT);
+}
+/** Assert the detail itself, so suppressing row rendering produces an assertion failure. */
+async function assertHeading(chrome, selector, id, text) {
+ const heading = await chrome.stable(`document.querySelector(${JSON.stringify(selector + ' h2')})?.textContent ?? null`);
+ assert.ok(heading?.includes(id) && heading.includes(text), `detail heading names ${id} ${text}: ${heading}`);
+}
+/** Read the real browser stack, including same-document pushState entries. */
+async function history(chrome) {
+ const { currentIndex, entries } = await chrome.send('Page.getNavigationHistory');
+ return { currentIndex, length: entries.length };
+}
+/** Click once, await the normal rendering boundary, then assert exactly one new place entry. */
+async function onePlace(chrome, selector, address, pane, root) {
+ const before = await history(chrome);
+ await press(chrome, selector);
+ await settled(chrome, SCRIPT);
+ await assertPlace(chrome, address, pane, root);
+ const after = await history(chrome);
+ assert.deepEqual(after, { currentIndex: before.currentIndex + 1, length: before.length + 1 }, `${address}: one entry per change`);
+ return { address, pane, root };
+}
+/** Create distinct real rows without duplicate identifiers, and two real items. */
+function addressBoard(box, name, group) {
+ const spec = SPEC.replace(/^- G2 .*$/m, `- G2 [pending, must] ${name} distinct specification row. | gate: review`);
+ const p = project(box, name, spec, { practice: 'DOCTRINE.md', ...(group ? { project: group } : {}) });
+ writeFileSync(join(p.repo, 'DOCTRINE.md'), `# Local rules\n\n## Team\n- PB1 [approved, must] ${name} distinct practice rule. | gate: review\n`);
+ box.run(p.repo, 'add', 'web', `${name} first address item`, '--specs', 'G1');
+ box.run(p.repo, 'add', 'web', `${name} second address item`, '--specs', 'G1');
+ box.run(p.repo, 'milestone', 'add', `${name} address milestone`, '--items', '1,2');
+ return p;
+}
+/** Own one browser and server, with cleanup even if an assertion fails. */
+async function withBrowser(box, run) {
+ const executable = chromeExecutable();
+ assert.ok(executable, 'real Chrome is required for address checks');
+ const server = await startView(box);
+ const profile = mkdtempSync(join(tmpdir(), 'pullboard-addresses-'));
+ let chrome;
+ try {
+ chrome = await openSnapshotChrome(executable, server.link.href, profile);
+ await settled(chrome, SCRIPT);
+ await run(chrome, server);
+ assert.deepEqual(chrome.exceptions, [], 'new-document navigation causes no page exceptions');
+ } finally {
+ if (chrome) await closeSnapshotChrome(chrome);
+ await server.stop();
+ rmSync(profile, { recursive: true, force: true });
+ }
+}
+/** Wait only for the addressed lookup to finish, then inspect the real target and its viewport box. */
+async function assertShout(chrome, id, text) {
+ await settled(chrome, `${SCRIPT} && !document.querySelector('#shout-address-status')?.textContent.startsWith('Loading')`);
+ const result = JSON.parse(await chrome.stable(`JSON.stringify((() => {
+ const node=document.getElementById('shout-${id}'), rect=node?.getBoundingClientRect();
+ return { text:node?.querySelector('.text')?.textContent ?? null, heading:node?.querySelector('h2')?.textContent ?? null, marked:node?.classList.contains('found') ?? false, top:rect?.top, bottom:rect?.bottom, bar:document.querySelector('.top').getBoundingClientRect().bottom, height:innerHeight };
+ })())`));
+ assert.equal(result.text, text, 'the addressed shout body is rendered');
+ assert.equal(result.heading, `Shout #${id}`, 'the addressed shout has its own heading');
+ assert.equal(result.marked, true, 'the addressed shout stays marked');
+ assert.ok(result.top >= result.bar && result.bottom <= result.height, `the shout is visible below the tab bar: ${JSON.stringify(result)}`);
+}
+
+test('every place in the view has its own address [N38,N26]', { timeout: 180_000 }, async () => { // budget: hang-only ceiling for the complete direct-address matrix.
+ const box = machine(), alpha = addressBoard(box, 'alpha');
+ box.run(alpha.repo, 'shout', 'person', 'Address target shout.');
+ await withBrowser(box, async (chrome, server) => {
+ const shout = (await boardOf(server, alpha.repo)).shouts.find(one => one.shout_text === 'Address target shout.');
+ assert.ok(shout?.shout_id);
+ const direct = [
+ ['/items/1', 'items', '#detail', '#1', 'alpha first address item'],
+ ['/items/pipeline', 'items'], ['/shouts', 'shouts'], [`/shouts/${shout.shout_id}`, 'shouts'],
+ ['/spec', 'spec'], ['/spec/G2', 'spec', '#spec-detail', 'G2', 'alpha distinct specification row'],
+ ['/doctrine', 'doctrine'], ['/doctrine/PB1', 'doctrine', '#doctrine-detail', 'PB1', 'alpha distinct practice rule'],
+ ['/activity', 'activity'], ['/roadmap', 'roadmap'],
+ ];
+ for (const [address, pane, selector, id, text] of direct) {
+ await openAddress(chrome, server, address);
+ await assertPlace(chrome, address, pane, alpha.repo);
+ if (selector) await assertHeading(chrome, selector, id, text);
+ if (address === '/items/pipeline') assert.equal(await chrome.stable("document.querySelector('#pipeline').hidden"), false);
+ if (address.startsWith('/shouts/')) await assertShout(chrome, shout.shout_id, 'Address target shout.');
+ assert.equal((await history(chrome)).length > 0, true);
+ }
+ for (const [address, pane, selector, id] of [
+ ['/items/9999', 'items', '#detail', '9999'], ['/spec/NO_SUCH_ROW', 'spec', '#spec-detail', 'NO_SUCH_ROW'],
+ ['/doctrine/NO_SUCH_ROW', 'doctrine', '#doctrine-detail', 'NO_SUCH_ROW'], ['/shouts/999999', 'shouts', '#feed', '999999'],
+ ]) {
+ await openAddress(chrome, server, address);
+ await assertPlace(chrome, address, pane, alpha.repo);
+ if (pane === 'shouts') await settled(chrome, "!document.querySelector('#shout-address-status')?.textContent.startsWith('Loading')");
+ const text = await chrome.stable(`document.querySelector(${JSON.stringify(selector)}).innerText`);
+ assert.match(text, /No (?:item|shout|Spec row|Doctrine row).*exists here/i, 'missing targets say so');
+ assert.ok(text.includes(id), 'missing-target message identifies the target');
+ assert.equal(await chrome.stable(`!!document.querySelector(${JSON.stringify(selector + ' h2')})`), false, 'no unrelated default detail');
+ }
+ await openAddress(chrome, server, '/#items/pipeline');
+ await assertPlace(chrome, '/items/pipeline', 'items', alpha.repo);
+ assert.equal(await chrome.stable("document.querySelector('#pipeline').hidden"), false, 'the legacy Pipeline fragment still opens Pipeline');
+ await openAddress(chrome, server, '/#roadmap');
+ await assertPlace(chrome, '/roadmap', 'roadmap', alpha.repo);
+ assert.equal((await fetch(new URL('/items/1', server.link))).status, 403, 'direct places retain the secret boundary');
+ });
+});
+
+test('back, forward and reload keep the place [N38,N26]', { timeout: 180_000 }, async () => { // budget: hang-only ceiling for real clicks, stack traversal and fresh-document reloads.
+ const box = machine(), alpha = addressBoard(box, 'history-alpha');
+ box.run(alpha.repo, 'shout', 'person', 'History journey shout.');
+ await withBrowser(box, async (chrome, server) => {
+ const shout = (await boardOf(server, alpha.repo)).shouts.find(one => one.shout_text === 'History journey shout.');
+ await openAddress(chrome, server, '/items');
+ const journey = [{ address: '/items', pane: 'items', root: alpha.repo }];
+ const steps = [
+ ['#chain .row[data-item="1"]', '/items/1', 'items'], ['[data-items-view="pipeline"]', '/items/pipeline', 'items'],
+ ['[data-tab="shouts"]', '/shouts', 'shouts'], [`#feed #shout-${shout.shout_id} .text`, `/shouts/${shout.shout_id}`, 'shouts'],
+ ['[data-tab="spec"]', '/spec', 'spec'], ['[data-row="spec:G2"]', '/spec/G2', 'spec'],
+ ['[data-tab="doctrine"]', '/doctrine', 'doctrine'], ['[data-row="doctrine:PB1"]', '/doctrine/PB1', 'doctrine'],
+ ['[data-tab="activity"]', '/activity', 'activity'], ['[data-tab="roadmap"]', '/roadmap', 'roadmap'],
+ ['[data-tab="items"]', '/items/pipeline', 'items'], ['[data-items-view="list"]', '/items', 'items'],
+ ['#chain .row[data-item="2"]', '/items/2', 'items'],
+ ];
+ for (const [selector, address, pane] of steps) journey.push(await onePlace(chrome, `document.querySelector(${JSON.stringify(selector)})`, address, pane, alpha.repo));
+ const unchanged = await history(chrome);
+ await press(chrome, 'document.querySelector(\'#chain .row[data-item="2"]\')');
+ await settled(chrome, SCRIPT);
+ assert.deepEqual(await history(chrome), unchanged, 'selecting the same item never pushes a duplicate');
+ await onePlace(chrome, 'document.querySelector(\'[data-tab="shouts"]\')', '/shouts', 'shouts', alpha.repo);
+ const sameTab = await history(chrome);
+ for (let repeat = 0; repeat < 2; repeat += 1) {
+ await press(chrome, 'document.querySelector(\'[data-tab="shouts"]\')');
+ await settled(chrome, SCRIPT);
+ assert.deepEqual(await history(chrome), sameTab, 'selecting the current tab never pushes a duplicate');
+ }
+ await travel(chrome, -1);
+ await settled(chrome, SCRIPT);
+ for (const direction of [-1, 1]) {
+ const indices = direction < 0 ? Array.from({ length: journey.length - 1 }, (_, index) => journey.length - 2 - index) : Array.from({ length: journey.length - 1 }, (_, index) => index + 1);
+ for (const index of indices) {
+ await travel(chrome, direction);
+ await settled(chrome, SCRIPT);
+ const step = journey[index];
+ await assertPlace(chrome, step.address, step.pane, step.root);
+ if (step.address === '/spec/G2') await assertHeading(chrome, '#spec-detail', 'G2', 'history-alpha distinct specification row');
+ if (step.address === '/doctrine/PB1') await assertHeading(chrome, '#doctrine-detail', 'PB1', 'history-alpha distinct practice rule');
+ if (/\/items\/\d+$/.test(step.address)) await assertHeading(chrome, '#detail', `#${step.address.split('/').at(-1)}`, 'address item');
+ if (step.address.startsWith('/shouts/')) await assertShout(chrome, shout.shout_id, 'History journey shout.');
+ }
+ }
+ for (const step of journey.slice(0, -2)) {
+ await openAddress(chrome, server, step.address);
+ const before = await chrome.stable('performance.timeOrigin');
+ await chrome.send('Page.reload');
+ await settled(chrome, `performance.timeOrigin !== ${before} && ${SCRIPT}`);
+ await assertPlace(chrome, step.address, step.pane, alpha.repo);
+ if (step.address === '/spec/G2') await assertHeading(chrome, '#spec-detail', 'G2', 'history-alpha distinct specification row');
+ if (step.address === '/doctrine/PB1') await assertHeading(chrome, '#doctrine-detail', 'PB1', 'history-alpha distinct practice rule');
+ if (step.address === '/items/1') await assertHeading(chrome, '#detail', '#1', 'history-alpha first address item');
+ if (step.address.startsWith('/shouts/')) await assertShout(chrome, shout.shout_id, 'History journey shout.');
+ }
+ });
+});
+
+test('a shout address opens an old shout [N38,N26]', { timeout: 180_000 }, async () => { // budget: hang-only ceiling for real writes and both viewport journeys.
+ const box = machine(), alpha = addressBoard(box, 'old-shout-alpha');
+ box.run(alpha.repo, 'shout', 'person', 'OLD ADDRESSED SHOUT, unique body.');
+ await withBrowser(box, async (chrome, server) => {
+ const target = (await boardOf(server, alpha.repo)).shouts.find(one => one.shout_text === 'OLD ADDRESSED SHOUT, unique body.');
+ assert.ok(target?.shout_id);
+ for (let index = 0; index < 46; index += 1) box.run(alpha.repo, 'shout', 'person', `Later shout ${index + 1}.`);
+ const state = await boardOf(server, alpha.repo);
+ assert.equal(state.shouts.length, 40);
+ assert.equal(state.shouts.some(one => one.shout_id === target.shout_id), false, 'the target is outside the actual public state window');
+ for (const width of [1280, 375]) {
+ await chrome.send('Emulation.setDeviceMetricsOverride', { width, height: 900, deviceScaleFactor: 1, mobile: false });
+ await openAddress(chrome, server, `/shouts/${target.shout_id}`);
+ await assertPlace(chrome, `/shouts/${target.shout_id}`, 'shouts', alpha.repo);
+ await assertShout(chrome, target.shout_id, 'OLD ADDRESSED SHOUT, unique body.');
+ }
+ });
+});
+
+test('grouped repos each get their own address [N38,N26]', { timeout: 180_000 }, async () => { // budget: hang-only ceiling for grouped repo switching and a separate one-repo machine.
+ const box = machine(), alpha = addressBoard(box, 'alpha', 'same-suite'), beta = addressBoard(box, 'beta', 'same-suite');
+ await withBrowser(box, async (chrome, server) => {
+ for (const [repo, name] of [[alpha, 'alpha'], [beta, 'beta']]) {
+ for (const [suffix, pane, selector, id, text] of [
+ ['/items/1', 'items', '#detail', '#1', `${name} first address item`],
+ ['/spec/G2', 'spec', '#spec-detail', 'G2', `${name} distinct specification row`],
+ ['/doctrine/PB1', 'doctrine', '#doctrine-detail', 'PB1', `${name} distinct practice rule`],
+ ]) {
+ await openAddress(chrome, server, `/${name}${suffix}`);
+ await assertPlace(chrome, `/${name}${suffix}`, pane, repo.repo);
+ await assertHeading(chrome, selector, id, text);
+ }
+ await onePlace(chrome, 'document.querySelector(\'[data-tab="shouts"]\')', `/${name}/shouts`, 'shouts', repo.repo);
+ }
+ await openAddress(chrome, server, '/alpha/items/1');
+ if (await chrome.stable("getComputedStyle(document.querySelector('#side .side-body')).display === 'none'")) await press(chrome, "document.querySelector('#proj-switch')");
+ await onePlace(chrome, 'document.querySelector(\'[data-root="' + beta.repo + '"]\')', '/beta/items', 'items', beta.repo);
+ await travel(chrome, -1);
+ await settled(chrome, `${SCRIPT} && view.root === ${JSON.stringify(alpha.repo)}`);
+ await assertPlace(chrome, '/alpha/items/1', 'items', alpha.repo);
+ await assertHeading(chrome, '#detail', '#1', 'alpha first address item');
+ });
+ const singleBox = machine(), single = addressBoard(singleBox, 'single');
+ await withBrowser(singleBox, async (chrome, server) => {
+ await openAddress(chrome, server, '/items/1');
+ await assertPlace(chrome, '/items/1', 'items', single.repo);
+ await assertHeading(chrome, '#detail', '#1', 'single first address item');
+ await onePlace(chrome, 'document.querySelector(\'[data-tab="spec"]\')', '/spec', 'spec', single.repo);
+ await onePlace(chrome, 'document.querySelector(\'[data-row="spec:G2"]\')', '/spec/G2', 'spec', single.repo);
+ await assertHeading(chrome, '#spec-detail', 'G2', 'single distinct specification row');
+ });
+});
+
+
+test('an older relay shout keeps its address and explains retained history [N38,H5]', {
+ // budget: three fixture work ceilings bound setup, browser pairing and the addressed read; no speed assertion.
+ timeout: relayWorkBudgetMs() * 3,
+}, async t => {
+ const box = await relayClientFixture(t);
+ const text = 'OLD RELAY ADDRESS TARGET 187';
+ for (let index = 0; index < 46; index += 1) {
+ const reply = await box.cli('shout', 'person', index === 0 ? text : `Later relay address shout ${index}`);
+ assert.equal(reply.code, 0, 'real CLI appends each fixture shout');
+ }
+ const exported = await box.cli('export');
+ assert.equal(exported.code, 0);
+ const target = exported.document.tables.shout.find(one => one.shout_text === text);
+ assert.ok(target?.shout_id);
+ await box.link();
+ const link = JSON.parse(readFileSync(box.linkFile, 'utf8'));
+ const encoded = readFileSync(box.keyFile, 'utf8').trim();
+ const chrome = await stableChrome(await startChrome());
+ t.after(() => chrome.close());
+ assert.equal((await chrome.send('Network.setCookie', {
+ name: 'pb_session', value: (await box.phoneSession()).token, url: box.origin, httpOnly: true, sameSite: 'Lax',
+ })).success, true, 'the actual paired person session authenticates this browser');
+ await chrome.send('Page.navigate', { url: box.origin + '/#board=' + link.board + '&key=' + encoded });
+ await settled(chrome, SCRIPT);
+ assert.equal(await chrome.stable('location.hash.includes("key=")'), false, 'pairing removes its secret before ordinary address navigation');
+ assert.equal(await chrome.stable(`data.project.shouts.some(one => one.shout_id === ${target.shout_id})`), false, 'the old shout is absent from the actual relay state projection');
+ const address = '/#shouts/' + target.shout_id;
+ await chrome.send('Page.navigate', { url: box.origin + address });
+ await settled(chrome, SCRIPT);
+ for (let visit = 0; visit < 2; visit += 1) {
+ await settled(chrome, `${SCRIPT} && !document.querySelector('#shout-address-status')?.textContent.startsWith('Loading')`);
+ await assertPlace(chrome, address, 'shouts', link.board);
+ const body = await chrome.stable(`document.querySelector('#feed #shout-${target.shout_id} .text')?.textContent ?? null`);
+ if (body === text) await assertShout(chrome, target.shout_id, text);
+ else assert.match(await chrome.stable("document.querySelector('#shout-address-status')?.textContent ?? ''"), /older than the relay holds/i,
+ 'an unsupported old read explains the relay retention limit in the Shouts pane');
+ if (visit === 0) {
+ const before = await chrome.stable('performance.timeOrigin');
+ await chrome.send('Page.reload');
+ await settled(chrome, `performance.timeOrigin !== ${before} && ${SCRIPT}`);
+ }
+ }
+});
diff --git a/test/cockpit/items.test.js b/test/cockpit/items.test.js
index 6181fbdb..decaded9 100644
--- a/test/cockpit/items.test.js
+++ b/test/cockpit/items.test.js
@@ -895,8 +895,8 @@ test('Pipeline view shows every stage, status counts, stage ages, detail links a
const listRead = "JSON.stringify([...document.querySelectorAll('#chain > li[data-item]')].map(row => ({id:Number(row.dataset.item),title:row.title,meta:row.querySelector('.meta').textContent,tag:row.lastElementChild.textContent})))";
const listBefore = await chrome.stable(listRead);
await press(chrome, "document.querySelector('[data-items-view=\"pipeline\"]')");
- assert.equal(await chrome.stable('location.hash'), '#items/pipeline', 'Pipeline has its own shareable address');
- await chrome.waitFor("location.hash === '#items/pipeline' && !document.querySelector('#pipeline').hidden");
+ assert.equal(await chrome.stable('location.pathname'), '/items/pipeline', 'Pipeline has its own shareable address');
+ await chrome.waitFor("typeof data !== 'undefined' && location.pathname === '/items/pipeline' && !document.querySelector('#pipeline').hidden");
const expectedCounts = [status.open, status.claimed, status.submitted, 1, 1];
const read = JSON.parse(await chrome.stable(`JSON.stringify([...document.querySelectorAll('[data-pipeline-stage]')].map(stage => ({ stage:stage.dataset.pipelineStage, label:stage.querySelector('h2').textContent, count:Number(stage.querySelector('[data-stage-count]').textContent), oldest:Number(stage.querySelector('.pipeline-oldest [data-item]')?.dataset.item || 0), since:stage.querySelector('.pipeline-oldest time')?.dataset.ago || null, age:stage.querySelector('.pipeline-oldest time')?.textContent || '', ids:[...stage.querySelectorAll('.pipeline-item')].map(item => Number(item.dataset.item)) })))`));
assert.deepEqual(read.map(stage => stage.label), ['Not started', 'Building', 'Waiting for review', 'Accepted, waiting to merge', 'Merged']);
@@ -946,9 +946,9 @@ test('Pipeline view shows every stage, status counts, stage ages, detail links a
assert.equal(await chrome.stable(listRead), listBefore, 'returning to List preserves its Active rows, metadata and ordering');
assert.deepEqual(JSON.parse(listBefore).map(row => row.id).sort((a,b)=>a-b), [3,4,5,6]);
await travel(chrome, -1);
- await settled(chrome, "location.hash === '#items/pipeline' && !document.querySelector('#pipeline').hidden");
+ await settled(chrome, "typeof data !== 'undefined' && location.pathname === '/items/6' && !document.querySelector('#pipeline').hidden");
await chrome.send('Page.reload', {});
- await settled(chrome, "location.hash === '#items/pipeline' && data?.project && !document.querySelector('#pipeline').hidden");
+ await settled(chrome, "typeof data !== 'undefined' && location.pathname === '/items/6' && data?.project && !document.querySelector('#pipeline').hidden");
assert.equal(await chrome.stable("document.querySelector('.tab.on').dataset.tab"), 'items', 'the Pipeline address reloads within Items');
await travel(chrome, 1);
await settled(chrome, "!location.hash && !document.querySelector('#item-list').hidden");
diff --git a/test/cockpit/roadmap.test.js b/test/cockpit/roadmap.test.js
index 7094d68c..f79f7747 100644
--- a/test/cockpit/roadmap.test.js
+++ b/test/cockpit/roadmap.test.js
@@ -125,7 +125,8 @@ test('the roadmap reads every item as the Items tab does, opens each one, anothe
{ id: '#7', label: 'withdrawn', tone: '' },
];
const view = await startView(box);
- const roadmap = `/roadmap${view.link.search}`;
+ const roadmapPath = '/roadmap-demo/roadmap';
+ const roadmap = `${roadmapPath}${view.link.search}`;
const profile = mkdtempSync(join(tmpdir(), 'pullboard-roadmap-chrome-'));
let chrome;
try {
@@ -140,14 +141,14 @@ test('the roadmap reads every item as the Items tab does, opens each one, anothe
if (message.method === 'Log.entryAdded' && message.params.entry.level === 'error') consoleErrors.push(message.params.entry.text);
});
await chrome.send('Log.enable');
- await settled(chrome, `!!data?.project && ${showing('roadmap', '/roadmap')} && document.querySelectorAll('#roadmap .milestone').length === 3`);
+ await settled(chrome, `!!data?.project && ${showing('roadmap', roadmapPath)} && document.querySelectorAll('#roadmap .milestone').length === 3`);
// This story reads every release; open the later cards through their actual controls.
await openRoadmapParts(chrome);
let seen;
for (const width of [375, 1280]) {
await chrome.send('Emulation.setDeviceMetricsOverride', { width, height: 900, deviceScaleFactor: 1, mobile: false });
- await chrome.waitFor(`innerWidth === ${width} && ${showing('roadmap', '/roadmap')}`);
+ await chrome.waitFor(`innerWidth === ${width} && ${showing('roadmap', roadmapPath)}`);
seen = await readRoadmap(chrome);
assert.deepEqual([seen.address, seen.shown, seen.tab], [roadmap, ['roadmap'], 'roadmap'], `${width}: the direct address shows the Roadmap tab, and only it`);
assert.ok(seen.document <= seen.client && seen.body <= seen.client, `${width}: no sideways scroll: ${JSON.stringify(seen)}`);
@@ -176,43 +177,43 @@ test('the roadmap reads every item as the Items tab does, opens each one, anothe
// An item opens on the Items tab; Back shows the Roadmap at its address again, Forward the item.
await press(chrome, roadmapRow('#3'));
- await pressedInto(chrome, `${showing('items', '/')} && document.querySelector('#detail h2')?.innerText.includes('Session timeout banner')`);
+ await pressedInto(chrome, `${showing('items', '/roadmap-demo/items/3')} && document.querySelector('#detail h2')?.innerText.includes('Session timeout banner')`);
assert.equal(await chrome.stable('location.search'), view.link.search, `${width}: the address keeps the rest of itself`);
await travel(chrome, -1);
- await settled(chrome, `${showing('roadmap', '/roadmap')} && document.querySelector('.tab.on')?.dataset.tab === 'roadmap'`);
+ await settled(chrome, `${showing('roadmap', roadmapPath)} && document.querySelector('.tab.on')?.dataset.tab === 'roadmap'`);
await travel(chrome, 1);
- await settled(chrome, `${showing('items', '/')} && document.querySelector('.tab.on')?.dataset.tab === 'items' && document.querySelector('#detail h2')?.innerText.includes('Session timeout banner')`);
+ await settled(chrome, `${showing('items', '/roadmap-demo/items/3')} && document.querySelector('.tab.on')?.dataset.tab === 'items' && document.querySelector('#detail h2')?.innerText.includes('Session timeout banner')`);
await press(chrome, `document.querySelector('[data-tab="roadmap"]')`);
- await pressedInto(chrome, `${showing('roadmap', '/roadmap')} && location.search === ${JSON.stringify(view.link.search)}`);
+ await pressedInto(chrome, `${showing('roadmap', roadmapPath)} && location.search === ${JSON.stringify(view.link.search)}`);
}
// Another repo's item opens on its own board, and Back and Forward move between the two boards.
await press(chrome, roadmapRow('beacon#1'));
- await chrome.waitFor(`document.querySelector('#proj-name').textContent === 'beacon' && ${showing('items', '/')} && document.querySelector('#detail h2')?.innerText.includes('Billing webhook retries')`);
+ await chrome.waitFor(`document.querySelector('#proj-name').textContent === 'beacon' && ${showing('items', '/beacon/items/1')} && document.querySelector('#detail h2')?.innerText.includes('Billing webhook retries')`);
const there = JSON.parse(await chrome.stable(`JSON.stringify((() => { const chip = document.querySelector('#detail .meta .chip'); return {
id: document.querySelector('#detail h2 span').innerText, label: chip.innerText, chip: getComputedStyle(chip).color + ' on ' + getComputedStyle(chip).backgroundColor,
dot: getComputedStyle(document.querySelector('#chain [data-item="1"] .dot')).backgroundColor }; })())`));
const crossed = seen.cards[0].rows.find((row) => row.id === 'beacon#1');
assert.deepEqual(there, { id: '#1', label: crossed.label, chip: crossed.chip, dot: crossed.dot }, "the other repo's Items tab shows that item with the Roadmap's word and colours");
await travel(chrome, -1);
- await settled(chrome, `document.querySelector('#proj-name').textContent === 'roadmap-demo' && ${showing('roadmap', '/roadmap')} && !!${roadmapRow('beacon#1')}`);
+ await settled(chrome, `document.querySelector('#proj-name').textContent === 'roadmap-demo' && ${showing('roadmap', roadmapPath)} && !!${roadmapRow('beacon#1')}`);
await travel(chrome, 1);
- await settled(chrome, `document.querySelector('#proj-name').textContent === 'beacon' && ${showing('items', '/')} && document.querySelector('#detail h2')?.innerText.includes('Billing webhook retries')`);
+ await settled(chrome, `document.querySelector('#proj-name').textContent === 'beacon' && ${showing('items', '/beacon/items/1')} && document.querySelector('#detail h2')?.innerText.includes('Billing webhook retries')`);
await travel(chrome, -1);
- await settled(chrome, `document.querySelector('#proj-name').textContent === 'roadmap-demo' && ${showing('roadmap', '/roadmap')} && !!${roadmapRow('#1')}`);
+ await settled(chrome, `document.querySelector('#proj-name').textContent === 'roadmap-demo' && ${showing('roadmap', roadmapPath)} && !!${roadmapRow('#1')}`);
// Each of this board's rows opens its item on the Items tab, which gives it the same word and
// colours, its list dot included; a withdrawn item is left out of the list while browsing.
for (const row of seen.cards.flatMap((card) => card.rows).filter((each) => each.id.startsWith('#'))) {
await press(chrome, roadmapRow(row.id));
- await chrome.waitFor(`${showing('items', '/')} && document.querySelector('#detail h2 span')?.innerText === ${JSON.stringify(row.id)}`);
+ await chrome.waitFor(`${showing('items', '/roadmap-demo/items/' + row.id.slice(1))} && document.querySelector('#detail h2 span')?.innerText === ${JSON.stringify(row.id)}`);
const here = JSON.parse(await chrome.stable(`JSON.stringify((() => {
const chip = document.querySelector('#detail .meta .chip'), dot = document.querySelector('#chain [data-item="${row.id.slice(1)}"] .dot');
return { label: chip.innerText, chip: getComputedStyle(chip).color + ' on ' + getComputedStyle(chip).backgroundColor, dot: dot ? getComputedStyle(dot).backgroundColor : 'not listed' };
})())`));
assert.deepEqual(here, { label: row.label, chip: row.chip, dot: row.label === 'withdrawn' ? 'not listed' : row.dot }, `${row.id}: the Items tab shows it with the Roadmap's word and colours`);
await travel(chrome, -1);
- await settled(chrome, `${showing('roadmap', '/roadmap')} && !!${roadmapRow(row.id)}`);
+ await settled(chrome, `${showing('roadmap', roadmapPath)} && !!${roadmapRow(row.id)}`);
}
// It updates live as items move, here and on the other repo's board.
@@ -223,20 +224,20 @@ test('the roadmap reads every item as the Items tab does, opens each one, anothe
// A board with no milestones says how one starts; the address stays the Roadmap's.
await press(chrome, `document.querySelector('[data-root=${JSON.stringify(beacon.repo)}]')`);
- await chrome.waitFor(`document.querySelector('#proj-name').textContent === 'beacon' && ${showing('roadmap', '/roadmap')} && document.querySelector('#roadmap').innerText.startsWith('No milestones yet.')`);
+ await chrome.waitFor(`document.querySelector('#proj-name').textContent === 'beacon' && ${showing('roadmap', '/beacon/roadmap')} && document.querySelector('#roadmap').innerText.startsWith('No milestones yet.')`);
await press(chrome, `document.querySelector('[data-root=${JSON.stringify(alpha.repo)}]')`);
await chrome.waitFor(`document.querySelector('#proj-name').textContent === 'roadmap-demo' && !!${roadmapRow('#1')}`);
// A reload keeps the Roadmap. The board's own address shows the tab last picked there, never the
// Roadmap, even when the Roadmap was picked last.
await chrome.send('Page.reload');
- await settled(chrome, `!!data?.project && ${showing('roadmap', '/roadmap')} && !!${roadmapRow('#1')}`);
+ await settled(chrome, `!!data?.project && ${showing('roadmap', roadmapPath)} && !!${roadmapRow('#1')}`);
await press(chrome, `document.querySelector('[data-tab="shouts"]')`);
- await chrome.waitFor(showing('shouts', '/'));
+ await chrome.waitFor(showing('shouts', '/roadmap-demo/shouts'));
await press(chrome, `document.querySelector('[data-tab="roadmap"]')`);
- await chrome.waitFor(showing('roadmap', '/roadmap'));
+ await chrome.waitFor(showing('roadmap', roadmapPath));
await chrome.send('Page.navigate', { url: view.link.href });
- await settled(chrome, `!!data?.project && ${showing('shouts', '/')} && document.querySelector('.tab.on')?.dataset.tab === 'shouts'`);
+ await settled(chrome, `!!data?.project && ${showing('shouts', '/roadmap-demo/shouts')} && document.querySelector('.tab.on')?.dataset.tab === 'shouts'`);
assert.deepEqual(chrome.exceptions, [], 'Chrome reports no uncaught page exceptions');
assert.deepEqual(consoleErrors, [], 'Chrome reports no console errors');
} finally {