Repository navigation
Commit d5e6b20
fix(metadata-core,objectql,cloud-connection,cli)!: the package upgrade plan counts the fields a package adds through objectExtensions (#34419)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"}
-->
_Requested by **Leehom** · [project
thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XRT27U1unc64yMdYqqPWFjw)_
Fixes #34095
Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: none — `git grep` of `skills/` finds no page that teaches
the upgrade plan's field lists or the schema upgrade confirmation;
`skills/objectstack-platform/references/operations.md` names `os diff`
in one table row ("Compare two ObjectStack config files and detect
breaking changes"), which stays true as written.
This PR is the platform half of the card. The cloud half (service-cloud
`upgradeSideOf`, in the cloud repository) stays with the cloud seat, as
the card body says: it can pass `objectExtensions` beside `objects` in
the side it builds, and the comparison in `@objectstack/metadata-core`
then folds them the same way.
## 维护者速读
- 改了什么:升级预览(升级计划)现在把包通过 `objectExtensions`
加到对象上的字段也算进去:新增、删除、改类型都会出现在预览、受影响列的行数和升级确认判定里。
- 为什么改:HotCRM 6.2.0 升 6.4.0 时预览显示“没有新增字段”,实际升级却加了 7 列;预览漏掉改动,管理员就无法信任预览。
-
风险与回滚:以前直接装上的四种升级现在被拦:扩展字段改类型;同一对象删一个字段同时新增另一个(扩展与扩展,或对象自己的字段与扩展字段互相配对)——这三种回
409,用 `--confirm-upgrade` 确认即可;扩展字段带 `renamedFrom` 改成不存列的类型(如
formula)——回 422 `destructive_type`,确认令牌不管用,要保留可存储的类型或手工搬数据。回滚即还原本
PR,没有数据迁移。
- 席位路线 ①(席位定
A,非维护者裁决):外包拥有的字段被扩展重声明、新版本不再声明时,预览把它列为删除(与新增字段同对象时列为疑似改名),虽然拥有方的字段仍在服务。接受这个偏差并写进文档:它偏向多要一次确认,不会漏掉一次确认。
- 席位路线 ②(席位定 A,非维护者裁决):单删一个扩展字段只列出并计行数,不拒,与卡面「删扩展字段需确认」不同;依据是
`package-upgrade-verdict.ts` 的既有裁决(记录 6709061297):删除的字段由 dry run
报告,任何门都不拒。删字段只在已有规则要求确认处才要确认:同对象同时新增字段(疑似改名),或改成无存储列的类型。
-
先看:`packages/metadata-core/src/package-upgrade-plan.ts`(`objectsByName`
的合并和只读扩展对象的比较)、`packages/cli/src/commands/diff.ts`(扩展对象的打印)、`packages/cloud-connection/src/marketplace-install-rename-planner.ts`(安装门的取侧)。
- 两分钟验证:`pnpm --filter @objectstack/metadata-core exec vitest run
src/package-upgrade-plan.test.ts`,应看到 `objectExtensions: an extension
field counts like an owned one` 一组全部通过。
- 需要你做的:无,席位落地。
## What changes
- **The comparison** (`comparePackageVersions`,
`@objectstack/metadata-core`): `PackageUpgradeSide` gains an optional
`objectExtensions` list. Each side's objects are now the objects as the
registry serves them from that version: the owner's declaration, with
each extension's `fields` merged over it by name (a later writer
replaces the whole field), in ascending `priority` (`200` when none is
declared), equal priorities in the order the side lists them. This is
the registry's own fold (`mergeObjectDefinitions`, applied by
`foldExtendersOntoDefinition`), keyed by the `extend` string verbatim as
the registry keys it. After the fold every existing rule applies to an
extension field unchanged. No new verdict category is added.
- **Objects reached only through an extension** (another package owns
them) are compared by the fields the extensions add, against no fields
when the other version does not reach the object at all. They are never
listed in `plan.objects.added` / `removed`: the upgrade neither creates
nor drops them.
- **The side readers** read `objectExtensions` with the same collection
reader as `objects`: `sideOf` in `@objectstack/objectql` (`planUpgrade`,
the dry run's and the hosted door's plan) and `packageUpgradeSideOf` in
`@objectstack/cloud-connection` (the install-local door's schema verdict
at step 2c′ and the declared-rename planner). The fold itself lives in
one place, the comparison.
- **`os diff`** already passed the whole union stack to the comparison,
so it now compares extension fields too. It also prints the field
changes of an object it reaches only through an extension, under
`objects.NAME.fields`.
- **What the door now refuses that it installed before.** Four arms,
each named in the changeset with its fix:
- an extension field retyped `needs_confirm` or `destructive`: `409
SCHEMA_UPGRADE_CONFIRMATION_REQUIRED`; fix: confirm with the token
(`--confirm-upgrade`);
- an extension field dropped while another stored extension field of the
same object is added: `409`, a suspected rename; fix: the token, or
`renamedFrom` when it is a rename;
- a stored field dropped from an object's own declaration while an
extension of the same object adds a stored field, or the reverse: `409`,
a suspected rename. The owned and the extension fields of one object are
one field map now, so they pair; on `main` they were never compared.
Fix: the token, as for any suspected rename;
- an extension field that declares `renamedFrom` and whose new type
stores no column: `422 VALIDATION_ERROR`, `details.refusals[].reason:
'destructive_type'`, at step 2c″ before any write, because the plan's
type change now reaches `planInstallDeclaredRenames`. No token answers
it, so `--confirm-upgrade` is the wrong fix: keep a stored type for the
renamed field, or carry the values by hand.
Landing point: the fold went into the comparison
(`package-upgrade-plan.ts`), not into each side reader, so the three
callers that build a side (planUpgrade, install-local, `os diff`) share
one fold and the cloud half needs only to pass the list.
## Tests
- `packages/metadata-core/src/package-upgrade-plan.test.ts`, new
top-level describe: an extension field added is listed in
`fields.added`; the rollback lists it in `fields.removed`; an
extension-only object is compared and never listed as an object; a
retyped extension field is a `needs_confirm` / `destructive` type change
and the verdict lists it; a dropped extension field is listed removed
and, alone, is refused by nothing, while dropped beside an added one it
is a suspected rename the verdict lists; the higher `priority` writes
last; CONTROL: an owned-field plan is byte-identical with empty
extension lists and with an unchanged extension of another object.
- `packages/objectql/src/package-upgrade-environment.test.ts`, new
describe, through the real `manifest` service's `planUpgrade` and a
HotCRM-shaped two-package artifact: added extension fields listed; the
rollback lists them and counts the rows holding a value; a retyped
extension field is a type change whose column is read.
-
`packages/cloud-connection/src/marketplace-install-local-upgrade-plan.test.ts`,
new describe, through the install-local door: a retyped extension field
answers `409` with code `SCHEMA_UPGRADE_CONFIRMATION_REQUIRED` naming it
and writes nothing; a drop beside an add answers `409` as a suspected
rename; the dry run lists an added extension field, and adding one or
dropping one alone installs unrefused. The file's test-only `fold`
mirror reads `objectExtensions` too.
-
`packages/cloud-connection/src/marketplace-install-local-declared-rename.test.ts`,
one new case beside the owned `destructive_type` one: an extension field
renamed with `renamedFrom` into a `formula` answers `422` with code
`VALIDATION_ERROR` and reason `destructive_type`, and nothing is
registered, synced, carried or written to the ledger.
- `packages/cli/test/diff-upgrade-plan.test.ts`, new describe: an
extension field added to an owned object prints under it; an
extension-only object prints its type change and is not an added or
removed object.
Red first, each against `origin/main`'s source with the fix committed
(restore leg `git checkout HEAD`, proved by the HEAD blob hash and an
empty `git status`):
- `package-upgrade-plan.ts` at base: `Tests 6 failed | 18 passed (24)`;
the six are the new non-control cases, the control passes.
- `package-upgrade-environment.ts` at base (side without
`objectExtensions`): `Tests 3 failed | 16 passed (19)`.
- `marketplace-install-rename-planner.ts` at base: `Tests 2 failed | 25
passed (27)`, the two `409` cases (the dry run case reads the test's own
fold).
- `diff.ts` at base: `Tests 1 failed | 9 passed (10)`, the
extension-only object.
- The `destructive_type` extension case, by a one-off ablation (`node
scripts/ablation-replace.mjs`, the `objectExtensions` read deleted from
`packageUpgradeSideOf`; anchor 1 → 0, restored to the HEAD blob with
`git diff HEAD` empty): `Tests 1 failed | 27 passed (28)`, the new case
only, which then installed `200`. Restored: `Tests 28 passed (28)`.
## Acceptance notes
- **The card asked for "dropped (requires confirmation)".** The ruling
in `package-upgrade-verdict.ts` (ruling record 6709061297) says a
removed field is reported by a dry run and refused by nothing, and this
dispatch's ruling says extension fields count like owned ones with no
new verdict category. So a dropped extension field is listed in
`fields.removed` with its rows counted, and needs confirmation only
where an owned drop does: beside an added stored field of the same
object (a suspected rename), or as a retype to a type with no stored
column (`destructive`). Both are pinned. Seat route ② (seat decision,
not a maintainer ruling) keeps this reading.
- **An extension that redeclares a field another, uninstalled-here
package owns.** For an object owned outside the upgraded artifact, the
comparison sees only the extension's fields, not the owner's. An
extension that stops redeclaring an owner's field is then listed as a
removed field (and can pair into a suspected rename), although the
owner's field is still served. The registry warns about such
redeclarations ("patch an owner field's display properties instead of
redeclaring it"), and the error leans toward asking a confirmation, not
toward skipping one. Seat route ① (seat decision, not a maintainer
ruling): accepted as documented here.
- **`fieldPatches`** change display properties only and store no column,
so they stay out of the comparison.
- `content/docs/deployment/cli.mdx` describes the schema confirmation in
terms of "a stored field", which reads correctly for an extension field;
it is not edited here.
- Contract review: the upgrade door accepts less (the four arms under
What changes), so a contract-review-tier L2 is owed before the queue.
## Verification
Run on head `9b0824ae` (`origin/main` merged in), every command through
`scripts/pm/os-verify-lock.sh`.
<details><summary>Narrowing battery (full dogfood)</summary>
- `pnpm --filter '@objectstack/dogfood^...' build && pnpm --filter
@objectstack/dogfood test`, no shard: exit 0, `Test Files 475 passed | 3
skipped (478)`, `Tests 4019 passed | 42 skipped (4061)`.
</details>
<details><summary>Package tests and typecheck</summary>
- metadata-core `vitest run`: `Test Files 27 passed (27)`, `Tests 1038
passed (1038)`.
- objectql `vitest run --maxWorkers=2`: `Test Files 604 passed (604)`,
`Tests 13478 passed (13478)`.
- cloud-connection `vitest run --maxWorkers=2`: `Test Files 86 passed
(86)`, `Tests 1258 passed (1258)`.
- cli `vitest run --project unit --maxWorkers=2`: `Test Files 424 passed
(424)`, `Tests 6029 passed (6029)`.
- typecheck of metadata-core, objectql, cloud-connection and cli (each
with its test layer): exit 0.
</details>
<details><summary>dispatch-gates</summary>
- At `432c9d2c` (before the main merge, same changed paths): 72
families, 71 exit 0; `check:dual-build-cjs-loads` exit 3 (prerequisite:
every package's `dist`), NOT MEASURED here, CI runs it. `--ran`
reconciliation: 72 derived, 72 run, 0 unrun.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01FEkQ5pNoRjsgMJKr5utN33)_
<!-- signed: repo:objectstack#1 · os-project-manager ·
session_01FEkQ5pNoRjsgMJKr5utN33 -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent d18d54b commit d5e6b20
10 files changed
Lines changed: 400 additions & 28 deletions
File tree
- .changeset
- packages
- cli
- src/commands
- test
- cloud-connection/src
- metadata-core/src
- objectql/src
| 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 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| 104 | + | |
104 | 105 | | |
105 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
106 | 115 | | |
107 | | - | |
108 | 116 | | |
109 | 117 | | |
110 | 118 | | |
| |||
138 | 146 | | |
139 | 147 | | |
140 | 148 | | |
141 | | - | |
| 149 | + | |
142 | 150 | | |
143 | 151 | | |
144 | 152 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
290 | 290 | | |
291 | 291 | | |
292 | 292 | | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
293 | 315 | | |
294 | 316 | | |
295 | 317 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
85 | 89 | | |
86 | 90 | | |
87 | 91 | | |
| |||
494 | 498 | | |
495 | 499 | | |
496 | 500 | | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
50 | 55 | | |
51 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
52 | 61 | | |
53 | 62 | | |
54 | 63 | | |
| |||
0 commit comments