Files
perry/test/perry.test.js
T
2026-10-07 09:27:20 -05:00

47 lines
2.0 KiB
JavaScript

const test = require("node:test");
const assert = require("node:assert/strict");
const Perry = require("..");
test("Perry requires explicit provider and model settings", () => {
assert.throws(() => Perry(), /settings are required/);
assert.throws(() => Perry({ model: "gemma" }), /'provider' is required/);
assert.throws(() => Perry({ provider: "lm-studio" }), /'model' is required/);
assert.throws(() => Perry({ provider: "ollama", model: "gemma" }), /Unsupported LLM provider/);
});
test("Perry is a lightweight independently configured instance", () => {
const first = Perry({ provider: "lm-studio", model: "model-a" });
const second = Perry({ provider: "lm-studio", model: "model-b" });
assert.equal(first.model(), "model-a");
assert.equal(second.model(), "model-b");
});
test("prepare assembles Perry-shaped conversation history", () => {
const perry = Perry({ provider: "lm-studio", model: "model-a" });
const agent = perry.prepare("Perry", "system", [{
messages: [
{ role: "user", content: "hello", providerSpecificThing: "discard me" },
{ role: "assistant", content: "hi", reasoning: "private" }
]
}]);
assert.equal(agent.name, "Perry");
assert.deepEqual(agent.conversation, {
systemPrompt: "system",
messages: [
{ role: "user", content: "hello" },
{ role: "assistant", content: "hi" }
],
add: agent.conversation.add
});
});
test("cleanText converts common LLM presentation markup without understanding project structure", () => {
assert.equal(Perry.cleanText(String.raw`$\text{He}$ ($\text{ה}$)`), "He (ה)");
assert.equal(Perry.cleanText(String.raw`left \rightarrow right`), "left → right");
assert.equal(Perry.cleanText(String.raw`\textbf{bold} and \textit{italic}`), "**bold** and //italic//");
assert.equal(Perry.cleanText("__bold__ and *italic*"), "**bold** and //italic//");
assert.equal(Perry.cleanText(String.raw`unknown \mystery{thing}`), String.raw`unknown \mystery{thing}`);
});