testRegistryListsAnnouncedCodebases
tcm announce: a codebase listed as its author (a codes.tcm.codebase record at its name, its URL, name and
description kept for next time), said when its server can't be read without a token; the registry's Codebases tab
and its author's page show it, linking to its server's web UI, and its page shows its code, mirrored; listed again
as it is, nothing changes; and
--withdraw takes it back, and the registry stops showing it.
import { startFakeAtproto } from "#codebase/tcmts/cli/test/e2e/examples"; import { withChildren } from "#codebase/tcmts/cli/test/e2e/harness"; import { registryOn } from "#codebase/tcmts/cli/test/e2e/registry"; import { codebase, onFakeNetwork } from "#codebase/tcmts/cli/test/e2e/releases"; import { startServerInfo } from "#codebase/tcmts/cli/test/e2e/sync"; import assert from "node:assert/strict"; export const testRegistryListsAnnouncedCodebases = () => withChildren(async (keep) => { const alice = { did: "did:plc:alice000000000000000000", handle: "alice.test", password: "a-pass", }; const net = await startFakeAtproto(keep, [alice]); const network = onFakeNetwork(keep, net); const notes = codebase("announced codebase"); notes.save(`// tcm: namespace notes\nexport const title = "Notes";\n`, "add"); const tcm = (...args: string[]) => network.run(notes.dir, ...args); const ok = (...args: string[]) => network.ok(notes.dir, ...args); const record = () => net.records.get(`at://${alice.did}/codes.tcm.codebase/notes`)?.value; // nowhere it's served, or a name that can't be one: refused before signing in assert.match((await tcm("announce", "--name", "notes")).out, /tcm announce <url>/); assert.match( (await tcm("announce", "https://x.example", "--name", "no/slash")).out, /a codebase's name is letters, digits/, ); assert.equal(net.oauth.signIns, 0); // served for its maintainer alone: listed, and said that people can't read it there const closed = (await startServerInfo(keep, notes.dir, "tok")).url; const first = await ok( "announce", closed, "--name", "notes", "--description", "Notes, and the app that keeps them.", "--as", "alice.test", ); assert.match( first, /listed notes as @alice\.test: at:\/\/did:plc:alice0+\/codes\.tcm\.codebase\/notes/, ); assert.match(first, /didn't answer without a token[\s\S]*tcm serve --public/); assert.equal(record()!.url, closed); // served to anyone: listed again (name and description kept), and nothing said const open = (await startServerInfo(keep, notes.dir, "tok", "--public")).url; const again = await ok("announce", open); assert.match(again, /listed again notes as @alice\.test \(as it is now\)/); assert.doesNotMatch(again, /without a token/); assert.equal(record()!.url, open); assert.equal(record()!.description, "Notes, and the app that keeps them."); assert.match(await ok("announce"), /notes is already listed as @alice\.test, as it is/); assert.equal(net.oauth.signIns, 1); // the registry's tab, and its author's page: each linking to its server's web UI const { until, page } = await registryOn(keep, net); await until("the codebase to be listed", async () => /@alice\.test\/notes<\/a>/.test(await page("/codebases")), ); const listed = await page("/codebases"); assert.match(listed, /Notes, and the app that keeps them\./); assert.match(listed, new RegExp(`href="${open.replace(/\/$/, "")}/forge/"`)); assert.match(listed, /1 on 1 server</); assert.match(listed, /Codebases<span class="count">1<\/span>/); assert.match(listed, /href="\/codebases\/@alice\.test\/notes"/); assert.match(await page("/@alice.test?tab=codebases"), /@alice\.test\/notes<\/a>/); // its code, mirrored from its server: on its page, and each definition on the forge's pages in the registry await until("its code to be mirrored", async () => /<span>1 definition<\/span>/.test(await page("/codebases/@alice.test/notes")), ); const code = await page("/codebases/@alice.test/notes?tab=code"); // (from its lone namespace, notes: its definitions) const ns = /href="\/code\/(plc_alice0+\/_codebases\/notes\/notes)\/title"/.exec(code)?.[1]; assert.ok(ns, code); assert.match(code, /tcm remote add notes http:/); const def = await page(`/code/${ns}/title`); assert.match(def, /<title>notes\.title · @alice\.test\/notes · tcm registry<\/title>/); assert.match(def, /"Notes"|"Notes"/); // (under Codebases, its crumbs from whose it is) assert.match(def, /<\w+[^>]*aria-selected="true"[^>]*>Codebases</); assert.match( def, /href="\/codebases\/@alice\.test\/notes\?tab=code"[^>]*>@alice\.test\/notes</, ); // withdrawn: its record deleted, and the registry stops showing it assert.match(await ok("announce", "--withdraw"), /withdrawn notes/); assert.equal(record(), undefined); assert.match((await tcm("announce", "--withdraw")).out, /notes isn't listed as @alice\.test/); await until("the codebase to go", async () => /No codebases yet\./.test(await page("/codebases")), ); })