Skip to content

Commit ef126bd

Browse files
committed
fix(metadata-protocol,cli): list a package-less view container cannot_declare, never attempt it
The packageless-overlays census listed a package-less view container row movable, and every --apply failed it: the move's declared save adds overrides, which the container schema refuses as an unrecognized key. The census now asks the save door's own schema whether the body can carry the override declaration (overrideDeclarationRefusedByShape) and lists a row that cannot as cannot_declare, with the way out in the CLI; the move never attempts it. The package-less close and the close of a write naming the base read the same predicate, so neither closes a write whose fix cannot be taken. Claude-Session: https://claude.ai/code/session_01Utp6CbC5BpV41NMLrJMt8Q Co-authored-by: Claude <noreply@anthropic.com>
1 parent 8b117c0 commit ef126bd

6 files changed

Lines changed: 235 additions & 4 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@objectstack/metadata-protocol': patch
3+
'@objectstack/cli': patch
4+
---
5+
6+
fix(metadata-protocol,cli): `os migrate packageless-overlays` lists a package-less view container `cannot_declare` instead of `movable`, and `--apply` no longer attempts (and fails) it on every run
7+
8+
Clause-②: yes (widening)
9+
Metadata-protocol: none
10+
11+
- **`@objectstack/metadata-protocol`: the census gains the disposition `cannot_declare`** (`PackagelessOverlayDisposition`, reachable through the exported `PackagelessOverlayCensus`). A row lands there when the schema the save door judges its body by refuses an `overrides` key on it, so the declared save the move makes could never land. Of the five overlay types the ceremony moves, that is a view container (`list` / `listViews` / `form` / `formViews`): only a single view declares an override. Before, such a row was listed `movable` and every `--apply` reported it `failed` with `Unrecognized key(s) on this view container: overrides`, leaving the row where it was. Now `migratePackagelessOverlays` does not attempt it: no outcome, no failure, no pair ensured for it.
12+
- **The two closes read the same answer.** The package-less write close (`packagelessCloseSubject`) closes only what the ceremony moves, so a container's package-less save and delete stay open, as they were before the close: they are the one door such a row keeps. The close of a write naming the read-only base (`overlayPairFixAdmits`, the "the fix can be taken" predicate both closes ask) no longer names the pair as the fix for a container body, because that fix (a declared save into the pair) cannot be taken; that write keeps the answer it had before the close.
13+
- **`@objectstack/cli`: `os migrate packageless-overlays`** prints the way out for a `cannot_declare` row under "left as they are": save each of the container's views into the pair as a single view named `<object>.<view>` (one the base ships declaring `overrides: { package, basedOn }`, a new one declaring nothing), then delete the container row with a delete naming no package (naming the base, for a row bound to it). In `--json`, the row carries `disposition: "cannot_declare"` and `outcome: "left"`, and `--apply` exits 0 for it.

‎packages/cli/src/commands/migrate/packageless-overlays.integration.test.ts‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,27 @@ const BOUND_SEED: SeedRow[] = [
102102
{ type: 'view', name: ENV_VIEW, state: 'active', body: viewBody(ENV_VIEW, STORED_COLUMNS) },
103103
];
104104

105+
/**
106+
* [#30261] A database whose customization of the package's view container (a
107+
* list view the package does not ship added beside its default list) was
108+
* stored as a package-less CONTAINER row, beside the environment row (control).
109+
*/
110+
const CONTAINER = 'm28413_task';
111+
const CONTAINER_SEED: SeedRow[] = [
112+
{
113+
type: 'view', name: CONTAINER, state: 'active', body: {
114+
object: 'm28413_task',
115+
list: { label: 'All', type: 'grid', data: { provider: 'object', object: 'm28413_task' }, columns: STORED_COLUMNS.map((field) => ({ field })) },
116+
listViews: { mine: { label: 'Mine', type: 'grid', data: { provider: 'object', object: 'm28413_task' }, columns: DRAFT_COLUMNS.map((field) => ({ field })) } },
117+
},
118+
},
119+
{ type: 'view', name: ENV_VIEW, state: 'active', body: viewBody(ENV_VIEW, STORED_COLUMNS) },
120+
];
121+
105122
let dir: string;
106123
let templateDb: string;
107124
let boundTemplateDb: string;
125+
let containerTemplateDb: string;
108126
const savedCwd = process.cwd();
109127
const ENV_KEYS = ['OS_ARTIFACT_PATH', 'OS_DATABASE_URL', 'DATABASE_URL', 'OS_DATABASE_DRIVER', 'OS_HOME', 'NODE_ENV',
110128
'OS_AUTH_SECRET', 'AUTH_SECRET', 'BETTER_AUTH_SECRET', 'OS_ENVIRONMENT_ID'] as const;
@@ -250,8 +268,11 @@ beforeAll(async () => {
250268
await seed.shutdown();
251269
boundTemplateDb = join(dir, 'bound-template.db');
252270
copyFileSync(templateDb, boundTemplateDb);
271+
containerTemplateDb = join(dir, 'container-template.db');
272+
copyFileSync(templateDb, containerTemplateDb);
253273
await insertRows(templateDb, SEED);
254274
await insertRows(boundTemplateDb, BOUND_SEED);
275+
await insertRows(containerTemplateDb, CONTAINER_SEED);
255276
}, CASE_TIMEOUT_MS);
256277

