chore: import ovis-composer into repo with baseline tests
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
1 parent
edf09cf532
commit
c05e252d79
21 files changed
+4312
No files matched your search
@@ -0,0 +1,38 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { LIMITS, validate, validateMany, mention, removeMention } from "../mod/ovis-composer/attachments.js";
|
||||
|
||||
test("validate rejects over 32 MiB", () => {
|
||||
const r = validate({ bytes: 33 * 2 ** 20 });
|
||||
assert.equal(r.ok, false);
|
||||
assert.equal(r.reason, "Plik przekracza limit 32 MiB");
|
||||
});
|
||||
|
||||
test("validate accepts a normal file and an image", () => {
|
||||
assert.deepEqual(validate({ name: "a.txt", bytes: 10 }), { ok: true });
|
||||
assert.deepEqual(validate({ name: "a.png", bytes: 10 }), { ok: true });
|
||||
});
|
||||
|
||||
test("validate rejects junk and unknown kind", () => {
|
||||
assert.equal(validate(null).ok, false);
|
||||
assert.equal(validate({ bytes: NaN }).ok, false);
|
||||
assert.equal(validate({ kind: "video", bytes: 1 }).ok, false);
|
||||
});
|
||||
|
||||
test("validateMany enforces count limit", () => {
|
||||
assert.equal(LIMITS.filesPerAction, 100);
|
||||
const files = Array.from({ length: 101 }, () => ({ name: "a", bytes: 1 }));
|
||||
assert.equal(validateMany(files).ok, false);
|
||||
assert.equal(validateMany(files.slice(0, 100)).ok, true);
|
||||
});
|
||||
|
||||
test("mention", () => {
|
||||
assert.equal(mention(" /a/b "), "@/a/b");
|
||||
assert.equal(mention(""), "");
|
||||
assert.equal(mention(5), "");
|
||||
});
|
||||
|
||||
test("removeMention removes only the standalone token", () => {
|
||||
assert.equal(removeMention("see @src/a.rs now", "src/a.rs"), "see now");
|
||||
assert.equal(removeMention("see @src/a.rsx now", "src/a.rs"), "see @src/a.rsx now");
|
||||
});
|
||||
@@ -0,0 +1,37 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { decide, gateAfter, onRestart } from "../mod/ovis-composer/delivery.js";
|
||||
|
||||
test("decide idle/done -> send", () => {
|
||||
assert.equal(decide("idle").kind, "send");
|
||||
assert.equal(decide("done").kind, "send");
|
||||
});
|
||||
|
||||
test("decide working -> queue, blocked -> hold", () => {
|
||||
assert.equal(decide("working").kind, "queue");
|
||||
assert.equal(decide("blocked").kind, "hold");
|
||||
});
|
||||
|
||||
test("decide unknown status -> queue", () => {
|
||||
assert.equal(decide("error").kind, "queue");
|
||||
});
|
||||
|
||||
test("gateAfter needs a seen working turn", () => {
|
||||
assert.equal(gateAfter("idle", false), false);
|
||||
assert.equal(gateAfter("idle", true), true);
|
||||
assert.equal(gateAfter("done", true), true);
|
||||
assert.equal(gateAfter("working", true), false);
|
||||
});
|
||||
|
||||
test("onRestart sending -> uncertain, others untouched", () => {
|
||||
const out = onRestart([
|
||||
{ id: "1", state: "sending" },
|
||||
{ id: "2", state: "queued" },
|
||||
{ id: "3", state: "held" },
|
||||
]);
|
||||
assert.deepEqual(out.map((i) => i.state), ["uncertain", "queued", "held"]);
|
||||
});
|
||||
|
||||
test("onRestart tolerates non-array", () => {
|
||||
assert.deepEqual(onRestart(null), []);
|
||||
});
|
||||
@@ -0,0 +1,60 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { createState, reduce, isSending } from "../mod/ovis-composer/state.js";
|
||||
|
||||
test("createState starts empty", () => {
|
||||
const s = createState();
|
||||
assert.deepEqual(s.drafts, {});
|
||||
assert.deepEqual(s.queue, {});
|
||||
assert.equal(s.menu, null);
|
||||
});
|
||||
|
||||
test("draft then send clears the draft", () => {
|
||||
let s = reduce(createState(), { type: "draft", agent: "a", text: "hi" });
|
||||
assert.equal(s.drafts.a, "hi");
|
||||
s = reduce(s, { type: "send", agent: "a" });
|
||||
assert.equal(s.drafts.a, "");
|
||||
});
|
||||
|
||||
test("reduce never mutates", () => {
|
||||
const s = createState();
|
||||
const n = reduce(s, { type: "draft", agent: "a", text: "x" });
|
||||
assert.notEqual(s, n);
|
||||
assert.deepEqual(s.drafts, {});
|
||||
});
|
||||
|
||||
test("queue adds item and isSending sees only sending state", () => {
|
||||
let s = reduce(createState(), { type: "queue", agent: "a", item: { id: "1", text: "t", createdAt: 1 } });
|
||||
assert.equal(s.queue.a[0].state, "queued");
|
||||
assert.equal(isSending(s, "a"), false);
|
||||
s = reduce(s, { type: "restore", agent: "a", items: [{ id: "2", text: "t", state: "sending", createdAt: 2 }] });
|
||||
assert.equal(isSending(s, "a"), true);
|
||||
assert.equal(isSending(s, "b"), false);
|
||||
});
|
||||
|
||||
test("queue without createdAt throws", () => {
|
||||
assert.throws(() => reduce(createState(), { type: "queue", agent: "a", item: { id: "1", text: "t" } }), TypeError);
|
||||
});
|
||||
|
||||
test("restart turns sending into uncertain for that agent only", () => {
|
||||
let s = reduce(createState(), { type: "restore", agent: "a", items: [{ id: "1", text: "t", state: "sending", createdAt: 1 }] });
|
||||
s = reduce(s, { type: "restore", agent: "b", items: [{ id: "2", text: "t", state: "sending", createdAt: 1 }] });
|
||||
s = reduce(s, { type: "restart", agent: "a" });
|
||||
assert.equal(s.queue.a[0].state, "uncertain");
|
||||
assert.equal(s.queue.b[0].state, "sending");
|
||||
});
|
||||
|
||||
test("attach and removeAttachment", () => {
|
||||
let s = reduce(createState(), { type: "attach", agent: "a", file: { id: "f", name: "x", path: "/x", bytes: 1 } });
|
||||
assert.equal(s.attachments.a[0].kind, "file");
|
||||
assert.equal(s.attachments.a[0].state, "ready");
|
||||
s = reduce(s, { type: "removeAttachment", agent: "a", id: "f" });
|
||||
assert.deepEqual(s.attachments.a, []);
|
||||
});
|
||||
|
||||
test("notice sets and clears", () => {
|
||||
let s = reduce(createState(), { type: "notice", notice: { text: "x" } });
|
||||
assert.deepEqual(s.notice, { text: "x" });
|
||||
s = reduce(s, { type: "notice", notice: null });
|
||||
assert.equal(s.notice, null);
|
||||
});
|
||||
@@ -0,0 +1,58 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import {
|
||||
HISTORY_LIMIT, queueKey, loadHistory, saveHistory, loadQueue, saveQueue, loadUsage, saveUsage,
|
||||
} from "../mod/ovis-composer/storage.js";
|
||||
|
||||
const memStore = () => {
|
||||
const m = new Map();
|
||||
return { get: (k) => m.get(k), set: (k, v) => void m.set(k, v) };
|
||||
};
|
||||
|
||||
test("saveHistory truncates to 500, keeping the newest", () => {
|
||||
const store = memStore();
|
||||
const items = Array.from({ length: 520 }, (_, i) => ({ id: `i${i}`, text: `t${i}`, at: i }));
|
||||
saveHistory(store, items);
|
||||
const out = loadHistory(store);
|
||||
assert.equal(HISTORY_LIMIT, 500);
|
||||
assert.equal(out.length, 500);
|
||||
assert.equal(out[0].id, "i20");
|
||||
assert.equal(out[499].id, "i519");
|
||||
});
|
||||
|
||||
test("history drops invalid entries on load", () => {
|
||||
const store = memStore();
|
||||
store.set("ovis-composer.history", [{ id: "a", text: "x", at: 1 }, { id: "b" }, null]);
|
||||
assert.equal(loadHistory(store).length, 1);
|
||||
});
|
||||
|
||||
test("queueKey is per agent", () => {
|
||||
assert.equal(queueKey("a1"), "ovis-composer.queue:a1");
|
||||
});
|
||||
|
||||
test("queue roundtrip; keeps sending state as written", () => {
|
||||
const store = memStore();
|
||||
const q = [{ id: "1", text: "t", state: "sending", createdAt: 5 }];
|
||||
saveQueue(store, "a", q);
|
||||
assert.deepEqual(loadQueue(store, "a"), q);
|
||||
assert.deepEqual(loadQueue(store, "b"), []);
|
||||
});
|
||||
|
||||
test("saveQueue ignores empty agent", () => {
|
||||
const store = memStore();
|
||||
saveQueue(store, "", [{ id: "1", text: "t", state: "queued", createdAt: 1 }]);
|
||||
assert.equal(store.get("ovis-composer.queue:"), undefined);
|
||||
});
|
||||
|
||||
test("usage keeps only non-negative finite numbers", () => {
|
||||
const store = memStore();
|
||||
saveUsage(store, { review: 3, bad: -1, worse: "x" });
|
||||
assert.deepEqual(loadUsage(store), { review: 3 });
|
||||
});
|
||||
|
||||
test("rubbish list does not wipe stored history", () => {
|
||||
const store = memStore();
|
||||
saveHistory(store, [{ id: "a", text: "x", at: 1 }]);
|
||||
saveHistory(store, [{ nope: 1 }]);
|
||||
assert.equal(loadHistory(store).length, 1);
|
||||
});
|
||||
@@ -0,0 +1,42 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { detect, startsLine, rank, merge, GROUPS } from "../mod/ovis-composer/suggest.js";
|
||||
|
||||
test("detect finds a slash command at caret", () => {
|
||||
assert.deepEqual(detect("ala /re", 7), { trigger: "/", needle: "re", start: 4 });
|
||||
});
|
||||
|
||||
test("detect ignores slash inside a path", () => {
|
||||
assert.equal(detect("see /tmp/x", 10), null);
|
||||
});
|
||||
|
||||
test("detect finds @ file token anywhere", () => {
|
||||
assert.deepEqual(detect("open @src/a", 11), { trigger: "@", needle: "src/a", start: 5 });
|
||||
});
|
||||
|
||||
test("detect rejects bad caret / non-string", () => {
|
||||
assert.equal(detect(null, 0), null);
|
||||
assert.equal(detect("abc", 99), null);
|
||||
});
|
||||
|
||||
test("startsLine", () => {
|
||||
assert.equal(startsLine("a\n/x", 2), true);
|
||||
assert.equal(startsLine("a /x", 2), false);
|
||||
assert.equal(startsLine("/x", 0), true);
|
||||
});
|
||||
|
||||
test("rank orders by level then uses; fuzzy only at line start", () => {
|
||||
const items = [
|
||||
{ key: "review", uses: 0 },
|
||||
{ key: "preview", uses: 0 },
|
||||
{ key: "revert", uses: 5 },
|
||||
];
|
||||
assert.deepEqual(rank(items, "rev").map((i) => i.key), ["revert", "review"]);
|
||||
assert.deepEqual(rank(items, "rev", { atLineStart: true }).map((i) => i.key), ["revert", "review", "preview"]);
|
||||
});
|
||||
|
||||
test("merge orders groups as the design names them", () => {
|
||||
const out = merge({ [GROUPS[1]]: [{ key: "b" }], [GROUPS[0]]: [{ key: "a" }] });
|
||||
assert.deepEqual(out.map((i) => i.key), ["a", "b"]);
|
||||
assert.equal(out[0].group, GROUPS[0]);
|
||||
});
|
||||
@@ -0,0 +1,55 @@
|
||||
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);
|
||||
});
|
||||
Reference in new issue
Block a user