Skip to content

test(e2e): add Account CRUD, Admin settings, Dashboard login E2E coverage (partial #376) - #760

Merged
SsuJojo merged 3 commits into
devfrom
pr376-e2e-coverage
Aug 30, 2026
Merged

test(e2e): add Account CRUD, Admin settings, Dashboard login E2E coverage (partial #376)#760
SsuJojo merged 3 commits into
devfrom
pr376-e2e-coverage

Conversation

@SsuJojo

@SsuJojo SsuJojo commented Aug 30, 2026

Copy link
Copy Markdown
Collaborator

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-warnings
  • tests/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 的差异

  • 适配当前 dev 架构:errorHandler 由中间件改为 onError 挂载
  • admin 401 鉴权已从路由内迁至全局 dashboardAuth 中间件,测试改为挂载该中间件并用非 localhost 地址触发拦截,保留原鉴权断言

Test Plan

  • 3 个新文件 47/47 通过(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)

icebear0828 and others added 2 commits August 30, 2026 21:22
…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 SsuJojo left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 校验分支

可选建议

  1. vi.mock("@src/config.js") / vi.mock("@hono/node-server/conninfo") 的 factory 直接引用模块顶层 const mockConfig / mockConnInfo(声明在 vi.mock 之后)。当前 CI 能通过(factory 惰性求值),但这是 vi.mock 提升的经典踩坑点,一旦求值时机变化就可能触发 TDZ ReferenceError。更稳妥的做法是用 vi.hoisted 声明可变配置。
  2. 这些用例在进程内挂载路由 + middleware,虽与仓库现有 e2e 风格一致,但对真实 server.ts 的装配(如全局 app.use("*", dashboardAuth))没有端到端验证。若想更贴近真实管线,可在 index.ts 上追加一次冒烟断言。

其余无阻塞项,package-boundary / backend-tests / frontend-tests 均通过,可以合并。

@SsuJojo
SsuJojo merged commit 7c9af74 into dev Aug 30, 2026
3 checks passed
@SsuJojo
SsuJojo deleted the pr376-e2e-coverage branch August 30, 2026 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: E2E coverage gaps — OAuth, Account CRUD, Admin settings

2 participants