257278
afterAll(() => {
@@ -384,3 +405,34 @@ describe('os migrate packageless-overlays: a row bound to the read-only package'
384405
expect(again.payload.rows).toEqual([]);
385406
}, CASE_TIMEOUT_MS * 3);
386407
});
408+
409+
/**
410+
* [#30261] A package-less view CONTAINER row of the package's view: its shape
411+
* refuses the `overrides` key, so the declared save `--apply` makes could
412+
* never land. The preview lists it `cannot_declare` (left), and `--apply`
413+
* attempts nothing: no failure, exit 0, the row and the database as they were.
414+
* Before, the preview listed it movable and every `--apply` failed it.
415+
*/
416+
describe('os migrate packageless-overlays: a package-less view container', () => {
417+
it('the preview lists it `cannot_declare`, left; --apply attempts nothing, fails nothing, and leaves the row', async () => {
418+
const db = caseDb(containerTemplateDb);
419+
const before = await storedRows(db);
420+
const preview = await runJson(['--database-url', `file:${db}`, '--json']);
421+
expect(preview.payload.error, JSON.stringify(preview.payload).slice(0, 600)).toBeUndefined();
422+
expect(preview.exitCode).toBe(0);
423+
expect(preview.payload.rows.map((r: any) => `${r.type}/${r.name}/${r.state} ${r.disposition} ${r.base} → ${r.pair} ${r.outcome}`)).toEqual([
424+
`view/${CONTAINER}/active cannot_declare ${PKG} → ${PAIR} left`,
425+
]);
426+
expect(preview.payload.movable).toBe(0);
427+
expect(preview.payload.left).toBe(1);
428+
429+
const { payload, exitCode } = await runJson(['--apply', '--yes', '--database-url', `file:${db}`, '--json']);
430+
expect(payload.error, JSON.stringify(payload).slice(0, 600)).toBeUndefined();
431+
expect(exitCode).toBe(0);
432+
expect(payload.failed).toBe(0);
433+
expect(payload.moved).toBe(0);
434+
expect(payload.rows.map((r: any) => `${r.name} ${r.disposition} ${r.outcome}`)).toEqual([`${CONTAINER} cannot_declare left`]);
435+
expect(await storedRows(db)).toEqual(before);
436+
expect(await storedPackages(db)).not.toContain(PAIR);
437+
}, CASE_TIMEOUT_MS * 2);
438+
});

