openspec-playwright 0.1.38 → 0.1.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,39 @@
1
+ Run Playwright E2E verification for an OpenSpec change.
2
+
3
+ ## Workflow
4
+
5
+ 1. **Validate environment**: Run the seed test to confirm your app is reachable.
6
+ ```bash
7
+ npx playwright test tests/playwright/seed.spec.ts --project=chromium
8
+ ```
9
+ If it fails, fix your BASE_URL or start the dev server first.
10
+
11
+ 2. **Select the change**: If no change name is provided, run `openspec list --json` and pick one. Then announce: "Using change: `<name>`".
12
+
13
+ 3. **Read specs**: Read all files from `openspec/changes/<name>/specs/*.md`.
14
+
15
+ 4. **Detect auth**: Check if specs mention login, protected routes, or session handling. See `tests/playwright/auth.setup.ts` for auth setup.
16
+
17
+ 5. **Generate test plan**: Create `openspec/changes/<name>/specs/playwright/test-plan.md` listing each test case with `@auth(required|none)` and `@role(...)` tags. Skip if already exists.
18
+
19
+ 6. **Generate tests**: Write `tests/playwright/<name>.spec.ts` from the test plan. Follow the patterns in `seed.spec.ts`:
20
+ - Prefer `data-testid`, fallback to `getByRole`, `getByLabel`, `getByText`
21
+ - Include happy path AND error/edge cases
22
+ - Never use conditional `if (isVisible())` — always use `expect().toBeVisible()` (false-pass anti-pattern)
23
+ - Use `browser.newContext()` for auth guard tests (fresh session, no cookies)
24
+
25
+ 7. **Run tests**:
26
+ ```bash
27
+ openspec-pw run <change-name>
28
+ ```
29
+ Or with role filtering:
30
+ ```bash
31
+ npx playwright test tests/playwright/<name>.spec.ts --grep "@<role>"
32
+ ```
33
+
34
+ 8. **Fix failures**: If tests fail, analyze the error:
35
+ - Network/backend error → `test.skip()` + report
36
+ - Selector changed → use Playwright MCP tools to find equivalent selectors, fix, re-run
37
+ - Auto-heal up to 3 attempts
38
+
39
+ 9. **Report**: Results are saved to `openspec/reports/playwright-e2e-<name>-<timestamp>.md`. Present the summary table to the user.
package/README.md CHANGED
@@ -18,21 +18,35 @@ openspec init # Initialize OpenSpec
18
18
  openspec-pw init # Install Playwright E2E integration
19
19
  ```
20
20
 
21
+ ## Supported AI Coding Assistants
22
+
23
+ Auto-detects and installs commands for these editors:
24
+
25
+ | Editor | Command | Format |
26
+ |--------|---------|--------|
27
+ | Claude Code | `/opsx:e2e` | Skill + command + MCP |
28
+ | Cursor | `/opsx-e2e` | Command |
29
+ | Windsurf | `/opsx-e2e` | Workflow |
30
+ | Cline | `/opsx-e2e` | Workflow |
31
+ | Continue | `/opsx-e2e` | Prompt |
32
+
33
+ `openspec-pw init` detects which editors you have in your project and installs the appropriate files. Claude Code gets the full experience (skill + command + Playwright MCP). Other editors get command/workflow files with the complete E2E workflow.
34
+
21
35
  ## Usage
22
36
 
23
- ### In Claude Code
37
+ ### In Your AI Coding Assistant
24
38
 
25
39
  ```bash
26
- /opsx:e2e my-feature # Primary command (OpenSpec convention)
27
- /openspec-e2e # Alternative from skill
40
+ /opsx:e2e my-feature # Claude Code
41
+ /opsx-e2e my-feature # Cursor, Windsurf, Cline, Continue
28
42
  ```
29
43
 
30
44
  ### CLI Commands
31
45
 
32
46
  ```bash
33
47
  openspec-pw init # Initialize integration (one-time setup)
