@mottyjs/test
The test kit of the Motty SDK, used with the author's own test runner. fake and on script the
models, memory is storage for a test, and run is the whole lifecycle of a request without the
wire. Cases, tables and coverage stay with the runner.
bun add --dev @mottyjs/test
import { fake, memory, on, run } from "@mottyjs/test";
A request answered by a scripted model:
import { expect, test } from "bun:test";
import { model, motty } from "@mottyjs/core";
import { fake, on, run } from "@mottyjs/test";
const luna = model("openai/gpt-6-luna");
const relay = motty({ name: "relay" }).handle(({ prompt }) => luna.complete(prompt));
test("a question is answered by the small model", async () => {
const models = fake(on(luna, "quick reply"));
const { answer } = await run(
relay,
{ text: "What does git stash do?" },
{ models: [models] },
);
expect(await answer.text()).toBe("quick reply");
});
A fake applies a connection's rules for the headers a call may state. It forwards none by default,
and takes forwardHeaders as an adapter does, ahead of its scripts. It holds no headers of its
own, so a name a real connection or its API states is not left out by a fake. What sent returns
holds only the headers the rules let through, and the rest are warnings on the call:
const models = fake({ forwardHeaders: ["x-session"] }, on(luna, "quick reply"));
The SDK as a whole is described in the root README, and the reasons behind its design in ARCHITECTURE.md.