murashit_codex-panel/tests/app-server/request-input.test.ts

59 lines
2.4 KiB
TypeScript
Raw Normal View History

import { describe, expect, it } from "vitest";
import { codexTextInputWithAttachments, codexTextInputWithMentions, type CodexInput } from "../../src/domain/chat/input";
import { additionalContextFromCodexInput, toAppServerUserInput } from "../../src/app-server/protocol/request-input";
describe("app-server request input", () => {
it("builds text input with mentions and skills", () => {
expect(
2026-06-10 02:49:43 +00:00
codexTextInputWithMentions(
"Use [[Note]] and $Skill",
[{ name: "Note", path: "Note.md" }],
[{ name: "Skill", path: ".codex/skills/skill/SKILL.md" }],
[{ key: "codex_panel_wikilinks", kind: "untrusted", value: "Resolved Obsidian wikilinks:\n- [[Note]] -> Note.md" }],
),
).toEqual([
2026-06-10 02:49:43 +00:00
{ type: "text", text: "Use [[Note]] and $Skill" },
{ type: "mention", name: "Note", path: "Note.md" },
{ type: "skill", name: "Skill", path: ".codex/skills/skill/SKILL.md" },
{
type: "additionalContext",
key: "codex_panel_wikilinks",
kind: "untrusted",
value: "Resolved Obsidian wikilinks:\n- [[Note]] -> Note.md",
},
]);
});
it("replaces text input while preserving non-text attachments", () => {
2026-06-10 02:49:43 +00:00
const input: CodexInput = [
{ type: "text", text: "visible request" },
{ type: "mention", name: "Note", path: "Note.md" },
{ type: "additionalContext", key: "codex_panel_wikilinks", kind: "untrusted", value: "- [[Note]] -> Note.md" },
];
2026-06-10 02:49:43 +00:00
expect(codexTextInputWithAttachments("rewritten prompt", input)).toEqual([
{ type: "text", text: "rewritten prompt" },
{ type: "mention", name: "Note", path: "Note.md" },
{ type: "additionalContext", key: "codex_panel_wikilinks", kind: "untrusted", value: "- [[Note]] -> Note.md" },
2026-06-10 02:49:43 +00:00
]);
});
it("serializes text input for app-server requests", () => {
const input = codexTextInputWithMentions(
"Use [[Note]]",
[{ name: "Note", path: "Note.md" }],
[],
[{ key: "codex_panel_wikilinks", kind: "untrusted", value: "- [[Note]] -> Note.md" }],
);
expect(toAppServerUserInput(input)).toEqual([
2026-06-10 02:49:43 +00:00
{ type: "text", text: "Use [[Note]]", text_elements: [] },
{ type: "mention", name: "Note", path: "Note.md" },
]);
expect(additionalContextFromCodexInput(input)).toEqual({
codex_panel_wikilinks: { kind: "untrusted", value: "- [[Note]] -> Note.md" },
});
});
});