Skip to content

Commit d9b72aa

Browse files
fix(metadata-protocol): the bare draft save beside a disabled package's rows writes the one enabled holder's draft (#39035)
Fixes #38753 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:作者在不指定包的情况下保存草稿时,如果同名条目有一个已停用包的数据和唯一一个启用包的数据,保存现在会写到启用包的草稿上,不再报冲突并点出已停用包的名字。 - 为什么做:这是「停用的包一律不算数」这项工作的最后一格,前一个合并已修好删除和丢弃草稿,这次补上保存草稿。 - 出错会怎样:最坏情况是这类草稿保存写到了启用包上而非报冲突;已停用包的数据不会被改动,撤回这次合并即可恢复原来的报错行为。 - 要你做什么:无。 ## What changes - `packages/metadata-protocol/src/protocol-save.ts`, `saveMetaItem`: just before the ambiguous-draft-address refusal (`disabledRowHoldersRefusal`), a draft save naming no package whose draft rows are bound to a disabled package D and to the one enabled holder E the read naming no package counts is re-addressed to E (`soleEnabledRowHolder`): `request.packageId = E`, `draftAddress` cleared, `followedBase = E`, as the row-held-base follow a few lines above does, so the named-base rule and the late override re-judgment judge E. Before: `409 RESOURCE_CONFLICT` naming D and E, while the bare read serves E and the bare publish save writes E's row. With two or more enabled holders `soleEnabledRowHolder` answers nothing and the refusal naming only the enabled holders stands. - The `packagelessHolderRefusal` docblock's "Known gap" paragraph is reworded: the delete, the draft discard and now the draft save all act at the one enabled holder first. - `packages/rest/src/meta-disabled-package-doors.test.ts`: four new cells on PR #38948's fixture (both save orders, D shipping the name in code or not): the bare draft save's effect on the stored rows equals its effect without D (E's draft replaced, nothing else), D's rows byte-unchanged, no refusal. The second-enabled-shipper CONTROL now also pins the draft save's `409` naming the two enabled shippers, never D, with nothing written. - `.changeset/38753-draft-save-cell.md`: `patch` for `@objectstack/metadata-protocol`. This is the last cell of #38753 (PR #38948 merged the rest as `Part of`), so this PR closes it. ## Tests <details><summary>Red first, fix, ablation (local, under the verify lock)</summary> - Red on `742b2442` (test only, fix absent): the four new draft-save cells failed with `RESOURCE_CONFLICT:409:Name the package this save is for, then send it again ... dashboard 'one_shipper_dash' belongs to 2 packages ('app.disabled_demo', 'app.healthy_demo') ...`; the other 11 cells of `-t 38753` (the extended CONTROL included) passed. - Green on `d059c60f` after rebuilding `@objectstack/metadata-protocol`: `-t 38753` 15 passed / 82 skipped. - Ablation (`scripts/ablation-replace.mjs --hold`, anchor `if (sole !== undefined) {` turned into a branch that never runs): rebuilt, `ablation-dist-preflight` found the marker in `dist/index.cjs` and `dist/index.js`; the four draft-save cells went red with the same 409 naming D and E, 11 passed. Restore leg: blob equal to HEAD, `git diff HEAD` empty, `git status --porcelain` empty; rebuilt, preflight `--absent` (marker absent from all 24 built files, tree clean); `-t 38753` 15 passed. </details> <details><summary>Suites and typecheck on 4fecd59 (local, under the verify lock)</summary> - `@objectstack/metadata-protocol`, full suite: 381 files passed / 9 skipped; 23940 tests passed / 45 skipped. - `pnpm turbo run typecheck --filter=@objectstack/metadata-protocol --filter=@objectstack/rest`: 33 of 33 tasks passed (rest's test layer compiles under `check:test-typecheck`, 0 errors). - `@objectstack/rest` full suite and `test:repo`: not run locally; CI's Test Core shards are the evidence. </details> <details><summary>Gates on 4fecd59</summary> - `dispatch-gates --commands` derived 72 families; all 72 run locally with exit codes; `--ran` reconciliation: 69 run, 3 NOT MEASURED (`check:dual-build-cjs-loads` exits 3, it needs every package's `dist/`; `check-comment-mask-corpus.mjs` and `check:query-options-erasure` did not finish inside a 240 s per-gate cap). 68 of the 69 run exit 0. - `pnpm check:closed-ceremony-text` exits 1, and will be red in `Lint & Repo Gates`: see the acceptance notes. - `overlap-check`: clean against `origin/main` 444dce6, 0 open PR heads sharing a file. </details> ## Acceptance notes - `protocol-enabled-holders.ts`'s module docblock and `soleEnabledRowHolder`'s own docblock still describe its callers as "the bare delete and draft discard"; the draft save is now a third caller. That file is read-only on this claim's surface, so the wording is left; noted, not filed. - **`check:closed-ceremony-text` goes red on this PR for a reason outside its diff.** `trackedFiles()` in `scripts/check-closed-ceremony-text.mjs` reads `git ls-files -z -- packages content/docs .changeset` through `execFileSync` with Node's default 1 MiB `maxBuffer` (1,048,576 bytes). That output is 1,048,565 bytes on `origin/main` 444dce6 and 1,048,601 bytes on this head; adding `.changeset/38753-draft-save-cell.md` (36 bytes with its NUL) crosses the limit, and the gate dies with `spawnSync git ENOBUFS` in both its self-test and its sweep. Any PR that adds a tracked file under those roots now trips it. The script is outside this claim's file surface, so it is not edited here; reported for filing as a reproducible defect. ## Verification Run `pnpm --filter @objectstack/rest exec vitest run --maxWorkers=2 src/meta-disabled-package-doors.test.ts -t 38753` after building `@objectstack/metadata-protocol`: 15 pass, including the four "the bare draft save writes E's draft" cells. Riskiest hunks: `packages/metadata-protocol/src/protocol-save.ts` (the new re-address block in `saveMetaItem`, and that `followedBase` now also carries the sole enabled holder into the named-base rule and the late override re-judgment). --- _Generated by [Claude Code](https://claude.ai/code/session_01WGufzhKEbEnW8pwZRgK2gJ)_ <!-- signed: repo:objectstack@os-support-ai · os-support-ai · session_01WGufzhKEbEnW8pwZRgK2gJ --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent f2ca884 commit d9b72aa

3 files changed

Lines changed: 76 additions & 9 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/metadata-protocol': patch
3+
---
4+
5+
fix(metadata-protocol): the draft save naming no package beside a disabled package's rows writes the one enabled holder's draft
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A draft save that names no package, of an item whose stored rows are bound to a disabled package and to the one enabled package that holds the name, now writes that enabled package's draft, as it does when the disabled package is not installed. The disabled package's rows stay as they are. Before, the save was refused `409 RESOURCE_CONFLICT` naming both packages, the disabled one among them, while the read naming no package served the enabled package's item and the publish save wrote its row. The bare delete and draft discard already act at that package's address. Where two or more enabled packages hold the name, the draft save is still refused naming only those packages.

‎packages/metadata-protocol/src/protocol-save.ts‎

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ import { overlayMemberValue } from './migrations/overlay-index.js';
9494
import { packagelessContentPackage, shippingPackageIds } from './protocol-environment-rows.js';
9595
import type { StoredOverlayRow } from './item-lock.js';
9696
import { installedManifestsOfEngine } from './installed-manifests.js';
97+
import { soleEnabledRowHolder } from './protocol-enabled-holders.js';
9798
import { packageScopedRefusalOf } from './protocol-meta-item-reads.js';
9899
import { pairsOf } from '@objectstack/metadata-core';
99100
import { BatchRowHealError, canJudgeBatchObjects, isBatchObjectType, readActiveBatchRow, settleBatchObjectRows, undoBatchRowWrite, undoOutcomeForLog, type WrittenBatchRow } from './batch-object-registration.js';
@@ -946,6 +947,26 @@ export class ProtocolSaveFacet {
946947
followedBase = base;
947948
}
948949
}
950+
// [#38753, ADR-0150 D3/D5, #32354] …or the one ENABLED holder the
951+
// read naming no package counts, where the ambiguous draft address's
952+
// rows are bound to a disabled package beside it
953+
// ({@link soleEnabledRowHolder}): the read serves that holder's item
954+
// and the bare publish save writes its row, so the draft save writes
955+
// its draft, as without the disabled package, and the disabled
956+
// package's rows stay where they are. Followed as the row-held base
957+
// above is, so the two rules below judge the package it inherits.
958+
// FROM (`main` 444dce61): refused `409` naming the disabled package
959+
// and the enabled one.
960+
if (draftAddress?.kind === 'ambiguous') {
961+
const sole = soleEnabledRowHolder(
962+
host, singularType, request.name, itemDiscriminator(singularType, request.item), draftAddress.candidates,
963+
);
964+
if (sole !== undefined) {
965+
request = { ...request, packageId: sole };
966+
draftAddress = undefined;
967+
followedBase = sole;
968+
}
969+
}
949970
// [#34346, ADR-0150 D3/D5] …and an ambiguous draft address whose
950971
// rows are bound to a disabled package too is refused naming the
951972
// holders the read naming no package counts, never the disabled one
@@ -3643,14 +3664,15 @@ export async function packagelessRowHeldBaseDraftAddress(
36433664
* registry without the reads.
36443665
*
36453666
* [#34346] With two or more ENABLED shippers and a disabled holder, the draft
3646-
* save and the delete take their address from the rows, so their refusal of
3647-
* rows bound to two or more packages is judged by
3667+
* save, the delete and the draft discard take their address from the rows, so
3668+
* their refusal of rows bound to two or more packages is judged by
36483669
* {@link disabledRowHoldersRefusal}, which never names the disabled package.
36493670
*
3650-
* Known gap (#38753): with ONE enabled shipper and the rows bound to it and to
3651-
* a disabled package, that helper answers `undefined` and the draft save and
3652-
* the delete still refuse `409` naming the disabled package, where the read
3653-
* serves the enabled shipper and the publish save writes its row.
3671+
* [#38753] With ONE enabled holder and the rows bound to it and to a disabled
3672+
* package, the draft save, the delete and the draft discard act at that
3673+
* holder's address first (`soleEnabledRowHolder`), where the read serves it
3674+
* and the publish save writes its row, so none of them reaches that refusal
3675+
* or names the disabled package.
36543676
*/
36553677
export function packagelessHolderRefusal(
36563678
host: Pick<ProtocolHost, 'engine' | 'shippedArtifactsOf'>,

‎packages/rest/src/meta-disabled-package-doors.test.ts‎

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,8 +1485,9 @@ describe('[#37915] RestServer: the history naming no package of a name only a di
14851485
* and the bare draft discard act at E's address, as without D, and D's rows
14861486
* stay byte-unchanged. FROM (`main` 8338d070, measured on this fixture, both
14871487
* save orders, D shipping the name in code or not): both refused `409
1488-
* RESOURCE_CONFLICT` naming D and E. The bare draft save still refuses
1489-
* naming both: its judgment sits in a file this change does not edit.
1488+
* RESOURCE_CONFLICT` naming D and E. The bare draft save too writes E's
1489+
* draft, as without D; FROM (`main` 444dce61): it refused `409` naming D
1490+
* and E.
14901491
*/
14911492
describe('[#38753] RestServer: the bare delete and draft discard beside a disabled package\'s rows and the one enabled shipper', () => {
14921493
const lay = (host: ReturnType<typeof setup>, pkg: string, label: string, state: 'active' | 'draft') => (host.protocol as any).engine.insert('sys_metadata', {
@@ -1534,7 +1535,31 @@ describe('[#38753] RestServer: the bare delete and draft discard beside a disabl
15341535
expect(effects[0].deleted.map((row) => row.split(':').slice(0, 2).join(':'))).toEqual([`active:${OTHER_PKG}`]);
15351536
}, 60_000);
15361537

1537-
it('CONTROL — a second enabled shipper: the bare delete and draft discard still refuse 409 naming the two enabled shippers, never D, and nothing is removed', async () => {
1538+
it.each(CELLS)('%s: the bare draft save writes E\'s draft, as without D, never 409 naming D, and D\'s rows stay', async (_label, order, disabledShips) => {
1539+
const effects: Array<{ removed: string[]; added: string[] }> = [];
1540+
for (const withD of [true, false]) {
1541+
const host = await boot(order, withD, disabledShips);
1542+
const before = await rowsOf(host);
1543+
const saved = await (host.protocol as any).saveMetaItem({
1544+
type: 'dashboard', name: 'one_shipper_dash', mode: 'draft',
1545+
item: { name: 'one_shipper_dash', label: 'edited draft', widgets: [] },
1546+
}).catch((error: any) => ({ refused: `${error?.code}:${error?.status ?? error?.httpStatus}:${error?.message}` }));
1547+
expect([withD, saved?.refused], String(saved?.refused)).toEqual([withD, undefined]);
1548+
const after = await rowsOf(host);
1549+
effects.push({
1550+
removed: before.filter((row) => !after.includes(row)),
1551+
added: after.filter((row) => !before.includes(row)),
1552+
});
1553+
// D's rows, both states, byte-unchanged.
1554+
expect(after.filter((row) => row.includes(`:${PKG}:`)), 'D\'s rows').toEqual(before.filter((row) => row.includes(`:${PKG}:`)));
1555+
}
1556+
expect(effects[0], JSON.stringify(effects)).toEqual(effects[1]);
1557+
expect(effects[0].removed.map((row) => row.split(':').slice(0, 2).join(':'))).toEqual([`draft:${OTHER_PKG}`]);
1558+
expect(effects[0].added.map((row) => row.split(':').slice(0, 2).join(':'))).toEqual([`draft:${OTHER_PKG}`]);
1559+
expect(effects[0].added.join('\n')).toContain('edited draft');
1560+
}, 60_000);
1561+
1562+
it('CONTROL — a second enabled shipper: the bare delete, draft discard and draft save still refuse 409 naming the two enabled shippers, never D, and nothing is written', async () => {
15381563
const THIRD_PKG = 'app.third_demo';
15391564
const host = await boot([PKG, OTHER_PKG], true, true);
15401565
host.registry.installPackage({ id: THIRD_PKG, name: THIRD_PKG, version: '1.0.0' } as any, 'code');
@@ -1547,6 +1572,16 @@ describe('[#38753] RestServer: the bare delete and draft discard beside a disabl
15471572
for (const pkg of [OTHER_PKG, THIRD_PKG]) expect(String(refusal?.message)).toContain(pkg);
15481573
expect(String(refusal?.message)).not.toContain(PKG);
15491574
}
1575+
let saveRefusal: any;
1576+
try {
1577+
await (host.protocol as any).saveMetaItem({
1578+
type: 'dashboard', name: 'one_shipper_dash', mode: 'draft',
1579+
item: { name: 'one_shipper_dash', label: 'edited draft', widgets: [] },
1580+
});
1581+
} catch (error) { saveRefusal = error; }
1582+
expect([saveRefusal?.code, saveRefusal?.status ?? saveRefusal?.httpStatus], String(saveRefusal?.message)).toEqual(['RESOURCE_CONFLICT', 409]);
1583+
for (const pkg of [OTHER_PKG, THIRD_PKG]) expect(String(saveRefusal?.message)).toContain(pkg);
1584+
expect(String(saveRefusal?.message)).not.toContain(PKG);
15501585
expect(await rowsOf(host)).toEqual(before);
15511586
}, 60_000);
15521587

0 commit comments

Comments
 (0)