34
- openspec-pw update # Update CLI and skill to latest version
35
- openspec-pw doctor # Check prerequisites
48
+ openspec-pw update # Update CLI and commands to latest version
49
+ openspec-pw doctor # Check prerequisites
36
50
  ```
37
51
 
38
52
  ## How It Works
@@ -62,13 +76,16 @@ openspec-pw doctor # Check prerequisites
62
76
 
63
77
  1. **Node.js >= 20**
64
78
  2. **OpenSpec** initialized: `npm install -g @fission-ai/openspec && openspec init`
65
- 3. **Claude Code** with Playwright MCP configured
79
+ 3. **One of**: Claude Code, Cursor, Windsurf, Cline, or Continue (auto-detected)
80
+ 4. **Claude Code only**: Playwright MCP — `claude mcp add playwright npx @playwright/mcp@latest`
66
81
 
67
82
  ## What `openspec-pw init` Does
68
83
 
69
- 1. Installs Playwright MCP globally via `claude mcp add`
70
- 2. Installs `/opsx:e2e` command and `/openspec-e2e` skill
71
- 3. Generates `tests/playwright/seed.spec.ts`, `auth.setup.ts`, `credentials.yaml`
84
+ 1. Detects installed AI coding assistants (Claude Code, Cursor, Windsurf, Cline, Continue)
85
+ 2. Installs E2E command/workflow files for each detected editor
86
+ 3. Installs `/openspec-e2e` skill for Claude Code
87
+ 4. Installs Playwright MCP globally for Claude Code (via `claude mcp add`)
88
+ 5. Generates `tests/playwright/seed.spec.ts`, `auth.setup.ts`, `credentials.yaml`
72
89
 
73
90
  > **Note**: After running `openspec-pw init`, manually install Playwright browsers: `npx playwright install --with-deps`
74
91
 
@@ -109,23 +126,30 @@ Edit `tests/playwright/credentials.yaml`:
109
126
  - Configure test user credentials
110
127
  - Add multiple users for role-based tests
111
128
 
112
- ### MCP server
129
+ ### MCP server (Claude Code only)
113
130
 
114
- Playwright MCP is installed globally via `claude mcp add`. Restart Claude Code after setup to activate.
131
+ Playwright MCP is installed globally via `claude mcp add` and enables the Healer Agent (auto-heals test failures via UI inspection). Restart Claude Code after setup to activate.
115
132
 
116
133
  ## Architecture
117
134
 
118
135
  ```
119
- openspec-pw (CLI - setup only)
120
- ├── Installs Playwright agents (.github/)
121
- ├── Installs Playwright MCP globally via claude mcp add
122
- ├── Installs Claude Code skill (/openspec-e2e)
123
- └── Installs command (/opsx:e2e)
124
-
125
- /openspec-e2e (Claude Code skill - runs in Claude)
126
- ├── Reads OpenSpec specs
127
- ├── Triggers Playwright agents via MCP
128
- └── Generates E2E verification report
136
+ Schema (openspec/schemas/playwright-e2e/)
137
+ └── Templates: test-plan.md, report.md, playwright.config.ts
138
+
139
+ CLI (openspec-pw)
140
+ ├── init → Installs commands for detected editors
141
+ ├── update → Syncs commands + schema from npm
142
+ └── doctor → Checks prerequisites
143
+
144
+ Skill/Commands (per editor)
145
+ ├── Claude Code /openspec-e2e (skill) + /opsx:e2e (command) + MCP
146
+ ├── Cursor → /opsx-e2e (command)
147
+ ├── Windsurf → /opsx-e2e (workflow)
148
+ ├── Cline → /opsx-e2e (workflow)
149
+ └── Continue → /opsx-e2e (prompt)
150
+
151
+ Healer Agent (Claude Code + MCP only)
152
+ └── browser_snapshot, browser_navigate, browser_run_code, etc.
129
153
  ```
130
154
 
131
155
  ## License
package/README.zh-CN.md CHANGED
@@ -18,27 +18,41 @@ openspec init # 初始化 OpenSpec
18
18
  openspec-pw init # 安装 Playwright E2E 集成
19
19
  ```
20
20
 
21
+ ## 支持的 AI 编码助手
22
+
23
+ 自动检测并安装以下编辑器的命令文件:
24
+
25
+ | 编辑器 | 命令 | 格式 |
26
+ |--------|------|------|
27
+ | Claude Code | `/opsx:e2e` | Skill + 命令 + MCP |
28
+ | Cursor | `/opsx-e2e` | 命令 |
29
+ | Windsurf | `/opsx-e2e` | 工作流 |
30
+ | Cline | `/opsx-e2e` | 工作流 |
31
+ | Continue | `/opsx-e2e` | Prompt |
32
+
33
+ `openspec-pw init` 会检测项目中安装了哪些编辑器并安装对应文件。Claude Code 获得完整体验(skill + 命令 + Playwright MCP)。其他编辑器获得包含完整 E2E 工作流的命令/工作流文件。
34
+
21
35
  ## 使用
22
36
 
23
- ### 在 Claude Code 中
37
+ ### 在 AI 编码助手中
24
38
 
25
39
  ```bash
26
- /opsx:e2e my-feature # 主命令(遵循 OpenSpec 规范)
27
- /openspec-e2e # 来自 skill 的别名
40
+ /opsx:e2e my-feature # Claude Code
41
+ /opsx-e2e my-feature # Cursor, Windsurf, Cline, Continue
28
42
  ```
29
43
 
30
44
  ### CLI 命令
31
45
 
32
46
  ```bash
33
47
  openspec-pw init # 初始化集成(一次性设置)
34
- openspec-pw update # 更新 CLI 和 skill 到最新版本
48
+ openspec-pw update # 更新 CLI 和命令到最新版本
35
49
  openspec-pw doctor # 检查前置条件
36
50
  ```
