Skip to content
53 linesCodeBlameRaw
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { HOSTED_ADDRESSES, addressesFor, addressesFrom, cloneUrl, usercontentFrom } from "./addresses.ts";
5import { MCP_URL } from "./agent-setup.ts";
6import { OG, SITE } from "./meta.ts";
7
8test("with no settings, the addresses are g1t.sh's", () => {
9 assert.deepEqual(addressesFor({}), HOSTED_ADDRESSES);
10 assert.deepEqual(addressesFor({ SITE_URL: "", API_URL: "", MCP_URL: "" }), HOSTED_ADDRESSES);
11});
12
13test("settings replace the addresses, without trailing slashes", () => {
14 assert.deepEqual(
15 addressesFor({
16 SITE_URL: "http://localhost:8787/",
17 API_URL: "http://localhost:8788",
18 MCP_URL: "http://localhost:8790/mcp/",
19 OG_URL: "",
20 }),
21 {
22 site: "http://localhost:8787",
23 api: "http://localhost:8788",
24 mcp: "http://localhost:8790/mcp",
25 og: null,
26 usercontent: "http://localhost:8787/-/usercontent",
27 },
28 );
29});
30
31test("files people supply are served from an origin of their own", () => {
32 assert.equal(addressesFor({}).usercontent, "https://g1tusercontent.com");
33 assert.equal(addressesFor({ SITE_URL: "https://git.example.com", USERCONTENT_URL: "https://files.example.net/" }).usercontent, "https://files.example.net");
34 assert.equal(addressesFor({ SITE_URL: "https://git.example.com", USERCONTENT_URL: "https://git.example.com" }).usercontent, "https://git.example.com/-/usercontent");
35 assert.equal(usercontentFrom(undefined), "");
36 assert.equal(usercontentFrom({ addresses: HOSTED_ADDRESSES }), "https://g1tusercontent.com");
37});
38
39test("pages without root data use g1t.sh's addresses", () => {
40 assert.deepEqual(addressesFrom(undefined), HOSTED_ADDRESSES);
41 const own = { site: "http://localhost:8787", api: "a", mcp: "m", og: null };
42 assert.deepEqual(addressesFrom({ addresses: own }), own);
43});
44
45test("the defaults kept in meta and agent setup are g1t.sh's", () => {
46 assert.equal(SITE, HOSTED_ADDRESSES.site);
47 assert.equal(OG, HOSTED_ADDRESSES.og);
48 assert.equal(MCP_URL, HOSTED_ADDRESSES.mcp);
49});
50
51test("a clone address is under the site", () => {
52 assert.equal(cloneUrl(HOSTED_ADDRESSES, "acme/web"), "https://g1t.sh/acme/web.git");
53});