用途:在独立于前端的 tests-e2e/ Node 包中创建与维护 Cypress E2E 测试。执行阶段实现,规划阶段对应 ns-pm-e2e-test-task-generator。存在 {harness}/rules/e2e-tests-rules.mdc 时先加载。
关键流程:
- 解析或引导 Cypress 根目录。按 {product_root} 顺序探测 tests-e2e/cypress.config.ts、testes-cypress/cypress.config.ts、frontend/cypress.config.ts,记录含 cypress.config.ts 的目录为 {e2e_root}。若均不存在则创建 {product_root}/tests-e2e/ 独立 Node 项目,package.json 置于此处,禁止加入 frontend/package.json,禁止在 frontend/cypress/ 下搭建或复制依赖。cypress.config.ts 的 baseUrl 来自 CYPRESS_BASE_URL,specPattern 为 cypress/e2e/**/*.cy.ts,脚本含 cypress:open、cypress:run。若存在 docs/context/stack-confirmed.md 或 architecture-rules.md,需更新 E2E 行,运行命令为 cd tests-e2e && npm run cypress:run 或项目 Docker 等价命令。
- 先发现:读取被测应用路由、表单、API、已有 data-testid,读取已有 commands 与配置环境变量。
- 命令架构优先:support/commands/ 下分 shared/[feature].commands.ts(业务动作,全设备)、pages/[feature].commands.ts(页面结构)、device/mobile|tablet|desktop.commands.ts(设备专属),并在 support/e2e.ts 注册。spec 中只用 describe/it、cy.visit()、命令与断言,不写 DOM 逻辑。
- spec 布局:cypress/e2e/device/{desktop|tablet|mobile}/[feature]/[feature]-successful-flows.cy.ts;视口分别为 1280×720、768×1024、375×812;禁止 spec 直接放在 cypress/e2e/ 下。
- 实现要求:使用前端任务契约中的 data-testid,禁止自造;禁止固定 cy.wait(N),改用 intercept 或断言超时;覆盖 RBAC(菜单隐藏与直接 URL 拒绝)与认证(UI 或 support session 登录,多租户 fixtures)。
- 运行报告:在 {e2e_root} 执行 npm run cypress:run 或产品 Docker 等价命令;失败时可用 ns-code-investigator 排查。
限制:在 SDD 版本执行(execution-handoff.md / run-implementation)下只编写或重构 spec,不运行 E2E 套件,由人工在版本末运行。合规性、收费等未提供。