mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-26 10:07:24 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Live 8-core PR runs (`45668834558`, `45667106472`) showed `e2e_shards` was the #1 critical-path bottleneck on normal PRs (`152–171s` test step) due to four compounding causes: > 1. `scripts/e2e-shard.mjs` still used the 4-vCPU `EFFECTIVE_PARALLEL_SPEEDUP = 1.85` even on 8-vCPU runners running 4 Playwright workers (`~3.35x` measured speedup), under-allocating serial shards (`5` serial shards running `96–124s` while parallel shards sat idle after `55–78s`). > 2. `scripts/e2e-shard-durations.json` had stale weights (`chat-adapters-ui-providers.spec.ts` `86.8s` vs `117–165s` actual; `acp-stop-continuation.spec.ts` `69.3s` vs `88–102s` actual). > 3. Three serial (`1-worker`) specs pinned the floor at `75–91s`: `agent-configuration.spec.ts` (`91.4s`), `agent-chat-sessions.spec.ts` (`79.9s`), and `onboarding.spec.ts` (`75.3s`). > 4. `playwright.config.ts` ran `vite build ui` (`~5.4s`) serially before starting embedded Postgres + 512 migrations (`~21s`) even though database bootstrap does not read `server/ui-dist`. > - This pull request overlaps the unminified Vite UI build with Postgres bootstrap inside `start-e2e-server.ts`, splits the top 3 serial specs into 6 balanced specs (keeping all 3 anchor filenames and 100% of 20 tests intact), makes `e2e-shard.mjs` CPU-aware (`3.2x` on 8-vCPU / `1.85x` on 4-vCPU), refreshes all 58 specs in `e2e-shard-durations.json`, and scales AWS `e2e_shards` `12 -> 16` while keeping `ubuntu-latest` hosted at `4` — bringing simulated E2E test execution to `~90–96s` (`-60 to -75s`). ## Linked Issues or Issue Description Refs #22804 **What existing behavior does this improve?** E2E shard wall-clock ceiling on 8-core PR runners (`tests/e2e/`, `scripts/e2e-shard.mjs`, `scripts/e2e-shard-durations.json`, `.github/ci-task-matrix.json`, `.github/workflows/pr-trusted.yml`). **Subsystem affected** tests/e2e/ and CI — Playwright server bootstrap, serial spec sharding, and E2E shard matrix **Current behavior** E2E shards take `152–171s` on 8-core runners because `vite build ui` runs serially before Postgres boot, 3 serial specs run `75–91s` each, `e2e-shard.mjs` assumes 4-vCPU `1.85x` parallel speedup, and AWS runs 12 shards. **Proposed behavior** Overlap unminified Vite UI build with embedded Postgres boot in `tests/e2e/start-e2e-server.ts`, split the top 3 serial specs into 6 balanced specs (preserving anchor paths and all tests), use CPU-aware parallel speedup (`3.2x` on 8-vCPU / `1.85x` on 4-vCPU) with refreshed 58-spec durations, and run 16 AWS E2E shards (`8 serial + 8 parallel`, `59.7–76.5s` Playwright) while keeping `ubuntu-latest` hosted at `4`. ## What Changed - **Overlapped UI build with Postgres bootstrap (`tests/e2e/playwright.config.ts`, `tests/e2e/start-e2e-server.ts`):** - Launches `start-e2e-server.ts` directly with `PAPERCLIP_E2E_BUILD_UI` (`0` when `PAPERCLIP_E2E_SKIP_UI_BUILD=1`), overlapping `vite build ui --outDir ../server/ui-dist --emptyOutDir --minify false` concurrently inside `Promise.all([dbPromise, import("../../server/src/index.js"), uiReady])` with `stopUiBuild()` and `dbPromise` cleanup on signals/failure, plus `maintenance_work_mem = 128MB` / `work_mem = 32MB` on disposable PG. - **Split top 3 serial E2E specs (100% of 20 tests preserved, all 3 anchor filenames & `maps/` links intact, all 3 new siblings registered in BOTH `playwright.config.ts` and `scripts/e2e-shard.mjs` `SERIAL_SPECS`):** - `agent-configuration.spec.ts` (3 tests) + `agent-configuration-revisions.spec.ts` (5 tests) + `agent-configuration.shared.ts` - `agent-chat-sessions.spec.ts` (3 tests) + `agent-chat-sessions-navigation.spec.ts` (3 tests) - `onboarding.spec.ts` (3 tests) + `onboarding-resume.spec.ts` (3 tests) - **CPU-aware speedup, refreshed 58-spec manifest, & 16 AWS E2E shards (`scripts/e2e-shard.mjs`, `scripts/e2e-shard-durations.json`, `.github/ci-task-matrix.json`, `.github/workflows/pr-trusted.yml`, `.github/scripts/tests/ci-plan.test.mjs`, `scripts/__tests__/e2e-shard.test.mjs`):** - Exported `EFFECTIVE_PARALLEL_SPEEDUP_4W = 3.2` and `resolveEffectiveParallelSpeedup(cpus)` matching `playwright.config.ts` worker scaling. - Refreshed all 58/58 spec weights from live 8-core runs `45668834558` & `45667106472`. - Scaled AWS `e2e_shards` `12 -> 16` while keeping `ubuntu-latest` hosted at `4`. ## Verification - `node --test scripts/__tests__/e2e-shard.test.mjs .github/scripts/tests/ci-plan.test.mjs scripts/check-test-budget.test.mjs scripts/__tests__/merge-queue-checks-workflow.test.mjs` — **45/45 PASS** - `npx playwright test --config tests/e2e/playwright.config.ts --list` on all 6 split specs — **20 tests in 6 files** - `tsc --strict --noEmit` across all 9 edited `tests/e2e/*.ts` files — **0 errors** - `node scripts/check-test-budget.mjs --base origin/master` and `node scripts/check-maps.mjs` — **PASS** - `ruby -ryaml -e 'YAML.load_file(".github/workflows/pr-trusted.yml")'` — **YAML OK** ## Risks - Low risk: all 3 original serial spec anchor filenames remain intact, `PAPERCLIP_E2E_SKIP_UI_BUILD=1` is preserved, signal/failure handlers clean up both the Vite child and embedded PG, `ubuntu-latest` stays at 4 hosted shards, and full CI runs all E2E shards live before merge. ## Model Used - Gemini 4 Neon (High) via Antigravity agent swarm (`e2e-opt`, `verifier`, `ci-pipeline`). ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge
249 lines
11 KiB
TypeScript
249 lines
11 KiB
TypeScript
import { expect, test } from "@playwright/test";
|
|
|
|
import { createLocalAgentJwt } from "../../server/src/agent-auth-jwt";
|
|
|
|
import { idle, json, send, setup } from "./agent-chat.shared";
|
|
|
|
test.use({ trace: "retain-on-failure" });
|
|
test.setTimeout(120_000);
|
|
|
|
/**
|
|
* Agent chat session reset and sidebar navigation coverage split out of
|
|
* agent-chat-sessions.spec.ts so serial E2E shards stay under 75s.
|
|
*/
|
|
test("Stop then queued /new resets unpause the conversation without losing history", async ({
|
|
page,
|
|
request,
|
|
}) => {
|
|
const f = await setup(request);
|
|
try {
|
|
await page.goto(f.route);
|
|
await send(page, { action: "hold" });
|
|
await expect
|
|
.poll(async () => {
|
|
const chat = await json(await request.get(f.chatPath));
|
|
return (
|
|
chat &&
|
|
(
|
|
await json(await request.get(`/api/issues/${chat.id}/comments`))
|
|
).some(
|
|
(c: any) => c.body === "Provider is streaming and ready to stop.",
|
|
)
|
|
);
|
|
}, { timeout: 30_000 })
|
|
.toBe(true);
|
|
const issue = await json(await request.get(f.chatPath));
|
|
const active = (
|
|
await json(await request.get(`/api/issues/${issue.id}/live-runs`))
|
|
)[0];
|
|
await page.getByTestId("task-chat-composer-stop").click();
|
|
await expect
|
|
.poll(
|
|
async () =>
|
|
(await json(await request.get(`/api/heartbeat-runs/${active.id}`)))
|
|
.status,
|
|
)
|
|
.toBe("cancelled");
|
|
const staleToken = createLocalAgentJwt(
|
|
f.agent.id,
|
|
f.company.id,
|
|
"process",
|
|
active.id,
|
|
);
|
|
expect(staleToken).toBeTruthy();
|
|
const late = await request.post(`/api/issues/${issue.id}/comments`, {
|
|
headers: { Authorization: `Bearer ${staleToken}` },
|
|
data: { body: "Forbidden late response" },
|
|
});
|
|
expect([403, 409]).toContain(late.status());
|
|
const mutation = await request.post(
|
|
`/api/companies/${f.company.id}/projects`,
|
|
{
|
|
headers: { Authorization: `Bearer ${staleToken}` },
|
|
data: { name: "Cancelled project" },
|
|
},
|
|
);
|
|
expect([403, 409]).toContain(mutation.status());
|
|
expect(
|
|
await json(await request.get(`/api/companies/${f.company.id}/projects`)),
|
|
).toHaveLength(0);
|
|
await send(page, "/new");
|
|
await send(page, "/new");
|
|
await send(page, "Fresh followup");
|
|
await idle(request, f.chatPath, 2);
|
|
const fresh = await json(await request.get(f.chatPath));
|
|
expect(fresh.id).toBe(issue.id);
|
|
expect(fresh.conversationSessionGeneration).toBe(2);
|
|
await expect(
|
|
page.getByText("Reply generation 2: Fresh followup", { exact: true }),
|
|
).toBeVisible();
|
|
await page.reload();
|
|
await expect(page.getByText("New session", { exact: true })).toHaveCount(2);
|
|
await expect(
|
|
page.getByRole("separator", { name: "Run completed", exact: true }),
|
|
).toHaveCount(0);
|
|
const runs = await json(
|
|
await request.get(`/api/companies/${f.company.id}/heartbeat-runs`),
|
|
);
|
|
const detailed = await Promise.all(
|
|
runs.map((run: any) =>
|
|
request.get(`/api/heartbeat-runs/${run.id}`).then(json),
|
|
),
|
|
);
|
|
expect(
|
|
detailed.filter((run) => run.contextSnapshot?.conversationReset),
|
|
).toHaveLength(2);
|
|
expect(
|
|
detailed
|
|
.filter((run) => run.contextSnapshot?.conversationReset)
|
|
.every((run) => !run.sessionIdAfter),
|
|
).toBe(true);
|
|
} finally {
|
|
await f.restore();
|
|
}
|
|
});
|
|
|
|
test("Coordinator agent switching preserves drafts and opens one conversation only on send", async ({ page, request }) => {
|
|
const f = await setup(request, { agentCount: 2 });
|
|
try {
|
|
await page.goto(f.route);
|
|
await expect(page.getByRole("navigation", { name: "Workspace navigation" })).toBeVisible();
|
|
const editor = page.getByTestId("task-chat-composer-input").locator('[contenteditable="true"]');
|
|
const contacts = page.getByRole("complementary", { name: "Chat contacts", exact: true });
|
|
const switchTo = async (name: string) => {
|
|
const contact = contacts.getByRole("link", { name: new RegExp(`^${name}`) });
|
|
await contact.click();
|
|
await expect(contact).toHaveAttribute("aria-current", "page");
|
|
};
|
|
await expect(page.getByRole("heading", { name: "Chat", exact: true })).toBeVisible();
|
|
await expect(contacts.getByRole("button", { name: "Add chat", exact: true })).toHaveCount(0);
|
|
await editor.fill("Unsent Coordinator draft for Alpha");
|
|
await switchTo("Beta");
|
|
await expect(editor).toHaveText("");
|
|
expect(await json(await request.get(`/api/companies/${f.company.id}/chats/${f.agents[1].id}`))).toBeNull();
|
|
await switchTo("Alpha");
|
|
await expect(editor).toContainText("Unsent Coordinator draft for Alpha");
|
|
await page.reload();
|
|
await expect(editor).toContainText("Unsent Coordinator draft for Alpha");
|
|
expect(await json(await request.get(f.chatPath))).toBeNull();
|
|
await editor.fill("");
|
|
await send(page, "Coordinator conversation acceptance");
|
|
await idle(request, f.chatPath);
|
|
const chat = await json(await request.get(f.chatPath));
|
|
await switchTo("Beta");
|
|
await switchTo("Alpha");
|
|
await expect(page.getByText("Coordinator conversation acceptance", { exact: true })).toBeVisible();
|
|
expect((await json(await request.get(f.chatPath))).id).toBe(chat.id);
|
|
expect(await json(await request.get(`/api/companies/${f.company.id}/chats`))).toHaveLength(1);
|
|
} finally {
|
|
await f.restore();
|
|
}
|
|
});
|
|
|
|
test("secondary chat navigation preserves layout, unique conversations, history, and drafts", async ({
|
|
page,
|
|
request,
|
|
}) => {
|
|
const originalExperimental = await json(await request.get("/api/instance/settings/experimental"));
|
|
const f = await setup(request, { agentCount: 6 });
|
|
const originalWorkspace = await json(await request.get("/api/workspace-preferences/me"));
|
|
try {
|
|
await page.route("**/api/workspace-preferences/me", (route) =>
|
|
route.fulfill({
|
|
json: { ...originalWorkspace, coordinatorWorkspaceEnabled: false },
|
|
}),
|
|
);
|
|
await page.route("**/api/instance/settings/experimental", (route) =>
|
|
route.fulfill({
|
|
json: { ...originalExperimental, enableStreamlinedUi: true },
|
|
}),
|
|
);
|
|
await page.goto(`/${f.company.issuePrefix}/dashboard`);
|
|
await page.getByRole("link", { name: /^Chat(?:\s|$)/ }).click();
|
|
expect(await json(await request.get(`/api/companies/${f.company.id}/primary-agent/me`))).toMatchObject({
|
|
primaryAgentId: f.agents[0].id, initialized: true,
|
|
});
|
|
const sidebar = page.getByRole("complementary", { name: "Chat contacts", exact: true });
|
|
const nav = sidebar.getByRole("navigation", { name: "Agent conversations" });
|
|
const alphaLink = nav.getByRole("link", { name: /^Alpha/ });
|
|
const betaLink = nav.getByRole("link", { name: /^Beta/ });
|
|
await expect(alphaLink).toHaveAttribute("aria-current", "page");
|
|
expect(await json(await request.get(f.chatPath))).toBeNull();
|
|
expect(await json(await request.get(`/api/companies/${f.company.id}/heartbeat-runs`))).toHaveLength(0);
|
|
await expect(nav.getByRole("link")).toHaveText([/^Alpha/, /^Beta/, /^Delta/, /^Epsilon/, /^Gamma/, /^Zeta/]);
|
|
const landingBounds = await sidebar.boundingBox();
|
|
const chatListPath = `/api/companies/${f.company.id}/chats`;
|
|
const betaPath = `${chatListPath}/${f.agents[1].id}`;
|
|
await betaLink.click();
|
|
await expect(betaLink).toHaveAttribute("aria-current", "page");
|
|
expect(await sidebar.boundingBox()).toEqual(landingBounds);
|
|
expect(await json(await request.get(betaPath))).toBeNull();
|
|
expect(await json(await request.get(chatListPath))).toHaveLength(0);
|
|
expect(await json(await request.get(`/api/companies/${f.company.id}/heartbeat-runs`))).toHaveLength(0);
|
|
await betaLink.click();
|
|
expect(await json(await request.get(betaPath))).toBeNull();
|
|
await send(page, "Beta conversation acceptance");
|
|
const beta = await idle(request, betaPath);
|
|
expect(beta.conversationAgentId).toBe(f.agents[1].id);
|
|
expect(await json(await request.get(chatListPath))).toHaveLength(1);
|
|
await alphaLink.click();
|
|
await expect(alphaLink).toHaveAttribute("aria-current", "page");
|
|
await betaLink.click();
|
|
await expect(betaLink).toHaveAttribute("aria-current", "page");
|
|
expect((await json(await request.get(betaPath))).id).toBe(beta.id);
|
|
expect(await json(await request.get(chatListPath))).toHaveLength(1);
|
|
await alphaLink.click();
|
|
await expect(alphaLink).toHaveAttribute("aria-current", "page");
|
|
await expect(nav.getByRole("link")).toHaveText([/^Alpha/, /^Beta/, /^Delta/, /^Epsilon/, /^Gamma/, /^Zeta/]);
|
|
const editor = page.getByTestId("task-chat-composer-input").locator('[contenteditable="true"]');
|
|
await editor.fill("Unsent draft for Alpha");
|
|
await betaLink.click();
|
|
await expect(editor).toHaveText("");
|
|
await alphaLink.click();
|
|
await expect(editor).toContainText("Unsent draft for Alpha");
|
|
|
|
const search = sidebar.getByRole("textbox", { name: "Search chats", exact: true });
|
|
await search.fill("No matching agent");
|
|
await expect(sidebar.getByText("No agents found", { exact: true })).toBeVisible();
|
|
await search.fill("Beta");
|
|
await expect(nav.getByRole("link")).toHaveCount(1);
|
|
await expect(betaLink).toBeVisible();
|
|
await search.press("Escape");
|
|
await expect(nav.getByRole("link")).toHaveCount(6);
|
|
await page.reload();
|
|
await expect(editor).toContainText("Unsent draft for Alpha");
|
|
await expect(nav.getByRole("link")).toHaveCount(6);
|
|
|
|
await page.getByRole("link", { name: /^Chat(?:\s|$)/ }).click();
|
|
await expect(alphaLink).toHaveAttribute("aria-current", "page");
|
|
await expect(editor).toContainText("Unsent draft for Alpha");
|
|
expect(await sidebar.boundingBox()).toEqual(landingBounds);
|
|
await page.goto(`/${f.company.issuePrefix}/dashboard`);
|
|
await expect(page).toHaveURL(/\/dashboard$/);
|
|
await json(await request.post(`/api/issues/${beta.id}/comments`, {
|
|
data: {
|
|
body: "Background activity",
|
|
clientRequestId: "00000000-0000-4000-8000-000000000099",
|
|
},
|
|
}));
|
|
await idle(request, betaPath);
|
|
await page.getByRole("link", { name: /^Chat(?:\s|$)/ }).click();
|
|
await expect(alphaLink).toHaveAttribute("aria-current", "page");
|
|
await betaLink.click();
|
|
await expect(betaLink).toHaveAttribute("aria-current", "page");
|
|
await expect(page.getByText("Background activity", { exact: true })).toBeVisible();
|
|
expect((await json(await request.get(betaPath))).id).toBe(beta.id);
|
|
expect(await json(await request.get(chatListPath))).toHaveLength(1);
|
|
await json(await request.post(`/api/agents/${f.agents[1].id}/terminate`));
|
|
await page.goto(`/${f.company.issuePrefix}/chats`);
|
|
await expect(betaLink).toContainText("Terminated");
|
|
await betaLink.click();
|
|
await expect(page).toHaveURL(new RegExp(`/chats/${f.agents[1].id}$`));
|
|
await expect(page.getByText("Background activity", { exact: true })).toBeVisible();
|
|
await page.reload();
|
|
await expect(page.getByText("Background activity", { exact: true })).toBeVisible();
|
|
} finally {
|
|
await f.restore();
|
|
}
|
|
});
|