Repository navigation
Commit cb99e2d
fix(lint): the record-write-discarded hint prescribes a write the sandbox installs; app-dependencies lists the closure-judged bindings (#38628)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9JeHmqv6CKCkW8ewrPBLekk)_
Refs #37815 (items c, d)
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
用户能看到什么变化:应用作者在构建检查里看到的「记录改动被丢弃」提示,现在给出一种在沙箱里真能运行的写法;应用依赖文档补上了保存时按依赖关系判定的完整绑定清单。
- 为什么做:原提示让作者照抄一个沙箱里根本不存在的方法,照做后动作第一次运行就报错;属于脚本动作写入的检查跟进工作。
- 出错会怎样:只改提示文字和文档,检查结论不变,不影响任何已保存的应用;有问题可直接撤回。
- 要你做什么:无。
## What changes
- **Item (c), the `action-record-write-discarded` hint.** It prescribed
`ctx.api.object('OBJECT').updateById(ctx.recordId, { … })`. Probed for
real (below): a sandboxed action body or hook body has no `updateById`
on `ctx.api.object(…)`, so following the hint throws `TypeError: not a
function` and writes nothing. The hint now prescribes
`ctx.api.object('OBJECT').update({ id: ctx.recordId, FIELD: … })`, the
single-record form the sandbox installs and `HookObjectApi.update`
documents (the id travels inside the payload). The method name lives in
one constant, `ACTION_RECORD_WRITE_REMEDY_METHOD` (not re-exported from
the package index), pinned to `SANDBOX_API_WRITE_METHODS`, which is
itself pinned to the runner's `WRITE` list.
- **The `os explain action-body-write-unknown-field` text** said an
action body persists "only through `insert / create / update /
updateById`". `create` and `updateById` are not installed in the sandbox
either. It now names `insert({ … })` and `update({ id, … })`. Same
defect class, same file, bounded fix.
- **Item (d), `content/docs/deployment/app-dependencies.mdx`.** The page
said the save door judges "a list view" against the package closure. It
now has a table of the bindings that door judges, including the two that
PR #37807 added: a standalone action's `objectName` and a flow
`get_record` / `create_record` / `update_record` / `delete_record` /
object-form `screen` node's `objectName`. Sources:
`validateObjectReferences` runs on the `flow`, `dataset` and `action`
runtime doors (`packages/lint/src/reference-integrity-suite.ts`, member
`runtimeTypes: ['flow', 'dataset', 'action']`, handed
`ctx.packageScope`), and the flow-node and action sites are in
`packages/lint/src/validate-object-references.ts`
(`OBJECT_BOUND_FLOW_NODE_TYPES`, `actions[i].objectName`). The form and
knowledge-source rows come from `form-object-outside-closure`
(`validate-form-items.ts`) and `knowledge-source-object-unknown`
(`validate-knowledge-source.ts`). The table says "include" because other
closure-aware rules exist (email template holes, AI tool and context
references) that this PR did not audit.
- What lint judges is unchanged: an `updateById` payload in a body is
still graded (`API_WRITE_METHODS`, the ledger's `api-crud-literal`
syntax line and example, and the explanations that say what is judged),
because a body can still contain the call.
- The ADR-0141 D1 note is not in this diff. It goes to the weekly ADR
revisions card.
## Tests
- `validate-action-body-writes.test.ts`: the existing case that pinned
`hint` to contain `updateById` now pins the remedy method. A new case
asserts the method the hint calls is in `SANDBOX_API_WRITE_METHODS` and
that the payload is addressed by `id: ctx.recordId`. Subjects, not
prose.
- Ablation (hint put back to `updateById(ctx.recordId, …)` via
`scripts/ablation-replace.mjs`, anchor 1 to 0, blob 262ceea to
a2f3f908): 2 cases red (`expected [ 'updateById' ] to deeply equal [
'update' ]`), 50 passed. Restored: `git diff HEAD` empty, 0 hits of the
mutation.
<details><summary>Sandbox probe (throwaway test, not committed): real
ObjectQL, real better-sqlite3 SqlDriver, real QuickJSScriptRunner and
body-runner factories</summary>
```
PROBE ACTION updateById (old hint) :: {"err":{"name":"SandboxError","message":"action 'close_deal' threw: TypeError: not a function","inner":"TypeError: not a function"}} :: stage after = open
PROBE ACTION update({ id }) (new hint) :: {"ok":"ok"} :: stage after = won
PROBE ACTION typeof updateById :: {"ok":"undefined"} :: stage after = open
PROBE HOOK updateById :: {"err":{"name":"SandboxError","message":"hook 'note_closes_deal' threw: TypeError: not a function"}} :: stage after = open
PROBE HOOK update({ id }) :: {"ok":true} :: stage after = won
Test Files 1 passed (1)
Tests 5 passed (5)
```
Hook bodies run in the same sandbox and fail the same way.
</details>
<details><summary>Local runs (head c2b9cff)</summary>
- `pnpm --filter @objectstack/lint exec vitest run --maxWorkers=2` (the
whole package) at c2b9cff: lock VERDICT command-exit 0, Test Files 246
passed (246), Tests 9959 passed (9959). The first whole-package run, at
0dfeeda, had 1 red in `rule-id-barrel-exports.test.ts`: it reads an
unannotated exported string constant as a rule id. The constant is now
annotated `string` (second commit).
- `pnpm --filter @objectstack/lint typecheck`: VERDICT command-exit 0.
- eslint on the three edited lint files: exit 0.
- `dispatch-gates.mjs --commands` derived 100 families; all 100 run
locally: 97 exit 0; 3 exit 3 PREREQUISITE NOT MET, so NOT MEASURED here
and left to CI (`check-plugin-teardown-shape --self-test` needs an
unshallow clone; `spec check:skill-examples` and
`check:dual-build-cjs-loads` need packages this worktree did not build).
None of the three reads a file this PR changes. `--ran` reconciliation:
100 derived, 100 run, 0 UNRUN. Re-run on c2b9cff after the second
commit: `check:doc-authoring`, `check:issue-citations`,
`check:nul-bytes`, `check:adr-anchors`,
`check:cross-package-test-inputs`, `check:undeclared-dep-imports`,
`check:type-check-debt`, `check:closed-ceremony-text`, all exit 0.
- `test:repo` not run locally (CI's `Test Core`).
</details>
## Acceptance notes
- **Not fixed here, reported for filing (outside this PR's file
surface):** `content/docs/automation/hook-bodies.mdx` (the "exactly one
way an action body persists anything" snippet) still teaches
`updateById(ctx.recordId, …)` in an action body. The spec contract
(`HookObjectApi.updateById` in `packages/spec/src/data/hook-api.ts`,
`IScopedObjectRepository.updateById`) declares the member a body cannot
call, and `objectstack build` does not refuse `.updateById(` at lowering
the way it refuses `.create(`. Whether the sandbox should install the
leaf or the body-facing contract should drop it is a decision; it is
raised in the report.
- The hook ledger's `api-crud-literal` syntax line and example still
name `updateById`: they mirror the extractor's graded verbs
(`validate-readonly-hook-writes.test.ts` reads the syntax line as that
mirror) and are not shown to authors.
## Verification
Read first: `packages/lint/src/validate-action-body-writes.ts` (the hint
and `ACTION_RECORD_WRITE_REMEDY_METHOD`), then the new test case, then
the docs table.
Two-minute check: `pnpm --filter @objectstack/lint exec vitest run
src/validate-action-body-writes.test.ts` shows all cases passing, and
the `prescribes a write the sandbox installs` case among them.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01ADHkmSwS4mQyXWrddL4r6B)_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01ADHkmSwS4mQyXWrddL4r6B
<!-- signed: repo:objectstack#3 · os-steve ·
session_01ADHkmSwS4mQyXWrddL4r6B -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 809c270 commit cb99e2d
5 files changed
Lines changed: 71 additions & 11 deletions
File tree
- .changeset
- content/docs/deployment
- packages/lint/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
45 | 58 | | |
46 | 59 | | |
47 | 60 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1422 | 1422 | | |
1423 | 1423 | | |
1424 | 1424 | | |
1425 | | - | |
1426 | | - | |
| 1425 | + | |
| 1426 | + | |
1427 | 1427 | | |
1428 | 1428 | | |
1429 | 1429 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
| |||
347 | 349 | | |
348 | 350 | | |
349 | 351 | | |
350 | | - | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
351 | 367 | | |
352 | 368 | | |
353 | 369 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
120 | 135 | | |
121 | 136 | | |
122 | 137 | | |
| |||
382 | 397 | | |
383 | 398 | | |
384 | 399 | | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
385 | 406 | | |
386 | | - | |
387 | | - | |
| 407 | + | |
| 408 | + | |
388 | 409 | | |
389 | 410 | | |
390 | 411 | | |
| |||
0 commit comments