Grade every waiting lesson with a separate check before the lessons card asks for approval

AI Assisted
This commit is contained in:
jparkerweb committed 2026-11-27 23:19:42 -08:00
1 parent b06a4cb4ab
commit 1345aa0a95
36 files changed
+2812 -139

No files matched your search

+1 -1
View File
@@ -351,7 +351,7 @@ function makeLearningProject() {
const note = (text, kind, about) =>
spawnSync(
process.execPath,
[path.join(ROOT, "src", "skill-scripts", "lessons.mjs"), "note", "--type", "lesson", "--text", text, "--kind", kind, "--about", about, "--source", "said", "--skill", "implement"],
[path.join(ROOT, "src", "skill-scripts", "lessons.mjs"), "note", "--type", "lesson", "--text", text, "--kind", kind, "--about", about, "--source", "said", "--skill", "implement", ...(kind === "convention" ? ["--why", "An offset skips rows when the list changes between pages."] : [])],
{ cwd: project, env: ENV, encoding: "utf8" }
);
note("Every list endpoint pages with a cursor, never an offset.", "convention", "src/tasks");
File diff suppressed because it is too large. Load diff
+78 -8
View File
@@ -14,9 +14,9 @@ import os from "node:os";
import path from "node:path";
import { spawnSync } from "node:child_process";
import { ENV, HOME, LEARNING_DIR, ROOT, cli, postPatch, readState, sessionUrl } from "./web-console-test-helpers.mjs";
import { learningScan, storeDir, writePause, writeWaiting } from "../src/web-console/learning.mjs";
import { followCounts, learningScan, lessonsNearCap, recordFollow, storeDir, writePause, writeWaiting } from "../src/web-console/learning.mjs";
import { sessionActions } from "../src/web-console/cmd-post-wait.mjs";
import { indentReply, learningAction, learningBannerText, learningReply, lessonsReply } from "../src/web-console/public/answers.js";
import { indentReply, learningAction, learningBannerText, learningNearCapText, learningReply, lessonDecisionLine, lessonsReply } from "../src/web-console/public/answers.js";
const LESSONS = path.join(ROOT, "src", "skill-scripts", "lessons.mjs");
@@ -67,7 +67,7 @@ function dashboard(t, dir) {
test("scan.learning: not set up, off, on and paused, with the waiting count", (t) => {
const none = project();
const s1 = dashboard(t, none);
assert.deepEqual(readState(s1.session).scan.learning, { state: "not-set-up", pausedSince: null, waiting: 0, oldestDays: 0 });
assert.deepEqual(readState(s1.session).scan.learning, { state: "not-set-up", pausedSince: null, waiting: 0, oldestDays: 0, nearCap: false });
const off = project(SETTINGS("off"));
assert.equal(readState(dashboard(t, off).session).scan.learning.state, "off");
@@ -76,7 +76,7 @@ test("scan.learning: not set up, off, on and paused, with the waiting count", (t
const noted = new Date(Date.now() - 2 * 24 * 60 * 60 * 1000 - 60000).toISOString();
writeWaiting(on, { id: "20261111-120000-abcdef", type: "lesson", text: "A lesson.", noted });
writeWaiting(on, { id: "20261112-120000-abcdef", type: "lesson", text: "Another.", noted: new Date().toISOString() });
assert.deepEqual(readState(dashboard(t, on).session).scan.learning, { state: "on", pausedSince: null, waiting: 2, oldestDays: 2 });
assert.deepEqual(readState(dashboard(t, on).session).scan.learning, { state: "on", pausedSince: null, waiting: 2, oldestDays: 2, nearCap: false });
const paused = project(SETTINGS("on"));
const pause = writePause(paused, true, "2026-11-13T09:00:00.000Z");
@@ -92,6 +92,33 @@ test("scan.learning is absent for a settings format this console does not know",
assert.equal("learning" in scan, false, "no learning field, so the page draws no row");
});
// An area file holding `n` lessons.
const lessonFile = (title, n) =>
`# ${title}\n\n` + Array.from({ length: n }, (_, i) => `### Lesson number ${i}\n- Kind: how-it-works\n- About: src/a.js\n- Noted: 2026-11-01, Implement\n`).join("\n");
test("scan.learning.nearCap: true at 22 general lessons or 30 in an area, false below, and only while Learning is on", (t) => {
const near = (files) => learningScan(project(files)).nearCap;
assert.equal(near({ ...SETTINGS("on") }), false, "no lessons folder");
assert.equal(near({ ...SETTINGS("on"), ".plan2code/lessons/general.md": lessonFile("General", 21) }), false);
assert.equal(near({ ...SETTINGS("on"), ".plan2code/lessons/general.md": lessonFile("General", 22) }), true);
assert.equal(near({ ...SETTINGS("on"), ".plan2code/lessons/general.md": lessonFile("General", 25) }), true);
assert.equal(near({ ...SETTINGS("on"), ".plan2code/lessons/web.md": lessonFile("Web", 29) }), false);
assert.equal(near({ ...SETTINGS("on"), ".plan2code/lessons/web.md": lessonFile("Web", 30) }), true);
// 22 is the general file's line only: an area at 22 is not crowded.
assert.equal(near({ ...SETTINGS("on"), ".plan2code/lessons/web.md": lessonFile("Web", 22) }), false);
// Either file is enough, and CRLF files count the same.
assert.equal(near({ ...SETTINGS("on"), ".plan2code/lessons/general.md": lessonFile("General", 3), ".plan2code/lessons/web.md": lessonFile("Web", 30).replace(/\n/g, "\r\n") }), true);
// Not on: no nudge, however full.
assert.equal(near({ ...SETTINGS("off"), ".plan2code/lessons/general.md": lessonFile("General", 25) }), false);
assert.equal(lessonsNearCap(project({ ".plan2code/lessons/general.md": lessonFile("General", 25) })), true, "the count itself ignores the state");
// It reaches the page through the dashboard's scan.
const full = project({ ...SETTINGS("on"), ".plan2code/lessons/general.md": lessonFile("General", 23) });
assert.equal(readState(dashboard(t, full).session).scan.learning.nearCap, true);
const before = listing(full);
learningScan(full);
assert.deepEqual(listing(full), before, "the scan writes nothing");
});
test("a failure in Learning's core never fails the scan", () => {
const boom = () => {
throw new Error("the core broke");
@@ -109,7 +136,7 @@ test("an unreadable learning store reads as empty: on, not paused, nothing waiti
fs.writeFileSync(store, "not a folder");
t.after(() => fs.rmSync(store, { force: true }));
const s = dashboard(t, dir);
assert.deepEqual(readState(s.session).scan.learning, { state: "on", pausedSince: null, waiting: 0, oldestDays: 0 });
assert.deepEqual(readState(s.session).scan.learning, { state: "on", pausedSince: null, waiting: 0, oldestDays: 0, nearCap: false });
});
test("the scan reads without pruning: an old waiting item stays on disk", (t) => {
@@ -170,7 +197,7 @@ test("GET /learning/state answers the scan's object, worked out now", async (t)
writeWaiting(dir, { id: "20261113-120000-bbbbbb", type: "lesson", text: "New.", noted: new Date().toISOString() });
const res = await s.get("/learning/state");
assert.equal(res.status, 200);
assert.deepEqual(await res.json(), { state: "on", pausedSince: null, waiting: 1, oldestDays: 0 });
assert.deepEqual(await res.json(), { state: "on", pausedSince: null, waiting: 1, oldestDays: 0, nearCap: false });
const unknown = dashboard(t, project({ ".plan2code/settings.json": "{}" }));
assert.deepEqual(await (await unknown.get("/learning/state")).json(), {});
@@ -208,13 +235,37 @@ test("GET /learning/lessons: general first, then the rest by name; no sub-folder
if (linked) assert.equal(files.some((f) => f.name === "linked.md"), false, "the link out was not followed");
const empty = dashboard(t, project(SETTINGS("on")));
assert.deepEqual(await (await empty.get("/learning/lessons")).json(), { files: [] });
assert.deepEqual(await (await empty.get("/learning/lessons")).json(), { files: [], follows: {} });
});
test("followCounts: sums lines per lesson, keeps the latest time and skips an unreadable line", () => {
const dir = project(SETTINGS("on"));
assert.deepEqual(followCounts(dir), {}, "no file yet");
recordFollow(dir, { lesson: "web/a", skill: "implement" }, new Date("2026-11-10T09:00:00Z"));
recordFollow(dir, { lesson: "web/a", skill: "quick-task" }, new Date("2026-11-20T09:00:00Z"));
recordFollow(dir, { lesson: "web/b", skill: "implement" }, new Date("2026-11-12T09:00:00Z"));
fs.appendFileSync(path.join(storeDir(dir), "follows.ndjson"), "{ not json\n\n{\"lesson\":3}\n");
recordFollow(dir, { lesson: "web/a", skill: "implement" }, new Date("2026-11-15T09:00:00Z"));
assert.deepEqual(followCounts(dir), {
"web/a": { count: 3, last: "2026-11-20T09:00:00.000Z" },
"web/b": { count: 1, last: "2026-11-12T09:00:00.000Z" },
});
assert.equal(listing(dir).some((f) => f.includes("follows")), false, "nothing written into the project");
});
test("GET /learning/lessons carries follows from this machine's store", async (t) => {
const dir = project({ ...SETTINGS("on"), ".plan2code/lessons/general.md": "# General\n\n### A lesson\n- Kind: how-it-works\n- About: src/x.js\n- Noted: 2026-11-01, Implement\n" });
recordFollow(dir, { lesson: "general/a-lesson", skill: "implement" }, new Date("2026-11-10T09:00:00Z"));
recordFollow(dir, { lesson: "general/a-lesson", skill: "implement" }, new Date("2026-11-11T09:00:00Z"));
const s = dashboard(t, dir);
const body = await (await s.get("/learning/lessons")).json();
assert.deepEqual(body.follows, { "general/a-lesson": { count: 2, last: "2026-11-11T09:00:00.000Z" } });
});
/* ------------------------------------------------- the action and reply */
test("a Learning action reaches the agent whole, and a launch keeps fromBanner", () => {
for (const what of ["review", "switch-on", "switch-off", "move-log", "remove"]) {
for (const what of ["review", "switch-on", "switch-off", "move-log", "remove", "tidy"]) {
const action = learningAction(what);
assert.deepEqual(action, { i: "__learning", type: "learning", do: what });
assert.deepEqual(sessionActions({ actions: [action] }), [{ i: "__learning", do: what }]);
@@ -235,6 +286,25 @@ test("the waiting banner's line shows only while lessons wait and Learning is on
assert.equal(learningBannerText(undefined), "");
});
test("the tidy-up nudge's line shows only while Learning is on and the lessons are near their limit", () => {
assert.equal(learningNearCapText({ state: "on", waiting: 0, nearCap: true }), "Lessons are nearing their limit. Tidy up?");
assert.equal(learningNearCapText({ state: "on", waiting: 3, nearCap: true }), "Lessons are nearing their limit. Tidy up?", "beside the waiting line");
assert.equal(learningNearCapText({ state: "on", waiting: 0, nearCap: false }), "");
assert.equal(learningNearCapText({ state: "on", waiting: 0 }), "");
assert.equal(learningNearCapText({ state: "paused", nearCap: true }), "");
assert.equal(learningNearCapText({ state: "off", nearCap: true }), "");
assert.equal(learningNearCapText({ state: "not-set-up", nearCap: true }), "");
assert.equal(learningNearCapText(undefined), "");
});
test("a tidy row's decisions read as the change, never as an AGENTS.md file", () => {
const retire = { id: "t1", type: "tidy", change: "retire", text: "Retire: Draw the page from state Reason: Git marks it.", choices: ["Apply", "Leave"] };
const fix = { id: "f1", type: "agents-fix", file: ".agents-docs/AGENTS-code-style.md", text: "x", choices: ["Apply", "Reword", "Drop"] };
assert.equal(lessonDecisionLine(retire, { id: "t1", choice: "Apply" }), "Apply: Retire: Draw the page from state Reason: Git marks it.");
assert.equal(lessonDecisionLine(retire, { id: "t1", choice: "Leave" }), "Leave: Retire: Draw the page from state Reason: Git marks it.");
assert.equal(lessonDecisionLine(fix, { id: "f1", choice: "Apply" }), "Apply: .agents-docs/AGENTS-code-style.md", "a fix still shows its file");
});
/* ---------------------------------------------- the lessons card, end to end */
test("the lessons card from lessons.mjs list goes up on the dashboard, and a Keep comes back as a Keep line and a decisions file decide takes", async (t) => {
+50 -1
View File
@@ -104,6 +104,8 @@ import {
loopLessonsLine,
} from "../src/web-console/public/answers.js";
import { chatView } from "../src/web-console/public/chat.js";
import { LEARNING_BUSY_MS, LEARNING_CHECK_MS, learningBusyLimit, learningBusyNow } from "../src/web-console/public/selectors.js";
import { page } from "../src/web-console/public/state.js";
import { agoWords, whenTitle, whenWords } from "../src/web-console/public/labels.js";
import { ACCENTS, DEFAULT_ACCENT, RETIRED_ACCENTS, accentId } from "../src/web-console/public/palette.js";
import {
@@ -1672,7 +1674,7 @@ test("validate: a lessons item takes rows each with a type and its own choices,
const one = (extra) => validate({ items: [item(extra)] });
assert.deepEqual(one({ opening: "You are on main: kept lessons will be uncommitted changes here.", rows: [row({ why: "A full run hides it.", origin: "You said this.", note: "", flags: [], refused: null, area: "General", areas: ["General"] })] }), []);
assert.deepEqual(
one({ rows: ["lesson", "doubt", "gone", "agents-fix", "log-line", "area"].map((type, i) => row({ id: `w${i}`, type })) }),
one({ rows: ["lesson", "doubt", "gone", "agents-fix", "tidy", "log-line", "area"].map((type, i) => row({ id: `w${i}`, type })) }),
[],
"every row type the list gives"
);
@@ -1705,6 +1707,53 @@ test("validate: a lessons item takes rows each with a type and its own choices,
assert.deepEqual(answered, [], "an answered card does not count");
});
test("validate: a lessons row takes the check's verdicts and a tag, and the card how it was checked", () => {
const check = { fails: [{ test: "Search", reason: "It matches 3 files." }], doubts: [{ test: "Why", reason: "No reason given." }], passed: 2, suggestion: "A shorter wording." };
const row = (extra = {}) => ({ id: "w1", type: "lesson", text: "A lesson.", choices: ["Keep", "Reword", "Drop"], ...extra });
const item = (extra) => ({ id: "lessons", kind: "lessons", title: "Lessons to keep", status: "open", rows: [row()], ...extra });
const one = (extra) => validate({ items: [item(extra)] });
const refused = (extra, field) => {
const problems = one(extra);
assert.ok(problems.some((p) => p.includes(field)), `${field}: ${problems.join(" | ")}`);
};
assert.deepEqual(one({ rows: [row({ check, tag: "Checked in an earlier run" })], checked: { how: "helper", count: 6, seconds: 40 } }), [], "a good check, tag and how");
assert.deepEqual(one({ rows: [row({ check: { fails: [], doubts: [], passed: 4 }, tag: "Not checked yet" })], checked: { how: "same-agent", count: 1, seconds: 0 } }), []);
assert.deepEqual(one({ checked: { failed: "The checker answered with nothing usable." } }), [], "a check that could not run");
refused({ rows: [row({ check: { ...check, extra: 1 } })] }, 'row "w1" check "extra"');
refused({ rows: [row({ check: { ...check, passed: 5 } })] }, 'row "w1" check passed');
refused({ rows: [row({ check: { ...check, fails: [{ test: "Search", reason: 7 }] } })] }, 'row "w1" check fails[0]');
refused({ rows: [row({ check: { ...check, doubts: Array.from({ length: 5 }, () => ({ test: "a", reason: "b" })) } })] }, 'row "w1" check doubts');
refused({ rows: [row({ check: { ...check, suggestion: "x".repeat(201) } })] }, 'row "w1" check suggestion');
refused({ rows: [row({ tag: "Old" })] }, 'row "w1" tag');
refused({ checked: { how: "robot", count: 1, seconds: 1 } }, "checked");
refused({ checked: { how: "helper", count: -1, seconds: 1 } }, "checked");
refused({ checked: { failed: "x".repeat(201) } }, "checked");
});
test("learning busy: a Review or Tidy up the agent is still working on outlasts LEARNING_BUSY_MS, a switch never does", () => {
const saved = { S: page.S, learningBusy: page.learningBusy, pendingResult: page.pendingResult };
try {
page.pendingResult = null;
const at = (what, agoMs, status) => {
page.S = { agent: { status }, items: [] };
page.learningBusy = { what, from: "on", at: Date.now() - agoMs, seen: true };
return learningBusyNow("on");
};
page.S = { agent: { status: "working" }, items: [] };
assert.equal(learningBusyLimit({ what: "review" }), LEARNING_CHECK_MS);
assert.equal(learningBusyLimit({ what: "tidy" }), LEARNING_CHECK_MS);
assert.equal(learningBusyLimit({ what: "switch-on" }), LEARNING_BUSY_MS, "a switch keeps the short limit");
assert.ok(at("review", LEARNING_BUSY_MS + 10000, "working"), "a Review still being checked stays busy past 30 seconds");
assert.ok(at("tidy", LEARNING_BUSY_MS + 10000, "working"), "so does a Tidy up");
assert.equal(at("review", LEARNING_CHECK_MS + 1000, "working"), null, "but not past the check limit");
assert.equal(at("review", LEARNING_BUSY_MS + 10000, "waiting"), null, "an agent back to waiting ends it at the short limit");
page.pendingResult = { id: "x" };
assert.equal(learningBusyLimit({ what: "review" }), LEARNING_CHECK_MS, "a send not yet picked up counts as working");
} finally {
Object.assign(page, saved);
}
});
test("validate: a lesson's own words never get the lessons card refused, but the card's own text still can", () => {
const marker = "TASK_" + "COMPLETE";
const words = ["Requirements 12 and 13 are checked by check-versions.mjs.", "Risk 3 is the slow blame on Windows.", `Never print ${marker} in a spec file.`, "The grill step reads the map first."];
+160 -1
View File
@@ -13,7 +13,7 @@ import test from "node:test";
import assert from "node:assert/strict";
import { pageSuite, openSession, tempProject, textOf, styleOf, stylesOf, itemCard, sendAndCollect, settled, scrollCard } from "./page-test-helpers.mjs";
import { cli, until } from "./web-console-test-helpers.mjs";
import { writePause, writeWaiting } from "../src/web-console/learning.mjs";
import { recordFollow, writePause, writeWaiting } from "../src/web-console/learning.mjs";
const suite = pageSuite(test);
@@ -126,6 +126,32 @@ test("on: the row is after the last card group, before the tip, with no count of
assert.match(await textOf(dlg), /The project's lessons \(\.plan2code\/lessons\/, saved with the repository\)/);
});
test("the lessons reader draws a quiet follow line under each lesson's heading", async (t) => {
const lesson = (title) => `### ${title}\n- Kind: how-it-works\n- About: src/x.js\n- Noted: 2026-11-01, Implement\n\n`;
const { main } = await dashboard(
t,
{ ...PROJECT("on"), ".plan2code/lessons/general.md": `# General\n\n${lesson("Followed lesson")}${lesson("Untouched lesson")}${lesson("Once lesson")}` },
(project) => {
recordFollow(project, { lesson: "general/followed-lesson", skill: "implement" }, new Date("2026-11-10T12:00:00Z"));
recordFollow(project, { lesson: "general/followed-lesson", skill: "quick-task" }, new Date("2026-11-20T12:00:00Z"));
recordFollow(project, { lesson: "general/once-lesson", skill: "implement" }, new Date("2026-11-12T12:00:00Z"));
}
);
const row = main.locator("section.learn-row");
await row.waitFor();
await row.getByRole("button", { name: "Open the lessons" }).click();
const dlg = main.page().locator("#learn-lessons-modal");
await dlg.locator(".learn-follow").first().waitFor();
const lines = await dlg.locator(".learn-follow").allInnerTexts();
assert.equal(lines.length, 3, "one line per lesson");
assert.match(lines[0], /^Followed 2 times, last on Nov 2[01]$/);
assert.equal(lines[1], "Not followed yet");
assert.match(lines[2], /^Followed once, last on Nov 1[123]$/);
// The line sits right under its heading.
const order = await dlg.locator(".learn-lessons-file").evaluate((n) => [...n.children].map((c) => (c.classList.contains("learn-follow") ? "follow" : c.textContent.includes("Followed lesson") ? "heading" : "other")));
assert.equal(order.indexOf("follow"), order.indexOf("heading") + 1);
});
test("Pause for me repaints the row with no agent listening, both ways", async (t) => {
const { s, main } = await dashboard(t, PROJECT("on"));
const bottom = main.locator("section.learn-row.is-bottom");
@@ -153,6 +179,7 @@ test("More opens upward and closes on Escape and on a click outside", async (t)
assert.ok(m.y + m.height <= b.y + 1, `the menu opens above its button: ${JSON.stringify({ m, b })}`);
assert.deepEqual(await menu.getByRole("menuitem").allInnerTexts(), [
"Switch off for this project",
"Tidy up lessons",
"Move the failure log into lessons",
"Remove all lessons…",
]);
@@ -211,6 +238,50 @@ test("the banner shows only with lessons waiting, directly above the title", asy
assert.equal(await paused.main.locator(".learn-banner").count(), 0, "hidden while paused");
});
test("More has Tidy up lessons, which sends the tidy Learning action and shows working at once", async (t) => {
const { s, main } = await dashboard(t, PROJECT("on"));
const row = main.locator("section.learn-row.is-bottom");
await row.getByRole("button", { name: /More/ }).click();
await row.getByRole("menuitem", { name: "Tidy up lessons" }).click();
const got = s.wait(10);
assert.equal(got.code, 0, "the send reached the agent");
assert.deepEqual(got.actions, [{ i: "__learning", type: "learning", do: "tidy" }]);
await main.locator(".learn-banner").getByText("Looking over your lessons…").waitFor();
});
// An area file holding `n` lessons.
const lessonFile = (title, n) =>
`# ${title}\n\n` + Array.from({ length: n }, (_, i) => `### Lesson number ${i}\n- Kind: how-it-works\n- About: src/a.js\n- Noted: 2026-11-01, Implement\n`).join("\n");
test("the banner nudges a tidy-up when lessons are near their limit, and only then", async (t) => {
const full = await dashboard(t, { ...PROJECT("on"), ".plan2code/lessons/general.md": lessonFile("General", 22) });
const banner = full.main.locator(".learn-banner");
await banner.waitFor();
assert.match(await textOf(banner), /Lessons are nearing their limit\. Tidy up\?/);
assert.equal(await banner.getByRole("button", { name: "Review" }).count(), 0, "nothing waits, so no Review");
await banner.getByRole("button", { name: "Tidy up" }).click();
const got = full.s.wait(10);
assert.equal(got.code, 0);
assert.deepEqual(got.actions, [{ i: "__learning", type: "learning", do: "tidy" }]);
// Beside the waiting line when lessons wait too.
const both = await dashboard(t, { ...PROJECT("on"), ".plan2code/lessons/web.md": lessonFile("Web", 30) }, (p) =>
writeWaiting(p, { id: "20261113-120000-ffffff", type: "lesson", text: "Waits.", noted: new Date().toISOString() })
);
const two = both.main.locator(".learn-banner");
await two.waitFor();
const text = await textOf(two);
assert.match(text, /1 lesson is waiting for your review/);
assert.match(text, /Lessons are nearing their limit\. Tidy up\?/);
assert.equal(await two.getByRole("button", { name: "Review" }).count(), 1);
assert.equal(await two.getByRole("button", { name: "Tidy up" }).count(), 1);
// One short of the line, in general.md and in an area: no nudge.
const below = await dashboard(t, { ...PROJECT("on"), ".plan2code/lessons/general.md": lessonFile("General", 21), ".plan2code/lessons/web.md": lessonFile("Web", 29) });
await below.main.locator("section.learn-row").waitFor();
assert.equal(await below.main.locator(".learn-banner").count(), 0, "no banner below the line");
});
test("a launch from a dashboard showing lessons waiting carries fromBanner", async (t) => {
const { s, main } = await dashboard(t, PROJECT("on"), (p) =>
writeWaiting(p, { id: "20261113-120000-eeeeee", type: "lesson", text: "Waits.", noted: new Date().toISOString() })
@@ -293,6 +364,29 @@ test("lessons card: each row shows its own choice words, and nothing is chosen",
assert.match(await textOf(rowOf(card, "w-area")), /Noted on feature\/x\./);
});
test("lessons card: a tidy row shows the change, the lessons it replaces and its reason, and Reword edits the new wording", async (t) => {
const merge = { id: "w-merge", type: "tidy", change: "merge", text: "Merge 2 lessons into: Keep modules small and kebab-case their files.", why: "They say the same thing twice.", origin: "", note: "", flags: [], refused: null, area: "Source", areas: ["General", "Source"], targets: [{ id: "source/keep-modules-small", text: "Keep modules small", area: "Source" }, { id: "source/name-files-in-kebab-case", text: "Name files in kebab case", area: "Source" }], wording: "Keep modules small and kebab-case their files.", wordingWhy: "Both keep the tree easy to scan.", choices: ["Apply", "Reword", "Leave"] };
const retire = { id: "w-retire", type: "tidy", change: "retire", text: "Retire: Draw the page from state Reason: Git marks it.", why: "", origin: "", note: "", flags: [], refused: null, area: "", areas: ["General", "Source"], targets: [{ id: "web/draw-the-page-from-state", text: "Draw the page from state", area: "Web" }], choices: ["Apply", "Leave"] };
const { s, card } = await lessonsCard(t, CARD([merge, retire]));
assert.deepEqual(await choicesOf(rowOf(card, "w-merge")).allInnerTexts(), ["Apply", "Reword", "Leave"]);
assert.deepEqual(await choicesOf(rowOf(card, "w-retire")).allInnerTexts(), ["Apply", "Leave"], "no Reword where there is no wording");
const text = await textOf(rowOf(card, "w-merge"));
assert.match(text, /Merge 2 lessons into: Keep modules small and kebab-case their files\./);
assert.match(text, /It replaces these lessons:\s+Keep modules small\s+Name files in kebab case/);
assert.match(text, /Why: They say the same thing twice\./);
assert.match(await textOf(rowOf(card, "w-retire")), /Retire: Draw the page from state Reason: Git marks it\./);
// Reword opens on the new wording and its own Why, not on the sentence describing the change.
await rowOf(card, "w-merge").getByRole("button", { name: "Reword" }).click();
const words = rowOf(card, "w-merge").getByLabel("The lesson");
assert.equal(await words.inputValue(), "Keep modules small and kebab-case their files.");
assert.equal(await rowOf(card, "w-merge").getByLabel("Why").inputValue(), "Both keep the tree easy to scan.");
await words.fill("Keep modules small and name their files in kebab case.");
await rowOf(card, "w-retire").getByRole("button", { name: "Apply" }).click();
const got = await sendAndCollect(s);
const decisions = got.actions.find((a) => a.i === "lessons").decisions;
assert.deepEqual(decisions, [{ id: "w-merge", choice: "Reword", text: "Keep modules small and name their files in kebab case.", why: "Both keep the tree easy to scan." }, { id: "w-retire", choice: "Apply" }]);
});
test("lessons card: Keep on one row sends only that row, and the rest are left waiting", async (t) => {
const { s, card } = await lessonsCard(t);
await rowOf(card, "w-lesson").getByRole("button", { name: "Keep" }).click();
@@ -409,6 +503,71 @@ test("lessons card: a refused row's Keep still chooses after its words go back a
]);
});
const CHECKED_ROWS = [
{ ...ROWS[0], id: "c-fail", text: "Never run the full suite.", check: { fails: [{ test: "Search", reason: "It matches 3 files." }], doubts: [], passed: 3 } },
{ ...ROWS[0], id: "c-doubt", text: "The handler is small.", tag: "Checked in an earlier run", check: { fails: [], doubts: [{ test: "Why", reason: "The reason repeats the lesson." }], passed: 3 } },
{ ...ROWS[0], id: "c-pass", text: "Use the helper.", check: { fails: [], doubts: [], passed: 4 } },
{ ...ROWS[0], id: "c-none", text: "Not looked at.", tag: "Not checked yet" },
{ ...ROWS[0], id: "c-all", text: "Every test flagged.", check: { fails: [{ test: "Search", reason: "No match." }, { test: "Worth", reason: "Already in AGENTS.md." }], doubts: [{ test: "Why", reason: "Thin." }, { test: "Clear", reason: "Vague." }], passed: 0 } },
];
test("lessons card: a Fail, a Doubt and a pass show their lines, and the outline follows suggested without choosing", async (t) => {
const { card } = await lessonsCard(t, CARD(CHECKED_ROWS, { suggested: { "c-fail": "Drop", "c-pass": "Keep" }, checked: { how: "helper", count: 4, seconds: 40 } }));
const fail = rowOf(card, "c-fail");
assert.match(await textOf(fail.locator(".lesson-check.fail")), /^Fail Search: It matches 3 files\.$/);
assert.equal(await fail.locator(".lesson-check.doubt").count(), 0);
assert.match(await textOf(fail.locator(".lesson-check-pass")), /^Passed the other 3$/);
const doubt = rowOf(card, "c-doubt");
assert.match(await textOf(doubt.locator(".lesson-check.doubt")), /^Doubt Why: The reason repeats the lesson\.$/);
assert.equal(await doubt.locator(".lesson-check.fail").count(), 0);
assert.match(await textOf(doubt.locator(".lessons-tag")), /^Checked in an earlier run$/);
const pass = rowOf(card, "c-pass");
assert.equal(await pass.locator(".lesson-check.fail, .lesson-check.doubt").count(), 0, "a pass lists no verdicts");
assert.match(await textOf(pass.locator(".lesson-check-pass")), /^Passed the check$/);
const none = rowOf(card, "c-none");
assert.equal(await none.locator(".lesson-checks").count(), 0, "a row never checked draws nothing");
assert.match(await textOf(none.locator(".lessons-tag")), /^Not checked yet$/);
const all = rowOf(card, "c-all");
assert.equal(await all.locator(".lesson-check.fail, .lesson-check.doubt").count(), 4);
assert.equal(await all.locator(".lesson-check-pass").count(), 0, "no pass line when nothing passed");
const outlined = async (row) => row.locator(".lessons-choices button.is-suggested").allInnerTexts();
assert.deepEqual(await outlined(fail), ["Drop"]);
assert.deepEqual(await outlined(doubt), [], "a Doubt outlines nothing");
assert.deepEqual(await outlined(pass), ["Keep"]);
assert.equal(await card.locator('.lessons-choices [aria-pressed="true"]').count(), 0, "nothing is chosen for the person");
assert.notEqual(await styleOf(fail.locator(".lesson-check.fail"), "color"), await styleOf(pass.locator(".lesson-check-pass"), "color"), "a Fail is not drawn like the quiet pass line");
const px = async (loc) => parseFloat(await styleOf(loc, "fontSize"));
assert.ok((await px(pass.locator(".lesson-check-pass"))) < (await px(fail.locator(".lesson-check.fail"))), "the pass line is smaller than a verdict line");
assert.match(await textOf(card.locator(".lessons-checked")), /^Checked 4 lessons in 40 seconds by a fresh helper that could only read$/);
});
test("lessons card: the how-checked line names the same agent, or why the check could not run", async (t) => {
const same = await lessonsCard(t, CARD(CHECKED_ROWS.slice(2, 3), { checked: { how: "same-agent", count: 1, seconds: 1 } }));
assert.match(await textOf(same.card.locator(".lessons-checked")), /^Checked 1 lesson in 1 second by the same agent that noted them$/);
const failed = await lessonsCard(t, CARD(CHECKED_ROWS.slice(3, 4), { checked: { failed: "the checker answered with nothing usable." } }));
assert.match(await textOf(failed.card.locator(".lessons-checked")), /^The check could not run: the checker answered with nothing usable\.$/);
const bare = await lessonsCard(t, CARD(CHECKED_ROWS.slice(3, 4)));
assert.equal(await bare.card.locator(".lessons-checked").count(), 0, "no line without a check");
});
test("lessons card: Use this wording opens Reword filled with the suggestion, and what is sent is a normal Reword", async (t) => {
const row = { ...ROWS[0], id: "c-sug", check: { fails: [], doubts: [{ test: "Search", reason: "Two files match." }], passed: 3, suggestion: "Run one page test file alone first." } };
const { s, card } = await lessonsCard(t, CARD([row]));
const li = rowOf(card, "c-sug");
assert.match(await textOf(li.locator(".lesson-suggestion")), /^Suggested wording: Run one page test file alone first\./);
await li.getByRole("button", { name: "Use this wording" }).click();
const edit = li.locator(".lessons-edit");
await edit.waitFor();
assert.equal(await li.getByRole("button", { name: "Reword" }).getAttribute("aria-pressed"), "true");
const text = edit.getByLabel("The lesson");
assert.equal(await text.inputValue(), "Run one page test file alone first.", "it opens on the suggestion, not the row's own words");
await text.fill("Run one page test file alone first, then the rest.");
const got = await sendAndCollect(s);
assert.deepEqual(got.actions.find((a) => a.i === "lessons").decisions, [
{ id: "c-sug", choice: "Reword", text: "Run one page test file alone first, then the rest.", why: "A full run hides the race." },
]);
});
test("lessons card: a flagged row says what was flagged", async (t) => {
const flagged = { ...ROWS[0], id: "w-flag", flags: [{ pattern: "email", part: "a@b.c" }] };
const { card } = await lessonsCard(t, CARD([flagged]));
+2 -1
View File
@@ -399,7 +399,7 @@ test("Implement's card launches Implement + Review when Review is ticked", () =>
assert.equal(launchVariant(quick, true), quick, "a card with no Review box is unchanged");
});
test("helper-strength.md ships in the seventeen skills that start helpers, and in no other", () => {
test("helper-strength.md ships in the eighteen skills that start helpers (the dashboard for its lesson check only), and in no other", () => {
// npm test has just built skills/; a direct run builds it so the check never reads a stale tree.
if (process.env.npm_lifecycle_event !== "test") {
execFileSync(process.execPath, [path.join(ROOT, "install.js"), "--build-skills"], { stdio: "ignore" });
@@ -407,6 +407,7 @@ test("helper-strength.md ships in the seventeen skills that start helpers, and i
const built = path.join(ROOT, "skills");
const having = fs.readdirSync(built).filter((dir) => fs.existsSync(path.join(built, dir, "references", "helper-strength.md")));
assert.deepEqual(having.sort(), [
"plan2code",
"plan2code-0-pathfinder",
"plan2code-1-plan",
"plan2code-1b-revise-plan",