Files
buzz/desktop/src/features/projects/lib/projectCloneUrl.test.mjs
thomaspblock fb73561e64 feat(desktop): Projects follow-ups — access restrictions, fast loading, activity feed polish (#5073)
## Summary

Follow-up batch on the Projects overview (continues merged #1677):

- **Repository access restrictions** — repositories the viewer can't
reach are surfaced with a reason instead of failing silently.
Channel-ACL denials (which arrive as the same 404 as a missing repo, for
anti-enumeration) are re-classified using the repository's channel
binding and the viewer's memberships (`useRepositoryAccess.ts`,
`projectRepoAvailability.ts`).
- **Projects loads in seconds instead of minutes** — enumeration no
longer crawls every kind:5 deletion event on the relay. It fetches
project/repo announcements first, then queries deletions scoped to those
coordinates via chunked `#a` filters (3 queries instead of hundreds on
staging).
- **Activity feed layout polish** — bare event-type glyph beside the
headline (no badge circle), timeline spine runs through the avatars
connecting consecutive cards, linkable actor/project names are bold in
theme foreground, rounded hover state, alignment fixes.
- **Create button pinned** — the "+" create menu is pinned to the pane's
top-right corner (equal 16px insets) and no longer scrolls away with the
page header.
- **List controls as a table header** — the scope selector (left) and
sort + layout toggle (right) render as the first row of the list
container on the Projects/Repositories/PRs/Issues tabs; in card view the
identical bar stands alone with the cards below
(`ProjectsListHeaderBar.tsx`).
- **Repository rows show the git location** — subtitle is
`github.com/org/repo` for external repos or `owner/repo` (resolved
profile name) for Buzz-hosted ones, instead of repeating the project
name (`repositoryDisplayPath`).
- **Uniform work-item row heights** — issue rows previously ran the
author chip in inline flow, letting the 20px avatar grow the line box
~3px taller than PR rows; both lists now share the same flex subtitle.

📸 Screenshots: [feed layout / pinned
button](https://github.com/block/buzz/pull/5073#issuecomment-5214114069)
· [list header / repo subtitles / row
heights](https://github.com/block/buzz/pull/5073#issuecomment-5217480712).

Note: two empty `chore: retrigger CI` commits exist on the branch from
working around the Aug 6 GitHub Actions incident; happy to drop them
with a signoff rebase before undrafting if preferred. Latest `main` is
merged in (`a0cc35220`).

## Test plan

- [x] Desktop unit tests (4,493 pass after merging main), Biome, tsc
- [x] New unit tests for scoped deletion enumeration and repo
availability re-classification
- [x] New unit tests for `repositoryDisplayPath` (external, Buzz-hosted,
unresolvable)
- [x] Screenshot verification of feed layout, connector spine, and
pinned button (top + scrolled states) — posted to the PR
- [x] Screenshot verification of the list header row (list + card), repo
subtitles, and matching PR/issue row heights — posted to the PR
- [ ] Manual pass against staging (projects list load time,
restricted-repo states)

---------

Signed-off-by: Thomas Petersen <thomasp@squareup.com>
2026-08-07 19:23:35 +02:00

157 lines
4.4 KiB
JavaScript

import assert from "node:assert/strict";
import { test } from "node:test";
import { deriveRelayCloneUrl, effectiveCloneUrls } from "./projectCloneUrl.ts";
import {
projectRepoHost,
projectRepoHostForProject,
repositoryDisplayPath,
} from "./projectRepoHost.ts";
const OWNER = "a".repeat(64);
const ORIGIN = "https://relay.example";
test("deriveRelayCloneUrl builds the canonical relay-hosted path", () => {
assert.equal(
deriveRelayCloneUrl(ORIGIN, OWNER, "flappy-bee"),
`${ORIGIN}/git/${OWNER}/flappy-bee`,
);
});
test("deriveRelayCloneUrl lowercases the owner pubkey", () => {
const upper = "A".repeat(64);
assert.equal(
deriveRelayCloneUrl(ORIGIN, upper, "repo"),
`${ORIGIN}/git/${OWNER}/repo`,
);
});
test("deriveRelayCloneUrl tolerates a trailing slash on the origin", () => {
assert.equal(
deriveRelayCloneUrl(`${ORIGIN}/`, OWNER, "repo"),
`${ORIGIN}/git/${OWNER}/repo`,
);
});
test("deriveRelayCloneUrl fails closed on an unresolved origin", () => {
assert.equal(deriveRelayCloneUrl(null, OWNER, "repo"), null);
assert.equal(deriveRelayCloneUrl(undefined, OWNER, "repo"), null);
assert.equal(deriveRelayCloneUrl("", OWNER, "repo"), null);
});
test("deriveRelayCloneUrl declines a non-hex or wrong-length owner", () => {
assert.equal(deriveRelayCloneUrl(ORIGIN, "short", "repo"), null);
assert.equal(deriveRelayCloneUrl(ORIGIN, "z".repeat(64), "repo"), null);
});
test("deriveRelayCloneUrl declines a missing repo id", () => {
assert.equal(deriveRelayCloneUrl(ORIGIN, OWNER, ""), null);
});
test("effectiveCloneUrls honors explicit clone URLs over the derived default", () => {
const explicit = ["https://github.com/octocat/hello"];
assert.deepEqual(
effectiveCloneUrls(explicit, ORIGIN, OWNER, "repo"),
explicit,
);
});
test("effectiveCloneUrls derives a default when none is advertised", () => {
assert.deepEqual(effectiveCloneUrls([], ORIGIN, OWNER, "flappy-bee"), [
`${ORIGIN}/git/${OWNER}/flappy-bee`,
]);
});
test("effectiveCloneUrls returns empty when no default can be derived", () => {
assert.deepEqual(effectiveCloneUrls([], null, OWNER, "repo"), []);
});
test("projectRepoHost recognizes a canonical repository on the relay", () => {
assert.deepEqual(projectRepoHost(`${ORIGIN}/git/${OWNER}/buzz`, ORIGIN), {
kind: "buzz",
});
});
test("projectRepoHost identifies an external repository by host", () => {
assert.deepEqual(
projectRepoHost("https://github.com/block/buzz.git", ORIGIN),
{ kind: "external", host: "github.com" },
);
});
test("projectRepoHost treats a non-repository relay path as external", () => {
assert.deepEqual(projectRepoHost(`${ORIGIN}/other/path`, ORIGIN), {
kind: "external",
host: "relay.example",
});
});
test("projectRepoHost fails closed while either URL is unresolved", () => {
assert.deepEqual(projectRepoHost(null, ORIGIN), { kind: "unresolved" });
assert.deepEqual(projectRepoHost(`${ORIGIN}/git/${OWNER}/buzz`, null), {
kind: "unresolved",
});
assert.deepEqual(projectRepoHost("not a URL", ORIGIN), {
kind: "unresolved",
});
});
test("projectRepoHostForProject recognizes an implicit relay repository", () => {
assert.deepEqual(
projectRepoHostForProject(
{ cloneUrls: [], dtag: "buzz", owner: OWNER },
ORIGIN,
),
{ kind: "buzz" },
);
});
test("repositoryDisplayPath renders an external repo as host/path without .git", () => {
assert.equal(
repositoryDisplayPath(
{
cloneUrls: ["https://github.com/block/buzz.git"],
dtag: "buzz",
owner: OWNER,
},
ORIGIN,
),
"github.com/block/buzz",
);
});
test("repositoryDisplayPath renders a relay-hosted repo as owner/repo", () => {
assert.equal(
repositoryDisplayPath(
{ cloneUrls: [], dtag: "buzz", owner: OWNER },
ORIGIN,
"thomas",
),
"thomas/buzz",
);
});
test("repositoryDisplayPath falls back to a shortened pubkey owner", () => {
assert.equal(
repositoryDisplayPath(
{ cloneUrls: [], dtag: "buzz", owner: OWNER },
ORIGIN,
),
`${"a".repeat(8)}…/buzz`,
);
});
test("repositoryDisplayPath fails closed without a resolvable clone URL", () => {
assert.equal(
repositoryDisplayPath({ cloneUrls: [], dtag: "buzz", owner: OWNER }, null),
null,
);
assert.equal(
repositoryDisplayPath(
{ cloneUrls: ["not a URL"], dtag: "buzz", owner: OWNER },
ORIGIN,
),
null,
);
});