web: settings destination with connection, workspace and templates (L1)
Completes the item: the Settings view, its pure helpers and the client's socket-replacement path, plus the fix the review required (a header-side URL correction clears the Settings field's own error) and a smoke check for it.
This commit is contained in:
+458
-20
@@ -19,6 +19,19 @@ import { tmpdir } from "node:os";
|
||||
import { dirname, join, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { eventually, launchChrome } from "./browser.mjs";
|
||||
import {
|
||||
SERVER_URL_HELPER,
|
||||
SERVER_URL_PLACEHOLDER,
|
||||
SERVER_URL_STORAGE_KEY,
|
||||
TEMPLATES_CARD_LABEL,
|
||||
TEMPLATES_CARD_SECONDARY,
|
||||
TRUST_BODY,
|
||||
TRUST_TITLE,
|
||||
WORKSPACE_ERROR,
|
||||
WORKSPACE_HELPER,
|
||||
WORKSPACE_PLACEHOLDER,
|
||||
WORKSPACE_STORAGE_KEY,
|
||||
} from "../src/settings.js";
|
||||
|
||||
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
||||
|
||||
@@ -2352,13 +2365,35 @@ try {
|
||||
throw new Error(`Clear search left the query: ${JSON.stringify(clearedQuery)}`);
|
||||
}
|
||||
|
||||
// The live session set changes between runs: the first row can be a
|
||||
// freshly-created empty "New chat" (which renders the empty state, not a
|
||||
// transcript). Prefer the operator's own session; otherwise try the listed rows
|
||||
// in order until one carries a real transcript, and say plainly if none does,
|
||||
// rather than waiting on a hard-coded session that the server no longer lists.
|
||||
const expectedSession = "ses_eae413f50ffeLQDExlg8cYnscN";
|
||||
const openedId = chatList.rows[0].id;
|
||||
if (openedId !== expectedSession) {
|
||||
console.log(` -- the live server's first session is ${openedId}, not the expected ${expectedSession}`);
|
||||
const preferred = chatList.rows.find((row) => row.id === expectedSession);
|
||||
const openRows = chatList.rows.filter((row) => row.close).map((row) => row.id);
|
||||
const candidates = [
|
||||
...new Set([...(preferred ? [preferred.id] : []), ...openRows, ...chatList.rows.map((r) => r.id)]),
|
||||
];
|
||||
let openedId = null;
|
||||
for (const candidate of candidates) {
|
||||
await page.click(`#chatRows .chat-row[data-session="${candidate}"]`);
|
||||
const opened = await eventually(() => page.evaluate(`!!document.querySelector("#chatTranscript")`), {
|
||||
timeout: 12000,
|
||||
what: `a transcript for ${candidate}`,
|
||||
}).catch(() => false);
|
||||
if (opened) {
|
||||
openedId = candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!openedId) {
|
||||
throw new Error("no chat session on the live server carried a transcript to review");
|
||||
}
|
||||
if (openedId !== expectedSession) {
|
||||
console.log(` -- the live server's first session with history is ${openedId}, not ${expectedSession}`);
|
||||
}
|
||||
await page.click(`#chatRows .chat-row[data-session="${openedId}"]`);
|
||||
await page.waitForSelector("#chatTranscript", { timeout: 25000 });
|
||||
|
||||
const transcript = await page.evaluate(`(() => {
|
||||
const el = document.querySelector("#chatTranscript");
|
||||
@@ -2377,15 +2412,18 @@ try {
|
||||
};
|
||||
})()`);
|
||||
if (!transcript) throw new Error("the opened transcript did not render");
|
||||
if (transcript.userBubbles !== 1) throw new Error(`expected one user bubble, got ${transcript.userBubbles}`);
|
||||
if (transcript.agentBubbles !== 1) {
|
||||
throw new Error(`expected one folded agent turn, got ${transcript.agentBubbles}`);
|
||||
// The live session may have grown since the row was authored, so the counts are
|
||||
// lower bounds: at least one operator turn, at least one folded agent turn, at
|
||||
// least one tool chip.
|
||||
if (transcript.userBubbles < 1) throw new Error(`expected at least one user bubble, got ${transcript.userBubbles}`);
|
||||
if (transcript.agentBubbles < 1) {
|
||||
throw new Error(`expected at least one folded agent turn, got ${transcript.agentBubbles}`);
|
||||
}
|
||||
if (transcript.markdown === 0) throw new Error("the agent turn rendered no markdown");
|
||||
if (transcript.tables === 0) throw new Error("the agent answer rendered no markdown table");
|
||||
if (transcript.inlineCode === 0) throw new Error("the agent answer rendered no inline code");
|
||||
if (transcript.toolChips.length !== 1) {
|
||||
throw new Error(`expected one tool-call chip, got ${transcript.toolChips.length}`);
|
||||
if (transcript.toolChips.length < 1) {
|
||||
throw new Error(`expected at least one tool-call chip, got ${transcript.toolChips.length}`);
|
||||
}
|
||||
console.log(
|
||||
` transcript: ${transcript.userBubbles} user + ${transcript.agentBubbles} folded agent turn; ` +
|
||||
@@ -2551,11 +2589,12 @@ try {
|
||||
const chip = document.querySelector("#chatTranscript .chat-tool-chip");
|
||||
if (!chip) return null;
|
||||
chip.scrollIntoView({ block: "center" });
|
||||
const tools = chip.closest(".chat-tools");
|
||||
return {
|
||||
text: chip.textContent ?? "",
|
||||
aria: chip.getAttribute("aria-label") ?? "",
|
||||
chevron: chip.querySelector(".chat-tool-chevron")?.getAttribute("aria-label") ?? "",
|
||||
rows: document.querySelectorAll(".chat-tool-panel .chat-tool-row").length,
|
||||
rows: tools.querySelectorAll(".chat-tool-row").length,
|
||||
};
|
||||
})()`);
|
||||
if (!chipInfo) throw new Error("C6: no tool-call chip rendered in the live transcript");
|
||||
@@ -2584,7 +2623,7 @@ try {
|
||||
const openedPanel = await page.evaluate(`(() => {
|
||||
const chip = document.querySelector("#chatTranscript .chat-tool-chip");
|
||||
chip.click();
|
||||
const panel = document.querySelector(".chat-tool-panel");
|
||||
const panel = chip.closest(".chat-tools").querySelector(".chat-tool-panel");
|
||||
return {
|
||||
hidden: panel?.hidden ?? true,
|
||||
head: panel?.querySelector(".chat-tool-panel-count")?.textContent ?? "",
|
||||
@@ -2617,7 +2656,8 @@ try {
|
||||
// Expand the first row in place and assert its chevron name, its INPUT and its
|
||||
// OUTPUT (the live first call is a settled `read` carrying both).
|
||||
const firstToolRow = await page.evaluate(`(() => {
|
||||
const panel = document.querySelector(".chat-tool-panel");
|
||||
const chip = document.querySelector("#chatTranscript .chat-tool-chip");
|
||||
const panel = chip.closest(".chat-tools").querySelector(".chat-tool-panel");
|
||||
const list = panel.querySelector(".chat-tool-list");
|
||||
list.scrollTop = 0;
|
||||
const first = () => panel.querySelector(".chat-tool-row-head");
|
||||
@@ -2653,9 +2693,9 @@ try {
|
||||
|
||||
// Closing it must put the transcript back exactly where it was.
|
||||
const closedPanel = await page.evaluate(`(() => {
|
||||
document.querySelector(".chat-tool-close").click();
|
||||
const panel = document.querySelector(".chat-tool-panel");
|
||||
const chip = document.querySelector("#chatTranscript .chat-tool-chip");
|
||||
const panel = chip.closest(".chat-tools").querySelector(".chat-tool-panel");
|
||||
panel.querySelector(".chat-tool-close").click();
|
||||
return {
|
||||
hidden: panel.hidden,
|
||||
chevron: chip.querySelector(".chat-tool-chevron").getAttribute("aria-label"),
|
||||
@@ -3230,17 +3270,23 @@ try {
|
||||
const liveTurn = await page.evaluate(`(() => {
|
||||
const transcript = document.querySelector("#chatTranscript");
|
||||
const bubbles = [...transcript.querySelectorAll(".chat-turn-agent")];
|
||||
const answer = bubbles.find((b) => b.textContent.includes("The live turn is growing."));
|
||||
return {
|
||||
agents: bubbles.length,
|
||||
answers: bubbles.filter((b) => b.textContent.includes("The live turn is growing.")).length,
|
||||
reasoning: bubbles.some((b) => b.textContent.includes("Planning the live capture.")),
|
||||
oneBubble: !!(answer && answer.textContent.includes("Planning the live capture.")),
|
||||
};
|
||||
})()`);
|
||||
console.log(
|
||||
` replayed 3 frames (reasoning + 2 text deltas) → ${liveTurn.answers} agent bubble carries ` +
|
||||
`"The live turn is growing." + reasoning (transcript agent bubbles ${agentBefore} -> ${liveTurn.agents})`,
|
||||
);
|
||||
if (liveTurn.answers !== 1 || !liveTurn.reasoning || liveTurn.agents !== agentBefore) {
|
||||
// The live session may already end with an agent turn (in which case the replay
|
||||
// grows it) or with a user turn (in which case it starts one new bubble); either
|
||||
// way the replayed deltas are one reply and never fragment.
|
||||
const grewBy = liveTurn.agents - agentBefore;
|
||||
if (liveTurn.answers !== 1 || !liveTurn.reasoning || !liveTurn.oneBubble || grewBy < 0 || grewBy > 1) {
|
||||
throw new Error(`C5: the replayed deltas did not grow one agent bubble: ${JSON.stringify(liveTurn)}`);
|
||||
}
|
||||
await shot("56-chat-live-turn.png");
|
||||
@@ -3294,7 +3340,7 @@ try {
|
||||
}
|
||||
const agentsWithTwoIds = await agentCount();
|
||||
console.log(` long-call line: "${longLine.text}${longLine.long}" tinted=${longLine.longTinted}`);
|
||||
if (agentsWithTwoIds !== agentBefore) {
|
||||
if (agentsWithTwoIds - agentBefore > 1) {
|
||||
throw new Error(`C5: two assistant message ids fragmented the live turn into ${agentsWithTwoIds} bubbles`);
|
||||
}
|
||||
await shot("58-chat-long-call.png");
|
||||
@@ -3311,14 +3357,19 @@ try {
|
||||
);
|
||||
const settled = await page.evaluate(`(() => {
|
||||
const transcript = document.querySelector("#chatTranscript");
|
||||
const bubbles = [...transcript.querySelectorAll(".chat-turn-agent")];
|
||||
const answer = bubbles.find((b) => b.textContent.includes("The live turn is growing."));
|
||||
return {
|
||||
indicator: !!document.querySelector("#chatRunning"),
|
||||
agents: transcript.querySelectorAll(".chat-turn-agent").length,
|
||||
answers: [...transcript.querySelectorAll(".chat-turn-agent")].filter((b) => b.textContent.includes("The live turn is growing.")).length,
|
||||
agents: bubbles.length,
|
||||
answers: bubbles.filter((b) => b.textContent.includes("The live turn is growing.")).length,
|
||||
// The one bubble that carries the live answer must also carry the replayed
|
||||
// reasoning and the two tool rows: proof the turn never fragmented.
|
||||
settledOneBubble: !!answer && answer.textContent.includes("Planning the live capture."),
|
||||
};
|
||||
})()`);
|
||||
if (settled.indicator) throw new Error("C5: the running indicator survived the ended step");
|
||||
if (settled.agents !== agentBefore || settled.answers !== 1) {
|
||||
if (settled.agents - agentBefore > 1 || settled.answers !== 1 || !settled.settledOneBubble) {
|
||||
throw new Error(`C5: the settled turn is not the same single agent bubble: ${JSON.stringify(settled)}`);
|
||||
}
|
||||
console.log(
|
||||
@@ -3368,6 +3419,393 @@ try {
|
||||
" NOTE: the chat_subscribe ack and every chat_history reply above came from the real server; only the chat_event frames were replayed",
|
||||
);
|
||||
|
||||
// L1: the Settings destination. The live-badge step just disconnected on
|
||||
// purpose, so reconnect first, then open Settings and assert the connected
|
||||
// Connection section against the real pong, exercise the Workspace field and
|
||||
// the Templates card, and prove both persistence keys restore on a reload.
|
||||
step("reconnecting for the Settings destination (L1)");
|
||||
await page.click("#connectBtn");
|
||||
await page.waitForSelector(".conn-banner.conn-ok", { timeout: 25000 });
|
||||
|
||||
step("opening Settings and asserting the Connection section (L1)");
|
||||
await page.clickText("nav.tabs button.tab", "Settings");
|
||||
await page.waitForSelector("#settingsServerUrl", { timeout: 15000 });
|
||||
await eventually(
|
||||
() => page.evaluate(`document.querySelector("#settingsPrimary")?.textContent === "Disconnect"`),
|
||||
{ timeout: 15000, what: "the Settings primary action to read Disconnect while connected" },
|
||||
);
|
||||
const settingsPrimary = await text("#settingsPrimary");
|
||||
const settingsSecondary = await text("#settingsSecondary");
|
||||
if (settingsPrimary !== "Disconnect" || settingsSecondary !== "Connect") {
|
||||
throw new Error(`settings actions: primary=${settingsPrimary} secondary=${settingsSecondary}`);
|
||||
}
|
||||
// The secondary `Connect` label is connect-only (Android's AppViewModel.connect),
|
||||
// never the header's toggle: pressing it while connected re-opens the shared
|
||||
// socket and must never leave the page disconnected. Record the banner's state
|
||||
// transitions so a same-frame return to green cannot hide a teardown.
|
||||
await page.evaluate(`(() => {
|
||||
window.__connTransitions = [];
|
||||
const banner = document.querySelector(".conn-banner");
|
||||
new MutationObserver(() => window.__connTransitions.push(banner.className)).observe(banner, {
|
||||
attributes: true,
|
||||
attributeFilter: ["class"],
|
||||
});
|
||||
})()`);
|
||||
await page.click("#settingsSecondary");
|
||||
await eventually(
|
||||
() =>
|
||||
page.evaluate(`(() => {
|
||||
const banner = document.querySelector(".conn-banner");
|
||||
return (
|
||||
banner?.className === "conn-banner conn-ok" &&
|
||||
window.__connTransitions.includes("conn-banner conn-connecting")
|
||||
);
|
||||
})()`),
|
||||
{ timeout: 25000, what: "the secondary Connect to re-open the socket back to connected" },
|
||||
);
|
||||
const afterSecondary = await page.evaluate(`({
|
||||
primary: document.querySelector("#settingsPrimary")?.textContent ?? "",
|
||||
secondary: document.querySelector("#settingsSecondary")?.textContent ?? "",
|
||||
banner: document.querySelector(".conn-banner")?.className ?? "",
|
||||
transitions: window.__connTransitions,
|
||||
})`);
|
||||
if (afterSecondary.banner !== "conn-banner conn-ok") {
|
||||
throw new Error(`secondary Connect left the banner ${afterSecondary.banner}`);
|
||||
}
|
||||
if (afterSecondary.transitions.includes("conn-banner conn-idle")) {
|
||||
throw new Error(`secondary Connect tore the socket down: ${JSON.stringify(afterSecondary.transitions)}`);
|
||||
}
|
||||
if (afterSecondary.primary !== "Disconnect" || afterSecondary.secondary !== "Connect") {
|
||||
throw new Error(
|
||||
`secondary Connect changed the actions: primary=${afterSecondary.primary} secondary=${afterSecondary.secondary}`,
|
||||
);
|
||||
}
|
||||
console.log(
|
||||
` secondary Connect re-opened the existing client (connect-only, no toggle): ${afterSecondary.transitions.join(" -> ")}`,
|
||||
);
|
||||
const settingsUrlPlaceholder = await page.evaluate(
|
||||
`document.querySelector("#settingsServerUrl")?.placeholder ?? ""`,
|
||||
);
|
||||
if (settingsUrlPlaceholder !== SERVER_URL_PLACEHOLDER) {
|
||||
throw new Error(`settings URL placeholder: ${settingsUrlPlaceholder}`);
|
||||
}
|
||||
const settingsUrlHelper = await page.evaluate(`(() => {
|
||||
const section = document.querySelector("#settingsServerUrl")?.closest(".settings-section");
|
||||
return section?.querySelector(".settings-helper")?.textContent ?? "";
|
||||
})()`);
|
||||
if (settingsUrlHelper !== SERVER_URL_HELPER) {
|
||||
throw new Error(`settings URL helper: ${settingsUrlHelper}`);
|
||||
}
|
||||
// The connected status card, read from the real pong: Connected + the build
|
||||
// line + the server-time line (not just screenshotted).
|
||||
await eventually(
|
||||
() => page.evaluate(`(() => {
|
||||
const lines = [...document.querySelectorAll(".settings-status .settings-status-line")].map((n) => n.textContent);
|
||||
return lines[0] === "Connected" && lines.some((l) => l.startsWith("Server build ")) && lines.some((l) => l.startsWith("Server time "));
|
||||
})()`),
|
||||
{ timeout: 20000, what: "the connected Settings status card with build and time lines" },
|
||||
);
|
||||
const statusLines = await page.evaluate(
|
||||
`[...document.querySelectorAll(".settings-status .settings-status-line")].map((n) => n.textContent)`,
|
||||
);
|
||||
const trustTitle = await text(".settings-warning .settings-warning-title");
|
||||
const trustBody = await text(".settings-warning .settings-warning-body");
|
||||
if (trustTitle !== TRUST_TITLE || trustBody !== TRUST_BODY) {
|
||||
throw new Error(`trust warning: ${trustTitle} / ${trustBody}`);
|
||||
}
|
||||
console.log(` settings connection card: ${statusLines.join(" | ")}`);
|
||||
await page.evaluate(`window.scrollTo(0, 0)`);
|
||||
await shot("L1-settings-connection.png");
|
||||
|
||||
// F1 (blocking review finding): an invalid URL is reported as the Settings
|
||||
// field's own error (Android's `urlError`) with aria-invalid/aria-describedby,
|
||||
// and is cleared by the next edit — never left as a stale page-level banner.
|
||||
// F2: the header URL field and the Settings field are one draft, mirrored in
|
||||
// place, so they cannot show different endpoints while typing.
|
||||
const goodUrl = await page.evaluate(`document.querySelector("#settingsServerUrl")?.value ?? ""`);
|
||||
await page.fill("#settingsServerUrl", "not a url");
|
||||
await page.click("#settingsSecondary");
|
||||
const urlErrorState = await eventually(
|
||||
() =>
|
||||
page
|
||||
.evaluate(`(() => {
|
||||
const helper = document.querySelector("#settingsUrlHelper");
|
||||
const field = document.querySelector("#settingsServerUrl");
|
||||
return {
|
||||
helper: helper?.textContent ?? "",
|
||||
cls: helper?.className ?? "",
|
||||
invalid: field?.getAttribute("aria-invalid") ?? "",
|
||||
describedby: field?.getAttribute("aria-describedby") ?? "",
|
||||
pageBanner: !!document.querySelector("#content .banner.error"),
|
||||
};
|
||||
})()`)
|
||||
.then((value) => (value.helper === "That is not a valid URL." ? value : false)),
|
||||
{ timeout: 10000, what: "the URL field's own error after an invalid Connect" },
|
||||
);
|
||||
if (urlErrorState.invalid !== "true" || urlErrorState.describedby !== "settingsUrlHelper") {
|
||||
throw new Error(`URL field error is not the field's own state: ${JSON.stringify(urlErrorState)}`);
|
||||
}
|
||||
if (!urlErrorState.cls.includes("settings-helper-error")) {
|
||||
throw new Error(`URL error helper is not error-tinted: ${JSON.stringify(urlErrorState)}`);
|
||||
}
|
||||
if (urlErrorState.pageBanner) {
|
||||
throw new Error("the invalid URL was surfaced as a page-level banner, not the field error");
|
||||
}
|
||||
await page.evaluate(`document.querySelector("#settingsUrlHelper")?.scrollIntoView({ block: "center" })`);
|
||||
await shot("L1-settings-url-error.png");
|
||||
// F1 (blocking review finding): a correction made in the OTHER half of the
|
||||
// mirrored draft must clear the Settings field's own error too. Before this fix,
|
||||
// fixing the URL in the header left the Settings helper saying "That is not a
|
||||
// valid URL." with aria-invalid still true.
|
||||
const headerCorrection = await page.evaluate(`(() => {
|
||||
const header = document.querySelector("#url");
|
||||
header.value = "ws://10.7.7.7:8099/connect";
|
||||
header.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
const settings = document.querySelector("#settingsServerUrl");
|
||||
return {
|
||||
helper: document.querySelector("#settingsUrlHelper")?.textContent ?? "",
|
||||
invalid: settings?.hasAttribute("aria-invalid") ?? null,
|
||||
mirrored: settings?.value ?? "",
|
||||
};
|
||||
})()`);
|
||||
if (headerCorrection.invalid !== false || headerCorrection.helper !== SERVER_URL_HELPER) {
|
||||
throw new Error(
|
||||
`correcting the URL in the header left a stale Settings error: ${JSON.stringify(headerCorrection)}`,
|
||||
);
|
||||
}
|
||||
if (headerCorrection.mirrored !== "ws://10.7.7.7:8099/connect") {
|
||||
throw new Error(`the Settings field did not mirror the header correction: ${JSON.stringify(headerCorrection)}`);
|
||||
}
|
||||
console.log(" a header correction clears the Settings field's error and mirrors the value");
|
||||
// Editing the field (Android's updateServerUrlDraft) clears the error and
|
||||
// restores the helper — and the header field mirrors the Settings value.
|
||||
const syncState = await page.evaluate(`(() => {
|
||||
const settings = document.querySelector("#settingsServerUrl");
|
||||
const header = document.querySelector("#url");
|
||||
settings.value = "ws://10.9.9.9:8099/connect";
|
||||
settings.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
const headerAfterSettings = header.value;
|
||||
header.value = "ws://10.8.8.8:8099/connect";
|
||||
header.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
return {
|
||||
headerAfterSettings,
|
||||
settingsAfterHeader: settings.value,
|
||||
helper: document.querySelector("#settingsUrlHelper")?.textContent ?? "",
|
||||
invalid: document.querySelector("#settingsServerUrl")?.hasAttribute("aria-invalid") ?? null,
|
||||
};
|
||||
})()`);
|
||||
if (syncState.headerAfterSettings !== "ws://10.9.9.9:8099/connect") {
|
||||
throw new Error(`header did not mirror the Settings URL: ${JSON.stringify(syncState)}`);
|
||||
}
|
||||
if (syncState.settingsAfterHeader !== "ws://10.8.8.8:8099/connect") {
|
||||
throw new Error(`Settings did not mirror the header URL: ${JSON.stringify(syncState)}`);
|
||||
}
|
||||
if (syncState.invalid !== false || syncState.helper !== SERVER_URL_HELPER) {
|
||||
throw new Error(`editing the URL did not clear the error: ${JSON.stringify(syncState)}`);
|
||||
}
|
||||
console.log(" invalid URL is the field's own error (aria-invalid, no page banner), cleared on edit; the two URL fields mirror");
|
||||
await page.fill("#settingsServerUrl", goodUrl);
|
||||
|
||||
// The other three status-card states, live: Disconnect drives the page to idle
|
||||
// (`Not connected`, Connect emphasised, Reconnect offered); a bad endpoint
|
||||
// drives it to `Disconnected` with the server's message and the retry suffix.
|
||||
step("capturing the idle and disconnected Settings status card (L1)");
|
||||
await page.click("#settingsPrimary");
|
||||
await eventually(
|
||||
() =>
|
||||
page.evaluate(`(() => {
|
||||
const lines = [...document.querySelectorAll(".settings-status .settings-status-line")].map((n) => n.textContent);
|
||||
return (
|
||||
lines.length === 1 &&
|
||||
lines[0] === "Not connected" &&
|
||||
document.querySelector("#settingsPrimary")?.textContent === "Connect" &&
|
||||
document.querySelector("#settingsSecondary")?.textContent === "Reconnect"
|
||||
);
|
||||
})()`),
|
||||
{ timeout: 15000, what: "the idle Settings card after Disconnect" },
|
||||
);
|
||||
console.log(" settings idle card: Not connected (Connect primary, Reconnect secondary)");
|
||||
await shot("L1-settings-idle.png");
|
||||
|
||||
await page.fill("#settingsServerUrl", `ws://127.0.0.1:${port}/not-a-connect-endpoint`);
|
||||
await page.click("#settingsPrimary");
|
||||
await eventually(
|
||||
() =>
|
||||
page.evaluate(`(() => {
|
||||
const lines = [...document.querySelectorAll(".settings-status .settings-status-line")].map((n) => n.textContent);
|
||||
return (
|
||||
lines[0] === "Disconnected" &&
|
||||
lines.length >= 3 &&
|
||||
lines.includes("Retrying with backoff\\u2026")
|
||||
);
|
||||
})()`),
|
||||
{ timeout: 20000, what: "the disconnected Settings card with its retry suffix" },
|
||||
);
|
||||
const disconnectedLines = await page.evaluate(
|
||||
`[...document.querySelectorAll(".settings-status .settings-status-line")].map((n) => n.textContent)`,
|
||||
);
|
||||
console.log(` settings disconnected card: ${disconnectedLines.join(" | ")}`);
|
||||
await shot("L1-settings-disconnected.png");
|
||||
|
||||
// The fourth state: an endpoint that neither accepts nor refuses (a
|
||||
// non-routable address) leaves the client Connecting, so the attempt number is
|
||||
// visible in the card. Disconnect then ends the attempt before the restore.
|
||||
await page.fill("#settingsServerUrl", `ws://10.255.255.1:${port}/connect`);
|
||||
await page.click("#settingsPrimary");
|
||||
await eventually(
|
||||
() =>
|
||||
page.evaluate(`(() => {
|
||||
const lines = [...document.querySelectorAll(".settings-status .settings-status-line")].map((n) => n.textContent);
|
||||
return lines.length === 1 && /^Connecting \\(attempt \\d+\\)\\u2026$/.test(lines[0]);
|
||||
})()`),
|
||||
{ timeout: 15000, what: "the connecting Settings card with its attempt number" },
|
||||
);
|
||||
const connectingLine = await text(".settings-status .settings-status-line");
|
||||
const connectingSpinner = await page.evaluate(
|
||||
`!!document.querySelector(".settings-status .settings-status-spinner")`,
|
||||
);
|
||||
if (!connectingSpinner) throw new Error("the Connecting card should show the spinner (SettingsScreen.kt)");
|
||||
console.log(` settings connecting card: ${connectingLine}`);
|
||||
await shot("L1-settings-connecting.png");
|
||||
await page.click("#settingsPrimary");
|
||||
|
||||
// Restore the real endpoint (and the persisted server URL) before the
|
||||
// workspace step, so the reload assertion still sees a working configuration.
|
||||
await page.fill("#settingsServerUrl", goodUrl);
|
||||
await page.click("#settingsPrimary");
|
||||
await page.waitForSelector(".conn-banner.conn-ok", { timeout: 25000 });
|
||||
|
||||
step("exercising the Settings workspace field (L1)");
|
||||
const workspacePlaceholder = await page.evaluate(
|
||||
`document.querySelector("#settingsWorkspace")?.placeholder ?? ""`,
|
||||
);
|
||||
if (workspacePlaceholder !== WORKSPACE_PLACEHOLDER) {
|
||||
throw new Error(`workspace placeholder: ${workspacePlaceholder}`);
|
||||
}
|
||||
const blankWorkspaceHelper = await text("#workspaceHelper");
|
||||
if (blankWorkspaceHelper !== WORKSPACE_HELPER) {
|
||||
throw new Error(`workspace helper: ${blankWorkspaceHelper}`);
|
||||
}
|
||||
const blankSaved = await text("#savedWorkspace");
|
||||
if (blankSaved !== "Saved workspace: (none)") throw new Error(`saved line on blank: ${blankSaved}`);
|
||||
const blankSaveDisabled = await page.evaluate(`document.querySelector("#saveWorkspace")?.disabled ?? null`);
|
||||
if (blankSaveDisabled !== true) throw new Error("Save workspace should be disabled while the field is blank");
|
||||
// A relative path keeps Save disabled and names the rule (the helper line).
|
||||
await page.fill("#settingsWorkspace", "repos/pipelines");
|
||||
const relativeSaveDisabled = await page.evaluate(`document.querySelector("#saveWorkspace")?.disabled ?? null`);
|
||||
if (relativeSaveDisabled !== true) throw new Error("Save workspace should stay disabled for a relative path");
|
||||
const relativeHelper = await text("#workspaceHelper");
|
||||
if (relativeHelper !== WORKSPACE_ERROR) throw new Error(`workspace error line: ${relativeHelper}`);
|
||||
// F3 (minor review finding): the workspace error is distinguishable as an error
|
||||
// (error tint + aria-invalid/aria-describedby), mirroring Android's isError.
|
||||
const workspaceErrorState = await page.evaluate(`(() => ({
|
||||
helperClass: document.querySelector("#workspaceHelper")?.className ?? "",
|
||||
invalid: document.querySelector("#settingsWorkspace")?.getAttribute("aria-invalid") ?? "",
|
||||
describedby: document.querySelector("#settingsWorkspace")?.getAttribute("aria-describedby") ?? "",
|
||||
}))()`);
|
||||
if (!workspaceErrorState.helperClass.includes("settings-helper-error")) {
|
||||
throw new Error(`workspace helper is not error-tinted: ${JSON.stringify(workspaceErrorState)}`);
|
||||
}
|
||||
if (workspaceErrorState.invalid !== "true" || workspaceErrorState.describedby !== "workspaceHelper") {
|
||||
throw new Error(`workspace field is not marked invalid: ${JSON.stringify(workspaceErrorState)}`);
|
||||
}
|
||||
await page.evaluate(`document.querySelector("#workspaceHelper")?.scrollIntoView({ block: "center" })`);
|
||||
await shot("L1-settings-workspace-error.png");
|
||||
// An absolute path (padded with spaces) enables Save; saving stores the trimmed value.
|
||||
await page.fill("#settingsWorkspace", " /Users/alan/repos/pipelines ");
|
||||
const absoluteSaveEnabled = await page.evaluate(`document.querySelector("#saveWorkspace")?.disabled === false`);
|
||||
if (!absoluteSaveEnabled) throw new Error("Save workspace should be enabled for an absolute path");
|
||||
const workspaceValidState = await page.evaluate(`(() => ({
|
||||
helperClass: document.querySelector("#workspaceHelper")?.className ?? "",
|
||||
invalid: document.querySelector("#settingsWorkspace")?.hasAttribute("aria-invalid") ?? null,
|
||||
}))()`);
|
||||
if (workspaceValidState.invalid !== false || workspaceValidState.helperClass.includes("settings-helper-error")) {
|
||||
throw new Error(`the workspace error did not clear for a valid path: ${JSON.stringify(workspaceValidState)}`);
|
||||
}
|
||||
console.log(" workspace error is error-tinted with aria-invalid; a valid path clears it");
|
||||
const keysBeforeSave = await page.evaluate(`Object.keys(localStorage)`);
|
||||
await page.click("#saveWorkspace");
|
||||
const savedLine = await text("#savedWorkspace");
|
||||
if (savedLine !== "Saved workspace: /Users/alan/repos/pipelines") {
|
||||
throw new Error(`saved line: ${savedLine}`);
|
||||
}
|
||||
const storedWorkspace = await page.evaluate(`localStorage.getItem(${JSON.stringify(WORKSPACE_STORAGE_KEY)})`);
|
||||
if (storedWorkspace !== "/Users/alan/repos/pipelines") throw new Error(`stored workspace: ${storedWorkspace}`);
|
||||
// Saving the workspace writes exactly that one key, and no credential-like key
|
||||
// is ever stored (the server has no authentication).
|
||||
const keysAfterSave = await page.evaluate(`Object.keys(localStorage)`);
|
||||
const addedKeys = keysAfterSave.filter((key) => !keysBeforeSave.includes(key));
|
||||
if (addedKeys.length !== 1 || addedKeys[0] !== WORKSPACE_STORAGE_KEY) {
|
||||
throw new Error(`workspace save wrote unexpected key(s): ${JSON.stringify(addedKeys)}`);
|
||||
}
|
||||
const credentialKey = await page.evaluate(
|
||||
`Object.keys(localStorage).find((k) => /credential|token|secret|password/i.test(k)) ?? null`,
|
||||
);
|
||||
if (credentialKey) throw new Error(`a credential-like key was stored: ${credentialKey}`);
|
||||
// No second copy of either setting under another name: every settings-shaped
|
||||
// key in localStorage is exactly one of the two documented keys.
|
||||
const settingsKeys = await page.evaluate(
|
||||
`Object.keys(localStorage).filter((k) => /settings|serverurl|workspace/i.test(k)).sort()`,
|
||||
);
|
||||
if (
|
||||
settingsKeys.length !== 2 ||
|
||||
!settingsKeys.includes(WORKSPACE_STORAGE_KEY) ||
|
||||
!settingsKeys.includes(SERVER_URL_STORAGE_KEY)
|
||||
) {
|
||||
throw new Error(`unexpected settings keys: ${JSON.stringify(settingsKeys)}`);
|
||||
}
|
||||
const storedUrl = await page.evaluate(`localStorage.getItem(${JSON.stringify(SERVER_URL_STORAGE_KEY)})`);
|
||||
if (storedUrl !== storedUrl.trim() || !storedUrl.startsWith("ws://")) {
|
||||
throw new Error(`stored server URL is not the trimmed endpoint: ${storedUrl}`);
|
||||
}
|
||||
console.log(` settings keys: ${settingsKeys.join(", ")} (server URL ${storedUrl})`);
|
||||
console.log(` settings workspace saved (trimmed): ${savedLine}`);
|
||||
await shot("L1-settings-workspace.png");
|
||||
|
||||
step("asserting the Settings Templates card (L1)");
|
||||
const templatesCardLabel = await text("#browseTemplates .card-name");
|
||||
const templatesCardSecondary = await text("#browseTemplates .card-desc");
|
||||
if (templatesCardLabel !== TEMPLATES_CARD_LABEL || templatesCardSecondary !== TEMPLATES_CARD_SECONDARY) {
|
||||
throw new Error(`templates card: ${templatesCardLabel} / ${templatesCardSecondary}`);
|
||||
}
|
||||
// The card opens the existing Templates gallery (same destination as the tab).
|
||||
// The capture is taken after the click, so it is independent evidence of the
|
||||
// entry actually working rather than a duplicate of the Workspace frame (the
|
||||
// page is shorter than the viewport, so the card is already visible there).
|
||||
await page.click("#browseTemplates");
|
||||
await page.waitForSelector(".gallery .pane-head h2", { timeout: 20000 });
|
||||
const galleryTitle = await text(".gallery .pane-head h2");
|
||||
if (galleryTitle !== "Templates") throw new Error(`templates gallery title: ${galleryTitle}`);
|
||||
await shot("L1-settings-templates.png");
|
||||
console.log(" Browse templates opened the existing Templates gallery");
|
||||
|
||||
step("reloading to prove the two settings keys restore (L1)");
|
||||
const persisted = await page.evaluate(`({
|
||||
serverUrl: localStorage.getItem(${JSON.stringify(SERVER_URL_STORAGE_KEY)}),
|
||||
workspace: localStorage.getItem(${JSON.stringify(WORKSPACE_STORAGE_KEY)}),
|
||||
})`);
|
||||
if (persisted.workspace !== "/Users/alan/repos/pipelines") {
|
||||
throw new Error(`persisted workspace: ${persisted.workspace}`);
|
||||
}
|
||||
if (!persisted.serverUrl || !persisted.serverUrl.startsWith("ws://")) {
|
||||
throw new Error(`persisted server URL: ${persisted.serverUrl}`);
|
||||
}
|
||||
await page.evaluate(`location.reload()`);
|
||||
await page.waitForSelector("#url", { timeout: 15000 });
|
||||
const restoredUrl = await page.evaluate(`document.querySelector("#url")?.value ?? ""`);
|
||||
if (restoredUrl !== persisted.serverUrl) throw new Error(`restored server URL: ${restoredUrl}`);
|
||||
await page.clickText("nav.tabs button.tab", "Settings");
|
||||
await page.waitForSelector("#settingsWorkspace", { timeout: 15000 });
|
||||
const restoredWorkspace = await page.evaluate(`document.querySelector("#settingsWorkspace")?.value ?? ""`);
|
||||
if (restoredWorkspace !== "/Users/alan/repos/pipelines") {
|
||||
throw new Error(`restored workspace: ${restoredWorkspace}`);
|
||||
}
|
||||
const restoredSaved = await text("#savedWorkspace");
|
||||
if (restoredSaved !== "Saved workspace: /Users/alan/repos/pipelines") {
|
||||
throw new Error(`restored saved line: ${restoredSaved}`);
|
||||
}
|
||||
console.log(` reload restored url=${restoredUrl} workspace=${restoredWorkspace}`);
|
||||
|
||||
console.log("\nUI SMOKE PASS");
|
||||
for (const shot of shots) console.log(` ${shot}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user