testServeShowsOtherCodebasesForges
tcm serve --forge: another codebase's web UI under a path, read by anyone and signed in to by no one (no pull command, no contributing), beside the served codebase's own; one not there yet says so, and one whose directory is a link shows the codebase it comes to link to
import { codebase, LIB, startServer, uiPage } from "#codebase/tcmts/cli/test/e2e/contributions"; import { tempDir, withChildren } from "#codebase/tcmts/cli/test/e2e/harness"; import assert from "node:assert/strict"; import fs from "node:fs"; import path from "node:path"; export const testServeShowsOtherCodebasesForges = async () => { const root = tempDir("forges"); await withChildren(async (keep) => { const server = codebase(root, "served"); server.write(LIB); server.tcm("add"); const shown = codebase(root, "shown"); shown.write( `// tcm: namespace geo\n/** A circle's area. */\nexport const area = (r: number): number => Math.PI * r * r;\n`, ); shown.tcm("add"); const next = codebase(root, "next"); next.write(`// tcm: namespace shapes\nexport const hexagons = 6;\n`); next.tcm("add"); fs.symlinkSync(shown.dir, path.join(root, "current")); const url = await startServer(keep, server.dir, "tok", [ "--public", "--forge", `/code/shown=${path.join(root, "current")},/code/later=${path.join(root, "later")}`, ]); const later = await fetch(`${url}/code/later/`, { headers: { accept: "text/html" } }); assert.equal(later.status, 503); assert.match(await later.text(), /no codebase to show here yet/); const front = await uiPage(`${url}/code/shown/`); assert.equal(front.status, 200, front.html); assert.match(front.html, />geo</); assert.doesNotMatch(front.html, />lib</, "the codebase shown, not the one served"); assert.doesNotMatch(front.html, /Sign in|Get it|tcm remote add/); assert.doesNotMatch(front.html, /Contributions|People/); assert.match( (await uiPage(`${url}/code/shown/code/geo/area`)).html, /A circle('|')s area\./, ); // the served codebase's own is where it was assert.match((await uiPage(`${url}/forge/`)).html, />lib</); // the link comes to be another codebase: that's the one shown fs.unlinkSync(path.join(root, "current")); fs.symlinkSync(next.dir, path.join(root, "current")); const moved = await uiPage(`${url}/code/shown/`); assert.equal(moved.status, 200, moved.html); assert.match(moved.html, />shapes</); assert.doesNotMatch(moved.html, />geo</); }); }