波次0-P1 后端卫生:token 契约对真 + core-api 拆分 + 身份行接通(#81) - #85
Merged
Conversation
- routes/auth.ts:OIDC 登录域(login/callback/logout/test-connection) - routes/setup.ts:setup 域(setup-token/status/activate) - routes/modules.ts:模块域(token 签发/注册表/启停/jwks) - middleware/admin.ts:requireAdmin 提为可挂载 Hono 中间件(路径级一挂一域) - services/users.ts:users 表域(JIT 建档/展示名/升管理员) - services/instance-config.ts:instance_config 表域(OIDC 配置/setup_done) - services/audit.ts:audit_log 表域 - setup.ts 瘦身为 setup_tokens 表域;MODULE_TOKEN_ISSUER 归 token.ts; getSigningRuntime 归 keys.ts(index 再导出保持外部 import 兼容) - index.ts 只留 Bindings/组装/request-id/health/me;组合根仍导出完整 app, 现有 app.request 集成测试零改动全通过 Signed-off-by: HandyWote <huangyinghui01@corp.netease.com>
- contracts token.ts:注释改为实现语义(aud=模块 id、sub=核心用户 uid、 act 从未签发,保留契约字段);新增 name?: string(会话展示名); contracts.test.ts fixture 同步(原 sub:'mod-a'/aud:'core-api' 语义颠倒) - core-api 签发侧带 session.name → hello 页身份行零改动即得真名 (模块侧 claims.name ?? claims.sub) - /api/me 响应加 role(真值来自 users 表服务端会话) - RegistryEntry 删 registeredAt 幻影字段(DB 无此列恒返 ''); apps/shell RegistryModule 类型本无该字段,无需改动 - consumeSetupToken 原子化:单条 UPDATE ... WHERE used_at IS NULL + meta.changes 判定;新增并发双激活仅一次成功测试 - 删 /api/admin/bootstrap-keygen(deploy 自有 keypair.ts,全仓零调用方) - 新增跨包契约链测试:core-api 签发 → ModuleTokenClaimsSchema.parse → module-sdk verifyModuleToken(devDep 加 @unself/module-sdk) Signed-off-by: HandyWote <huangyinghui01@corp.netease.com>
This was referenced Sep 9, 2026
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.
波次0-P1 后端卫生(issue #81)
只清理不新增功能。按「纯重构 / 行为修复」拆两个 commit,评审可分段核对。
改动
commit 1(纯重构)
refactor(core-api): index.ts 按职责域拆分routes/{auth,setup,modules}.ts+middleware/admin.ts(requireAdmin 提为可挂载 Hono 中间件,路径级一挂一域)+services/{users,instance-config,audit}.tssetup.ts瘦身为 setup_tokens 表域;MODULE_TOKEN_ISSUER归 token.ts;getSigningRuntime归 keys.ts(index 再导出,外部 import 保持兼容)index.ts只留 Bindings/组装/request-id/health/me;组合根仍导出完整 appcommit 2(行为修复)
fix(core-api): token 契约对真 + 身份行 name + /api/me role + 死账清理token.ts注释改实现语义(aud=模块 id、sub=核心用户 uid、act 从未签发);contracts.test.ts fixture 同步(原 fixture sub:'mod-a'/aud:'core-api' 语义颠倒)ModuleTokenClaimsSchema.parse→ module-sdkverifyModuleToken一条测试(core-api devDep +@unself/module-sdk)name?: string;签发侧带会话展示名(session.name)→ hello 页claims.name ?? claims.sub零改动即得真名/api/admin/bootstrap-keygen(deploy 自有 keypair.ts,全仓零调用方)/api/me加role(真值来自 users 表);RegistryEntry删 registeredAt 幻影字段(DB 无此列恒返'')——apps/shellRegistryModule类型本无该字段,无需改动consumeSetupToken原子化:单条UPDATE ... WHERE used_at IS NULL+meta.changes判定;新增并发双激活仅一次成功测试验收对照表
services/core-api/test/cross-package-token.test.ts(签发→schema→verifyModuleToken 全链)setup.test.ts「并发双激活同一 token:仅一次成功」,真库断言仅一条 setup_activated测试说明
/.well-known/jwks.json响应体)走 module-sdk 本地验签路径遗留友好提示(不改 docs)
services/core-api/src/setup.ts仍位于 src 根(setup_tokens 域,本次未挪动);后续可考虑与 services/ 目录对齐