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): day names stay true past midnight without a redraw [N26,N40]
Corey Olson10f4d788969e
diff --cc src/cockpit.jsindex d23247c3,3dad0dfc..dba4a6ee--- a/src/cockpit.js+++ b/src/cockpit.js@@@ -488,13 -292,13 +488,15 @@@ const dayName = (iso) =>today.setDate(today.getDate() - 1);return then === today.toDateString() ? 'Yesterday' : new Date(iso).toLocaleDateString([], { weekday: 'short', month: 'short', day: 'numeric' });};++// When the page last named days, so tickDays can rename them in place once the clock passes midnight (#644).++let daysNamedAt = new Date();// A feed's rows, newest first, with the day named above each run of rows from the same day.--const byDay = (rows, at, row) => rows.map((x, i) => (i && new Date(at(x)).toDateString() === new Date(at(rows[i - 1])).toDateString() ? '' : '<h4 class="day">' + dayName(at(x)) + '</h4>') + row(x)).join('');++const byDay = (rows, at, row) => { daysNamedAt = new Date(); return rows.map((x, i) => (i && new Date(at(x)).toDateString() === new Date(at(rows[i - 1])).toDateString() ? '' : '<h4 class="day">' + dayName(at(x)) + '</h4>') + row(x)).join(''); };// Where the shouts cross into an earlier day, a rule names it in the middle; today needs no label at the top.--const dayRules = (rows, at, row) => rows.map((x, i) => {++const dayRules = (rows, at, row) => { daysNamedAt = new Date(); return rows.map((x, i) => {const day = new Date(at(x)).toDateString(), before = i ? new Date(at(rows[i - 1])).toDateString() : new Date().toDateString();return (day === before ? '' : '<div class="day-rule" role="separator"><span>' + dayName(at(x)) + '</span></div>') + row(x);--}).join('');++}).join(''); };const firstLine = (text) => String(text ?? '').split('\\n').map((line) => line.trim()).find(Boolean) || '';/** Omit a duplicated leading verdict code from rendered copy while preserving the recorded note. */function visibleVerdictNote(reason, note) {@@@ -1479,11 -1106,11 +1506,16 @@@ async function refresh(fresh = null)if (text !== seen) {seen = text;data = next;+ syncBoardMode(view.root);+ itemSearches.clear();+ const reading = detailRead;render();+ if (detailRead !== reading) await detailRead;+ } 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();++ tickAges();}if (changed) {address(false);@@@ -3253,6 -2855,6 +3285,24 @@@ function foldShouts()function tickAges() {document.querySelectorAll('[data-ago]').forEach((node) => { node.textContent = node.classList.contains('long') ? agoLong(node.dataset.ago) : ago(node.dataset.ago); });++ tickDays();++}++++/**++ * Once the clock has passed midnight since the page named its days, rename them in place with no redraw (#644): the++ * day that was Today and the one that was Yesterday get their names for now, and the shouts, which carry no rule above++ * today's, get one above what is no longer today. Every other day was named by its date and stays true.++ */++function tickDays() {++ const then = daysNamedAt, now = new Date();++ if (then.toDateString() === now.toDateString()) return;++ const before = new Date(then);++ before.setDate(then.getDate() - 1);++ const names = { Today: dayName(then.toISOString()), Yesterday: dayName(before.toISOString()) };++ document.querySelectorAll('.feed .day, #feed > .day-rule span').forEach((node) => { if (names[node.textContent]) node.textContent = names[node.textContent]; });++ const first = $('feed')?.querySelector?.('.shout');++ if (first && !first.previousElementSibling?.classList?.contains('day-rule')) first.insertAdjacentHTML('beforebegin', '<div class="day-rule" role="separator"><span>' + names.Today + '</span></div>');++ daysNamedAt = now;}/** Open or close the project list where the sidebar is folded into a top bar (under 900px). */diff --cc test/cockpit/stats.test.jsindex 4d56d03c,6d3f3001..539e6cea--- a/test/cockpit/stats.test.js+++ b/test/cockpit/stats.test.js@@@ -516,3 -516,64 +516,92 @@@ test('the stats card shows API flow anrmSync(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`);+ }++ // Past midnight, an unchanged read still draws nothing, and the day the page named Today is renamed Yesterday in++ // place, the shouts gaining the rule above it they leave off for today: the page's clock moves a day on, alone.++ const days = `JSON.stringify({ headings: [...document.querySelectorAll('.feed .day')].map((node) => node.textContent),++ rules: [...document.querySelectorAll('#feed > .day-rule span')].map((node) => node.textContent),++ untopped: (() => { const first = document.querySelector('#feed .shout'); return Boolean(first) && !first.previousElementSibling?.classList.contains('day-rule'); })() })`;++ const today = JSON.parse(await chrome.stable(days));++ assert.ok(today.headings.includes('Today'), `the page names today's run of rows Today: ${JSON.stringify(today)}`);++ await chrome.stable(`(() => {++ const Real = Date;++ window.Date = class extends Real {++ constructor(...args) { super(...(args.length ? args : [Real.now() + 86_400_000])); }++ static now() { return Real.now() + 86_400_000; }++ };++ return true;++ })()`);++ const midnight = await reread();++ const renamed = JSON.parse(await chrome.stable(days));++ t.diagnostic(`read past midnight: ${JSON.stringify({ midnight, today, renamed })}`);++ assert.equal(midnight.redraws, 0, `a read past midnight of an unchanged board does not redraw the page: ${JSON.stringify(midnight)}`);++ assert.equal(midnight.kept, true, 'a read past midnight keeps every element where it was');++ assert.deepEqual(midnight.scroll, midnight.start, 'a read past midnight keeps the scroll position');++ assert.deepEqual(renamed.headings.map((name, index) => today.headings[index] === 'Today' ? name === 'Yesterday' : name !== 'Today'),++ today.headings.map(() => true), `the day the page called Today is called Yesterday now, in place: ${JSON.stringify({ today, renamed })}`);++ assert.ok(!renamed.rules.includes('Today'), 'no shout rule calls a day Today');++ assert.deepEqual(renamed.rules, today.untopped ? ['Yesterday', ...today.rules.map((name) => name === 'Yesterday' ? renamed.rules[1] : name)] : renamed.rules,++ 'the shouts gain one rule, Yesterday, above what is no longer today');++ assert.equal(renamed.untopped, false, 'no shout run is left without its day');++ await chrome.stable('(() => { window.Date = Object.getPrototypeOf(window.Date); return true; })()');+ // 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 });+ }+ });