‎packages/cli/src/commands/migrate/packageless-overlays.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ function reasonOf(row: CensusRow): string {
6363
+ '(served then at that package\'s address, ?package=<base>).';
6464
case 'no_pair':
6565
return `'${row.base}' has no paired .custom package id, so there is nowhere to move it. Left as it is.`;
66+
case 'cannot_declare':
67+
// [#30261] Its shape refuses the `overrides` key, so the move's declared save can never land.
68+
return (row.type === 'view'
69+
? 'it is a view container (list/listViews/form/formViews), and only a single view can declare an override, '
70+
: 'its shape cannot carry an `overrides` declaration, ')
71+
+ 'so it cannot be moved as one. Left as it is: '
72+
+ (row.type === 'view'
73+
? `save each of its views into '${row.pair}' as a single view named <object>.<view> (?package=${row.pair}) — `
74+
+ `one '${row.base}' ships declaring overrides: { package: '${row.base}', basedOn }, a new one declaring nothing — `
75+
: `save its content into '${row.pair}' in a shape that declares overrides: { package: '${row.base}', basedOn } — `)
76+
+ `then delete this row with a delete naming ${row.boundToBase ? `'${row.base}'` : 'no package'}.`;
6677
case 'foreign_declaration':
6778
return `its body already carries an \`overrides\` key that does not name '${row.base}'. Left as it is: `
6879
+ (row.boundToBase

‎packages/metadata-protocol/src/protocol-packaged-base-refusal.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
import { SysMetadataRepository } from './sys-metadata-repository.js';
4747
import { OBJECT_EXTENSION_TYPE } from './protocol-object-extension-item.js';
4848
import { customizationPairEnsureRefusal, type PairRegistry } from './protocol-customization-package.js';
49+
import { resolveOverlaySchema } from './protocol-meta-type-schema.js';
4950
import { overlayMemberField, overlayMemberOfBody, overlayMemberValue } from './migrations/overlay-index.js';
5051
import {
5152
customizationBasePackageId,
@@ -419,10 +420,59 @@ export function overlayPairFixAdmits(
419420
...(body ?? { name, ...(disc && member !== null ? { [disc]: member } : {}) }),
420421
overrides: { package: fix.base, basedOn: fix.basedOn },
421422
};
423+
// [#30261] The save door's schema half: a body whose shape cannot carry
424+
// the declaration (a view container) is refused there, whatever the gate
425+
// answers. A bare identity has no shape to judge.
426+
if (body !== undefined && overrideDeclarationRefusedByShape(type, body)) return false;
422427
const verdict = host.overrideWriteVerdict({ type, name, packageId: fix.pair, item: declaredBody });
423428
return verdict.verdict !== 'refuse';
424429
}
425430

431+
/**
432+
* [#30261, ADR-0146 D2, D11] Whether the schema the save door judges `body`
433+
* by (`resolveOverlaySchema`, the door's own resolver) refuses an `overrides`
434+
* key on it as unrecognized: the body's SHAPE cannot carry the override
435+
* declaration, so no save declaring it lands, whatever the override write gate
436+
* answers.
437+
*
438+
* Measured over the five overlay types the ceremony moves, one shape answers
439+
* `true`: the view CONTAINER (`ViewSchema`, the `container` member of
440+
* `ViewMetadataSchema`). A single view, a list or form overlay, a dashboard, a
441+
* report, a translation and an email template each spread
442+
* `OverrideDeclarationFields`. Read from the parse, not from a list of shapes,
443+
* so a member that gains or loses the key is answered by its own schema.
444+
*
445+
* Only the refusal of the KEY is read: an `unrecognized_keys` issue naming
446+
* `overrides` at the body's root, or at the root inside a union's branch
447+
* issues (the view union keeps the branch the body claims and mutes the
448+
* others, `focusClaimedBranch`). Every other finding on the body is the save
449+
* door's to answer, as before, and answers `false` here. The body's own
450+
* `overrides` value, if any, is replaced by a well-formed probe: the key
451+
* alone decides.
452+
*/
453+
export function overrideDeclarationRefusedByShape(type: string, body: Record<string, unknown>): boolean {
454+
const schema = resolveOverlaySchema(type, body);
455+
if (!schema) return false;
456+
const parsed = schema.safeParse({ ...body, overrides: OVERRIDES_KEY_PROBE });
457+
return !parsed.success && parsed.error.issues.some(namesOverridesAtRoot);
458+
}
459+
460+
/** A well-formed declaration: the probe asks whether the KEY is carried, so its value raises nothing. */
461+
const OVERRIDES_KEY_PROBE = Object.freeze({ package: 'com.example.base', basedOn: '1.0.0' });
462+
463+
/** An `unrecognized_keys` issue naming `overrides` at the parsed body's root, here or in a union branch's issues. */
464+
function namesOverridesAtRoot(issue: unknown): boolean {
465+
const candidate = issue as { code?: unknown; path?: unknown; keys?: unknown; errors?: unknown } | null;
466+
if (candidate?.code === 'unrecognized_keys') {
467+
return Array.isArray(candidate.path) && candidate.path.length === 0
468+
&& Array.isArray(candidate.keys) && candidate.keys.includes('overrides');
469+
}
470+
if (candidate?.code === 'invalid_union' && Array.isArray(candidate.errors)) {
471+
return candidate.errors.some((branch) => Array.isArray(branch) && branch.some(namesOverridesAtRoot));
472+
}
473+
return false;
474+
}
475+
426476
/** The class members {@link namedBaseCloseSubject} reads, typed as the class declares them. */
427477
export interface NamedBaseCloseHost {
428478
readonly engine: ObjectStackProtocolImplementation['engine'];

‎packages/metadata-protocol/src/protocol-packageless-overlay-migration.ts‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@
3434
* "Ships" counts read-only code packages only, as the write gate does: a
3535
* writable package's item is edited in place (ADR-0070), and the pair itself
3636
* is writable.
37+
* - `cannot_declare` (#30261) — the body's shape cannot carry the override
38+
* declaration: the schema the save door judges it by refuses an `overrides`
39+
* key on it ({@link overrideDeclarationRefusedByShape}). Of the five overlay
40+
* types, that is a view CONTAINER (`list` / `listViews` / `form` /
41+
* `formViews`): only a single view declares an override. Listed with the
42+
* way out — each of its views saved into the pair as a single view, then
43+
* the container deleted naming no package — and never attempted, so no run
44+
* fails it.
3745
* - `foreign_declaration` — the body already carries an `overrides` key that
3846
* does not name the base: listed, never rewritten.
3947
* - `shadowed` — the pair already holds a row of that item, in EITHER state
@@ -136,6 +144,7 @@ import type { ObjectStackProtocolImplementation } from './protocol.js';
136144
import {
137145
overlayPairFixAdmits,
138146
overlayPairFixOf,
147+
overrideDeclarationRefusedByShape,
139148
overrideWriteMemberOf,
140149
type OverrideWriteSubject,
141150
type OverrideWriteVerdict,
@@ -165,6 +174,7 @@ export type PackagelessOverlayDisposition =
165174
| 'movable'
166175
| 'multi_shipped'
167176
| 'no_pair'
177+
| 'cannot_declare'
168178
| 'foreign_declaration'
169179
| 'shadowed';
170180

@@ -357,8 +367,14 @@ function addedMemberOf(
357367
* {@link listPackagelessOverlays} lists by it, and the close of the
358368
* package-less write ({@link packagelessCloseSubject}) refuses only a row it
359369
* answers `movable` — ⛔ never a second copy.
370+
*
371+
* `type` is the canonical singular type: `cannot_declare` reads the schema the
372+
* save door judges the body by. It is asked before `foreign_declaration` and
373+
* `shadowed`, whose ways out end in this ceremony moving the row; with no body
374+
* (a write of an unstored item that carries none) there is no shape to judge.
360375
*/
361376
export function classifyPackagelessRow(
377+
type: string,
362378
shippers: readonly string[],
363379
body: Record<string, unknown> | undefined,
364380
shadowOf: (pair: string) => unknown,
@@ -368,6 +384,7 @@ export function classifyPackagelessRow(
368384
const pairId = customizationPackageId(base);
369385
if (!pairId.ok) return { base, disposition: 'no_pair' };
370386
const pair = pairId.value;
387+
if (body !== undefined && overrideDeclarationRefusedByShape(type, body)) return { base, pair, disposition: 'cannot_declare' };
371388
const declared = (body as { overrides?: unknown } | undefined)?.overrides;
372389
if (declared !== undefined && (declared === null || typeof declared !== 'object'
373390
|| (declared as { package?: unknown }).package !== base)) {
@@ -439,7 +456,7 @@ export async function listPackagelessOverlays(
439456
};
440457
const body = bodyOf(row);
441458
// A row bound to the base names its base: the binding is its one shipper.
442-
const classified = classifyPackagelessRow(binding !== undefined ? [binding] : shippers, body,
459+
const classified = classifyPackagelessRow(type, binding !== undefined ? [binding] : shippers, body,
443460
(pair) => shadowOf(pair, type, name, member, state));
444461
const addedMember = classified.disposition === 'movable' && classified.base !== undefined
445462
? addedMemberOf(this, type, name, classified.base, body)
@@ -719,10 +736,12 @@ export interface PackagelessWriteSubject {
719736
* member and state, or — when there is none — the row a save would store
720737
* (its body), or none at all (a delete or rollback of an unstored item);
721738
* - it is classified by the census's own {@link classifyPackagelessRow}:
722-
* only `movable` is closed (`multi_shipped`, `no_pair`,
739+
* only `movable` is closed (`multi_shipped`, `no_pair`, `cannot_declare`,
723740
* `foreign_declaration` and `shadowed` stay open, and so does a name no
724741
* read-only package ships). `shadowed` applies to a stored row only: a
725-
* first write has nothing in the pair to be shadowed by;
742+
* first write has nothing in the pair to be shadowed by. `cannot_declare`
743+
* (a view container, #30261) has no declared write into the pair at all,
744+
* so its package-less write is the one door it keeps;
726745
* - its move must be able to succeed, read from the steps the ceremony
727746
* takes: `overlayPairFixOf` and `overlayPairFixAdmits`
728747
* (`protocol-packaged-base-refusal.ts`), the predicate the close of the
@@ -771,7 +790,7 @@ export async function packagelessCloseSubject(
771790
const writtenBody = request.item !== null && typeof request.item === 'object' && !Array.isArray(request.item)
772791
? (request.item as Record<string, unknown>) : undefined;
773792
const body = stored !== undefined ? storedBody : writtenBody;
774-
const classified = classifyPackagelessRow(shippers, body, (p) => (stored === undefined
793+
const classified = classifyPackagelessRow(type, shippers, body, (p) => (stored === undefined
775794
? undefined
776795
: ofItem.find((row) => row.package_id === p && stateOf(row) === request.state)
777796
?? ofItem.find((row) => row.package_id === p)));

0 commit comments

Comments
 (0)