Files
buzz/desktop/src/features/projects/useAddProjectRepository.test.mjs
thomaspblock 122a8b8988 Projects v3: unify sharing, discussions, and issue ownership (#5792)
## Summary

Projects v3 makes repository work shareable, discussion-aware, and
easier to scan in one coherent workspace. People can copy canonical
links, reopen the exact workspace tab, understand issue and pull-request
context at a glance, find related channel conversations, and assign or
unassign issues across Desktop and CLI.

- **Unified workspace** — top-level sections sit above repository
controls in one rounded workspace, with navigation positioned close to
the page heading. README and Files retain branch selection; every
section has a labeled icon header, and Issues and Pull Requests expose
creation from a consistent right-aligned action.
- **Repository management** — the repository selector is always
available, including single-repository projects. Its integrated add flow
lets project owners create a repository manually or select an existing
repository without a separate toolbar button.
- **Readable work-item lists** — issue and pull-request rows use
plain-language context instead of opaque metadata. Files, commits,
issues, pull requests, channels, and contributors share consistent row
density and right-aligned timestamps, while deterministic
fallback-avatar colors keep participants distinct on light backgrounds.
Inbox pull-request metadata wraps between complete phrases and truncates
long channel names instead of compressing copy into narrow columns.
- **Reliable entity links** — projects, repositories, issues, pull
requests, and commits have canonical `buzz://` links, preview cards, OS
deep-link routing, and tab-aware navigation. Reopening the same link
re-applies its destination instead of leaving the user on a locally
selected tab.
- **Related conversations** — repository and work-item views surface
channels discussing the current entity, including participants, channel
navigation, message context, and an explicit notice when discovery
reaches its 500-result cap.
- **Reversible issue ownership** — trusted assignment and unassignment
events work across Desktop, Tauri, `buzz-sdk`, and `buzz issues`.
Assignees appear in project views and the assigned inbox, while
authorized users can remove assignments directly from the assignee row.

Assignment state is derived chronologically from labeled Nostr notes.
Issue authors and repository owners may change any assignee; other users
may only assign or unassign themselves. Shared golden fixtures keep
entity-link grammar and validation aligned across TypeScript and Rust.

The branch also updates `webbrowser` to the patched release for
RUSTSEC-2026-0257.

### Related issue

N/A.

### Testing

- [x] `just ci` — formatting, lint, typechecking, unit tests, and builds
passed
- [x] Full pre-push suite — organization, branch-skew, Desktop checks,
typechecking, and tests passed on the latest push
- [x] `cargo test -p buzz-cli` and focused `buzz-sdk` assignment tests
passed
- [x] Focused Tauri recipient-note and 500-result search-limit tests
passed
- [x] Desktop entity-link and issue-assignment unit tests passed
- [x] Playwright smoke coverage passed for assignment, repeated
entity-link navigation, repository create/select flows, section headers
and actions, timestamp alignment, timeline icons, sentence-style
issue/PR metadata, header spacing, avatar contrast, and Inbox metadata
at stacked and side-rail breakpoints
- [ ] Manual staging pass: link round-trips, Channels tab, assignment
flows, and inbox routing

### Screenshots

Pull requests explain who opened the request, where it lives, and which
branch it comes from; fallback avatars remain visually distinct.

![Pull request list with conversational
metadata](https://raw.githubusercontent.com/block/buzz/2a536de86f7e6f79b349d7bc147b2923ff2b817d/pr-5624--05-pr-list-metadata.png)

Issues use the same sentence-style hierarchy while keeping status and
recency easy to scan.

![Issue list with conversational
metadata](https://raw.githubusercontent.com/block/buzz/2a536de86f7e6f79b349d7bc147b2923ff2b817d/pr-5624--06-issue-list-metadata.png)

The wide Inbox detail keeps author, timestamp, and origin context
readable beside its metadata rail.

![Pull request Inbox detail with readable
metadata](https://raw.githubusercontent.com/block/buzz/e65b433e14b97c45365ed7b68ea402ec01d26615/pr-5624--02-pull-request-detail-wide.png)

[View the complete six-state Projects v3 screenshot
set](https://github.com/block/buzz/pull/5624#issuecomment-5268039672)
and [the compact/wide Inbox
comparison](https://github.com/block/buzz/pull/5624#issuecomment-5268614585).


---

> Supersedes #5624, whose head commit accumulated permanently-queued
required check suites (block-dco-check et al.) that GitHub never
dispatched. History flattened into a single signed-off commit on latest
main; tree verified byte-identical (`git merge-tree`) to merging the
original branch into main.

---------

Signed-off-by: Thomas Petersen <thomasp@squareup.com>
Co-authored-by: Wintermute <3f1797424fd9ad6653a83665c660517777cd7f8c228c0d5907f49e01537f3ca5@buzz.block.builderlab.xyz>
2026-08-14 16:48:41 -04:00

203 lines
5.8 KiB
JavaScript

import assert from "node:assert/strict";
import test from "node:test";
import { addProjectRepository } from "./useAddProjectRepository.ts";
// ── Partial-publish retry heals through the real mutation ───────────────────
//
// Round-3 review finding: the resume-aware dominated-write guard is only
// meaningful if a retry can actually reach it. After a partial publish (the
// project head landed, the repository event did not), the live head's
// created_at is necessarily NEWER than the cached snapshot — the failed
// mutation never updated the cache. A template-builder unit test cannot catch
// an early unconditional guard throwing first, so these tests run the whole
// exported mutation with stubbed relay/publish seams.
const OWNER = "a".repeat(64);
const ACCESS_CHANNEL = "11111111-1111-4111-8111-111111111111";
const EXISTING_ADDRESS = `30617:${OWNER}:desktop`;
const NEW_ADDRESS = `30617:${OWNER}:mobile`;
function makeProject(overrides = {}) {
return {
id: `30621:${OWNER}:platform`,
createdAt: 100,
dtag: "platform",
owner: OWNER,
accessChannelId: ACCESS_CHANNEL,
repositoryAddresses: [EXISTING_ADDRESS],
repositories: [],
...overrides,
};
}
/** Live head as left by a partial publish: newer than the cached snapshot
* (created_at 101 > 100) and already referencing the new coordinate. */
function makeDanglingLiveHead() {
return {
id: "f".repeat(64),
kind: 30621,
pubkey: OWNER,
created_at: 101,
content: "",
tags: [
["d", "platform"],
["buzz-channel", ACCESS_CHANNEL],
["a", EXISTING_ADDRESS],
["a", NEW_ADDRESS],
],
sig: "0".repeat(128),
};
}
function makeRepositoryEvent(createdAt) {
return {
id: "b".repeat(64),
kind: 30617,
pubkey: OWNER,
created_at: createdAt,
content: "",
tags: [
["d", "mobile"],
["name", "Mobile"],
["buzz-channel", ACCESS_CHANNEL],
],
sig: "0".repeat(128),
};
}
/** fetchEvents stub: live project head exists (newer than cache), and no
* repository head exists at the new coordinate — the dangling-member state. */
function makeFetchEvents(liveHead) {
return async (filter) => {
if (filter.kinds?.includes(30621)) return [liveHead];
return [];
};
}
test("retry after a partial publish heals the dangling member instead of throwing (local path)", async () => {
const published = [];
const result = await addProjectRepository(
{
accessChannelId: ACCESS_CHANNEL,
name: "Mobile",
project: makeProject(),
},
{
fetchEvents: makeFetchEvents(makeDanglingLiveHead()),
publishOwnerAnnouncement: async (input) => {
published.push(input);
return {
event: makeRepositoryEvent(input.createdAt),
publicationError: null,
};
},
},
);
// The heal publishes ONLY the missing repository event — republishing the
// project head would advance created_at for nothing.
assert.deepEqual(
published.map((input) => input.kind),
[30617],
"resume must publish exactly one repository event and no project head",
);
assert.equal(result.repository.dtag, "mobile");
assert.ok(
result.project.repositoryAddresses.includes(NEW_ADDRESS),
"the healed project must list the repaired coordinate",
);
});
test("retry after a partial publish heals through the owner-agent path", async () => {
const batches = [];
const result = await addProjectRepository(
{
accessChannelId: ACCESS_CHANNEL,
name: "Mobile",
ownerControlAgentPubkey: "c".repeat(64),
project: makeProject(),
},
{
fetchEvents: makeFetchEvents(makeDanglingLiveHead()),
publishOwnedAgentAnnouncements: async (_agent, templates) => {
batches.push(templates);
return templates.map((template) =>
makeRepositoryEvent(template.createdAt),
);
},
},
);
assert.equal(batches.length, 1);
assert.deepEqual(
batches[0].map((template) => template.kind),
[30617],
"resume must send only the missing repository event to the owner agent",
);
assert.equal(result.repository.dtag, "mobile");
});
test("a genuinely dominated write (no dangling member) still throws", async () => {
// Live head is newer than the cache but does NOT reference the coordinate:
// another session advanced the project. The guard must still block the
// write instead of clobbering it.
const liveHead = {
...makeDanglingLiveHead(),
tags: [
["d", "platform"],
["buzz-channel", ACCESS_CHANNEL],
["a", EXISTING_ADDRESS],
],
};
await assert.rejects(
addProjectRepository(
{
accessChannelId: ACCESS_CHANNEL,
name: "Mobile",
project: makeProject(),
},
{
fetchEvents: makeFetchEvents(liveHead),
publishOwnerAnnouncement: async () => {
throw new Error("must not publish past the dominated-write guard");
},
},
),
/updated by another session/,
);
});
test("a dangling member with an unmoved head still resumes", async () => {
// Crash-recovery shape: the partial state can also be observed with a
// cache that already caught up (created_at equal). Resume must not depend
// on the head being newer.
const liveHead = { ...makeDanglingLiveHead(), created_at: 100 };
const published = [];
const result = await addProjectRepository(
{
accessChannelId: ACCESS_CHANNEL,
name: "Mobile",
project: makeProject(),
},
{
fetchEvents: makeFetchEvents(liveHead),
publishOwnerAnnouncement: async (input) => {
published.push(input);
return {
event: makeRepositoryEvent(input.createdAt),
publicationError: null,
};
},
},
);
assert.deepEqual(
published.map((input) => input.kind),
[30617],
);
assert.equal(result.repository.dtag, "mobile");
});