Repository navigation
Commit 5d2ce34
fix(spec): the save door reads ctx.text?.( as a literal text-key ask (#35686)
repo:objectstack#1 · os-sales · session_01L6bhgX6mQpVU8yUysiRAFC
<!-- claude-projects-attribution: {"github_login":"os-sales"} -->
_Requested by **Sales** · [project
thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4Uu19ctjaTjyM4gmWfgBPNRmc)_
Fixes #35512
Clause-②: no (narrowing)
Metadata-protocol: narrowed
Skills-docs: none — skills/objectstack-data/references/data-hooks.md and
skills/objectstack-ui/rules/actions.md already teach "an undeclared key
is refused at save when asked for literally, else at run" without naming
a call shape; this diff makes that sentence hold for the optional-call
shape, so nothing new is taught. The one hand-written page that names
the call shape, content/docs/automation/hooks.mdx (~499), now names
`ctx.text?.('key')` beside `ctx.text('key')`
## 维护者速读
- 用户无感的作者面变化:写钩子或脚本动作的作者,用可选调用 `ctx.text?.(`
的写法去取一句没声明的文案时,保存时就被拒,以前要等运行时才报错。
- 属于"组织语言文案"那组工作:兑现钩子与动作文案字段已经写明的承诺,即按字面取的未声明文案在保存时就被拒。
- 若出错,受影响的是用 `ctx.text?.(` 写法取了未声明文案的钩子或动作,保存会被拒;声明那句文案即可通过,本改动可直接撤回。
- 无
## What changes
- `TEXT_CALL` in `packages/spec/src/data/hook-refusal-codes.ts`, the one
literal key reader behind both save doors (`HookSchema` at `hook.zod.ts`
and `ActionSchema` at `action.zod.ts`, through `hookTextKeysAskedIn`),
now also reads `ctx.text?.('k')`, awaited or not. So an undeclared key
asked for in that shape is refused at save with the existing
`undeclaredHookTextKeyAtSave` / `undeclaredActionTextKeyAtSave`
sentence, at `body.source` (or `handler` for an in-process hook
handler). The masking of comments and longer strings and the snake_case
key group are unchanged.
- Shape decisions: whitespace or a line break around `?.` is read
(`ctx.text ?. ('k')`), matching the reader's existing whitespace
tolerance around the dot. The card's second shape, non-null
`ctx.text!('k')`, is deliberately NOT read (patch round 1, L2 S1 on
7025732554): it is TypeScript with no JavaScript form. A handler's `!`
is erased before the save reads `Function.prototype.toString()`, so
`main` already reads it as the plain call; in a `js` body it is a syntax
error (an action is refused as `action-body-does-not-compile`, a hook
body never runs). So the card's `!(` ask is moot, and a pin documents
why. `ctx?.text(` and `ctx!.text(` are left out: `ctx` is the bound
parameter and is never optional in the type.
- The refusal sentence's echo stays `` (`ctx.text('k')`) ``. It names
the call, not the spelling the author used, and it reads correctly for
both read shapes (the plain call and `?.`). Its bytes, which tests pin,
are unchanged.
- Rider (accepted L1 nit on PR #35510): the TSDoc that describes the
literal-only save check now names the `?.(` shape. That covers
`HookSchema.texts`, `HookContext.text`, `ActionSchema.texts`, the two
internal docblocks beside the doors, and the header comments above
`TEXT_CALL`. `.describe()` strings are unchanged.
- ADR-0087: a registered semantic entry,
`hook-action-text-key-optional-call-refused`. The `narrowed` kind
refuses `no-migration-prescription`, and there is no mechanical rewrite.
- Changeset: `@objectstack/spec` `minor` (the kind is `narrowed`), with
a BREAKING FROM/TO section and the fix.
## Tests
- Pins in `packages/spec/src/data/hook-texts.test.ts` and
`packages/spec/src/ui/action-texts.test.ts`, one per shape
(`ctx.text?.(`, `await ctx.text?.(`) for each door. A lit pin checks
that an undeclared key is refused at `body.source` with the exact
sentence. A dark pin checks that a declared key, and a computed key in
that shape, still pass save. The hook file also has a reader pin for
whitespace and a line break around `?.`, a `handler`-path pin (an inline
handler asking `ctx.text?.('undeclared')` is refused at `handler`, the
strict-TypeScript case; an action has no handler path), and a pin that
`ctx.text!('k')` is not read, with the reason.
- On head 0acd17d both files are green (51/51).
- Ablation on head 0acd17d: replacing the optional-call arm
`text(?:\s*\?\.)?\s*\(` with the old `text\s*\(` (one occurrence) turned
8 of the 51 tests red. The restore was proved by an empty `git diff
HEAD`. (The earlier 12-red-first and 13-red readings were taken on
269566b, before patch round 1 removed the `!(` arm.)
- `pnpm --filter @objectstack/spec test`: 859 files / 27461 tests
passed. `pnpm --filter @objectstack/spec typecheck`: exit 0.
## Acceptance notes
- `ctx?.text(` and `ctx!.text(` are still not read at save (see above).
If one of them is used with an undeclared key, the runtime refuses it
when the code runs.
- A real producer of the new shape already exists in this tree with a
declared key: `packages/spec/src/data/hook-context-text.test.ts:43`
(`ctx.text?.('follow_up_subject', …)`), and it stays green. The
runtime's own `ctx.text!(String(key), …)` in
`packages/runtime/src/sandbox/quickjs-runner.ts` is host TypeScript,
never a saved body. The break is the hook half only:
`ActionSchema.texts` is unreleased (pending changeset), so the action
half ships already narrowed (L2 N1).
## Verification
Two-minute check: `pnpm --filter @objectstack/spec exec vitest run
--maxWorkers=2 src/data/hook-texts.test.ts src/ui/action-texts.test.ts`,
including the two `ctx.text?.(` shape rows per door and the handler pin.
Read first, by risk:
1. `packages/spec/src/data/hook-refusal-codes.ts`: the `TEXT_CALL` regex
hunk (the `(?:\s*\?\.)?` arm) and its header comment on why `!` is not
read.
2. `.changeset/35512-text-call-shapes.md`: the declarations and the
BREAKING section.
3.
`packages/spec/src/migrations/entries/semantic/18.hook-action-text-key-optional-call-refused.ts`.
All the local readings below were taken at head `269566b8`.
<details><summary>Local gates (derived list, 96 commands)</summary>
- `pnpm --filter @objectstack/spec build`: VERDICT command-exit 0.
`check:generated`: all 14 artifacts are up to date (exit 0).
- `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 96 commands, and I ran all 96. On
the first pass, 86 exited 0.
- Six spec gates exited 3 (PREREQUISITE NOT MET: dist predated a later
TSDoc rewrap). After a spec rebuild they exited 0: `check:api-surface`,
`check:browser-reachable-entries`, `check:dual-source-exports`,
`check:entry-nameability`, `check:exported-any` (and `check:docs` /
`check:authorable-surface` again).
- Four gates were missing workspace builds on the first pass and exited
0 once the dogfood/cli closure was built: the cli
`migrate-meta-engine-guidance` test (3/3),
`check:doc-formula-expressions`, `check:lean-entry-closure` and
`check:dual-build-cjs-loads`.
- NOT MEASURED: `check-plugin-teardown-shape.mjs --self-test`, because
the shallow clone cannot reach its battery. CI runs it.
- Changeset gates, each exit 0: `check-adr-0087-registration`
(registered `hook-action-text-key-optional-call-refused`),
`check-changeset-no-major` and `check-empty-changeset`.
- `--ran` reconciliation: 96 derived, 96 run, 0 UNRUN.
- `overlap-check --branch=HEAD`: VERDICT clean exit 0, against
origin/main 03865ae.
</details>
<details><summary>Dogfood battery (owed by the narrowing arm)</summary>
- I built the `@objectstack/dogfood^...` closure under the lock (exit
0), then ran `pnpm --filter @objectstack/dogfood test` at `269566b8`.
- Result: VERDICT command-exit 0, Test Files 482 passed / 3 skipped
(485), Tests 4092 passed / 68 skipped (4160). No failures.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01L6bhgX6mQpVU8yUysiRAFC)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 9b6db73 commit 5d2ce34
8 files changed
Lines changed: 142 additions & 20 deletions
File tree
- .changeset
- content/docs/automation
- packages/spec/src
- data
- migrations/entries/semantic
- ui
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
497 | 497 | | |
498 | 498 | | |
499 | 499 | | |
500 | | - | |
501 | | - | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
502 | 503 | | |
503 | 504 | | |
504 | 505 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
423 | 423 | | |
424 | 424 | | |
425 | 425 | | |
426 | | - | |
427 | | - | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
428 | 429 | | |
429 | 430 | | |
430 | 431 | | |
| |||
433 | 434 | | |
434 | 435 | | |
435 | 436 | | |
436 | | - | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
437 | 447 | | |
438 | | - | |
| 448 | + | |
439 | 449 | | |
440 | 450 | | |
441 | 451 | | |
442 | 452 | | |
443 | | - | |
444 | | - | |
445 | | - | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
446 | 457 | | |
447 | 458 | | |
448 | 459 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 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 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
108 | 145 | | |
109 | 146 | | |
110 | 147 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
337 | 337 | | |
338 | 338 | | |
339 | 339 | | |
340 | | - | |
341 | | - | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
342 | 343 | | |
343 | 344 | | |
344 | 345 | | |
| |||
816 | 817 | | |
817 | 818 | | |
818 | 819 | | |
819 | | - | |
820 | | - | |
| 820 | + | |
| 821 | + | |
821 | 822 | | |
822 | 823 | | |
823 | 824 | | |
| |||
1939 | 1940 | | |
1940 | 1941 | | |
1941 | 1942 | | |
1942 | | - | |
1943 | | - | |
| 1943 | + | |
| 1944 | + | |
| 1945 | + | |
1944 | 1946 | | |
1945 | 1947 | | |
1946 | 1948 | | |
| |||
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
133 | 154 | | |
134 | 155 | | |
135 | 156 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1572 | 1572 | | |
1573 | 1573 | | |
1574 | 1574 | | |
1575 | | - | |
1576 | | - | |
1577 | | - | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
1578 | 1578 | | |
1579 | 1579 | | |
1580 | 1580 | | |
| |||
2658 | 2658 | | |
2659 | 2659 | | |
2660 | 2660 | | |
2661 | | - | |
2662 | | - | |
| 2661 | + | |
| 2662 | + | |
2663 | 2663 | | |
2664 | 2664 | | |
2665 | 2665 | | |
| |||
0 commit comments