import test from "node:test"; import assert from "node:assert/strict"; import { targetAgent, agentKey, agentName, agentStatus, createGate, gatePasses, openGate, closeGate, isPlainEnter, statusText, queueLabel, applySuggestion, insertedNewline, } from "../mod/ovis-composer/view.js"; const agents = [{ address: "t1", app: "claude-code" }, { address: "a2" }]; test("targetAgent picks by focused.terminal, then focused.agent", () => { assert.equal(targetAgent(agents, { terminal: "t1" }), agents[0]); assert.equal(targetAgent(agents, { agent: "a2" }), agents[1]); assert.equal(targetAgent(agents, { terminal: "zz" }), null); assert.equal(targetAgent(agents, null), null); }); test("agentKey/agentName/agentStatus", () => { assert.equal(agentKey({ address: " x " }), "x"); assert.equal(agentName({ program: { key: "k" } }), "k"); assert.equal(agentName(null), "default"); assert.equal(agentStatus({}), "idle"); }); test("gate: opens after a seen turn, or outright", () => { let g = createGate(); assert.equal(gatePasses(g, "idle"), false); assert.equal(gatePasses({ sawWorking: true }, "done"), true); g = openGate(g); assert.equal(gatePasses(g, "working"), true); g = closeGate(g); assert.equal(gatePasses(g, "idle"), false); }); test("isPlainEnter", () => { assert.equal(isPlainEnter({}), true); assert.equal(isPlainEnter({ shift: true }), false); assert.equal(isPlainEnter({ secondary: true }), false); assert.equal(isPlainEnter(null), false); }); test("labels", () => { assert.equal(statusText("working"), "pracuje"); assert.equal(statusText("x"), "gotowy"); assert.equal(queueLabel({ state: "queued" }), "Następna tura"); assert.equal(queueLabel({}), ""); }); test("applySuggestion replaces token and places caret", () => { assert.deepEqual(applySuggestion("ala /re", 7, { start: 4 }, "/review "), { value: "ala /review ", caret: 12 }); }); test("insertedNewline finds the index", () => { assert.deepEqual(insertedNewline("ab", "a\nb"), { index: 1 }); assert.equal(insertedNewline("ab", "abc"), null); }); test("canAutoSend waits for the draft/identity check of the agent", async () => { const { canAutoSend } = await import("../mod/ovis-composer/view.js"); assert.equal(canAutoSend(new Set(), "t2"), false); assert.equal(canAutoSend(new Set(["t2"]), "t2"), true); assert.equal(canAutoSend(new Set(["t3"]), "t2"), false); assert.equal(canAutoSend(null, "t2"), false); }); test("queueLabel for every state", () => { assert.equal(queueLabel({ state: "queued" }), "Następna tura"); assert.equal(queueLabel({ state: "held" }), "Wstrzymana — wyślij ręcznie"); assert.equal(queueLabel({ state: "sending" }), "Wysyłanie…"); assert.equal(queueLabel({ state: "uncertain" }), "Nie potwierdzono"); assert.equal(queueLabel({ state: "countdown", left: 2 }), "Wysyłam za 2 s"); }); import { stillSameAgent } from "../mod/ovis-composer/view.js"; test("stillSameAgent: only when the field and the focus are on one agent", () => { assert.equal(stillSameAgent({ before: "t2", after: "t2", target: "t2" }), true); // the focus moved to t3 while the field still showed t2: the sync switched the field assert.equal(stillSameAgent({ before: "t2", after: "t3", target: "t3" }), false); // the focus is on something that is not an agent assert.equal(stillSameAgent({ before: "t2", after: "", target: "" }), false); assert.equal(stillSameAgent({ before: "", after: "", target: "" }), false); assert.equal(stillSameAgent({ before: "", after: "t2", target: "t2" }), false); });