Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion desktop/src/features/projects/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import * as React from "react";

import { relayClient } from "@/shared/api/relayClient";
import { getRelaySelf } from "@/features/moderation/lib/relaySelf";
import { getCachedRelayOrigin } from "@/shared/lib/mediaUrl";
import { signRelayEvent } from "@/shared/api/tauri";
import { getIdentity } from "@/shared/api/tauriIdentity";
Expand Down Expand Up @@ -345,9 +346,17 @@ function eventToRepoState(event: RelayEvent): RepoState {
}

async function fetchRepoState(project: Project): Promise<RepoState | null> {
const relaySelf = await getRelaySelf();
const trustedAuthors = [
...new Set(
[project.owner, relaySelf].filter((value): value is string =>
Boolean(value),
),
),
];
const events = await relayClient.fetchEvents({
kinds: [KIND_REPO_STATE],
authors: [project.owner],
authors: trustedAuthors,
"#d": [project.dtag],
limit: 1,
});
Expand Down
41 changes: 40 additions & 1 deletion desktop/src/testing/e2eBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4748,6 +4748,36 @@ function mulberry32(seed: number) {
}

let mockProjectEventStore: RelayEvent[] | null = null;
const MOCK_PROJECT_BRANCHES_KEY = "buzz-e2e-project-branches";

function readMockProjectBranches(): Record<string, Record<string, string>> {
try {
return JSON.parse(
window.sessionStorage.getItem(MOCK_PROJECT_BRANCHES_KEY) ?? "{}",
);
} catch {
return {};
}
}

function writeMockProjectBranch(
dtag: string,
branch: string,
commit: string | null,
) {
const projects = readMockProjectBranches();
const branches = { ...(projects[dtag] ?? {}) };
if (commit) {
branches[branch] = commit;
} else {
delete branches[branch];
}
projects[dtag] = branches;
window.sessionStorage.setItem(
MOCK_PROJECT_BRANCHES_KEY,
JSON.stringify(projects),
);
}

function buildMockProjectEvents(): RelayEvent[] {
const events: RelayEvent[] = [];
Expand Down Expand Up @@ -4795,8 +4825,11 @@ function buildMockProjectEvents(): RelayEvent[] {
}`,
],
["refs/heads/main", "0123456789abcdef0123456789abcdef01234567"],
...Object.entries(readMockProjectBranches()[seed.dtag] ?? {}).map(
([branch, commit]) => [`refs/heads/${branch}`, commit],
),
],
owner,
getConfig()?.mock?.relaySelf ?? owner,
now - projectIndex,
`mock-repo-state-${seed.dtag}`.replace(/[^a-zA-Z0-9]/g, ""),
),
Expand Down Expand Up @@ -9427,6 +9460,9 @@ export function maybeInstallE2eTauriMocks() {
]);
repoState.created_at = Math.floor(Date.now() / 1000);
}
if (dtag) {
writeMockProjectBranch(dtag, input.newBranch, input.expectedCommit);
}
return {
branch: input.newBranch,
commit: input.expectedCommit,
Expand Down Expand Up @@ -9455,6 +9491,9 @@ export function maybeInstallE2eTauriMocks() {
);
repoState.created_at = Math.floor(Date.now() / 1000);
}
if (dtag) {
writeMockProjectBranch(dtag, input.branch, null);
}
return {
branch: input.branch,
commit: input.expectedCommit,
Expand Down
11 changes: 10 additions & 1 deletion desktop/tests/e2e/project-pr-review.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,10 @@ test("project branches can be created from the selected remote branch", async ({
page,
}) => {
await enableProjectsFeature(page);
await installMockBridge(page, { projectHeadBranch: "master" });
await installMockBridge(page, {
projectHeadBranch: "master",
relaySelf: TEST_IDENTITIES.bob.pubkey,
});
await openBuzzProject(page);

await page.getByRole("button", { name: /main/ }).click();
Expand Down Expand Up @@ -745,6 +748,12 @@ test("project branches can be created from the selected remote branch", async ({
() => window.__BUZZ_E2E_COMMANDS__ ?? [],
);
expect(commands).toContain("create_project_remote_branch");

await openBuzzProject(page);
await page.getByRole("button", { name: /main/ }).click();
await expect(
page.getByRole("menuitemradio", { name: "feature/branch-management" }),
).toBeVisible();
});

test("project branches can be deleted but the default branch cannot", async ({
Expand Down
2 changes: 2 additions & 0 deletions desktop/tests/helpers/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ export type MockAgentMemoryListing = {
type MockBridgeOptions = {
/** Advertised HEAD for the first mock project without adding that branch. */
projectHeadBranch?: string;
/** Relay NIP-11 identity used to sign authoritative repository state. */
relaySelf?: string | null;
/** Builderlab account returned by hosted-community onboarding. Null/omitted = signed out. */
builderlabAuth?: { email?: string; name?: string; expiresAt: string } | null;
/** Bound Builderlab Nostr identity. Null/omitted = not linked yet. */
Expand Down
Loading