Skip to content

Commit 0dfeeda

Browse files
committed
fix(lint): the action-record-write-discarded hint prescribes update({ id, … }), a write the sandbox installs
Claude-Session: https://claude.ai/code/session_01ADHkmSwS4mQyXWrddL4r6B Co-authored-by: Claude <noreply@anthropic.com>
1 parent 48da716 commit 0dfeeda

5 files changed

Lines changed: 68 additions & 11 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/lint': patch
3+
---
4+
5+
fix(lint): the `action-record-write-discarded` hint prescribes a write a sandboxed body can run
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The hint now reads `ctx.api.object('<object>').update({ id: ctx.recordId, <field>: … })`. It used to prescribe `ctx.api.object('<object>').updateById(ctx.recordId, { … })`, and the sandbox an action body runs in installs no `updateById` on `ctx.api.object(…)`: following the hint turned the discarded write into `TypeError: not a function` on the action's first run. The `os explain action-body-write-unknown-field` text no longer lists `create` and `updateById` among the calls an action body persists through, for the same reason. What lint judges is unchanged: an `updateById` payload in a body is still graded.

‎content/docs/deployment/app-dependencies.mdx‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,28 @@ export default defineStack({
3333

3434
The declaration does two things:
3535

36-
- **It opens the reference.** The runtime save door judges a list view against
37-
your package's own objects and those of the packages your manifest declares,
38-
transitively; a view bound to an object outside that set is refused there,
39-
`422`, and the fix it prints is this declaration. A dependency opens the
40-
reference, not the data: users still see the other app's records under that
41-
app's own permission sets and sharing rules.
36+
- **It opens the reference.** The runtime save door judges the bindings below
37+
against your package's own objects and those of the packages your manifest
38+
declares, transitively; a binding to an object outside that set is refused
39+
there, `422`, and the fix it prints is this declaration. A dependency opens
40+
the reference, not the data: users still see the other app's records under
41+
that app's own permission sets and sharing rules.
4242
- **It is checked before install** — below.
4343
- **It lets your package share the depended-on app's namespace** — below.
4444

45+
The bindings the save door judges this way, when the item is saved into a
46+
package, include:
47+
48+
| You save | The binding judged |
49+
|:---|:---|
50+
| A flow | its trigger object |
51+
| A flow | the `objectName` of each `get_record`, `create_record`, `update_record` and `delete_record` node, and of a `screen` node that renders an object's form, nested nodes included |
52+
| A dataset | its base object |
53+
| A list view | its object |
54+
| A form | its object |
55+
| A knowledge source | its object |
56+
| A standalone action | its `objectName` |
57+
4558
Every entry is required; there is no optional arm. Declare only the packages
4659
your app actually references. Two modules of one app need not declare each
4760
other: each declares the app, and that is enough for both to install, in either

‎packages/lint/src/rule-explanations.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,8 +1422,8 @@ const ACTION_BODY_WRITE_UNKNOWN_FIELD_EXPLANATION: RuleExplanation = {
14221422
rule: 'action-body-write-unknown-field',
14231423
covers: 'why an undeclared field write is refused',
14241424
paragraphs: [
1425-
'An action body persists records only through ' +
1426-
'`ctx.api.object(NAME).insert / create / update / updateById(…)`. `ctx.api` is a scoped handle on ' +
1425+
'An action body persists records only through `ctx.api`: ' +
1426+
'`ctx.api.object(NAME).insert({ … })`, or `.update({ id, … })` for one record. `ctx.api` is a scoped handle on ' +
14271427
'the running engine, so the payload arrives as an ordinary CALLER write. An action\'s `ctx.input` ' +
14281428
'is its params bag, validated against the action\'s own `params`, so it is never resolved against ' +
14291429
'fields.',

‎packages/lint/src/validate-action-body-writes.test.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import {
1212
ACTION_BODY_WRITE_UNPROVISIONED_ANCHOR,
1313
ACTION_RECORD_WRITE_DISCARDED,
1414
ACTION_BODY_SOURCE_UNPARSEABLE,
15+
ACTION_RECORD_WRITE_REMEDY_METHOD,
1516
} from './validate-action-body-writes.js';
17+
import { SANDBOX_API_WRITE_METHODS } from './validate-action-body-capabilities.js';
1618
import {
1719
extractHookBodyWrites,
1820
HOOK_BODY_WRITE_PATTERNS,
@@ -347,7 +349,21 @@ describe('validateActionBodyWrites — discarded ctx.record writes (#4345)', ()
347349
expect(explanationOf(ACTION_RECORD_WRITE_DISCARDED)).toContain(
348350
"The snapshot stays read-only by design: an action's write channel is `ctx.api`.",
349351
);
350-
expect(findings[0].hint).toContain('updateById');
352+
expect(findings[0].hint).toContain(`.${ACTION_RECORD_WRITE_REMEDY_METHOD}(`);
353+
});
354+
355+
it('prescribes a write the sandbox installs, addressed to ctx.recordId', () => {
356+
// The remedy is code an author pastes into a body, so the member it names
357+
// must be one the sandbox's `ctx.api.object(…)` actually has. It once named
358+
// `updateById`, which the host repository has and the sandbox does not:
359+
// following the hint was a `TypeError: not a function` on the first run.
360+
// `SANDBOX_API_WRITE_METHODS` is pinned to the runner's own `WRITE` list.
361+
expect(SANDBOX_API_WRITE_METHODS).toContain(ACTION_RECORD_WRITE_REMEDY_METHOD);
362+
const [finding] = validateActionBodyWrites(stackWith("ctx.record.stage = 'won';"));
363+
const called = [...finding.hint.matchAll(/\.object\('<object>'\)\.(\w+)\(/g)].map((m) => m[1]);
364+
expect(called).toEqual([ACTION_RECORD_WRITE_REMEDY_METHOD]);
365+
// The single-record `update` form reads the primary key from the payload.
366+
expect(finding.hint).toMatch(/\(\{ id: ctx\.recordId, stage: /);
351367
});
352368

353369
it('reads from ctx.record do not rescue the write', () => {

‎packages/lint/src/validate-action-body-writes.ts‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,18 @@ export interface ActionBodyWriteFinding {
117117
export const ACTION_BODY_WRITE_UNKNOWN_FIELD = 'action-body-write-unknown-field';
118118
export const ACTION_RECORD_WRITE_DISCARDED = 'action-record-write-discarded';
119119

120+
/**
121+
* The `ctx.api.object(…)` member the `action-record-write-discarded` hint
122+
* prescribes. It must be a write leaf the sandbox installs on a body's
123+
* `ctx.api.object(…)` (`WRITE` in packages/runtime/src/sandbox/quickjs-runner.ts):
124+
* the hint once named `updateById`, which the host repository has and the
125+
* sandbox does not, so following it traded a silent no-op for a
126+
* `TypeError: not a function`. Its test pins it to `SANDBOX_API_WRITE_METHODS`
127+
* (validate-action-body-capabilities.ts), which is itself pinned to the
128+
* runner's list. Not re-exported from the package index.
129+
*/
130+
export const ACTION_RECORD_WRITE_REMEDY_METHOD = 'update';
131+
120132
/**
121133
* [#10653] The action-surface twin of `hook-body-source-unparseable`. Same
122134
* extractor, same synthesised wrapper, same parse — so the body that came back
@@ -382,9 +394,15 @@ export function validateActionBodyWrites(stack: AnyRec): ActionBodyWriteFinding[
382394
message:
383395
`body assigns ctx.record.${w.field}, but an action's ctx.record is a snapshot the runtime never ` +
384396
`writes back, so the assignment is discarded while the action returns success`,
397+
// The remedy names `update({ id, … })`, the single-record write the
398+
// sandbox installs (`WRITE` in packages/runtime/src/sandbox/
399+
// quickjs-runner.ts) and the shape `HookObjectApi.update` documents:
400+
// the id travels inside the payload. ⛔ Not `updateById`: a body's
401+
// `ctx.api.object(…)` has no such member, so that call throws
402+
// `TypeError: not a function` on its first run.
385403
hint:
386-
`To persist it, write through the API: ctx.api.object('<object>').updateById(ctx.recordId, ` +
387-
`{ ${w.field}: … })`,
404+
`To persist it, write through the API: ctx.api.object('<object>').${ACTION_RECORD_WRITE_REMEDY_METHOD}(` +
405+
`{ id: ctx.recordId, ${w.field}: … })`,
388406
});
389407
}
390408
}

0 commit comments

Comments
 (0)