fix(example-showcase): my-work 的 admin 卡片改用 ADR-0089 组件级 visibleWhen (#6274) - #6513
Merged
Merged
Conversation
…6274) `page:card` 的可见性谓词原先写在 `properties.visible` 里,靠 objectui SchemaRenderer 把 `properties` hoist 到节点上才生效 —— 是渲染器的巧合, 不是契约。`PageCardProps` 不声明任何可见性键,#5068 的 `component-props-unknown-key` 闸门正是这样报的它。 改为组件节点的兄弟键 `visibleWhen`(ADR-0089 唯一规范拼法),绑定根用 `current_user` —— ADR-0089 为 page 组件谓词声明的身份根(`record` / `current_user` / `page.<var>`)。绑定名是浏览器实测确定的,不是读 ADR 推断: 对 pin 住的 console(objectui 7dfbeb70)以 admin / 非 admin 双身份各看一次 My Work 页。 新增 test/my-work-visibility.test.ts 同时钉住形状与语义:谓词在组件级、 任何 page:card 的 properties 里不再出现可见性键、绑定根是 `current_user`、 以及谓词按页面自己声称的方式门控。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011M7UwH25Unfi73UHim7ajY
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
qq9340100
marked this pull request as ready for review
August 8, 2026 03:12
This was referenced Aug 8, 2026
Merged
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 #6274
做了什么
examples/app-showcase/src/ui/pages/my-work.page.ts里 "Leadership View" 那张page:card,可见性谓词原先写在
properties.visible。properties是控件自己的 prop 包(PageCardProps,ComponentPropsMap),它不声明任何可见性键 —— 那行之所以能生效,只是因为 objectui 的SchemaRenderer在求值前把properties的每个键 hoist 到节点上,是渲染器的巧合而非契约,#5068 的
component-props-unknown-key闸门正是这样报的它。改为 ADR-0089 的规范拼法:组件节点的兄弟键
visibleWhen(不是properties里的键),绑定根
current_user。侧栏共 2 处
page:card:"Shortcuts" 不带任何可见性键(其title/children都是PageCardProps声明的键,闸门不报),无需改写;带谓词的只有 "Leadership View" 这一处。浏览器实测证据(绑定名判定 + 双身份可见性)
分诊把「绑定名」标为 load-bearing:ADR-0089 声明 page 组件谓词绑定
record/current_user/page.,没有user,机械改写疑似会得到恒假谓词。所以先量后写。环境:worktree 内
objectstack dev --ui --seed-admin -p 3862,console 用@objectstack/console@17.0.0-rc.5的 dist —— 其 CHANGELOG 记为 "refreshed to7dfbeb704e1e",正是本仓
.objectui-shapin 的那个 objectui commit,所以量到的就是 main 会 serve 的那份 UI。非 admin 身份由
POST /api/v1/auth/sign-up/email新建(analyst@objectos.ai,roleuser)。探针:临时在同一侧栏加 4 张
page:card,各带一个组件级visibleWhen,双身份各看一次(探针已在提交前删除,不在本 PR 的 diff 里):
visibleWhen1 == 1current_user.email == 'admin@objectos.ai'user.email == 'admin@objectos.ai'nosuchroot.email == 'admin@objectos.ai'properties.visible)服务端下发的 page 元数据确认
visibleWhen过了 parse 并以 CEL 信封到达前端:{"dialect":"cel","source":"current_user.email == 'admin@objectos.ai'"}。结论 1 — 绑定名:
current_user实测可用。选它而不是user,因为 ADR-0089 为这层声明的身份根就是
current_user(user只是 ADR-0068 那组向后兼容别名之一,由 app-shell 的ExpressionProvider一起喂进谓词 scope:current_user/user/ctx.user/os.user)。结论 2 — 分诊那条陷阱假设,实测两半都不成立(照实报,不套模板):
user不在绑定里 ⇒ 机械改写会得到恒假谓词」:不成立。user在这层是活的绑定,机械改写并不会让卡片消失。
nosuchroot.)是 fail-open —— 卡片照常渲染,并在 console 打出一条实名警告:
[object-ui] A conditional predicate failed to evaluate and was treated as its safe default (true): "nosuchroot.email == ..." . Reason: [type] Unknown variable: nosuchroot。所以既不静默、也不消失。
这两点不改变本单的结论(
properties.visible仍是写错了位置的键,仍该改成组件级visibleWhen),只是把「为什么要先量」的那条理由校正掉,免得下一个读者按错误的失败模型去推断。
结论 3 — 改写后双身份复验(最终代码,探针已删除):
admin@objectos.aivisibleWhen措辞)analyst@objectos.ai(非 admin)截图两份(admin / 非 admin)均已目视确认,行为与改写前的
properties.visible基线一致。#5068 闸门(
component-props-unknown-key)os lint对 showcase config,反向验证按预期方向(before 红 / after 绿):⚠ page "showcase_my_work" · page:card: 'visible' is not a prop 'page:card' declaresat
pages[18].regions[2].components[1].properties.visible;总计490 warning(s)。page:card.visible那条消失;总计489 warning(s)。整份 lint 输出 diff 只有那一行的删除,没有任何新增诊断(既没有新的
visibility-root-mislayered,也没有 #6472 新加的visibility-predicate-syntax)。测试
examples/app-showcase/test/my-work-visibility.test.ts,同时钉形状与语义:谓词必须在组件级、任何
page:card的properties里不得再出现可见性键(visible/visibleWhen/visibleOn/visibility/hidden)、绑定根是current_user且不是data.、以及谓词按页面自己声称的方式门控(admin 真 / 非 admin 假)。
pnpm --filter @objectstack/example-showcase typecheck→ 通过。pnpm --filter @objectstack/example-showcase test→ 14 files / 150 tests 全绿。changeset
@objectstack/example-showcase是private: true的示例包,不在.changeset/config.json的 fixed 组里,本 PR 不发布任何包 —— 因此打
skip-changeset,不写 changeset。Generated by Claude Code