Trim comments and docs to what the code needs

AI Assisted
This commit is contained in:
Seth committed 2026-12-05 13:19:59 -08:00
1 parent eba3c3bf0c
commit 0bd721fc27
33 files changed
+292 -392

No files matched your search

+1 -1
View File
@@ -1416,7 +1416,7 @@ test("clipboardAction on a Mac: Ctrl+V goes to the agent, Cmd+V is left to the w
});
test("clipboardAction off a Mac: every key decides exactly as before the Mac rule", () => {
// The rule as it was before Ctrl+V was left to the agent on a Mac.
// The rule without its Mac branch, written out on its own.
const before = (event, hasSelection) => {
if (event.altKey) return null;
const key = event.key.toLowerCase();
+4 -6
View File
@@ -2,10 +2,8 @@
// macOS smoke run starts in place of a real agent CLI. Run with:
// node --test scripts/test-app-smoke-agent.mjs
//
// The stand-in has one job: open a real web console the way an agent would,
// so the app's dashboard frame has something to connect to. This runs it
// outside the app, under a throwaway console home, and checks a live session
// appears and the stand-in ends when its input closes.
// Runs it outside the app, under a throwaway console home, and checks a live
// session appears and the stand-in ends when its input closes.
import test from "node:test";
import assert from "node:assert/strict";
@@ -19,8 +17,8 @@ const HERE = path.dirname(fileURLToPath(import.meta.url));
const AGENT = path.join(HERE, "../plan2code-app/scripts/smoke-agent.mjs");
const CONSOLE_DIR = path.join(HERE, "../src/web-console");
// The desktop app's own variables would have the console announce itself to
// a live window. Deleted from the spawned environment, never inherited.
// The desktop app's own variables, removed so the console does not announce
// itself to a live window.
const APP_VARS = ["PLAN2CODE_IN_APP", "PLAN2CODE_APP_TOKEN", "PLAN2CODE_APP_VERSION", "PLAN2CODE_APP_ANNOUNCE", "PLAN2CODE_EMBED_ORIGIN", "PLAN2CODE_CONSOLE_SID"];
function outsideAppEnv(extra) {
+2 -3
View File
@@ -99,9 +99,8 @@ test("smoke frame: refuses to run with no console home", async () => {
});
test("smoke frame: the CI step keeps the console from opening a browser, so only the frame can count", () => {
// Inside the app the console opens no browser of its own. If the app's signal
// to it were lost, `open` would start the runner's browser, which signs in by
// cookie and would pass this check with the frame dead.
// Without it, a lost in-app signal would let `open` start the runner's
// browser, which signs in by cookie and passes the check with the frame dead.
const workflow = fs.readFileSync(path.join(HERE, "../.github/workflows/app.yml"), "utf8");
const start = workflow.indexOf("- name: Smoke-test the dashboard frame connects (macOS)");
assert.ok(start >= 0, "the frame step is there");
+5 -8
View File
@@ -20,9 +20,8 @@ const SERVER_JS = path.join(ROOT, "src", "web-console", "server.mjs");
// Boot a session server whose environment carries PLAN2CODE_EMBED_ORIGIN set
// to `origin` (or does not carry it at all when origin is undefined). Returns
// the child and its base URL; the caller always kills the child. `platform`
// fakes process.platform in the server before it loads (the whole server
// sees it, not only frameKey()), so the macOS-only frame sign-in is tested on
// every OS. `state` adds fields to state.json.
// fakes process.platform for the whole server, so the macOS-only frame sign-in
// is tested on every OS. `state` adds fields to state.json.
async function bootServer(origin, { platform, token = "t", state = {} } = {}) {
const dir = fs.mkdtempSync(path.join(HOME, "embed-"));
fs.writeFileSync(path.join(dir, "state.json"), JSON.stringify({ sid: path.basename(dir), phase: "collecting", ...state }));
@@ -148,8 +147,7 @@ function raw(port, urlPath, { method = "GET", headers = {}, body, head = false }
});
}
// The frame's key: a hash of the token, so the token the terminal prints
// never sits in the frame's address, and still 128 bits.
// The frame's key, as routes.mjs makes it from the token.
const frameKey = (token) => crypto.createHash("sha256").update(token).digest("hex").slice(0, 32);
// A real token's shape: 16 random bytes in base64url, uppercase included.
@@ -287,7 +285,7 @@ test("a browser tab on the macOS app's console keeps the cookie and `/`", async
assert.equal(signIn.status, 302);
assert.equal(signIn.headers.location, "/");
// The tauri://localhost cookie (cookieSameSite): Lax, never Secure,
// since Safari drops a Secure cookie on plain http.
// since WebKit drops a Secure cookie on plain http.
assert.match(String(signIn.headers["set-cookie"]), /HttpOnly; SameSite=Lax;/);
assert.doesNotMatch(String(signIn.headers["set-cookie"]), /Secure/);
const cookie = cookieFor(`http://127.0.0.1:${port}`, MIXED_TOKEN);
@@ -327,8 +325,7 @@ test("the frame prefix is off everywhere but the macOS app, where `/f/` is just
test("the page-closed signal is a keepalive fetch, which carries the page's origin, not a beacon", () => {
// A body-less sendBeacon is a no-cors POST: under the console's
// `referrer-policy: no-referrer` it goes out with `Origin: null`, which /bye's
// origin check refuses (WebKit showed it; the Fetch standard says every engine
// does the same). A keepalive fetch is a cors request and sends the real origin.
// origin check refuses. A keepalive fetch is a cors request and sends the real origin.
const core = fs.readFileSync(path.join(ROOT, "src", "web-console", "public", "screens", "core.js"), "utf8");
const wire = core.slice(core.indexOf("export function wireChrome()"));
const pagehide = wire.slice(0, wire.indexOf("});"));
+4 -5
View File
@@ -2355,8 +2355,8 @@ test("picker: the workspace picker cannot drift from the launcher's", () => {
});
test("picker: the launcher and the workspace read a picker's exit the same way", () => {
// Two copies of one rule (macOS: only osascript's (-128) is a cancel), each
// with its own tests: this keeps an edit to one from leaving the other behind.
// One rule in two places (macOS: only osascript's (-128) is a cancel); this
// keeps an edit to one from leaving the other behind.
const { pickerCancelled } = createRequire(import.meta.url)(path.join(ROOT, "src", "launcher", "plan2code.js"));
const errors = ["", "0:17: execution error: User canceled. (-128)", "execution error: Not authorized to send Apple events. (-1743)", "(-1280)", "Gtk-WARNING\n"];
for (const platform of ["darwin", "linux", "win32"]) {
@@ -2405,7 +2405,7 @@ function fakeSpawn(code, output, errorText = "", platform = process.platform) {
}
// What osascript prints on a cancel, and on a failure (a bad script here; a
// missing default folder or a refused permission end the same way, exit 1).
// missing default folder or a refused permission also exit 1).
const MAC_CANCEL = "0:17: execution error: User canceled. (-128)\n";
const MAC_FAILURE = "0:4: execution error: The variable this is not defined. (-2753)\n";
@@ -2786,8 +2786,7 @@ test("initialWorkspace names the original folder after itself and marks it origi
assert.deepEqual([ws.missing, ws.changes, ws.remote], [[], [], ""]);
});
// Browse... opens beside the last folder added. When that folder is gone, a missing
// start must not read as "Browse is not available here".
// A start deleted on disk must not read as "Browse is not available here".
test("pickerStart opens beside the last folder added, or at its nearest folder still on disk", () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-picker-start-"));
try {
+10 -15
View File
@@ -1,10 +1,8 @@
// Web console page tests: the page as the macOS app's frame has it. WebKit
// gives that frame no cookie, so the console signs it in by a path prefix
// (`/f/<key>/`, routes.mjs) and the page runs under it. Every request the page
// makes there must stay under the prefix: one that leaves it gets a 403, and
// only in the macOS app. This file opens the page that way in a browser
// context with no cookie, uses the parts that fetch, and fails on any request
// that left the prefix or was refused. Run with:
// Web console page tests: the page as the macOS app's frame has it, signed in
// by the path prefix `/f/<key>/` (routes.mjs) with no cookie. A request that
// leaves the prefix gets a 403, and only in the macOS app. This opens the page
// that way, uses the parts that fetch, and fails on any request that left the
// prefix or was refused. Run with:
// node --test scripts/test-web-console-page-frame.mjs
import crypto from "node:crypto";
@@ -20,11 +18,9 @@ const suite = pageSuite(test);
const LOOKS_FILE = path.join(HOME, "looks.json");
// The server takes the app's frame mode only on macOS, with the app's page as
// the embed ancestor. On any other OS this makes the server alone believe it
// runs on macOS (the CLI that starts it is left as it is), so CI's Linux run
// checks the same thing. The whole server sees darwin, not only frameKey():
// every macOS branch in it runs here too.
// Frame mode needs macOS and the app's page as the embed ancestor. This makes
// only the server (not the CLI that starts it) see darwin, so CI's Linux run
// checks it too; every macOS branch in the server runs, not only frameKey().
const FAKE_MAC =
"data:text/javascript," +
encodeURIComponent('if (/server\\.mjs$/.test(process.argv[1] || "")) Object.defineProperty(process, "platform", { value: "darwin" });');
@@ -76,9 +72,8 @@ test("under the frame's prefix, with no cookie, the dashboard draws, its stream
await until(() => streamed, 10000);
assert.ok(streamed, "the event stream connected under the prefix");
// A step that waits on a request the server refused times out; the
// requests that left the prefix or were refused are the reason, so they
// are reported first.
// A step waiting on a refused request times out; the finally block reports
// the requests that left the prefix or were refused instead, as the cause.
try {
// The Notebook: its tab list and note come from the server.
await page.click("#btn-notepad");
+1 -1
View File
@@ -934,7 +934,7 @@ test("with the Narrow card width in a wide window, no Appearance choice overflow
await s.page.waitForFunction((w) => (document.documentElement.getAttribute("data-width") ?? "comfortable") === w, width);
assert.deepEqual(await crampedChoices(s), [], width);
}
// A small window still stacks the choices in one column, as before.
// A small window still stacks the choices in one column.
await s.page.setViewportSize({ width: 600, height: 800 });
await s.page.waitForFunction(() => getComputedStyle(document.querySelector("#prefs-panel-appearance .looks-row.four")).gridTemplateColumns.split(" ").length === 1);
});
+14 -19
View File
@@ -1,10 +1,8 @@
// Web console tests, the page's URLs: every URL the page uses is page-relative.
// The macOS app's frame gets no cookie, so it signs in by a path prefix
// (`/f/<key>/`, routes.mjs) and the page is served under it there, while a
// browser tab has it at `/`. A relative `state` reaches the server either
// way; a slash-leading `/state` drops the prefix and gets a 403, in the macOS
// app only, so no other test would notice. This guard reads the page's source
// (and the links the server hands it) and names each slash-leading one.
// The macOS app's frame signs in by a path prefix (`/f/<key>/`, routes.mjs) and
// gets the page under it; a slash-leading `/state` drops the prefix and gets a
// 403 there only, so no other test would notice. This reads the page's source,
// and the links the server hands it, and names each slash-leading URL.
// Run with: node --test scripts/test-web-console-relative-urls.mjs
import test from "node:test";
@@ -43,19 +41,16 @@ function pageFiles(rel = "") {
}
/**
* Each string literal in `text` (double quotes, single quotes or backticks)
* that makes a slash-leading URL, as `{ line, literal }`, in three shapes:
* text opening with `/` and a path character (a letter, digit, `_`, `.`, `-`
* or `${`); a lone `"/"` that starts an expression joined on with `+`
* (`fetch("/" + route)`; one joined in the middle of a path is fine); and
* markup in a string whose `src`, `href` or like attribute opens with `/`
* (`` `<img src="/x">` ``). A comment line and anything after a `//` outside
* a string are skipped; `//` opening a string is the protocol-relative case,
* which render.js blocks on its own. Quotes are tracked one line at a time, so
* a template literal that spans lines, or a regex literal holding a quote,
* can put the scan out of step for the rest of that line: a URL there goes
* unflagged, and only the frame page test, which loads the dashboard alone,
* would catch it at run time.
* Each string literal in `text` (any quote) that makes a slash-leading URL, as
* `{ line, literal }`: text opening with `/` and a path character (a letter,
* digit, `_`, `.`, `-` or `${`); a lone `"/"` starting an expression joined on
* with `+` (`fetch("/" + route)`, not one mid-path); and markup whose `src`,
* `href` or like attribute opens with `/`. Comment lines and anything after a
* `//` outside a string are skipped; a string opening `//` is protocol-relative,
* which render.js blocks itself. Quotes are tracked per line, so a template
* literal spanning lines or a regex holding a quote can hide a URL for the rest
* of that line; only the frame page test, which loads just the dashboard, could
* catch it at run time.
*/
function scriptUrls(text) {
const hits = [];