import assert from "node:assert/strict"; import { test } from "node:test"; import { distinctTaskTypes, scanTaskDefinitions } from "./taskdef.ts"; const MODEL = ` `; test("scans taskDefinition leaves with process and element provenance", () => { const leaves = scanTaskDefinitions(MODEL); assert.deepEqual(leaves, [ { taskType: "planning.planner", process: "plan-fanout", elementId: "plan", agentic: false }, { taskType: "qa.tester", process: "plan-fanout", elementId: "test", agentic: false }, ]); }); test("skips service tasks without a task definition", () => { const leaves = scanTaskDefinitions(MODEL); assert.ok(!leaves.some((l) => l.elementId === "notype")); assert.ok(!leaves.some((l) => l.elementId === "approve")); }); test("tolerates attribute ordering (type before id on the task-definition)", () => { const xml = ` `; const leaves = scanTaskDefinitions(xml); assert.equal(leaves.length, 1); assert.equal(leaves[0].taskType, "ci.runner"); }); test("returns an empty process id when none is present", () => { const xml = ` `; const leaves = scanTaskDefinitions(xml); assert.equal(leaves[0].process, ""); }); test("tolerates whitespace around attribute equals signs (id / type / process id)", () => { const xml = ` `; const leaves = scanTaskDefinitions(xml); assert.deepEqual(leaves, [ { taskType: "ci.runner", process: "spaced-proc", elementId: "t", agentic: false }, ]); }); test("distinctTaskTypes de-duplicates in first-occurrence order", () => { assert.deepEqual( distinctTaskTypes([ { taskType: "b", process: "p", elementId: "1", agentic: false }, { taskType: "a", process: "p", elementId: "2", agentic: false }, { taskType: "b", process: "p", elementId: "3", agentic: false }, ]), ["b", "a"], ); }); test("marks a leaf agentic when it carries a linkName=\"prompt\" linked resource", () => { const xml = ` `; const leaves = scanTaskDefinitions(xml); assert.deepEqual(leaves, [ { taskType: "senior:retro", process: "nwf-retro", elementId: "retro", agentic: true }, { taskType: "pr.retro-gather", process: "nwf-retro", elementId: "gather", agentic: false }, ]); }); test("prompt detection tolerates attribute ordering (linkName before resourceId)", () => { const xml = ` `; assert.equal(scanTaskDefinitions(xml)[0].agentic, true); }); test("a non-prompt linked resource (other linkName) does not mark a leaf agentic", () => { const xml = ` `; assert.equal(scanTaskDefinitions(xml)[0].agentic, false); });