mirror of
https://github.com/shinyobjectz/raea.git
synced 2026-12-01 12:44:11 -10:00
The rules are raea/goal's (sdk/goal), run by `raea goal check` at four moments: the hook after a save, every render's end, raea cloud's publish, and the Stop hook. Rust's cut and goal gates and the box's word, sound, frame and place checks are packs (MK30-MK39); runtime/cut-plan, runtime/goal-plan, raea make status and the box's check code are gone with no alias (MK41). brief.ts is the one registered root (MK43): raea runs it, and every file that imports raea must be reached from it (the registered check, an error at publish and done). Its tasks are its `plan` (MK44), read from its run and written back where each is written by `raea goal tasks`, the one path for the app, agents and the box. Its `goal` is one goal or a workflow of several (MK46), each with its step, after and rules, checked and reported alone. Taste lines and signed asks run inside the loop (MK47). `raea goal check|tasks|seen|judge|gates|next` is the loop; `raea make clothes|motion|solid|wear|splat|physics|bake| sao|tokensynth|sounds|component|blockout|...` the asset tools (MK45). Old names are refused with where they went. docs/make.feature is docs/goal.feature; tools/legacy-names.sh holds the old names out. raea's Node mode on JavaScriptCore now gives a CommonJS package's names as named exports (React's jsx), loads a file a tool imports by URL, keeps process.exit's code from a promise callback, and reads stdin as fd 0, so the goal runner runs on the shipped binary.
195 lines
10 KiB
TypeScript
195 lines
10 KiB
TypeScript
// PL3: every change by task id, every other task as it was (src/edit.ts), and the plan as values (src/model.ts), on a
|
|
// plan.ts (docs/goal.feature MK40).
|
|
import { describe, expect, test } from "vitest"
|
|
import { createRegistry, defineKeywords, find, planDigest, toggled, type PlanEdit } from "../src"
|
|
import { applyEdits, newPlan, readPlan } from "./text"
|
|
|
|
const NOW = new Date(2026, 10, 14, 16, 40)
|
|
let n = 0
|
|
const ids = () => `t-${++n}`
|
|
const apply = (text: string, edits: PlanEdit[]) => applyEdits(text, edits, { now: NOW, newId: ids })
|
|
|
|
const PLAN = `import { plan } from "raea/task"
|
|
|
|
export default plan({
|
|
title: "Ides",
|
|
keywords: ["TODO MAKING REVIEW | DONE DROPPED"],
|
|
tasks: [
|
|
{
|
|
title: "Act one",
|
|
tasks: [
|
|
{
|
|
id: "t-rome",
|
|
keyword: "TODO",
|
|
title: "Rome storyboard",
|
|
notes: ["Notes a person wrote, kept."],
|
|
tasks: [
|
|
{ id: "t-forum", keyword: "TODO", title: "The forum" },
|
|
{ id: "t-steps", keyword: "TODO", title: "The steps" },
|
|
],
|
|
},
|
|
{ id: "t-cast", keyword: "DONE", title: "Cast the narrator", closed: "2026-11-02 10:14" },
|
|
],
|
|
},
|
|
{
|
|
title: "Sound",
|
|
tasks: [{ keyword: "TODO", title: "Foley for the fire" }],
|
|
},
|
|
],
|
|
})
|
|
`
|
|
|
|
describe("PL2: the plan as values", () => {
|
|
const p = readPlan(PLAN)
|
|
test("tasks and the headings that group them; states from the keywords; stages, parents and progress", () => {
|
|
expect(p.problem).toBeUndefined()
|
|
expect(p.title).toBe("Ides")
|
|
expect(p.entries.map((t) => [t.ref, t.keyword ?? "", t.state ?? "", t.stage])).toEqual([
|
|
["#0", "", "", ""],
|
|
["t-rome", "TODO", "todo", "Act one"],
|
|
["t-forum", "TODO", "todo", "Act one"],
|
|
["t-steps", "TODO", "todo", "Act one"],
|
|
["t-cast", "DONE", "done", "Act one"],
|
|
["#5", "", "", ""],
|
|
["#6", "TODO", "todo", "Sound"],
|
|
])
|
|
expect(find(p, "t-rome")!.children).toEqual(["t-forum", "t-steps"])
|
|
expect(find(p, "t-rome")!.progress).toEqual({ done: 0, total: 2 })
|
|
expect(find(p, "t-rome")!.body).toBe("Notes a person wrote, kept.")
|
|
expect(find(p, "t-cast")!.closed).toMatchObject({ date: "2026-11-02", time: "10:14" })
|
|
})
|
|
test("a plan's own keywords are read with their states", () => {
|
|
const own = readPlan(`export default plan({ keywords: ["OPEN NEXT | SHIPPED KILLED"], tasks: [{ keyword: "NEXT", title: "a" }, { keyword: "KILLED", title: "b" }, { keyword: "REVIEW", title: "c" }] })`)
|
|
expect(own.tasks.map((t) => [t.keyword, t.state])).toEqual([
|
|
["NEXT", "making"],
|
|
["KILLED", "dropped"],
|
|
["REVIEW", "review"],
|
|
])
|
|
})
|
|
test("a text that isn't a plan reads empty and says why; an edit to it throws", () => {
|
|
const bad = readPlan("export default plan({ tasks: [ { title: 'a' } ")
|
|
expect(bad.entries).toEqual([])
|
|
expect(bad.problem).toMatch(/line 1/)
|
|
expect(() => apply("export default plan({ tasks: [{ title: \"x\", deadline: \"soon\" }] })", [{ op: "add", title: "y" }])).toThrow(/deadline "soon"/)
|
|
})
|
|
})
|
|
|
|
describe("PL3: edits by id", () => {
|
|
test("closing a subtask records when, links what was made; every other task is as it was", () => {
|
|
const r = apply(PLAN, [{ op: "state", ref: "t-forum", state: "done", item: "i-forum-1", note: "Made the forum still." }])
|
|
expect(r.refs).toEqual(["t-forum"])
|
|
expect(r.text).toContain(`{
|
|
id: "t-forum",
|
|
keyword: "DONE",
|
|
title: "The forum",
|
|
closed: "2026-11-14 16:40",
|
|
props: {
|
|
ITEM: "i-forum-1",
|
|
},
|
|
notes: ["Made the forum still."],
|
|
}`)
|
|
expect(find(r.plan, "t-rome")!.progress).toEqual({ done: 1, total: 2 })
|
|
const others = (text: string) => readPlan(text).entries.filter((t) => t.id !== "t-forum").map(({ index: _, ...t }) => t)
|
|
expect(others(r.text).map((t) => [t.ref, t.title, t.body])).toEqual(others(PLAN).map((t) => [t.ref === "#6" ? "t-1" : t.ref, t.title, t.body]))
|
|
// and opened again: closed comes off
|
|
const back = apply(r.text, [toggled(find(r.plan, "t-forum")!)])
|
|
expect(find(back.plan, "t-forum")).toMatchObject({ keyword: "TODO" })
|
|
expect(find(back.plan, "t-forum")!.closed).toBeUndefined()
|
|
})
|
|
test("add: under a heading by its words (made when missing), with priority, tags, deadline, agent and checkboxes", () => {
|
|
n = 0
|
|
const r = apply(PLAN, [
|
|
{ op: "add", title: "Senate theme, final mix", under: "Sound", priority: "a", tags: ["trailer", "final-mix"], deadline: "11-20", agents: ["a-score"], from: "m-1", checks: ["stems", "master"] },
|
|
{ op: "add", title: "Colour the titles", under: "Look" },
|
|
])
|
|
expect(r.refs).toEqual(["t-1", "t-2"])
|
|
expect(r.text).toContain(`{
|
|
id: "t-1",
|
|
keyword: "TODO",
|
|
priority: "A",
|
|
title: "Senate theme, final mix",
|
|
tags: ["trailer", "final_mix"],
|
|
deadline: "2026-11-20",
|
|
props: {
|
|
AGENT: "a-score",
|
|
FROM: "m-1",
|
|
},
|
|
notes: ["- [ ] stems", "- [ ] master"],
|
|
}`)
|
|
expect(r.plan.entries.at(-2)).toMatchObject({ text: "Look", level: 1 })
|
|
expect(r.plan.entries.at(-1)).toMatchObject({ id: "t-2", stage: "Look", level: 2 })
|
|
// the task with no id got one on this write (t-3), so every task can be named from now on
|
|
expect(find(r.plan, "t-3")?.text).toBe("Foley for the fire")
|
|
expect(find(r.plan, "t-1")).toMatchObject({ priority: "A", tags: ["trailer", "final_mix"], agents: ["a-score"], from: "m-1", stage: "Sound", progress: { done: 0, total: 2 } })
|
|
})
|
|
test("#N names an entry with no id as the plan was before the edits, even after an add moved it", () => {
|
|
const r = apply(PLAN, [
|
|
{ op: "add", title: "First", before: "t-rome" },
|
|
{ op: "set", ref: "#6", title: "Foley for the fire and the crowd" },
|
|
])
|
|
expect(r.plan.tasks.at(-1)!.text).toBe("Foley for the fire and the crowd")
|
|
})
|
|
test("move: a subtree goes before another task, taking its level; under a heading; never into itself", () => {
|
|
const r = apply(PLAN, [{ op: "move", ref: "t-rome", before: "#6" }])
|
|
expect(readPlan(r.text).entries.map((t) => `${t.level}${t.text}`)).toEqual(["1Act one", "2Cast the narrator", "1Sound", "2Rome storyboard", "3The forum", "3The steps", "2Foley for the fire"])
|
|
const up = apply(PLAN, [{ op: "move", ref: "t-forum", under: "Sound" }])
|
|
expect(find(up.plan, "t-forum")).toMatchObject({ level: 2, stage: "Sound" })
|
|
expect(find(up.plan, "t-rome")!.progress).toEqual({ done: 0, total: 1 })
|
|
expect(() => apply(PLAN, [{ op: "move", ref: "t-rome", after: "t-steps" }])).toThrow(/into itself/)
|
|
})
|
|
test("set and remove; a checkbox ticked and one added; what's wrong is said and nothing is written", () => {
|
|
const r = apply(PLAN, [
|
|
{ op: "set", ref: "t-steps", deadline: "2026-11-21", tags: ["gate"], props: { SHOT: "12" } },
|
|
{ op: "remove", ref: "t-cast" },
|
|
])
|
|
expect(find(r.plan, "t-steps")).toMatchObject({ deadline: { date: "2026-11-21" }, tags: ["gate"], props: { ID: "t-steps", SHOT: "12" } })
|
|
expect(find(r.plan, "t-cast")).toBeUndefined()
|
|
const c = apply(`export default plan({ tasks: [{ id: "g", keyword: "TODO", title: "Grade", notes: ["- [ ] warm", "- [ ] cool"] }] })`, [{ op: "check", ref: "g", index: 1 }, { op: "check", ref: "g", add: "contrast" }])
|
|
expect(find(c.plan, "g")!.body).toBe("- [ ] warm\n- [X] cool\n- [ ] contrast")
|
|
expect(find(c.plan, "g")!.progress).toEqual({ done: 1, total: 3 })
|
|
expect(() => apply(PLAN, [{ op: "state", ref: "t-nope", state: "done" }])).toThrow(/no task t-nope/)
|
|
expect(() => apply(PLAN, [{ op: "state", ref: "t-rome", state: "finished" }])).toThrow(/neither a keyword nor a state/)
|
|
expect(() => apply(PLAN, [{ op: "set", ref: "t-rome", deadline: "someday" }])).toThrow(/YYYY-MM-DD/)
|
|
})
|
|
test("a plan written by hand keeps its fields and its dates through an edit", () => {
|
|
const mine = `// Kept by hand.
|
|
import { plan } from "raea/task"
|
|
|
|
export default plan({
|
|
title: 'Kept by hand',
|
|
notes: ['What this plan is for.'],
|
|
tasks: [
|
|
{ title: 'Work', tags: ['look'], tasks: [
|
|
{ id: 't-door', keyword: 'TODO', priority: 'B', title: 'Light the door', scheduled: '2026-11-20', deadline: '2026-11-22 10:00 -2d', props: { EFFORT: '1:00' } },
|
|
{ id: 't-score', keyword: 'TODO', title: 'Score it' }, // trailing comma kept out
|
|
] },
|
|
],
|
|
})
|
|
`
|
|
const r = apply(mine, [{ op: "state", ref: "t-door", state: "done" }])
|
|
expect(find(r.plan, "t-door")).toMatchObject({ keyword: "DONE", priority: "B", scheduled: { date: "2026-11-20" }, deadline: { date: "2026-11-22", time: "10:00", warn: "-2d" }, closed: { date: "2026-11-14", time: "16:40" }, props: { EFFORT: "1:00" } })
|
|
expect(find(r.plan, "t-score")).toMatchObject({ keyword: "TODO", inherited: ["look"] })
|
|
expect(r.plan.doc.notes).toEqual(["What this plan is for."])
|
|
})
|
|
test("under a task's id that isn't there is a mistake, not a stage to make", () => {
|
|
expect(() => apply(PLAN, [{ op: "add", title: "x", under: "t-gone" }])).toThrow(/no task t-gone/)
|
|
expect(() => apply(PLAN, [{ op: "move", ref: "t-forum", under: "#99" }])).toThrow(/no task #99/)
|
|
})
|
|
test("a plugin's keyword written into a plan that doesn't name it adds its sequence to the plan's keywords", () => {
|
|
const reg = createRegistry()
|
|
defineKeywords({ name: "shots", words: "SHOT LIT | APPROVED" }, reg)
|
|
const r = applyEdits(PLAN, [{ op: "add", title: "Shot 12", state: "SHOT" }], { now: NOW, registry: reg })
|
|
expect(r.plan.doc.keywords).toEqual(["TODO MAKING REVIEW | DONE DROPPED", "SHOT LIT | APPROVED"])
|
|
// raea's own words need none
|
|
const own = applyEdits(`export default plan({ tasks: [{ id: "a", keyword: "TODO", title: "a" }] })`, [{ op: "state", ref: "a", state: "making" }], { now: NOW })
|
|
expect(own.plan.doc.keywords).toEqual([])
|
|
expect(find(own.plan, "a")!.keyword).toBe("MAKING")
|
|
})
|
|
test("a new plan is raea's keywords spelled out; the digest an agent reads lists open tasks by id", () => {
|
|
expect(newPlan("Pong")).toBe('import { plan } from "raea/task"\n\nexport default plan({\n title: "Pong",\n keywords: ["TODO MAKING REVIEW | DONE DROPPED"],\n tasks: [],\n})\n')
|
|
const r = apply(newPlan("Pong"), [{ op: "add", title: "Tune the paddle", under: "Feel" }, { op: "add", title: "Old idea", state: "dropped" }])
|
|
expect(r.plan.entries.map((t) => `${t.level} ${t.keyword ?? ""} ${t.text}`)).toEqual(["1 Feel", "2 TODO Tune the paddle", "1 DROPPED Old idea"])
|
|
expect(planDigest(r.plan)).toMatch(/^Feel:\n {2}- t-\d+ {2}TODO {2}Tune the paddle\n1 closed \(done or dropped\)\.$/)
|
|
})
|
|
})
|