Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/32849-nomember-read-declared-override.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@objectstack/metadata-protocol': patch
---

fix(metadata-protocol): the read naming no bundle member serves an App pair's declared override of the canonical member a bundle addition ships

Clause-②: no
Metadata-protocol: none

A read that names no bundle member addresses the canonical one (`en-US` for an email template), the same request as `?member=en-US`. When a bundle addition Z ships that canonical member beside another package's member of the same name (for example X ships `fr-FR`), and the App's customization pair (`<app>.custom`) stores a row declaring `overrides: { package: Z }` for it, `?member=en-US` already served the override. The plain read, the execution read and the layered read naming no member (`GET /meta/email_template/:name`, `?layers=true`) served Z's shipped `en-US` instead, and `/published`, which asks the layered read for its overlay exit, found no runtime-published row there.

They now judge the canonical member as `?member=en-US` does and read it at Z: the override is served, the layered `effective` is the override with Z's shipped member as `code`, and `/published` serves the override. The strict draft read and the layered draft layer stay where they were. Nothing else moves: no override declared, an undeclared pair row, a row declaring another package (still refused naming both), another package's own member, the environment's own item, a disabled shipper, and a bundle that ships no canonical member answer as before. No stored row changes shape.
20 changes: 15 additions & 5 deletions packages/metadata-protocol/src/protocol-meta-item-face.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {
} from '@objectstack/core';
import type { ObjectStackProtocolImplementation } from './protocol.js';
import { shippingPackageIds } from './protocol-environment-rows.js';
import { resolveBundleMemberSelector } from './protocol-bundle-members.js';
import { bundleMemberDiscriminator, resolveBundleMemberSelector } from './protocol-bundle-members.js';
import { installedManifestsOfEngine } from './installed-manifests.js';
import { pairsOf } from '@objectstack/metadata-core';
import { disabledExactAddressHolder } from './protocol-exact-qualifier.js';
Expand Down Expand Up @@ -424,20 +424,30 @@ export function isAnotherHoldersCopy(registry: any, type: string, name: string,
* The rows are read through `host.readItemActiveRows`, so the read below takes
* them instead of reading them again (#24371). The layered read naming no
* package takes the same address for its layers (`getMetaItemLayered`).
*
* [#32849] The read that names no member addresses the CANONICAL member
* ({@link bundleMemberDiscriminator}), which is the same request as naming it
* (`?member=en-US`), so it is judged at that member here and takes the same
* address. Before, it was left as it was: with the addition Z shipping the
* canonical member and a pair row declaring Z for it, the read naming no
* member served Z's shipped member while `?member=en-US` served the override.
* A bundle with no shipped canonical member has no one shipper of it here, and
* is left as it was. A type with no members is never moved.
*/
export async function declaredMemberOverrideAddressOf(
host: ServedRowHost,
type: string, name: string, member: string | undefined,
): Promise<string | undefined> {
if (member === undefined) return undefined;
const addressed = bundleMemberDiscriminator(type, member);
if (addressed === undefined) return undefined;
const registry: any = host.engine?.registry;
if (typeof registry?.readsByPackage !== 'function' || registry.readsByPackage(type) !== true) return undefined;
if (shippingPackageIds(host.shippedArtifactsOf(type, name)).size < 2) return undefined;
const memberShippers = [...shippingPackageIds(host.shippedArtifactsOf(type, name, undefined, member))];
const memberShippers = [...shippingPackageIds(host.shippedArtifactsOf(type, name, undefined, addressed))];
if (memberShippers.length !== 1) return undefined;
const [shipper] = memberShippers;
if (typeof registry.isPackageDisabled === 'function' && registry.isPackageDisabled(shipper) === true) return undefined;
if (typeof registry.getEnvironmentScopedItem === 'function' && registry.getEnvironmentScopedItem(type, name, member) !== undefined) {
if (typeof registry.getEnvironmentScopedItem === 'function' && registry.getEnvironmentScopedItem(type, name, addressed) !== undefined) {
return undefined;
}
let activeRows: Awaited<ReturnType<ServedRowHost['readItemActiveRows']>>;
Expand All @@ -448,7 +458,7 @@ export async function declaredMemberOverrideAddressOf(
activeRows = [];
}
const singular = PLURAL_TO_SINGULAR[type] ?? type;
const where = { type: singular, name, state: 'active', ...overlayMemberWhere(singular, member) };
const where = { type: singular, name, state: 'active', ...overlayMemberWhere(singular, addressed) };
const installed = installedManifestsOfEngine(host.engine);
return activeRows.some((row) => rowMatchesOverlayWhere(row, where) && isServedOverrideRowOf(row, shipper, installed))
? shipper
Expand Down
112 changes: 112 additions & 0 deletions packages/objectql/src/package-scoped-exact-qualifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,118 @@ describe('[#32849] the bare layered read serves the pair\'s declared override of
});
});

/**
* [#32849, ADR-0146 D8 item 2, ADR-0150 D4] The read naming NO member of a
* name whose canonical member (`en-US`) an addition ships, with the App's pair
* storing that addition's declared override of it. X ships `welcome` in
* `fr-FR`, the addition Z on X ships its `en-US`, and a row of the App's pair
* declares `overrides.package` Z for `en-US`. A read naming no member
* addresses the canonical member, the same request as `?member=en-US`, so it
* serves what that read serves: the override, at Z.
*
* BASE (measured on `main` b8456ebd4a, this fixture, both install orders):
* the plain bare read and the bare execution read served `zeta en-US`, and
* the bare layered read answered `effective` `zeta en-US` with `overlay`
* null, while `?member=en-US`, `?package=Z` and the layered `?member=en-US`
* served `pair en-US`. `/published` asks the layered read naming no member
* for its overlay exit, so it found no runtime-published row there either.
*/
describe('[#32849] the read naming no member serves the pair\'s declared override of the canonical member an addition Z ships, as `?member=en-US` does', () => {
const APP = 'com.acme.suite';
const X = 'com.acme.suitex';
const Z = 'com.acme.zeta';
const PAIR = `${APP}.custom`;
const moduleOf = (id: string, dependencies: Record<string, string>) => ({
id, name: id, version: '1.0.0', type: 'module', namespace: id.split('.').pop()!, dependencies,
}) as never;
const installZ = () => registry.installPackage(moduleOf(Z, { [APP]: '^1.0.0', [X]: '^1.0.0' }), 'code');
const tpl = (locale: string, packageId: string) => registry.registerItem('email_template', {
name: 'welcome', label: `${packageId.split('.').pop()} ${locale}`, locale,
subject: `${packageId.split('.').pop()} ${locale}`, bodyHtml: '<p>x</p>',
}, 'name' as never, packageId);
/** A row of the App's pair for the canonical member (stored with no `bundle_member`); an active one is hydrated as the boot lays it. */
const pairRow = (over: Record<string, unknown> = {}, state: 'active' | 'draft' = 'active') => {
const body = { name: 'welcome', label: state === 'draft' ? 'pair en-US draft' : 'pair en-US', locale: 'en-US', subject: 'pair en-US', bodyHtml: '<p>p</p>', ...over };
rows.push({ id: `row_en_${state}`, type: 'email_template', name: 'welcome', state, package_id: PAIR, bundle_member: null, metadata: JSON.stringify(body) });
if (state === 'active') registry.registerItem('email_template', { ...body, _packageId: PAIR, _provenance: 'org' }, 'name' as never);
};
type Served = { item?: { label?: string; _packageId?: string }; packageId?: string } | undefined;
type Layers = { code?: { label?: string } | null; overlay?: { label?: string } | null; effective?: { label?: string; _packageId?: string } | null; draft?: { label?: string } | null; packageId?: string };
const T = { type: 'email_template', name: 'welcome' } as const;
const plain = (over: Record<string, unknown> = {}, face: 'served' | 'execution' = 'served') =>
(face === 'served' ? protocol.getMetaItem : protocol.getMetaItemForExecution).call(protocol, { ...T, ...over } as never) as Promise<Served>;
const layered = (over: Record<string, unknown> = {}, withDraft = false) =>
protocol.getMetaItemLayered({ ...T, ...over } as never, { withDraft } as never) as Promise<Layers>;
const servedOf = (a: Served) => [a?.item?.label ?? null, a?.item?._packageId ?? null, a?.packageId];
const layersOf = (a: Layers) => [a.code?.label ?? null, a.overlay?.label ?? null, a.effective?.label ?? null, a.packageId];

beforeEach(() => {
registry.installPackage(manifest(APP), 'code');
registry.installPackage(moduleOf(X, { [APP]: '^1.0.0' }), 'code');
registry.installPackage(manifest(PAIR), 'code');
});

it.each([
['addition installed first', () => { installZ(); tpl('fr-FR', X); tpl('en-US', Z); pairRow({ overrides: { package: Z } }); }],
['row stored first', () => { tpl('fr-FR', X); pairRow({ overrides: { package: Z } }); installZ(); tpl('en-US', Z); }],
] as const)('the plain, execution and layered reads naming no member serve the override at Z, as `?member=en-US` does (%s; BASE: `zeta en-US`, no overlay)', async (_order, arrange) => {
arrange();
const named = await plain({ member: 'en-US' });
expect(servedOf(named), 'CONTROL: bare `?member=en-US` (UNCHANGED since the member read\'s fix)').toEqual(['pair en-US', Z, Z]);
expect(servedOf(await plain()), 'bare, no member').toEqual(servedOf(named));
expect(servedOf(await plain({}, 'execution')), 'the bare execution read, no member').toEqual(['pair en-US', Z, Z]);
const atZ = await layered({ packageId: Z });
expect(layersOf(atZ), 'CONTROL: `?package=Z&layers=true` (UNCHANGED)').toEqual(['zeta en-US', 'pair en-US', 'pair en-US', Z]);
expect(await protocol.packagelessLayeredReadRefusal(T as never), 'the door\'s step 1c refuses nothing').toBeUndefined();
// `/published` reads this same call for its overlay exit.
const bare = await layered();
expect(layersOf(bare), 'bare `?layers=true`, no member').toEqual(layersOf(atZ));
expect(bare.effective, '`effective` is the document `?member=en-US` serves').toEqual(atZ.effective);
expect(layersOf(await layered({ member: 'en-US' })), 'CONTROL: bare `?member=en-US&layers=true` (UNCHANGED)').toEqual(layersOf(atZ));
// CONTROL: X's own member is untouched by the override of Z's.
expect(servedOf(await plain({ member: 'fr-FR' })), 'bare `?member=fr-FR` (UNCHANGED)').toEqual(['suitex fr-FR', X, X]);
});

it('the draft stays at the strict draft read\'s address, which the arm does not move: the pair\'s pending draft (UNCHANGED; at Z\'s address it is no draft)', async () => {
installZ(); tpl('fr-FR', X); tpl('en-US', Z);
pairRow({ overrides: { package: Z } });
pairRow({ overrides: { package: Z } }, 'draft');
const strictDraft = await plain({ state: 'draft' });
expect([strictDraft?.item?.label, strictDraft?.item?._packageId], 'the plain bare strict draft read, no member').toEqual(['pair en-US draft', PAIR]);
const bare = await layered({}, true);
expect([bare.effective?.label, bare.draft?.label ?? null], 'bare `?layers=true` with drafts, no member').toEqual(['pair en-US', 'pair en-US draft']);
expect((await layered({ packageId: Z }, true)).draft ?? null, 'CONTROL: `?package=Z` reads no draft there (UNCHANGED)').toBeNull();
});

it.each([
['no row stored', () => { installZ(); tpl('fr-FR', X); tpl('en-US', Z); }],
['an undeclared pair row of the canonical member', () => { installZ(); tpl('fr-FR', X); tpl('en-US', Z); pairRow(); }],
] as const)('CONTROL — no override of Z declared (%s): the reads naming no member serve Z\'s own `en-US` and no overlay (UNCHANGED)', async (_order, arrange) => {
arrange();
expect(servedOf(await plain())).toEqual(['zeta en-US', Z, Z]);
expect(servedOf(await plain({}, 'execution'))).toEqual(['zeta en-US', Z, Z]);
expect(layersOf(await layered())).toEqual(['zeta en-US', null, 'zeta en-US', Z]);
});

it('CONTROL — the row declares X (the #32606 shape): the reads naming no member are not moved to Z, and keep their refusal naming both (UNCHANGED)', async () => {
installZ(); tpl('fr-FR', X); tpl('en-US', Z);
pairRow({ overrides: { package: X } });
for (const read of [() => plain(), () => layered()]) {
const err = await refusalOf(read);
expect([err.code, err.status, err.refusal.candidates.map((c) => (c as { packageId?: string }).packageId).sort()])
.toEqual(['RESOURCE_CONFLICT', 409, [X, Z].sort()]);
}
});

it('CONTROL — the shipper Z disabled: the plain read naming no member answers Z\'s withheld item, and the layered read is not moved by the override (UNCHANGED)', async () => {
installZ(); tpl('fr-FR', X); tpl('en-US', Z);
pairRow({ overrides: { package: Z } });
registry.disablePackage(Z);
expect(servedOf(await plain()), 'bare, no member').toEqual([null, null, Z]);
expect(layersOf(await layered()), 'bare `?layers=true`, no member').toEqual(['zeta en-US', null, 'zeta en-US', Z]);
});
});

/**
* [#33817, from #33131 N1] A package X of an App holds the name only through
* its own stored row (`package_id` X, hydrated into the bare slot), and that
Expand Down
Loading