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.

fix(view): defer Pipeline redraw during click [N26,N38,C7]

Corey Olson4d971df85dfb
diff --git a/src/cockpit.js b/src/cockpit.js
index 00f191bf..8198798b 100644
--- a/src/cockpit.js
+++ b/src/cockpit.js
@@ -193,8 +193,32 @@ if (snapshot) view.state = 'all';
let data = null;
let seen = '';
let addressReady = false;
+let heldPipelinePointer = null;
+let deferredPipelineRender = false;
const addressedShouts = new Map();
const $ = (id) => document.getElementById(id);
+
+/** Mark the primary pointer while it holds a Pipeline card so a refresh cannot replace its click target. */
+function holdPipelinePointer(event) {
+ if (!event.isPrimary || event.button !== 0 || !(event.target instanceof Element && event.target.closest('#pipeline .pipeline-item'))) return;
+ heldPipelinePointer = event.pointerId;
+}
+
+/** Flush a deferred refresh only after the browser has had the chance to dispatch the resulting click. */
+function releasePipelinePointer(event) {
+ if (event.pointerId !== heldPipelinePointer) return;
+ heldPipelinePointer = null;
+ if (deferredPipelineRender) requestAnimationFrame(() => {
+ if (heldPipelinePointer === null && deferredPipelineRender) {
+ deferredPipelineRender = false;
+ render();
+ }
+ });
+}
+
+document.addEventListener('pointerdown', holdPipelinePointer, true);
+document.addEventListener('pointerup', releasePipelinePointer, true);
+document.addEventListener('pointercancel', releasePipelinePointer, true);
/**
* Draw the page in the theme the person picked, light or dark; with none picked it follows the system, live. The button
* only ever offers the other of the two: it shows the scheme on screen, and a press picks the opposite. Following the
@@ -1432,6 +1456,8 @@ if (typeof MutationObserver === 'function') new MutationObserver((changes) => {
/** Draw the board shown: the sidebar, then every tab's panes from the project's board. */
function render() {
+ if (heldPipelinePointer !== null) { deferredPipelineRender = true; return; }
+ deferredPipelineRender = false;
const statsFocus = document.activeElement?.id === 'proof-stats-summary' ? document.activeElement.id : null;
const p = data.project;
const group = data.group;
diff --git a/test/cockpit/items.test.js b/test/cockpit/items.test.js
index 17a24c2b..99dfba99 100644
--- a/test/cockpit/items.test.js
+++ b/test/cockpit/items.test.js
@@ -1109,6 +1109,57 @@ function pipelineBoard(box, alpha) {
return { base, arrivals: { open: [5, 0], claimed: [4, 12], submitted: [3, 11], accepted: [2, 9], merged: [1, 6] } };
}
+/** Installs capture diagnostics for real Pipeline card presses and leaves the original timeout error intact. */
+async function installPipelinePressDiagnostics(chrome) {
+ const setup = await chrome.stable(`(() => {
+ const pipeline = document.querySelector('#pipeline');
+ if (!pipeline) throw new Error('Pipeline container is missing');
+ const state = { armed: false, redraws: 0, redrawsAtPress: 0, expected: null, down: null, up: null, click: null };
+ const observer = new MutationObserver(records => { state.redraws += records.filter(record => record.target === pipeline && record.type === 'childList').length; });
+ observer.observe(pipeline, { childList: true });
+ const flush = () => { state.redraws += observer.takeRecords().filter(record => record.target === pipeline && record.type === 'childList').length; return state.redraws; };
+ const describe = node => node instanceof Element ? node.tagName.toLowerCase() + (node.id ? '#' + node.id : '') + (typeof node.className === 'string' && node.className ? '.' + node.className.trim().split(/\\s+/).join('.') : '') : String(node);
+ const listen = kind => event => {
+ if (!state.armed) return;
+ const card = event.composedPath().find(node => node instanceof Element && node.classList.contains('pipeline-item')) ?? null;
+ state[kind] = { target: describe(event.target), dataItem: card?.dataset.item ?? null, connected: card?.isConnected ?? false,
+ viewItem: view.item, pathname: location.pathname, innerWidth, redraws: flush(), node: card };
+ if (kind === 'up' && state.down) state.down.connectedAtUp = Boolean(state.down.node?.isConnected);
+ if (kind === 'click' && state.down) state.click.sameNodeAsDown = state.click.node === state.down.node;
+ };
+ document.addEventListener('mousedown', listen('down'), true);
+ document.addEventListener('mouseup', listen('up'), true);
+ document.addEventListener('click', listen('click'), true);
+ state.arm = card => { flush(); state.expected = { dataItem: card?.dataset.item ?? null, connected: Boolean(card?.isConnected), disabled: card?.disabled ?? null };
+ state.expectedNode = card; state.down = state.up = state.click = null; state.redrawsAtPress = state.redraws; state.armed = true; return state.expected; };
+ state.snapshot = () => {
+ const redraws = flush();
+ const clean = event => event && ({ target: event.target, dataItem: event.dataItem, connected: event.connected, connectedAtUp: event.connectedAtUp,
+ disabled: event.disabled, viewItem: event.viewItem, pathname: event.pathname, innerWidth: event.innerWidth, redraws: event.redraws,
+ sameNodeAsDown: event.sameNodeAsDown });
+ return { expected: state.expected, down: clean(state.down), up: clean(state.up), click: clean(state.click), refresh: state.refresh ?? null, expectedNodeConnected: Boolean(state.expectedNode?.isConnected),
+ downNodeConnectedNow: Boolean(state.down?.node?.isConnected), viewItem: view.item, pathname: location.pathname, innerWidth,
+ pipelineRedrawsSincePress: redraws - state.redrawsAtPress,
+ pipelineRedrawsBetweenDownAndUp: state.down && state.up ? state.up.redraws - state.down.redraws : null };
+ };
+ globalThis.__pipelinePressDiagnostic = state;
+ return { ready: true, pathname: location.pathname, selected: view.item };
+ })()`);
+ assert.equal(setup.ready, true, 'the real Pipeline diagnostics are installed');
+}
+
+/** Waits for the original Pipeline selection predicate and adds real press diagnostics if its wait times out. */
+async function waitForPipelineItem(chrome, id) {
+ try {
+ await chrome.waitFor(`view.item === ${id}`);
+ } catch (error) {
+ let snapshot = 'diagnostics unavailable';
+ try { snapshot = await chrome.stable('JSON.stringify(globalThis.__pipelinePressDiagnostic?.snapshot() ?? null)'); } catch {}
+ error.message += `; Pipeline press diagnostics for #${id}: ${snapshot}`;
+ throw error;
+ }
+}
+
test('Pipeline view shows every stage, status counts, stage ages, detail links and its phone address [N26,N38]', { timeout: 120_000 }, async () => {
const executable = chromeExecutable();
assert.ok(executable, 'Chrome is required for the Pipeline view criterion');
@@ -1143,6 +1194,7 @@ test('Pipeline view shows every stage, status counts, stage ages, detail links a
assert.ok(Math.abs(elapsed - (observedAt - Date.parse(since)) / 60_000) <= 1, stage.stage + ': elapsed time matches native fixture arrival'); // budget: one minute is the display's measured-age rounding unit.
}
assert.equal(await chrome.stable("document.querySelector('#item-list').hidden"), true);
+ await installPipelinePressDiagnostics(chrome);
for (const width of [375, 1280]) {
await chrome.send('Emulation.setDeviceMetricsOverride', { width, height: 900, deviceScaleFactor: 1, mobile: false });
await chrome.waitFor(`innerWidth === ${width}`);
@@ -1151,8 +1203,10 @@ test('Pipeline view shows every stage, status counts, stage ages, detail links a
await chrome.stable('(async()=>{await new Promise(requestAnimationFrame);await new Promise(requestAnimationFrame)})()');
assert.equal(await chrome.stable('document.documentElement.dataset.scheme'), scheme);
for (const id of [1, 2, 3, 4, 5, 6]) {
- await press(chrome, `document.querySelector('#pipeline .pipeline-item[data-item="${id}"]')`);
- await chrome.waitFor(`view.item === ${id}`);
+ const selector = `document.querySelector('#pipeline .pipeline-item[data-item="${id}"]')`;
+ await chrome.stable(`globalThis.__pipelinePressDiagnostic.arm(${selector})`);
+ await press(chrome, selector);
+ await waitForPipelineItem(chrome, id);
assert.equal(await chrome.stable('view.item'), id, `${width}: every item opens its detail`);
await chrome.waitFor(`document.querySelector('#detail h2')?.textContent.includes('#${id}')`);
}
@@ -1189,6 +1243,110 @@ test('Pipeline view shows every stage, status counts, stage ages, detail links a
}
});
+/** A real card press records click delivery, Pipeline redraws and address selection under CPU throttling [N26,N38,C7]. */
+test('the pipeline opens the clicked item under a 6× CPU throttle [N26,N38,C7]', { timeout: 120_000 }, async (t) => { // budget: hang ceiling for one browser journey at the declared 6× CPU load.
+ const executable = chromeExecutable();
+ assert.ok(executable, 'Chrome is required for the throttled Pipeline click diagnostic');
+ const box = machine(), alpha = project(box, 'pipeline-click-under-load');
+ pipelineBoard(box, alpha);
+ const view = await startView(box), profile = mkdtempSync(join(tmpdir(), 'pullboard-pipeline-click-chrome-'));
+ let chrome;
+ try {
+ chrome = await openSnapshotChrome(executable, view.link.href, profile);
+ await chrome.waitFor(`data?.project?.root === ${JSON.stringify(alpha.repo)} && document.querySelector('#chain [data-item="5"]')`);
+ await chrome.send('Emulation.setDeviceMetricsOverride', { width: 375, height: 900, deviceScaleFactor: 1, mobile: false });
+ await press(chrome, "document.querySelector('[data-items-view=\"pipeline\"]')");
+ await chrome.waitFor("location.pathname === '/items/pipeline' && !document.querySelector('#pipeline').hidden");
+ await chrome.send('Emulation.setCPUThrottlingRate', { rate: 6 });
+ await installPipelinePressDiagnostics(chrome);
+ const id = 2;
+ const selector = `document.querySelector('#pipeline .pipeline-item[data-item="${id}"]')`;
+ const armed = await chrome.stable(`globalThis.__pipelinePressDiagnostic.arm(${selector})`);
+ assert.deepEqual(armed, { dataItem: String(id), connected: true, disabled: false }, 'the intended real card is present and enabled before press');
+ let failure = null;
+ try {
+ await press(chrome, selector);
+ await chrome.waitFor(`(() => { const evidence = globalThis.__pipelinePressDiagnostic.snapshot(); globalThis.__pipelinePressDiagnostic.last = evidence; return evidence.viewItem === ${id}; })()`, 15_000); // budget: hang ceiling for the clicked item to reach its detail, not a speed target.
+ } catch (error) {
+ failure = error;
+ }
+ const evidence = JSON.parse(await chrome.stable('JSON.stringify(globalThis.__pipelinePressDiagnostic.last || globalThis.__pipelinePressDiagnostic.snapshot())'));
+ assert.equal(failure, null, `${failure?.message || 'the selected item matched'}; Pipeline click evidence: ${JSON.stringify(evidence)}`);
+ assert.equal(evidence.down?.dataItem, String(id), `the mousedown reached the intended card: ${JSON.stringify(evidence)}`);
+ assert.equal(evidence.up?.dataItem, String(id), `the mouseup remained on the intended card: ${JSON.stringify(evidence)}`);
+ assert.equal(evidence.click?.dataItem, String(id), `the real click reached the intended card: ${JSON.stringify(evidence)}`);
+ assert.equal(evidence.viewItem, id, `the intended item is selected: ${JSON.stringify(evidence)}`);
+ assert.equal(evidence.pathname, `/items/${id}`, `the address names the intended item: ${JSON.stringify(evidence)}`);
+ await chrome.waitFor(`document.querySelector('#detail h2')?.textContent.includes('#${id}')`);
+ t.diagnostic(`375px 6× Pipeline click: ${JSON.stringify(evidence)}`);
+ assert.deepEqual(chrome.exceptions, [], 'the throttled Pipeline click has no uncaught page errors');
+ } finally {
+ if (chrome) await closeSnapshotChrome(chrome);
+ await view.stop();
+ rmSync(profile, { recursive: true, force: true });
+ }
+});
+
+/** A real API refresh while the pointer is held must leave the pressed Pipeline card for its click. */
+test('a refresh between pointer down and up does not lose the click [N26,N38,C7]', { timeout: 120_000 }, async (t) => { // budget: hang ceiling for one native press and forced local refresh; no speed threshold.
+ const executable = chromeExecutable();
+ assert.ok(executable, 'Chrome is required for the held-pointer refresh journey');
+ const box = machine(), alpha = project(box, 'pipeline-refresh-under-press');
+ pipelineBoard(box, alpha);
+ const view = await startView(box), profile = mkdtempSync(join(tmpdir(), 'pullboard-pipeline-refresh-press-chrome-'));
+ let chrome;
+ try {
+ chrome = await openSnapshotChrome(executable, view.link.href, profile);
+ await chrome.waitFor(`data?.project?.root === ${JSON.stringify(alpha.repo)} && document.querySelector('#chain [data-item="5"]')`);
+ await chrome.send('Emulation.setDeviceMetricsOverride', { width: 375, height: 900, deviceScaleFactor: 1, mobile: false });
+ await press(chrome, "document.querySelector('[data-items-view=\"pipeline\"]')");
+ await chrome.waitFor("location.pathname === '/items/pipeline' && !document.querySelector('#pipeline').hidden");
+ await chrome.send('Emulation.setCPUThrottlingRate', { rate: 6 });
+ await installPipelinePressDiagnostics(chrome);
+ await chrome.stable(`globalThis.__pipelinePressDiagnostic.arm(document.querySelector('#pipeline .pipeline-item[data-item="2"]'))`);
+ let refreshObservation;
+ await press(chrome, "document.querySelector('#pipeline .pipeline-item[data-item=\"2\"]')", {
+ afterMouseDown: async () => {
+ const title = 'A new item arrives during the held Pipeline press';
+ box.run(alpha.repo, 'add', 'web', title, '--specs', 'G1', '--criterion', 'Refresh the board while a card is pressed');
+ refreshObservation = JSON.parse(await chrome.stable(`(async () => {
+ await refresh();
+ const old = globalThis.__pipelinePressDiagnostic.down?.node;
+ const observation = { fetchedNewItem: data.project.items.some(item => item.title === ${JSON.stringify(title)}),
+ originalCardConnectedWhileHeld: Boolean(old?.isConnected), selected: view.item, pathname: location.pathname, innerWidth,
+ pipelineRedrawsBeforeRelease: globalThis.__pipelinePressDiagnostic.snapshot().pipelineRedrawsSincePress };
+ globalThis.__pipelinePressDiagnostic.refresh = observation;
+ return JSON.stringify(observation);
+ })()`));
+ assert.equal(refreshObservation.fetchedNewItem, true, `the real API refresh received the new native board item: ${JSON.stringify(refreshObservation)}`);
+ assert.equal(refreshObservation.originalCardConnectedWhileHeld, true, `the changed board does not replace the pressed card before mouseup: ${JSON.stringify(refreshObservation)}`);
+ assert.equal(refreshObservation.pipelineRedrawsBeforeRelease, 0, `the Pipeline has not redrawn while the pointer is held: ${JSON.stringify(refreshObservation)}`);
+ },
+ });
+ const evidence = JSON.parse(await chrome.stable('JSON.stringify(globalThis.__pipelinePressDiagnostic.snapshot())'));
+ assert.equal(evidence.down?.dataItem, '2', `mousedown reached the intended item: ${JSON.stringify(evidence)}`);
+ assert.equal(evidence.up?.dataItem, '2', `mouseup reached the intended item: ${JSON.stringify(evidence)}`);
+ assert.equal(evidence.click?.dataItem, '2', `the browser dispatched click to the intended item: ${JSON.stringify(evidence)}`);
+ assert.equal(evidence.down?.connectedAtUp, true, `the original card remained connected through mouseup: ${JSON.stringify(evidence)}`);
+ assert.equal(evidence.click?.sameNodeAsDown, true, `the click belongs to the card that received mousedown: ${JSON.stringify(evidence)}`);
+ assert.equal(evidence.viewItem, 2, `the native click opens item #2: ${JSON.stringify(evidence)}`);
+ assert.equal(evidence.pathname, '/items/2', `the item address agrees with the real selection: ${JSON.stringify(evidence)}`);
+ assert.equal(evidence.pipelineRedrawsBetweenDownAndUp, 0, `no Pipeline redraw separates mousedown and mouseup: ${JSON.stringify(evidence)}`);
+ await chrome.waitFor("document.querySelector('#detail h2')?.textContent.includes('#2')");
+ await chrome.stable('refresh()');
+ assert.equal(await chrome.stable('view.item'), 2, 'refresh preserves the selected item instead of an address candidate');
+ await chrome.send('Page.reload', {});
+ await settled(chrome, "typeof data !== 'undefined' && location.pathname === '/items/2' && view.item === 2");
+ assert.equal(await chrome.stable('view.item'), 2, 'reload restores the selected item from its address');
+ t.diagnostic(`375px 6× held-pointer API refresh: ${JSON.stringify({ refreshObservation, evidence })}`);
+ assert.deepEqual(chrome.exceptions, [], 'the refresh and held-pointer click produce no uncaught page errors');
+ } finally {
+ if (chrome) await closeSnapshotChrome(chrome);
+ await view.stop();
+ rmSync(profile, { recursive: true, force: true });
+ }
+});
+
test('Pipeline view dates an expired claim from its recorded deadline [N26,N38]', async () => {
const box = machine(), alpha = project(box, 'pipeline-lapse');
const base = Date.now() - 60 * 60_000, commit = box.git(alpha.repo, 'rev-parse', 'HEAD');
diff --git a/test/cockpit/stable.js b/test/cockpit/stable.js
index 551e0c0d..9709d20a 100644
--- a/test/cockpit/stable.js
+++ b/test/cockpit/stable.js
@@ -59,8 +59,12 @@ export async function waitForStableBoxes(chrome, find = 'document.documentElemen
/**
* Press an uncovered, stable target through real Chrome input. A pointer move can change hover layout,
* so wait again after it and refuse a changed point rather than retrying the action at another point.
+ * @param {object} chrome
+ * @param {string} find
+ * @param {{ native?: boolean, afterMouseDown?: () => Promise<void> }} [options] - Optionally run a bounded observation while the real pointer remains held.
+ * @returns {Promise<void>}
*/
-export async function press(chrome, find, { native = true } = {}) {
+export async function press(chrome, find, { native = true, afterMouseDown = null } = {}) {
await waitForStableBoxes(chrome, find);
if (!native) return rawChromeEvaluation(chrome, `(${find}).click()`);
await rawChromeEvaluation(chrome, `(${find}).scrollIntoView({ block: 'center', behavior: 'instant' })`);
@@ -84,7 +88,11 @@ export async function press(chrome, find, { native = true } = {}) {
document.addEventListener('mousedown', event => Object.assign(window.__pressed, { landed: name(event.target), landedAt: Math.round(event.clientY), scrolledTo: Math.round(scrollY) }), { capture: true, once: true });
})()`);
await raw.send('Input.dispatchMouseEvent', { type: 'mousePressed', x: point.x, y: point.y, button: 'left', clickCount: 1 });
- await raw.send('Input.dispatchMouseEvent', { type: 'mouseReleased', x: point.x, y: point.y, button: 'left', clickCount: 1 });
+ try {
+ if (afterMouseDown) await afterMouseDown();
+ } finally {
+ await raw.send('Input.dispatchMouseEvent', { type: 'mouseReleased', x: point.x, y: point.y, button: 'left', clickCount: 1 });
+ }
}
/** Tap a stable visible target with Chrome's real touch input path, so touch interactions are not simulated clicks. */