diff --git a/.github/scripts/tests/ci-plan.test.mjs b/.github/scripts/tests/ci-plan.test.mjs index a1232bb33d0..9c446fb265d 100644 --- a/.github/scripts/tests/ci-plan.test.mjs +++ b/.github/scripts/tests/ci-plan.test.mjs @@ -190,6 +190,23 @@ test("canary dry run, runner support, chat, docker and test-only edits select th assert.equal(selected(plan([file]), "docker_context_integrity"), true, `docker: ${file}`); } assert.deepEqual([...selectedTasks(plan(["tests/e2e/smoke.spec.ts"]))].sort(), ["ci:e2e", "ci:typecheck"]); + for (const file of [ + "tests/release-smoke/docker-auth-onboarding.spec.ts", + "tests/release-smoke/onboarding-scenario.ts", + "tests/release-smoke/playwright.config.ts", + ]) { + const result = plan([file]); + assert.equal(result.forceReason, null, file); + assert.deepEqual([...selectedTasks(result)].sort(), ["ci:e2e", "ci:typecheck"], file); + } + for (const file of [ + "ui/src/components/OnboardingWizard.tsx", + "ui/src/pages/AgentChat.tsx", + "server/src/services/onboarding-chat.ts", + "packages/shared/src/question-set.ts", + ]) { + assert.equal(selected(plan([file]), "e2e_shards"), true, file); + } assert.deepEqual([...selectedTasks(plan(["tests/runner-e2e/catalog.test.ts"]))].sort(), ["ci:runner-e2e-support", "ci:runner-package", "ci:runner-static", "ci:typecheck"]); assert.equal(selectedTasks(plan(["packages/paperclip-runner/src/index.ts"])).has("ci:runner-package"), true); assert.equal(selectedTasks(plan(["packages/adapter-utils/src/github-launcher.ts"])).has("ci:runner-package"), true); diff --git a/.github/workflows/pr-trusted.yml b/.github/workflows/pr-trusted.yml index cded7b34fc7..083c7023b3b 100644 --- a/.github/workflows/pr-trusted.yml +++ b/.github/workflows/pr-trusted.yml @@ -1944,6 +1944,7 @@ jobs: - name: Run e2e tests env: + CI_PLAN: ${{ needs.gate.outputs.plan }} PAPERCLIP_E2E_SKIP_LLM: "true" PAPERCLIP_PLAYWRIGHT_CHANNEL: "chrome" PAPERCLIP_E2E_SKIP_UI_BUILD: ${{ steps.e2e_ui_dist.outputs.cache-hit == 'true' && '1' || '' }} diff --git a/doc/testing/onboarding-first-chat-test-drive.md b/doc/testing/onboarding-first-chat-test-drive.md index edac5cfaab4..f6cdabf7b62 100644 --- a/doc/testing/onboarding-first-chat-test-drive.md +++ b/doc/testing/onboarding-first-chat-test-drive.md @@ -31,3 +31,34 @@ PAPERCLIP_TELEMETRY_DISABLED=1 PAPERCLIP_FIRST_CHAT_MANUAL=1 pnpm exec playwri The script starts a separate loopback app and opens a headed browser with scripted model sign-in and scripted replies after submission. It uses the actual wizard, built-in personalized greeting, saved thread, and question response handler. When Playwright pauses, use the browser to follow the steps above. All three choices have scripted replies. After choosing one, type a follow-up such as “build a website” to receive the scripted acknowledgment. Reload and check that the messages keep their order. The fixture stops when Playwright exits. To run the automated fast-arrival and delayed/reduced-motion checks without the inspector, omit `PAPERCLIP_FIRST_CHAT_MANUAL` and `--debug`, and select both tests with `-g 'warms the welcome|welcome request is pending'`. + +## PR and release smoke coverage + +The required `ci / e2e` check runs `tests/e2e/release-onboarding.spec.ts` against +the PR's source and built UI. It uses the same `completeOnboarding` scenario as +the authenticated Docker release smoke. Keep wizard, hire, welcome, and choice +assertions in `tests/release-smoke/onboarding-scenario.ts` so both gates change +together. Changes to the release smoke files also select the source E2E lane. + +The shard planner omits this extra case only for changes confined to the Costs +or Approvals UI pages, source unit tests, and audited prose. Shared components, +hooks, libraries, server code, and new source paths keep the case by default. +Mixed changes keep it when any source file falls outside the known unrelated +set. The skip set lives in `scripts/e2e-shard.mjs`; extend it only after checking +that the new path cannot affect onboarding. + +The browser and Vitest selectors share the source-diff eligibility check. Full +or shadow CI, missing or malformed change plans, deleted or non-source inputs, +and plans for a different checkout keep the case. Local unfiltered E2E runs also +keep it. No separate browser job is added. + +Run the shared scenario before submitting onboarding changes: + +```sh +pnpm exec playwright test --config tests/e2e/playwright.config.ts release-onboarding.spec.ts +``` + +The source run uses a disposable local instance and simulates only the upstream +API key check with the existing provider fixture. It does not need model +credentials. The release run also checks authentication and the published npm +installation. A source E2E pass does not replace that installation check. diff --git a/scripts/__tests__/e2e-shard.test.mjs b/scripts/__tests__/e2e-shard.test.mjs index 244c308f34b..dd365c1972a 100644 --- a/scripts/__tests__/e2e-shard.test.mjs +++ b/scripts/__tests__/e2e-shard.test.mjs @@ -20,6 +20,7 @@ import { resolveEffectiveParallelSpeedup, resolveSerialSlowdown, selectE2eShard, + selectE2eSpecsForPlan, } from "../e2e-shard.mjs"; const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", ".."); @@ -36,8 +37,10 @@ const SHARD_COUNT = JSON.parse(readFileSync(ciTaskMatrixPath, "utf8")).e2e_shard const TARGET_AWS_SHARD_COUNT = 16; const TARGET_HOSTED_SHARD_COUNT = 4; -function runShard(args) { - const result = spawnSync(process.execPath, [script, ...args], { cwd: repoRoot, encoding: "utf8" }); +function runShard(args, ciPlan = "") { + const result = spawnSync(process.execPath, [script, ...args], { + cwd: repoRoot, encoding: "utf8", env: { ...process.env, CI_PLAN: ciPlan }, + }); assert.equal(result.status, 0, `expected success for ${args.join(" ")}: ${result.stderr}`); return result.stdout.trim().split(/\s+/).filter(Boolean); } @@ -132,6 +135,84 @@ test("the e2e shards form a complete, non-overlapping partition", () => { } }); +const planHead = "a".repeat(40); +const scopedPlan = (changed, overrides = {}) => JSON.stringify({ + version: 1, mode: "enabled", forceReason: null, changed, + diff: { head: planHead }, ...overrides, +}); + +test("release onboarding is omitted for unrelated changes without removing other browser specs", () => { + const files = listE2eSpecs(); + const ordinary = files.filter(file => file !== "tests/e2e/release-onboarding.spec.ts"); + for (const changed of [ + ["ui/src/pages/Costs.tsx"], + ["ui/src/lib/onboarding-route.test.ts", "server/src/__tests__/onboarding-chat-route.test.ts"], + ["ui/src/pages/Approvals.tsx", "doc/testing/onboarding-first-chat-test-drive.md"], + ]) { + assert.deepEqual(selectE2eSpecsForPlan(files, scopedPlan(changed), planHead), ordinary); + } +}); + +test("release onboarding is retained for its flow, shared dependencies, and smoke fixtures", () => { + const files = listE2eSpecs(); + for (const file of [ + "ui/src/components/OnboardingWizard.tsx", "ui/src/components/onboarding/FooterNav.tsx", + "ui/src/lib/onboarding-route.ts", "ui/src/pages/AgentChat.tsx", "ui/src/pages/IssueDetail.tsx", + "ui/src/components/ui/button.tsx", "ui/src/api/agents.ts", "ui/src/context/CompanyContext.tsx", + "ui/src/index.css", "ui/src/pages/IssueDetail/history.ts", + "ui/src/components/task-chat/TaskChatComposer.tsx", + "ui/src/lib/new-agent-runtime-config.ts", "ui/src/components/ai-connections/AiConnectionField.tsx", + "ui/src/hooks/useAgentChatEnabled.ts", "ui/src/lib/recent-agent-chats.ts", + "server/src/routes/agents.ts", "server/src/services/onboarding-chat.ts", + "server/src/services/costs.ts", + "server/src/services/ai-api-key-test.ts", "server/src/services/agent-conversations.ts", + "packages/shared/src/question-set.ts", "packages/db/src/schema/agents.ts", + "tests/release-smoke/onboarding-scenario.ts", "tests/e2e/release-onboarding.spec.ts", + "tests/e2e/start-e2e-server.ts", "tests/e2e/fixtures/ai-connection-provider.mjs", + ]) { + assert.deepEqual(selectE2eSpecsForPlan(files, scopedPlan([file]), planHead), files, file); + } + for (const changed of [ + ["ui/src/components/OnboardingWizard.tsx", "ui/src/components/SetupWizard.tsx"], + ["ui/src/pages/Costs.tsx", "ui/src/lib/new-agent-runtime-config.ts"], + ["ui/src/pages/Approvals.tsx", "ui/src/components/task-chat/TaskChatComposer.tsx"], + ]) assert.deepEqual(selectE2eSpecsForPlan(files, scopedPlan(changed), planHead), files); +}); + +test("release onboarding remains in full, unavailable, malformed, or stale plans", () => { + const files = listE2eSpecs(); + for (const serialized of [ + undefined, "", "{", "null", "[]", "{}", + scopedPlan([]), scopedPlan([null]), scopedPlan(["../outside.ts"]), + scopedPlan(["ui/src/pages/Costs.tsx"], { mode: "invalid" }), + scopedPlan(["ui/src/pages/Costs.tsx"], { mode: "shadow" }), + scopedPlan(["ui/src/pages/Costs.tsx"], { diff: null }), + scopedPlan(["ui/src/pages/Costs.tsx"], { version: 2 }), + scopedPlan(["ui/src/pages/Costs.tsx"], { mode: "full" }), + scopedPlan(["ui/src/pages/Costs.tsx"], { forceReason: "Diff unavailable" }), + scopedPlan(["ui/src/pages/Costs.tsx"], { diff: { head: "b".repeat(40) } }), + ]) { + assert.deepEqual(selectE2eSpecsForPlan(files, serialized, planHead), files); + } +}); + +test("conditional onboarding selection keeps an exact CLI shard partition", () => { + const result = spawnSync("git", ["rev-parse", "HEAD"], { cwd: repoRoot, encoding: "utf8" }); + assert.equal(result.status, 0); + const serialized = scopedPlan(["ui/src/pages/Costs.tsx"], { diff: { head: result.stdout.trim() } }); + const expected = listE2eSpecs().filter(file => file !== "tests/e2e/release-onboarding.spec.ts"); + const shards = Array.from({ length: TARGET_HOSTED_SHARD_COUNT }, (_, index) => + runShard(["--shard-index", String(index), "--shard-count", String(TARGET_HOSTED_SHARD_COUNT)], serialized)); + assert.deepEqual(shards.flat().sort(), expected); + assert.ok(shards.every(shard => shard.length > 0)); +}); + +test("the PR browser step passes the trusted change plan to shard selection", () => { + const block = readWorkflowJobs(readTrustedPrWorkflow()).get("e2e_shards"); + const step = block.split(" - name: Run e2e tests\n")[1].split(" - name:")[0]; + assert.match(step, /CI_PLAN: \$\{\{ needs\.gate\.outputs\.plan \}\}/); +}); + test("the ignored spec list matches playwright.config.ts testIgnore", () => { const config = readFileSync(playwrightConfig, "utf8"); const match = config.match(/testIgnore:\s*\[([^\]]*)\]/); diff --git a/scripts/ci/select-tests.mjs b/scripts/ci/select-tests.mjs index 6ef2a898ae8..1597a983882 100644 --- a/scripts/ci/select-tests.mjs +++ b/scripts/ci/select-tests.mjs @@ -1,5 +1,5 @@ import { execFileSync } from "node:child_process"; -import { appendFileSync, lstatSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; +import { appendFileSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; import { fileURLToPath } from "node:url"; import path from "node:path"; import assert from "node:assert/strict"; @@ -8,24 +8,9 @@ import { activeNightlySuitesForEnv } from "./nightly-only-suites.mjs"; import { productInputs } from "../../.github/scripts/ci-inputs.mjs"; import { mergeDiff } from "../../.github/scripts/ci-diff.mjs"; import { selectProjects } from "./select-projects.mjs"; +import { selectionEligibility } from "./selection-eligibility.mjs"; -export function selectionEligibility(plan, root = process.cwd()) { - if (plan?.version !== 1 || plan.mode !== "enabled" || plan.forceReason) return "Full/shadow/forced task plan"; - if (!Array.isArray(plan.changed) || !plan.changed.length) return "Incomplete comparison"; - const changed = productInputs(plan.changed); - if (!changed.length) return "Documentation-only diff"; - for (const file of changed) { - // Business modules can contain "config"/"setup" in their names. The graph - // separately tracks actual setup and configuration dependencies. - if (!/^(?:ui\/src|server\/src|cli\/src|packages\/.+\/src)\/.+\.[cm]?[jt]sx?$/.test(file) - || /(?:^|\/)(?:vite|vitest)\.(?:config|setup)\.[cm]?[jt]sx?$|\.d\.[cm]?ts$/i.test(file) - || file.split("/").includes("..")) return `Broad input: ${file}`; - try { - if (!lstatSync(path.join(root, file)).isFile()) return `Non-regular source: ${file}`; - } catch { return `Deleted or missing source: ${file}`; } - } - return null; -} +export { selectionEligibility }; function runnerInventory(group) { const args = group === "serialized" ? ["--mode", "serialized", "--shard-index", "0", "--shard-count", "1"] diff --git a/scripts/ci/selection-eligibility.mjs b/scripts/ci/selection-eligibility.mjs new file mode 100644 index 00000000000..c7425ef84d9 --- /dev/null +++ b/scripts/ci/selection-eligibility.mjs @@ -0,0 +1,19 @@ +import { lstatSync } from "node:fs"; +import path from "node:path"; +import { productInputs } from "../../.github/scripts/ci-inputs.mjs"; + +export function selectionEligibility(plan, root = process.cwd()) { + if (plan?.version !== 1 || plan.mode !== "enabled" || plan.forceReason) return "Full/shadow/forced task plan"; + if (!Array.isArray(plan.changed) || !plan.changed.length) return "Incomplete comparison"; + const changed = productInputs(plan.changed); + if (!changed.length) return "Documentation-only diff"; + for (const file of changed) { + if (!/^(?:ui\/src|server\/src|cli\/src|packages\/.+\/src)\/.+\.[cm]?[jt]sx?$/.test(file) + || /(?:^|\/)(?:vite|vitest)\.(?:config|setup)\.[cm]?[jt]sx?$|\.d\.[cm]?ts$/i.test(file) + || file.split("/").includes("..")) return `Broad input: ${file}`; + try { + if (!lstatSync(path.join(root, file)).isFile()) return `Non-regular source: ${file}`; + } catch { return `Deleted or missing source: ${file}`; } + } + return null; +} diff --git a/scripts/e2e-shard.mjs b/scripts/e2e-shard.mjs index ccbfda8de5b..e763bcd0ac0 100644 --- a/scripts/e2e-shard.mjs +++ b/scripts/e2e-shard.mjs @@ -1,9 +1,12 @@ +import { execFileSync } from "node:child_process"; import { readdirSync } from "node:fs"; import os from "node:os"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { loadShardDurations, partitionGeneralServerSuites } from "./general-server-shard.mjs"; +import { selectionEligibility } from "./ci/selection-eligibility.mjs"; +import { productInputs } from "../.github/scripts/ci-inputs.mjs"; const HERE = path.dirname(fileURLToPath(import.meta.url)); const REPO_ROOT = path.resolve(HERE, ".."); @@ -130,6 +133,22 @@ export function selectE2eShard(files, shardIndex, shardCount, durations = {}, op return partitionE2eShards(files, shardCount, durations, options)[shardIndex].files; } +const unrelatedOnboardingInputs = new Set([ + "ui/src/pages/Costs.tsx", + "ui/src/pages/Approvals.tsx", +]); + +export function selectE2eSpecsForPlan(files, serializedPlan, head) { + try { + const plan = JSON.parse(serializedPlan); + if (!/^[a-f0-9]{40}$/.test(head ?? "") || plan?.diff?.head !== head + || selectionEligibility(plan, REPO_ROOT)) return files; + const unrelated = productInputs(plan.changed).every(file => + unrelatedOnboardingInputs.has(file) || /\.test\.[cm]?[jt]sx?$/.test(file)); + return unrelated ? files.filter(file => file !== "tests/e2e/release-onboarding.spec.ts") : files; + } catch { return files; } +} + function parseArgs(argv) { const args = { shardIndex: 0, shardCount: 1, parallelSpeedup: null, serialSlowdown: null }; for (let index = 0; index < argv.length; index += 1) { @@ -164,7 +183,13 @@ function main(argv) { ? envSlowdown : resolveSerialSlowdown(); - const specs = listE2eSpecs(); + let head; + try { + if (process.env.CI_PLAN) head = execFileSync("git", ["rev-parse", "HEAD"], { + cwd: REPO_ROOT, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], + }).trim(); + } catch {} + const specs = selectE2eSpecsForPlan(listE2eSpecs(), process.env.CI_PLAN, head); const durations = loadShardDurations(DURATIONS_MANIFEST); process.stdout.write( `${selectE2eShard(specs, shardIndex, shardCount, durations, { diff --git a/tests/e2e/release-onboarding.spec.ts b/tests/e2e/release-onboarding.spec.ts new file mode 100644 index 00000000000..9086954e489 --- /dev/null +++ b/tests/e2e/release-onboarding.spec.ts @@ -0,0 +1,12 @@ +import { test } from "@playwright/test"; +import { completeOnboarding } from "../release-smoke/onboarding-scenario"; + +test("the release onboarding scenario passes against PR source", async ({ page }) => { + test.setTimeout(90_000); + await page.goto("/"); + await completeOnboarding(page, { + companyName: `Source-Release-Smoke-${Date.now()}`, + agentName: "Release Smoke Lead", + anthropicApiKey: "paperclip-e2e-personal-claude-key", + }); +}); diff --git a/tests/release-smoke/docker-auth-onboarding.spec.ts b/tests/release-smoke/docker-auth-onboarding.spec.ts index 3d6329029bb..1bfca95c96d 100644 --- a/tests/release-smoke/docker-auth-onboarding.spec.ts +++ b/tests/release-smoke/docker-auth-onboarding.spec.ts @@ -1,4 +1,5 @@ import { expect, test, type Page } from "@playwright/test"; +import { completeOnboarding } from "./onboarding-scenario"; const ADMIN_EMAIL = process.env.PAPERCLIP_RELEASE_SMOKE_EMAIL ?? @@ -32,14 +33,6 @@ const ANTHROPIC_API_KEY = process.env.PAPERCLIP_RELEASE_SMOKE_ANTHROPIC_API_KEY ?? (TARGET_IS_LOOPBACK ? "sk-ant-release-smoke-placeholder" : ""); -const COMPANY_NAME = `Release-Smoke-${Date.now()}`; -const AGENT_NAME = "Release Smoke Lead"; -// The arc asks for a name, not a role, so every onboarding hire is filed under -// the neutral role (DEFAULT_AGENT_ROLE in ui/src/lib/onboarding-agent-role.ts). -const AGENT_ROLE = "general"; -// ONBOARDING_CHAT_ORIGIN_KIND in packages/shared/src/constants.ts. -const ONBOARDING_CHAT_ORIGIN_KIND = "onboarding_chat"; - async function signIn(page: Page) { await page.goto("/"); await expect(page).toHaveURL(/\/auth/); @@ -51,257 +44,17 @@ async function signIn(page: Page) { await expect(page).not.toHaveURL(/\/auth/, { timeout: 20_000 }); } -async function getJson(page: Page, url: string): Promise { - const response = await page.request.get(url); - expect(response.ok()).toBe(true); - return (await response.json()) as T; -} - -// ONBOARDING_STORAGE_KEY in ui/src/components/OnboardingWizard.tsx. -const ONBOARDING_DRAFT_STORAGE_KEY = "paperclip-onboarding-state"; - -/** - * Open the wizard on its first step and hand back the organization-name field. - * - * `/onboarding` resolves to `{ initialStep: 1 }` on a self-hosted instance - * (`resolveRouteOnboardingOptions`) and the route keeps the wizard open, so - * this lands on "name your organization" whether or not the instance already - * holds a company. Navigating explicitly is what keeps the spec re-runnable: - * the release-smoke config retries once in CI, and by the second attempt the - * instance is no longer company-less, so sign-in lands on a dashboard instead. - * - * The saved draft is dropped first. Sign-in on an instance that already holds - * an agentless company redirects into *that* company's onboarding, which - * persists its id into the draft; the restored draft then makes step 1 skip - * creating a company and hire into the old one instead. That is an artifact of - * re-running against a re-used instance, not behaviour this spec is asserting, - * and a fresh release-smoke container never has it. - * - * The field is located by role. Step 1 has no id and its `