Spaces:
Paused
Paused
File size: 3,289 Bytes
4e7644b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | import { describe, it, expect } from "vitest";
import { getAgentDisplayName } from "./agentDisplayName";
import { parseMarkdownFrontmatter, stripFrontmatter } from "./markdown";
// ---------------------------------------------------------------------------
// getAgentDisplayName
// ---------------------------------------------------------------------------
const t = (key: string) => key; // test t function: returns the key as-is
describe("getAgentDisplayName", () => {
it('returns i18n key when id is "default" and name is the default placeholder', () => {
expect(
getAgentDisplayName({ id: "default", name: "Default Agent" }, t as any),
).toBe("agent.defaultDisplayName");
});
it('returns i18n key when id is "default" and name is empty', () => {
expect(getAgentDisplayName({ id: "default", name: "" }, t as any)).toBe(
"agent.defaultDisplayName",
);
});
it('returns custom name when id is "default" but name is customized', () => {
expect(
getAgentDisplayName({ id: "default", name: "My Custom Name" }, t as any),
).toBe("My Custom Name");
});
it('returns name when id is not "default"', () => {
expect(
getAgentDisplayName({ id: "agent-1", name: "My Agent" }, t as any),
).toBe("My Agent");
});
it("falls back to id when name is empty", () => {
expect(getAgentDisplayName({ id: "agent-1", name: "" }, t as any)).toBe(
"agent-1",
);
});
it("falls back to id when name is undefined", () => {
expect(
getAgentDisplayName({ id: "agent-1", name: undefined as any }, t as any),
).toBe("agent-1");
});
});
// ---------------------------------------------------------------------------
// stripFrontmatter
// ---------------------------------------------------------------------------
describe("stripFrontmatter", () => {
it("removes standard YAML frontmatter", () => {
const input = "---\ntitle: Test\ndate: 2024-01-01\n---\n# Hello";
expect(stripFrontmatter(input)).toBe("# Hello");
});
it("returns input unchanged when no frontmatter", () => {
const input = "# Hello\nsome content";
expect(stripFrontmatter(input)).toBe(input);
});
it("returns empty string for empty input", () => {
expect(stripFrontmatter("")).toBe("");
});
it("preserves all content after frontmatter", () => {
const input = "---\nkey: value\n---\nline1\nline2\n\nline3";
expect(stripFrontmatter(input)).toBe("line1\nline2\n\nline3");
});
it("returns empty string when only frontmatter with no body", () => {
const input = "---\ntitle: Only\n---\n";
expect(stripFrontmatter(input)).toBe("");
});
it("handles Windows line endings \\r\\n", () => {
const input = "---\r\ntitle: Test\r\n---\r\n# Hello";
expect(stripFrontmatter(input)).toBe("# Hello");
});
});
describe("parseMarkdownFrontmatter", () => {
it("returns ordered metadata entries and the Markdown body", () => {
const input =
"---\ndescription: Memory Search: query guidance\nname: memory-search\n---\n## Body";
expect(parseMarkdownFrontmatter(input)).toEqual({
body: "## Body",
entries: [
{ key: "description", value: "Memory Search: query guidance" },
{ key: "name", value: "memory-search" },
],
});
});
});
|