mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-17 04:45:33 -08:00
Split the web console into by-job files, add page tests and a docs-table test, plus docs
AI Assisted
This commit is contained in:
1 parent
699a827cae
commit
3edb4468a8
121 files changed
+25603
-20145
No files matched your search
@@ -0,0 +1,247 @@
|
||||
// Web console tests, the skill list: public/skills.js holds every per-skill
|
||||
// fact the console uses, and the older tables are lookups on it.
|
||||
// Run with: node --test scripts/test-web-console-skills.mjs
|
||||
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import {
|
||||
SKILLS,
|
||||
skillFor,
|
||||
skillByName,
|
||||
isBuild,
|
||||
isPhased,
|
||||
isMetered,
|
||||
subagentsFor,
|
||||
takesTemplates,
|
||||
labelFor,
|
||||
} from "../src/web-console/public/skills.js";
|
||||
import { CONSOLE_WORKFLOWS, SKILL_CATALOG, START_POSES, WORKFLOW_LABEL, dashNoteKind, onInitialPick, startPose, startingHint } from "../src/web-console/public/answers.js";
|
||||
import { LAUNCH_COUNTED, PROGRESS_WORKFLOWS } from "../src/web-console/public/meter.js";
|
||||
import { BUILD_WORKFLOWS } from "../src/web-console/public/labels.js";
|
||||
import { helpTabFor } from "../src/web-console/public/help.js";
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { createRequire } from "node:module";
|
||||
import { ROOT, cli, poseTemplate } from "./web-console-test-helpers.mjs";
|
||||
import { SUBAGENT_WORKFLOWS } from "../src/web-console/public/subagents.js";
|
||||
import { TEMPLATE_WORKFLOWS } from "../src/web-console/public/starters.js";
|
||||
|
||||
// meter.js keeps its answers-row names private: what they were when the list
|
||||
// moved, written out. A skill added since has no row here, and only has to
|
||||
// have a name.
|
||||
const NAMES_AT_THE_MOVE = {
|
||||
dashboard: "the dashboard",
|
||||
pathfinder: "Pathfinder",
|
||||
plan: "Plan",
|
||||
"revise-plan": "Revise plan",
|
||||
document: "Document",
|
||||
implement: "Implement",
|
||||
"implement-review": "Implement + Review",
|
||||
review: "Review",
|
||||
"quick-task": "Quick task",
|
||||
init: "Init",
|
||||
"init-update": "Init update",
|
||||
finalize: "Finalize",
|
||||
handoff: "Handoff",
|
||||
git: "Git",
|
||||
changelog: "Changelog",
|
||||
xray: "X-ray",
|
||||
diagnose: "Diagnose",
|
||||
};
|
||||
|
||||
const CARD_FIELDS = ["group", "chip", "title", "blurb", "about", "spec"];
|
||||
|
||||
test("every skill the console knows has one entry, the dashboard included", () => {
|
||||
const workflows = SKILLS.map((s) => s.workflow);
|
||||
assert.deepEqual([...workflows].sort(), Object.keys(WORKFLOW_LABEL).sort());
|
||||
assert.equal(new Set(workflows).size, workflows.length, "one entry per workflow");
|
||||
assert.deepEqual(SKILLS.map((s) => s.command).sort(), [...CONSOLE_WORKFLOWS].sort());
|
||||
// The cards come first, in the dashboard's order.
|
||||
const carded = SKILLS.filter((s) => s.card);
|
||||
assert.deepEqual(carded.map((s) => s.skill), SKILL_CATALOG.map((e) => e.skill));
|
||||
assert.equal(skillFor("dashboard").skill, "plan2code");
|
||||
assert.equal(skillFor("dashboard").card, null, "the dashboard is the hub, not a card");
|
||||
});
|
||||
|
||||
// The older exports (WORKFLOW_LABEL, SKILL_CATALOG, LAUNCH_COUNTED and the
|
||||
// rest) are now built from SKILLS, so this checks the wiring: each one still
|
||||
// says what its entry says. It proved the move when the tables were still
|
||||
// written by hand; the meter names and the build flags, which have no
|
||||
// importable twin, are held to their values at the move.
|
||||
test("the derived exports agree with each entry", () => {
|
||||
for (const s of SKILLS) {
|
||||
const w = s.workflow;
|
||||
for (const f of ["skill", "workflow", "label", "name"]) assert.ok(typeof s[f] === "string" && s[f].trim(), `${w}: ${f} must be filled in`);
|
||||
assert.equal(s.command, "/" + s.skill, `${w}: command`);
|
||||
assert.equal(s.label, WORKFLOW_LABEL[w], `${w}: label`);
|
||||
if (Object.hasOwn(NAMES_AT_THE_MOVE, w)) assert.equal(s.name, NAMES_AT_THE_MOVE[w], `${w}: name`);
|
||||
assert.equal(s.pose, startPose(w), `${w}: pose`);
|
||||
assert.equal(s.metered, LAUNCH_COUNTED.has(w), `${w}: metered`);
|
||||
assert.equal(s.subagents, SUBAGENT_WORKFLOWS[w] ? SUBAGENT_WORKFLOWS[w].instruction : null, `${w}: subagents`);
|
||||
assert.equal(s.templates, TEMPLATE_WORKFLOWS.includes(w), `${w}: templates`);
|
||||
if (Object.hasOwn(NAMES_AT_THE_MOVE, w)) {
|
||||
assert.equal(s.builds, ["implement", "implement-review", "quick-task"].includes(w), `${w}: builds`);
|
||||
assert.equal(s.phased, ["implement", "implement-review"].includes(w), `${w}: phased`);
|
||||
}
|
||||
const entry = SKILL_CATALOG.find((e) => e.workflow === w);
|
||||
if (!entry) {
|
||||
assert.equal(s.card, null, `${w}: no card`);
|
||||
continue;
|
||||
}
|
||||
assert.equal(entry.skill, s.skill, `${w}: skill`);
|
||||
assert.equal(entry.command, s.command, `${w}: card command`);
|
||||
for (const f of CARD_FIELDS) assert.equal(s.card[f], entry[f], `${w}: card.${f}`);
|
||||
}
|
||||
// Every pose in the page's list belongs to an entry.
|
||||
for (const pose of START_POSES) assert.ok(SKILLS.some((s) => s.pose === pose), `${pose} belongs to a skill`);
|
||||
for (const w of PROGRESS_WORKFLOWS) assert.ok(isPhased(w), `${w} counts its tasks`);
|
||||
});
|
||||
|
||||
test("the entries are frozen data", () => {
|
||||
assert.ok(Object.isFrozen(SKILLS));
|
||||
for (const s of SKILLS) {
|
||||
assert.ok(Object.isFrozen(s), `${s.workflow} is frozen`);
|
||||
if (s.card) assert.ok(Object.isFrozen(s.card), `${s.workflow}.card is frozen`);
|
||||
}
|
||||
});
|
||||
|
||||
test("the lookups answer by workflow or skill name, and say nothing for an unknown one", () => {
|
||||
assert.equal(skillFor("implement-review").skill, "plan2code-3-implement-review");
|
||||
assert.equal(skillByName("plan2code-git").workflow, "git");
|
||||
assert.equal(skillByName("plan2code").workflow, "dashboard");
|
||||
assert.equal(labelFor("xray"), "X-ray");
|
||||
assert.equal(subagentsFor("review"), SUBAGENT_WORKFLOWS.review.instruction);
|
||||
for (const unknown of ["nope", undefined, null, "", "constructor", "__proto__"]) {
|
||||
assert.equal(skillFor(unknown), null);
|
||||
assert.equal(skillByName(unknown), null);
|
||||
assert.equal(labelFor(unknown), null);
|
||||
assert.equal(subagentsFor(unknown), null);
|
||||
for (const is of [isBuild, isPhased, isMetered, takesTemplates]) assert.equal(is(unknown), false);
|
||||
}
|
||||
});
|
||||
|
||||
// Which workflows labels.js and help.js count as builds, as they stood when the
|
||||
// sets moved onto skills.js: labels.js leaves Quick Task out, help.js keeps it.
|
||||
test("the two build sets hold what they held before", () => {
|
||||
assert.deepEqual([...BUILD_WORKFLOWS].sort(), ["implement", "implement-review"]);
|
||||
assert.deepEqual(SKILLS.filter((s) => isBuild(s.workflow)).map((s) => s.workflow).sort(), ["implement", "implement-review", "quick-task"]);
|
||||
// help.js keeps its set private: Help opens on its Building tab for exactly these.
|
||||
const onBuild = SKILLS.map((s) => s.workflow).filter((workflow) => helpTabFor({ workflow }) === "build");
|
||||
assert.deepEqual(onBuild.sort(), ["implement", "implement-review", "quick-task"]);
|
||||
assert.equal(helpTabFor({ workflow: "nope" }), "about");
|
||||
});
|
||||
|
||||
/* ------------------------------------------- tests that name what was missed */
|
||||
|
||||
// Each check below is a pure function of a skill list, so a test can hand it a
|
||||
// copy with one thing wrong and see the message name the skill.
|
||||
|
||||
// Each skill's starting screen clones its pose from index.html. A pose with no
|
||||
// drawing silently falls back to the flight, and a drawing no skill uses is
|
||||
// dead markup.
|
||||
function poseProblems(skills, drawn) {
|
||||
const problems = [];
|
||||
for (const s of skills) {
|
||||
if (s.card && !s.pose) problems.push(`${s.skill} has a card but no pose`);
|
||||
if (s.pose && !drawn.includes(s.pose)) problems.push(`${s.skill} names pose "${s.pose}", which index.html does not draw`);
|
||||
}
|
||||
for (const pose of drawn) {
|
||||
if (!skills.some((s) => s.pose === pose)) problems.push(`index.html draws pose "${pose}", which belongs to no skill`);
|
||||
}
|
||||
return problems;
|
||||
}
|
||||
|
||||
// Every workflow the console can open has its notes behind `console.mjs help`.
|
||||
function helpProblems(skills, topics) {
|
||||
return skills.filter((s) => !Object.hasOwn(topics, s.workflow)).map((s) => `${s.skill} (${s.workflow}) has no help topic in console.mjs`);
|
||||
}
|
||||
|
||||
// The skills with a card, plus the dashboard, are exactly what install.js builds.
|
||||
function installProblems(skills, installed) {
|
||||
const named = skills.filter((s) => s.card || s.workflow === "dashboard").map((s) => s.skill);
|
||||
return [
|
||||
...named.filter((n) => !installed.includes(n)).map((n) => `${n} is in skills.js but not in install.js SOURCE_PROMPTS`),
|
||||
...installed.filter((n) => !named.includes(n)).map((n) => `${n} is in install.js SOURCE_PROMPTS but has no card in skills.js`),
|
||||
];
|
||||
}
|
||||
|
||||
const drawnPoses = () => [...poseTemplate().matchAll(/data-pose="([^"]+)"/g)].map((m) => m[1]);
|
||||
const helpTopics = () => cli(["help", "topics"]).json.topics;
|
||||
|
||||
// install.js reads the home directory at load: point it at a temp one, as the
|
||||
// install tests do. Requiring it never runs its CLI (that waits on require.main).
|
||||
function installedSkills() {
|
||||
const home = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-skills-"));
|
||||
const saved = { HOME: process.env.HOME, USERPROFILE: process.env.USERPROFILE };
|
||||
process.env.HOME = home;
|
||||
process.env.USERPROFILE = home;
|
||||
try {
|
||||
const { SOURCE_PROMPTS, generateSkillName } = createRequire(import.meta.url)(path.join(ROOT, "install.js"));
|
||||
return SOURCE_PROMPTS.map(generateSkillName);
|
||||
} finally {
|
||||
for (const [k, v] of Object.entries(saved)) v === undefined ? delete process.env[k] : (process.env[k] = v);
|
||||
fs.rmSync(home, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
test("every skill's pose is drawn in the page, and every drawn pose belongs to a skill", () => {
|
||||
const drawn = drawnPoses();
|
||||
assert.deepEqual(poseProblems(SKILLS, drawn), []);
|
||||
assert.doesNotMatch(poseTemplate(), /\sstyle=/, "a style attribute would be refused by the CSP");
|
||||
// Variants borrow their pose; the dashboard keeps the flight.
|
||||
assert.equal(startPose("implement-review"), "implement");
|
||||
assert.equal(startPose("revise-plan"), "plan");
|
||||
assert.equal(startPose("init-update"), "init");
|
||||
assert.equal(startPose("dashboard"), null);
|
||||
assert.equal(startPose(undefined), null);
|
||||
|
||||
const broken = SKILLS.map((s) => (s.workflow === "xray" ? { ...s, pose: "x-ray-glasses" } : s));
|
||||
assert.deepEqual(poseProblems(broken, drawn), [
|
||||
'plan2code-xray names pose "x-ray-glasses", which index.html does not draw',
|
||||
'index.html draws pose "xray", which belongs to no skill',
|
||||
]);
|
||||
const poseless = SKILLS.map((s) => (s.workflow === "git" ? { ...s, pose: null } : s));
|
||||
assert.deepEqual(poseProblems(poseless, drawn), ["plan2code-git has a card but no pose", 'index.html draws pose "git", which belongs to no skill']);
|
||||
});
|
||||
|
||||
test("every workflow in the skill list has a help topic", () => {
|
||||
const topics = helpTopics();
|
||||
assert.deepEqual(helpProblems(SKILLS, topics), []);
|
||||
const extra = [...SKILLS, { skill: "plan2code-made-up", workflow: "made-up" }];
|
||||
assert.deepEqual(helpProblems(extra, topics), ["plan2code-made-up (made-up) has no help topic in console.mjs"]);
|
||||
});
|
||||
|
||||
test("the skill list and install.js agree on which skills exist", () => {
|
||||
const installed = installedSkills();
|
||||
assert.ok(installed.includes("plan2code"), "read SOURCE_PROMPTS");
|
||||
assert.deepEqual(installProblems(SKILLS, installed), []);
|
||||
const extra = [...SKILLS, { skill: "plan2code-made-up", workflow: "made-up", card: {} }];
|
||||
assert.deepEqual(installProblems(extra, installed), ["plan2code-made-up is in skills.js but not in install.js SOURCE_PROMPTS"]);
|
||||
assert.deepEqual(installProblems(SKILLS, [...installed, "plan2code-orphan"]), ["plan2code-orphan is in install.js SOURCE_PROMPTS but has no card in skills.js"]);
|
||||
});
|
||||
|
||||
test("dashboard note: the agent's note shows only on the spec the picker opened on", () => {
|
||||
const a = { dir: "specs/a" };
|
||||
const b = { dir: "specs/b" };
|
||||
assert.equal(onInitialPick(a, a), true);
|
||||
assert.equal(onInitialPick(a, b), false);
|
||||
assert.equal(onInitialPick(a, null), false);
|
||||
assert.equal(onInitialPick(null, null), true, "no spec at all: scratch is the opening pick");
|
||||
assert.equal(onInitialPick(null, a), false);
|
||||
});
|
||||
|
||||
test("dashboard note: the agent's note, the looking-over line and the neutral line", () => {
|
||||
const menu = { note: "Phase 2 is next." };
|
||||
assert.equal(dashNoteKind({ menu, hasMenu: true, onInitial: true, working: false }), "agent");
|
||||
assert.equal(dashNoteKind({ menu, hasMenu: true, onInitial: false, working: false }), "neutral", "another pick, another line");
|
||||
assert.equal(dashNoteKind({ menu: { note: " " }, hasMenu: true, onInitial: true, working: true }), "neutral", "a blank note is no note");
|
||||
assert.equal(dashNoteKind({ menu: {}, hasMenu: false, onInitial: true, working: true }), "looking");
|
||||
assert.equal(dashNoteKind({ menu: {}, hasMenu: false, onInitial: true, working: false }), "neutral");
|
||||
});
|
||||
|
||||
test("starting screen: the hint stays calm for ninety seconds, then points at the terminal", () => {
|
||||
assert.match(startingHint(0), /fills in by itself/);
|
||||
assert.match(startingHint(90000), /fills in by itself/, "ninety seconds is still calm");
|
||||
assert.match(startingHint(90001), /terminal has the play-by-play/);
|
||||
});
|
||||
Reference in new issue
Block a user