Files
radicle-explorer/explorer/tests/unit/releases.test.ts
T
Daniel Norman 0dc1e557a5 Move repo facts outside the project payload
Repos need not carry a `xyz.radicle.project` payload; the default
branch can come from `xyz.radicle.crefs` alone. Such repos got no
counts and no default branch, and failed schema validation in
explorer, which broke the parse of a whole listing.

httpd:
- Add top-level `cobs` with issue, patch and bucketed release counts
- Add top-level `defaultBranch`, qualified like the crefs payload
- Omit a count the node cannot determine instead of reporting zero
- Drop `head`: the tip is `refs[defaultBranch]`
- Keep counts in the project payload for older clients until a
  major release
- Keep the project payload when a COB read fails
- Keep `meta.releases` a single count: delegate + other
- Log and skip canonical ref rules and refs that fail to read,
  so one bad ref doesn't drop the default branch tip

explorer:
- Model `cobs` and `defaultBranch`, adapting older nodes to one shape
- Resolve the default branch from the crefs HEAD on older nodes
- Collect the shims for older httpd in http-client/lib/compat.ts,
  each naming the httpd release that the client can drop it with
- Add `defaultBranchTip`, replacing `head`, with a fallback to the
  legacy `meta.head`
- Make the project payload and its legacy meta optional
- Fall back to the RID for the repo name, and show a placeholder
  for a missing name in repo cards and the header
- Hide a counter instead of reading a missing count as zero
- Fall back to a full-page check for "More" without counts
- Add a `repo.sourceUnavailable` route for repos without a
  default branch or tip
- Browse explicit revisions and offer the branch selector without
  a default branch
- List these repos in repo grids and on the landing page
- Say the node is older or built without releases
- Scope release pages in the client, so views never call the shims
- Read OG worker repos through the same compat shims
- Share the repo name and default branch helpers with the OG worker

CI:
- Add check:open-graph, a wrangler deploy dry run
- Run it in GitHub CI, Buildkite and check:ci
- Install explorer's dependencies first: the worker
  resolves compat.ts imports, such as zod, from there

Tests:
- Test that a build without releases omits the count
- Test that one failing rule keeps the others
- Test the repo shape across httpd versions and the release shims
- Test `hasMorePages` and `repoName`
- Test repos without a project payload end to end
2026-10-29 18:21:09 +01:00

144 lines
4.1 KiB
TypeScript

import type { Artifact } from "@http-client";
import { describe, expect, test } from "vitest";
import {
artifactView,
attestedBy,
redactedByTrusted,
releaseWarning,
} from "@app/lib/releases";
const delegate = "did:key:z6MkDelegate";
const other = "did:key:z6MkOther";
const delegates = new Set([delegate]);
function artifact(
cid: string,
author: string,
redactedBy: string[] = [],
): Artifact {
return {
cid,
author: { id: author },
redactions: redactedBy.map(id => ({ user: { id } })),
} as Artifact;
}
describe("redactedByTrusted", () => {
test.each([
{ by: [delegate], author: other, expected: true },
{ by: [other], author: other, expected: true },
{ by: [other], author: delegate, expected: false },
{ by: [], author: other, expected: false },
])("redacted by $by for $author => $expected", ({ by, author, expected }) => {
expect(redactedByTrusted(artifact("a", author, by), delegates)).toBe(
expected,
);
});
});
describe("artifactView", () => {
const ours = artifact("ours", delegate);
const ourRedacted = artifact("ours-redacted", delegate, [delegate]);
const theirs = artifact("theirs", other);
test("splits artifacts into disjoint scopes", () => {
const all = [ours, theirs];
expect(artifactView(all, delegates, "trusted", false).shown).toEqual([
ours,
]);
expect(artifactView(all, delegates, "untrusted", false).shown).toEqual([
theirs,
]);
});
test("keeps the asked scope when it is empty", () => {
const view = artifactView([theirs], delegates, "trusted", false);
expect(view.shown).toEqual([]);
expect(view.showFilters).toBe(true);
});
test("keeps the filter on others without artifacts by others", () => {
const view = artifactView([ours], delegates, "untrusted", false);
expect(view.shown).toEqual([]);
expect(view.showFilters).toBe(true);
});
test("hides the filter without artifacts by others", () => {
const view = artifactView([ours], delegates, "trusted", false);
expect(view.showFilters).toBe(false);
});
test("hides redacted artifacts unless asked", () => {
const all = [ours, ourRedacted];
expect(artifactView(all, delegates, "trusted", false).shown).toEqual([
ours,
]);
expect(artifactView(all, delegates, "trusted", true).shown).toEqual(all);
});
test("counts redacted artifacts in the current scope only", () => {
const all = [ourRedacted, artifact("x", other, [other])];
expect(artifactView(all, delegates, "trusted", false).redactedCount).toBe(
1,
);
});
test("counts only what each scope would show", () => {
const view = artifactView(
[ours, ourRedacted, theirs],
delegates,
"trusted",
false,
);
expect(view.counts).toEqual({ trusted: 1, untrusted: 1 });
});
test("keeps the filter when only redacted artifacts by others exist", () => {
const view = artifactView(
[ours, artifact("x", other, [other])],
delegates,
"trusted",
false,
);
expect(view.showFilters).toBe(true);
});
test("handles a release without artifacts", () => {
const view = artifactView([], delegates, "trusted", false);
expect(view).toEqual({
shown: [],
redactedCount: 0,
counts: { trusted: 0, untrusted: 0 },
showFilters: false,
});
});
});
describe("attestedBy", () => {
test("counts only delegate attestations", () => {
expect(attestedBy([{ id: delegate }, { id: other }], delegates)).toBe(1);
});
test("counts nothing without attestations", () => {
expect(attestedBy([], delegates)).toBe(0);
});
});
describe("releaseWarning", () => {
test.each(["trusted" as const, "untrusted" as const])(
"warns about a release by a non-delegate in the %s scope",
scope => {
expect(releaseWarning(other, delegates, scope)).toBe("release");
},
);
test("warns about others' artifacts on a delegate's release", () => {
expect(releaseWarning(delegate, delegates, "untrusted")).toBe("artifacts");
});
test("trusts a delegate's release with delegate artifacts", () => {
expect(releaseWarning(delegate, delegates, "trusted")).toBeUndefined();
});
});