testCodebaseLibrariesByAuthor

tcmts.hub.test.testCodebaseLibrariesByAuthor · #fjayjxcl · term

A codebase's libraries are its records' outermost entries: an announced one by its author and package.

import { recordText } from "#codebase/tcmts/cli/libraries";
import { librariesOfRemote } from "#codebase/tcmts/hub";
import assert from "node:assert/strict";

export const testCodebaseLibrariesByAuthor = async () => {
  const outer = recordText({
    geo: {
      namespace: "geons",
      release: "geo@1.2.0",
      sources: ["https://alice.dev"],
      did: "did:plc:alice",
    },
    local: { namespace: "nothing-the-hub-has", sources: ["../local"] },
  });
  const inner = recordText({
    deep: { namespace: "d", release: "deep@1.0.0", sources: ["x"], did: "did:plc:deep" },
  });
  const rows = [
    { path: "app.libraries", hash: "rec1", kind: "file" as const },
    { path: "app.geo.libraries", hash: "rec2", kind: "file" as const },
    { path: "app.main", hash: "m", kind: "term" as const },
  ];
  const texts: Record<string, string> = { rec1: outer, rec2: inner };
  const got = await librariesOfRemote({
    branch: async () => ({ head: "h", names: rows }) as never,
    get: async (hashes: string[]) =>
      hashes.map((hash) => ({ hash, sourceText: texts[hash] ?? "" })) as never,
  });
  assert.deepEqual([...got], ["did:plc:alice geo"]);
}

uses