Skip to content

修复第 3 轮(正确性):按审查报告修复前后端正确性与可靠性问题 - #122

Merged
todosdev[bot] merged 4 commits into
mainfrom
tds/conv-01a14a57-8285-752b-9b19-c908804463be
Oct 17, 2026
Merged

todosdev[bot] merged 4 commits into
mainfrom
tds/conv-01a14a57-8285-752b-9b19-c908804463be

Conversation

@todosdev

@todosdev todosdev Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • 修复 docs/review/REVIEW.md(分支 tds/conv-01a149a5-…)中第 3 轮的正确性和可靠性问题:BE-C1、BE-C3、FE-C1C4、FE-R1R3。
  • BE-R1(SMTP/Resend 超时)在第 1 轮已经做完:smtp.ts 每次读写都有 10s 超时,Resend 请求用了 AbortSignal.timeout(10_000)。本轮没有改它。
  • 没有改 schema;.github/** 也只有从 main 合并进来的改动,本分支自己没有动。

Changes

Worker

  • 新增 lib/params.ts,提供 parseIntParam 和 parsePagination。缺失或非数字的值回退到默认值,并限定取值范围,page 最大 100 万。links、admin 的 users/links,以及 analytics 的 days 都改用这两个函数(BE-C1)。
  • lib/db.ts 新增 isUniqueConstraintError。注册(两条 INSERT 路径)和管理员创建用户时,遇到唯一约束冲突返回 409,不再报 500(BE-C3)。
  • /auth/refresh 只有在 token 无效时才返回 401 并清除 cookie;KV/D1 故障改为返回 503 并保留 cookie。旧 token 改为在所有读取都成功之后才拉黑(FE-R1)。
  • package.json 加上 "type": "module" 和 test 脚本(node --test,不新增依赖)。新增 test/params.test.ts 和 test/db.test.ts。

Web

  • api/client.ts:refresh 的结果分为 ok、expired、transient 三种,只有 expired 才结束会话(FE-R1)。会话过期在每个会话里只处理一次,由 AuthProvider 在应用内处理,不再整页跳转(FE-R2)。
  • AuthContext:
    • 恢复会话时如果遇到临时故障,会记下 restoreFailed,联网后自动重试。
    • 新增会话过期处理函数。
    • 没有登录用户时清空 react-query 缓存。
  • App.tsx:会话恢复失败时,路由守卫显示"重试"页面,不再跳到 /login。
  • AppConfigContext:新增 isLoading 和 loadFailed。注册页会等配置加载完成再决定去向;注册页和登录页在加载失败时显示错误并提供重试(FE-R3)。
  • LinksPage:
    • 创建链接时,只发送当前所选过期选项对应的字段(FE-C1)。
    • datetime-local 改为按本地时区格式化和解析;编辑时只有改过过期时间才发送 expiresAt(FE-C2)。
  • TwoFactorPage:去掉渲染期间调用的 navigate,改用 <Navigate>;验证成功后先跳转,再清除 pending 状态(FE-C3)。
  • RegisterPage:verify-email 的响应带 access token 才进入 dashboard;返回 2FA 时转到二次验证页;其他情况提示后回到登录页(FE-C4)。
  • 新增的文案已补齐中英文。

Root

  • 新增 pnpm test(turbo run test),turbo.json 加 test 任务,CLAUDE.md 补了说明。CI 目前还没有运行这些单测,接入留到后续轮次。

Testing

  • 本地按 CI 的步骤全部跑过且通过:pnpm install --frozen-lockfile、pnpm check、typecheck、build、shellcheck .github/scripts/*.sh、两个部署脚本测试(17/17)、worker 单测(5/5)、pnpm audit --prod --audit-level=high(No known vulnerabilities found)。合并最新 main 之后又跑了 install、typecheck 和单测,也都通过。
  • 加上 "type": "module" 之后,d1-migrations.mjs SL 的输出和加之前逐字节一致;wrangler deploy --dry-run 打包正常。
  • 本地用 wrangler dev 冒烟测试:
    • 非法的 page/limit/days 参数返回 200。
    • 关掉 SELECT 查重之后,重复注册返回 409(走的是唯一约束兜底那条路径)。
    • /auth/refresh 的有效、复用、伪造、缺失四种 token 分别返回 200、401、401、401。
  • refresh 遇到 KV/D1 故障时返回 503 这条路径本地没有实际触发过,只是读代码确认的。前端改动只做了类型检查和构建,没有在浏览器里测过。

Todos and others added 4 commits October 17, 2026 23:09
- BE-C1: shared parseIntParam/parsePagination helpers guard page, limit
  and days against NaN in links, admin and analytics routes
- BE-C3: map D1 UNIQUE violations to 409 in register and admin create user
- FE-C1/C2: drop stale expiry fields from the create payload and use
  local time for datetime-local; edit only sends expiresAt when changed
- FE-C3/C4: replace render-time navigate in TwoFactorPage; only treat
  verify-email as signed in when an access token is returned
- FE-R1/R2: keep the session on transient refresh failures, handle
  expiry once in-SPA and clear the query cache when signed out
- FE-R3: expose AppConfig isLoading/loadFailed; register and login
  pages wait for config and surface load errors
- add node --test worker unit tests and a pnpm test script

Co-Authored-By: Claude Code <noreply@anthropic.com>

Checkpoint: dedJ4t0xV3KkeaGQPpASD
- /auth/refresh returns 401 (and clears the cookie) only for invalid
  tokens; KV/D1 errors now return 503 and rotation runs after all reads
- session restore keeps the transient outcome: guards show a retry
  screen instead of redirecting to /login, and retry when back online

Co-Authored-By: Claude Code <noreply@anthropic.com>

Checkpoint: xnld6jmMrKwfyDfiv40E_
@todosdev
todosdev Bot merged commit 616994d into main Oct 17, 2026
@mapxn
mapxn deleted the tds/conv-01a14a57-8285-752b-9b19-c908804463be branch October 18, 2026 08:56
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.

1 participant