|
4 | 4 | * [ADR-0146 D10, #28564] The `__c` extension-field reservation at every door |
5 | 5 | * of this package — one judge (`protocol-extension-field-suffix.ts`), asked by |
6 | 6 | * the save door, the restore doors, the draft promotion (`publishMetaItem` and |
7 | | - * the `publishPackageDrafts` batch that shares it) and `duplicatePackage`; and |
| 7 | + * the `publishPackageDrafts` batch that shares it), `duplicatePackage` and |
| 8 | + * ([#28735]) `reassignOrphanedMetadata`, the adopt-orphans door; and |
8 | 9 | * `installPackage`, which its closed manifest already covers. |
9 | 10 | * |
10 | 11 | * Maintainer, verbatim: 「扩展字段用 __c 后缀,只有 .custom 包能用。」 |
@@ -532,6 +533,34 @@ describe('[ADR-0146 D10] the draft promotion refuses an object draft carrying a |
532 | 533 | }); |
533 | 534 | }); |
534 | 535 |
|
| 536 | +describe('[#28735] the promotion\'s suffix block is not asked of sealed managed content', () => { |
| 537 | + /** A code package's shipped object, as `SchemaRegistry.getArtifactItem` stamps it. */ |
| 538 | + const SHIPPED = 'probe_sealed'; |
| 539 | + const sealedHarness = () => { |
| 540 | + const h = makeProtocol(); |
| 541 | + h.engine.registry.getArtifactItem = (type: string, name: string) => (type === 'object' && name === SHIPPED |
| 542 | + ? { name, label: 'Sealed', _packageId: 'com.acme.shipper', _provenance: 'package' } |
| 543 | + : undefined); |
| 544 | + return h; |
| 545 | + }; |
| 546 | + |
| 547 | + it('a draft of a shipped object carrying `x__c`, stored before the rule, answers the store\'s NOT_OVERRIDABLE, not "rename the field"', async () => { |
| 548 | + const h = sealedHarness(); |
| 549 | + // The save door refuses this draft (`refusePackagedBaseOverride`), so it is staged as a row stored before the gate. |
| 550 | + const row: Row = { |
| 551 | + id: 'r_sealed', type: 'object', name: SHIPPED, organization_id: null, package_id: BOUND, state: 'draft', |
| 552 | + metadata: JSON.stringify(obj(SHIPPED, 'Sealed', 'x__c')), |
| 553 | + }; |
| 554 | + h.rows.set(keyOf(row as unknown as Record<string, unknown>), row); |
| 555 | + |
| 556 | + const { error } = await attempt(() => h.protocol.publishMetaItem({ type: 'object', name: SHIPPED, packageId: BOUND })); |
| 557 | + |
| 558 | + expect(error).toBeInstanceOf(Error); |
| 559 | + expect({ code: error.code, status: error.status }).toEqual({ code: 'NOT_OVERRIDABLE', status: 403 }); |
| 560 | + expect(storedObjects(h)).toEqual([{ row: SHIPPED, state: 'draft', binding: BOUND, fields: ['title', 'x__c'] }]); |
| 561 | + }); |
| 562 | +}); |
| 563 | + |
535 | 564 | // ═══════════════════════════════════════════════════════════════════════════ |
536 | 565 | // 4. duplicatePackage, judged against the target id |
537 | 566 | // ═══════════════════════════════════════════════════════════════════════════ |
@@ -567,6 +596,56 @@ describe('[ADR-0146 D10] duplicatePackage from a `.custom` pair into a plain id |
567 | 596 | }); |
568 | 597 | }); |
569 | 598 |
|
| 599 | +// ═══════════════════════════════════════════════════════════════════════════ |
| 600 | +// 4b. reassignOrphanedMetadata (the adopt-orphans door), judged against the target id |
| 601 | +// ═══════════════════════════════════════════════════════════════════════════ |
| 602 | + |
| 603 | +describe('[ADR-0146 D10, #28735] the adopt-orphans door judges each object row it rebinds against the target', () => { |
| 604 | + /** Package-less active objects through the real save door (not judged: no package), then the write-through spied. */ |
| 605 | + async function orphans(h: Harness, ...bodies: Array<ReturnType<typeof obj>>) { |
| 606 | + for (const item of bodies) await h.protocol.saveMetaItem({ type: 'object', name: item.name, item }); |
| 607 | + h.saveDoor.mockClear(); |
| 608 | + return vi.spyOn(h.protocol, 'applyRegistryWriteThrough'); |
| 609 | + } |
| 610 | + |
| 611 | + it('a package-less object with `x__c` adopted into a plain package is refused with case (a); nothing moves, nothing registers', async () => { |
| 612 | + const h = makeProtocol(); |
| 613 | + const writeThrough = await orphans(h, obj('probe_env', 'Env', 'x__c')); |
| 614 | + const update = vi.spyOn(h.engine, 'update'); |
| 615 | + |
| 616 | + const { error } = await attempt(() => h.protocol.reassignOrphanedMetadata({ targetPackageId: BOUND })); |
| 617 | + |
| 618 | + expectReservedRefusal(error, 'x__c', 'probe_env', BOUND, 'objects.probe_env.fields.x__c'); |
| 619 | + expect(update).not.toHaveBeenCalled(); |
| 620 | + expect(writeThrough).not.toHaveBeenCalled(); |
| 621 | + expect(storedObjects(h)).toEqual([{ row: 'probe_env', state: 'active', binding: null, fields: ['title', 'x__c'] }]); |
| 622 | + }); |
| 623 | + |
| 624 | + it('a mixed adoption (one clean row, one `x__c` row) into a plain package is refused whole: the clean row does not move either', async () => { |
| 625 | + const h = makeProtocol(); |
| 626 | + const writeThrough = await orphans(h, obj('probe_clean', 'Clean'), obj('probe_env', 'Env', 'x__c')); |
| 627 | + |
| 628 | + const { error } = await attempt(() => h.protocol.reassignOrphanedMetadata({ targetPackageId: BOUND })); |
| 629 | + |
| 630 | + expectReservedRefusal(error, 'x__c', 'probe_env', BOUND, 'objects.probe_env.fields.x__c'); |
| 631 | + expect(writeThrough).not.toHaveBeenCalled(); |
| 632 | + expect(storedObjects(h).map((r) => [r.row, r.binding])).toEqual([['probe_clean', null], ['probe_env', null]]); |
| 633 | + }); |
| 634 | + |
| 635 | + it('CONTROL: the same `x__c` row adopted into the base\'s `.custom` pair is admitted and moves; a clean row into the plain package too', async () => { |
| 636 | + const pairH = makeProtocol(); |
| 637 | + await orphans(pairH, obj('probe_env', 'Env', 'x__c')); |
| 638 | + const res = await pairH.protocol.reassignOrphanedMetadata({ targetPackageId: PAIR }); |
| 639 | + expect(res).toMatchObject({ success: true, reassignedCount: 1, targetPackageId: PAIR }); |
| 640 | + expect(storedObjects(pairH)).toEqual([{ row: 'probe_env', state: 'active', binding: PAIR, fields: ['title', 'x__c'] }]); |
| 641 | + |
| 642 | + const plainH = makeProtocol(); |
| 643 | + await orphans(plainH, obj('probe_clean', 'Clean', 'region')); |
| 644 | + expect((await plainH.protocol.reassignOrphanedMetadata({ targetPackageId: BOUND })).reassignedCount).toBe(1); |
| 645 | + expect(storedObjects(plainH)).toEqual([{ row: 'probe_clean', state: 'active', binding: BOUND, fields: ['title', 'region'] }]); |
| 646 | + }); |
| 647 | +}); |
| 648 | + |
570 | 649 | // ═══════════════════════════════════════════════════════════════════════════ |
571 | 650 | // 5. installPackage — covered by its closed manifest |
572 | 651 | // ═══════════════════════════════════════════════════════════════════════════ |
|
0 commit comments