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.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
fix(view): an unchanged board does not redraw on refresh [N26,N40]
Corey Olson6a4f32b84700
diff --git a/src/cockpit.js b/src/cockpit.jsindex e589d13e..2c6f1089 100644--- a/src/cockpit.js+++ b/src/cockpit.js@@ -865,6 +865,11 @@ function flowMinutes(value) {return Math.floor(hours / 24) + ' d ' + hours % 24 + ' h';}+/** A queue's oldest item and how long it has waited, as the flow card reads it. */+function oldestLine(oldest) {+ return 'Oldest: ' + (oldest ? '#' + oldest.id + ' · ' + flowMinutes(oldest.ageMinutes) : 'none');+}+/** Render the four stages, live queues and single recommendation supplied by stats [N26]. */function proofFlowCard(flow) {if (!flow) return '';@@ -878,7 +883,7 @@ function proofFlowCard(flow) {const queue = flow.queues[key];const oldest = queue.oldest;return '<div><span>' + label + ' queue</span><b data-queue="' + key + '" data-value="' + esc(queue.size) + '">' + esc(queue.size) + '</b>'- + '<small data-oldest="' + key + '" data-value="' + esc(oldest?.ageMinutes ?? '') + '">Oldest: ' + (oldest ? '#' + esc(oldest.id) + ' · ' + esc(flowMinutes(oldest.ageMinutes)) : 'none') + '</small></div>';+ + '<small data-oldest="' + key + '" data-value="' + esc(oldest?.ageMinutes ?? '') + '">' + esc(oldestLine(oldest)) + '</small></div>';}).join('');const bottleneck = flow.bottleneck;return '<div class="proof-stats-flow"><div class="proof-stats-grid">' + averages + waiting + '</div>'@@ -1039,6 +1044,26 @@ async function revokeCredential(id) {if (root === view.root) renderCredentials();}+/**+ * A board read as text with its clock readings blanked: the flow's observation time (asOf) and each queue's oldest age+ * (ageMinutes) are stamped afresh on every read, so two reads that differ only there show the same board (#644).+ * Matching whole JSON keys is safe: a quote inside any string value is escaped, so no title can look like one.+ */+function boardText(state) {+ return JSON.stringify(state).replace(/"(asOf|ageMinutes)":(?:"[^"]*"|[-+.0-9eE]+|null)/g, '"$1":null');+}++/** Show each queue's oldest age from the board on hand in place: the one thing on the page that moves with the clock alone. */+function showFlowAges() {+ const flow = data?.project?.proofStats?.flow;+ if (!flow) return;+ for (const node of document.querySelectorAll('#proof-stats [data-oldest]')) {+ const oldest = flow.queues[node.dataset.oldest]?.oldest;+ node.dataset.value = oldest?.ageMinutes ?? '';+ node.textContent = oldestLine(oldest);+ }+}+/** Refresh from API v1, every board or only those in fresh, and discard a response for a project the person left. */async function refresh(fresh = null) {const generation = ++refreshStarted;@@ -1076,12 +1101,16 @@ async function refresh(fresh = null) {if (place) applyPlace(place, globalThis.history?.state);addressReady = true;}- const text = JSON.stringify(next);+ const text = boardText(next);const changed = text !== seen;- if (text !== seen) {+ if (changed) {seen = text;data = next;render();+ } else if (data !== next) {+ // The same board read again: keep its newest clock readings and show them in place, with no redraw (#644).+ data = next;+ showFlowAges();}if (changed) {address(false);diff --git a/test/cockpit/stats.test.js b/test/cockpit/stats.test.jsindex 4d56d03c..6d3f3001 100644--- a/test/cockpit/stats.test.js+++ b/test/cockpit/stats.test.js@@ -516,3 +516,64 @@ test('the stats card shows API flow and bottleneck at 375 and 1280 [N26]', { timrmSync(profile, { recursive: true, force: true });}});++test('an unchanged board does not redraw on refresh [N26,N40]', {+ timeout: 90_000, // budget: hang ceiling for real board setup, Chrome and five real board reads.+}, async (t) => {+ // #644: every board read stamps the flow's observation clock (asOf) and each queue's oldest age afresh, so before+ // this a refresh of an unchanged board redrew the whole page and replaced every control under the pointer.+ const executable = chromeExecutable();+ assert.ok(executable, 'Chrome is required for the refresh redraw criterion.');+ const box = machine();+ const alpha = project(box, 'flow-refresh');+ stageFlowBoard(box, alpha);+ const view = await startView(box);+ const profile = mkdtempSync(join(tmpdir(), 'pullboard-flow-refresh-chrome-'));+ let chrome;+ try {+ chrome = await openSnapshotChrome(executable, view.link.href, profile);+ await chrome.waitFor('data?.project?.root === ' + JSON.stringify(alpha.repo) + ' && !!document.querySelector("[data-oldest=open]")');+ await chrome.send('Emulation.setDeviceMetricsOverride', { width: 1280, height: 900, deviceScaleFactor: 1, mobile: false });+ await press(chrome, "document.querySelector('#proof-stats-summary')");+ await chrome.waitFor("!document.querySelector('#proof-stats-full').hidden");+ // Count every redraw from here on, and keep the nodes a person could be pointing at to see they survive.+ await chrome.stable(`(() => {+ const drawn = window.render;+ window.__redraws = 0;+ window.render = function (...args) { window.__redraws += 1; return drawn.apply(this, args); };+ window.__kept = [...document.querySelectorAll('#tabs .tab, #proof-stats-summary, #chain > li, [data-oldest]')];+ window.__scroll = [scrollX, scrollY];+ return true;+ })()`);+ /** Read the board as the page's live catch-up does, then report what the read changed on the page. */+ const reread = async () => JSON.parse(await chrome.stable(`(async () => {+ const before = data.project.proofStats.flow.asOf;+ await refresh();+ const oldest = document.querySelector('[data-oldest=open]');+ return JSON.stringify({ redraws: window.__redraws, newer: data.project.proofStats.flow.asOf > before,+ kept: window.__kept.every((node) => node.isConnected), scroll: [scrollX, scrollY], start: window.__scroll,+ shown: { value: oldest.dataset.value, text: oldest.textContent }, api: data.project.proofStats.flow.queues.open.oldest });+ })()`));+ for (let read = 1; read <= 3; read += 1) {+ await chrome.stable('new Promise((resolve) => setTimeout(() => resolve(true), 5))');+ const after = await reread();+ t.diagnostic(`unchanged read ${read}: ${JSON.stringify(after)}`);+ assert.equal(after.newer, true, `read ${read} is a fresh observation of the board: ${JSON.stringify(after)}`);+ assert.equal(after.redraws, 0, `read ${read} of an unchanged board does not redraw the page: ${JSON.stringify(after)}`);+ assert.equal(after.kept, true, `read ${read} keeps every element where it was: ${JSON.stringify(after)}`);+ assert.deepEqual(after.scroll, after.start, `read ${read} keeps the scroll position`);+ // What reads relative to now still follows the newest observation, without a redraw.+ assert.deepEqual(after.shown, { value: String(after.api.ageMinutes), text: 'Oldest: #' + after.api.id + ' · ' + displayDuration(after.api.ageMinutes) }, `read ${read}: the oldest age is the newest observation's`);+ }+ // A changed board still redraws, once: the page's own stream catch-up and a further read together draw it once.+ box.run(alpha.repo, 'shout', 'person', 'refresh redraw control');+ await chrome.waitFor("data.project.shouts.some((shout) => shout.shout_text === 'refresh redraw control')");+ const changed = await reread();+ t.diagnostic(`changed read: ${JSON.stringify(changed)}`);+ assert.equal(changed.redraws, 1, `a changed board redraws the page once: ${JSON.stringify(changed)}`);+ } finally {+ if (chrome) await closeSnapshotChrome(chrome);+ await view.stop();+ rmSync(profile, { recursive: true, force: true });+ }+});