Files
buzz/desktop/tests/e2e/persistent-agent-audience.spec.ts
morgmart 19dc33bda6 Persist agent audiences with native inline mentions (#1949)
Signed-off-by: npub1n4y9luxx9y27pz5qz93vr9w8auyk7mmpgwf9gpe9tn4zv4kyhzjqtcntu7 <9d485ff0c62915e08a801162c195c7ef096f6f6143925407255cea2656c4b8a4@sprout-oss.stage.blox.sqprod.co>
Signed-off-by: npub1d6t84ajeg9skp2609l2k6axgcme8x7g7u7luj352r03hcwreg7lqnxcsex <6e967af659416160ab4f2fd56d74c8c6f273791ee7bfc9468a1be37c387947be@sprout-oss.stage.blox.sqprod.co>
Co-authored-by: npub1n4y9luxx9y27pz5qz93vr9w8auyk7mmpgwf9gpe9tn4zv4kyhzjqtcntu7 <9d485ff0c62915e08a801162c195c7ef096f6f6143925407255cea2656c4b8a4@sprout-oss.stage.blox.sqprod.co>
Co-authored-by: npub1d6t84ajeg9skp2609l2k6axgcme8x7g7u7luj352r03hcwreg7lqnxcsex <6e967af659416160ab4f2fd56d74c8c6f273791ee7bfc9468a1be37c387947be@sprout-oss.stage.blox.sqprod.co>
2026-07-16 10:25:44 -07:00

110 lines
3.5 KiB
TypeScript

import { expect, test, type Page } from "@playwright/test";
import { waitForAnimations } from "../helpers/animations";
import { installMockBridge } from "../helpers/bridge";
const SHOTS = "test-results/persistent-agent-audience";
const OWNER = "deadbeef".repeat(8);
const CHANNEL_ID = "9a1657ac-f7aa-5db0-b632-d8bbeb6dfb50";
const AGENT_A = "a".repeat(64);
const AGENT_B = "b".repeat(64);
const SCOPE = `${OWNER}:${CHANNEL_ID}:timeline`;
async function seedAudience(page: Page, pubkeys: string[], theme = "buzz") {
await page.addInitScript(
({ audience, scope, selectedTheme }) => {
window.localStorage.setItem("buzz:keep-addressed-agents-active", "1");
window.localStorage.setItem(
"buzz:persistent-agent-audiences:v2",
JSON.stringify({ [scope]: audience }),
);
window.localStorage.setItem("buzz-theme", selectedTheme);
},
{ audience: pubkeys, scope: SCOPE, selectedTheme: theme },
);
}
async function openGeneral(page: Page) {
await page.goto(`/#/channels/${CHANNEL_ID}`, {
waitUntil: "domcontentloaded",
});
await expect(page.getByTestId("chat-title")).toHaveText("general");
}
async function installAudienceFixtures(page: Page) {
await installMockBridge(page, {
managedAgents: [
{
pubkey: AGENT_A,
name: "Morgarita",
status: "running",
channelNames: ["general"],
},
{
pubkey: AGENT_B,
name: "Vogue",
status: "running",
channelNames: ["general"],
},
],
});
}
test("persistent agents restore through the native inline mention UI", async ({
page,
}) => {
await seedAudience(page, [AGENT_B, AGENT_A]);
await installAudienceFixtures(page);
await openGeneral(page);
const input = page.getByTestId("message-input");
await expect(input).toHaveText("@Vogue @Morgarita ");
await expect(page.getByText("Talking to", { exact: true })).toHaveCount(0);
await expect(input.locator(".agent-mention-highlight")).toHaveCount(2);
await input.fill("@Morgarita hello");
await expect
.poll(() =>
page.evaluate(
({ scope }) => {
const stored = JSON.parse(
localStorage.getItem("buzz:persistent-agent-audiences:v2") ?? "{}",
);
return stored[scope] ?? [];
},
{ scope: SCOPE },
),
)
.toEqual([AGENT_A]);
await page.getByTestId("send-message").click();
await expect(input).toContainText("@Morgarita");
await expect(input).not.toContainText("@Vogue");
await expect(input.locator(".agent-mention-highlight")).toHaveCount(1);
});
for (const theme of ["buzz", "buzz-dark"]) {
test(`captures native persistent mentions in ${theme}`, async ({ page }) => {
await seedAudience(page, [AGENT_A, AGENT_B], theme);
await installAudienceFixtures(page);
await openGeneral(page);
const composer = page.getByTestId("message-composer");
await page.getByTestId("message-input").focus();
await waitForAnimations(page);
await composer.screenshot({
path: `${SHOTS}/${theme}-native-mentions.png`,
});
});
}
test("native persistent mentions fit the narrow composer", async ({ page }) => {
await page.setViewportSize({ width: 700, height: 760 });
await seedAudience(page, [AGENT_A, AGENT_B]);
await installAudienceFixtures(page);
await openGeneral(page);
const composer = page.getByTestId("message-composer");
await expect(page.getByTestId("message-input")).toContainText("@Morgarita");
await waitForAnimations(page);
await composer.screenshot({ path: `${SHOTS}/narrow-native-mentions.png` });
});