Skip to content

Commit 4dfb9f1

Browse files
fix(plugin-email): a name an enabled and a disabled package hold sends what it sends when only the enabled one holds it (#33678)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} --> _Requested by **Elon** · [project thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9D3DpgJLtDkE1fR76z3bz5Xm)_ Part of #32670 Clause-②: no Metadata-protocol: none The card stays open: its `_env` half is #33385 (area E1, still open). This PR is the "separate, declared move" that #33361's acceptance notes and its contract review (record 6882047833, item ③) left owed once #32354 landed. #32354 landed in #33405 (merged 2026-11-14T22:08Z, before #33361). ## 维护者速读 - 改了什么:邮件模板名有一个持有包被停用、只剩一个在服务的持有包时,发送(经元数据协议的执行列表)改为读环境级列表,与"只有这一个包持有该名"时完全一致;另把 `servedBundleAddressOf` 中不可达的环境项分支改为"找不到模板"(复审 nit N1)。 - 为什么改:ADR-0150 D3「停用的包不持有任何名字」。#32354(#33405)落地后,环境级列表已不再列出停用包一侧的成员(自身项、定制对行、依赖包追加的语言),所以地址可以只按在服务持有包数量来选;此前读该包自己的地址,会漏掉依赖它的包追加的语言。 - 风险与回滚:只在有持有包被停用、且只剩一个在服务持有包时生效。实测唯一变化:该持有包的定制对行与依赖包追加语言落在同一语言时,答案从定制对行变为依赖包的语言,与停用包根本不持有该名时的答案相同。没有包停用时、或无协议只读注册表时,答案不变。回滚即 revert 本 PR。 - 先看:`packages/plugins/plugin-email/src/template-loader.ts` 的 `servedBundleAddressOf`(`onServedCount` 与 `servedCountDecides` 参数)以及 `readBundle` 中 `viaProtocol` 的传入;`template-loader.test.ts` 中 `two holders, BETA disabled` 一例的期望与新的 `one holder` CONTROL。 - 两分钟验证:`pnpm --filter @objectstack/plugin-email exec vitest run src/template-loader.test.ts`,预期 80 个测试全部通过。 - 需要你做的:无,席位落地 ## What changes `packages/plugins/plugin-email/src/template-loader.ts`, `servedBundleAddressOf` (the branch taken only while a holder of the name is disabled): - **The address is chosen on the served count when the bundle is read from the protocol's execution list.** One served holder ⇒ the environment-wide list (`undefined`), two or more ⇒ the answering holder's own address, exactly as `bundleAddressOf` chooses on the holder count when nothing is disabled. This applies to both answers that read a package's bundle: the name resolving to a served holder, and the closure re-resolve (a caller holding an addition only, or the built-ins for an `auth.*` name). - **Why it is safe now:** since #33405 (#32354) the environment-wide execution list holds no member of a disabled holder's side: its own items were already filtered, and the list naming no package now withholds its customization pair's rows and a dependent's added bundle members. So the read beside a disabled holder answers what it answers when that holder holds nothing of the name. - **The registry's own list keeps the per-holder address.** `registry.listItems` (read only when no protocol is registered) withholds neither, so there the move would leak a dependent's addition to the disabled holder (measured, see the second ablation). `readBundle` passes `viaProtocol` into `bundleAddressOf` as `servedCountDecides`. - **Nit N1:** the environment-item branch (`resolved.holder.kind` other than `package`) now answers `NO_BUNDLE` instead of the environment-wide read. It is unreachable while a holder is disabled (a name a package holds resolves to no environment item), so no answer moves; "no read is made beside a disabled holder for it" now holds by construction. - Doc comments on `bundleAddressOf` and `servedBundleAddressOf` restate the rule. Changeset: `@objectstack/plugin-email` patch. ### Moved answers Probe: the #33361 world (a real `SchemaRegistry` and the protocol's real `getMetaItemsForExecution` over stored rows), 8 disabled states × 2 registration orders × 2 reads × 9 callers × 2 locales = 1,152 answers, on `babd5d4a` (FROM, `main`) and on this branch (TO), plus the same worlds with the disabled package's side removed instead of disabled (ABSENT: it ships nothing of the name; for ALPHA also no pair row and no dependent's addition). | Read | State | Caller | Locale | FROM | TO | ABSENT | |:--|:--|:--|:--|:--|:--|:--| | protocol | two holders, BETA disabled (ALPHA carries a pair row and a dependent's addition, both fr-FR) | omitted, null, ALPHA, BOTH, VIA_ALPHA, ADDER | fr-FR | the pair's row (`PAIR fr-FR`) | the dependent's addition (`ADDER fr-FR`) | `ADDER fr-FR` | 12 answers move (6 callers × 2 orders), all toward the ABSENT answer; 0 of the 1,152 move away from it. The answers that still differ from ABSENT number 204 (216 on FROM), and every one is a declared row of #33361: the disabled package's own send (row 36), the environment's item or a package-less stored row beside a name only a disabled package holds (row 37), and the registry-only read (below). With nothing disabled the code path is unchanged (`bundleAddressOf`'s first branch), and the pinned CONTROLs hold. ## Tests `packages/plugins/plugin-email/src/template-loader.test.ts`, describe `a disabled package holds no name at the send (ADR-0150 D3, #32670)`: - The `two holders, BETA disabled` case's protocol expectations move fr-FR from `PAIR fr-FR` to `ADDER fr-FR` for the six callers above (its registry-read override is unchanged: `no template`). - A new CONTROL, state `one holder` (ALPHA alone holds the name, nothing disabled), pins the answers the BETA-disabled case must equal for every caller but BETA itself. 1 case × 2 orders × 2 reads = 4 new tests; the file runs 80 (76 on `main`). ## Acceptance notes - **The registry-only read keeps a disabled-vs-absent difference.** With no protocol registered and BETA disabled, a fr-FR send for ALPHA's callers answers `no template` (ALPHA's own address, which the registry list narrows by `_packageId`), where ABSENT answers `ADDER fr-FR`. The move cannot be applied there because `registry.listItems` still lists a dependent's addition to a disabled holder (ablation 2 measures the leak). A host with no protocol has no metadata door; noted, not filed. - **The moved answer prefers the dependent's addition over the holder's pair row at the same locale.** That is `main`'s answer for a name one package holds with nothing disabled (the new CONTROL, both orders, and #33361's R4-F note), not a rule this PR adds: the move only makes the disabled case equal to it. - **Not in this PR:** the `_env` cell of #32183 row 17 (#33385, area E1, `packages/metadata-protocol/src/**`) and the R4-G flow doors, as #33361 recorded. So `Part of #32670`, not a closing line. - The probe files were temporary and are not committed. ## Verification Read at `7612a59d` (the change). The head `9754555c` adds one merge of `origin/main` (`dd291b83` era, no conflict); the incoming commits touch no file of `plugin-email` and nothing in the list reads or the package-scoped resolver the loader calls (they change `objectql` engine-update, search and validation files and `metadata-protocol`'s seed loader and registry question), so the readings below are not re-run on the merge; CI reads the head. <details><summary>Tests, typecheck and lint (plugin-email), at 7612a59</summary> ``` pnpm --filter @objectstack/plugin-email test Test Files 53 passed (53) · Tests 1018 passed (1018) pnpm --filter @objectstack/plugin-email typecheck exit 0 · check:test-typecheck OK (0 errors) pnpm exec eslint (the two changed source files) exit 0 os-verify-lock: VERDICT command-exit 0 ``` </details> <details><summary>Ablation 1: the pins against main's loader (template-loader.ts restored from babd5d4)</summary> ``` on-disk mutation: servedCountDecides count=0 (HEAD has 6) × read: protocol > registered as listed > two holders, BETA disabled × read: protocol > registered reversed > two holders, BETA disabled Tests 2 failed | 78 passed (80) VERDICT command-exit 1 restored: git checkout HEAD -- the file; blob hash equals HEAD's; git status clean ``` </details> <details><summary>Ablation 2: the move forced onto the registry read (servedCountDecides passed as true)</summary> ``` anchor before: 1 · after: 0 · injected: 1 × read: registry > two holders, ALPHA disabled (both orders: ADDER fr-FR leaks) × read: registry > two holders, BETA disabled (both orders) × read: registry > an auth name one package overrides, ALPHA disabled (both orders: ADDER fr-FR leaks) Tests 6 failed | 74 passed (80) VERDICT command-exit 1 restored: blob hash equals HEAD's; git status clean ``` </details> <details><summary>Gate families</summary> Derived with `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` at 7612a59 (64 commands), each run locally with its exit code captured before any pipe: ``` 61 of 64 exit 0 (check-adr-0087-registration, check-changeset-no-major, check-empty-changeset, check-issue-citations, check:engine-double-contract, check:test-source-alias, check:registry-log-declared, check:cross-package-test-inputs, check:nul-bytes, check:published-files, check:type-check-coverage, the comment-mask corpus and the rest) NOT MEASURED, 3 (prerequisites of this checkout, not readings of the diff; CI runs each): check-plugin-teardown-shape --self-test exit 3: shallow clone, positive control commit unreachable check:dual-build-cjs-loads exit 3: PREREQUISITE NOT MET, reads every package's dist/ check:type-check-debt exit 3 under the 4096 MB heap cap; re-run uncapped, it began a whole-closure build under the shared lock, stopped (not read) ``` </details> --- _Generated by [Claude Code](https://claude.ai/code/session_016WV4cx5ZPCyTk8ckTsx4ut)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
1 parent 481f642 commit 4dfb9f1

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)