Repository navigation
Commit 3e19223
fix(lint)!: the object_extension publish door judges a computed field an extension adds by the build's field-formula pass, against the extended object as served (#33119)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} -->
_Requested by **Tesla** · [project
thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoWK5rFW1SUGSkDw9iatZE4f)_
Fixes #33072
Clause-②: no (narrowing) — the runtime `object_extension` publish door
(Studio's add-field on a `.custom` pair, `PUT
/api/v1/meta/object_extension/TARGET`, the MCP and AI authoring doors)
now refuses an extension whose computed field carries an `expression`
`os build` refuses. No exported type or signature changes. Measured
first-party exposure: 0 newly refused items.
Metadata-protocol: narrowed
Skills-docs: none owed — this PR edits
`content/docs/deployment/validating-metadata.mdx` (the CEL row's runtime
column gains `ᵒˣ`, and the object extension door paragraph names the
formula pass); `skills/objectstack-data` teaches
`defineObjectExtension({ extend, fields })` and the computed-field rules
without saying the runtime door is exempt, so the door now gives the
verdict the build already gives.
## 维护者速读
- 改了什么:运行时发布对象扩展(Studio 在 `.custom` 对上加字段、`PUT
/api/v1/meta/object_extension/对象`、MCP/AI 作者)时,现在会对扩展新增的计算字段跑和 `os build`
相同的公式检查(同一条规则、同一份遍历,不另写一套)。公式调用不存在的函数、读对象上没有的字段,发布返回 422
`INVALID_METADATA`,规则 id 与 build 相同,位置为 `object '对象' ·
objectExtensions[0] · field '字段'
expression`。重新发布时,按「去掉本包已存扩展后的目标对象」来判(写入会替换它),与 build 看到的一致。
- 为什么改:#33070 之后 build 会拒这类扩展字段,但运行时发布口只跑了保留词检查,build 拒的计算字段经 Studio
仍能发布,之后每行读出 null 或报错。
- 风险与回滚:收窄;第一方实测 0 处受影响(showcase 扩展 3 个普通字段、plugin-auth 扩展 1 个 secret
字段、HotCRM
无对象扩展)。草稿保存不受影响;已存的行再次发布才会被判。已知限制:整包发布草稿(`publishPackageDrafts`)时,若草稿依赖同批的另一个扩展草稿会被拒(#33152),先用单项发布口发布该扩展即可。回滚即
revert。
-
先看:`packages/lint/src/validate-expressions.ts`(`extensionWrite`)、`packages/lint/src/authoring-rules.ts`(`runtimeTypes`
加
`object_extension`)、`packages/metadata-protocol/src/protocol-authoring-gate.ts`(`objectExtensionWriteFold`
/
`withTargetFoldedWithout`)、`packages/runtime/src/domains/meta-object-extension-item.test.ts`(真实保存+发布口的
#33072 一节,6 条)。
- 两分钟验证:`pnpm --filter @objectstack/runtime exec vitest run
src/domains/meta-object-extension-item.test.ts -t "33072"`(需先构建
metadata-protocol),预期 6
条全过:坏公式被拒、合法公式发布、重新发布时去掉被引用字段被拒、改指查找字段后按新目标判、目标有已存对象行时同样被拒。
- 需要你做的:无,席位落地。
## What changes
**Lint: the door runs the build's one pass.**
- **`packages/lint/src/authoring-rules.ts`.** `validateStackExpressions`
declares `object_extension` in `runtimeTypes`, so
`runtimeAuthoringRulesFor('object_extension')` answers
`validateStackExpressions`, `validateSecurityRoleWord` (registry order).
- **`packages/lint/src/validate-expressions.ts`.** On an
`object_extension` write (`runtimeWriteType`),
`runStackExpressionPasses` runs exactly one pass, by construction:
#32875's extension walk (`judgeFieldFormula` over each field of each
`objectExtensionsByTarget` entry). The object walk and the flows walk
read an empty list under it, and the function returns right after the
extension walk. No second field walk and no second fold: the door's
snapshot is `{ objects: LIVE_OBJECTS, permissions, books, datasets,
objectExtensions: [WRITTEN_ENTRY] }`, and the walk reads the target
through the indexes already built over `objectsAsServed`.
- **`packages/lint/src/runtime-gate.ts`.** Comment only, on the
`object_extension` row of `TYPE_TO_STACK_KEY`.
**Metadata-protocol: the target is the one the write will serve.**
A package holds one extension per target, so a republish replaces the
stored one. The gate used to hand the walk the target as served before
the write, with the stored extension still folded in. That was wrong
both ways: dropping a field the extension's own formula reads was
admitted, and a formula over a lookup the same write re-targets was
judged over the old target.
- **`packages/metadata-protocol/src/protocol-authoring-gate.ts`.**
`objectExtensionWriteFold` names the narrowing for an `object_extension`
write that names a package: the registry's existing
`withoutExtensionsOf` fold option, on the body's `extend` target.
`withTargetFoldedWithout` takes only the target's entry from
`listItems('object', undefined, { withoutExtensionsOf })` and keeps
every other object as served, because the option is package-wide and the
package's extensions of other objects are not being written. The
narrowing is keyed on the singular type, so the plural retry narrows the
same way.
- **`protocol-stored-collection-fold.ts`,
`protocol-object-extender-fold.ts`, and the two private wrappers in
`protocol.ts`** (amendment 6858898742). There is a new optional trailing
argument on each fold: `targetFold` on `foldStoredCollection`, and
`withoutExtensionsOf` on `foldObjectExtendersFromRegistry`. They apply
the same narrowing to a target that has its own stored `object` row, and
only to that row. Every other caller passes nothing and reaches the call
it made before. With both `onlyExtensionsOf` and `withoutExtensionsOf`
given, both are handed to the registry, which leaves out a contribution
either one leaves out; no caller passes both today. Both method
docblocks state this.
**Docs, migration and changeset.**
- **`content/docs/deployment/validating-metadata.mdx`.** The CEL row's
runtime column is now `✓ᶠᵃᶜʰᵒˣᵒᵛᵖ`: `ᵒˣ` goes before `ᵒ`, because after
`ᵖ` the longest-first reading would take `ᵖᵒ`. One sentence was added to
the object extension door paragraph.
-
**`packages/spec/src/migrations/entries/semantic/18.object-extension-door-computed-field-expression-judged.ts`**
is the ADR-0087 D3 entry the narrowing owes. There is no D2 conversion,
because how a refused expression is repaired is the author's fact.
- **`.changeset/33072-object-extension-door-formula.md`**:
`@objectstack/lint` minor, `@objectstack/spec` minor,
`@objectstack/metadata-protocol` patch, both declaration lines, BREAKING
banner, migration.
**Known limit (#33152).** A package-wide draft publish
(`publishPackageDrafts`) whose drafts depend on a sibling extension
draft is refused, because that batch's pending set carries no extension
drafts. Publishing the extension first through the per-item door works.
The same gap exists on `main` for object drafts. The changeset, the
entry and the `[#33072]` docblocks state it.
## Tests
1. **`packages/lint/src/runtime-gate.object-formula-writes.test.ts`**,
new describe `#33072` (10 cases) at the real gate
(`runRuntimeAuthoringRules`). Cases:
- the roster;
- LIT: `sqrt(record.amount)` is refused under `expression-invalid` at
the build's location;
- LIT: a read of a field the target does not serve is refused;
- LIT: a stored field reading another record is an advisory, never a
422;
- PARITY: on one shared input, the door's findings deep-equal the
build's, for an error and for an advisory;
- CONTROL: a valid formula, and a formula reading a field the same
extension adds, both publish clean;
- an undeclared target is judged on what does not depend on its fields;
- the differential;
- the narrowing;
- CONTROL: the object save door is unchanged.
2.
**`packages/runtime/src/domains/meta-object-extension-item.test.ts`**,
new describe `[#33072]` (6 cases) through the real `saveMetaItem` +
`publishMetaItem` over better-sqlite3 and the real
`ObjectQL`/`SchemaRegistry`. Cases:
- LIT `sqrt(record.name)` → 422 `expression-invalid` at `object
'crm_account' · objectExtensions[0] · field 'score__c' expression`, the
field not served and the row left a draft;
- LIT: a misspelt field read is refused;
- CONTROL: a valid formula publishes;
- and three republish cases, each over a stored self:
- lenient direction: dropping `bonus__c` while `total__c` reads it → 422
(was 200);
- strict direction: re-targeting lookup `ref__c` from `crm_region` to
`crm_account` with `via__c: record.ref__c.name` → 200 (was 422 against
`crm_region`). This is also the first hop pinned on the real door;
- a target with its own stored `object` row (the pair's runtime-authored
`crm_custom_lead`) → 422.
3.
**`packages/metadata-protocol/src/protocol-authoring-gate.extension-write-fold.test.ts`**
(new, 7 cases):
- `objectExtensionWriteFold`: which writes narrow;
- `withTargetFoldedWithout`: only the target is replaced;
- `foldObjectExtendersFromRegistry`: what each package argument hands
the registry, both included.
4.
**`packages/lint/src/validate-security-posture.runtime-surface.test.ts`**:
the #31998 extension case's roster and `rulesRun` pins now read
`['validateStackExpressions', 'validateSecurityRoleWord']`.
**Reproduction at `main` `2c98485d`**, with the pins committed first: 8
of the 10 lint door cases were red. The door published
`sqrt(record.amount)` with 0 errors while the build refused it.
<details><summary>Ablations (fix committed first, mutated through
scripts/ablation-replace.mjs, each restore read blob == HEAD and git
diff HEAD empty)</summary>
| # | Mutation | Expected | Observed |
|:--|:--|:--|:--|
| 1 | `object_extension` dropped from the rule's `runtimeTypes`, lint
rebuilt, dist marker proved absent | lint door pins and runtime LIT pins
red, controls green | lint 8 failed / 41 passed; runtime 2 failed (both
LIT), CONTROL passed |
| 2 | the object-walk fence on an extension write removed | the
narrowing pin red | 1 failed (the narrowing pin) |
| 3 | host narrowing off (`extensionWrite` forced `undefined`),
metadata-protocol rebuilt | the three republish pins red, the r0 pins
green | 3 failed / 3 passed |
| 4 | stored half off (the target-name match in `foldStoredCollection`
broken), metadata-protocol rebuilt | only the stored-object-row pin red
| 1 failed / 5 passed |
</details>
## Acceptance notes
- **Exposure, measured at `2c98485d`:** `examples/app-showcase` has one
extension entry with 3 plain fields; `packages/plugins/plugin-auth` has
one with a `secret` field; HotCRM (`4f0ffd8`, re-verified at `0009f58`)
has none. 0 carry an `expression`, so the door refuses nothing
first-party.
- **Location agreement is index-exact for a package with one extension
entry.** The door's snapshot always holds the written entry at
`objectExtensions[0]`. The build of a package with several entries
prints that entry's own index, and
`packages[j].manifest.objectExtensions[i]` in an artifact stack. Rule
id, object, field and message are the same in every case.
- **N1.** A served `object_extension` draft's `_diagnostics` now carries
the formula verdict, because `draftPublishVerdict` reads the same
roster. No prose face names it, and no pin covers it.
- **N3.** The real door now pins a hop (the strict republish case).
There is still no real-door pin for `label()` or for the draft
`_diagnostics`. The lint "(the differential)" case passes by the
object-walk fence.
- **N4.** An extension of an object outside the written package's
closure is refused first by the item gate (`objectExtensionItemRefusal`
step 5), so at the door the formula pass never sees it. Only the lint
API reaches the "judged on what does not depend on the target's fields"
arm.
- **N5, N6.** The two folds' docblocks describe their optional arguments
and the both-given case. The changeset names
`@objectstack/metadata-protocol` (patch), which carries the host half.
- **Filed by the seat, out of scope here:**
- #33152, batch publish with interdependent extension drafts (the known
limit above);
- #33153, formula cycles through an extension;
- #33154, an extension's `validations` judged at neither door, although
the registry registers them on the object.
- **Ruling grep** (`ruling|Ruling-ref|maintainer|⛔`) over the surface:
the readings that bear on this diff are "the per-write snapshot is not
widened for cross-item judgments" (rulings `5791822697` item 3 and
`6104584601`) and "⛔ no context row for symmetry" (`runtime-gate.ts`).
This diff adds no context collection and no snapshot key; it narrows the
existing `objects` list for the target. None is reversed.
- **File surface.** Production changes are in `packages/lint`, in
`packages/metadata-protocol` (the gate plus the two folds' optional
pass-through, amendment 6858898742), in the docs page and in the
semantic entry. `packages/runtime` is test only.
- **Release:** 18.4.0 shipped before this PR opened, so this rides the
next release train.
## Verification
Readings at HEAD `f57cc273` unless noted. `f57cc273` is the r2 prose and
metadata commit on top of `ac6dd79d`, which merged `origin/main`
`bf02d33b` cleanly. main is ahead again and merges clean; it was not
merged again.
<details><summary>Tests</summary>
Each heavy command ran under `scripts/pm/os-verify-lock.sh` (VERDICT
command-exit 0). Exit codes were captured before any pipe.
- At `f57cc273`, after `pnpm build --concurrency=2` (exit 0):
- `@objectstack/metadata-protocol` full suite: Test Files 338 passed | 7
skipped (345), Tests 22810 passed | 36 skipped;
- `@objectstack/spec` full suite: Test Files 931 passed (931), Tests
28389 passed | 1 todo;
- `meta-object-extension-item.test.ts`: 29 passed (29), the 6 `[#33072]`
cases among them.
- At `ac6dd79d` (the r1 head; r2 changes comments, the changeset, the
entry's text, one fold's option hand-off for a case no caller reaches,
and test files only):
- `pnpm check:dual-build-cjs-loads` exit 0;
- dogfood battery (owed by the `(narrowing)` arm): 460 files and 3874
tests passed, 42 skipped;
- `@objectstack/runtime` full suite: 11938 passed, 19 skipped;
- `@objectstack/lint` full suite: 8751 passed.
- CI at `ac6dd79d`: 68 check runs, every one success or skipped.
</details>
<details><summary>Gates</summary>
`node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` at `f57cc273` derives 119 families. Each ran
with stdin from `/dev/null`: all 119 exited 0. The `--ran`
reconciliation read: `119 derived famil(ies) accounted for — 119 run, 0
NOT-MEASURED`.
</details>
---
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01L9qibwwiSN1TXWjohzCZN9
<!-- signed: domain:spec#2 · os-tesla · session_01L9qibwwiSN1TXWjohzCZN9
-->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 68972cd commit 3e19223
14 files changed
Lines changed: 588 additions & 28 deletions
File tree
- .changeset
- content/docs/deployment
- packages
- lint/src
- metadata-protocol/src
- runtime/src/domains
- spec/src/migrations/entries/semantic
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
494 | 494 | | |
495 | 495 | | |
496 | 496 | | |
497 | | - | |
| 497 | + | |
498 | 498 | | |
499 | 499 | | |
500 | 500 | | |
| |||
606 | 606 | | |
607 | 607 | | |
608 | 608 | | |
609 | | - | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
610 | 613 | | |
611 | 614 | | |
612 | 615 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
821 | 821 | | |
822 | 822 | | |
823 | 823 | | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
824 | 841 | | |
825 | | - | |
| 842 | + | |
826 | 843 | | |
827 | 844 | | |
828 | 845 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
336 | 336 | | |
337 | 337 | | |
338 | 338 | | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
289 | 289 | | |
290 | 290 | | |
291 | 291 | | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
292 | 297 | | |
293 | 298 | | |
294 | 299 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2262 | 2262 | | |
2263 | 2263 | | |
2264 | 2264 | | |
| 2265 | + | |
| 2266 | + | |
| 2267 | + | |
| 2268 | + | |
| 2269 | + | |
| 2270 | + | |
| 2271 | + | |
| 2272 | + | |
| 2273 | + | |
| 2274 | + | |
| 2275 | + | |
| 2276 | + | |
| 2277 | + | |
2265 | 2278 | | |
2266 | 2279 | | |
2267 | 2280 | | |
| |||
2321 | 2334 | | |
2322 | 2335 | | |
2323 | 2336 | | |
| 2337 | + | |
| 2338 | + | |
| 2339 | + | |
| 2340 | + | |
| 2341 | + | |
| 2342 | + | |
| 2343 | + | |
2324 | 2344 | | |
2325 | 2345 | | |
2326 | 2346 | | |
| |||
2827 | 2847 | | |
2828 | 2848 | | |
2829 | 2849 | | |
2830 | | - | |
| 2850 | + | |
2831 | 2851 | | |
2832 | 2852 | | |
2833 | 2853 | | |
| |||
3527 | 3547 | | |
3528 | 3548 | | |
3529 | 3549 | | |
3530 | | - | |
| 3550 | + | |
| 3551 | + | |
| 3552 | + | |
3531 | 3553 | | |
3532 | 3554 | | |
3533 | 3555 | | |
| |||
4003 | 4025 | | |
4004 | 4026 | | |
4005 | 4027 | | |
| 4028 | + | |
| 4029 | + | |
| 4030 | + | |
| 4031 | + | |
| 4032 | + | |
| 4033 | + | |
4006 | 4034 | | |
4007 | 4035 | | |
4008 | 4036 | | |
| |||
4044 | 4072 | | |
4045 | 4073 | | |
4046 | 4074 | | |
| 4075 | + | |
| 4076 | + | |
| 4077 | + | |
4047 | 4078 | | |
4048 | 4079 | | |
4049 | 4080 | | |
| |||
0 commit comments