Repository navigation
Commit c42a045
fix(lint)!: three publish-time checks for seeds, flow nodes and actions that save and do not work (#37807)
Part of #35143
Clause-②: yes (narrowing)
Metadata-protocol: narrowed
Skills-docs: follow-up #37814
## 维护者速读
-
搭应用的人在发布种子数据、流程和按钮动作以及本地校验时,会被拦下三类“保存成功却不工作”的写法:种子数据里写了对象没有的字段、种子/流程步骤/按钮绑到不存在的对象、按钮脚本要写数据却没勾写权限。
- 属于“发布期作者规则第二批”中的种子与动作一族,替搭应用的人在保存时就发现启动后少记录、流程每次运行都失败、按钮一点就报无权限这类问题。
- 已经存好的配置不会被改写也不会在启动时被拒,只是下次发布被拦并给出改法;误拦时撤回这次合并即可恢复。
- 无
## What changes
The Seeds and actions family of the card's second batch of publish-time
checks, three lines, each verified on `origin/main` first (probe configs
under `examples/app-todo`, removed afterwards).
| Line | Verdict on main | This PR |
|---|---|---|
| S1 seed key that is not a field of its object | holds for a plain
`data: [{ object, records }]` entry and for a `seed` saved at the
runtime door: `os validate` passed a misspelt key and the runtime gate
dispatched nothing for `seed`. `defineSeed` already refused it when it
ran. | new error `seed-record-unknown-field` |
| S2 seed, flow node or action bound to an object that does not exist |
partly covered. A seed: `defineStack` refuses an unprefixed miss on the
CLI, and the runtime save door already refuses a seed over an object
neither the registry nor a draft answers for (#34864, pinned in
`protocol.seed-external-id-refusal.test.ts`); a platform-prefixed
`sys_nothing_here` seed built clean. An action: `defineStack` refuses a
missing `objectName` on the CLI; the runtime `action` door judged
nothing. A flow `create_record` node to `pr_nope` passed everywhere |
extends the existing `object-reference-unknown` ladder
(`validateObjectReferences`) to the three bindings, as the card asks; no
second rule. The seed binding is judged on the CLI only: the runtime
seed door stays with #34864 |
| S3 action body that writes without declaring the write | holds: an L2
body calling `ctx.api.object(…).update(…)` with `capabilities: []`
passed. The declaration key exists (`body.capabilities`, enum
`HookBodyCapability`, `api.write`), so the line was not stopped | new
error `action-body-write-capability-undeclared` |
- **S1** (`packages/lint/src/validate-seed-record-keys.ts`). The column
set is the object's fields as served, including fields an object
extension adds, plus the system columns the platform injects on that
object (`injectedColumnsFor`). So an object built with `systemFields:
false` is refused `created_at`, exactly as `defineSeed` refuses it.
- Record keys and seed `columns` keys are both judged. A key is reported
once per dataset.
- A dataset whose object is unknown is left to S2.
- Runs on the runtime `seed` door.
- **S2** (`validate-object-references.ts`). New sites:
- a seed dataset's `object` (CLI only, see below);
- `config.objectName` on `get_record` / `create_record` /
`update_record` / `delete_record` and object-form `screen` nodes, nested
nodes included;
- a standalone action's `objectName`.
- At all three, an object the stack extends resolves. An unprefixed miss
is an error. A platform-prefixed miss outside the known registry is the
existing warning `object-reference-unregistered-platform`.
- The member now runs on the `action` door as well. The suite entry
dispatches on `action`, but only the member that declares the type runs.
It does **not** run on the `seed` door: #34864's save-door refusal
already answers it there, accepting a draft of the object in the same
package and leaving the publish promotion and restore doors to the load.
A snapshot of served objects cannot reproduce those carve-outs, so a
second verdict there would contradict them. Found by the
metadata-protocol suite and corrected in e5a226a.
- An empty object set with no package closure in force is not a verdict,
as at the list-view member (#24668): a host that hands over no objects
supplied no universe. Under a closure an empty set is still a verdict
(#24563). Both directions are pinned.
- **Package closure.** An action saved into a package (`?package=`) is
judged against that package's closure, as a flow saved there already
was. An object another package owns resolves only when the manifest
declares that package in `dependencies`. Three fixtures (one dogfood,
one runtime, one protocol) had an authored package bind another
package's object without declaring it, and each now declares the
dependency. This is the part of the change most likely to meet a real
author; see Acceptance notes.
- **S3** (`validate-action-body-capabilities.ts`). The write set is the
sandbox runner's `WRITE` list (`insert`, `update`, `delete`,
`updateMany`, `deleteMany`, `upsert`). A test pins it against
`quickjs-runner.ts`.
- The scan is a regex over a copy of the source with comments and
strings masked. The runtime gate must not load a parser: the tier-1
lazy-deps fence still holds, and the PR adds an action-write leg to that
fence.
- It recognises three call shapes: `ctx.api` direct, `const api =
ctx.api` (or its destructured form) bound once, and a handle `const repo
= ctx.api.object(…)`.
- Runs on the runtime `action` and `object` doors.
- **M1 check (the platform's own UI producing the refused shape).**
Studio's `ScriptCapabilitiesField` lets the author tick `api.write`.
- `os build` lowers a handler through `extract-hook-body.ts`, which
infers the grant. Measured: a handler whose only write was `updateMany`
or `deleteMany` inferred **no** grant, so it was lowered into exactly
the shape S3 refuses.
- Fixed here (`packages/cli`, commit ee0969c), with a two-case
`it.each` pin.
### Commits outside the claim's `packages/lint` surface
- ee0969c `fix(cli)`: the extractor's write regex, named above
(`packages/cli/src/utils/extract-hook-body.ts` plus its test).
- cd83ed8 `docs`: the rule count 81 → 83 on four pages, and the
`validating-metadata.mdx` rows (two new, two extended).
- 4ba19b7 `chore`: the changeset and the upgrade-guide entry
`packages/spec/src/migrations/entries/semantic/19.publish-refuses-seeds-and-actions-that-save-and-do-not-work.ts`
(notice only, no conversion).
- 0a916bb `chore`: `turbo.json` and
`scripts/cross-package-test-inputs.mjs` declare
`packages/runtime/src/sandbox/quickjs-runner.ts` as an input of the lint
test task, which reads it (`check:cross-package-test-inputs` went red
without it).
- 04d056b, a683a7d `test`: the fixtures named above, in
`packages/qa/dogfood`, `packages/runtime` and `packages/objectql`. The
objectql orphan-action pin is the one whose FROM this PR changes: the
save is now refused 422.
- e5a226a also edits two `packages/metadata-protocol` fixtures that
save under a package closure, so that they serve the objects their
actions and flow nodes bind.
- c670495: one merge of `origin/main`. It touched nothing under
`packages/lint`.
## Rework after contract review 7209862537 (head `6361589d`)
- M1 (c6bb575): the flow-node site of `object-reference-unknown` is a
warning when no closure and no whole collection is stated (the CLI case:
a binding to a dependency's object the build cannot see), and an error
at the publish door, as `flow-trigger-unknown-object` splits. The
changeset, the ADR-0087 entry, the explanation and the docs row no
longer claim the step "fails the run on every execution"
unconditionally.
- S1 (295210a): the `os build` extractor infers `api.write` through a
bound handle, `?.` before the leaf, and an `.object(...)` argument
holding a call; pinned shape by shape; the rule header names the shapes.
- S2 (c6bb575): `seed-record-unknown-field` admits `id` / `created_at`
/ `updated_at` (the engine's provisioned columns, pinned to the objectql
source) and gives the engine's door as the reason.
- N2 (c6bb575): `os explain` entries for both new ids;
`@objectstack/lint` now exports the two rule-id constants (and only
those) so the explanation table can carry them.
- Out of scope, filed: #37815 (hook bodies, other capability tokens,
`updateById` advice, ADR-0141 D1 binding list). Skills follow-up:
#37814.
## Tests
- New: `validate-seed-record-keys.test.ts`,
`validate-action-body-capabilities.test.ts` (19 scanner shapes, write
set pinned to the runner), and a `[#35143]` block in
`validate-object-references.test.ts`. Each rule has a positive and a
negative pin through the registry and at the runtime door.
- Re-pinned fences:
- `runtime-gate.inert-type-writes.test.ts`: an `action` write now
reaches only `validateObjectReferences` from the suite; a `hook` write
still dispatches nothing.
- `runtime-gate.object-writes.test.ts`: the object-door rosters.
- `runtime-lazy-deps.test.ts`: the action leg, with no parser loaded.
- Ablation, with the source mutated on disk and restored with `git
checkout HEAD`:
- The CLI regex: the two new cases go red.
- Three lint guards (the extended-object exemption, the injected
columns, the `api.write` skip): four tests go red.
### Readings at head a683a7d
<details><summary>Scoped suites (all at a683a7d or at e5a226a, whose
lint and metadata-protocol sources a683a7d does not change)</summary>
- `@objectstack/lint`, whole package: Test Files 241/241, Tests
9760/9760. The three new or extended files: 3/3, 114/114 at a683a7d.
- `@objectstack/metadata-protocol`, whole package: Test Files 371 passed
+ 9 skipped, Tests 23450 passed + 45 skipped. Before the fixes it read
84 failed across 8 files, every one `object-reference-unknown`.
- `@objectstack/cli`: the extractor test plus
`migrate-meta-engine-guidance` 63/63; the `unit` tier 446/446 files,
6395/6395 tests. The `integration` tier is left to CI.
- `@objectstack/objectql`: whole package 6 failed before the fixtures
(all `object-reference-unknown`); the four touched files 68/68 after.
- `@objectstack/runtime`: whole package 1 failed before the fixture
(`object-reference-unknown`); the touched file 2/2 after.
- `@objectstack/mcp` 1589/1589, `@objectstack/plugin-approvals`
1966/1966, `@objectstack/example-showcase` 554/554.
- Typecheck, each exit 0: `lint`, `objectql`, `runtime`,
`metadata-protocol`, `dogfood`, `cli`. The test layers compile under
`tsconfig.test.json`. It caught a stray gate-input key in three new lint
tests, fixed in 72b7cec.
</details>
<details><summary>Dogfood battery (the PR narrows)</summary>
- a683a7d: `VERDICT command-exit 0`, Test Files 490 passed + 3 skipped
(493), Tests 4144 passed + 68 skipped (4212).
- An earlier run at 72b7cec went red, 3 failed in
`action-save-packageless-other-object.dogfood.test.ts`. Its package
bound an action to a showcase object without declaring the showcase
package. Fixed in 04d056b; the battery above is the rerun on the final
head.
</details>
<details><summary>Derived gates (dispatch-gates at a683a7d)</summary>
- 141 derived, 140 run with exit 0. One is NOT MEASURED: `node
scripts/check-plugin-teardown-shape.mjs --self-test` exits 3 because its
positive control is pinned to a commit this shallow clone cannot reach.
It is a checker-health self-test.
- `--ran` reconciliation: 141 accounted for, 0 unrun.
- `check:cross-package-test-inputs` was red at 4ba19b7 and is green at
head (0a916bb).
- `check-nul-bytes` OK. `check-platform-checklist --changed-from
origin/main` OK (4 anchors judged, 0 lost).
- Every CI-only family (type-check lanes, Build Core, Test Core shards,
the merge-queue dogfood shards) is left to this PR's check-runs.
</details>
## Acceptance notes
- **Pins sweep.**
- `os validate` and `os build` on `app-crm`, `app-multi-package`,
`app-starter`, `app-todo` and `app-showcase` all exit 0 with "Running
author-time rules (83)" and no new finding.
- hotcrm, read at 99a4279: every action body that writes grants
`api.write`; its 45 flows bind only declared or platform-provided
objects; its seeds use `defineSeed`.
- The `create-objectstack` template is not affected.
- **Severity.** A flow node's object miss is an error, because that is
the ladder's rule. The existing CLI `flow-trigger-unknown-object` stays
a warning. The divergence is noted here, not changed.
- **Widened door.** An `action` write is now also judged for its params'
`reference` / `objectOverride` objects, as `os validate` already judged
them. The changeset says so.
- **Package closure on the action door (for contract review).** A
package authored in Studio that adds an action to an object another
package owns is now refused until its manifest declares that package.
Flows have already been held to this. It comes with the ladder the card
said to extend, and three in-repo fixtures needed the declaration. If
actions should be judged against the whole served collection even under
a closure, that is a one-line change in the member's options. The report
raises it as an open question.
- **Not judged, same family:**
- hook bodies (`body.capabilities` on a hook has the same gap);
- `ctx.api.transaction` without `api.transaction`;
- the other capability tokens.
- These are listed in the report for the seat.
- **`updateById` is not installed by the sandbox**, yet lint's
`API_WRITE_METHODS` grades it, and the `action-record-write-discarded`
hint recommends `ctx.api.object(…).updateById(…)`. Reported for the seat
to measure; not touched here.
- **Contract review is owed.** The seat runs it.
## Verification
Two-minute check:
```bash
pnpm --filter @objectstack/lint exec vitest run --maxWorkers=2 src/validate-seed-record-keys.test.ts src/validate-action-body-capabilities.test.ts src/validate-object-references.test.ts
```
Expect `Test Files 3 passed (3)` and `Tests 114 passed (114)`.
Read first, by risk:
1. `packages/lint/src/validate-action-body-capabilities.ts`: the masked
regex scanner. A false positive here refuses a publish. The hunk to read
is `bodyApiWriteCalls` and its alias / `boundOnce` handling.
2. `packages/lint/src/authoring-rules.ts` with
`reference-integrity-suite.ts`: the suite entry now dispatches on `seed`
and `action`. The hunk to read is the `runtimeTypes` widening and the
member filter it relies on.
3. `packages/lint/src/validate-object-references.ts`: the new binding
block. The hunk to read is the `extended` exemption and the flow-node
type list.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01Q4EjjQkY5yXZrN9BEA3rEK
<!-- signed: repo:objectstack#6 · hotlong ·
session_01Q4EjjQkY5yXZrN9BEA3rEK -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 91875c7 commit c42a045
32 files changed
Lines changed: 1474 additions & 34 deletions
File tree
- .changeset
- content/docs
- deployment
- getting-started
- ui
- packages
- cli
- src/utils
- test
- lint/src
- metadata-protocol/src
- objectql/src
- qa/dogfood/test
- runtime/src/domains
- spec/src/migrations/entries/semantic
- scripts
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
937 | 937 | | |
938 | 938 | | |
939 | 939 | | |
940 | | - | |
| 940 | + | |
941 | 941 | | |
942 | 942 | | |
943 | 943 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
506 | 506 | | |
507 | 507 | | |
508 | 508 | | |
509 | | - | |
510 | | - | |
| 509 | + | |
| 510 | + | |
511 | 511 | | |
512 | 512 | | |
513 | 513 | | |
| |||
520 | 520 | | |
521 | 521 | | |
522 | 522 | | |
| 523 | + | |
| 524 | + | |
523 | 525 | | |
524 | 526 | | |
525 | 527 | | |
| |||
867 | 869 | | |
868 | 870 | | |
869 | 871 | | |
870 | | - | |
| 872 | + | |
871 | 873 | | |
872 | 874 | | |
873 | 875 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
318 | 318 | | |
319 | 319 | | |
320 | 320 | | |
321 | | - | |
| 321 | + | |
322 | 322 | | |
323 | 323 | | |
324 | 324 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
404 | 404 | | |
405 | 405 | | |
406 | 406 | | |
407 | | - | |
| 407 | + | |
408 | 408 | | |
409 | 409 | | |
410 | 410 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
514 | 514 | | |
515 | 515 | | |
516 | 516 | | |
517 | | - | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
518 | 520 | | |
519 | 521 | | |
520 | 522 | | |
| |||
553 | 555 | | |
554 | 556 | | |
555 | 557 | | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
556 | 603 | | |
557 | 604 | | |
558 | 605 | | |
| |||
657 | 704 | | |
658 | 705 | | |
659 | 706 | | |
| 707 | + | |
| 708 | + | |
660 | 709 | | |
661 | 710 | | |
662 | 711 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 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 | + | |
59 | 106 | | |
60 | 107 | | |
61 | 108 | | |
| |||
0 commit comments