You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 10321fa
Browse filesBrowse the repository at this point in the historyBrowse files
fix(spec): the hook form offers refusals and texts only where HookSchema accepts them (#38078)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} -->
_Requested by **Tesla** · [project
thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6Jao25upKJEGo6EpwNBNHeRSB5)_Fixes#36799
repo:objectstack#3 · os-tesla · session_01L9qibwvndECT67oMnono1P
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 搭建者在工作室里编辑一个表达式写成的钩子时,不会再看到拒绝码和文案这两栏;JavaScript 钩子和旧式处理函数钩子照常显示。
- 属于「作者界面只提供保存时会被接受的东西」这条线,替用工作室写钩子的搭建者解决填了就保存失败的问题。
- 只改表单什么时候显示这两栏,钩子能写什么完全不变;万一条件写错,最多是该显示的栏没显示,可以直接撤回。
- 无
## What changes
- `packages/spec/src/data/hook.metadata-form.ts`: the `refusals` and
`texts` rows both carry one `visibleWhen`, `SANDBOXED_CODE_VISIBLE`,
which is the test `HookSchema` refuses both keys by (`hook.zod.ts`, the
refusals and texts refinements): shown for a `js` body, or for no body
and a non-empty `handler`; hidden on an `expression` body. The form
serves it as `{ dialect: 'cel', source: "data.body.language == 'js' ||
data.body == null && data.handler != null && data.handler != ''" }`
(`defineMetadataForm` lifts the string, as for every other row).
- Written without parentheses on purpose: the Studio form evaluator
(`ui/packages/app-shell/src/views/metadata-admin/predicate.ts`) splits
`||` before `&&` and has no grouping, so a parenthesised group fails
open. The const's docblock says so.
- No schema, no other form, no evaluator, no locale pack changes (label
and help text are unchanged).
- `patch` changeset for `@objectstack/spec`.
## Tests
- `packages/spec/src/system/metadata-form-declared-rows.pin.test.ts`,
new top-level `describe` "hook.refusals and hook.texts are shown exactly
where HookSchema accepts them" (the shared harness that already pins the
action form's gated `refusals` / `texts` rows):
- each row is offered once and its served `visibleWhen` equals `{
dialect: 'cel', source: <the predicate> }`;
- for each row × five drafts (expression body, js body, handler and no
body, neither, empty handler and no body), the predicate read against `{
data: draft }` equals "`HookSchema.safeParse` raises no issue at that
key";
- the predicate is read by a test-local reader of exactly the subset it
is written in (`||` over `&&` over `data.path ==|!= 'literal'|null`,
loose `null == undefined`, no grouping); any other shape throws, so a
rewrite fails the pin. CONTROLS: the reader refuses a grouped and an
`in` rewrite, and the schema refuses the key on some drafts and accepts
it on others.
<details><summary>Readings at 8c37099 (base origin/main
815e882)</summary>
- Premise at 815e882: `git show
origin/main:packages/spec/src/data/hook.metadata-form.ts | grep -c
visibleWhen` = 0 (the card's `hook.form.ts` has since been renamed).
- The predicate through the real Studio evaluator (`evaluatePredicate` +
`buildPredicateCtx` from `predicate.ts` at 815e882, run under `node
--experimental-transform-types`): expression body `false`, js body
`true`, handler `'fn'` and no body `true`, neither `false`, handler `''`
`false`; all five equal `HookSchema`'s verdict.
- Ablation on the committed fix, file restored with `git checkout HEAD
--` after each (`git status --porcelain` empty): `visibleWhen` removed
from `refusals` → `Tests 6 failed | 23 passed (29)` (that row's six
pins); removed from `texts` → `6 failed | 23 passed (29)` (that row's
six).
- Build: `env -u OS_SKIP_DTS bash scripts/pm/os-verify-lock.sh -c "pnpm
exec turbo run build --filter='./packages/**'
--filter='@objectstack/dogfood^...' --concurrency=2"` exit 0 (83 tasks).
- `pnpm --filter @objectstack/spec check:generated` exit 0 ("All 14
generated artifacts are up to date"); spec `typecheck` exit 0; `eslint`
on the two changed `.ts` exit 0.
- `vitest run src/data src/system src/ui` in `packages/spec`: `Test
Files 470 passed (470)`, `Tests 16505 passed | 1 todo (16506)`.
- `dispatch-gates --ran`: 86 derived, 86 run, every one exit 0, 0
NOT-MEASURED (a derived zero), 0 unrun.
</details>
## Acceptance notes
- A hidden row keeps a value already written: an author who fills
`refusals` on a `js` body and then switches the body to `expression` no
longer sees the row, and the save is refused at a key the form does not
show. This holds for every `visibleWhen` row (the metadata form does not
clear hidden values); not widened here.
- Out of scope, for the seat to file (seat said it will): the Studio
form evaluator fails open on a parenthesised group, so
`field.metadata-form.ts`'s `percentDisplay` row and the currency row
after it read TRUE on every field type (measured at 815e882: `{ type:
'text' }` → `true`; the same predicate without parentheses → `false`).
## Verification
Read first (by risk):
1. `packages/spec/src/data/hook.metadata-form.ts`:
`SANDBOXED_CODE_VISIBLE` and its two uses.
2. `packages/spec/src/system/metadata-form-declared-rows.pin.test.ts`:
the new describe, `evalFormPredicate` and `refusedAt`.
Two-minute check: `pnpm --filter @objectstack/spec exec vitest run
src/system/metadata-form-declared-rows.pin.test.ts` shows 29 passing;
delete `visibleWhen: SANDBOXED_CODE_VISIBLE,` from the `texts` row and
the same command shows 6 failing.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01L9qibwvndECT67oMnono1P)_
---------
Co-authored-by: Claude <noreply@anthropic.com>
fix(spec): the Studio hook form offers `refusals` and `texts` only where a hook may declare them
6
+
7
+
Clause-②: no
8
+
Metadata-protocol: none
9
+
10
+
`hookForm` offered the `refusals` and `texts` rows on every hook. `HookSchema` refuses both keys on an `expression` body, so an author writing an expression hook was offered two sections that could only make the save fail. Both rows now carry a `visibleWhen` that is the schema's own test: they are shown for a `js` body, and for a hook with no body and a non-empty `handler`, and hidden on an `expression` body. What a hook may declare does not change. Nothing to migrate.
helpText: 'Refusal catalogue, keyed by the SCREAMING_SNAKE code the hook throws (e.g. CLEAN_VERSION_REQUIRED). The caller reads the declared message, translated into their language, with the declared status. For a JavaScript (L2) body or a handler; refused on an expression body',
62
78
fields: [
63
79
{field: 'message',type: 'textarea',required: true,helpText: 'The sentence the user reads when the body throws this code. Plain text, unless the entry declares params: then a {{ name }} hole fills a declared param'},
helpText: "Sentences the hook writes into records, keyed by the snake_case key its code asks for with ctx.text (e.g. follow_up_subject). The hook gets the declared message in the organization's language, translated, with the declared message as the fallback. For a JavaScript (L2) body or a handler; refused on an expression body",
86
103
fields: [
87
104
{field: 'message',type: 'textarea',required: true,helpText: 'The sentence the hook writes when its code asks for this key. Plain text, unless the entry declares params: then a {{ name }} hole fills a declared param'},
0 commit comments