Repository navigation
修复第 4 轮(工程质量·后端/CI):测试基线接入 CI 门禁、schema 单一来源、Low 级后端加固 - #124
Merged
todosdev[bot] merged 3 commits intoOct 18, 2026
Merged
Conversation
- BE-Q2/CI-C1: node:test route tests for auth/links/redirect backed by an in-memory SQLite D1 (node:sqlite) and tsx for .js->.ts resolution; wired `pnpm test` into CI so deploy is gated on it - BE-Q1: generate migrations/*.sql from lib/migrations.ts and assert consistency in a test - BE-Q3: app.onError with structured logging and a per-request id - BE-S9: forgot-password sends email via waitUntil (timing side-channel) - BE-S10: CORS allows localhost origins only on plain-http (dev) - BE-S11: SPA/static responses get security headers plus a Vite-compatible CSP - BE-S12: totp setup becomes POST (route + client.ts call) - BE-C4: delete stale verification codes before inserting new ones - BE-R2: redact Resend failure before logging - CI-C9: tag.yml verifies CI on main, release.yml validates tag source/format, vite dev proxy target configurable via env Checkpoint: ZsFIsGEbQRfT1JpslSW3E
…cs, forgot-password ordering - tag.yml: query the CI workflow via listWorkflowRuns (workflow file + push event) instead of the repo-wide list, so the tag workflow itself is never mistaken for CI - index.ts: only allow localhost CORS origins over http on a loopback host, not merely on http scheme - generate-migrations: strip idempotency markers when rendering .sql so the wrangler migrations keep their fail-if-exists semantics; lib/migrations.ts SQL is unchanged; add an existing-object test - auth.ts: persist the reset code before sending the email and wrap the whole forgot-password background task in a redacted catch Checkpoint: UBfQSDzaq25VhKiTMGKwP
…2-7027-8d17-d72f706f13d0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pnpm test进 CI 后即成为部署门禁。lib/migrations.ts成为 schema 唯一事实来源,migrations/*.sql改由它生成并加一致性测试,保留 wrangler 迁移原本的 fail-if-exists 语义。app.onError)+ 一批 Low 级后端加固与 CI/发版安全校验。Changes
测试基线与 CI 门禁(BE-Q2 / CI-C1)
apps/worker/test/{auth,links,redirect,migrations,email}.test.ts,用 Node 内置node:sqlite建真实内存 SQLite(套用真实 DDL)+ 内存 KV mock,JWT 用真实jose签发/校验;覆盖登录、refresh、token_version 吊销、links 创建/更新/权限、redirect 跳转/过期/停用。apps/worker新增唯一 dev 依赖tsx,解决 Node 类型剥离不重写.js→.ts相对导入的问题。.github/workflows/ci.yml增加pnpm test步骤(Build 之后)。Schema 单一来源(BE-Q1)
getMigrations()迁移对象新增fileName;新增apps/worker/scripts/generate-migrations.ts从getMigrations('')生成migrations/*.sql,渲染时剥掉幂等标记(IF NOT EXISTS/OR IGNORE),保证与原有 wrangler SQL 语义完全一致;lib/migrations.ts的 SQL 未改动。test/migrations.test.ts校验生成内容与磁盘一致、schema_vN ↔ NNNN_*.sql约定、以及「对象已存在即报错」语义。Worker 加固
app.onError输出结构化日志(path/method/error/requestId),客户端只收通用 500;新增 per-requestrequestId中间件。waitUntil且先落库再发信,消除时间侧信道。lib/security.ts)。GET /2fa/totp/setup改 POST,同步改apps/web/src/api/client.ts的totpSetup。CI / 发版安全(CI-C9)
tag.yml:打 tag 前用actions.listWorkflowRuns按 workflow 文件 + push 事件校验 main HEAD 有成功的 CI 运行。release.yml:校验 tag 格式且 tag 解析到 main 上可达的 commit。apps/web/vite.config.ts:dev proxy target 改为API_PROXY_TARGET环境变量可配。Testing
pnpm check(biome)、pnpm typecheck、pnpm build均通过。pnpm test:worker 27 项单测 + web 单测全部通过。shellcheck .github/scripts/*.sh通过;pnpm audit --prod --audit-level=high无已知漏洞。migrations/*.sql为生成产物且已在本次变更中重新生成,内容与生成器一致(无过期产物)。