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-spring-harness-")); const harnessRoot = path.join(root, "_________AgentHarnessBase"); const targetDir = path.join(root, "sample-server"); 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-server", 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-server", "--path", "sample-server", "--shared"], ["compose", "--project", "sample-server"], ["verify", "--project", "sample-server"], ]); });