registryTrial

tcmts.dev.registryTrial · #76cvqaev · term · runs on the server

uses node:path

The registry, locally, on the end-to-end tests' fake AT Protocol network, to look at while working on its pages: alice's geo released twice (a breaking change, two additions, one reaching the network, and a change with the same API), maya's review of it, and alice's Bluesky profile; the registry mirrors them, says its address, and runs until it's stopped. pnpm tcm run tcmts.dev.registryTrial <tcm.js>: a packed tcm's (tcm pack tcm-ts, installed), as the registry ships only in one.

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 path_1 from "node:path";

export async function registryTrial(tcm: string): Promise<void> {
  process.env.TCM_BIN = path_1.resolve(tcm);
  await withChildren(async (keep) => {
    const alice = {
      did: "did:plc:alice000000000000000000",
      handle: "alice.test",
      password: "a-pass",
    };
    const maya = {
      did: "did:plc:maya0000000000000000000",
      handle: "maya.test",
      password: "m-pass",
    };
    const net = await startFakeAtproto(keep, [alice, maya]);
    net.seed(alice.did, "app.bsky.actor.profile", "self", {
      displayName: "Alice Park",
      description: "Maps and geometry.",
    });
    const { ok } = onFakeNetwork(keep, net);
    const geo = codebase("registry trial geo");
    geo.save(
      `// tcm: namespace geo
export const manifest = { name: "geo", description: "Shapes, areas and distances.", license: "MIT" };
/** A square's area. */
export const area = (side: number) => side * side;
/** The distance from the origin. */
export const distance = (x: number, y: number) => Math.hypot(x, y);
`,
      "add",
    );
    const source = (await startServerInfo(keep, geo.dir, "tok", "--public")).url;
    await ok(
      geo.dir,
      "release",
      "geo@1.0.0",
      "--announce",
      "--as",
      "alice.test",
      "--source",
      source,
    );
    geo.save(
      `// tcm: namespace geo
/** A square's area, from its shape. */
export const area = (s: { side: number }) => s.side * s.side;
/** A cube's volume. */
export const cube = (side: number) => side ** 3;
/** Map tiles around a point. */
export const fetchTiles = async (x: number, y: number) => (await fetch(\`https://tiles.example/\${x}/\${y}\`)).json();
/** The distance from the origin, as the crow flies. */
export const distance = (x: number, y: number) => Math.sqrt(x * x + y * y);
`,
    );
    await ok(geo.dir, "release", "--announce");
    await ok(
      geo.dir,
      "lib",
      "attest",
      "@alice.test/geo@1.0.0",
      "review",
      "-m",
      "Read all of area.",
      "--as",
      "maya.test",
    );
    const registry = await registryOn(keep, net);
    console.log(`registry: ${registry.url}  (stop it to end the trial)`);
    await new Promise(() => {});
  });
}

uses