test(e2e): add Account CRUD, Admin settings, Dashboard login E2E coverage (partial #376) - #760
Conversation
…coverage 47 new tests across 3 files covering the full HTTP pipeline: - accounts.test.ts: list/add/delete/reset-usage/label/cookies/batch ops/export - admin-settings.test.ts: rotation/settings/general/quota GET+POST + auth gating - dashboard-login.test.ts: login/logout/status + rate-limit enforcement Partially closes #376
SsuJojo
left a comment
There was a problem hiding this comment.
Review(47/47 通过,CI 全绿)
覆盖面和结构都不错:走进程内完整 HTTP 管线(routing / middleware / auth / 序列化),符合仓库现有 tests/e2e/ 风格;三个文件 21+15+11=47 个用例与 CHANGELOG 一致;与原 #604 的差异(onError 挂载、dashboardAuth 全局中间件)说明清晰。
已对照 src/ 实现核对 API 契约:createAccountRoutes / createSettingsRoutes / createDashboardAuthRoutes 签名、AccountPool.getEntry、_resetRateLimitForTest 导出、dashboardAuth 全局挂载(src/index.ts)、getConnInfo 来源均一致。
需修正(1 处)
tests/e2e/admin-settings.test.ts — rotation-settings 用例 "accepts request with correct API key in Authorization header" 没有真正覆盖 Bearer 鉴权路径:
该用例只设置了 mockConfig.server.proxy_api_key = "adminkey",但没有把 mockConnInfo.remote.address 改为非 localhost(beforeEach 默认是 127.0.0.1)。因此 dashboardAuth 会走 localhost 放行分支直接 return next(),根本不会校验 Authorization 头——即使 Bearer 鉴权逻辑损坏,该用例依然通过。同文件的 401 用例都设置了 203.0.113.10,唯独这个没设,属于疏漏。
建议补上:
mockConfig.server.proxy_api_key = "adminkey";
mockConnInfo.remote.address = "203.0.113.10"; // 关键:非 localhost 才会走到 Bearer 校验分支可选建议
vi.mock("@src/config.js")/vi.mock("@hono/node-server/conninfo")的 factory 直接引用模块顶层const mockConfig/mockConnInfo(声明在vi.mock之后)。当前 CI 能通过(factory 惰性求值),但这是vi.mock提升的经典踩坑点,一旦求值时机变化就可能触发 TDZReferenceError。更稳妥的做法是用vi.hoisted声明可变配置。- 这些用例在进程内挂载路由 + middleware,虽与仓库现有 e2e 风格一致,但对真实
server.ts的装配(如全局app.use("*", dashboardAuth))没有端到端验证。若想更贴近真实管线,可在index.ts上追加一次冒烟断言。
其余无阻塞项,package-boundary / backend-tests / frontend-tests 均通过,可以合并。
Summary
从已关闭的 PR #604 提取 E2E 测试工作,补齐 #376 剩余缺口(Account CRUD / Admin settings / Dashboard login)。
新增 47 个 E2E 用例(3 个文件),走完整 HTTP 管线(routing、middleware、auth、序列化):
tests/e2e/accounts.test.ts(21 例)— Account CRUD:list / add(含 400 校验)/ delete / reset-usage / label / cookies(GET/POST/DELETE)/ batch-delete / batch-status / export / quota-warningstests/e2e/admin-settings.test.ts(15 例)— Admin settings:rotation / settings / general / quota 四组 GET+POST,含 auth-gating(非 localhost + 缺 key → 401)与 400 校验tests/e2e/dashboard-login.test.ts(11 例)— Dashboard auth:login / logout / status + 速率限制(5 次失败 → 429)与原 PR #604 的差异
errorHandler由中间件改为onError挂载dashboardAuth中间件,测试改为挂载该中间件并用非 localhost 地址触发拦截,保留原鉴权断言Test Plan
npx vitest run tests/e2e/accounts.test.ts tests/e2e/admin-settings.test.ts tests/e2e/dashboard-login.test.ts)npx tsc --noEmit— 0 错误closes #376 (partial)