mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 22:30:41 +08:00
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
212 lines
6.0 KiB
TypeScript
212 lines
6.0 KiB
TypeScript
import type { Page } from "@playwright/test";
|
|
import type { PeerManager, RadiclePeer } from "@tests/support/peerManager";
|
|
|
|
import * as Fs from "node:fs/promises";
|
|
import * as Path from "node:path";
|
|
|
|
import { defaultConfig, gitOptions } from "@tests/support/fixtures.js";
|
|
|
|
export async function changeBranch(peer: string, branch: string, page: Page) {
|
|
await page.locator('[title="Change branch"]:visible').first().click();
|
|
const peerLocator = page.getByLabel("peer-item").filter({ hasText: peer });
|
|
|
|
const branchButton = page.getByRole("button", { name: branch });
|
|
const isVisible = await branchButton.isVisible().catch(() => false);
|
|
|
|
if (!isVisible) {
|
|
await peerLocator.getByTitle("Expand peer").click();
|
|
}
|
|
|
|
await branchButton.click();
|
|
}
|
|
|
|
// Create a repo using the rad CLI.
|
|
export async function createRepo(
|
|
peer: RadiclePeer,
|
|
{
|
|
name,
|
|
description = "",
|
|
defaultBranch = "main",
|
|
visibility = "public",
|
|
}: {
|
|
name: string;
|
|
description?: string;
|
|
defaultBranch?: string;
|
|
visibility?: "public" | "private";
|
|
},
|
|
): Promise<{ rid: string; repoFolder: string; defaultBranch: string }> {
|
|
const repoFolder = Path.join(peer.checkoutPath, name);
|
|
|
|
await peer.git(["init", name, "--initial-branch", defaultBranch], {
|
|
cwd: peer.checkoutPath,
|
|
});
|
|
await peer.git(["commit", "--allow-empty", "--message", "initial commit"], {
|
|
cwd: repoFolder,
|
|
});
|
|
await peer.rad(
|
|
[
|
|
"init",
|
|
"--name",
|
|
name,
|
|
"--default-branch",
|
|
defaultBranch,
|
|
"--description",
|
|
description,
|
|
`--${visibility}`,
|
|
],
|
|
{
|
|
cwd: repoFolder,
|
|
},
|
|
);
|
|
|
|
const { stdout: rid } = await peer.rad(["inspect"], {
|
|
cwd: repoFolder,
|
|
});
|
|
|
|
return { rid, repoFolder, defaultBranch };
|
|
}
|
|
|
|
// Run a rad-artifact command without prompts or network announcements.
|
|
export function radArtifact(
|
|
peer: RadiclePeer,
|
|
repoFolder: string,
|
|
args: string[],
|
|
) {
|
|
return peer.spawn("rad-artifact", ["--no-announce", "--no-input", ...args], {
|
|
cwd: repoFolder,
|
|
});
|
|
}
|
|
|
|
// Add a peer that has cloned the repo but is not a delegate, so tests can
|
|
// create releases and artifacts from a non-delegate author. Its contributions
|
|
// live in its own storage; pull them into the delegate's storage, which the UI
|
|
// reads, with `syncFrom`. The contributor is always Eve, which is safe because
|
|
// `peerManager` is scoped to a single test.
|
|
export async function createContributor(
|
|
peerManager: PeerManager,
|
|
delegate: RadiclePeer,
|
|
{ rid, repoName }: { rid: string; repoName: string },
|
|
): Promise<{ contributor: RadiclePeer; repoFolder: string }> {
|
|
const contributor = await peerManager.createPeer({
|
|
name: "eve",
|
|
gitOptions: gitOptions["eve"],
|
|
});
|
|
await contributor.startNode({
|
|
node: { ...defaultConfig.node, connect: [delegate.address], alias: "eve" },
|
|
});
|
|
await contributor.rad(["clone", rid, "--seed", delegate.nodeId], {
|
|
cwd: contributor.checkoutPath,
|
|
});
|
|
|
|
return {
|
|
contributor,
|
|
repoFolder: Path.join(contributor.checkoutPath, repoName),
|
|
};
|
|
}
|
|
|
|
// Fetch what other peers have contributed to the repo. Artifact fixtures are
|
|
// registered without announcing, so the delegate's node needs an explicit
|
|
// fetch before its httpd serves them.
|
|
// Replace a repo's identity document with one that has no project payload,
|
|
// so its default branch comes only from the canonical refs payload.
|
|
export async function dropProjectPayload(
|
|
peer: RadiclePeer,
|
|
repoFolder: string,
|
|
defaultBranch = "main",
|
|
) {
|
|
const { stdout: did } = await peer.rad(["self", "--did"]);
|
|
const docPath = `${repoFolder}.identity.json`;
|
|
await Fs.writeFile(
|
|
docPath,
|
|
JSON.stringify({
|
|
payload: {
|
|
"xyz.radicle.crefs": {
|
|
rules: {
|
|
[`refs/heads/${defaultBranch}`]: {
|
|
allow: "delegates",
|
|
threshold: 1,
|
|
},
|
|
},
|
|
symbolic: { HEAD: `refs/heads/${defaultBranch}` },
|
|
},
|
|
},
|
|
delegates: [did],
|
|
threshold: 1,
|
|
}),
|
|
);
|
|
|
|
// `rad id update --edit` only runs its editor in a terminal, so `script`
|
|
// provides one. The editor then copies the prepared document into place.
|
|
const update = [
|
|
"rad",
|
|
"id",
|
|
"update",
|
|
"--edit",
|
|
"--title",
|
|
"Drop project payload",
|
|
"--description",
|
|
"Use canonical refs only",
|
|
"--no-confirm",
|
|
// Printing the result panics on the zero-width terminal of `script`.
|
|
"--quiet",
|
|
];
|
|
const quoted = update.map(arg => `'${arg}'`).join(" ");
|
|
const script =
|
|
process.platform === "darwin"
|
|
? `script -q /dev/null ${quoted}`
|
|
: `script -qec "${quoted}" /dev/null`;
|
|
// `script` reads the terminal settings of its standard input, which a pipe
|
|
// doesn't have.
|
|
await peer.spawn("sh", ["-c", `${script} < /dev/null`], {
|
|
cwd: repoFolder,
|
|
env: { EDITOR: `cp ${docPath}` },
|
|
});
|
|
}
|
|
|
|
export async function syncFrom(peer: RadiclePeer, repoFolder: string) {
|
|
await peer.rad(["sync", "--fetch"], { cwd: repoFolder });
|
|
}
|
|
|
|
// Write a file and register it as a release artifact. The file is named after
|
|
// the artifact and the CID is computed from its contents, which default to the
|
|
// name, so artifacts in one release need distinct names to get distinct CIDs.
|
|
// The release is created when `release` is not given.
|
|
export async function registerArtifact(
|
|
peer: RadiclePeer,
|
|
repoFolder: string,
|
|
{
|
|
name,
|
|
content = `${name}\n`,
|
|
revision = "HEAD",
|
|
release,
|
|
}: {
|
|
name: string;
|
|
content?: string;
|
|
revision?: string;
|
|
release?: string;
|
|
},
|
|
): Promise<{ releaseId: string; cid: string }> {
|
|
const artifactPath = Path.join(repoFolder, name);
|
|
await Fs.writeFile(artifactPath, content);
|
|
|
|
const { stdout } = await radArtifact(peer, repoFolder, [
|
|
"register",
|
|
artifactPath,
|
|
...(release ? ["--release", release] : ["--revision", revision]),
|
|
"--name",
|
|
name,
|
|
"--json",
|
|
]);
|
|
|
|
return JSON.parse(stdout);
|
|
}
|
|
|
|
export function extractPatchId(cmdOutput: { stderr: string }) {
|
|
const match = cmdOutput.stderr.match(/[0-9a-f]{40}/);
|
|
if (match) {
|
|
return match[0];
|
|
} else {
|
|
throw new Error("Could not get patch id");
|
|
}
|
|
}
|