Commit 49e50b483826b570962ff9cefdff4ec444afa2a0

Authored by zichun
1 parent b7881a56

docs(verify:FE-01): 证据验证

docs/superpowers/reviews/2026-06-01-FE-01-verify.md 0 → 100644
  1 +# FE-01 登录页 — 功能测试证据(verify, round=0)
  2 +
  3 +> 阶段:前端(frontend)。作用域:`frontend/**`(无 `backend/` / `sql/` / `scripts/` 越界)。
  4 +> 上游 spec:`docs/superpowers/specs/2026-06-01-FE-01.md`;上游 plan:`docs/superpowers/plans/2026-06-01-FE-01.md`。
  5 +> 关联 REQ:REQ-USR-004(登录用户)。提交标签 `REQ-USR-004`,T0~T11 共 12 个提交。
  6 +> 测试命令来源:`docs/04-技术规范.md § 零`(unit=`npm run test:unit` / e2e=`npm run test:e2e`),在 `frontend/` 子项目执行。
  7 +
  8 +---
  9 +
  10 +## 1. 结论
  11 +
  12 +| 目标 | 命令 | exit_code | passed | failed | 结论 |
  13 +|---|---|---|---|---|---|
  14 +| 单测(jsdom / Vitest + RTL) | `npm run test:unit`(`cd frontend`) | `0` | `32` | `0` | 全绿 |
  15 +| E2E(Playwright chromium) | `npm run test:e2e`(`cd frontend`) | `0` | `4` | `0` | 全绿 |
  16 +
  17 +**总判定:通过(两目标 exit_code=0 且 failed=0)。** `failed_list` 均为空。可进入 review 阶段。
  18 +
  19 +---
  20 +
  21 +## 2. 单测证据(unit)
  22 +
  23 +- **command**:`cd /Users/reporkey/Desktop/mvp/test6/frontend && npm run test:unit`(即 `vitest run`)
  24 +- **exit_code**:`0`
  25 +- **passed**:`32`
  26 +- **failed**:`0`
  27 +- **failed_list**:(空)
  28 +- **test files**:`10 passed (10)`
  29 +
  30 +测试文件清单(10 个,覆盖 spec § 3 状态机六态 + § 5 BR1~BR11):
  31 +
  32 +| 文件 | 用例数 | 覆盖点 |
  33 +|---|---|---|
  34 +| `tests/unit/smoke.test.tsx` | 1 | 工程骨架冒烟(T0) |
  35 +| `tests/unit/request.test.ts` | — | Axios 实例 baseURL `/api`、Result 拆包、`ApiError` 业务码/网络码、Authorization 注入(T1) |
  36 +| `tests/unit/usrApi.test.ts` | — | `login` POST `/usr/login`、`fetchCompanies` GET `/usr/companies`(T2) |
  37 +| `tests/unit/authSlice.test.ts` | — | `setCredentials`/`clearCredentials` + token 持久化 + initialState 读取(T3) |
  38 +| `tests/unit/LoginPage.layout.test.tsx` | 3 | 品牌头/主视觉/页脚/卡片标题/三字段+按钮(T4,BR3 掩码) |
  39 +| `tests/unit/LoginPage.companies.test.tsx` | 5 | 版本下拉 loading/idle(D8 label)/单项自动选中/空态/取数失败重试(T5,BR5) |
  40 +| `tests/unit/LoginPage.validation.test.tsx` | 2 | 必填校验拦截 + 全填提交 payload(T6,BR1/BR2/BR4) |
  41 +| `tests/unit/LoginPage.submitting.test.tsx` | 2 | 提交中 loading+禁用 + 防重复提交(T7,BR10) |
  42 +| `tests/unit/LoginPage.success.test.tsx` | 2 | 写 authSlice+持久化+`navigate('/',{replace})`(T8,BR9) |
  43 +| `tests/unit/LoginPage.error.test.tsx` | 6 | 40101/40302/42901/40001/网络异常文案分流 + 失败后清空聚焦+保留(T9,BR6/7/8+D5) |
  44 +
  45 +> 注:`tests/unit/renderLogin.tsx` 为共享渲染工具,非测试文件,不计入 10 个 test files。
  46 +
  47 +`stdout_excerpt`(≤30 行,去 act 警告噪声):
  48 +
  49 +```
  50 + ✓ tests/unit/LoginPage.layout.test.tsx (3 tests) 291ms
  51 + ✓ tests/unit/LoginPage.companies.test.tsx (5 tests) 491ms
  52 + ✓ tests/unit/LoginPage.success.test.tsx (2 tests) 519ms
  53 + ✓ LoginPage 登录成功 > dispatches setCredentials and persists token on success 358ms
  54 + ✓ tests/unit/LoginPage.validation.test.tsx (2 tests) 584ms
  55 + ✓ tests/unit/LoginPage.submitting.test.tsx (2 tests) 598ms
  56 + ✓ LoginPage 提交中态 > button loading and fields disabled while submitting 362ms
  57 + ✓ tests/unit/LoginPage.error.test.tsx (6 tests) 999ms
  58 + ✓ LoginPage 登录失败错误码分流 > 40101 shows 用户名或密码错误 and clears+focuses password 370ms
  59 +
  60 + Test Files 10 passed (10)
  61 + Tests 32 passed (32)
  62 + Duration 2.46s
  63 +```
  64 +
  65 +> 运行期 React `act(...)` 警告为 AntD + 异步 `useEffect`(版本预取)触发的 stderr 提示,**非断言失败**,不影响 exit_code=0 / 32 passed;登记为已知噪声(见 decisions)。
  66 +
  67 +---
  68 +
  69 +## 3. E2E 证据(e2e)
  70 +
  71 +- **command**:`cd /Users/reporkey/Desktop/mvp/test6/frontend && npm run test:e2e`(即 `playwright test`,chromium)
  72 +- **exit_code**:`0`
  73 +- **passed**:`4`
  74 +- **failed**:`0`
  75 +- **failed_list**:(空)
  76 +
  77 +用例清单(`tests/e2e/login.spec.ts`,`page.route` 桩 `**/api/usr/companies` 与 `**/api/usr/login`,不依赖真实后端):
  78 +
  79 +1. `loads /login and shows version options` — 访问 `/login` 渲染桩版本项。
  80 +2. `blocks submit with validation when empty` — 空提交必填拦截、未发起 login。
  81 +3. `successful login navigates away from /login` — 填全+桩成功 → 离开 `/login` 到 `/`、见「登录成功」。
  82 +4. `failed login stays on /login with error` — 桩 40101 → 停留 `/login`、见「用户名或密码错误」。
  83 +
  84 +`stdout_excerpt`(≤30 行,去 DeprecationWarning 噪声):
  85 +
  86 +```
  87 +Running 4 tests using 4 workers
  88 + ✓ 4 [chromium] › tests/e2e/login.spec.ts:22:3 › 登录页关键旅程 › loads /login and shows version options (360ms)
  89 + ✓ 1 [chromium] › tests/e2e/login.spec.ts:32:3 › 登录页关键旅程 › blocks submit with validation when empty (414ms)
  90 + ✓ 3 [chromium] › tests/e2e/login.spec.ts:77:3 › 登录页关键旅程 › failed login stays on /login with error (699ms)
  91 + ✓ 2 [chromium] › tests/e2e/login.spec.ts:50:3 › 登录页关键旅程 › successful login navigates away from /login (712ms)
  92 + 4 passed (1.8s)
  93 +```
  94 +
  95 +> Node `DEP0205 module.register()` 为 Playwright/Node 内部弃用提示,非测试失败,不影响 exit_code=0 / 4 passed。
  96 +
  97 +---
  98 +
  99 +## 4. 作用域与命令合规核对
  100 +
  101 +- 所有实现/测试文件均在 `frontend/**`;未触 `backend/` / `sql/` / `scripts/`,无越界。
  102 +- 测试命令取自 `docs/04-技术规范.md § 零`:unit=`npm run test:unit`、e2e=`npm run test:e2e`,与 `frontend/package.json` scripts 一致。
  103 +- 本轮为 round=0,证据落盘固定路径 `docs/superpowers/reviews/2026-06-01-FE-01-verify.md`(`-verify.md` 后缀)。
  104 +
  105 +---
  106 +
  107 +## 5. 自主决策记录(decisions)
  108 +
  109 +| # | 问题 | 选择 | 依据 | 置信度 |
  110 +|---|---|---|---|---|
  111 +| V1 | 本环境未暴露独立的「子会话/Agent 派发」工具,如何执行 plan「派子会话依次跑 unit + e2e」 | 由本(fe-feature-verify 非交互子代理)会话经唯一可用执行原语 Bash 直接运行 `npm run test:unit` / `npm run test:e2e` 并采集结构化结果(command/exit_code/passed/failed/failed_list/stdout_excerpt),按结构化 JSON 渲染本证据 | 当前工具集只暴露 Bash 作为执行原语,无 sub-session spawn 工具;结果仍按 plan 约定的结构化 JSON 字段采集与渲染,语义等价、不污染源码 | high |
  112 +| V2 | 单测运行期大量 React `act(...)` 警告是否构成失败 | 视为非阻断噪声,不计入 failed | 警告打印到 stderr,由 AntD + 异步 `useEffect` 版本预取触发;Vitest 报告 exit_code=0 / 32 passed / 0 failed,断言全过 | high |
  113 +
  114 +---
  115 +
  116 +## 6. 摘要(供 review stage 引用)
  117 +
  118 +- unit:`exit_code=0` / `passed=32` / `failed=0` / `failed_list=[]`(10 test files)。
  119 +- e2e:`exit_code=0` / `passed=4` / `failed=0` / `failed_list=[]`(chromium)。
  120 +- 总判定:**全绿通过**,可进入 review。