feat: register generated apps with agent harness
This commit is contained in:
59
tests/harness.test.mjs
Normal file
59
tests/harness.test.mjs
Normal file
@@ -0,0 +1,59 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdtemp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import test from "node:test";
|
||||
|
||||
import { parseArguments } from "../dist/args.js";
|
||||
import { composeAgentHarness } from "../dist/harness.js";
|
||||
|
||||
async function createFixture(t) {
|
||||
const root = await mkdtemp(path.join(os.tmpdir(), "kri-create-next-harness-"));
|
||||
const harnessRoot = path.join(root, "_________AgentHarnessBase");
|
||||
const targetDir = path.join(root, "sample-front");
|
||||
const logPath = path.join(root, "calls.jsonl");
|
||||
await mkdir(path.join(harnessRoot, "dist"), { recursive: true });
|
||||
await mkdir(targetDir, { recursive: true });
|
||||
await writeFile(path.join(harnessRoot, "workspace.yml"), "schema_version: 1\nprojects: {}\n", "utf8");
|
||||
await writeFile(
|
||||
path.join(harnessRoot, "dist", "cli.cjs"),
|
||||
`const { appendFileSync } = require("node:fs");\nappendFileSync(${JSON.stringify(logPath)}, JSON.stringify(process.argv.slice(2)) + "\\n");\n`,
|
||||
"utf8",
|
||||
);
|
||||
t.after(() => rm(root, { recursive: true, force: true }));
|
||||
return { harnessRoot, targetDir, logPath };
|
||||
}
|
||||
|
||||
test("defaults to shared registration and accepts an explicit local override", () => {
|
||||
assert.equal(parseArguments([]).agentRegistration, "shared");
|
||||
assert.equal(
|
||||
parseArguments(["--agent-registration", "local"]).agentRegistration,
|
||||
"local",
|
||||
);
|
||||
assert.throws(
|
||||
() => parseArguments(["--agent-registration", "invalid"]),
|
||||
/shared 또는 local/,
|
||||
);
|
||||
});
|
||||
|
||||
test("registers shared, composes, and verifies in deterministic order", async (t) => {
|
||||
const { harnessRoot, targetDir, logPath } = await createFixture(t);
|
||||
|
||||
await composeAgentHarness({
|
||||
targetDir,
|
||||
agentProjectId: "sample-front",
|
||||
harnessRoot,
|
||||
agentRegistration: "shared",
|
||||
skipAgentCompose: false,
|
||||
});
|
||||
|
||||
const calls = (await readFile(logPath, "utf8"))
|
||||
.trim()
|
||||
.split("\n")
|
||||
.map((line) => JSON.parse(line));
|
||||
assert.deepEqual(calls, [
|
||||
["register", "--project", "sample-front", "--path", "sample-front", "--shared"],
|
||||
["compose", "--project", "sample-front"],
|
||||
["verify", "--project", "sample-front"],
|
||||
]);
|
||||
});
|
||||
Reference in New Issue
Block a user