evOo-local/apps/www/src/agent-content.test.ts
cynarAI 6c7eed7580 Initial clean evOo-local from f00577b
Fresh history cut from cynarAI/evoo antigravity-handoff/project-timeline
(Voice First + project timeline). Brand docs/titles as evOo; keep @rakazo/*
packages as tech debt. Excludes node_modules, caches, secrets, voice blobs.
2026-09-20 17:15:16 +02:00

70 lines
2.8 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
ABOUT_MARKDOWN,
AGENT_INSTRUCTIONS,
HOME_MARKDOWN,
getMarkdownAlternate,
getMarkdownDocument,
markdownResponse,
negotiateRepresentation,
} from "./agent-content";
describe("agent content negotiation", () => {
it("serves Markdown when it is the most specific preferred representation", () => {
expect(negotiateRepresentation("text/markdown")).toBe("markdown");
expect(negotiateRepresentation("text/markdown, text/html;q=0.8")).toBe(
"markdown",
);
expect(negotiateRepresentation("text/markdown, text/*")).toBe("markdown");
});
it("keeps browser requests on HTML and rejects unsupported representations", () => {
expect(negotiateRepresentation(null)).toBe("html");
expect(
negotiateRepresentation("text/html,application/xhtml+xml,*/*;q=0.8"),
).toBe("html");
expect(negotiateRepresentation("text/html, text/markdown;q=0.5")).toBe(
"html",
);
expect(negotiateRepresentation("application/json")).toBe("not-acceptable");
expect(negotiateRepresentation("text/html;q=0, text/markdown;q=0")).toBe(
"not-acceptable",
);
});
it("maps canonical and trailing-slash page paths to Markdown documents", () => {
expect(getMarkdownDocument("/")).toContain("# evOo");
expect(getMarkdownDocument("/about/")).toContain("# About evOo");
expect(getMarkdownAlternate("/")).toBe("/index.md");
expect(getMarkdownAlternate("/support/")).toBe("/support.md");
expect(getMarkdownDocument("/missing")).toBeUndefined();
expect(getMarkdownAlternate("/missing")).toBeUndefined();
expect(getMarkdownAlternate("/changelog")).toBeUndefined();
});
it("publishes specific when-to-use instructions for agents", () => {
expect(HOME_MARKDOWN).toContain("open source evOo alternative");
expect(ABOUT_MARKDOWN).toContain("open source evOo alternative");
expect(AGENT_INSTRUCTIONS).toContain("open source evOo alternative");
expect(AGENT_INSTRUCTIONS).toContain("## When to use evOo");
expect(AGENT_INSTRUCTIONS).toContain("## How an agent should use evOo");
expect(AGENT_INSTRUCTIONS).toContain("Self-hosting is available now");
});
it("returns cache-safe Markdown responses and omits bodies for HEAD", async () => {
const response = markdownResponse("# evOo\n");
expect(response.headers.get("content-type")).toBe(
"text/markdown; charset=utf-8",
);
expect(response.headers.get("link")).toBe(
'</llms.txt>; rel="describedby"; type="text/plain"',
);
expect(response.headers.get("vary")).toBe("Accept, Accept-Encoding");
await expect(response.text()).resolves.toBe("# evOo\n");
const headResponse = markdownResponse("# evOo\n", "HEAD", 404);
expect(headResponse.status).toBe(404);
await expect(headResponse.text()).resolves.toBe("");
});
});