Carry the spec into the app's New Session and name it beside the meter

AI Assisted
This commit is contained in:
jparkerweb committed 2026-11-09 22:09:03 -08:00
1 parent 7856618a4c
commit 7891c06642
14 files changed
+320 -6

No files matched your search

+57
View File
@@ -0,0 +1,57 @@
// The page side of the spec an app's New Session carries: loadSpecCarry() in selectors.js.
import assert from "node:assert/strict";
import test from "node:test";
import { page } from "../src/web-console/public/state.js";
import { loadSpecCarry } from "../src/web-console/public/selectors.js";
const specs = [
{ dir: "specs/a", name: "a", state: "building" },
{ dir: "specs/b", name: "b", state: "planned" },
];
// loadSpecCarry asks once per page, so each case is a fresh module copy.
async function fresh() {
return (await import(`../src/web-console/public/selectors.js?${Math.random()}`)).loadSpecCarry;
}
function setup({ spec, sel } = {}) {
page.S = { workflow: "dashboard", scan: { specs } };
page.local = sel === undefined ? {} : { specSel: sel };
globalThis.localStorage = { setItem() {}, getItem: () => null, removeItem() {} };
const calls = [];
globalThis.fetch = async (url, init) => {
calls.push([url, init && init.method]);
return { status: 200, json: async () => ({ spec }) };
};
return calls;
}
test("a carried spec the picker lists becomes the pick", async () => {
setup({ spec: "specs/b" });
await (await fresh())();
assert.equal(page.local.specSel, "specs/b");
});
test("a carried spec the picker does not list leaves the default", async () => {
setup({ spec: "specs/gone" });
await (await fresh())();
assert.equal("specSel" in page.local, false);
});
test("a pick the person already made is never replaced, or even asked about", async () => {
const calls = setup({ spec: "specs/b", sel: null });
await (await fresh())();
assert.equal(page.local.specSel, null);
assert.equal(calls.length, 0);
});
test("it asks once per page", async () => {
const calls = setup({ spec: undefined });
const load = await fresh();
await load();
await load();
assert.equal(calls.length, 1);
assert.deepEqual(calls[0], ["/spec-carry", "POST"]);
assert.equal(typeof loadSpecCarry, "function");
});
+46
View File
@@ -0,0 +1,46 @@
// The spec an app's New Session carries to the fresh dashboard (spec-carry.mjs).
import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import test from "node:test";
import { takeSpecCarry, SPEC_CARRY_MAX_AGE_MS } from "../src/web-console/spec-carry.mjs";
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "spec-carry-"));
const file = path.join(dir, "spec-carry.json");
const put = (entry) => fs.writeFileSync(file, JSON.stringify(entry));
const NOW = 1_000_000_000;
test("a fresh hint for this folder is taken once", () => {
put({ project: dir, spec: "specs/feature", at: NOW });
assert.equal(takeSpecCarry(dir, NOW + 1000, file), "specs/feature");
assert.equal(fs.existsSync(file), false);
assert.equal(takeSpecCarry(dir, NOW + 1000, file), null);
});
test("a stale hint is dropped, not used", () => {
put({ project: dir, spec: "specs/feature", at: NOW });
assert.equal(takeSpecCarry(dir, NOW + SPEC_CARRY_MAX_AGE_MS + 1, file), null);
assert.equal(fs.existsSync(file), false);
});
test("another folder's fresh hint stays for its own dashboard", () => {
put({ project: path.join(dir, "elsewhere"), spec: "specs/feature", at: NOW });
assert.equal(takeSpecCarry(dir, NOW, file), null);
assert.equal(fs.existsSync(file), true);
});
test("a spec that is not directly under specs/ is refused", () => {
for (const spec of ["../x", "specs/a/b", "specs/.hidden", "other", 5]) {
put({ project: dir, spec, at: NOW });
assert.equal(takeSpecCarry(dir, NOW, file), null, String(spec));
}
});
test("no file, or a broken one, is no hint", () => {
fs.rmSync(file, { force: true });
assert.equal(takeSpecCarry(dir, NOW, file), null);
fs.writeFileSync(file, "{nope");
assert.equal(takeSpecCarry(dir, NOW, file), null);
});
+3 -1
View File
@@ -365,6 +365,7 @@ test("the scratch sweep removes old patches and helpers, never looks, the pointe
file("looks.json"),
file("workspaces.json"),
file("loop-setup.json"),
file("spec-carry.json"),
file("loop-reports.json"),
file("subagents.json"),
file("pr-hosts.json"),
@@ -381,7 +382,7 @@ test("the scratch sweep removes old patches and helpers, never looks, the pointe
const stale = staleScratch(dir, Date.now(), SESSION_MAX_AGE_MS).sort();
assert.deepEqual(stale, ["helper.mjs", "p2.json"]);
assert.deepEqual(
(await removeScratch(dir, [...stale, "looks.json", "workspaces.json", "loop-setup.json", "loop-reports.json", "subagents.json", "pr-hosts.json", "../p.json", "console-dir", "update-check.json"])).sort(),
(await removeScratch(dir, [...stale, "looks.json", "workspaces.json", "loop-setup.json", "loop-reports.json", "subagents.json", "spec-carry.json", "pr-hosts.json", "../p.json", "console-dir", "update-check.json"])).sort(),
["helper.mjs", "p2.json"]
);
for (const p of removable) assert.equal(fs.existsSync(p), false, p);
@@ -392,6 +393,7 @@ test("the scratch sweep removes old patches and helpers, never looks, the pointe
"loop-reports.json",
"loop-setup.json",
"pr-hosts.json",
"spec-carry.json",
"subagents.json",
"update-check.json",
"workspaces.json",
+1 -1
View File
@@ -193,7 +193,7 @@ const ROUTE_ORDER = [
"/notepad", "/notepad/text", "/notepad/image", "/notepad/thumb", "/notepad/image/delete", "/notepad/tab",
"/notepad/tab/rename", "/notepad/tab/delete", "/notepad/tab/order", "/notepad/tab/last", "/notepad/tab/sent", "/notepad/images/",
"/attachments/", "/shots/", "/uploads/", "/submit", "/open-link", "/chat", "/chat/decision", "/workspace",
"WORKSPACE_EDITS", "/workspace/scope", "/workspace/browse", "/loop-setup", "/loop-setup", "/cancel", "/ping", "/bye",
"WORKSPACE_EDITS", "/workspace/scope", "/workspace/browse", "/loop-setup", "/loop-setup", "/spec-carry", "/cancel", "/ping", "/bye",
];
test("shape: routes.mjs lists every URL the server answers, in order", () => {