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:
@@ -182,3 +182,26 @@ test("disconnect goes idle and does not schedule a reconnect", () => {
|
||||
assert.equal(client.state.retrying, false);
|
||||
assert.deepEqual(ws.closed, { code: 1000, reason: "client closing" });
|
||||
});
|
||||
|
||||
test("connecting again replaces the socket and ignores the superseded one", async () => {
|
||||
// The Settings `Connect` action is connect-only and must be safe to press while
|
||||
// connected: it re-opens the endpoint (Android's connectLocked replaces the
|
||||
// socket) instead of leaving two live sockets or letting the old one's late
|
||||
// close mark the new connection disconnected.
|
||||
const { client, ws } = connectedClient();
|
||||
const pending = client.call({ type: "ping" }); // sent on the old socket
|
||||
await flush();
|
||||
client.connect(VALID);
|
||||
const replacement = FakeWebSocket.instances.at(-1);
|
||||
assert.notEqual(replacement, ws);
|
||||
assert.equal(client.state.kind, "connecting");
|
||||
await assert.rejects(() => pending, /Connection replaced/);
|
||||
assert.deepEqual(ws.closed, { code: 1000, reason: "superseded" });
|
||||
|
||||
replacement.open();
|
||||
assert.equal(client.state.kind, "connected");
|
||||
// The superseded socket's late failure must not touch the live connection.
|
||||
ws.drop(1006);
|
||||
assert.equal(client.state.kind, "connected");
|
||||
assert.equal(client.state.retrying, false);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,357 @@
|
||||
// Unit tests for the Settings destination's pure logic (src/settings.js): the
|
||||
// workspace validation rules, the Save-enabled rule, the `Saved workspace:` line,
|
||||
// the connection status card's four states and the two persisted keys. No DOM, no
|
||||
// socket: `node --test test/settings.test.mjs` proves the logic the page wires up,
|
||||
// so the browser run only has to prove the rendering.
|
||||
//
|
||||
// The wording is asserted against the Android client's own strings
|
||||
// (ui/screens/SettingsScreen.kt, ui/AppViewModel.kt, data/SettingsRepository.kt);
|
||||
// the last test reads those sources so a rename there cannot silently drift past
|
||||
// this one.
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { dirname, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
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,
|
||||
canSaveWorkspace,
|
||||
connectionActionKind,
|
||||
connectionActions,
|
||||
connectionCard,
|
||||
readServerUrl,
|
||||
readWorkspace,
|
||||
savedWorkspaceLine,
|
||||
validateWorkspacePath,
|
||||
workspaceErrorText,
|
||||
writeServerUrl,
|
||||
writeWorkspace,
|
||||
} from "../src/settings.js";
|
||||
import { bannerState, connectingLabel } from "../src/connection.js";
|
||||
|
||||
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..", "..");
|
||||
const source = (rel) => readFileSync(resolve(ROOT, rel), "utf8");
|
||||
const androidSrc = (rel) => source(`android/app/src/main/java/net/awan/pipelines/${rel}`);
|
||||
|
||||
/** A minimal in-memory Storage, plus a throwing one, for the persistence tests. */
|
||||
function memoryStorage(seed = {}) {
|
||||
const map = new Map(Object.entries(seed));
|
||||
return {
|
||||
getItem: (key) => (map.has(key) ? map.get(key) : null),
|
||||
setItem: (key, value) => map.set(key, String(value)),
|
||||
key: (i) => [...map.keys()][i] ?? null,
|
||||
get length() {
|
||||
return map.size;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// The exact copy constants
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test("the settings copy is the Android strings verbatim", () => {
|
||||
assert.equal(SERVER_URL_PLACEHOLDER, "ws://192.168.1.20:8081/connect");
|
||||
assert.equal(
|
||||
SERVER_URL_HELPER,
|
||||
"ws:// on a trusted LAN/VPN, or wss:// through a proxy/VPN. No authentication is used.",
|
||||
);
|
||||
assert.equal(WORKSPACE_PLACEHOLDER, "/Users/you/repos/pipelines");
|
||||
assert.equal(
|
||||
WORKSPACE_HELPER,
|
||||
"An absolute directory that already exists on the execution server. For Docker, " +
|
||||
"mount the host directory at the same absolute path with its owner's UID/GID. " +
|
||||
"This is not the phone's storage.",
|
||||
);
|
||||
assert.equal(
|
||||
WORKSPACE_ERROR,
|
||||
"The workspace must be an absolute path that exists on the execution server.",
|
||||
);
|
||||
assert.equal(TRUST_TITLE, "Trusted LAN/VPN only");
|
||||
assert.equal(
|
||||
TRUST_BODY,
|
||||
"The Pipelines API has no authentication and is not internet-safe. Do not " +
|
||||
"expose it to untrusted networks, and never enter provider credentials here \u2014 " +
|
||||
"the app stores none.",
|
||||
);
|
||||
assert.equal(TEMPLATES_CARD_LABEL, "Browse templates");
|
||||
assert.equal(TEMPLATES_CARD_SECONDARY, "Reusable pipeline definitions offered by the server.");
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// validateWorkspacePath / workspaceErrorText — AppViewModel.validateWorkspace
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test("validateWorkspacePath accepts a blank draft and an absolute path", () => {
|
||||
assert.equal(validateWorkspacePath(""), null);
|
||||
assert.equal(validateWorkspacePath(" "), null);
|
||||
assert.equal(validateWorkspacePath(undefined), null);
|
||||
assert.equal(validateWorkspacePath(null), null);
|
||||
assert.equal(validateWorkspacePath("/Users/you/repos/pipelines"), null);
|
||||
assert.equal(validateWorkspacePath(" /srv/pipelines "), null);
|
||||
});
|
||||
|
||||
test("validateWorkspacePath names the failure for a relative or bare path", () => {
|
||||
assert.equal(validateWorkspacePath("repos/pipelines"), WORKSPACE_ERROR);
|
||||
assert.equal(validateWorkspacePath("~/pipelines"), WORKSPACE_ERROR);
|
||||
assert.equal(validateWorkspacePath("C:\\pipelines"), WORKSPACE_ERROR);
|
||||
assert.equal(validateWorkspacePath(" relative "), WORKSPACE_ERROR);
|
||||
});
|
||||
|
||||
test("workspaceErrorText is the error or empty (Android's `workspaceError ?: helper`)", () => {
|
||||
assert.equal(workspaceErrorText("repos/pipelines"), WORKSPACE_ERROR);
|
||||
assert.equal(workspaceErrorText(""), "");
|
||||
assert.equal(workspaceErrorText("/srv/pipelines"), "");
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// canSaveWorkspace — the Save button's enabled state
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test("canSaveWorkspace enables Save only for a trimmed absolute path", () => {
|
||||
assert.equal(canSaveWorkspace("/srv/pipelines"), true);
|
||||
assert.equal(canSaveWorkspace(" /srv/pipelines "), true);
|
||||
// Deliberately stricter than Android (which also enables Save on a blank
|
||||
// field): the browser has nothing to save for a blank path.
|
||||
assert.equal(canSaveWorkspace(""), false);
|
||||
assert.equal(canSaveWorkspace(" "), false);
|
||||
assert.equal(canSaveWorkspace("repos/pipelines"), false);
|
||||
assert.equal(canSaveWorkspace(undefined), false);
|
||||
});
|
||||
|
||||
test("canSaveWorkspace derives from validateWorkspacePath, so the rule has one source", () => {
|
||||
for (const value of ["", " ", "repos/pipelines", "~/x", "C:\\x", "/srv/x", " /srv/x ", "/", "/a/b"]) {
|
||||
const trimmed = String(value).trim();
|
||||
assert.equal(
|
||||
canSaveWorkspace(value),
|
||||
trimmed !== "" && validateWorkspacePath(value) === null,
|
||||
`disagreement for ${JSON.stringify(value)}`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// savedWorkspaceLine
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test("savedWorkspaceLine reads the path, or (none) when unset", () => {
|
||||
assert.equal(savedWorkspaceLine("/Users/you/repos/pipelines"), "Saved workspace: /Users/you/repos/pipelines");
|
||||
assert.equal(savedWorkspaceLine(" /srv/x "), "Saved workspace: /srv/x");
|
||||
assert.equal(savedWorkspaceLine(""), "Saved workspace: (none)");
|
||||
assert.equal(savedWorkspaceLine(" "), "Saved workspace: (none)");
|
||||
assert.equal(savedWorkspaceLine(null), "Saved workspace: (none)");
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// connectionCard — SettingsScreen.kt's ConnectionStatusCard
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test("connectionCard idle reads Not connected", () => {
|
||||
assert.deepEqual(connectionCard({ kind: "idle" }), ["Not connected"]);
|
||||
assert.deepEqual(connectionCard(undefined), ["Not connected"]);
|
||||
assert.deepEqual(connectionCard({ kind: "something-else" }), ["Not connected"]);
|
||||
});
|
||||
|
||||
test("connectionCard connecting names the attempt", () => {
|
||||
assert.deepEqual(connectionCard({ kind: "connecting", attempt: 4 }), ["Connecting (attempt 4)\u2026"]);
|
||||
assert.deepEqual(connectionCard({ kind: "connecting" }), ["Connecting (attempt 0)\u2026"]);
|
||||
});
|
||||
|
||||
test("the connecting line is the banner's own, so the app sentence has one source", () => {
|
||||
for (const attempt of [0, 1, 7]) {
|
||||
const state = { kind: "connecting", attempt };
|
||||
assert.deepEqual(connectionCard(state), [bannerState(state).text]);
|
||||
}
|
||||
assert.equal(connectingLabel(3), "Connecting (attempt 3)\u2026");
|
||||
});
|
||||
|
||||
test("connectionCard connected shows the build and server time when present", () => {
|
||||
assert.deepEqual(
|
||||
connectionCard(
|
||||
{ kind: "connected" },
|
||||
{ version: "v1.2.3", commit: "abc123", serverTime: "2026-10-19T08:00:00Z" },
|
||||
),
|
||||
["Connected", "Server build v1.2.3 (abc123)", "Server time 2026-10-19T08:00:00Z"],
|
||||
);
|
||||
// Missing fields are tolerated: no build line, no time line.
|
||||
assert.deepEqual(connectionCard({ kind: "connected" }, {}), ["Connected"]);
|
||||
assert.deepEqual(connectionCard({ kind: "connected" }, { version: "v1", serverTime: " " }), [
|
||||
"Connected",
|
||||
"Server build v1",
|
||||
]);
|
||||
});
|
||||
|
||||
test("connectionCard disconnected carries the reason and the retry suffix", () => {
|
||||
assert.deepEqual(
|
||||
connectionCard({ kind: "disconnected", reason: "Connection closed (1006)", retrying: true }),
|
||||
["Disconnected", "Connection closed (1006)", "Retrying with backoff\u2026"],
|
||||
);
|
||||
assert.deepEqual(
|
||||
connectionCard({ kind: "disconnected", reason: "Connection closed (1000)", retrying: false }),
|
||||
["Disconnected", "Connection closed (1000)"],
|
||||
);
|
||||
// A blank reason renders no empty line; retrying alone still shows.
|
||||
assert.deepEqual(connectionCard({ kind: "disconnected", reason: " ", retrying: true }), [
|
||||
"Disconnected",
|
||||
"Retrying with backoff\u2026",
|
||||
]);
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// connectionActions — SettingsScreen.kt's `active` branch
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test("connectionActions emphasises Disconnect while connected or connecting", () => {
|
||||
assert.deepEqual(connectionActions({ kind: "connected" }), { primary: "Disconnect", secondary: "Connect" });
|
||||
assert.deepEqual(connectionActions({ kind: "connecting", attempt: 2 }), {
|
||||
primary: "Disconnect",
|
||||
secondary: "Connect",
|
||||
});
|
||||
});
|
||||
|
||||
test("connectionActions emphasises Connect and offers Reconnect otherwise", () => {
|
||||
assert.deepEqual(connectionActions({ kind: "idle" }), { primary: "Connect", secondary: "Reconnect" });
|
||||
assert.deepEqual(connectionActions({ kind: "disconnected", reason: "x" }), {
|
||||
primary: "Connect",
|
||||
secondary: "Reconnect",
|
||||
});
|
||||
assert.deepEqual(connectionActions(undefined), { primary: "Connect", secondary: "Reconnect" });
|
||||
});
|
||||
|
||||
test("connectionActionKind keeps Connect connect-only (never the header's toggle)", () => {
|
||||
// Android's connect() validates + persists + opens; only disconnect() closes.
|
||||
assert.equal(connectionActionKind("Connect"), "connect");
|
||||
assert.equal(connectionActionKind("Reconnect"), "reconnect");
|
||||
assert.equal(connectionActionKind("Disconnect"), "disconnect");
|
||||
// Any unknown label is treated as a connect, never as a disconnect.
|
||||
assert.equal(connectionActionKind(""), "connect");
|
||||
assert.equal(connectionActionKind(undefined), "connect");
|
||||
for (const state of [{ kind: "connected" }, { kind: "connecting" }, { kind: "idle" }]) {
|
||||
const { primary, secondary } = connectionActions(state);
|
||||
const kinds = [connectionActionKind(primary), connectionActionKind(secondary)];
|
||||
assert.deepEqual(kinds, state.kind === "idle" ? ["connect", "reconnect"] : ["disconnect", "connect"]);
|
||||
}
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Persisted keys round-trip
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test("the two persisted keys are the exact, stable localStorage keys", () => {
|
||||
assert.equal(SERVER_URL_STORAGE_KEY, "pipelines.web.serverUrl.v2");
|
||||
assert.equal(WORKSPACE_STORAGE_KEY, "pipelines.web.workspace.v1");
|
||||
});
|
||||
|
||||
test("writeWorkspace trims and reads back; readWorkspace is tolerant", () => {
|
||||
const storage = memoryStorage();
|
||||
assert.equal(writeWorkspace(storage, " /srv/pipelines "), "/srv/pipelines");
|
||||
assert.equal(storage.getItem(WORKSPACE_STORAGE_KEY), "/srv/pipelines");
|
||||
assert.equal(storage.length, 1, "only the workspace key is written");
|
||||
assert.equal(readWorkspace(storage), "/srv/pipelines");
|
||||
|
||||
// Blank reads back as "" (the stored value), never throwing.
|
||||
writeWorkspace(storage, " ");
|
||||
assert.equal(readWorkspace(storage), "");
|
||||
assert.equal(storage.length, 1);
|
||||
});
|
||||
|
||||
test("the server-URL key round-trips trimmed, under its own key only", () => {
|
||||
const storage = memoryStorage();
|
||||
assert.equal(writeServerUrl(storage, " ws://127.0.0.1:8080/connect "), "ws://127.0.0.1:8080/connect");
|
||||
assert.equal(storage.getItem(SERVER_URL_STORAGE_KEY), "ws://127.0.0.1:8080/connect");
|
||||
assert.equal(readServerUrl(storage), "ws://127.0.0.1:8080/connect");
|
||||
assert.equal(storage.length, 1, "only the server-URL key is written");
|
||||
// The two keys are independent: writing one never disturbs the other.
|
||||
writeWorkspace(storage, "/srv/pipelines");
|
||||
assert.equal(storage.length, 2);
|
||||
assert.equal(readServerUrl(storage), "ws://127.0.0.1:8080/connect");
|
||||
assert.equal(readWorkspace(storage), "/srv/pipelines");
|
||||
});
|
||||
|
||||
test("readServerUrl is blank on a missing/unreadable storage and never throws", () => {
|
||||
assert.equal(readServerUrl(memoryStorage()), "");
|
||||
assert.equal(readServerUrl(undefined), "");
|
||||
assert.equal(readServerUrl(null), "");
|
||||
const throwing = {
|
||||
getItem() {
|
||||
throw new Error("denied");
|
||||
},
|
||||
setItem() {
|
||||
throw new Error("denied");
|
||||
},
|
||||
};
|
||||
assert.equal(readServerUrl(throwing), "");
|
||||
assert.equal(writeServerUrl(throwing, " ws://host:1/connect "), "ws://host:1/connect");
|
||||
});
|
||||
|
||||
test("readWorkspace is blank on a missing/unreadable storage and never throws", () => {
|
||||
assert.equal(readWorkspace(memoryStorage()), "");
|
||||
assert.equal(readWorkspace(undefined), "");
|
||||
assert.equal(readWorkspace(null), "");
|
||||
const throwing = {
|
||||
getItem() {
|
||||
throw new Error("denied");
|
||||
},
|
||||
setItem() {
|
||||
throw new Error("denied");
|
||||
},
|
||||
};
|
||||
assert.equal(readWorkspace(throwing), "");
|
||||
assert.equal(writeWorkspace(throwing, "/srv/x"), "/srv/x");
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Parity with the Android sources
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test("the wording still matches the Android client's sources", () => {
|
||||
const settings = androidSrc("ui/screens/SettingsScreen.kt");
|
||||
for (const line of [
|
||||
'Text("Connection"',
|
||||
'Text("Server URL")',
|
||||
'Text("ws://192.168.1.20:8081/connect")',
|
||||
"ws:// on a trusted LAN/VPN, or wss:// through a proxy/VPN. No authentication is used.",
|
||||
'Text("Workspace"',
|
||||
'Text("Workspace path (on the server)")',
|
||||
'Text("/Users/you/repos/pipelines")',
|
||||
"An absolute directory that already exists on the execution server. For Docker, ",
|
||||
"This is not the phone's storage.",
|
||||
'Text("Save workspace")',
|
||||
'"Trusted LAN/VPN only"',
|
||||
"The Pipelines API has no authentication and is not internet-safe. Do not ",
|
||||
"never enter provider credentials here \\u2014 ",
|
||||
'Text("Browse templates"',
|
||||
"Reusable pipeline definitions offered by the server.",
|
||||
'Text("Disconnected"',
|
||||
'Text("Retrying with backoff\\u2026")',
|
||||
'Text("Connecting (attempt ${state.attempt})\\u2026")',
|
||||
'Text("Connected"',
|
||||
]) {
|
||||
assert.ok(settings.includes(line), `SettingsScreen.kt is missing: ${line}`);
|
||||
}
|
||||
|
||||
const vm = androidSrc("ui/AppViewModel.kt");
|
||||
assert.ok(
|
||||
vm.includes("The workspace must be an absolute path that exists on the execution server."),
|
||||
"AppViewModel.kt workspace error",
|
||||
);
|
||||
assert.ok(vm.includes("!trimmed.startsWith(\"/\")"), "AppViewModel.kt absolute-path rule");
|
||||
|
||||
// The two Android preference keys the browser analogues stand in for.
|
||||
const repo = androidSrc("data/SettingsRepository.kt");
|
||||
assert.ok(repo.includes('const val KEY_SERVER_URL = "server_url"'), "KEY_SERVER_URL");
|
||||
assert.ok(repo.includes('const val KEY_WORKSPACE = "workspace"'), "KEY_WORKSPACE");
|
||||
// Only non-secret preferences are stored (no credentials).
|
||||
assert.ok(repo.includes("No credentials or tokens are ever stored"), "no-secrets note");
|
||||
});
|
||||
+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