Repository navigation
Commit c363084
fix(metadata-protocol)!: the adopt-orphans door asks the
<!-- claude-projects-attribution: {"github_login":"os-project-manager"}
-->
_Requested by **Leehom** · [project
thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XUSbzmMRfCQ13hL4Jffkmqp)_
Fixes #28735
Clause-②: no (narrowing)
Metadata-protocol: narrowed
Skills-docs: none — no file under `skills/**` teaches the adopt-orphans
door or a field spelled `__c` (0 hits for `adopt-orphans`,
`reassignOrphanedMetadata` and `[a-z0-9]__c`).
## 维护者速读
- **改了什么**:「收养孤儿元数据」(`POST /api/v1/packages/:id/adopt-orphans`) 现在也问
`__c` 判官:要把一个不属于任何包、带 `x__c` 字段的对象收进普通包(不是 `.custom`
配对包)时,整次收养被拒,一行都不动;收进基础包的 `.custom` 配对包照常放行。另外,草稿发布时的 `__c`
检查对「代码包自带的受封对象」不再先开口,让存储层的 `NOT_OVERRIDABLE` 作为唯一答复,和上面两道检查一致。
- **为什么改**:#28564 让保存、恢复、发布、复制、`os validate`、市场安装都拒绝普通包里的 `__c`
字段,唯独收养这道门不问,等于留了一条把 `x__c` 塞进普通包的后路(#28724 合同审查的两条 should-fix)。
- **风险与回滚**:收窄只拦今天没人用的情形:在本 PR 基点实测
`examples/**`、`packages/*/src`(不含测试)里 `[a-z0-9]__c` 字段 0
个(文本命中全在文档注释里)。沿用保存门的 `VALIDATION_ERROR` / 400 信封,不新增错误码,不动 spec。回滚即
revert,无数据迁移。
- **先看**:`packages/metadata-protocol/src/protocol.ts` 的
`reassignOrphanedMetadata`(第一次 `update` 之前新加的判官块);同文件
`promoteDraftForPublish` 里 `__c`
块的条件;`packages/metadata-protocol/src/protocol.extension-field-suffix.test.ts`
新增的 4b 节和受封用例。
- **两分钟验证**:`pnpm --filter @objectstack/metadata-protocol exec vitest
run src/protocol.extension-field-suffix.test.ts`,预期 `Tests 24 passed
(24)`(main 上新增的 3 条红)。
- **需要你做的**:无,席位落地(合同审查后)。
## What changes
- **The adopt door asks the `__c` judge** (`reassignOrphanedMetadata`,
REST `POST /api/v1/packages/:id/adopt-orphans`). After the orphan list
is read and before the first storage `update`, every ACTIVE `object` row
the adoption would rebind is handed to `judgeExtensionFieldSuffix` as
the TARGET package's own object (`{ packageId: targetPackageId, objects
}`), the same call `duplicatePackage` makes. Any refused field throws
`extensionFieldSuffixRefusalError`: `400 VALIDATION_ERROR`, the message
case (a)'s sentence, `issues[]` locating each field at
`objects.OBJECT.fields.FIELD`. The adoption is refused whole: no row
moves and `applyRegistryWriteThrough` never runs. An adoption into the
base's `.custom` pair is admitted (a pair's own objects are not judged).
An unparseable row body is left to the loop, as `duplicatePackage`
leaves it. The type folds through `canonicalMetaType`, as the loop's own
registry limb does.
- **Drafts.** Ruling 1 names active rows. An adopted package-less draft
is rebound in storage only (unchanged), and when it is promoted the
promotion asks the same judge against its binding, so `x__c` still
cannot go live in a plain package.
- **The promotion's suffix block is seal-gated**
(`promoteDraftForPublish`): `if (draftForGate && singularType ===
'object' && !this.isSealedManagedItem(singularType, request.name))`,
exactly like the D9.9 block and the namespace-prefix block above it. A
sealed draft carrying `x__c` now reaches the store's one
`NOT_OVERRIDABLE` / 403 (`repo.promoteDraft` → `assertAllowed`) instead
of "rename the field". For a non-object type the judge answered
`undefined` already, so adding `singularType === 'object'` to the
condition changes nothing else.
- **No new error code, no `packages/spec/**` change, no ui change, no
new gate.** Not touched: `protocol-packaged-base-refusal.ts`,
`stored-row-binding.ts`, `withRowBinding`, the automation boot pull.
- **Changeset**
`.changeset/28735-adopt-orphans-extension-field-suffix.md`: `minor` on
`@objectstack/metadata-protocol` (kind `narrowed`), with the BREAKING
banner, both declaration lines, the migration paragraph and the ADR-0087
`not-required (no-migration-prescription)` disposition.
**Why `Metadata-protocol: narrowed`.** An adoption into a plain package
that admitted an object row carrying `x__c` is now refused: one more
write door applies the requirement #28564 declared `narrowed` at its
doors. Nothing an author could save before is refused at the save door
(the package-less save is unchanged); what narrows is the set of package
contents the adopt door can produce.
## Tests
New in
`packages/metadata-protocol/src/protocol.extension-field-suffix.test.ts`
(the #28564 file, its stub engine and helpers):
- **§4b, adopt-orphans.** (1) A package-less active `probe_env` with
`x__c`, saved through the real save door (not judged: no package),
adopted into the plain `app.probe-bound`: refused with case (a)'s
envelope and sentence, `issues` path `objects.probe_env.fields.x__c`;
`engine.update` never called, `applyRegistryWriteThrough` never called;
the store reads back the row still package-less and active. (2) Mixed: a
clean `probe_clean` beside `probe_env` (`x__c`) into the plain package:
refused whole; both rows stay package-less; no write-through. (3)
CONTROL: the same `x__c` row adopted into `app.probe-bound.custom` is
admitted (`success: true`, `reassignedCount: 1`) and the row reads back
bound to the pair; a clean row into the plain package moves too.
- **§3b, the seal gate.** The stub registry ships `probe_sealed`
(`getArtifactItem` answers `_packageId: com.acme.shipper`, `_provenance:
package`), so `isSealedManagedItem('object','probe_sealed')` holds. A
draft of it carrying `x__c`, bound to the plain package, is staged as a
row stored before the gate (the save door refuses that draft first,
`refusePackagedBaseOverride`). `publishMetaItem` answers
`NOT_OVERRIDABLE` / 403, and the draft is still a draft. The gate is
reachable this way only (a pre-gate stored row); no public save produces
that draft today.
<details><summary>Red on base, green on head</summary>
- **Base** (`protocol.ts` from `db357f6d`, the new tests at head):
`Tests 3 failed | 21 passed (24)`. The seal pin: `expected { code:
'VALIDATION_ERROR', …(1) } to deeply equal { Object (code, status) }`.
The two adopt refusals: `expected null to be an instance of Error` (the
adoption succeeded). The `.custom` CONTROL is green on base and head, as
a control should be. Restore: `git checkout HEAD -- protocol.ts`, `git
diff HEAD` empty.
- **Head**: `Tests 24 passed (24)`.
</details>
<details><summary>Ablations (one-off, from committed HEAD, `node
scripts/ablation-replace.mjs`)</summary>
The suite imports `./protocol.js` from source, so no build sits between
mutation and run.
- **Adopt call removed.** `if (suffixRefusals.length > 0) throw
extensionFieldSuffixRefusalError(suffixRefusals);` in
`reassignOrphanedMetadata` replaced with `void suffixRefusals; /*
ABLATE_28735_ADOPT */`: anchor 1 → 0, blob `065792a3d3d0` →
`618118ae6818`. `Tests 2 failed | 22 passed (24)`: the two adopt
refusals. Restored: blob equals HEAD `065792a3d3d0`, `git diff HEAD`
empty.
- **Seal gate removed.** The promotion's suffix-block condition replaced
with `if (draftForGate /* ABLATE_28735_SEAL */)`: anchor 1 → 0, blob
`065792a3d3d0` → `7a4b2a52267f`. `Tests 1 failed | 23 passed (24)`: the
seal pin. Restored: blob equals HEAD, `git diff HEAD` empty.
</details>
## Acceptance notes
- **The other two judges (ruling 2).** Not added. The namespace-prefix
judge (`objectNamespacePrefixViolation`) and the owner judge
(`permissionSetOwnerBindingRefusal`) are skipped at this door too. See
the report's `open_questions` for whether they should ride this call and
what that costs.
- **The judge module's door list.**
`protocol-extension-field-suffix.ts`'s header lists the doors that call
the judge and does not yet name the adopt door. That file is outside the
claim's file surface, so it is left; the call site's comment and
`reassignOrphanedMetadata`'s header carry the reference.
- **Narrowing count.** 0 fields spelled `[a-z0-9]__c` in `examples/**`
and `packages/*/src` outside tests (`git grep -nE '[a-z0-9]__c\b'`, 10
textual hits, all doc comments, including the two this PR adds), so no
package-less `object` row in the tree carries one.
## Verification
All readings at head `8bdde034` (the fix `67c08437` + changeset
`6f6d2f35`, merged once with `origin/main` `7a48bf73`, which carries
#28734's `protocol.ts` edit; clean merge, both kept), after `pnpm
install --frozen-lockfile` and a full `pnpm turbo run build
--concurrency=2` (118/118 tasks).
<details><summary>Package tests, typecheck, lint</summary>
- `pnpm --filter @objectstack/metadata-protocol test`: `Test Files 294
passed | 4 skipped (298)`, `Tests 22012 passed | 26 skipped (22038)`
(lock VERDICT command-exit 0).
- `pnpm --filter @objectstack/metadata-protocol typecheck`: exit 0 (the
package type-checks its own tests: `check:type-check-debt` reports 0
packages hiding tests from tsc).
- `pnpm exec eslint --no-inline-config` on the two touched files: exit
0.
- REST door and the adopt pins downstream: `@objectstack/runtime`
`src/domains/packages-adopt-orphans-readonly.test.ts` +
`src/package-duplicate-adopt-org-scope.integration.test.ts` 13/13;
`@objectstack/objectql` (reads metadata-protocol from `dist`, rebuilt)
`protocol-adopt-orphans-object-registry`,
`protocol-adopt-orphans-draft-view-registry`,
`protocol-package-lifecycle`, `protocol-packageless-overlay-migration`,
`protocol-sentinel-owner-package-save-refusal` 44/44 (pre-merge head
`6f6d2f35`). The REST door relays the protocol's throw through
`deps.errorFromThrown`, as `duplicate` does, so the code, status and
`issues` reach the wire unchanged; no route code moved.
</details>
<details><summary>Full dogfood battery (the `(narrowing)` arm)</summary>
- Head `8bdde034`: `pnpm --filter @objectstack/dogfood test` under the
lock, VERDICT command-exit 0, `Test Files 374 passed | 3 skipped (377)`,
`Tests 3034 passed | 28 skipped (3062)`. No failure.
- Also green at the pre-merge head `6f6d2f35` (same counts).
</details>
<details><summary>Derived gates (`dispatch-gates.mjs --commands`, 61
families)</summary>
- All 61 exit 0 at `8bdde034`; `dispatch-gates --ran`: `61 derived, 61
run, 0 NOT-MEASURED, 0 UNRUN`.
- `check:type-check-debt` (under the lock): `check-type-check-coverage:
OK — 126/129 workspace packages type-checked`, `--re-measure: OK`.
- First pass at `6f6d2f35` had three PREREQUISITE reds (no full build
yet: `check:dts-closure`, `check:dual-build-cjs-loads`; shallow clone:
`check-plugin-teardown-shape --self-test`) and one queue-timeout
(`check:type-check-debt`, behind the dogfood run). None measured
anything; all four are green in the `8bdde034` pass after the full build
and `git fetch --depth=1` of the fixture commit.
- `pnpm lint` (repo-wide) and the CI-only families are CI's; see the
PR's check-runs.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01FEkQ5mTYb1BTJNRqf3bdJ8)_
---------
Co-authored-by: Claude <noreply@anthropic.com>__c judge against the target package; the promotion's suffix block is seal-gated (#28768)1 parent 8afaf12 commit c363084
3 files changed
Lines changed: 142 additions & 3 deletions
File tree
- .changeset
- packages/metadata-protocol/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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
532 | 533 | | |
533 | 534 | | |
534 | 535 | | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
535 | 564 | | |
536 | 565 | | |
537 | 566 | | |
| |||
567 | 596 | | |
568 | 597 | | |
569 | 598 | | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
570 | 649 | | |
571 | 650 | | |
572 | 651 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23957 | 23957 | | |
23958 | 23958 | | |
23959 | 23959 | | |
23960 | | - | |
23961 | | - | |
| 23960 | + | |
| 23961 | + | |
| 23962 | + | |
| 23963 | + | |
23962 | 23964 | | |
23963 | 23965 | | |
23964 | 23966 | | |
| |||
26833 | 26835 | | |
26834 | 26836 | | |
26835 | 26837 | | |
| 26838 | + | |
| 26839 | + | |
| 26840 | + | |
| 26841 | + | |
| 26842 | + | |
| 26843 | + | |
| 26844 | + | |
| 26845 | + | |
| 26846 | + | |
| 26847 | + | |
| 26848 | + | |
| 26849 | + | |
| 26850 | + | |
| 26851 | + | |
| 26852 | + | |
26836 | 26853 | | |
26837 | 26854 | | |
26838 | 26855 | | |
| |||
26865 | 26882 | | |
26866 | 26883 | | |
26867 | 26884 | | |
| 26885 | + | |
| 26886 | + | |
| 26887 | + | |
| 26888 | + | |
| 26889 | + | |
| 26890 | + | |
| 26891 | + | |
| 26892 | + | |
| 26893 | + | |
| 26894 | + | |
| 26895 | + | |
| 26896 | + | |
| 26897 | + | |
| 26898 | + | |
| 26899 | + | |
| 26900 | + | |
| 26901 | + | |
| 26902 | + | |
| 26903 | + | |
| 26904 | + | |
| 26905 | + | |
| 26906 | + | |
| 26907 | + | |
| 26908 | + | |
26868 | 26909 | | |
26869 | 26910 | | |
26870 | 26911 | | |
| |||
0 commit comments