mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-26 01:39:51 +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
167 lines
12 KiB
TypeScript
167 lines
12 KiB
TypeScript
import { stringify } from "yaml";
|
|
import { document, edit, expect, json, save, setup, test } from "./agent-configuration.shared";
|
|
|
|
test("Secrets shows masked inline variables and preserves them when another variable is saved", async ({ page, request }) => {
|
|
const { company, agent, url } = await setup(request);
|
|
const secret = await json(await request.post(`/api/companies/${company.id}/secrets`, { data: {
|
|
name: "Release credential", value: "disposable-reference-credential",
|
|
} }));
|
|
await json(await request.patch(`/api/agents/${agent.id}`, { data: { adapterConfig: {
|
|
command: "true",
|
|
env: {
|
|
RELEASE_WEBHOOK: { type: "plain", value: "disposable-inline-credential" },
|
|
SHARED_TOKEN: { type: "secret_ref", secretId: secret.id, version: "latest" },
|
|
},
|
|
} } }));
|
|
|
|
await page.goto(`${url}/secrets`);
|
|
const variableNames = () => page.getByRole("textbox", { name: "Variable name", exact: true })
|
|
.evaluateAll(elements => elements.map(element => (element as HTMLInputElement).value).sort());
|
|
await expect(page.getByRole("heading", { name: "Environment variables", exact: true })).toBeVisible();
|
|
await expect.poll(variableNames).toEqual(["RELEASE_WEBHOOK", "SHARED_TOKEN"]);
|
|
await expect(page.getByLabel("Variable value", { exact: true })).toHaveValue("***REDACTED***");
|
|
await expect(page.getByText("Release credential", { exact: true }).first()).toBeVisible();
|
|
expect(await page.locator("body").textContent()).not.toContain("disposable-inline-credential");
|
|
const before = await json(await request.get(`/api/agents/${agent.id}/configuration`));
|
|
expect(before.configurationRevision).toMatch(/^[a-f0-9]{64}$/);
|
|
|
|
await page.getByRole("button", { name: "Add variable", exact: true }).click();
|
|
await page.getByRole("textbox", { name: "Variable name", exact: true }).last().fill("RELEASE_CHANNEL");
|
|
await page.getByLabel("Variable value", { exact: true }).last().fill("drafts");
|
|
await page.getByRole("button", { name: "Save changes", exact: true }).click();
|
|
await expect(page.getByRole("button", { name: "Save changes", exact: true })).toBeDisabled();
|
|
const config = await json(await request.get(`/api/agents/${agent.id}/configuration`));
|
|
expect(config.adapterConfig.env).toMatchObject({
|
|
RELEASE_WEBHOOK: { type: "plain", value: "***REDACTED***" },
|
|
SHARED_TOKEN: { type: "secret_ref", secretId: secret.id, version: "latest" },
|
|
RELEASE_CHANNEL: { type: "plain", value: "***REDACTED***" },
|
|
});
|
|
await page.reload();
|
|
await expect.poll(variableNames).toEqual(["RELEASE_CHANNEL", "RELEASE_WEBHOOK", "SHARED_TOKEN"]);
|
|
await expect(page.getByLabel("Variable value", { exact: true }).first()).toHaveValue("***REDACTED***");
|
|
await page.getByRole("button", { name: "Remove RELEASE_CHANNEL", exact: true }).click();
|
|
await page.getByRole("button", { name: "Save changes", exact: true }).click();
|
|
await expect(page.getByRole("button", { name: "Save changes", exact: true })).toBeDisabled();
|
|
const after = await json(await request.get(`/api/agents/${agent.id}/configuration`));
|
|
// The server's opaque revision includes the actual hidden values. Returning
|
|
// to the same revision proves they survived both saves without reading them.
|
|
expect(after.configurationRevision).toBe(before.configurationRevision);
|
|
});
|
|
|
|
test("compact YAML stays small as the company grows and preserves hidden configuration", async ({ page, request }) => {
|
|
const { company, agent, url } = await setup(request);
|
|
await json(await request.patch(`/api/agents/${agent.id}/instructions-bundle`, { data: { mode: "managed" } }));
|
|
const entry = await json(await request.get(`/api/agents/${agent.id}/instructions-bundle/file?path=AGENTS.md`));
|
|
const instructions = "Keep the agent instructions outside its YAML configuration.\n".repeat(500);
|
|
await json(await request.put(`/api/agents/${agent.id}/instructions-bundle/file`, { data: {
|
|
path: "AGENTS.md", content: instructions, baseHash: entry.contentHash, baseRevisionId: entry.revision?.id ?? null,
|
|
} }));
|
|
const profiles: Array<{ id: string }> = [];
|
|
for (let index = 0; index < 8; index++) profiles.push(await json(await request.post(`/api/companies/${company.id}/tools/profiles`, { data: {
|
|
profileKey: `profile-${index}`, name: `Profile ${index}`, defaultAction: "deny",
|
|
entries: Array.from({ length: 30 }, (_, tool) => ({ selectorType: "tool_name", effect: "include", toolName: `fixture_tool_${tool}` })),
|
|
} })));
|
|
await json(await request.post(`/api/companies/${company.id}/tools/profiles/${profiles[0].id}/bind`, { data: { targetType: "agent", targetId: agent.id, priority: 100 } }));
|
|
await page.goto(`${url}/advanced`);
|
|
const compact = await document(page);
|
|
const source = stringify(compact);
|
|
expect(source.split("\n").length).toBeLessThan(60);
|
|
for (const omitted of ["observed:", "fixture_tool_", "profile-7", "Keep the agent instructions", "create:", "metadata: null"]) expect(source).not.toContain(omitted);
|
|
expect(compact.spec.tools?.profiles).toEqual([{ profileKey: "profile-0" }]);
|
|
expect(compact.spec.instructions).toEqual({ mode: "managed", entryFile: "AGENTS.md" });
|
|
await edit(page, value => { value.spec = { title: "Sparse saved edit" }; });
|
|
await save(page);
|
|
const saved = await json(await request.get(`/api/agents/${agent.id}/configuration`));
|
|
expect(saved.name).toBe(agent.name);
|
|
expect(saved.adapterConfig).toMatchObject({ command: "true", removable: "old value" });
|
|
expect((await json(await request.get(`/api/agents/${agent.id}/instructions-bundle/file?path=AGENTS.md`))).content).toBe(instructions);
|
|
await edit(page, value => { value.spec.tools = { profiles: [{ profileKey: "profile-0" }, { profileKey: "profile-1" }] }; });
|
|
await save(page);
|
|
const selected = await json(await request.get(`/api/companies/${company.id}/tools/profiles`));
|
|
expect(selected.profiles.find((profile: { id: string }) => profile.id === profiles[1].id).bindings).toContainEqual(expect.objectContaining({ targetType: "agent", targetId: agent.id }));
|
|
for (const profile of selected.profiles.filter((profile: { id: string }) => profiles.some(created => created.id === profile.id))) expect(profile.entries).toHaveLength(30);
|
|
});
|
|
|
|
test("Advanced YAML persists settings and commands through their real resource APIs", async ({ page, request, toolProvider }, info) => {
|
|
test.setTimeout(120_000);
|
|
const { company, agent, url } = await setup(request);
|
|
await json(await request.patch(`/api/agents/${agent.id}/instructions-bundle`, { data: { mode: "managed" } }));
|
|
const skill = await json(await request.post(`/api/companies/${company.id}/skills`, { data: {
|
|
name: "YAML proof", slug: "yaml-proof", markdown: "---\nname: yaml-proof\ndescription: Verify saved configuration.\n---\nCheck the persisted state.\n",
|
|
} }));
|
|
const connection = await json(await request.post(`/api/companies/${company.id}/tools/connections`, { data: {
|
|
name: "YAML tools", transport: "mcp_remote", config: { url: toolProvider.url }, status: "draft", enabled: false,
|
|
} }));
|
|
await page.goto(`${url}/overview`);
|
|
await page.getByRole("link", { name: "Advanced", exact: true }).click();
|
|
await edit(page, value => {
|
|
value.spec.title = "Saved YAML engineer";
|
|
value.spec.budgetMonthlyCents = 12300;
|
|
delete value.spec.adapterConfig!.removable;
|
|
value.spec.adapterConfig!.env = { YAML_VARIABLE: { type: "plain", value: "saved variable" } };
|
|
value.spec.instructions!.files = { "workflow.md": "Saved through YAML.\n" };
|
|
value.spec.skills = [{ key: skill.key, versionId: skill.currentVersionId }];
|
|
value.spec.tools = { connections: [{ connectionId: connection.id }] };
|
|
value.spec.tools!.profiles = [{ profileId: null, priority: 100, metadata: null, configuration: {
|
|
profileKey: "yaml-profile", name: "YAML profile", description: null, status: "active", defaultAction: "deny", metadata: null,
|
|
entries: [{ selectorType: "tool_name", toolName: "read_repository", effect: "include" }],
|
|
} }];
|
|
value.spec.tools!.policies = [{ id: null, configuration: { name: "YAML block", policyType: "block", priority: 100, enabled: true, selectors: { agentIds: [agent.id], toolNames: ["delete_repository"] } } }];
|
|
value.spec.permissions = { canCreateSkills: false };
|
|
value.spec.secrets = { create: [{ secret: { name: "YAML secret", value: "disposable-yaml-secret" }, bind: { env: ["YAML_SECRET"], api: [] } }] };
|
|
value.spec.apiKeys = { create: [{ name: "YAML automation", scope: { kind: "standard" } }] };
|
|
value.spec.channelOperations = { create: [{ provider: "telegram" }] };
|
|
});
|
|
await save(page);
|
|
const token = page.getByRole("textbox", { name: "API key: YAML automation token" });
|
|
await expect(token).toBeVisible();
|
|
expect(await token.inputValue()).toMatch(/^pcp_/);
|
|
await page.reload();
|
|
const saved = await document(page);
|
|
expect(saved.spec).toMatchObject({ title: "Saved YAML engineer", budgetMonthlyCents: 12300, permissions: { canCreateSkills: false } });
|
|
expect(saved.spec.adapterConfig).not.toHaveProperty("removable");
|
|
expect(saved.spec.adapterConfig!.env).toMatchObject({ YAML_VARIABLE: { type: "plain", value: "***REDACTED***" }, YAML_SECRET: { type: "secret_ref" } });
|
|
expect(stringify(saved)).not.toContain("disposable-yaml-secret");
|
|
expect(saved.spec.instructions).not.toHaveProperty("files");
|
|
expect((await json(await request.get(`/api/agents/${agent.id}/instructions-bundle/file?path=workflow.md`))).content).toBe("Saved through YAML.\n");
|
|
expect(saved.spec.skills).toEqual([{ key: skill.key, versionId: skill.currentVersionId }]);
|
|
expect(saved.spec.tools!.profiles).toEqual(expect.arrayContaining([expect.objectContaining({ profileKey: "yaml-profile" })]));
|
|
expect(saved.spec.tools!.policies).toEqual([expect.objectContaining({ id: expect.any(String), configuration: expect.objectContaining({ name: "YAML block" }) })]);
|
|
expect(saved.spec.channels).toEqual([expect.objectContaining({ provider: "telegram" })]);
|
|
expect(saved.spec.apiKeys).toBeUndefined();
|
|
expect(saved.spec.secrets).toBeUndefined();
|
|
expect(saved.spec.channelOperations).toBeUndefined();
|
|
await edit(page, value => { value.spec.skills = [skill.key]; });
|
|
await save(page);
|
|
expect((await document(page)).spec.skills).toEqual([skill.key]);
|
|
let repeatedSkillSyncs = 0;
|
|
page.on("request", event => {
|
|
if (event.method() === "POST" && new URL(event.url()).pathname === `/api/agents/${agent.id}/skills/sync`) repeatedSkillSyncs++;
|
|
});
|
|
await edit(page, value => { value.spec.title = "Unpinned skill stays unchanged"; });
|
|
await save(page);
|
|
expect(repeatedSkillSyncs).toBe(0);
|
|
expect((await json(await request.get(`/api/agents/${agent.id}/configuration`))).adapterConfig.env.YAML_SECRET.type).toBe("secret_ref");
|
|
expect((await json(await request.get(`/api/tool-connections/${connection.id}/installs`))).installs).toContainEqual(expect.objectContaining({ targetType: "agent", targetId: agent.id }));
|
|
const key = (await json(await request.get(`/api/agents/${agent.id}/keys`))).find((row: { name: string }) => row.name === "YAML automation");
|
|
await edit(page, value => {
|
|
value.spec.apiKeys = { revoke: [key.id] };
|
|
value.spec.channels![0].settings = { allowUnlinkedPeople: true };
|
|
value.spec.instructions!.files = { "workflow.md": null };
|
|
value.spec.tools!.profiles = [];
|
|
value.spec.tools!.policies = [];
|
|
value.spec.tools!.connections = [];
|
|
value.spec.skills = [];
|
|
});
|
|
await save(page);
|
|
await page.reload();
|
|
const cleared = await document(page);
|
|
expect((await json(await request.get(`/api/agents/${agent.id}/instructions-bundle`))).files.map((file: { path: string }) => file.path)).not.toContain("workflow.md");
|
|
expect(cleared.spec.skills).toBeUndefined();
|
|
expect(cleared.spec.tools).toBeUndefined();
|
|
expect(cleared.spec.channels![0].settings!.allowUnlinkedPeople).toBe(true);
|
|
expect(cleared.spec.channels![0].settings).not.toHaveProperty("communicationInstructions");
|
|
expect((await json(await request.get(`/api/agents/${agent.id}/keys`))).find((row: { id: string }) => row.id === key.id).revokedAt).not.toBeNull();
|
|
await page.screenshot({ path: info.outputPath("saved-agent-yaml.png") });
|
|
});
|