mirror of
https://github.com/block/buzz.git
synced 2026-10-27 04:30:52 +00:00
fix(desktop): harden relay mesh connect p-tag (#834)
This commit is contained in:
@@ -9,9 +9,15 @@ import { openSettings } from "../helpers/settings";
|
||||
// invariant and the membership-denial copy.
|
||||
|
||||
type E2eWindow = Window & {
|
||||
__SPROUT_E2E__?: { mock?: { meshReporterPubkey?: string } };
|
||||
__SPROUT_E2E_INVOKE_MOCK_COMMAND__?: unknown;
|
||||
__TAURI_INTERNALS__?: { invoke?: unknown };
|
||||
__SPROUT_E2E_COMMANDS__?: string[];
|
||||
__SPROUT_E2E_SIGNED_EVENTS__?: Array<{
|
||||
content: string;
|
||||
kind: number;
|
||||
tags: string[][];
|
||||
}>;
|
||||
__SPROUT_E2E_SET_MESH__?: (mesh: {
|
||||
admitted?: boolean;
|
||||
models?: Array<{ id: string; name: string | null }>;
|
||||
@@ -44,6 +50,13 @@ async function commands(page: import("@playwright/test").Page) {
|
||||
);
|
||||
}
|
||||
|
||||
/** Signed event templates the bridge recorded so far. */
|
||||
async function signedEvents(page: import("@playwright/test").Page) {
|
||||
return page.evaluate(
|
||||
() => (window as E2eWindow).__SPROUT_E2E_SIGNED_EVENTS__ ?? [],
|
||||
);
|
||||
}
|
||||
|
||||
async function setMesh(
|
||||
page: import("@playwright/test").Page,
|
||||
mesh: { admitted?: boolean; denyReason?: string },
|
||||
@@ -53,6 +66,17 @@ async function setMesh(
|
||||
}, mesh);
|
||||
}
|
||||
|
||||
async function openManagedAgentActions(
|
||||
page: import("@playwright/test").Page,
|
||||
pubkey: string,
|
||||
) {
|
||||
const trigger = page.getByTestId(`managed-agent-actions-${pubkey}`);
|
||||
await trigger.scrollIntoViewIfNeeded();
|
||||
await trigger.focus();
|
||||
await trigger.press("Enter");
|
||||
await expect(trigger).toHaveAttribute("data-state", "open");
|
||||
}
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await installMockBridge(page);
|
||||
});
|
||||
@@ -157,6 +181,80 @@ test("Run-on-relay-mesh ensures the client node BEFORE spawning the agent", asyn
|
||||
expect(ensureIdx).toBeLessThan(createIdx);
|
||||
});
|
||||
|
||||
test("Run-on-relay-mesh skips connect signaling for own serve target", async ({
|
||||
page,
|
||||
}) => {
|
||||
await gotoApp(page);
|
||||
await page.getByTestId("open-agents-view").click();
|
||||
await page.getByRole("button", { name: "New" }).click();
|
||||
await page.getByText("Custom Agent").click();
|
||||
await page.getByTestId("agent-name-input").fill("Own Mesh Agent");
|
||||
|
||||
const toggle = page.getByTestId("agent-relay-mesh-toggle");
|
||||
await expect(toggle).toBeEnabled({ timeout: 10_000 });
|
||||
await toggle.click();
|
||||
await page
|
||||
.getByTestId("agent-relay-mesh-model")
|
||||
.selectOption({ label: "SmolLM2 135M — Mock desktop" });
|
||||
|
||||
const before = (await commands(page)).length;
|
||||
await page.getByTestId("create-agent-submit").click();
|
||||
await expect
|
||||
.poll(async () => (await commands(page)).slice(before))
|
||||
.toContain("create_managed_agent");
|
||||
|
||||
const slice = (await commands(page)).slice(before);
|
||||
expect(slice).toContain("mesh_ensure_client_node");
|
||||
expect(
|
||||
(await signedEvents(page)).filter((event) => event.kind === 24621),
|
||||
).toHaveLength(0);
|
||||
});
|
||||
|
||||
test("Run-on-relay-mesh canonicalizes the mesh connect #p target", async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.addInitScript(() => {
|
||||
const w = window as E2eWindow;
|
||||
w.__SPROUT_E2E__ = {
|
||||
...(w.__SPROUT_E2E__ ?? {}),
|
||||
mock: {
|
||||
...(w.__SPROUT_E2E__?.mock ?? {}),
|
||||
meshReporterPubkey:
|
||||
" CAFEBABECAFEBABECAFEBABECAFEBABECAFEBABECAFEBABECAFEBABECAFEBABE ",
|
||||
},
|
||||
};
|
||||
});
|
||||
await gotoApp(page);
|
||||
await page.getByTestId("open-agents-view").click();
|
||||
await page.getByRole("button", { name: "New" }).click();
|
||||
await page.getByText("Custom Agent").click();
|
||||
await page.getByTestId("agent-name-input").fill("Mesh Agent");
|
||||
|
||||
const toggle = page.getByTestId("agent-relay-mesh-toggle");
|
||||
await expect(toggle).toBeEnabled({ timeout: 10_000 });
|
||||
await toggle.click();
|
||||
await page
|
||||
.getByTestId("agent-relay-mesh-model")
|
||||
.selectOption({ label: "SmolLM2 135M — Mock desktop" });
|
||||
|
||||
await page.getByTestId("create-agent-submit").click();
|
||||
await expect
|
||||
.poll(async () =>
|
||||
(await signedEvents(page)).find((event) => event.kind === 24621),
|
||||
)
|
||||
.toMatchObject({
|
||||
tags: [
|
||||
[
|
||||
"p",
|
||||
"cafebabecafebabecafebabecafebabecafebabecafebabecafebabecafebabe",
|
||||
],
|
||||
],
|
||||
});
|
||||
await expect
|
||||
.poll(async () => await commands(page))
|
||||
.toContain("create_managed_agent");
|
||||
});
|
||||
|
||||
test("a non-member cannot enable relay-mesh — membership is the gate", async ({
|
||||
page,
|
||||
}) => {
|
||||
@@ -179,3 +277,89 @@ test("a non-member cannot enable relay-mesh — membership is the gate", async (
|
||||
const seq = await commands(page);
|
||||
expect(seq).not.toContain("create_managed_agent");
|
||||
});
|
||||
|
||||
test("saved relay-mesh agents require a fresh serve target before manual start", async ({
|
||||
page,
|
||||
}) => {
|
||||
await gotoApp(page);
|
||||
await page.getByTestId("open-agents-view").click();
|
||||
await page.getByRole("button", { name: "New" }).click();
|
||||
await page.getByText("Custom Agent").click();
|
||||
await page.getByTestId("agent-name-input").fill("Saved relay mesh agent");
|
||||
|
||||
const toggle = page.getByTestId("agent-relay-mesh-toggle");
|
||||
await expect(toggle).toBeEnabled({ timeout: 10_000 });
|
||||
await toggle.click();
|
||||
await page
|
||||
.getByTestId("agent-relay-mesh-model")
|
||||
.selectOption({ label: "SmolLM2 135M — Mock desktop" });
|
||||
|
||||
await page.getByTestId("create-agent-submit").click();
|
||||
await expect
|
||||
.poll(async () => await commands(page))
|
||||
.toContain("create_managed_agent");
|
||||
|
||||
const agents = await page.evaluate(async () => {
|
||||
const w = window as E2eWindow & {
|
||||
__SPROUT_E2E_INVOKE_MOCK_COMMAND__?: (
|
||||
command: string,
|
||||
payload?: Record<string, unknown>,
|
||||
) => Promise<Array<{ name: string; pubkey: string }>>;
|
||||
};
|
||||
const invoke = w.__SPROUT_E2E_INVOKE_MOCK_COMMAND__;
|
||||
if (!invoke) throw new Error("Mock invoke bridge is unavailable.");
|
||||
return invoke("list_managed_agents");
|
||||
});
|
||||
const pubkey = agents.find(
|
||||
(agent) => agent.name === "Saved relay mesh agent",
|
||||
)?.pubkey;
|
||||
expect(pubkey).toBeTruthy();
|
||||
|
||||
const row = page.getByTestId(`managed-agent-${pubkey}`);
|
||||
await expect(row).toContainText("Saved relay mesh agent");
|
||||
await expect(row).toContainText("running");
|
||||
await page.getByRole("button", { name: "Done" }).click();
|
||||
await expect(page.getByRole("dialog", { name: "Agent created" })).toHaveCount(
|
||||
0,
|
||||
);
|
||||
|
||||
await openManagedAgentActions(page, pubkey);
|
||||
await page.getByRole("menuitem", { name: "Stop" }).click();
|
||||
await expect
|
||||
.poll(async () => await commands(page))
|
||||
.toContain("stop_managed_agent");
|
||||
await expect(row).toContainText("stopped");
|
||||
|
||||
const before = (await commands(page)).length;
|
||||
await openManagedAgentActions(page, pubkey);
|
||||
await page.getByRole("menuitem", { name: "Spawn" }).click();
|
||||
|
||||
await expect(
|
||||
page
|
||||
.locator("[data-sonner-toast]")
|
||||
.filter({ hasText: "Relay-mesh agents need a fresh serve target" }),
|
||||
).toBeVisible();
|
||||
expect((await commands(page)).slice(before)).not.toContain(
|
||||
"start_managed_agent",
|
||||
);
|
||||
await expect(row).toContainText("stopped");
|
||||
|
||||
await expect(
|
||||
page.evaluate(async (agentPubkey) => {
|
||||
const invoke = (window as E2eWindow).__SPROUT_E2E_INVOKE_MOCK_COMMAND__ as
|
||||
| ((
|
||||
command: string,
|
||||
payload?: Record<string, unknown>,
|
||||
) => Promise<unknown>)
|
||||
| undefined;
|
||||
if (!invoke) throw new Error("Mock invoke bridge is unavailable.");
|
||||
try {
|
||||
await invoke("start_managed_agent", { pubkey: agentPubkey });
|
||||
return "started";
|
||||
} catch (err) {
|
||||
return err instanceof Error ? err.message : String(err);
|
||||
}
|
||||
}, pubkey),
|
||||
).resolves.toContain("selected serve target is not persisted");
|
||||
await expect(row).toContainText("stopped");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user