Skip to content

Commit 1e4656d

Browse files
fix(metadata-protocol): a package's rollback, revert or package rollback of its own permission set restores beside another namespace's shipped set (#34550)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9BNdBet5uqNbzVw5DWcs1wy)_ Fixes #34401 Clause-②: yes (widening) — a rollback, a commit revert or a package rollback of a package's own permission set N, refused 403 `NOT_OVERRIDABLE` ("provided by a managed package and is sealed") while a package of another namespace ships N, now restores; a delete of that set answers "Deleted permission 'N' (package=P) — it no longer exists." in place of "Customization overlay deleted (package=P) — permission/N reset to artifact default.", with `reset: true` as before; nothing the doors accepted is refused Metadata-protocol: none ## 维护者速读 - 改了什么:包 crm 发布了权限集 N 时,另一命名空间的包 hr 现在可以把自己的 N 回滚到旧版本、回退改过 N 的提交、或把整个包回滚到更早提交,旧版本会恢复且 hr 的授权生效旧版本;hr 删除自己的 N 时,回执改为「已删除、不再存在」,不再说「重置为制品默认」。 - 为什么改:保存、草稿发布、发布撤销已经按「包 + 名称」判断(#34359),回滚和回退仍只看名称,把 crm 的同名集当成被覆盖的封存基线,误拒了 hr 对自己集合的恢复;删除回执也读同一个只看名称的事实。 - 风险与回滚:风险在恢复写入意图的收窄;它只复用保存门已在用的同一个判定 `isOwnPermissionSetWrite`,凡是覆盖 crm 所发布 N 的恢复(不绑包、绑 crm、绑 crm 的定制配对包、绑 crm 或 fin 同命名空间的包)仍按原来的错误码拒绝。回滚即 revert 本 PR,无数据迁移。 - 先看:`packages/metadata-protocol/src/protocol-class-head.ts`(`restoreWriteFor` 一行收窄,回滚与提交回退共用),`packages/metadata-protocol/src/protocol-diff-delete-load.ts`(删除回执的同一判定)。 - 两分钟验证:`pnpm --filter @objectstack/plugin-security exec vitest run src/packaged-permission-set-lock-gate.test.ts`,预期 71 个全部通过,其中 `[#34401]` 一组覆盖两种注册顺序下的恢复、删除回执和全部拒绝对照。 - 需要你做的:评审本次声明的放宽(回滚、提交回退、包回滚三处门,以及删除回执文字)。 ## What changes A permission set is `(package, name)` (ADR-0150 D2/D9). #34359 made the save door, the draft publish and the publish undo judge a write of a package's own set `N` by the package it is addressed to (`isOwnPermissionSetWrite`, `protocol-packaged-base-refusal.ts`). The per-item rollback and a commit revert's restore limb still handed `restoreWriteFor` the name-wide `isArtifactBacked`, so a restore into `hr`'s own `N`, while `crm` of another namespace ships `N`, was told `override-artifact` and refused by the store's managed seal. - `restoreWriteFor` (`protocol-class-head.ts`), the one derivation both restore sites share, narrows the `artifactBacked` it receives by `isOwnPermissionSetWrite(engine, type, name, binding)`, where `binding` is the row the restore writes (the rollback's resolved row binding, the revert's commit package). A restore into a package's own set is a runtime-only write, as that package's save is. Every other restore keeps the intent and the pair handling it had. One place covers all three doors: `POST /api/v1/meta/:type/:name/rollback`, `POST /packages/:id/commits/:commitId/revert`, and `POST /packages/:id/rollback`, which reverts commit by commit. - `deleteMetaItem` (`protocol-diff-delete-load.ts`): the two repository-path receipts that claim a code-shipped item sits under the deleted address (the success receipt and the "no row" receipt) read the same verdict at the resolved address. A delete of `hr`'s own `N` answers "Deleted permission 'N' (package=hr) — it no longer exists."; a delete naming `hr` when `hr` holds no `N` answers "No permission 'N' found — nothing to delete.". The delete's write intent is unchanged (the store already admits it; see Acceptance notes). | Request about `N` (crm ships `N`) | FROM (main) | TO (this PR) | |---|---|---| | rollback of `hr`'s own `N` to v1 | 403 `NOT_OVERRIDABLE`, v2 kept | v1 restored; `hr`'s grant confers v1 | | revert of `hr`'s commit that edited `N` | `N` in `failed[]`, `NOT_OVERRIDABLE` | v1 restored, `failed: []` | | `rollbackToPackageCommit` to `hr`'s earlier commit | the revert in `failed[]` | v1 restored | | the same with `crm` AND `fin` shipping `N` | refused | restored | | delete of `hr`'s own `N` | `reset: true`, "Customization overlay deleted (package=hr) — permission/N reset to artifact default." | `reset: true`, "Deleted permission 'N' (package=hr) — it no longer exists." | | delete naming `hr`, no `hr` row | "No customization overlay found … already at artifact default." | "No permission 'N' found — nothing to delete." | | rollback of a row bound to crm / crm's pair | 403 `NOT_OVERRIDABLE` | unchanged | | rollback of a row bound to no package | 409 `RESOURCE_CONFLICT` | unchanged | | rollback of a row bound to a co-owner of crm's (or, with fin shipping, fin's) namespace | 422 `NAMESPACE_CONFLICT` | unchanged | | revert of a commit of `N` bound to crm / crm's pair | `failed[]` `NOT_OVERRIDABLE` | unchanged | | revert of a commit of `N` bound to no package / a co-owner | `failed[]` `NAMESPACE_CONFLICT` | unchanged | | delete of crm's pair's customization of `N` | `reset: true`, "… reset to artifact default." | unchanged | ## Tests `packages/plugins/plugin-security/src/packaged-permission-set-lock-gate.test.ts`, the #34226 pin file: - New top-level describe `[#34401] restoring or deleting a package's own set N beside another namespace's shipped N`, every case in both registration orders: the rollback, the commit revert and the package rollback restore v1 (and `hr`'s grant confers it); `crm` and `fin` both shipping still restores; ten CONTROL cases (5 rollback, 5 revert) assert the `code` and `status` main answered, measured before the fix, and that the active row is untouched; the two delete receipts; a CONTROL that the pair's customization delete still reads as a reset. - The composition the #34226 describe used (packages, `N`, `composition`, `confers`) moved from inside that describe to module scope, unchanged, so both describes share it. `git diff -w` shows the move as whitespace. - The file's fake engine (forced change, named): a row of a table other than `sys_metadata` is keyed by its own id, so a second package commit no longer overwrites the first, and the history rows are exposed for the CONTROL rebind. No `findOne`/`update`/`delete` double was added (`check:engine-double-contract` counts unchanged). ## Acceptance notes - Deviation from comment 6917777398: it asked for `reset: false` on the delete of `hr`'s own `N`. `DeleteMetaItemResponseSchema` defines `reset === true` as "a row was deleted" and `false` as "nothing was removed", so `reset` stays `true` (a row was deleted) and only the receipt text changes. Amended claim 6932622107 records this. - Not changed: the delete's write intent and `revertCommit`'s removal limb (`isArtifactBacked` alone). Both hand the store `override-artifact` for `hr`'s own `N`, and `assertDeleteAllowed` admits it for a `supportsOverlay` type, so nothing is refused and the change would not be observable. The card names the removal limb as not refused. - The rollback CONTROL bound to no package answers 409 `RESOURCE_CONFLICT`, and the co-owner CONTROLs answer 422 `NAMESPACE_CONFLICT`. Those refusals are judged ahead of the restore, on main as on this branch. ## Verification <details><summary>FROM on main source, ablations, suites and gates</summary> - FROM (the new describe on unchanged source, `bdd51769`): 22 failed / 10 passed. Rollback 403 `NOT_OVERRIDABLE`; revert `failed[]` `NOT_OVERRIDABLE`; package rollback failed; delete receipt "reset to artifact default". The CONTROL envelopes were read from this run and pinned. - TO: `pnpm --filter @objectstack/plugin-security exec vitest run src/packaged-permission-set-lock-gate.test.ts`, 71 passed (71). - Ablation R1 (`restoreWriteFor` narrowing removed, `const overridesShipped = artifactBacked;`): 8 failed / 63 passed. The failures are the rollback, revert, package rollback and two-shipper cases, both orders. Restored: blob == HEAD. - Ablation D1 (delete receipt narrowing removed): the first attempt replaced the anchor with `;` and was a no-op that `ablation-replace.mjs` refused (replacement count did not move), so no reading. Re-run with a marker replacement: 4 failed / 67 passed, the two delete-receipt cases in both orders. Restored: blob == HEAD. - The suite resolves `@objectstack/metadata-protocol` to source (`vitest.config.ts` alias), so no rebuild is needed between legs. - After merging `origin/main`, under `os-verify-lock`, VERDICT command-exit 0: closure build, `metadata-protocol` typecheck, `plugin-security` typecheck, `plugin-security` test (274 files, 6883 passed / 45 skipped), `metadata-protocol` test (346 passed / 9 skipped files, 22968 passed / 45 skipped). - Derived gate families at head `bf5dccdba2`: 74 derived, 74 run, 0 NOT-MEASURED (`dispatch-gates.mjs --ran`). The first pass had 3 exit-3 prerequisites (`check-plugin-teardown-shape --self-test` on a shallow clone; `check:dual-build-cjs-loads` and `check:i18n` on an unbuilt workspace). Each re-ran to exit 0 after `git fetch --unshallow` and a full `pnpm build` (VERDICT command-exit 0). </details> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 8fb9fbf commit 1e4656d

4 files changed

Lines changed: 250 additions & 67 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@objectstack/metadata-protocol': patch
3+
---
4+
5+
fix(metadata-protocol): a package's rollback, commit revert or package rollback of its own permission set is no longer refused because a package of another namespace ships a set of that name
6+
7+
Clause-②: yes (widening) — a rollback, a commit revert or a package rollback of a package's own permission set N, refused 403 `NOT_OVERRIDABLE` ("provided by a managed package and is sealed") while a package of another namespace ships N, now restores; a delete of that set answers "Deleted permission 'N' (package=P) — it no longer exists." in place of "Customization overlay deleted (package=P) — permission/N reset to artifact default.", with `reset: true` as before; nothing the doors accepted is refused
8+
Metadata-protocol: none
9+
10+
A permission set is `(package, name)` (ADR-0150 D2/D9). The save door, the draft publish and the publish undo already judge a write of a package's own set `N` by the package it is addressed to. The per-item rollback (`POST /api/v1/meta/:type/:name/rollback`), the commit revert (`POST /packages/:id/commits/:commitId/revert`) and the package rollback (`POST /packages/:id/rollback`, which reverts commit by commit) still judged the name alone: when package `crm` shipped `N`, package `hr` of another namespace could not restore an earlier version of its own `N`. The rollback answered 403 `NOT_OVERRIDABLE`, and a revert listed `N` in `failed[]`.
11+
12+
Those restores now read the same verdict as the save. A restore into `hr`'s own `N` is a runtime write to `hr`, so the earlier version is restored and `hr`'s grants confer it. Every package that ships the name is judged, so the answer is the same in every registration order. A restore into a row bound to no package, to the shipper, to the shipper's customization pair or to a package that shares the shipper's set of the name is refused exactly as before.
13+
14+
A delete of `hr`'s own `N` already succeeded, but its receipt said an overlay was deleted and `N` was reset to its artifact default. `hr` ships no `N`, so the receipt now says the set was deleted and no longer exists. A delete naming `hr` when `hr` holds no `N` answers "nothing to delete" in place of "already at artifact default". The receipts for a customization of a shipped set are unchanged.
15+
16+
Nothing to migrate.

‎packages/metadata-protocol/src/protocol-class-head.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import type { IObjectQLEngine, IPubSub } from '@objectstack/spec/contracts';
4242
import { isPairOf } from '@objectstack/metadata-core';
4343
import { installedManifestsOfEngine } from './installed-manifests.js';
4444
import { someShipperOf } from './protocol-environment-rows.js';
45-
import { overrideWriteRefusalError } from './protocol-packaged-base-refusal.js';
45+
import { isOwnPermissionSetWrite, overrideWriteRefusalError } from './protocol-packaged-base-refusal.js';
4646
import { OBJECT_EXTENSION_TYPE, registrableObjectExtension } from './protocol-object-extension-item.js';
4747
import type { ObjectExtensionRegistry } from './protocol-object-extension-item.js';
4848
import { canonicalMetaType } from './protocol-meta-type-schema.js';
@@ -201,19 +201,27 @@ export class ProtocolClassHeadFacet {
201201
* `deriveRestoredBody`, so nothing is written. Any other binding: the
202202
* caller's `artifactBacked` decides the intent, and the body writer is
203203
* {@link restoredBodyWriter}'s alone.
204+
*
205+
* [ADR-0150 D2, #34401] A restore into a package's OWN permission set,
206+
* beside sets other namespaces' packages ship, overrides no shipped set,
207+
* so the name-wide `artifactBacked` is narrowed by the verdict the save,
208+
* publish and undo doors read ({@link isOwnPermissionSetWrite}): the
209+
* store is told a runtime-only write, as that package's save is. Every
210+
* restore that does override a shipped set keeps the intent it had.
204211
*/
205212
static restoreWriteFor(host: Pick<ProtocolHost, 'engine' | 'overrideWriteVerdict' | 'packagedArtifactOwner' | 'restoredBodyWriter' | 'shippedArtifactsOf'>, singularType: string,
206213
name: string,
207214
binding: string | null,
208215
artifactBacked: boolean,
209216
source: string,): { intent: 'override-artifact' | 'runtime-only'; deriveRestoredBody: (historyBody: unknown) => Promise<unknown> } {
217+
const overridesShipped = artifactBacked && !isOwnPermissionSetWrite(host.engine, singularType, name, binding);
210218
// [ADR-0150 D4, #32552] The binding is judged against every package
211219
// that ships the name ({@link someShipperOf}): each namespace's holder
212220
// has its own pair, never only the shipper registered first.
213221
const installed = installedManifestsOfEngine(host.engine);
214-
const pairRow = artifactBacked && someShipperOf(host, singularType, name,
222+
const pairRow = overridesShipped && someShipperOf(host, singularType, name,
215223
(owner) => owner !== undefined && isPairOf(binding, owner, installed));
216-
const intent: 'override-artifact' | 'runtime-only' = artifactBacked && !pairRow ? 'override-artifact' : 'runtime-only';
224+
const intent: 'override-artifact' | 'runtime-only' = overridesShipped && !pairRow ? 'override-artifact' : 'runtime-only';
217225
const writeRestored = host.restoredBodyWriter(singularType, name, binding, source);
218226
const deriveRestoredBody = pairRow
219227
? async (historyBody: unknown): Promise<unknown> => {

‎packages/metadata-protocol/src/protocol-diff-delete-load.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import type { ServedOverrideRow } from './served-override.js';
4747
import { REFERENCE_SITES } from './reference-sites.js';
4848
import { computeMetadataDiagnostics } from './metadata-diagnostics.js';
4949
import { hasMetadataRedactor, redactMetadataItem } from './metadata-redaction.js';
50-
import { isPairRowRemoval } from './protocol-packaged-base-refusal.js';
50+
import { isOwnPermissionSetWrite, isPairRowRemoval } from './protocol-packaged-base-refusal.js';
5151
import { canonicalMetaType, canonicalizeMetaRequestType } from './protocol-meta-type-schema.js';
5252
import { boundPackageOf, servesSealedOverrideRow } from './protocol-package-bindings.js';
5353
import { remainingRowsPhrase } from './protocol-authoring-refusals.js';
@@ -750,6 +750,13 @@ export class ProtocolDiffDeleteLoadFacet {
750750
}
751751
const packageId: string | null = request.packageId
752752
?? (draftAddress !== undefined ? draftAddress.key : rowsAtAddress.packageId);
753+
// [ADR-0150 D2, #34401] Whether a code-shipped item sits under
754+
// THIS address, which the two receipts below claim: a package's
755+
// own permission set beside sets other namespaces' packages ship
756+
// has none ({@link isOwnPermissionSetWrite}, the verdict its save
757+
// reads), so removing it removes the set, never resets one.
758+
const shippedUnderAddress = artifactBacked
759+
&& !isOwnPermissionSetWrite(host.engine, singularTypeForRepo, request.name, packageId);
753760
// Probe first — "no overlay exists" is a success/no-op, not
754761
// a conflict. The repo would otherwise throw ConflictError.
755762
const current = await repo.get(ref, { state: targetState, packageId, ...memberOption(member) });
@@ -817,7 +824,7 @@ export class ProtocolDiffDeleteLoadFacet {
817824
// unchanged, verbatim.
818825
message: targetState === 'draft'
819826
? `No pending draft for ${request.type}/${request.name}.`
820-
: artifactBacked
827+
: shippedUnderAddress
821828
? `No customization overlay found for ${request.type}/${request.name} — already at artifact default.`
822829
: `No ${singularTypeForRepo} '${request.name}' found — nothing to delete.`,
823830
};
@@ -1005,7 +1012,7 @@ export class ProtocolDiffDeleteLoadFacet {
10051012
// discard reads byte for byte as before.
10061013
message: (request.state === 'draft')
10071014
? `Draft discarded${deletedPackage} — ${request.type}/${request.name}. [seq=${result.seq}]`
1008-
: artifactBacked
1015+
: shippedUnderAddress
10091016
? (remains
10101017
? `Customization overlay deleted${deletedPackage} — ${request.type}/${request.name} still carries another overlay: ${remainingRowsPhrase(remainingPackages, unboundRemains, 'row')}. [seq=${result.seq}]`
10111018
: `Customization overlay deleted${deletedPackage} — ${request.type}/${request.name} reset to artifact default. [seq=${result.seq}]`)

0 commit comments

Comments
 (0)