37
51
 
38
52
  ## 工作原理
39
53
 
40
54
  ```
41
- /openspec-e2e <change-name>
55
+ /opsx:e2e <change-name>
42
56
 
43
57
  ├── 1. 从 openspec/changes/<name>/specs/ 读取 OpenSpec specs
44
58
 
@@ -46,7 +60,7 @@ openspec-pw doctor # 检查前置条件
46
60
 
47
61
  ├── 3. Generator Agent → 创建 tests/playwright/<name>.spec.ts
48
62
 
49
- └── 4. Healer Agent → 运行测试 + 自动修复失败
63
+ └── 4. Healer Agent → 运行测试 + 自动修复失败(Claude Code + MCP)
50
64
 
51
65
  └── 报告: openspec/reports/playwright-e2e-<name>.md
52
66
  ```
@@ -62,13 +76,16 @@ openspec-pw doctor # 检查前置条件
62
76
 
63
77
  1. **Node.js >= 20**
64
78
  2. **OpenSpec** 已初始化: `npm install -g @fission-ai/openspec && openspec init`
65
- 3. **Claude Code** 已配置 Playwright MCP
79
+ 3. **任一**: Claude Code、Cursor、Windsurf、Cline Continue(自动检测)
80
+ 4. **仅 Claude Code**: Playwright MCP — `claude mcp add playwright npx @playwright/mcp@latest`
66
81
 
67
82
  ## `openspec-pw init` 做了什么
68
83
 
69
- 1. 通过 `claude mcp add` 全局安装 Playwright MCP
70
- 2. 安装 `/opsx:e2e` 命令和 `/openspec-e2e` skill
71
- 3. 生成 `tests/playwright/seed.spec.ts`、`auth.setup.ts`、`credentials.yaml`
84
+ 1. 检测已安装的 AI 编码助手(Claude Code、Cursor、Windsurf、Cline、Continue)
85
+ 2. 为每个检测到的编辑器安装 E2E 命令/工作流文件
86
+ 3. Claude Code 安装 `/openspec-e2e` skill
87
+ 4. 为 Claude Code 全局安装 Playwright MCP(通过 `claude mcp add`)
88
+ 5. 生成 `tests/playwright/seed.spec.ts`、`auth.setup.ts`、`credentials.yaml`
72
89
 
73
90
  > **注意**:运行 `openspec-pw init` 后,手动安装 Playwright 浏览器:`npx playwright install --with-deps`
74
91
 
@@ -109,9 +126,9 @@ npx playwright test --project=setup
109
126
  - 配置测试用户凭证
110
127
  - 为角色测试添加多用户
111
128
 
112
- ### MCP 服务器
129
+ ### MCP 服务器(仅 Claude Code)
113
130
 
114
- Playwright MCP 通过 `claude mcp add` 全局安装。设置后需重启 Claude Code 生效。
131
+ Playwright MCP 通过 `claude mcp add` 全局安装,启用 Healer Agent(通过 UI 检查自动修复测试失败)。设置后需重启 Claude Code 生效。
115
132
 
116
133
  ## 许可
117
134
 
@@ -0,0 +1,33 @@
1
+ /** Shared YAML escape — matches OpenSpec's escape logic */
2
+ export declare function escapeYamlValue(value: string): string;
3
+ /** Format tags as YAML inline array (escaped) */
4
+ export declare function formatTagsArray(tags: string[]): string;
5
+ /** Command metadata shared across editors */
6
+ export interface CommandMeta {
7
+ id: string;
8
+ name: string;
9
+ description: string;
10
+ category: string;
11
+ tags: string[];
12
+ body: string;
13
+ }
14
+ /** Editor adapter — Strategy Pattern */
15
+ export interface EditorAdapter {
16
+ toolId: string;
17
+ hasSkill: boolean;
18
+ getCommandPath(commandId: string): string;
19
+ formatCommand(meta: CommandMeta): string;
20
+ }
21
+ /** Claude Code: .claude/commands/opsx/<id>.md + SKILL.md */
22
+ declare const claudeAdapter: EditorAdapter;
23
+ /** Detect which editors are installed by checking their config directories */
24
+ export declare function detectEditors(projectRoot: string): EditorAdapter[];
25
+ /** Detect Codex by checking if CODEX_HOME or ~/.codex exists */
26
+ export declare function detectCodex(): EditorAdapter | null;
27
+ /** Build the shared command metadata */
28
+ export declare function buildCommandMeta(body: string): CommandMeta;
29
+ /** Install command files for all detected editors */
30
+ export declare function installForAllEditors(body: string, adapters: EditorAdapter[], projectRoot: string): void;
31
+ /** Install SKILL.md only for Claude Code */
32
+ export declare function installSkill(projectRoot: string, skillContent: string): void;
33
+ export { claudeAdapter };