feat(runtime)!: 退役 ctx.user 的 roles 别名,positions 成为唯一拼法 (#6011) - #6048
Draft
qq9340100 wants to merge 1 commit into
Draft
feat(runtime)!: 退役 ctx.user 的 roles 别名,positions 成为唯一拼法 (#6011)#6048qq9340100 wants to merge 1 commit into
qq9340100 wants to merge 1 commit into
Conversation
ActorUser 同时声明并发出 `positions` 与 `roles`,两者由同一次赋值产生、值 逐字相同。`roles` 是 ADR-0090 D3 保留并禁用的词,且从未有关闭日期 —— 与 #5613 给 ctx.session 装上迁移窗口的同族面相比,这一面既无 spec 契约、也无 ADR-0087 台账条目、也无移除路径。维护者 2026-08-06 就地裁决:立即退役, 不设弃用窗口、不双发。 消费方核实(删除的前置条件,因为旧注释声称该别名 "kept for the REST/AI shapes"):全仓 + objectui 扫描未见任何活体读取 `ActorUser.roles` 的代码。 四个生产点(action-execution / dispatcher-plugin / domains.actions / domains.ai)构造的都是服务端 body / 路由处理器信封,不进入任何响应体; objectui 的 `.roles` 读取全部落在 better-auth 会话与 `/api/v1/auth/me/permissions` 两个独立生产者上。 钉子同批翻转而非删除:三处断言改为既断言新语义的实质(`positions` 逐字 承载),又钉住方向(`roles` 键不存在)。反向验证已做:恢复被删的构造分支 后 7 条断言转红,方向与预期一致。 ⛔ 不含 ctx.session:该面按 #5613 保留其弃用窗口,双发不动。 ⛔ 不含 packages/spec:ADR-0087 台账条目另行落地。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Wbxm29qPKnLf44AbSxizqW
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Contributor
📓 Docs Drift CheckThis PR changes 1 package(s): 21 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:
|
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.
Fixes #6011
按维护者 2026-08-06 14:49Z 的就地裁决执行:方向 2「直接退役」—— 立即删除
ctx.user上的roles别名,不设弃用窗口、不双发。改了什么
ActorUser(action body 的ctx.user/ AI 路由处理器的req.user)此前同时声明并发出两个键,值由同一次赋值产生、逐字相同:packages/runtime/src/security/actor-user.ts的roles: string[]buildActorUser()里的roles: core.positions两处一并删除,
positions成为该面唯一的位置拼法。原注释声称该别名 "kept for the REST/AI shapes" —— 这一说法在删除前被核实并证伪(见下)。消费方核实(删除的硬前置)
一律以
origin/main(>=739f496,即 #5991 合并后)为准做git grep,不读工作树;零命中结果都用已知存在的邻近词positions做了反证,确认 grep 本身有效。user.roles/req.user.roles(所有文件类型)ActorUser的四个生产点action-execution.ts/dispatcher-plugin.ts/domains/actions.ts/domains/ai.ts—— 构造的都是服务端 body / 路由处理器信封,不进入任何 HTTP 响应体.rolesexamples/(showcase / CRM 的 action body)objectui(/home/user/objectui,origin/main).roles命中全部落在另外两个独立生产者上:better-auth 会话的user.roles/user.role(AuthGuard/useIsWorkspaceAdmin),以及/api/v1/auth/me/permissions响应体(由plugin-hono-server/src/current-user-endpoints.ts自行构造)。没有一处消费ActorUserctx.user.roles;唯一相关的一处 (content/docs/permissions/permission-metadata.mdx:201) 恰恰在申明「不存在current_user.roles」cloud仓在本会话不可达,因此它是未经核实的消费面。changeset 里的迁移处方(roles→positions,值不变)即为该面的处置说明。钉子:翻转而非删除
三个文件里的断言都同批翻转并继续承载,既断言新语义的实质,又钉住方向:
action-ctx-user-shape.test.ts—— 原「aliases stay in lockstep」整条替换(它钉的正是被删的那条肢,留着会因「什么都没产生」而空绿):现在断言positions逐字承载调用者位置,且'roles' in ctx.user === false。http-dispatcher.test.ts—— 两处user.roles断言改为其反面(键不存在),而非删掉。ai-request-user-capability-channel.test.ts——user.roles改读user.positions(该用例的实质是「位置是与两条权限通道互不合并的第三条通道」,实质保留),并补键不存在断言。断言用
'roles' in user而不是toBeUndefined():后者无法区分「键已删除」与「键还在、值为空」的半吊子退役。反向验证(方向预先判定为「红」,结果一致):把删掉的
roles: core.positions恢复回去后,7 条断言转红 —— 2 条键集断言(8 键 vs 7 键)、1 条 value-for-valuetoEqual、4 条expected true to be false(新的键不存在钉子)。恢复后即刻回退。⛔ 范围外(已刻意不动)
packages/spec零字节。ADR-0087 语义迁移台账条目(spec 半边)按 issue 上 14:59Z / 15:10Z 两条分诊评论的待定拆分决定,另行单独落地,不在本 PR。ctx.session不动。那是 [runtime] action body 的ctx.session仍在生产roles(值是ec.positions)—— 自称「mirroring hook ctx.session」,而 hook 侧该键已按 ADR-0049 退役 #5613 的弃用窗口,buildActionSession的双发(positions+roles)与action-session-shape-contract.test.ts原样保留。两个面同名不同物:ctx.session 保留窗口,ctx.user 立即关闭。content/docs/releases/未触碰。测试证据
关于待定的 spec 半边(回答派发时的必答问题)
本改动使 spec 半边的 ADR-0087 台账条目更简单,并不使其变得不必要。
理由:台账条目要记录的「FROM → TO」事实已经在本 PR 里被确定并固定了 —— 退役已发生、迁移映射是纯改键(值不变)、消费面已扫清且证据在案、
positions唯一拼法已有钉子守住。因此 spec 座位写条目时不必再自行判定退役范围或复核消费方,只需把既成事实登记入册。它仍然必要:没有条目,这次退役在台账上不可见,与同族 session 侧已有的三条(data.hookContext.session.roles、ui.actionSession.roles、CEL/formula: current_user.roles)不对称,而这种不对称正是本 issue 立单的原因。需要提醒 spec 座位的一点:
ctx.user面至今没有 spec schema,只有 runtime 的 TS interface —— 所以该条目登记的是一个 spec 从未声明过的键的退役,这与 session 侧「schema 里有声明可改」的情形不同,条目的surface写法需要相应处理。🤖 Generated with Claude Code
https://claude.ai/code/session_01Wbxm29qPKnLf44AbSxizqW
Generated by Claude Code