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.
99 lines
6.0 KiB
TypeScript
99 lines
6.0 KiB
TypeScript
// MK43: an edit is written back where each task is written (src/source.ts), however the brief composes its plan:
|
|
// inline, a plan.ts it imports, or modules of its own; what code makes is refused, naming its file and line.
|
|
import { describe, expect, test } from "vitest"
|
|
import { applyEdits } from "../src/edit.ts"
|
|
import type { PlanFile } from "../src/doc.ts"
|
|
import { registerPlan, writeBack, type Source } from "../src/source.ts"
|
|
|
|
const NOW = new Date(2026, 10, 29, 9, 30)
|
|
const opts = { now: NOW, newId: () => "t-new00001" }
|
|
|
|
/** the edits on `plan` (as the brief's run gives it), written back into `sources` */
|
|
function edit(sources: Source[], plan: PlanFile | undefined, edits: Parameters<typeof applyEdits>[1]) {
|
|
const r = applyEdits(plan, edits, opts)
|
|
return { ...writeBack(sources, plan, r.file), file: r.file }
|
|
}
|
|
|
|
describe("MK43: an edit written back where the task is written", () => {
|
|
test("a plan.ts of plain values: the plan's literal rewritten, every line around it kept", () => {
|
|
const text = `// the shots, by hand
|
|
import { plan } from "raea/task"
|
|
|
|
export default plan({
|
|
tasks: [{ id: "t-door", keyword: "TODO", title: "Light the door" }],
|
|
})
|
|
// after
|
|
`
|
|
const plan: PlanFile = { tasks: [{ id: "t-door", keyword: "TODO", title: "Light the door" }] }
|
|
const r = edit([{ file: "plan.ts", text }], plan, [{ op: "state", ref: "t-door", state: "done" }])
|
|
expect(r.changed).toHaveLength(1)
|
|
expect(r.changed[0].text.startsWith('// the shots, by hand\nimport { plan } from "raea/task"\n\nexport default plan({\n tasks: [\n {\n id: "t-door",\n keyword: "DONE",\n title: "Light the door",\n closed: "2026-11-29 09:30",')).toBe(true)
|
|
expect(r.changed[0].text).toEndWith("})\n// after\n")
|
|
})
|
|
|
|
test("a plan inline in brief.ts, beside a contract made by calls: only the plan's literal changes", () => {
|
|
const text = `import { brief, cut } from "raea/brief"
|
|
|
|
export default brief({
|
|
title: "Spring",
|
|
goal: cut({ deliverables: ["spring_9x16.mp4"] }),
|
|
plan: plan({ tasks: [{ id: "t-cut", keyword: "TODO", title: "First cut" }] }),
|
|
})
|
|
`
|
|
const plan: PlanFile = { tasks: [{ id: "t-cut", keyword: "TODO", title: "First cut" }] }
|
|
const r = edit([{ file: "brief.ts", text }], plan, [{ op: "add", title: "Sound pass" }])
|
|
const out = r.changed[0].text
|
|
expect(out).toContain('goal: cut({ deliverables: ["spring_9x16.mp4"] }),')
|
|
expect(out).toContain(' plan: plan({\n tasks: [\n {\n id: "t-cut",')
|
|
expect(out).toContain('title: "Sound pass"')
|
|
})
|
|
|
|
test("a plan composed by code: a task written as plain values in another module changes there; the list itself can't", () => {
|
|
const plan = `import { plan } from "raea/task"
|
|
import { shots } from "./shots.ts"
|
|
|
|
export default plan({ tasks: [...shots, { id: "t-grade", keyword: "TODO", title: "Grade" }] })
|
|
`
|
|
const shots = `export const shots = [
|
|
{ id: "t-s1", keyword: "TODO", title: "Shot 1" },
|
|
{ id: "t-s2", keyword: "TODO", title: "Shot 2" },
|
|
]
|
|
`
|
|
const sources = [{ file: "plan.ts", text: plan }, { file: "shots.ts", text: shots }]
|
|
const value: PlanFile = { tasks: [{ id: "t-s1", keyword: "TODO", title: "Shot 1" }, { id: "t-s2", keyword: "TODO", title: "Shot 2" }, { id: "t-grade", keyword: "TODO", title: "Grade" }] }
|
|
const r = edit(sources, value, [{ op: "state", ref: "t-s2", state: "done" }])
|
|
expect(r.changed.map((c) => c.file)).toEqual(["shots.ts"])
|
|
expect(r.changed[0].text).toContain('{ id: "t-s1", keyword: "TODO", title: "Shot 1" },\n {\n id: "t-s2",\n keyword: "DONE",')
|
|
const g = edit(sources, value, [{ op: "set", ref: "t-grade", title: "Grade it warm" }])
|
|
expect(g.changed.map((c) => c.file)).toEqual(["plan.ts"])
|
|
expect(g.changed[0].text).toContain("...shots, {")
|
|
expect(() => edit(sources, value, [{ op: "add", title: "Deliver" }])).toThrow(/the plan's own list is made by code at plan\.ts:4: add, move or remove its top tasks there by hand/)
|
|
})
|
|
|
|
test("a task made by code is refused, naming where; nothing is written", () => {
|
|
const shots = `const names = ["Shot 1", "Shot 2"]
|
|
export const shots = names.map((title, i) => ({ id: \`t-s\${i}\`, keyword: "TODO", title }))
|
|
`
|
|
const sources = [{ file: "plan.ts", text: `export default plan({ tasks: [{ title: "Shots", tasks: shots }] })` }, { file: "shots.ts", text: shots }]
|
|
const value: PlanFile = { tasks: [{ title: "Shots", tasks: [{ id: "t-s0", keyword: "TODO", title: "Shot 1" }] }] }
|
|
expect(() => edit(sources, value, [{ op: "state", ref: "t-s0", state: "done" }])).toThrow(/t-s0 isn't written in any file the brief reaches: it's made by code/)
|
|
})
|
|
|
|
test("a task written without an id is given one where it's written, found by its words", () => {
|
|
const text = `export default plan({ tasks: [...more, { keyword: "TODO", title: "By hand" }] })`
|
|
const value: PlanFile = { tasks: [{ id: "t-a", keyword: "TODO", title: "A" }, { keyword: "TODO", title: "By hand" }] }
|
|
const r = edit([{ file: "plan.ts", text }, { file: "more.ts", text: 'export const more = [{ id: "t-a", keyword: "TODO", title: "A" }]' }], value, [])
|
|
expect(r.changed.map((c) => c.file)).toEqual(["plan.ts"])
|
|
expect(r.changed[0].text).toBe('export default plan({ tasks: [...more, {\n id: "t-new00001",\n keyword: "TODO",\n title: "By hand",\n}] })')
|
|
})
|
|
|
|
test("a project with no plan: a plan.ts to make, and the brief given it", () => {
|
|
const r = edit([{ file: "brief.ts", text: 'import { brief } from "raea/brief"\n\nexport default brief({\n title: "Spring",\n})\n' }], undefined, [{ op: "add", title: "First cut" }])
|
|
expect(r.changed).toEqual([])
|
|
expect(r.created!.file).toBe("plan.ts")
|
|
expect(r.created!.text.startsWith('import { plan } from "raea/task"\n\nexport default plan({\n')).toBe(true)
|
|
expect(registerPlan('import { brief } from "raea/brief"\n\nexport default brief({\n title: "Spring",\n})\n')).toBe('import { brief } from "raea/brief"\nimport plan from "./plan.ts"\n\nexport default brief({\n plan,\n title: "Spring",\n})\n')
|
|
expect(() => registerPlan('export default brief({ title: "x", plan: makePlan() })')).toThrow(/already names a plan/)
|
|
})
|
|
})
|