Skip to content

Commit 7612a59

Browse files
committed
fix(plugin-email): a name an enabled and a disabled package hold sends what it sends when only the enabled one holds it
With a holder of the name disabled, the send's address over the protocol's execution list is now chosen on the served count, as it is chosen on the holder count with nothing disabled: one served holder reads the environment-wide list, which since the list doors withhold a disabled holder's side holds none of its members. The registry's own list keeps the per-holder address, since it withholds neither. The environment-item branch of servedBundleAddressOf (unreachable while a holder is disabled) now answers no template, so no read is made beside a disabled holder for it. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cx5ZPCyTk8ckTsx4ut
1 parent babd5d4 commit 7612a59

3 files changed

Lines changed: 79 additions & 29 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@objectstack/plugin-email': patch
3+
---
4+
5+
fix(plugin-email): a template name an enabled and a disabled package hold sends what it sends when only the enabled package holds it (ADR-0150 D3)
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
While one of two packages that hold an email template name is disabled, the send (over the metadata protocol's execution list) now reads the bundle the way it reads a name one package holds: from the environment-wide list, which no longer lists a disabled package's members, its customization pair's rows or a dependent's added locales. Before, it read the enabled package's own address, which leaves out the locales its dependents add.
11+
12+
FROM → TO, with `B` disabled and `A` the one enabled holder: a send of a locale that both `A`'s customization pair (`A.custom`) and a dependent of `A` carry answered the pair's row, and now answers the same member a send answers when `B` holds nothing of the name (the dependent's locale). Every other answer is unchanged, and nothing changes while no holder of the name is disabled, or when the loader reads the registry's own list (no protocol registered).

‎packages/plugins/plugin-email/src/template-loader.test.ts‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ describe('createRegistryEmailTemplateLoader — a disabled package holds no name
513513
};
514514
const STATES: Record<string, State> = {
515515
'two holders': { holders: [ALPHA, BETA], besideRow: 'none', adderDisabled: false, auth: false },
516+
'one holder': { holders: [ALPHA], besideRow: 'none', adderDisabled: false, auth: false },
516517
'two holders, the dependent disabled': { holders: [ALPHA, BETA], besideRow: 'none', adderDisabled: true, auth: false },
517518
'one holder beside the environment\'s item, registered first': { holders: [ALPHA], besideRow: 'environment item first', adderDisabled: false, auth: false },
518519
'one holder beside the environment\'s item, registered last': { holders: [ALPHA], besideRow: 'environment item last', adderDisabled: false, auth: false },
@@ -630,17 +631,19 @@ describe('createRegistryEmailTemplateLoader — a disabled package holds no name
630631
BUILTIN: ['409 outside-closure [BETA]', '409 outside-closure [BETA]'],
631632
},
632633
},
633-
{ // rows 27, 28 and 30, the pair's row the enabled holder's own
634+
{ // rows 27, 28 and 30, the enabled holder's side its own; the one served
635+
// holder is read from the environment-wide list, so every caller but the
636+
// disabled one answers as the CONTROL below, where only ALPHA holds it
634637
state: 'two holders', disabled: [BETA],
635638
protocol: {
636-
omitted: ['ALPHA en-US', 'PAIR fr-FR'],
637-
null: ['ALPHA en-US', 'PAIR fr-FR'],
638-
ALPHA: ['ALPHA en-US', 'PAIR fr-FR'],
639+
omitted: ['ALPHA en-US', 'ADDER fr-FR'],
640+
null: ['ALPHA en-US', 'ADDER fr-FR'],
641+
ALPHA: ['ALPHA en-US', 'ADDER fr-FR'],
639642
BETA: ['no template', 'no template'],
640-
BOTH: ['ALPHA en-US', 'PAIR fr-FR'],
641-
VIA_ALPHA: ['ALPHA en-US', 'PAIR fr-FR'],
643+
BOTH: ['ALPHA en-US', 'ADDER fr-FR'],
644+
VIA_ALPHA: ['ALPHA en-US', 'ADDER fr-FR'],
642645
NEITHER: ['409 outside-closure [ALPHA]', '409 outside-closure [ALPHA]'],
643-
ADDER: ['ALPHA en-US', 'PAIR fr-FR'],
646+
ADDER: ['ALPHA en-US', 'ADDER fr-FR'],
644647
BUILTIN: ['409 outside-closure [ALPHA]', '409 outside-closure [ALPHA]'],
645648
},
646649
registry: {
@@ -652,6 +655,21 @@ describe('createRegistryEmailTemplateLoader — a disabled package holds no name
652655
ADDER: ['ALPHA en-US', 'no template'],
653656
},
654657
},
658+
{ // CONTROL: only ALPHA holds the name, nothing disabled (the world above
659+
// with BETA holding nothing)
660+
state: 'one holder', disabled: [],
661+
protocol: {
662+
omitted: ['ALPHA en-US', 'ADDER fr-FR'],
663+
null: ['ALPHA en-US', 'ADDER fr-FR'],
664+
ALPHA: ['ALPHA en-US', 'ADDER fr-FR'],
665+
BETA: ['409 outside-closure [ALPHA]', '409 outside-closure [ALPHA]'],
666+
BOTH: ['ALPHA en-US', 'ADDER fr-FR'],
667+
VIA_ALPHA: ['ALPHA en-US', 'ADDER fr-FR'],
668+
NEITHER: ['409 outside-closure [ALPHA]', '409 outside-closure [ALPHA]'],
669+
ADDER: ['ALPHA en-US', 'ADDER fr-FR'],
670+
BUILTIN: ['409 outside-closure [ALPHA]', '409 outside-closure [ALPHA]'],
671+
},
672+
},
655673
{ // rows 31 and 36
656674
state: 'two holders', disabled: [ALPHA, BETA],
657675
protocol: {

‎packages/plugins/plugin-email/src/template-loader.ts‎

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,24 @@ type BundleAddress = string | undefined | typeof NO_BUNDLE;
171171
* [ADR-0150 D3, #32183, #32670] A disabled package holds no name at the send.
172172
* When no holder of the name is disabled, the reads below are the ones they
173173
* were: the served holders ARE every holder. When one is, the name is judged
174-
* over the served holders ({@link servedBundleAddressOf}).
174+
* over the served holders ({@link servedBundleAddressOf}); `servedCountDecides`
175+
* says the bundle is read from the protocol's execution list, which withholds
176+
* every member of a disabled holder's side.
175177
*/
176-
function bundleAddressOf(scoped: PackageScopedRegistry, name: string, callerPackageId: string | null): BundleAddress {
178+
function bundleAddressOf(
179+
scoped: PackageScopedRegistry,
180+
name: string,
181+
callerPackageId: string | null,
182+
servedCountDecides: boolean,
183+
): BundleAddress {
177184
const holdersOf = (options?: { includeDisabledPackages: true }) =>
178185
(scoped.packageScopedHoldersOf(EMAIL_TEMPLATE_TYPE, name, null, options) ?? [])
179186
.filter((id) => id !== BUILTIN_EMAIL_TEMPLATES_PACKAGE_ID);
180187
const holders = holdersOf({ includeDisabledPackages: true });
181188
const served = holdersOf();
182-
if (served.length < holders.length) return servedBundleAddressOf(scoped, name, callerPackageId, served, holders);
189+
if (served.length < holders.length) {
190+
return servedBundleAddressOf(scoped, name, callerPackageId, served, holders, servedCountDecides);
191+
}
183192
const resolved = resolvePackageScopedName(scoped, {
184193
type: EMAIL_TEMPLATE_TYPE, name, callerPackageId, includeDisabledPackages: true,
185194
});
@@ -202,46 +211,56 @@ function bundleAddressOf(scoped: PackageScopedRegistry, name: string, callerPack
202211
* disabled: judged over the served holders, so a disabled package is never
203212
* the answer, and a refusal names only the packages that serve the name.
204213
*
205-
* The answer is only ever a list that holds no member of a disabled holder's
206-
* side, because the environment-wide list does: a row its customization pair
207-
* stores and a locale a dependent adds to it stay listed there, and their
208-
* envelope (`_packageId`) is the slot they fill, not the package they are
209-
* stored under, so no member can be filtered out after the read. So:
214+
* Over the protocol's execution list (`servedCountDecides`), the address is
215+
* then chosen on the served count alone, as {@link bundleAddressOf} chooses
216+
* it on the holder count: a name one served package holds is read from the
217+
* environment-wide list, a name two or more hold at the answering holder's own
218+
* address. That list holds no member of a disabled holder's side: its own
219+
* items are filtered out, and the metadata lists withhold the rows its
220+
* customization pair stores and the locales a dependent adds to it (ADR-0150
221+
* D3, #32354). So a name an enabled and a disabled package hold sends what it
222+
* sends when only the enabled one holds it. The registry's own list
223+
* (`listItems`, read when no protocol is registered) withholds neither, so
224+
* there the answer is always read at one address: the answering holder's own.
225+
* So:
210226
*
211-
* - the name resolves to a served holder: that holder's own address (its
212-
* members, its pair's rows, its environment overlay), the list a name two
213-
* holders hold was already read at;
214-
* - the name resolves to the environment's own item: the environment-wide
215-
* list, as before (the caller has no package, and the bare-name meaning
216-
* is unchanged);
227+
* - the name resolves to a served holder: the environment-wide list when it
228+
* is the one served holder and the served count decides, else that
229+
* holder's own address;
217230
* - the caller's own holding is the disabled one, or no served holder
218231
* answers it: no template. Its own items are withheld, and no other
219232
* holder's are its own;
233+
* - the name resolves to the environment's own item: no template. A name a
234+
* package holds resolves to no environment item (the registry answers none
235+
* for it), so this answer is unreachable while a holder is disabled; it is
236+
* spelled so that no read is made beside a disabled holder for it;
220237
* - the caller holds an addition only, or the name resolves to the
221238
* built-ins: resolved again from the caller's closure over the served
222239
* holders, so a dependent of a disabled base never gets a template from
223-
* outside its closure; the built-ins are read at their own address, where
224-
* no disabled package's member is listed either.
240+
* outside its closure; the answer is read like a served holder's (the
241+
* built-ins answer an `auth.*` name only when no served package holds it,
242+
* so over the protocol it is the environment-wide list).
225243
*/
226244
function servedBundleAddressOf(
227245
scoped: PackageScopedRegistry,
228246
name: string,
229247
callerPackageId: string | null,
230248
served: readonly string[],
231249
holders: readonly string[],
250+
servedCountDecides: boolean,
232251
): BundleAddress {
233252
const resolved = resolvePackageScopedName(scoped, { type: EMAIL_TEMPLATE_TYPE, name, callerPackageId });
234253
if (resolved.status === 'refused') throw new EmailTemplateAmbiguousError(resolved);
235-
if (resolved.status !== 'resolved') return NO_BUNDLE;
236-
if (resolved.holder.kind !== 'package') return undefined;
254+
if (resolved.status !== 'resolved' || resolved.holder.kind !== 'package') return NO_BUNDLE;
255+
const onServedCount = (holder: string): BundleAddress => (servedCountDecides && served.length < 2 ? undefined : holder);
237256
const holder = resolved.holder.packageId;
238-
if (served.includes(holder)) return holder;
257+
if (served.includes(holder)) return onServedCount(holder);
239258
if (holders.includes(holder)) return NO_BUNDLE;
240259
const base = resolvePackageScopedName(withoutCallerHolding(scoped), { type: EMAIL_TEMPLATE_TYPE, name, callerPackageId });
241260
if (base.status === 'refused') throw new EmailTemplateAmbiguousError(base);
242261
if (base.status !== 'resolved' || base.holder.kind !== 'package') return NO_BUNDLE;
243262
const baseHolder = base.holder.packageId;
244-
return baseHolder === BUILTIN_EMAIL_TEMPLATES_PACKAGE_ID || served.includes(baseHolder) ? baseHolder : NO_BUNDLE;
263+
return baseHolder === BUILTIN_EMAIL_TEMPLATES_PACKAGE_ID || served.includes(baseHolder) ? onServedCount(baseHolder) : NO_BUNDLE;
245264
}
246265

247266
/**
@@ -342,10 +361,11 @@ export function createRegistryEmailTemplateLoader(
342361
// disabled holder, finds nothing (#32670); any other answer leaves the
343362
// bundle to the environment-wide read below, as before.
344363
const scoped = packageScopedRegistryOf(registry);
345-
const address = scoped ? bundleAddressOf(scoped, name, options?.callerPackageId ?? null) : undefined;
364+
const viaProtocol = typeof protocol?.getMetaItemsForExecution === 'function';
365+
const address = scoped ? bundleAddressOf(scoped, name, options?.callerPackageId ?? null, viaProtocol) : undefined;
346366
if (address === NO_BUNDLE) return [];
347367
let items: unknown[];
348-
if (typeof protocol?.getMetaItemsForExecution === 'function') {
368+
if (viaProtocol) {
349369
const listed = await protocol.getMetaItemsForExecution(
350370
address === undefined ? { type: EMAIL_TEMPLATE_TYPE } : { type: EMAIL_TEMPLATE_TYPE, packageId: address },
351371
);

0 commit comments

Comments
 (0)