repositories / pi-ext
pi-ext
bugabingas pi extensions
owned by bugabinga
extensions/ultra/__tests__/feature.test.ts
RawFile outline
- here line 12
- FEATURE_PATH line 13
- READ_ONLY_TOOLS line 17
- loadRaw line 19
- feature shipped workflow line 23
- parses through parseWorkflow (validates the actual shipped file) line 24
- takes a free-text task as a positional arg consumed by every phase line 36
- chains the phases: each consumes its predecessors' results line 46
- only `implement` (a single phase) may write; the fanout review stays read-only line 57
- reviews across security + quality, each echoing its dimension as the join key line 73
- returns the review verdicts, and the selector keeps each full row line 84
- is discoverable as a bundled workflow named `feature line 110
import * as fs from "node:fs";
import * as os from "node:os";
import * as path from "node:path";
import { fileURLToPath } from "node:url";
import { describe, expect, it } from "vitest";
import { resolveSelector } from "../interp.ts";
import { discoverWorkflows, parseWorkflow } from "../spec.ts";
// The shipped `feature` workflow — a linearized feature pipeline
// for ultra (which has no gate/loop/conditional): research → plan → critique →
// implement → review. It lives beside the bundled-workflows lookup.
const here = path.dirname(fileURLToPath(import.meta.url));
const FEATURE_PATH = path.join(here, "..", "workflows", "feature.json");
// Read-only allowlist for the v1 read-only-`fanout` rule. The single `implement`
// phase is exempt (it writes via edit/write); only `fanout` steps are checked.
const READ_ONLY_TOOLS = new Set(["read", "grep", "find", "ls", "bash"]);
function loadRaw(): string {
return fs.readFileSync(FEATURE_PATH, "utf8");
}
describe("feature shipped workflow", () => {
it("parses through parseWorkflow (validates the actual shipped file)", () => {
const spec = parseWorkflow(loadRaw());
expect(spec.name).toBe("feature");
expect(spec.phases.map((p) => p.id)).toEqual([
"research",
"plan",
"critique",
"implement",
"review",
]);
});
it("takes a free-text task as a positional arg consumed by every phase", () => {
const spec = parseWorkflow(loadRaw());
expect(spec.args?.params).toEqual(["task"]);
// research/critique/implement all scope to the task.
for (const id of ["research", "critique", "implement"]) {
const p = spec.phases.find((ph) => ph.id === id);
expect(p?.step.prompt).toContain("{args.task}");
}
});
it("chains the phases: each consumes its predecessors' results", () => {
const spec = parseWorkflow(loadRaw());
const get = (id: string) =>
spec.phases.find((p) => p.id === id)?.step.prompt ?? "";
expect(get("plan")).toContain("{research.results}");
expect(get("critique")).toContain("{plan.results}");
expect(get("implement")).toContain("{plan.results}");
expect(get("implement")).toContain("{critique.results}");
expect(get("review")).toContain("{implement.results}");
});
it("only `implement` (a single phase) may write; the fanout review stays read-only", () => {
const spec = parseWorkflow(loadRaw());
const implement = spec.phases.find((p) => p.id === "implement");
expect(implement?.kind).toBe("single");
expect(implement?.step.tools).toEqual(
expect.arrayContaining(["edit", "write"]),
);
for (const phase of spec.phases) {
if (phase.kind !== "fanout") continue; // the rule only binds fanout steps
for (const t of phase.step.tools ?? []) {
expect(READ_ONLY_TOOLS.has(t)).toBe(true);
}
}
});
it("reviews across security + quality, each echoing its dimension as the join key", () => {
const spec = parseWorkflow(loadRaw());
const review = spec.phases.find((p) => p.id === "review");
expect(review?.kind).toBe("fanout");
expect(review?.over).toEqual(["security", "quality"]);
// the verdict echoes `dimension` so a result ties back to its lens
expect(review?.step.prompt).toMatch(/dimension/);
const verdict = spec.schemas?.Verdict as { required?: string[] };
expect(verdict.required).toContain("dimension");
});
it("returns the review verdicts, and the selector keeps each full row", () => {
const spec = parseWorkflow(loadRaw());
expect(spec.return).toBe("{review.results}");
const ctx = {
results: {
review: [
{ dimension: "security", passed: true, findings: [] },
{
dimension: "quality",
passed: false,
findings: ["no tests"],
},
],
},
};
const out = resolveSelector(spec.return ?? "", ctx) as Array<
Record<string, unknown>
>;
expect(out).toHaveLength(2);
expect(out[1]).toEqual({
dimension: "quality",
passed: false,
findings: ["no tests"],
});
});
it("is discoverable as a bundled workflow named `feature`", () => {
const emptyCwd = fs.mkdtempSync(path.join(os.tmpdir(), "ultra-cwd-"));
const emptyHome = fs.mkdtempSync(path.join(os.tmpdir(), "ultra-home-"));
try {
const found = discoverWorkflows(emptyCwd, { home: emptyHome });
const feature = found.find((w) => w.name === "feature");
expect(feature).toBeDefined();
expect(feature?.source).toBe("bundled");
} finally {
fs.rmSync(emptyCwd, { recursive: true, force: true });
fs.rmSync(emptyHome, { recursive: true, force: true });
}
});
});