Skip to content

Commit 74a15cb

Browse files
fix(spec,metadata-protocol): name the row-held-base exception's whole cell in the packageId texts; the read-only-base rollback pin restores a real version (#38639)
repo:objectstack#3 · os-steve · session_01ADHkmSAjFEZHRpRq3WCj6z <!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi95y2NHsVF2knp6wnXXUMwDL)_ Fixes #35529 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:没有。只改协议说明文字、三处代码注释和一条测试,服务端行为不变。 - 为什么做:写操作跟随基座包上线后的契约复审留了三个小尾巴,说明文字漏了两种情形,注释还按旧规则写。 - 出错会怎样:不改的话,读协议文档的人会以为代码里自带同名项时也能按名字写,或以为只有一个依赖包;改错只影响文字,可直接撤回。 - 要你做什么:无。 ## What changes Nits N4–N6 of the contract review on the parent change (record 7011078775, VERDICT PASS), each re-checked on `origin/main` 681fec2 before editing. - **N4 — `packages/spec/src/api/protocol.zod.ts`.** The row-held-base exception in the `packageId` descriptions of the save (active and draft), per-item publish, delete and history/diff/rollback requests (`HISTORY_PACKAGE_SELECTOR_DESCRIPTION`) now names the two conditions the texts left out (a name no package ships in code; one or more dependents) of the cell the server applies (`rowHeldBaseJudgment` in `packages/metadata-protocol/src/protocol-meta-item-face.ts`): a bundled type's member **of a name no package ships in code**, whose active rows a base package and **one or more** packages declaring it hold, with no package-unbound row beside them. The delete's consequence sentence no longer assumes one dependent: after the base's row goes, the next bare request is judged over the dependents' rows alone (one dependent: served next, a second bare delete removes it; two or more: judged by the same rule). The deletion is bounded to the base holding no other member, or the canonical member; at a named non-canonical member while the base holds another, the bare read still takes the base's address (404). The draft-save sentence refers back to the save's and is unchanged. Regenerated: `packages/spec/docs/references/api/protocol.md`, `protocol.part-2.md`, `protocol.part-3.md` (`check:docs`; the card's `content/docs/references/api/protocol.mdx` path no longer exists, the generated reference lives here now). - **N5 — `packages/metadata-protocol/src/protocol-door-requests.ts`.** The publish, rollback and delete request docblocks state the row-held-base exception beside the two-package `409`, pointing at `packagelessRowHeldBaseAddress`. Comment-only. - **N6 — `packages/runtime/src/domains/meta-bare-write-doors-follow-base-34681.test.ts`.** The read-only-base pin seeds one `sys_metadata_history` version of the base's slot before the rollback, so `toVersion: 1` is a real restore, and asserts that the bare rollback restored that version into the base's row with the dependent's row untouched, as `?package=BASE` does. - Changeset `.changeset/35529-spec-row-held-base-texts.md` (`@objectstack/spec` patch: the describe text ships in the package; `@objectstack/metadata-protocol` patch: the three request types' comments ship in its `dist/index.d.ts`). No schema shape, key, accepted value, error code or server answer moves. ## Tests - `meta-bare-write-doors-follow-base-34681.test.ts`: 11/11 pass. - Ablation of N6 (seed line removed, test file only): the pin goes red, both bare and named rollback answering `404 VERSION_NOT_FOUND` with the rows unchanged, which is what the pin measured before this change. Restored from the commit. <details><summary>Ablation reading</summary> ``` "rollback":["VERSION_NOT_FOUND",404],"rolledRows":["active:com.qa.writeaddon:addon en","active:com.qa.writebase:base en"] Tests 1 failed | 10 skipped (11) ``` </details> ## Acceptance notes - None filed. The read-only (code) base's rows are restored, discarded and removed in process by a system caller, bare and named alike; this pin records that equality and judges nothing about it. ## Verification Read first: the delete sentence in `protocol.zod.ts` (the one text whose meaning moved), then the N6 hunk. Two-minute check: `pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2 src/domains/meta-bare-write-doors-follow-base-34681.test.ts` prints `Tests 11 passed (11)`. <details><summary>Local gates at 0ee1576</summary> - `node scripts/pm/dispatch-gates.mjs --commands` derived 94 commands; all 94 run, each exit 0; `--ran` reconciliation: 94 derived, 94 run, 0 NOT-MEASURED. Three first answers were not verdicts and were re-run: the teardown-shape self-test exit 3 (shallow clone; re-run after `git fetch --unshallow`), `check:dual-build-cjs-loads` exit 3 (no full build) and `check:lean-entry-closure` exit 1 (`packages/spec/dist` being rebuilt under it by a concurrent build), both re-run after `turbo run build` (123/123). - `pnpm --filter @objectstack/spec check:generated`: stale `check:docs` regenerated with `--fix`, re-check all 14 up to date. - `pnpm --filter @objectstack/runtime typecheck`: exit 0. - `node scripts/pm/overlap-check.mjs`: clean against `origin/main` and the two open PRs sharing a file. - Not run locally: `@objectstack/metadata-protocol` tests (comment-only diff there); CI carries the rest of the farm. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01ADHkmT5it85jhPpGaNANG7)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4b57756 commit 74a15cb

