testYankedVersionsAreNotLatest

tcmts.registry.test.testYankedVersionsAreNotLatest · #iaip5l74 · term

A release is yanked only by its own author's yank of its namespace (anyone else's yanks nothing), and a yanked version isn't a library's latest: the newest version left is, mirrored first, and, every one yanked, the newest.

import { latestRelease, yanksOf } from "#codebase/tcmts/registry";
import type { RegistryAttestation, RegistryRelease } from "#codebase/tcmts/registry";
import assert from "node:assert/strict";

export const testYankedVersionsAreNotLatest = () => {
  const alice = "did:plc:alice";
  const maya = "did:plc:maya";
  const release = (version: string, state: RegistryRelease["state"] = "mirrored"): RegistryRelease => ({
    uri: `at://${alice}/codes.tcm.release/geo:${version}`,
    did: alice,
    rkey: `geo:${version}`,
    cid: "c",
    package: "geo",
    version,
    namespace: `ns${version}`,
    entry: "x",
    notes: "",
    sources: [],
    createdAt: new Date(0).toISOString(),
    seq: 0,
    state,
    verifiedAt: new Date(0),
  });
  const yank = (did: string, namespace: string): RegistryAttestation => ({
    uri: `at://${did}/codes.tcm.yank/${namespace}`,
    did,
    kind: "yank",
    namespace,
    body: "don't",
    createdAt: new Date(0).toISOString(),
    seq: 0,
    state: "verified",
  });
  const versions = [release("1.2.0"), release("1.1.0", "withdrawn"), release("1.0.0")];
  const latest = (said: RegistryAttestation[]) =>
    latestRelease(versions, yanksOf(versions, said)).version;
  assert.equal(latest([]), "1.2.0");
  assert.equal(latest([yank(maya, "ns1.2.0")]), "1.2.0", "only its author yanks it");
  assert.deepEqual([...yanksOf(versions, [yank(alice, "ns1.2.0")]).keys()], [versions[0]!.uri]);
  assert.equal(latest([yank(alice, "ns1.2.0")]), "1.0.0", "the newest mirrored one left");
  assert.equal(
    latest([yank(alice, "ns1.2.0"), yank(alice, "ns1.0.0")]),
    "1.1.0",
    "else the newest left",
  );
  assert.equal(
    latest(["ns1.2.0", "ns1.1.0", "ns1.0.0"].map((n) => yank(alice, n))),
    "1.2.0",
    "every one yanked: the newest mirrored",
  );
}

uses