import { describe, expect, it } from "vitest"; import { BRIEF_FILE_NAME, buildObjective, renderBrief } from "./brief.ts"; import { emptyRoster, formatRow, type RosterRow, SECTIONS } from "./roster.ts"; const row: RosterRow = { difficulty: 2, provider: "ollama", model: "glm-5.3:cloud", effort: "high", concurrency: 3 }; const options = { taskDir: "/project/.selesai/tasks/6-example", implementerSkillPath: "/skills/plan-todo-implementer/SKILL.md" }; // Routing order: cheap, priority, fallback. const headings = [ "Cheap (try first)", "Priority (when no cheap row is strong enough)", "Fallback (only after a usage or rate limit)", ]; describe("renderBrief", () => { it("renders only the cheap heading for a cheap-only roster", () => { const roster = emptyRoster(); roster.sections.cheap.push(row); const brief = renderBrief({ ...options, roster }); expect(brief).toContain(`### ${headings[0]}`); expect(brief).toContain(`- ${formatRow(row)}`); expect(brief).not.toContain(headings[1]); expect(brief).not.toContain(headings[2]); }); it("renders all populated sections in cheap, priority, fallback order", () => { const roster = emptyRoster(); for (const section of SECTIONS) roster.sections[section].push(row); const brief = renderBrief({ ...options, roster }); const positions = headings.map((heading) => brief.indexOf(`### ${heading}`)); expect(positions.every((position) => position >= 0)).toBe(true); expect(positions[0]).toBeLessThan(positions[1]); expect(positions[1]).toBeLessThan(positions[2]); expect(brief.split(`- ${formatRow(row)}`)).toHaveLength(4); }); it("includes task, skill, procedure, scoring, and routing rules", () => { const roster = emptyRoster(); roster.sections.cheap.push(row); const brief = renderBrief({ ...options, roster }); expect(brief).toContain(`${options.taskDir}/plan.md`); expect(brief).toContain(`${options.taskDir}/todo.md`); expect(brief).toContain(`Read the skill at \`${options.implementerSkillPath}\` fully and follow it.`); expect(brief).toContain("do not ask for it again"); expect(brief).toContain('model: "/:"'); expect(brief).toContain("counts per provider/model, summed across all rows"); expect(brief).toContain("Commit only when a worktree writer needs a clean checkout"); expect(brief).toContain('action: "worktree.cleanup", options: { repo: "", mode: "plan" }'); expect(brief).toContain("contact_supervisor"); expect(brief).toContain("do it yourself as the supervisor. Do not ask the user."); expect(brief).toContain("tools.ask_sai("); expect(brief).toContain('"4 - meaningfully hard: novel design, cross-cutting, real blast radius"'); expect(brief).toContain("return answer.score + (1 - (answer.confidence ?? 0));"); expect(brief).not.toContain("Live run on 5 tasks"); // Procedure comes before scoring, routing, then the model rows. const order = ["## Procedure", "## Scoring", "## Routing", "## Models"].map((heading) => brief.indexOf(heading)); expect(order).toEqual([...order].sort((a, b) => a - b)); expect(brief).not.toContain("/goal "); expect(brief).not.toContain("go ahead with the implementations"); }); }); describe("buildObjective", () => { it("exports the filename and returns the exact objective", () => { expect(BRIEF_FILE_NAME).toBe("goal-brief.md"); expect(buildObjective("/task")).toBe("Implement the plan in /task exactly as specified in /task/goal-brief.md; read it and the skill file it names first."); }); it("keeps a 300-character path under the objective cap", () => { const objective = buildObjective("/" + "a".repeat(299)); expect(objective.length).toBeLessThan(4000); expect(objective).toContain("goal-brief.md"); }); it("accepts the largest representable objective below the cap and rejects the next", () => { const overhead = buildObjective("").length; const pathLength = Math.floor((3999 - overhead) / 2); expect(buildObjective("a".repeat(pathLength)).length).toBeLessThan(4000); expect(() => buildObjective("a".repeat(pathLength + 1))).toThrow("shorter than 4000"); }); });