opencode/packages/stories/playwright/README.md
Luke Parker be315b1db8 chore: merge beta into dev
Brings the desktop beta work into dev as a merge commit, so its history is kept.
Core, server and client changes from beta were backported to dev one PR at a time
first (#59081 to #59107).

Left out of this merge, so dev keeps its current behaviour:
- Generated UI, entirely: the plugin-genui package, its core registration and
  publishing, the session-ui surfaces, charts, form replies and streaming tool
  input, the app setting and its strings, tool-input delta publishing, and their
  tests. It lands on dev later through its own pull request.
- The `ast-grep-ignore: no-star-import` comment in cross-spawn-spawner.ts,
  which lint:effect-patterns still needs.

Notes:
- Dev-channel builds now use their own service-dev.json, port and
  opencode-dev.db (#58331), so dev-build users start on a fresh database.
- #56550 (plugin instruction entries) and #57527 (untracked folder rows) come
  in as on beta; follow-ups go to dev.
- Docs from beta are pointed at check-test.yml, after the workflow rename.
- #59132's fix (settings toggles MCP servers in the session's location) is
  ported onto beta's rewritten Extensions page, and #59131's browser title test
  joins beta's tab tests.
2026-10-26 13:56:31 +10:00

61 lines
3.9 KiB
Markdown

# Component browser tests
Production Solid components are tested through their existing `*.stories.tsx` stories without booting the app, configuring a server, seeding browser storage, or navigating unrelated routes.
Keep each spec in the package that owns its production component:
- `packages/session-ui/component-tests/` owns timeline, tool, notice, reasoning, lifecycle, and review coverage.
- `packages/app/component-tests/` owns Composer and other app-only component coverage.
- `packages/stories/` owns the story server (a plain Vite page that renders one story with fixed data in place of the server, router and project), the shared Playwright configuration and the `story` mount fixture.
Run a package's isolated browser suite from that package:
```sh
# Session UI components.
cd packages/session-ui
bun run test:components
bun run test:components -- component-tests/session-timeline.spec.ts
bun run test:components:ui
# App-owned components.
cd packages/app
bun run test:components
bun run test:components -- component-tests/composer.spec.ts
```
Both suites are separately filterable Turbo tasks:
```sh
bun turbo test:components --filter=@opencode/session-ui
bun turbo test:components --filter=@opencode/app
```
Component browser coverage deliberately remains separate from each package's default `test` script and from `packages/app`'s `test:e2e`, so expensive browser checks can be scheduled independently from required unit and full-app journey CI. CI runs each suite in its own leg of the `e2e` job in `.github/workflows/check-test.yml` (`session-ui-components` and `app-components`). Set `PLAYWRIGHT_STORIES_URL` to reuse a running story server (`bun --cwd packages/stories dev`) or `PLAYWRIGHT_STORIES_PORT` to choose its port.
## Adding a test
Keep inspectable scenarios next to the production component in a `*.stories.tsx` file. A story owns its fixtures, providers, state, and callbacks; its package-local spec owns user-visible interactions and assertions.
```ts
import { expect, story } from "../../stories/playwright/story"
// Moved from packages/app/e2e/regression/session-timeline-context-state.spec.ts
story("preserves collapsed state while a tool completes", async ({ mount }) => {
const component = await mount("current-session-research-agents--agent-research", {
args: { scenario: "exploration" },
})
const trigger = component.locator('[data-slot="collapsible-trigger"]')
await expect(trigger).toHaveAttribute("aria-expanded", "false")
await component.getByRole("button", { name: "Complete read" }).click()
await expect(trigger).toHaveAttribute("aria-expanded", "false")
})
```
The story ID is the story file's meta `id` (or its title, kebab-cased) followed by `--` and the kebab-cased story export, as Storybook named them. Open `http://127.0.0.1:6006/?id=<story id>` on a running story server, or the story in the app's components lab, to inspect exactly the scenario covered by the browser test. Preserve an original-source-path comment for every migrated E2E case.
Keep cross-route navigation, remote-server ownership, persistent session state, full-app virtualization, and workflows spanning independent surfaces in `packages/app/e2e/`.
Component rendering and integration coverage can be complementary. A local story control that installs a completed message does not test event delivery, production reducer cleanup, or a live stream. Keep those original checks in E2E, including stream/chunk identity, compaction and retry events, independent lifecycle transitions, and the real app scroll owner. A provenance comment records the source of a component assertion; it is not evidence that its integration counterpart can be deleted.
When moving an assertion, preserve its discriminating fixture: file status kinds, empty/single-variant inputs, singleton groups, live message state, and the order of intermediate updates. Verify the actual scroll container overflows before asserting that keyboard activation does not scroll it.