From 3f05355fcffbcaf8d8c8fc0e5164d6327440fc27 Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Fri, 13 Nov 2026 08:14:15 -0600 Subject: [PATCH] test(pm-aggregator): add MOB-00 deterministic browser acceptance harness (#9467) --- .github/workflows/pm-aggregator-tests.yml | 39 ++++++ pm-stack/aggregator/bun.lock | 7 ++ pm-stack/aggregator/package.json | 1 + pm-stack/aggregator/playwright.config.ts | 46 +++++++ .../test/browser/mobile-work-view.spec.ts | 117 ++++++++++++++++++ 5 files changed, 210 insertions(+) create mode 100644 pm-stack/aggregator/playwright.config.ts create mode 100644 pm-stack/aggregator/test/browser/mobile-work-view.spec.ts diff --git a/.github/workflows/pm-aggregator-tests.yml b/.github/workflows/pm-aggregator-tests.yml index e8902a1089..0ea73de9e9 100644 --- a/.github/workflows/pm-aggregator-tests.yml +++ b/.github/workflows/pm-aggregator-tests.yml @@ -88,3 +88,42 @@ jobs: run: bun install --frozen-lockfile - name: Run projector tests run: bun test + + browser: + name: browser acceptance (MOB-00) + runs-on: ubuntu-latest + timeout-minutes: 30 + # Same fixture contract as the test job (#5557): the MOB-00 + # Playwright harness (#9467) boots the aggregator in fixture mode + # and aborts every non-local request, so the run is deterministic + # and needs no GitHub/Project/session credentials. + env: + PM_AGG_SOURCE: fixtures + PM_AGG_DEV: "1" + defaults: + run: + working-directory: pm-stack/aggregator + steps: + - uses: actions/checkout@v7 + - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0 + - name: Install dependencies + run: bun install --frozen-lockfile + - name: Resolve pinned Playwright version + id: pw + run: echo "version=$(bunx playwright --version | awk '{print $2}')" >> "$GITHUB_OUTPUT" + - name: Cache Playwright browsers (pinned by @playwright/test in bun.lock) + uses: actions/cache@v4 + with: + path: ~/.cache/ms-playwright + key: playwright-${{ runner.os }}-${{ steps.pw.outputs.version }}-${{ hashFiles('pm-stack/aggregator/bun.lock') }} + - name: Install Chromium for the pinned Playwright version + run: bunx playwright install --with-deps chromium + - name: Run browser acceptance (MOB-00 contract test) + run: bunx playwright test --config playwright.config.ts --grep pmo_mob_03/04 + - name: Upload Playwright trace/video on failure + if: failure() + uses: actions/upload-artifact@v7 + with: + name: playwright-test-results + path: pm-stack/aggregator/test-results + if-no-files-found: ignore diff --git a/pm-stack/aggregator/bun.lock b/pm-stack/aggregator/bun.lock index 5626a88600..94ad44ede4 100644 --- a/pm-stack/aggregator/bun.lock +++ b/pm-stack/aggregator/bun.lock @@ -8,6 +8,7 @@ "web-push": "^3.6.7", }, "devDependencies": { + "@playwright/test": "1.64.0", "@tailwindcss/cli": "^4.3.4", "@types/bun": "latest", "daisyui": "^5.7.50", @@ -53,6 +54,8 @@ "@parcel/watcher-win32-x64": ["@parcel/watcher-win32-x64@2.6.0", "https://registry.npmmirror.com/@parcel/watcher-win32-x64/-/watcher-win32-x64-2.6.0.tgz", { "os": "win32", "cpu": "x64" }, "sha512-cA+/pXV2YkfxlIcXOQ5fSWqAzzPyD78/x5qbK/I0vUkrlYHA8TIz+MXjAbGouguKVSI4bOmkTSJ1/poVSsgt+A=="], + "@playwright/test": ["@playwright/test@1.64.0", "https://registry.npmmirror.com/@playwright/test/-/test-1.64.0.tgz", { "dependencies": { "playwright": "1.64.0" }, "bin": { "playwright": "cli.js" } }, "sha512-oTN9FNYuN6bqQMwiho6jJKLCG2/QOYCixGXuCjRmzOq23eODeukuY2XiAVoVpAECbuezMt1MHQjAiQxK8F+Y+g=="], + "@tailwindcss/cli": ["@tailwindcss/cli@4.3.4", "https://registry.npmmirror.com/@tailwindcss/cli/-/cli-4.3.4.tgz", { "dependencies": { "@parcel/watcher": "2.6.0", "@tailwindcss/node": "4.3.4", "@tailwindcss/oxide": "4.3.4", "enhanced-resolve": "^5.24.5", "mri": "^1.2.0", "picocolors": "^1.1.1", "tailwindcss": "4.3.4" }, "bin": { "tailwindcss": "./dist/index.mjs" } }, "sha512-279RsQ1SjT5PcUp6za3F9Qavw933WkMErTOArEKl+gOS4BBgW/2/w9Tn5zLSRy8t/U1Kiy4LmKjuxrFFsbbtAw=="], "@tailwindcss/node": ["@tailwindcss/node@4.3.4", "https://registry.npmmirror.com/@tailwindcss/node/-/node-4.3.4.tgz", { "dependencies": { "@jridgewell/remapping": "^2.3.5", "enhanced-resolve": "^5.24.5", "jiti": "^2.7.0", "lightningcss": "1.33.0", "magic-string": "^1.1.0", "source-map-js": "^1.2.1", "tailwindcss": "4.3.4" } }, "sha512-b7QK/QG04v3j04NbpG82XLCedRyulnkuwUDwRa9oK/ypnJIzMapz2Wg+0TltVczjUzDaJJHIa1+jj9aMUOFMTQ=="], @@ -165,6 +168,10 @@ "picomatch": ["picomatch@4.0.7", "https://registry.npmmirror.com/picomatch/-/picomatch-4.0.7.tgz", {}, "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA=="], + "playwright": ["playwright@1.64.0", "https://registry.npmmirror.com/playwright/-/playwright-1.64.0.tgz", { "dependencies": { "playwright-core": "1.64.0" }, "bin": { "playwright": "cli.js" } }, "sha512-kVzTnYFYEyQ9RGzBjNCd2+yEqWmVbxl3AHPynv3qQ6JTjv4a+kwRcnqQwIpuP3NnrnIrE/Q6wWAIAvMfIE2/Yg=="], + + "playwright-core": ["playwright-core@1.64.0", "https://registry.npmmirror.com/playwright-core/-/playwright-core-1.64.0.tgz", { "bin": { "playwright-core": "cli.js" } }, "sha512-T9r+MZkTECl2+oUcZ26YgZzTrYidTsIhYYkJix+6iDOymOb1FB2RLLSOxRGnZGv5DStt+aduIVbt+E8WygXYpg=="], + "safe-buffer": ["safe-buffer@5.2.1", "https://registry.npmmirror.com/safe-buffer/-/safe-buffer-5.2.1.tgz", {}, "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ=="], "safer-buffer": ["safer-buffer@2.1.2", "https://registry.npmmirror.com/safer-buffer/-/safer-buffer-2.1.2.tgz", {}, "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="], diff --git a/pm-stack/aggregator/package.json b/pm-stack/aggregator/package.json index 70ce48c845..e5d4bb3773 100644 --- a/pm-stack/aggregator/package.json +++ b/pm-stack/aggregator/package.json @@ -13,6 +13,7 @@ "build:css": "tailwindcss -i src/ui.css -o src/assets/app.css" }, "devDependencies": { + "@playwright/test": "1.64.0", "@tailwindcss/cli": "^4.3.4", "@types/bun": "latest", "daisyui": "^5.7.50", diff --git a/pm-stack/aggregator/playwright.config.ts b/pm-stack/aggregator/playwright.config.ts new file mode 100644 index 0000000000..3339daabae --- /dev/null +++ b/pm-stack/aggregator/playwright.config.ts @@ -0,0 +1,46 @@ +// MOB-00 (#9467): deterministic browser acceptance harness for the +// pm-stack aggregator's mobile work views. The harness boots the real +// server in fixture mode (PM_AGG_SOURCE=fixtures — the same fixture +// contract as the bun suite) on loopback-only ports and drives it with +// a pinned @playwright/test + Chromium. No GitHub/Project/session +// credentials are involved; the spec additionally aborts every request +// that is not aimed at the fixture server, so a passing run proves the +// flow works on isolated deterministic fixture data only. +// +// Trace and video are retained on failure (never a screenshot-only +// pass). The bun contract/read-model fixtures stay in `bun test` and +// are not part of this config: testDir is test/browser only. +import { defineConfig } from "@playwright/test"; + +const PORT = 4797; +const FRESHNESS_PORT = 4897; +const ORIGIN = `http://127.0.0.1:${PORT}`; + +export default defineConfig({ + testDir: "./test/browser", + timeout: 60_000, + expect: { timeout: 10_000 }, + fullyParallel: false, + workers: 1, + retries: 0, + reporter: [["list"]], + use: { + baseURL: ORIGIN, + viewport: { width: 360, height: 740 }, + trace: "retain-on-failure", + video: "retain-on-failure", + screenshot: "only-on-failure", + }, + projects: [{ name: "chromium-360", use: { browserName: "chromium" } }], + webServer: { + command: "bun run src/server.ts", + url: `${ORIGIN}/api/health`, + reuseExistingServer: false, + timeout: 60_000, + env: { + PM_AGG_SOURCE: "fixtures", + PM_AGG_PORT: String(PORT), + PM_AGG_FRESHNESS_PORT: String(FRESHNESS_PORT), + }, + }, +}); diff --git a/pm-stack/aggregator/test/browser/mobile-work-view.spec.ts b/pm-stack/aggregator/test/browser/mobile-work-view.spec.ts new file mode 100644 index 0000000000..508aea51ce --- /dev/null +++ b/pm-stack/aggregator/test/browser/mobile-work-view.spec.ts @@ -0,0 +1,117 @@ +// MOB-00 (#9467): the browser acceptance contract for the mobile work +// views, named for the slices whose acceptance it carries — MOB-03 +// (responsive mobile queue, item detail, saved views, #9470) and +// MOB-04 (accessible compact responsive interaction system, #9471). +// +// The test runs against the aggregator's deterministic fixture mode +// only: every request that is not aimed at the local fixture server +// is aborted, and the queue item under test is read from the fixture +// server's own /api/queue.json, so the run is reproducible offline +// with no GitHub/Project/session credentials. +// +// Assertions (the MOB-00 acceptance contract): +// 1. Queue flow at 360px: the queue shell loads its fragment and +// renders the fixture item's card; the page has no horizontal +// overflow at 360px or at 768px. +// 2. Keyboard reachability: repeated Tab presses move focus onto +// the queue card's title link (no mouse involved). +// 3. Detail flow: the same item's /item/ detail page renders +// its title as the page heading at 360px, again with no +// horizontal overflow. +// 4. Action + status announcement: on the needs-you work view, a +// triage action submitted from the keyboard (focus + Enter) is +// accepted by the actions API (201) and the app then presents +// the result back in the page — the acted item joins the +// "Dismissed / done by you" section, whose count increments. +// (Comment posting is deliberately not used here: its author +// authorization resolves through the host secret store, which +// would make the harness non-deterministic across machines.) +import { expect, test, type Page } from "@playwright/test"; + +const ORIGIN = "http://127.0.0.1:4797"; + +test.beforeEach(async ({ page }) => { + // Network isolation: local fixture server only. + await page.route("**/*", (route) => { + const url = route.request().url(); + if (url.startsWith(ORIGIN) || url.startsWith("data:") || url.startsWith("blob:")) { + return route.continue(); + } + return route.abort(); + }); +}); + +async function expectNoHorizontalOverflow(page: Page) { + const overflow = await page.evaluate( + () => document.documentElement.scrollWidth - document.documentElement.clientWidth, + ); + expect(overflow).toBeLessThanOrEqual(1); +} + +test("pmo_mob_03/04_mobile_queue_keyboard_and_viewport_contract", async ({ page, request }) => { + // The deterministic fixture item: first in-progress row of the + // queue's own API, rendered by the queue page below. + const apiRes = await request.get(`${ORIGIN}/api/queue.json`); + expect(apiRes.ok()).toBe(true); + const queue = (await apiRes.json()) as { + inProgress: { id: string; title: string }[]; + }; + const item = queue.inProgress[0]; + expect(item, "fixture queue must contain an in-progress item").toBeTruthy(); + + // 1. Queue flow at 360px (fragment shell, as a phone browser gets it). + await page.setViewportSize({ width: 360, height: 740 }); + await page.goto("/queue"); + const card = page.locator("#queue-main article.card", { hasText: item.title }).first(); + await expect(card).toBeVisible(); + await expectNoHorizontalOverflow(page); + + // The same queue page must also fit the 768px tablet width. + await page.setViewportSize({ width: 768, height: 900 }); + await expectNoHorizontalOverflow(page); + await page.setViewportSize({ width: 360, height: 740 }); + + // 2. Keyboard reachability: Tab from the top of the page until the + // card's title link holds focus. + const titleLink = card.locator("a").first(); + await page.evaluate(() => window.scrollTo(0, 0)); + let focused = false; + for (let i = 0; i < 80 && !focused; i += 1) { + await page.keyboard.press("Tab"); + focused = await titleLink.evaluate((el) => document.activeElement === el); + } + expect(focused, "queue card title link must be reachable by Tab").toBe(true); + + // 3. Detail flow for the same queue item, at phone width. + await page.goto(`/item/${encodeURIComponent(item.id)}`); + await expect(page.locator("h1")).toContainText(item.title); + await expectNoHorizontalOverflow(page); + + // 4. Action + status announcement, driven from the keyboard: + // dismiss the first needs-you card and verify the result is + // presented back in the page (the Dismissed / done count grows). + await page.goto("/attention?full=1"); + const dismissedCount = async (): Promise => { + try { + return await page.evaluate(() => { + const m = document.body.innerText.match(/Dismissed \/ done by you \((\d+)\)/); + return m ? Number(m[1]) : 0; + }); + } catch { + return -1; // navigation in flight; the poll below retries + } + }; + const before = await dismissedCount(); + expect(before).toBeGreaterThanOrEqual(0); + const dismissButton = page + .locator('form.aform[data-verb="dismiss"] button[type="submit"]') + .first(); + await expect(dismissButton).toBeVisible(); + const actionResponse = page.waitForResponse( + (r) => r.url().includes("/api/actions") && r.request().method() === "POST", + ); + await dismissButton.focus(); + await page.keyboard.press("Enter"); + expect((await actionResponse).status()).toBe(201); + await expect.poll(dismissedCount).toBe(before + 1); +});