diff --git a/desktop/src/testing/e2eBridge.ts b/desktop/src/testing/e2eBridge.ts index fc35fb7c13..502178be23 100644 --- a/desktop/src/testing/e2eBridge.ts +++ b/desktop/src/testing/e2eBridge.ts @@ -931,6 +931,7 @@ type RawManagedAgent = { pubkey: string; name: string; persona_id: string | null; + team_id?: string | null; /** Record-level harness/runtime pin (`null` when inheriting from the persona). */ runtime: string | null; relay_url: string; @@ -1841,6 +1842,7 @@ function cloneManagedAgent(agent: MockManagedAgent): RawManagedAgent { pubkey: agent.pubkey, name: agent.name, persona_id: agent.persona_id, + team_id: agent.team_id ?? null, runtime: agent.runtime ?? null, relay_url: agent.relay_url, acp_command: agent.acp_command, @@ -9380,6 +9382,7 @@ async function handleCreateManagedAgent( input: { name: string; personaId?: string; + teamId?: string; relayUrl?: string; acpCommand?: string; agentCommand?: string; @@ -9456,6 +9459,7 @@ async function handleCreateManagedAgent( pubkey, name, persona_id: args.input.personaId ?? null, + team_id: args.input.teamId ?? null, // Create never pins a harness id — the record inherits from the persona. runtime: null, relay_url: args.input.relayUrl ?? DEFAULT_RELAY_WS_URL, diff --git a/desktop/tests/e2e/onboarding.spec.ts b/desktop/tests/e2e/onboarding.spec.ts index 9cc17c11ac..c8fb9b6ed5 100644 --- a/desktop/tests/e2e/onboarding.spec.ts +++ b/desktop/tests/e2e/onboarding.spec.ts @@ -9,6 +9,10 @@ import { } from "../helpers/bridge"; import { expectEmojiMartStylesInstalled } from "../helpers/css"; import { installFakeCamera } from "../helpers/fakeCamera"; +import { + addWelcomeCollision, + WELCOME_COLLISION, +} from "../helpers/welcomeCollision"; import { E2E_IDENTITY_OVERRIDE_STORAGE_KEY, seedActiveIdentity, @@ -490,7 +494,7 @@ async function expectWelcomeComposerBannerCompletesAfterPersonaMention( // Make selection intent explicit; do not remove the colliding fixture or // relax extraction. The resulting event must tag only our starter identity. await input.fill(""); - await input.fill(content); + await input.pressSequentially(content); await page.getByTestId(`mention-suggestion-${fizz[0].pubkey}`).click(); await page.getByTestId("send-message").click(); await expect.poll(sentRecipients).toEqual([[fizz[0].pubkey]]); @@ -3349,7 +3353,11 @@ test("finishing onboarding creates starter channels and focuses welcome-everyone page, }) => { await seedActiveIdentity(page, BLANK_TYLER_IDENTITY); - await installMockBridge(page, undefined, { skipOnboardingSeed: true }); + await installMockBridge( + page, + { managedAgents: [WELCOME_COLLISION] }, + { skipOnboardingSeed: true }, + ); await page.goto("/"); await page.getByTestId("onboarding-display-name").fill("Morty QA"); @@ -3359,6 +3367,10 @@ test("finishing onboarding creates starter channels and focuses welcome-everyone await expect(page.getByTestId("channel-general")).toBeVisible(); await expectStarterChannels(page); await expectWelcomeGuideIntro(page); + expect(await commandCount(page, "create_managed_agent")).toBe(3); + const channelId = await getWelcomeChannelId(page); + if (!channelId) throw new Error("Missing Welcome channel"); + await addWelcomeCollision(page, channelId); await expectWelcomeComposerBannerCompletesAfterPersonaMention(page); }); diff --git a/desktop/tests/helpers/welcomeCollision.ts b/desktop/tests/helpers/welcomeCollision.ts new file mode 100644 index 0000000000..c50fbc03e6 --- /dev/null +++ b/desktop/tests/helpers/welcomeCollision.ts @@ -0,0 +1,71 @@ +import { expect, type Page } from "@playwright/test"; +import { TEST_IDENTITIES } from "./bridge"; + +export const WELCOME_COLLISION = { + pubkey: "c".repeat(64), + name: "Fizz", + personaId: "builtin:fizz", + status: "stopped" as const, +}; + +/** Add a deliberate same-name member and deliver the relay event mock IPC omits. */ +export async function addWelcomeCollision(page: Page, channelId: string) { + await expect + .poll(() => + page.evaluate( + () => + window.__BUZZ_E2E_HAS_MOCK_LIVE_SUBSCRIPTION__?.({ + channelName: "Welcome", + }) ?? false, + ), + ) + .toBe(true); + await page.evaluate( + async ({ channelId, pubkey, actor }) => { + const invoke = window.__BUZZ_E2E_INVOKE_MOCK_COMMAND__; + const emit = window.__BUZZ_E2E_EMIT_MOCK_MESSAGE__; + if (!invoke || !emit) + throw new Error("Mock membership seams unavailable"); + const result = (await invoke("add_channel_members", { + channelId, + pubkeys: [pubkey], + role: "bot", + })) as { added: string[]; errors: unknown[] }; + if (result.errors.length || !result.added.includes(pubkey)) { + throw new Error("Collision fixture membership was not added"); + } + // Real relay side_effects emits member_joined after kind:9000. Mock + // add_channel_members only mutates backend arrays. Model delivery, not + // the resulting QueryClient state: production owns roster invalidation. + emit({ + channelName: "Welcome", + kind: 40099, + content: JSON.stringify({ + type: "member_joined", + actor, + target: pubkey, + }), + }); + }, + { + channelId, + pubkey: WELCOME_COLLISION.pubkey, + actor: TEST_IDENTITIES.tyler.pubkey, + }, + ); + await expect + .poll(() => + page.evaluate( + ({ channelId, pubkey }) => { + const client = window.__BUZZ_E2E_QUERY_CLIENT__ as unknown as { + getQueryData: (key: string[]) => { pubkey: string }[] | undefined; + }; + return client + .getQueryData(["channels", channelId, "members"]) + ?.some((member) => member.pubkey === pubkey); + }, + { channelId, pubkey: WELCOME_COLLISION.pubkey }, + ), + ) + .toBe(true); +}