Let the app bar's update line use the room the bar has

AI Assisted
This commit is contained in:
jparkerweb committed 2026-11-29 10:49:44 -08:00
1 parent 834b71e82d
commit 97f65edd84
4 files changed
+132 -4

No files matched your search

+6
View File
@@ -115,6 +115,12 @@
- Why: Each launcher prompt opens a new readline, so piping all answers at once loses every answer after the first.
- Noted: 2026-11-17, implement-review, checked 2026-11-28
### To run plan2code-app/ui/app.js in a page test, serve the ui folder over HTTP and stub window.__TAURI__, with platform_info answering { os }; from file:// the module never loads.
- Kind: how-it-works
- About: scripts/test-app-meter.mjs, plan2code-app/ui/app.js
- Why: A test that loaded index.html from file:// never ran fitBar(), and a catch-all stub made mountTerminal's top-level await throw.
- Noted: 2026-11-29, quick-task
### When a card in src/plan2code-deps.md changes (what it lists or asks), change the same card in src/web-console/notes/deps.md in the same edit: the console builds the card from the notes.
- Kind: correction
- About: src/plan2code-deps.md, src/web-console/notes/deps.md
+4 -1
View File
@@ -427,8 +427,11 @@ function fitBar() {
barRowEl.classList.remove('no-model', 'no-status');
const model = agentModelEl.hidden ? 0 : agentModelEl.offsetWidth;
const status = agentStatusEl.textContent ? agentStatusEl.offsetWidth : 0;
// The step text shrinks rather than overflowing the row, so what it hides
// counts as needed room: the model and status drop before it is cut.
const stepCut = nextStepEl.hidden ? 0 : Math.max(0, nextStepTextEl.scrollWidth - nextStepTextEl.clientWidth);
// Only an agent's menu can hold them, so with none the row keeps everything.
const fit = agentMenuBtn.hidden ? { model: true, status: true } : barFit({ available: barRowEl.clientWidth, needed: barRowEl.scrollWidth, model, status });
const fit = agentMenuBtn.hidden ? { model: true, status: true } : barFit({ available: barRowEl.clientWidth, needed: barRowEl.scrollWidth + stepCut, model, status });
const dropModel = !fit.model && model > 0;
const dropStatus = !fit.status && status > 0;
barRowEl.classList.toggle('no-model', dropModel);
+9 -2
View File
@@ -105,8 +105,15 @@
@media (prefers-reduced-motion: reduce) { #loop-dot, .loop-pip.current { animation: none; } }
#bar-grow { flex: 1; min-width: 0; }
/* The one next step for the console or the skills, at the right end. */
#next-step { display: flex; align-items: center; gap: 8px; flex: none; }
#next-step-text { overflow: hidden; text-overflow: ellipsis; max-width: 320px; }
/* It takes the room the row has left and is cut, with an ellipsis, only
once fitBar() has already dropped the model and status text. The text's
column may shrink to nothing, so the box's own floor is its buttons:
it never squeezes them, or runs them under the menu button. */
#bar-row > #next-step {
display: grid; grid-auto-flow: column; grid-template-columns: minmax(0, max-content); grid-auto-columns: max-content;
align-items: center; gap: 8px; flex: 0 1 auto;
}
#next-step > #next-step-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
#next-step-text.is-ok { color: var(--ok); }
#next-step-text.is-warn { color: var(--stage); }
#next-step-text.is-err { color: var(--warn); }
+113 -1
View File
@@ -9,6 +9,7 @@
import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import http from "node:http";
import path from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
import { looksFromMessage, terminalFontStep, TERMINAL_FONT_DEFAULT, TERMINAL_FONT_MIN, TERMINAL_FONT_MAX, splitterFraction, splitterAria, terminalTitle, barFit, terminalAnsi, TERMINAL_ANSI, hexToRgba, helloRetryAction, retryLabel, RETRY_AFTER_SECONDS, attentionSignal, commandSegments, plainCommandText, menuStep, pageNotShownView, pageDetailsLine, redactSessionUrl, barNextSteps, continueKeys, defaultRightFraction, folderName, folderPickerRows, pickDefaultAgent, taskbarSwitch, windowTitleFor, deadConsoleAction, loopBanner, loopRunText, loopLocks, loopStopLabels, loopWindowTitle, CONSOLE_ASIDE_BREAKPOINT_PX, NEXT_STEP_LABELS, NEW_RELEASE_COMMAND, STILL_WAITING_MS, STILL_WAITING_TEXT, waitingView, friendlyError, endedView, confirmButtons, trapTab, SHORTCUTS, shortcutAction, shortcutLabel, tipWithShortcut, shortcutFromMessage, clipboardAction, releaseAfterCheck, releaseNotesUrl, reasonSentence, UPDATE_RECHECK_MS } from "../plan2code-app/ui/meter.js";
@@ -1135,11 +1136,122 @@ test("barFit drops the model text first, then the status line, and only when the
assert.deepEqual(barFit({ available: 500, needed: 800 }), { model: false, status: false }, "no parts measured, none claimed");
});
// The app's ui/ folder over HTTP on a free local port, for a test that needs app.js to run.
function serveFolder(dir) {
const TYPES = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".woff2": "font/woff2" };
const server = http.createServer((req, res) => {
const file = path.join(dir, decodeURIComponent(new URL(req.url, "http://x").pathname));
if (!file.startsWith(dir) || !fs.existsSync(file) || !fs.statSync(file).isFile()) {
res.writeHead(404).end();
return;
}
res.writeHead(200, { "content-type": TYPES[path.extname(file)] || "application/octet-stream" });
fs.createReadStream(file).pipe(res);
});
return new Promise((resolve) => server.listen(0, "127.0.0.1", () => resolve(server)));
}
test("the bar's step text uses the room the row has; model and status drop before it is cut, and its buttons never shrink", async (t) => {
if (!findBrowser()) return t.skip("no Chrome or Edge installed");
const browser = await launchBrowser();
try {
const page = await browser.newPage({ viewport: { width: 1800, height: 600 } });
// Later start-up steps trip over the stub's nulls; the bar is wired before them,
// and "the model alone drops" below shows fitBar() ran.
page.on("pageerror", () => {});
// Enough of __TAURI__ for app.js to run, so its real fitBar() lays out the row:
// every command answers null (platform_info a platform), every window call resolves.
await page.addInitScript(() => {
const resolved = () => Promise.resolve();
const win = new Proxy({}, { get: () => resolved });
const known = {
core: { invoke: (cmd) => Promise.resolve(cmd === "platform_info" ? { os: "linux" } : null), Channel: class {} },
window: { getCurrentWindow: () => win },
event: { listen: () => Promise.resolve(() => {}) },
};
window.__TAURI__ = new Proxy(known, { get: (all, key) => all[key] || new Proxy({}, { get: () => resolved }) });
});
// app.js is a module, which Chrome will not load from file://: serve the folder.
const server = await serveFolder(path.dirname(INDEX_HTML_PATH));
t.after(() => server.close());
await page.goto(`http://127.0.0.1:${server.address().port}/index.html`, { waitUntil: "networkidle" });
await page.evaluate(() => {
const show = (id, text) => {
const el = document.getElementById(id);
el.hidden = false;
if (text !== undefined) el.textContent = text;
};
document.getElementById("agent-none").hidden = true;
show("project-menu-button");
document.getElementById("project-name").textContent = "plan2code";
show("agent-restart");
show("agent-menu-button");
document.getElementById("agent-name").textContent = "Claude Code";
show("agent-model", "opus 5.5 xhigh");
document.getElementById("agent-status").textContent = "Working: reading the plan and every phase file";
show("next-step");
const text = document.getElementById("next-step-text");
text.textContent = "npx fetches it quietly first, which can take a minute or two.";
text.className = "is-warn is-busy";
show("next-step-button", "Update and restart");
show("next-step-more", "+1 more");
show("next-step-notes");
});
const settle = () => page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
const measure = () =>
page.evaluate(() => {
const row = document.getElementById("bar-row");
const text = document.getElementById("next-step-text");
const box = (id) => document.getElementById(id).getBoundingClientRect();
const menu = box("app-menu-button");
const buttons = ["next-step-button", "next-step-more", "next-step-notes"].map(box);
return {
noModel: row.classList.contains("no-model"),
noStatus: row.classList.contains("no-status"),
cut: text.scrollWidth > text.clientWidth,
textWidth: text.clientWidth,
buttonWidths: buttons.map((b) => Math.round(b.width)),
overlap: buttons.some((b) => b.right > menu.left + 0.5),
menuInside: menu.width > 0 && menu.right <= row.getBoundingClientRect().right + 0.5,
};
});
await settle();
const wide = await measure();
assert.deepEqual([wide.noModel, wide.noStatus, wide.cut], [false, false, false], "a wide window shows everything, the whole line included");
assert.ok(wide.textWidth > 320, `wider than the old 320px cap (${wide.textWidth}px)`);
const seen = new Set();
// Down to the app's minimum width (tauri.conf.json minWidth 960).
for (let width = 1800; width >= 960; width -= 20) {
await page.setViewportSize({ width, height: 600 });
await settle();
const at = await measure();
if (at.cut) assert.ok(at.noModel && at.noStatus, `${width}px: the line is cut only after the model and status dropped`);
if (at.noStatus) assert.ok(at.noModel, `${width}px: the model drops before the status`);
assert.deepEqual(at.buttonWidths, wide.buttonWidths, `${width}px: the step buttons keep their width`);
assert.equal(at.overlap, false, `${width}px: no step button runs under the menu button`);
assert.equal(at.menuInside, true, `${width}px: the menu button stays inside the row`);
seen.add(`${at.noModel}/${at.noStatus}/${at.cut}`);
}
assert.ok(seen.has("true/false/false"), `the model alone drops at some width (${[...seen]})`);
assert.ok(seen.has("true/true/true"), `the line is cut at the narrowest widths (${[...seen]})`);
assert.equal(await page.evaluate(() => getComputedStyle(document.getElementById("next-step-text")).textOverflow), "ellipsis");
// Below the minimum, the row runs out at its end as it always did: the text
// has shrunk to nothing, but its buttons are never squeezed under the menu.
await page.setViewportSize({ width: 400, height: 600 });
await settle();
const tight = await measure();
assert.deepEqual(tight.buttonWidths, wide.buttonWidths, "400px: the step buttons keep their width");
assert.equal(tight.overlap, false, "400px: no step button runs under the menu button");
} finally {
await browser.close();
}
});
test("the top bar collapses instead of scrolling, and +N more is a button that lists the other steps", () => {
assert.doesNotMatch(INDEX_HTML, /#bar-row \{[^}]*overflow-x: auto/, "no sideways scrolling row");
assert.match(INDEX_HTML, /#bar-row\.no-model #agent-model, #bar-row\.no-status #agent-status \{ display: none; \}/);
assert.match(APP_JS, /new ResizeObserver\(scheduleFitBar\)\.observe\(barRowEl\);/);
assert.match(APP_JS, /barFit\(\{ available: barRowEl\.clientWidth, needed: barRowEl\.scrollWidth, model, status \}\)/);
assert.match(APP_JS, /barFit\(\{ available: barRowEl\.clientWidth, needed: barRowEl\.scrollWidth \+ stepCut, model, status \}\)/);
assert.doesNotMatch(APP_JS, /barRowEl\.addEventListener\('scroll'/);
assert.match(INDEX_HTML, /<button id="next-step-more" type="button" aria-haspopup="menu" aria-expanded="false" aria-controls="more-menu" hidden><\/button>/);
assert.match(INDEX_HTML, /<div id="more-menu" class="bar-dropdown" role="menu"[^>]*tabindex="-1" hidden><\/div>/);