Repository navigation
Commit 139bc18
fix(objectql): name a refused state_machine move by its option labels (#28173)
Fixes #28052
Clause-②: no
Metadata-protocol: none
Skills-docs: none — `skills/**` and `content/docs/**` carry no copy of
the built-in `invalid_transition` sentence (grep for
`invalid_transition`, `Invalid transition for` and `不允许从`: four doc
hits, all naming the code or a user hook's own message, none quoting the
built-in wording)
## 维护者速读
- 改了什么:状态机规则拒绝非法状态流转时,内置提示句里的「从哪到哪」改用选项的显示名(按调用者语言翻译),不再用原始选项值。
- 为什么改:用户被拒时看到「Invalid transition for Status: presented →
draft」这种机器值,看不懂哪一步错了;现在读到「Presented → Draft」,中文读到「已提交 → 草稿」。
- 风险与回滚:只改提示文字;`code` 与机器可读的 `constraint: { from, to }` 仍是原始值,作者自写的
message 原样不动;回滚即 revert 本 PR。
- 先看:`packages/objectql/src/validation/rule-validator.ts` 的
`checkStateMachine` 末尾与新函数 `resolveOptionLabel`;再看新测试文件。
- 两分钟验证:`pnpm --filter @objectstack/objectql exec vitest run
src/validation/rule-validator.state-machine-option-labels.test.ts`,预期 6
个用例全绿。
- 需要你做的:无,席位落地。
## What changes
- `checkStateMachine`
(`packages/objectql/src/validation/rule-validator.ts`): on the built-in
path (no authored `message`), the `invalid_transition` template's
`{{from}}` / `{{to}}` are now filled with each state's option label;
`constraint` is still built from, and shipped with, the raw option
values. The authored-message path is untouched and does not even run the
label lookup.
- New `resolveOptionLabel(field, def, value, messages)`: the field's own
option translation (`objects.OBJECT.fields.FIELD.options.VALUE`) → for a
picklist-bound field, the list's (`picklists.NAME.options.VALUE`) → the
option's declared `label` → the raw value. That is the chain
`translateObject` serves a field's options by on `/meta`, asked through
the same `ValidationMessageContext.translate` hook `resolveFieldLabel`
uses (no second i18n path), with the same echo-on-miss test and the same
swallow-a-throwing-service guard.
- `buildFieldError` interpolates its `constraint` over its
`messageParams`, so the built-in path renders with `messageParams: {
...constraint, ...labels }` and no constraint, then attaches the raw
`constraint` itself. The returned key order (`field, code, message,
label, constraint`) is unchanged.
- `ConditionalFieldDef` gains the `picklist` key and
`ConditionalFieldOption` the `label` key it already receives at runtime
(types only).
- `.changeset/28052-state-machine-option-labels.md`:
`@objectstack/objectql` patch.
Not in scope, per triage: `{{from}}` / `{{to}}` holes in an
author-written `message` (new authorable vocabulary, `Clause-②: yes`,
back to triage). `packages/spec` is untouched; the template text is
unchanged.
## Tests
New
`packages/objectql/src/validation/rule-validator.state-machine-option-labels.test.ts`,
six pins:
1. built-in sentence names declared option labels: `Invalid transition
for Status: Presented → Draft`; `constraint` is `{ from: 'presented',
to: 'draft' }`;
2. translated option labels under `zh-CN`: `状态不允许从 已提交 变更为 草稿`;
3. picklist-bound field: the field-level entry wins, the picklist entry
answers for an option the field does not translate;
4. fallback: a missing translation falls to the declared label, an
unlabelled option and a bare scalar option fall to the raw value;
5. a throwing i18n service leaves the declared labels standing (a 400
never becomes a 500);
6. an authored `message` containing `{{from}}` / `{{to}}` is returned
exactly as written, with the raw `constraint` beside it.
Measured on `main` 277275a before the fix (test file only): pins 1–5
red, pin 6 green (a preservation pin). Received on main for pin 1:
```text
Expected: "Invalid transition for Status: Presented → Draft"
Received: "Invalid transition for Status: presented → draft"
```
Ablations, each reverted from the committed fix and restored with `git
restore --source=HEAD --staged --worktree` (tree clean afterwards, 6/6
green on restore):
| Ablation | Red pins |
|---|---|
| A1 built-in path renders from `constraint` again (as on main) | 1, 2,
3, 4, 5 |
| A2 no translate lookup for options | 2, 3 |
| A3 no picklist key | 3 |
| A4 no raw-value fallback | 4 |
| A5 `constraint` carries the labels | 1, 2, 4 |
| A6 no try/catch around the option lookup | 5 |
| A7 an authored message gets its holes filled | 6 |
## Acceptance notes
- The `invalid_initial_state` built-in sentence still lists `{{value}}`
/ `{{allowed}}` as raw option values. Same wording shape, left alone
because the card and its claim scope this PR to `invalid_transition`
only; noted, not filed.
- No helper in `packages/spec` spells the option-label bundle key (only
`objectFieldLabelKey` / `objectLabelKey` / `objectValidationMessageKey`
exist), so the key is spelled inline here, as `plugin-audit`'s activity
summary already does. A spec helper would be a `domain:spec` change;
noted, not filed.
## Verification
All at head f118099 (worktree off `origin/main` 277275a):
- `pnpm --filter @objectstack/objectql test`: 495 files / 9629 tests
passed.
- `pnpm --filter @objectstack/objectql typecheck` (tsc plus
`check:test-typecheck`): exit 0.
- eslint on the two changed `.ts` files: exit 0. `pnpm lint`: exit 0.
- `node scripts/pm/dispatch-gates.mjs --commands`: 62 families, each run
with its exit code recorded before any pipe; `--ran` reconciliation: "62
derived, 62 run, 0 NOT-MEASURED, 0 UNRUN" (exit 0).
`check:dual-build-cjs-loads` first exited 3 (PREREQUISITE NOT MET, no
full build yet); re-run after a full `pnpm turbo run build` (116/116
tasks): exit 0, "113 published require entry point(s) across 70
package(s) load". The ten commits `main` gained since 277275a touch
neither `packages/objectql` nor the `invalid_transition` template.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_016WV4czVnUdQQCVKSW5J2uk
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent dc4755c commit 139bc18
3 files changed
Lines changed: 223 additions & 1 deletion
File tree
- .changeset
- packages/objectql/src/validation
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2911 | 2911 | | |
2912 | 2912 | | |
2913 | 2913 | | |
| 2914 | + | |
| 2915 | + | |
2914 | 2916 | | |
2915 | 2917 | | |
2916 | 2918 | | |
| |||
2938 | 2940 | | |
2939 | 2941 | | |
2940 | 2942 | | |
| 2943 | + | |
| 2944 | + | |
| 2945 | + | |
2941 | 2946 | | |
2942 | 2947 | | |
2943 | 2948 | | |
| |||
3848 | 3853 | | |
3849 | 3854 | | |
3850 | 3855 | | |
| 3856 | + | |
| 3857 | + | |
| 3858 | + | |
3851 | 3859 | | |
3852 | 3860 | | |
3853 | 3861 | | |
| |||
3870 | 3878 | | |
3871 | 3879 | | |
3872 | 3880 | | |
| 3881 | + | |
| 3882 | + | |
| 3883 | + | |
| 3884 | + | |
| 3885 | + | |
| 3886 | + | |
| 3887 | + | |
| 3888 | + | |
| 3889 | + | |
| 3890 | + | |
| 3891 | + | |
| 3892 | + | |
3873 | 3893 | | |
3874 | 3894 | | |
3875 | 3895 | | |
| |||
3899 | 3919 | | |
3900 | 3920 | | |
3901 | 3921 | | |
3902 | | - | |
| 3922 | + | |
| 3923 | + | |
| 3924 | + | |
| 3925 | + | |
| 3926 | + | |
| 3927 | + | |
| 3928 | + | |
| 3929 | + | |
| 3930 | + | |
| 3931 | + | |
3903 | 3932 | | |
3904 | 3933 | | |
3905 | 3934 | | |
3906 | 3935 | | |
| 3936 | + | |
| 3937 | + | |
| 3938 | + | |
| 3939 | + | |
| 3940 | + | |
| 3941 | + | |
| 3942 | + | |
| 3943 | + | |
| 3944 | + | |
| 3945 | + | |
| 3946 | + | |
| 3947 | + | |
| 3948 | + | |
| 3949 | + | |
| 3950 | + | |
| 3951 | + | |
| 3952 | + | |
| 3953 | + | |
| 3954 | + | |
| 3955 | + | |
| 3956 | + | |
| 3957 | + | |
| 3958 | + | |
| 3959 | + | |
| 3960 | + | |
| 3961 | + | |
| 3962 | + | |
| 3963 | + | |
| 3964 | + | |
| 3965 | + | |
| 3966 | + | |
| 3967 | + | |
| 3968 | + | |
| 3969 | + | |
| 3970 | + | |
| 3971 | + | |
| 3972 | + | |
| 3973 | + | |
| 3974 | + | |
| 3975 | + | |
| 3976 | + | |
| 3977 | + | |
| 3978 | + | |
| 3979 | + | |
| 3980 | + | |
3907 | 3981 | | |
3908 | 3982 | | |
3909 | 3983 | | |
| |||
0 commit comments