feat(harness): add orchestration plan helpers

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
2026-03-24 18:34:56 +08:00
parent fe24dfba68
commit 704cacfd8d
3 changed files with 511 additions and 8 deletions
+134
View File
@@ -0,0 +1,134 @@
// @vitest-environment node
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import {
legacyOrchBinPath,
parsePlanTaskSketch,
resolveOrchBinary,
writeTaskBodyFile
} from "./orch-support.mjs";
const tempDirs: string[] = [];
afterEach(() => {
for (const directory of tempDirs.splice(0)) {
fs.rmSync(directory, { force: true, recursive: true });
}
});
function createTempDir(prefix: string) {
const directory = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
tempDirs.push(directory);
return directory;
}
describe("parsePlanTaskSketch", () => {
it("parses plan tasks and inline dependencies from the task sketch", () => {
const parsed = parsePlanTaskSketch(`# Example Plan
## Orchestration Task Sketch
- \`T1\`: stabilize smoke coverage
- \`T2 -> T1, T3\`: reconcile browser validation
## Status Log
`);
expect(parsed.planTitle).toBe("Example Plan");
expect(parsed.tasks).toEqual([
{
dependsOn: [],
id: "T1",
title: "stabilize smoke coverage"
},
{
dependsOn: ["T1", "T3"],
id: "T2",
title: "reconcile browser validation"
}
]);
});
});
describe("resolveOrchBinary", () => {
it("prefers CADENCE_UI_ORCH_BIN when it points to an existing binary", () => {
const tempDir = createTempDir("cadence-orch-explicit-");
const explicitBinary = path.join(tempDir, process.platform === "win32" ? "orch.exe" : "orch");
fs.writeFileSync(explicitBinary, "", "utf8");
expect(
resolveOrchBinary({
env: {
CADENCE_UI_ORCH_BIN: explicitBinary,
PATH: ""
}
})
).toMatchObject({
binaryPath: explicitBinary,
source: "CADENCE_UI_ORCH_BIN"
});
});
it("falls back to PATH before the legacy location", () => {
const tempDir = createTempDir("cadence-orch-path-");
const pathBinary = path.join(tempDir, process.platform === "win32" ? "orch.exe" : "orch");
fs.writeFileSync(pathBinary, "", "utf8");
expect(
resolveOrchBinary({
env: {
PATH: tempDir
}
})
).toMatchObject({
binaryPath: pathBinary,
source: "PATH"
});
});
it("returns the checked locations when no binary exists", () => {
expect(
resolveOrchBinary({
env: {
CADENCE_UI_ORCH_BIN: "/missing/orch",
PATH: ""
},
existsSync: () => false
})
).toEqual({
binaryPath: null,
checkedPaths: [path.resolve("/missing/orch"), legacyOrchBinPath],
source: null
});
});
});
describe("writeTaskBodyFile", () => {
it("writes a generated task body under the run-specific artifact directory", () => {
const bodyRoot = createTempDir("cadence-orch-bodies-");
const outputPath = writeTaskBodyFile({
bodyRoot,
plan: {
planTitle: "Harness Hardening",
relativePath: "docs/exec-plans/2026-03-24-harness-control-plane-hardening.md"
},
runId: "cadence ui demo",
task: {
dependsOn: ["T0"],
id: "T1",
title: "stabilize changed-suite selection"
}
});
expect(outputPath).toContain(path.join("cadence-ui-demo", "T1.md"));
expect(fs.readFileSync(outputPath, "utf8")).toContain("# T1 — stabilize changed-suite selection");
expect(fs.readFileSync(outputPath, "utf8")).toContain("Dependencies: T0");
});
});