evOo-local/apps/web/e2e/team-computer.spec.ts
cynarAI 63f96b6edd fix(ci): restore the web client and the failing product checks (#83)
* fix(ci): restore browser preview module and onboarding e2e

The web bundle imported a browser-preview store that was never added, so production builds and every Playwright signup failed before the shell rendered. Mobile check failed because Expo packages were a patch behind the SDK.

Restore the store, type the optional desktop bridge, and walk whichever onboarding step scripted CI actually opens.

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

* fix(ci): stop the blank web client and the send 500

The core barrel pulled git checkout into the browser, so node:child_process crashed the page before sign-up. Serve that module from a node export instead.

Add the missing run tool-call budget columns that threads/send writes. Guard an indexed shell flag for typecheck, and expect the files key the desktop preload already exposes.

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

* fix(ci): isolate pnpm setup and the takeover membership

The Team Computer takeover journey inserted a space member the
default-space trigger had already created, so shared Postgres rejected
the unique pair. Self-hosted jobs now keep a per-job pnpm home and
store, and artifact uploads no longer fail a job that already passed.

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

* fix(ci): clear typecheck, lint, and unit failures

Inbound channel rosters can mark a participant list as authoritative.
Answered channel asks stay off the group, and clearing a thread waits
until delegated returns land. Lint, unit, and web e2e contracts follow
the current shell, composer, and settings.

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

* fix(web): align e2e with the shipped shell and onboarding

Web E2E still expected older focus buttons, nested project rows, and
settings that never opened MCP. Persist the signed-in space, list
non-default spaces under Projekte, and keep the quote control on screen.

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

* fix(web): open group reply from a revealed hover rail

The first user row covered its Reply control until the rail accepted
pointer events. The group transcript now reveals that rail, then replies.

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

* fix(web): stop the shell render loop and settle computer and mention UI

A working bot rewrote preview state on every render, the computer menu never stayed still, and the mention picker did not expose its expanded state or option name.

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

* fix(ci): stop idle probes hanging and accept a follow-up send

Background probes walked every process fd and timed out on the shared runner. Linux now tracks the marker with flock and /proc/locks. A new composer draft can send while an earlier send is still refreshing, and group members stay mentionable.

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

* fix(adapters): detect background work when flock ids are padded

The idle probe compared /proc/locks with an unpadded device key, so majors
or minors under 16 never matched. It deleted the live marker and reported
idle while the command still held the lock. Probe by taking the lock, and
print the cancel key the way the kernel does.

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

* fix(adapters): stabilize background-work probe tests on self-hosted CI

Clear stale marker files before each probe scenario and allow longer
polling so launch can acquire flock on busy persistent runners.

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

* fix(web): do not block onboarding on spaces list

Render the first onboarding step from me and integration setup alone.
Resolve the optional skip-to-app redirect after that so Playwright
signups are not stuck on the loading shell when spaces.list is slow.

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

* fix(ci): restore green gates after second main rebase

Re-apply biome formatting on Shell/SortableGroup and strict TypeScript
assertions in computer-idle tests dropped when skipping the duplicate
conflict-resolution commit.

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

* fix(web): wait for onboarding bootstrap before E2E proceeds

Expose data-onboarding-step on the onboarding shell and have Playwright
wait until loading finishes. Ignore ad-hoc screenshot scripts on
self-hosted runners so they do not fail lint.

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

* fix(web): fall back when onboarding bootstrap stalls

Race me/integration setup against a timeout and promote loading to the
emoji step after 20s so Playwright is not blocked on a hung RPC.

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

* fix(web): render onboarding immediately for E2E signups

Start on the emoji step instead of a loading shell that waits on RPC.
Bootstrap can still redirect once me and integration setup resolve.

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

* fix(ci): stabilize web e2e on self-hosted runners

Per-job pnpm stores broke node_modules symlinks when setup-node restored
cached installs, so Vite could not resolve react during dependency
optimization. Keep a runner-scoped store, clear stale Vite caches, and pin
Playwright to one worker in CI to reduce onboarding RPC contention.

Add Vite resolve aliases for react/react-dom, wait for an interactive
onboarding step in E2E helpers, and include the React hook smoke spec from
main.

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

* fix(web): resolve React aliases through pnpm package layout

Root node_modules/react does not exist under pnpm, so Vite aliases pointed
at missing paths and broke production builds and the Playwright webServer.
Resolve react and react-dom from the web package and map jsx-runtime to the
actual entry files.

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

* fix(core): type the lazy child_process spawn cache

Main's lazy require left spawn typed as null after assignment, which broke
Typecheck on the rebased branch.

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

* fix(db): mock git-checkout export path in unit tests

Vitest resolves vi.mock against package exports; the .js suffix is not
declared for @rakazo/core/git-checkout.

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

* fix(web): stabilize E2E after main sidebar and onboarding changes

Use first() for duplicate transcript lines, wait for interactive onboarding
before model-required assertions, and allow project sidebar to settle after
create. Extend the Playwright job timeout so the single-worker suite can finish.

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

* fix(web): restore Projekte sidebar and integrations MCP entry

Use the default space for Unterhaltungen/Projekte separation instead of the
active space header, persist the bootstrapped space in localStorage, wire
SettingsOverlay to MCP management, and compare hover tones on inactive rows.

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

* fix(web): satisfy biome format on homeSpaceId line

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

* fix(web): align sidebar E2E with nested Projekte shell layout

Scope Unterhaltungen assertions to conversation rows only, target project-space
Chief actions under .sidebar-projekte, and stabilize hover-tone polling.

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

* fix: satisfy lint after main merge (format and unused var)

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

* fix(web): show project-space 1:1 bots in Projekte sidebar

Include lone bots in projectSidebarGroups, render bot rows in Projekte,
and stabilize E2E for nested sidebar layout and duplicate group entries.

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

* fix(web): disambiguate duplicate group sidebar buttons in E2E

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

* fix(web): align spaces and group-chats E2E with Projekte sidebar IA

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

* fix(web): dedupe Projekte sidebar rows and stabilize E2E specs

- Deduplicate project space and group-chat entries in projectSidebarGroups
- Scope group-chats/spaces E2E clicks to first Projekte match after IA split
- Wait for shell ready before mention-picker keyboard test; restore main locators
- Fix PrivacySettingsOverlay lint and align biome schema with CLI 2.5.13

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

* fix(web): restrict project drag handle and stabilize space E2E

- Move SortableGroup drag listeners to ProjectDragGrip only so sidebar clicks work
- Scope space delete actions to project-space rows; wait for menu in E2E
- Switch group settings E2E via direct navigation after unsaved draft check
- Merge main (DataTrustPanel) and fix Shell import order for CI lint

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

* fix(web): stabilize message hover Escape assertion in E2E

Assert the More menu closes and the hover rail stays visible instead of
requiring focus restoration, which is flaky across Chromium builds.

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

* chore: format apps/api/src/app.ts after main merge

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

* fix(web): stabilize team-computer E2E send after bot switch

Wait for shell ready and use the Send button instead of Enter after
switching bots and closing the computer overlay. The prior run timed
out on threads/send with only an apps/api format commit in between.

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>
2026-09-23 22:09:49 +02:00

358 lines
14 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 {
activeBotId,
captureScreenshot,
completeOnboarding,
createNamedBot,
realSandboxTimeout,
rpc,
signup,
} from "./helpers";
test("Team Computer gives bots a home folder plus shared space while Private stays isolated", async ({
page,
}, testInfo) => {
const stamp = Date.now();
const personalMarker = `personal-${stamp}`;
const sharedMarker = `shared-${stamp}`;
const privateMarker = `private-${stamp}`;
await signup(page, `team-computer-${stamp}@rakazo.test`, "password12", "Team Computer");
await completeOnboarding(page);
const chiefId = activeBotId(page);
await openComputerPanel(page);
await expect(page.getByText("Team Computer", { exact: true }).last()).toBeVisible();
await captureScreenshot(page, testInfo, "41-team-computer");
const writerId = await createBot(page, "Writer", "team");
await sendAndWait(
page,
writerId,
`write a file in your home called notes/result.txt that says ${personalMarker}`,
);
await expect(readFile(page, writerId, "notes/result.txt")).resolves.toContain(personalMarker);
await expect(readFileResponse(page, chiefId, "notes/result.txt")).resolves.toMatchObject({
ok: false,
});
await expect(readFile(page, chiefId, `bots/${writerId}/notes/result.txt`)).resolves.toContain(
personalMarker,
);
await captureScreenshot(page, testInfo, "42-team-bot-home-folder");
await sendAndWait(
page,
writerId,
`write a file called shared/notes/result.txt that says ${sharedMarker}`,
);
await expect(readFile(page, chiefId, "shared/notes/result.txt")).resolves.toContain(sharedMarker);
const privateId = await createBot(page, "Private Writer", "dedicated");
await openComputerPanel(page);
await expect(page.getByText(/Private Writer['’]s screen/).last()).toBeVisible();
await captureScreenshot(page, testInfo, "43-private-computer");
await expect(readFileResponse(page, privateId, "notes/result.txt")).resolves.toMatchObject({
ok: false,
});
await sendAndWait(
page,
privateId,
`write a file in your home called notes/result.txt that says ${privateMarker}`,
);
await expect(readFile(page, privateId, "notes/result.txt")).resolves.toContain(privateMarker);
await expect(readFileResponse(page, chiefId, "notes/result.txt")).resolves.toMatchObject({
ok: false,
});
await setComputerMode(page, "Private Writer", privateId, "team");
await expect(readFileResponse(page, privateId, "notes/result.txt")).resolves.toMatchObject({
ok: false,
});
await expect(readFile(page, privateId, "shared/notes/result.txt")).resolves.toContain(
sharedMarker,
);
await captureScreenshot(page, testInfo, "44-private-bot-joined-team-computer");
await setComputerMode(page, "Private Writer", privateId, "dedicated");
await expect(readFile(page, privateId, "notes/result.txt")).resolves.toContain(privateMarker);
await expect(readFile(page, writerId, "notes/result.txt")).resolves.toContain(personalMarker);
await captureScreenshot(page, testInfo, "45-private-computer-restored");
});
test("user control leaves another Team bot's screen available", async ({ page }, testInfo) => {
const stamp = Date.now();
const marker = `after-release-${stamp}`;
await signup(page, `team-control-${stamp}@rakazo.test`, "password12", "Team Control");
await completeOnboarding(page);
const chiefId = activeBotId(page);
const workerId = await createBot(page, "Worker", "team");
await openBot(page, "Chief");
await page.getByTitle("Agent computer").click();
await page.getByTestId("computer-preview").hover();
await page.getByTestId("computer-preview-open").click();
await expect(page.getByRole("button", { name: "Close computer" })).toBeVisible();
await page.getByRole("button", { name: "Close computer" }).click();
await expect(page.getByRole("button", { name: "Close computer" })).toHaveCount(0);
await openBot(page, "Worker");
const workerRunId = await sendMessage(
page,
`write a file in your home called notes/result.txt that says ${marker}`,
);
await waitForRun(page, workerId, workerRunId);
await expect(
rpc<{ controlHolder: string; controlBotId: string | null }>(page, "computer/status", {
botId: workerId,
}),
).resolves.toMatchObject({ controlHolder: "user", controlBotId: chiefId });
await expect(readFile(page, workerId, "notes/result.txt")).resolves.toContain(marker);
await captureScreenshot(page, testInfo, "46-team-computer-user-control-allows-parallel-bot");
await rpc(page, "computer/release", { botId: chiefId });
await expect(
rpc<{ controlHolder: string; controlBotId: string | null }>(page, "computer/status", {
botId: chiefId,
}),
).resolves.toMatchObject({ controlHolder: "bot", controlBotId: null });
await expect(readFileResponse(page, chiefId, "notes/result.txt")).resolves.toMatchObject({
ok: false,
});
await captureScreenshot(page, testInfo, "47-team-computer-control-released");
});
test("a failed control release keeps the computer open for retry", async ({ page }, testInfo) => {
await signup(page, `team-release-${Date.now()}@rakazo.test`, "password12", "Team Release");
await completeOnboarding(page);
await page.getByTitle("Agent computer").click();
await page.getByTestId("computer-preview").hover();
await page.getByTestId("computer-preview-open").click();
const chrome = page.getByTestId("computer-chrome");
const release = chrome.getByRole("button", { name: "Release", exact: true });
await expect(release).toBeVisible();
await page.route("**/rpc/computer/release", (route) =>
route.fulfill({ status: 500, body: "release unavailable" }),
);
await release.click();
await expect(page.getByText("Could not continue", { exact: true }).last()).toBeVisible();
await expect(page.getByRole("button", { name: "Close computer" })).toBeVisible();
await captureScreenshot(page, testInfo, "48-team-computer-release-retry");
await page.unroute("**/rpc/computer/release");
await release.click();
await expect(page.getByRole("button", { name: "Close computer" })).toBeHidden();
});
test("an active Team bot must be stopped before user takeover", async ({ page }, testInfo) => {
const stamp = Date.now();
await signup(
page,
`active-team-control-${stamp}@rakazo.test`,
"password12",
"Active Team Control",
);
await completeOnboarding(page);
const chiefId = activeBotId(page);
await sendMessage(page, "keep working until I stop you");
await expect
.poll(async () => (await threadSnapshot(page, chiefId)).run?.status ?? "idle")
.toBe("running");
await captureScreenshot(page, testInfo, "48-active-team-bot-blocks-takeover");
await expect
.poll(
async () => (await rpc<{ state: string }>(page, "computer/status", { botId: chiefId })).state,
)
.toBe("running");
await expect
.poll(
async () =>
(
await rpc<{ busyBotName: string | null }>(page, "computer/status", {
botId: chiefId,
})
).busyBotName,
)
.not.toBeNull();
const takeover = await rpcResponse(page, "computer/takeover", { botId: chiefId });
expect(takeover.ok).toBe(false);
expect(takeover.status).toBe(409);
await expect
.poll(async () => (await threadSnapshot(page, chiefId)).run?.status ?? "idle")
.toBe("running");
await page.getByTitle("Agent computer").click();
const sidePanel = page.getByTestId("side-panel");
await expect(sidePanel.getByRole("button", { name: /Take control/i })).toHaveCount(0);
await page.getByTestId("computer-preview").hover();
const openBusy = sidePanel.getByTestId("computer-preview-open");
await expect(openBusy).toBeVisible();
await expect(openBusy.getByText("Open", { exact: true })).toBeVisible();
await openBusy.click();
const chrome = page.getByTestId("computer-chrome");
await expect(page.getByRole("button", { name: "Close computer" })).toBeVisible();
// Open while the bot is busy must not grant control (takeover stays blocked).
await expect(chrome.getByText("You have control", { exact: true })).toHaveCount(0);
await expect(chrome.getByRole("button", { name: /Take control/i })).toHaveCount(0);
await captureScreenshot(page, testInfo, "48b-open-while-busy-no-control");
await page.getByRole("button", { name: "Close computer" }).click();
// Stop through the shell so the client refreshes computer status (API stop alone
// does not emit a terminal thread event).
await page.getByRole("button", { name: "Stop", exact: true }).click();
await waitForIdle(page, chiefId);
await expect
.poll(
async () =>
(
await rpc<{ busyBotName: string | null }>(page, "computer/status", {
botId: chiefId,
})
).busyBotName,
)
.toBeNull();
// After stop, Open via hover is the takeover path (no Take control button).
await page.getByTestId("computer-preview").hover();
await page.getByTestId("computer-preview-open").click();
await expect(page.getByRole("button", { name: "Close computer" })).toBeVisible();
await expect(chrome.getByText("You have control", { exact: true })).toBeVisible();
await expect(chrome.getByRole("button", { name: /Take control/i })).toHaveCount(0);
await expect(chrome.getByRole("button", { name: "Release", exact: true })).toBeVisible();
await captureScreenshot(page, testInfo, "49-team-computer-open-after-stop");
await chrome.getByRole("button", { name: "Release", exact: true }).click();
// Release closes the overlay and clears control without a DB edit.
await expect(page.getByRole("button", { name: "Close computer" })).toHaveCount(0);
});
async function createBot(page: Page, name: string, mode: "team" | "dedicated") {
return createNamedBot(page, name, { computerMode: mode });
}
async function setComputerMode(
page: Page,
botName: string,
botId: string,
mode: "team" | "dedicated",
) {
await page.getByRole("button", { name: botName, exact: true }).last().click();
const settings = page.getByTestId("bot-settings");
await expect(settings.locator("label:has-text('Name') input")).toHaveValue(botName);
const advanced = settings.getByTestId("bot-settings-advanced");
await advanced.evaluate((element) => {
(element as HTMLDetailsElement).open = true;
});
await settings
.getByRole("button", { name: mode === "team" ? "Team" : "Private", exact: true })
.click();
await settings.getByRole("button", { name: "Save", exact: true }).click();
await expect
.poll(async () => {
const bots = await rpc<Array<{ id: string; computerMode: string }>>(page, "bots/list", {});
return bots.find((bot) => bot.id === botId)?.computerMode;
})
.toBe(mode);
}
async function openBot(page: Page, name: string) {
await page
.getByRole("complementary")
.getByRole("button", { name: new RegExp(`^${name}`) })
.first()
.click();
await expect(page.getByRole("combobox", { name: "Message" })).toBeVisible();
await expectShellReady(page);
}
async function expectShellReady(page: Page) {
await expect(page.getByTestId("shell-root")).toHaveAttribute("data-ready", "true", {
timeout: 30_000,
});
}
async function expectComposerReady(page: Page) {
await expectShellReady(page);
const composer = page.getByPlaceholder(/Message/);
await expect(composer).toBeVisible();
await expect(composer).toBeEnabled();
}
async function openComputerPanel(page: Page) {
await page.getByTitle("Agent computer").click();
await expect(page.getByTestId("computer-preview")).toBeVisible();
await expect(page.getByTestId("computer-preview-open")).toHaveCount(1);
}
async function sendAndWait(page: Page, botId: string, text: string) {
const runId = await sendMessage(page, text);
await waitForRun(page, botId, runId);
}
async function sendMessage(page: Page, text: string) {
await expectComposerReady(page);
const composer = page.getByPlaceholder(/Message/);
await composer.click();
await composer.fill(text);
const sent = page.waitForResponse(
(response) =>
response.url().includes("/rpc/threads/send") && response.request().method() === "POST",
);
await page.getByRole("button", { name: "Send", exact: true }).click();
const response = await sent;
expect(response.ok()).toBe(true);
const result = (await response.json()) as { json?: { runId?: string } };
if (!result.json?.runId) throw new Error("threads/send did not return a run id");
return result.json.runId;
}
async function waitForRun(page: Page, botId: string, runId: string) {
await expect
.poll(
async () => {
const snapshot = await threadSnapshot(page, botId);
if (snapshot.run?.id === runId) return false;
return snapshot.messages.some((message) => message.runId === runId);
},
{
timeout: realSandboxTimeout(90_000, 20_000),
message: `run ${runId} must finish before its result is inspected`,
},
)
.toBe(true);
}
async function waitForIdle(page: Page, botId: string) {
await expect
.poll(async () => (await threadSnapshot(page, botId)).run?.status ?? "idle", {
timeout: realSandboxTimeout(90_000, 20_000),
})
.toBe("idle");
}
function threadSnapshot(page: Page, botId: string) {
return rpc<{
run: { id: string; status: string } | null;
messages: Array<{ runId?: string | null }>;
}>(page, "threads/get", { botId });
}
async function readFile(page: Page, botId: string, path: string) {
const result = await rpc<{ content: string }>(page, "computer/readFile", { botId, path });
return result.content;
}
async function readFileResponse(page: Page, botId: string, path: string) {
return rpcResponse(page, "computer/readFile", { botId, path });
}
async function rpcResponse(page: Page, procedure: string, body: unknown) {
const response = await page.request.post(`/rpc/${procedure}`, { data: { json: body } });
return { ok: response.ok(), status: response.status() };
}