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
This commit is contained in:
Daniel Norman
2026-10-29 18:21:09 +01:00
parent 1d760abe96
commit 0dc1e557a5
42 changed files with 1716 additions and 450 deletions
+160
View File
@@ -0,0 +1,160 @@
// Shims that let this client read older httpd releases, so the app only ever
// sees one shape. See docs/adr/0001 and docs/api-changes.md.
//
// Each shim has a "Compat:" comment that says what older httpd does and the
// last httpd release that needs it: "Client: remove when explorer drops httpd
// 0.30". Fallbacks to an older endpoint stay in the client method that calls
// the endpoint, with the same comment.
import type { Release } from "./repo/release.js";
import type { ReleaseScope } from "./repo.js";
import type { Author } from "./shared.js";
import type { z } from "zod";
import { number, object, record, string } from "zod";
// Compat: older httpd reports the issue and patch counts and the default
// branch tip inside the project payload, and the release count as a single
// number. Client: remove when explorer drops httpd 0.30.
export const legacyMetaSchema = object({
head: string(),
patches: object({
open: number(),
draft: number(),
archived: number(),
merged: number(),
}),
issues: object({
open: number(),
closed: number(),
}),
releases: number().optional(),
});
// Compat: older httpd names the default branch only in the project payload,
// so a repo without one has none, even when the symbolic `HEAD` of its
// `xyz.radicle.crefs` payload names it. It sends that payload, so the client
// resolves `HEAD` itself. A malformed payload counts as missing, so that the
// repo still parses. Client: remove when explorer drops httpd 0.30.
export const crefsPayloadSchema = object({
data: object({ symbolic: record(string(), string()).optional() }),
})
.optional()
.catch(undefined);
type LegacyProject =
| {
data: { defaultBranch: string };
meta?: z.infer<typeof legacyMetaSchema>;
}
| undefined;
type LegacyRefs<T> =
{ tags: Record<string, T>; refs: Record<string, string> } | undefined;
// Compat: older httpd, see `legacyMetaSchema` and `crefsPayloadSchema`. It
// reports the counts and the default branch only in the project payload.
// Client: remove when explorer drops httpd 0.30.
export function legacyRepoFields<T>(
project: LegacyProject,
crefs: z.infer<typeof crefsPayloadSchema>,
refs: LegacyRefs<T>,
) {
const meta = project?.meta;
const defaultBranch = legacyDefaultBranch(project, crefs);
return {
cobs: meta
? { patches: meta.patches, issues: meta.issues, releases: undefined }
: undefined,
releaseCount: meta?.releases,
defaultBranch,
refs: legacyRefs(project, defaultBranch, refs),
};
}
// httpd before 0.25.0 sends no canonical refs, and 0.25.0 leaves the default
// branch out of them unless the repo has a crefs payload. Both report the tip
// as `meta.head`, so add it to the canonical refs.
function legacyRefs<T>(
project: LegacyProject,
defaultBranch: string | undefined,
refs: LegacyRefs<T>,
) {
const head = project?.meta?.head;
if (
head === undefined ||
defaultBranch === undefined ||
refs?.refs[defaultBranch] !== undefined ||
// `meta.head` is the tip of the project's default branch, which a crefs
// HEAD may name differently.
defaultBranch !== `refs/heads/${project?.data.defaultBranch}`
) {
return refs;
}
return {
tags: refs?.tags ?? {},
refs: { ...refs?.refs, [defaultBranch]: head },
};
}
// Like heartwood's `Doc::default_branch`: the crefs `HEAD`, which may point
// at another symbolic ref, else the project payload. Only a branch counts.
function legacyDefaultBranch(
project: { data: { defaultBranch: string } } | undefined,
crefs: z.infer<typeof crefsPayloadSchema>,
): string | undefined {
const symbolic = crefs?.data.symbolic;
if (symbolic?.HEAD !== undefined) {
const seen = new Set<string>();
let target: string | undefined = symbolic.HEAD;
while (target !== undefined && !seen.has(target)) {
if (target.startsWith("refs/")) {
return target.startsWith("refs/heads/") ? target : undefined;
}
seen.add(target);
target = symbolic[target];
}
return undefined;
}
return project ? `refs/heads/${project.data.defaultBranch}` : undefined;
}
// Compat: older httpd ignores `scope` and only knows `allAuthors`, which
// asks for every author. Client: remove when explorer drops httpd 0.30.
export function legacyReleasesQuery(
scope: ReleaseScope | undefined,
): Record<string, boolean> {
return scope === "untrusted" ? { allAuthors: true } : {};
}
// Compat: older httpd answers the untrusted scope with every author, so
// keep only the releases that no delegate created. A no-op on newer nodes.
// Client: remove when explorer drops httpd 0.30.
export function legacyScopeReleases(
releases: Release[],
delegates: Author[],
scope: ReleaseScope,
): Release[] {
if (scope === "trusted") {
return releases;
}
const delegateIds = new Set(delegates.map(d => d.id));
return releases.filter(r => !delegateIds.has(r.creator.id));
}
// Compat: older httpd reports no release buckets, so look for others'
// releases in the first page of every author. A full page means others may
// come later, and only the filter depends on this, so a full page or a failed
// fetch counts as having others. Client: remove when explorer drops httpd
// 0.30.
export async function legacyHasOtherReleases(
getPage: () => Promise<Release[]>,
delegates: Author[],
perPage: number,
): Promise<boolean> {
const everyAuthor = await getPage().catch(() => undefined);
if (everyAuthor === undefined || everyAuthor.length === perPage) {
return true;
}
return legacyScopeReleases(everyAuthor, delegates, "untrusted").length > 0;
}
+112 -27
View File
@@ -1,10 +1,19 @@
import type { Fetcher, RequestOptions } from "./fetcher.js";
import { ResponseError } from "./fetcher.js";
import {
crefsPayloadSchema,
legacyHasOtherReleases,
legacyMetaSchema,
legacyReleasesQuery,
legacyRepoFields,
legacyScopeReleases,
} from "./compat.js";
import type { Commit, Commits } from "./repo/commit.js";
import type { Issue } from "./repo/issue.js";
import type { Patch } from "./repo/patch.js";
import type { Release } from "./repo/release.js";
import type { Author } from "./shared.js";
import type { ZodSchema } from "zod";
import {
@@ -67,33 +76,47 @@ export type ReleaseCounts = z.infer<typeof releaseCountsSchema>;
// delegate, or by anyone else.
export type ReleaseScope = "trusted" | "untrusted";
const repoSchema = object({
// Repository-level COB counts. Each is absent when the node cannot determine
// it — an unreadable COB cache, or a build without release support — so a
// missing count never reads as zero.
const cobCountsSchema = object({
patches: optional(
object({
open: number(),
draft: number(),
archived: number(),
merged: number(),
}),
),
issues: optional(
object({
open: number(),
closed: number(),
}),
),
releases: optional(releaseCountsSchema),
});
export type CobCounts = z.infer<typeof cobCountsSchema>;
export const repoSchema = object({
rid: string(),
payloads: object({
// Optional: a repo may declare its default branch in `xyz.radicle.crefs`
// instead, and carry no project payload at all.
"xyz.radicle.project": object({
data: object({
name: string(),
description: string(),
// Unqualified, unlike the top-level `defaultBranch`.
defaultBranch: string(),
}),
meta: object({
head: string(),
patches: object({
open: number(),
draft: number(),
archived: number(),
merged: number(),
}),
issues: object({
open: number(),
closed: number(),
}),
// Absent on older nodes that don't report release counts, and a
// single count on nodes that report one instead of the buckets.
releases: optional(union([releaseCountsSchema, number()])),
}),
}),
meta: legacyMetaSchema.optional(),
}).optional(),
"xyz.radicle.crefs": crefsPayloadSchema,
}),
cobs: optional(cobCountsSchema),
defaultBranch: optional(string()),
delegates: array(authorSchema),
threshold: number(),
visibility: union([
@@ -106,6 +129,27 @@ const repoSchema = object({
refs: record(string(), string()),
}).optional(),
alias: string().optional(),
}).transform(repo => {
// Older httpd doesn't send `cobs`, so only a node without it needs the
// legacy fields. A newer node that leaves out `defaultBranch` has none.
if (repo.cobs === undefined) {
return {
...repo,
...legacyRepoFields(
repo.payloads["xyz.radicle.project"],
repo.payloads["xyz.radicle.crefs"],
repo.refs,
),
};
}
return {
...repo,
cobs: repo.cobs,
// The unredacted delegate releases, which the releases tab opens on.
// Absent when the node cannot serve releases.
releaseCount: repo.cobs.releases?.delegate,
};
});
const reposSchema = array(repoSchema);
@@ -387,9 +431,10 @@ export class Client {
);
return commits;
} catch (error) {
// Older nodes don't serve the dedicated commit-count endpoint, so fall
// Compat: httpd < 0.27.0 doesn't serve the commit-count endpoint, so fall
// back to the tree stats endpoint, which also returns the commit count.
// TODO: Drop this fallback once enough nodes serve /stats/commits.
// Outside the support window; remove once the e2e tests stop running
// against httpd 0.26.0.
if (error instanceof ResponseError && error.status === 404) {
const stats = await this.getTreeStatsBySha(rid, sha, options);
return stats.commits;
@@ -496,9 +541,10 @@ export class Client {
diffStatsSchema,
);
} catch (error) {
// Older nodes don't serve the dedicated diff-stats endpoint, so fall back
// to the full diff, which also carries the stats.
// TODO: Drop this fallback once enough nodes serve /diff/:base/:oid/stats.
// Compat: httpd < 0.27.0 doesn't serve the diff-stats endpoint, so fall
// back to the full diff, which also carries the stats. Outside the
// support window; remove once the e2e tests stop running against httpd
// 0.26.0.
if (error instanceof ResponseError && error.status === 404) {
const { diff } = await this.getDiff(
rid,
@@ -618,9 +664,6 @@ export class Client {
page?: number;
perPage?: number;
scope?: ReleaseScope;
// Older nodes ignore `scope` and only know this superset of both
// scopes.
allAuthors?: boolean;
showRedacted?: boolean;
},
options?: RequestOptions,
@@ -629,10 +672,52 @@ export class Client {
{
method: "GET",
path: `repos/${rid}/releases`,
query,
query: { ...query, ...legacyReleasesQuery(query?.scope) },
options,
},
releasesSchema,
);
}
// One page of releases in an author scope, and whether more may follow.
// Takes the delegates as a promise too, so that the page can load
// alongside the repo.
public async getReleasesPage(
rid: string,
delegates: Author[] | Promise<Author[]>,
query: { scope: ReleaseScope; page: number; perPage: number },
options?: RequestOptions,
): Promise<{ releases: Release[]; morePages: boolean }> {
const [response, authors] = await Promise.all([
this.getAllReleases(rid, query, options),
delegates,
]);
return {
releases: legacyScopeReleases(response, authors, query.scope),
// Page on the response, as older nodes fill it with every author.
morePages: response.length === query.perPage,
};
}
// Whether anyone other than a delegate has a release that a user can see.
public async hasOtherReleases(
repo: Repo,
perPage: number,
options?: RequestOptions,
): Promise<boolean> {
const counts = repo.cobs?.releases;
if (counts) {
return counts.other > 0;
}
return legacyHasOtherReleases(
() =>
this.getAllReleases(
repo.rid,
{ scope: "untrusted", page: 0, perPage },
options,
),
repo.delegates,
perPage,
);
}
}