evOo-local/apps/web/e2e/onboarding-conversation.spec.ts
Claude 311551da04
feat: land in the main conversation, led by the main bot
After onboarding the user ended up in a 1:1 chat with "Chief", and the
"Hauptthread" was a group the web client created and found by name. The
main bot had no conversation it actually led, and addressing another bot
there did nothing unless the user had added it as a member first.

Now the main conversation is a real place:

- bots.ensureMain creates or returns the main bot. Bootstrap and space
  navigation return `main` ({ botId, groupId, spaceId }) once the main
  bot exists; reading navigation never creates a bot.
- The main bot leads the main conversation and answers when nobody is
  addressed: message routing, follow-ups, reactions and clearing the
  thread fall back to the group's lead instead of its first member.
- Addressing a same-space bot that is not a member yet, by @Name or a
  mention chip, makes it join before the message is routed, so it
  answers in the conversation. Specialists from other spaces do not join.
- The main bot cannot be archived or deleted, the main conversation
  cannot be archived or deleted or have its members edited, and child
  bots never dissolve it. Renaming the main bot renames the conversation.
- Web: onboarding uses bots.ensureMain and finishes in the main
  conversation. The main conversation is the first sidebar entry in every
  space, shown with the main bot's avatar and name; from another space it
  switches back to the home space. The main bot is not listed again among
  the bots, its 1:1 thread stays reachable by URL. The client no longer
  creates or detects the "Hauptthread" by name, refetches a group when it
  changes, and shows the speaker of any of the user's bots in a group.
- Onboarding no longer resets the step when its bootstrap resolves after
  the user has already moved on, and new spaces open in the app instead
  of walking onboarding again.

Tests: group mention routing with a default responder, lead follow-ups,
child-bot guards, a journey for the main conversation (lead answers,
addressed bot joins, guards, rename), authorization for bots.ensureMain,
and an E2E spec that lands in the main conversation, gets an answer from
the lead, sees an addressed bot join, and reaches the conversation from
another space. Existing E2E specs start in the main bot's thread through
a helper or use the main conversation where that is what they test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MRtGG9ARfqqhma3t85Ro2u
2026-10-03 00:24:16 +00:00

114 lines
5.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { expect, type Page, test } from "@playwright/test";
import { captureScreenshot, completeOnboarding, rpc, signup } from "./helpers";
function slackCard(page: Page) {
return page.getByRole("group", { name: "Slack connection" });
}
test("focus choice suggests apps and preserves a completed connection", async ({
page,
}, testInfo) => {
const stamp = Date.now();
await signup(page, `onboarding-${stamp}@rakazo.test`, "password12", "Robin");
// The main bot greets the user in the main conversation, where onboarding lands.
await completeOnboarding(page, undefined, { mainConversation: true });
await expect(
page.getByText("Hey Robin. Fresh start on my side, so I’ll keep this short."),
).toHaveCount(0);
await expect(page.getByText("What do you want me on first?", { exact: true })).toBeVisible();
await expect(page.getByTestId("focus-choice-day")).toBeVisible();
await expect(page.getByTestId("focus-choice-day")).toContainText("Day-to-day work");
await expect(page.getByTestId("focus-choice-research")).toContainText("Research & writing");
await expect(page.getByTestId("focus-choice-crew")).toContainText("Specialist crew");
await page.mouse.move(1, 1);
await captureScreenshot(page, testInfo, "01-focus-choice");
await captureScreenshot(page, testInfo, "choice-card-onboarding");
await page.getByTestId("focus-choice-day").click();
// The focus step suggests apps but must not rename the bot: the name the
// user chose during creation ("Chief") is preserved.
await expect(
page.getByTestId("bot-settings-trigger").getByText("Chief", { exact: true }),
).toBeVisible();
expect((await rpc<{ name: string }>(page, "bots/ensureMain", {})).name).toBe("Chief");
await expect(page.getByRole("combobox", { name: "Message" })).toBeVisible();
await expect(page.getByText("Slack", { exact: true })).toBeVisible();
await expect(page.getByText("Gmail", { exact: true })).toBeVisible();
const connectionCards = page.getByRole("group", { name: / connection$/ });
await expect(connectionCards).toHaveCount(3);
const cardBoxes = await connectionCards.evaluateAll((cards) =>
cards.map((card) => {
const { bottom, top } = card.getBoundingClientRect();
return { bottom, top };
}),
);
expect(cardBoxes[1].top - cardBoxes[0].bottom).toBeGreaterThanOrEqual(8);
expect(cardBoxes[2].top - cardBoxes[1].bottom).toBeGreaterThanOrEqual(8);
await page
.getByTestId("transcript")
.getByText("Hit those three and I’ll start pulling the picture.")
.scrollIntoViewIfNeeded();
await page.mouse.move(1, 1);
await captureScreenshot(page, testInfo, "02-app-suggestions");
const authorizeButton = slackCard(page).getByRole("button", { name: "Authorize" });
const restingBackground = await authorizeButton.evaluate(
(button) => getComputedStyle(button).backgroundColor,
);
const accentBackground = await authorizeButton.evaluate((button) => {
const probe = document.createElement("span");
probe.style.backgroundColor = "var(--accent)";
button.append(probe);
const backgroundColor = getComputedStyle(probe).backgroundColor;
probe.remove();
return backgroundColor;
});
expect(accentBackground).not.toBe(restingBackground);
await authorizeButton.hover();
await expect
.poll(() => authorizeButton.evaluate((button) => getComputedStyle(button).backgroundColor))
.toBe(accentBackground);
await captureScreenshot(page, testInfo, "02-app-suggestions-authorize-hover");
await authorizeButton.click();
await expect(slackCard(page).getByText("Connected", { exact: true })).toBeVisible();
await expect(slackCard(page).getByText("Connected", { exact: true })).toHaveCSS("opacity", "1");
await expect
.poll(async () => {
const connections = await rpc<Array<{ provider: string; status: string }>>(
page,
"connections/list",
{},
);
return connections.some(
(connection) => connection.provider === "SLACK" && connection.status === "connected",
);
})
.toBe(true);
await page.mouse.move(1, 1);
await captureScreenshot(page, testInfo, "03-slack-connected");
await page.reload();
await expect(slackCard(page).getByText("Connected", { exact: true })).toBeVisible();
await page.mouse.move(1, 1);
await captureScreenshot(page, testInfo, "04-connected-after-reload");
});
test("choice refresh failures leave options available for retry", async ({ page }) => {
await signup(page, `choice-refresh-${Date.now()}@rakazo.test`, "password12", "Choice Retry");
await completeOnboarding(page, undefined, { mainConversation: true });
const choice = page.getByTestId("focus-choice-day");
await expect(choice).toBeEnabled();
// Keep the existing choice rendered while its save succeeds and navigation refresh fails.
await page.route("**/rpc/onboarding/choose", (route) =>
route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({ json: { ok: true } }),
}),
);
await page.route("**/rpc/spaces/list", (route) => route.abort());
await Promise.all([page.waitForRequest("**/rpc/spaces/list"), choice.click()]);
await expect(choice).toBeEnabled();
});