testRegistryListsCodebases
Listed codebases show once they check against their author's repository, as it signs them: a forged one, one at another key than its name, or one whose URL isn't http(s), doesn't; one changed shows as it is now, and one taken back goes.
import { startFakeAtproto } from "#codebase/tcmts/cli/test/e2e/examples"; import { tempDir, withChildren } from "#codebase/tcmts/cli/test/e2e/harness"; import { codebaseRecord } from "#codebase/tcmts/records"; import { checkCodebase, codebases, readJetstream, shownCodebases } from "#codebase/tcmts/registry"; import { readFromTheStart, withEnv } from "#codebase/tcmts/registry/test"; import { runJobs } from "#codebase/tcmts/server"; import assert from "node:assert/strict"; export const testRegistryListsCodebases = () => withChildren(async (keep) => { const alice = { did: "did:plc:alice000000000000000000", handle: "alice.test", password: "a-pass", }; const sam = { did: "did:plc:sam00000000000000000000", handle: "sam.test", password: "s-pass" }; const net = await startFakeAtproto(keep, [alice, sam]); const listing = (name: string, url: string, description = ""): Record<string, unknown> => ({ ...codebaseRecord({ name, url, description }, "2026-11-04T00:00:00.000Z"), }); net.seed( alice.did, "codes.tcm.codebase", "notes", listing("notes", "https://code.alice.invalid", "Notes."), ); net.seed(sam.did, "codes.tcm.codebase", "tiles", listing("tiles", "https://sam.invalid")); net.forge(`at://${sam.did}/codes.tcm.codebase/tiles`); // (at a key that isn't its name, or somewhere that isn't a server: not a listing) net.seed(sam.did, "codes.tcm.codebase", "elsewhere", listing("maps", "https://sam.invalid")); net.seed(sam.did, "codes.tcm.codebase", "local", listing("local", "file:///etc")); const ours = async () => (await shownCodebases()) .filter((c) => c.did === alice.did || c.did === sam.did) .map((c) => `${c.did} ${c.name} ${c.url} ${c.description}`); await withEnv( { TCM_ATPROTO_DIRECTORY: net.url, TCM_ATPROTO_LOCAL: "1", TCM_JETSTREAM: net.url, TCM_RELAY: net.url, TCM_REGISTRY_CODEBASE: tempDir("registry codebases"), JETSTREAM_API_KEY: "", }, async () => { await readFromTheStart(); await readJetstream({ idleMs: 500 }); await runJobs({ all: true }); assert.deepEqual(await ours(), [`${alice.did} notes https://code.alice.invalid Notes.`]); assert.equal((await codebases.find({ did: sam.did, state: "verified" })).length, 0); // (said otherwise now: shown as its repository signs it) net.seed( alice.did, "codes.tcm.codebase", "notes", listing("notes", "https://notes.alice.invalid"), ); await checkCodebase(`at://${alice.did}/codes.tcm.codebase/notes`); assert.deepEqual(await ours(), [`${alice.did} notes https://notes.alice.invalid `]); // (taken back: gone once the repository no longer holds it) const del = await fetch(`${net.url}/xrpc/com.atproto.repo.deleteRecord`, { method: "POST", headers: { authorization: `Bearer acc-${alice.did}`, "content-type": "application/json" }, body: JSON.stringify({ repo: alice.did, collection: "codes.tcm.codebase", rkey: "notes", }), }); assert.equal(del.status, 200); await checkCodebase(`at://${alice.did}/codes.tcm.codebase/notes`); assert.deepEqual(await ours(), []); }, ); })
uses
- tcmts.cli.test.e2e.examples.startFakeAtproto
- tcmts.cli.test.e2e.harness.tempDir
- tcmts.cli.test.e2e.harness.withChildren
- tcmts.records.codebaseRecord
- tcmts.registry.checkCodebase
- tcmts.registry.codebases
- tcmts.registry.readJetstream
- tcmts.registry.shownCodebases
- tcmts.registry.test.readFromTheStart
- tcmts.registry.test.withEnv
- tcmts.server.runJobs