Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

58 linesCodeBlameRaw
1import assert from "node:assert/strict";
2import { test } from "node:test";
3import { agentPage, developerResource, pageRepresentation } from "./agent-pages.ts";
4
5test("developer discovery aliases point at the installation's machine endpoints", () => {
6 const addresses = { api: "https://api.example", mcp: "https://mcp.example" };
7 assert.equal(developerResource("/openapi.json", addresses), "https://api.example/openapi.json");
8 assert.equal(developerResource("/mcp", addresses), "https://mcp.example");
9 assert.equal(developerResource("/developers", addresses), "https://docs.g1t.sh/reference/developers/");
10 assert.equal(developerResource("/private", addresses), null);
11});
12
13test("negotiation honors explicit types, quality, specificity, exclusions and browser defaults", () => {
14 for (const accept of [
15 null,
16 "*/*",
17 "text/html",
18 "text/html,application/xhtml+xml,*/*;q=0.8",
19 "text/markdown;q=0, */*;q=1",
20 "text/html;q=1,text/markdown;q=0.5",
21 ])
22 assert.equal(pageRepresentation(accept), "html", String(accept));
23 for (const accept of ["text/markdown", "TEXT/MARKDOWN; charset=utf-8", "text/html;q=0.5,text/markdown;q=1", "text/markdown,*/*", "text/html;q=0,text/*"])
24 assert.equal(pageRepresentation(accept), "markdown", accept);
25 for (const accept of ["application/json", "text/html;q=0,text/markdown;q=0", "text/markdown;q=bad", "text/markdown;q=1.1"])
26 assert.equal(pageRepresentation(accept), "none", accept);
27});
28
29test("homepage and genuine 404 documents have Markdown with the right status, discovery links and Vary", async () => {
30 for (const [path, status] of [
31 ["/", 200],
32 ["/__missing", 404],
33 ] as const) {
34 const headers = new Headers({ vary: "Accept-Encoding", "content-type": "text/html" });
35 const answer = agentPage(new Request(`https://g1t.sh${path}`, { headers: { accept: "text/markdown" } }), status, headers)!;
36 assert.equal(answer.status, status);
37 assert.match(answer.headers.get("content-type")!, /^text\/markdown/);
38 assert.equal(answer.headers.get("vary"), "Accept-Encoding, Accept");
39 const body = await answer.text();
40 assert.ok(body.length > 20);
41 assert.match(body, /\[.*\]\(https:\/\/g1t.sh\/llms.txt\)/);
42 assert.doesNotMatch(body, /<!DOCTYPE|<html/i);
43 const htmlHeaders = new Headers();
44 assert.equal(agentPage(new Request(`https://g1t.sh${path}`, { headers: { accept: "text/html" } }), status, htmlHeaders), null);
45 assert.equal(htmlHeaders.get("vary"), "Accept");
46 }
47});
48
49test("HEAD, unsupported types, private refusals and writes preserve protocol boundaries", async () => {
50 const head = agentPage(new Request("https://g1t.sh/", { method: "HEAD", headers: { accept: "text/markdown" } }), 200, new Headers())!;
51 assert.equal(head.headers.get("content-type"), "text/markdown; charset=utf-8");
52 assert.equal(await head.text(), "");
53 const json = agentPage(new Request("https://g1t.sh/", { headers: { accept: "application/json" } }), 200, new Headers())!;
54 assert.equal(json.status, 406);
55 for (const status of [301, 302, 401, 403, 500]) assert.equal(agentPage(new Request("https://g1t.sh/"), status, new Headers()), null);
56 assert.equal(agentPage(new Request("https://g1t.sh/", { method: "POST" }), 404, new Headers()), null);
57 assert.equal(agentPage(new Request("https://g1t.sh/private", { headers: { accept: "text/markdown" } }), 200, new Headers()), null);
58});