Repository navigation
Commit 1e4656d
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
- .changeset
- packages
- metadata-protocol/src
- plugins/plugin-security/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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| |||
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
204 | 211 | | |
205 | 212 | | |
206 | 213 | | |
207 | 214 | | |
208 | 215 | | |
209 | 216 | | |
| 217 | + | |
210 | 218 | | |
211 | 219 | | |
212 | 220 | | |
213 | 221 | | |
214 | | - | |
| 222 | + | |
215 | 223 | | |
216 | | - | |
| 224 | + | |
217 | 225 | | |
218 | 226 | | |
219 | 227 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
| 50 | + | |
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| |||
750 | 750 | | |
751 | 751 | | |
752 | 752 | | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
753 | 760 | | |
754 | 761 | | |
755 | 762 | | |
| |||
817 | 824 | | |
818 | 825 | | |
819 | 826 | | |
820 | | - | |
| 827 | + | |
821 | 828 | | |
822 | 829 | | |
823 | 830 | | |
| |||
1005 | 1012 | | |
1006 | 1013 | | |
1007 | 1014 | | |
1008 | | - | |
| 1015 | + | |
1009 | 1016 | | |
1010 | 1017 | | |
1011 | 1018 | | |
| |||
0 commit comments