test(desktop): model Welcome collision membership delivery

Preserve mock-created team identity across create/list so Welcome reuses its starters. Explicitly seed a separate same-name Fizz and model the member_joined event omitted by mock add-members. Keep ambiguity, draft, no-publication and sole-starter recipient assertions intact.

Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz>
Signed-off-by: Logan Johnson <loganj@squareup.com>
This commit is contained in:
Logan Johnson
2026-09-08 14:42:52 -04:00
parent 30bc57da82
commit b4a4f6f243
3 changed files with 89 additions and 2 deletions

View File

@@ -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,

View File

@@ -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);
});

View File

@@ -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);
}