A local-first multi-agent app development platform, built on PenguinHarness
/**
* The pure half of the "Create with AI" bridge (src/features/ai-create/ai-bridge.ts): what the
* draft cache and the route state hold once a surface hands its prompt to the draft page.
*/
import { describe, expect, it } from "vitest";
import { aiChatRouteState, buildAiDraft } from "../src/features/ai-create/ai-bridge";
describe("buildAiDraft", () => {
it("merges over the cached draft, so the model carry-over survives", () => {
const draft = buildAiDraft(
{ modelRef: { provider: "p", modelId: "m" }, approvalMode: "read-only", text: "typed" },
{ agentId: "default_agent", text: "prompt" },
);
expect(draft.modelRef).toEqual({ provider: "p", modelId: "m" });
expect(draft.approvalMode).toBe("read-only");
expect(draft.agentId).toBe("default_agent");
expect(draft.text).toBe("prompt");
});
it("replaces the cached model only when the request pins one", () => {
const cached = { modelRef: { provider: "p", modelId: "m" } };
expect(buildAiDraft(cached, { agentId: "a", text: "t" }).modelRef).toEqual(cached.modelRef);
expect(
buildAiDraft(cached, { agentId: "a", text: "t", modelRef: { provider: "q", modelId: "n" } })
.modelRef,
).toEqual({ provider: "q", modelId: "n" });
});
it("resets the skill selection unless the request pins one", () => {
expect(buildAiDraft({ skills: ["old"] }, { agentId: "a", text: "t" }).skills).toEqual([]);
expect(buildAiDraft({}, { agentId: "a", text: "t", skills: ["s"] }).skills).toEqual(["s"]);
});
it("pins the Workspace only when asked, keeping the cached one otherwise", () => {
expect(buildAiDraft({ workspace: "/w" }, { agentId: "a", text: "t" }).workspace).toBe("/w");
// "" is the temporary Workspace — a pin, not an absence.
const pinned = buildAiDraft({ workspace: "/w" }, { agentId: "a", text: "t", workspace: "" });
expect(pinned.workspace).toBe("");
});
it("drops a stale handoff target, which would forward the prompt to another agent", () => {
const draft = buildAiDraft({ handoffAgentId: "other" }, { agentId: "a", text: "t" });
expect("handoffAgentId" in draft).toBe(false);
});
it("marks the prompt as composed, so it is not kept or parked as text the user typed", () => {
expect(buildAiDraft({ text: "typed" }, { agentId: "a", text: "t" }).aiPrefill).toBe(true);
});
});
describe("aiChatRouteState", () => {
it("carries only what was asked for", () => {
expect(aiChatRouteState({ agentId: "a", text: "t" })).toEqual({ agentId: "a" });
// "" is the temporary Workspace — a pin, so it travels; an absent one leaves no key behind.
expect(aiChatRouteState({ agentId: "a", text: "t", workspace: "" })).toEqual({
agentId: "a",
workspace: "",
});
});
});