7 files changed

Lines changed: 78 additions & 30 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@objectstack/spec': patch
3+
'@objectstack/metadata-protocol': patch
4+
---
5+
6+
docs(spec): the row-held-base exception in the request texts names its whole cell
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
The `packageId` descriptions of the save, draft save, per-item publish, delete and history/diff/rollback requests (`HISTORY_PACKAGE_SELECTOR_DESCRIPTION`) state when a request naming no package follows the row-held base. They now name the two conditions the server already applies and the earlier text left out: the exception holds only for a name no package ships in code (a shipped name is its shipper's, and such a request answers as before), and the base may be declared by one or more packages, not exactly one. The delete text no longer assumes a single dependent: after the base's row is removed, and where the base holds no other member of the name or the member is the canonical one, the next request naming no package is judged over the dependents' rows alone, so one dependent's row is served next and a second delete removes it, while two or more are judged by the same rule. At a named non-canonical member while the base still holds another member, the read naming no package still takes the base's address and answers `404` until the base holds a row there again, and a second delete naming no package still removes a lone dependent's row. Description text only; no schema shape, key, accepted value or server answer moves.
12+
13+
In `@objectstack/metadata-protocol`, the doc comments of the publish, rollback and delete request types, which ship in the built declarations, now state the same row-held-base exception beside the two-package `409`; comment text only.

‎packages/metadata-protocol/src/protocol-door-requests.ts‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ type PublishMetaItemRequest = {
7878
* publish promotes the draft a draft save naming no package writes
7979
* ({@link packagelessDraftAddress}), and is refused `409
8080
* RESOURCE_CONFLICT` when the item's active rows are bound to two or
81-
* more packages. Spread it in conditionally; never write
81+
* more packages, except where the read naming no package serves the
82+
* row-held base ({@link packagelessRowHeldBaseAddress}): there it
83+
* promotes the base's draft into the base's row, as naming the base
84+
* does. Spread it in conditionally; never write
8285
* `packageId: maybeUndefined`, which arrives as a present-and-undefined
8386
* key, coerces to `null` downstream, and makes a package-bound draft
8487
* unfindable — a silent `no_draft` on the untouched path.
@@ -143,8 +146,11 @@ type RollbackMetaItemRequest = {
143146
* or the package-less row its read falls back to; the version must be
144147
* that holder's — one attributed to no package, or to the environment,
145148
* only while it is the name's sole slot. Absent, a name two row slots
146-
* hold, or one the bare plain read refuses, is refused `409` naming every
147-
* holder, before anything is written; a name one holder holds restores
149+
* hold is refused `409` naming every holder, before anything is written,
150+
* except where the read naming no package serves the row-held base
151+
* ({@link packagelessRowHeldBaseAddress}): there the base's slot is
152+
* restored, as naming the base restores it. A name the bare plain read
153+
* refuses is refused `409` the same way; a name one holder holds restores
148154
* any of its versions, as before.
149155
*/
150156
packageId?: string;
@@ -175,8 +181,11 @@ type DeleteMetaItemRequest = {
175181
* the delete removes that package's row and no other. Absent or `null`
176182
* names no package: the delete removes the row of the one package the
177183
* item's rows at its state are bound to, is refused `409
178-
* RESOURCE_CONFLICT` when they are bound to two or more, and with none
179-
* removes the package-unbound row ({@link packagelessAddress}).
184+
* RESOURCE_CONFLICT` when they are bound to two or more (except where the
185+
* read naming no package serves the row-held base,
186+
* {@link packagelessRowHeldBaseAddress}: there it removes the base's row,
187+
* as naming the base does), and with none removes the package-unbound
188+
* row ({@link packagelessAddress}).
180189
* [#23495] A draft discard naming none removes the draft a draft save
181190
* naming none writes ({@link packagelessDraftAddress}), the one the
182191
* per-item publish naming none promotes.

‎packages/runtime/src/domains/meta-bare-write-doors-follow-base-34681.test.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,17 @@ const layRow = (engine: ObjectQL, type: string, name: string, packageId: string
102102
...(type === 'email_template' && metadata.locale !== 'en-US' ? { bundle_member: metadata.locale } : {}),
103103
metadata: JSON.stringify({ name, ...metadata }),
104104
}, { context: { isSystem: true } } as any);
105+
// One `sys_metadata_history` version of the name, attributed to `packageId`'s slot, as a save into that package
106+
// records it: the next environment-wide `event_seq`, as the history writer numbers it.
107+
const layHistory = async (engine: ObjectQL, name: string, packageId: string, version: number, metadata: Record<string, unknown>) => {
108+
const seqs = ((await engine.find('sys_metadata_history', { context: { isSystem: true } } satisfies EngineQueryOptions)) as any[])
109+
.map((row) => Number(row.event_seq) || 0);
110+
return engine.insert('sys_metadata_history', {
111+
id: `hist_${name}_${version}`, event_seq: Math.max(0, ...seqs) + 1, type: 'email_template', name, version, package_id: packageId,
112+
operation_type: 'update', metadata: JSON.stringify({ name, ...metadata }), checksum: `seeded_${name}_${version}`,
113+
recorded_at: new Date().toISOString(), source: 'database-loader',
114+
}, { context: { isSystem: true } } as any);
115+
};
105116
const layPair = async (engine: ObjectQL, name: string, base: string, dependent: string) => {
106117
await layRow(engine, 'email_template', name, base, template('en-US', 'base en'));
107118
await layRow(engine, 'email_template', name, dependent, template('en-US', 'addon en'));
@@ -274,16 +285,21 @@ describe('[#34681] the bare write doors follow the row-held base the bare read s
274285
const name = `ro_destroy_${label}`;
275286
await layPair(b.engine, name, A, D);
276287
await layRow(b.engine, 'email_template', name, A, template('en-US', 'base drafted'), 'draft');
288+
// A real version of the base's slot to restore, so the rollback is judged as a restore into the base.
289+
await layHistory(b.engine, name, A, 1, template('en-US', 'base v1'));
277290
const at = packageId === undefined ? {} : { packageId };
278291
const discard = await settle(b.protocol.deleteMetaItem({ type: 'email_template', name, state: 'draft', ...at }));
279292
const rollback = await settle(b.protocol.rollbackMetaItem({ type: 'email_template', name, toVersion: 1, ...at }));
293+
const rolledRows = await rowsOf(b.engine, name);
280294
const remove = await settle(b.protocol.deleteMetaItem({ type: 'email_template', name, ...at }));
281-
seen[label] = { discard: outcome(discard), rollback: outcome(rollback), remove: outcome(remove), rows: await rowsOf(b.engine, name) };
295+
seen[label] = { discard: outcome(discard), rollback: outcome(rollback), rolledRows, remove: outcome(remove), rows: await rowsOf(b.engine, name) };
282296
if (label === 'bare') {
283297
for (const answer of [discard, rollback, remove]) expect(answer.code, JSON.stringify(answer)).not.toBe('RESOURCE_CONFLICT');
284298
}
285299
}
286300
expect(seen.bare, JSON.stringify(seen)).toEqual(seen.named);
301+
// The rollback restored the seeded version into the base's row, the dependent's row untouched.
302+
expect(seen.bare, JSON.stringify(seen)).toMatchObject({ rollback: ['resolved', true], rolledRows: [`active:${D}:addon en`, `active:${A}:base v1`] });
287303
});
288304

289305
const versionedPair = async (name: string) => {

‎packages/spec/docs/references/api/protocol.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ A write-path strip event: caller-supplied fields legally dropped from the payloa
788788
| **state** | `Enum<'active' \| 'draft'>` | optional | Which lifecycle row to discard: `draft` discards the pending draft overlay only (the still-active overlay, if any, keeps serving); `active` or absent resets the live row. Absent defaults to `active`. |
789789
| **dropStorage** | `boolean` | optional | Destructive opt-in, default false: also drop the object's physical table after the metadata row is removed (`object` type + `active` state only; never `sys_` tables). Used by the "discard a previewed object" flow so a publish-to-preview leaves no orphan table. |
790790
| **member** | `string` | optional | Bundle member selector, for a metadata type whose identity is a pair (today only `email_template`, identified by `(name, locale)`): the member this request addresses, spelled as its discriminator value (`zh-CN`). Absent, the canonical member (`en-US` for `email_template`), which is what a bare-name read answers; naming the canonical value is the same request. It is not the response translation locale, which `?locale=` and `Accept-Language` choose. Refused with 400 `VALIDATION_ERROR` on a type that has no members, and for a blank value or one longer than a stored member can be (100 characters). A well-formed member with nothing stored or shipped answers as that door answers an absent item. |
791-
| **packageId** | `string \| null` | optional | ADR-0048 — the software package whose row this delete removes (`sys_metadata.package_id`; `?package=<id>` on the REST door, where `all` and an empty value name no package), as a save names the row it writes. Named, the delete removes that package's row and no other; a package that holds no row removes nothing. Absent or `null` names no package: the delete of the `active` row then removes the row of the one package the item's active rows are bound to, is refused `409 RESOURCE_CONFLICT` when they are bound to two or more, and with none removes the env-local row (no package stamp). Bound to two or more, one exception: a bundled type's member whose active rows a base package and a package declaring it both hold, with no package-unbound row beside them, is the row-held base's, as the read naming no package serves it, and the delete removes the base's row as naming the base does (two packages neither of which declares the other are still refused `409`). The dependent's row is then the item's only row at that address: the read naming no package serves it next, and a second delete naming no package removes it too; the base's copy comes back only by saving it again. The discard of the `draft` removes the draft a draft save naming no package writes, the one the per-item publish naming none promotes, and is refused where that publish is (see `PublishMetaItemRequestSchema.packageId`). That row is the one `parentVersion` is judged against. When another row of the item is still stored afterwards, the receipt `message` names it. |
791+
| **packageId** | `string \| null` | optional | ADR-0048 — the software package whose row this delete removes (`sys_metadata.package_id`; `?package=<id>` on the REST door, where `all` and an empty value name no package), as a save names the row it writes. Named, the delete removes that package's row and no other; a package that holds no row removes nothing. Absent or `null` names no package: the delete of the `active` row then removes the row of the one package the item's active rows are bound to, is refused `409 RESOURCE_CONFLICT` when they are bound to two or more, and with none removes the env-local row (no package stamp). Bound to two or more, one exception: a bundled type's member of a name no package ships in code, whose active rows a base package and one or more packages declaring it hold, with no package-unbound row beside them, is the row-held base's, as the read naming no package serves it, and the delete removes the base's row as naming the base does (two packages neither of which declares the other are still refused `409`). The dependents' rows stay. Where the base holds no other member of the name, or the member is the canonical one, the next request naming no package is judged over them alone: one dependent's row is served next and a second delete naming no package removes it too, while two or more are judged by the rule above. At a named non-canonical member while the base still holds another member, the read naming no package still takes the base's address and answers `404` until the base holds a row there again, and a second delete naming no package still removes a lone dependent's row there. The base's copy comes back only by saving it again. The discard of the `draft` removes the draft a draft save naming no package writes, the one the per-item publish naming none promotes, and is refused where that publish is (see `PublishMetaItemRequestSchema.packageId`). That row is the one `parentVersion` is judged against. When another row of the item is still stored afterwards, the receipt `message` names it. |
792792

793793

794794
---
@@ -862,7 +862,7 @@ A write-path strip event: caller-supplied fields legally dropped from the payloa
862862
| **name** | `string` | ✅ | Item name |
863863
| **fromVersion** | `integer` | optional | The older side's history version, a whole number as the history lists it. Absent, the nearest earlier version whose body differs from the `to` side's. A version with no history row of the item (or, with `packageId`, of that holder) is refused 404 `VERSION_NOT_FOUND`. |
864864
| **toVersion** | `integer` | optional | The newer side's history version, a whole number as the history lists it. Absent, the active row (with `packageId`, that holder's own active row). Refused 404 `VERSION_NOT_FOUND` as `fromVersion` is. |
865-
| **packageId** | `string` | optional | Optional package ID (`?package=` on the REST door, the `/layers` spelling) — for a type stored per (package, name), the holder whose versions to address: the slot of the row a read naming the package serves (its own row, its `.custom` pair's declared override, or the package-less row that read falls back to), else the package's own empty slot when it ships the name; a package that neither holds nor ships the name is refused 409 `not-held-by-qualifier` (ADR-0150 D3/D4). Versions attributed to no package, or to the environment, are that slot's only while it is the name's sole slot. Absent, a name two holders hold (in stored rows or in code) is refused 409 naming every holder, except where the read naming no package serves the row-held base (a bundled type's member whose active rows a base package and a package declaring it both hold, with no package-unbound row beside them): there the base's slot is addressed, as naming the base addresses it. Two packages neither of which declares the other are still refused. Refused with 400 `VALIDATION_ERROR` on a type not stored per (package, name). |
865+
| **packageId** | `string` | optional | Optional package ID (`?package=` on the REST door, the `/layers` spelling) — for a type stored per (package, name), the holder whose versions to address: the slot of the row a read naming the package serves (its own row, its `.custom` pair's declared override, or the package-less row that read falls back to), else the package's own empty slot when it ships the name; a package that neither holds nor ships the name is refused 409 `not-held-by-qualifier` (ADR-0150 D3/D4). Versions attributed to no package, or to the environment, are that slot's only while it is the name's sole slot. Absent, a name two holders hold (in stored rows or in code) is refused 409 naming every holder, except where the read naming no package serves the row-held base (a bundled type's member of a name no package ships in code, whose active rows a base package and one or more packages declaring it hold, with no package-unbound row beside them): there the base's slot is addressed, as naming the base addresses it. Two packages neither of which declares the other are still refused. Refused with 400 `VALIDATION_ERROR` on a type not stored per (package, name). |
866866

867867

868868
---

0 commit comments

Comments
 (0)