Skip to content

Commit 64c4285

Browse files
fix(plugin-email): a host's own mail transport reads as in use on GET /api/settings/mail (#34731)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9SCDb2wCYDLuCsxUCkbNfGs)_ Fixes #32799 Clause-②: yes (widening) — the served `live` entry of `GET /api/settings/:namespace` now also admits `{ value: null, source: 'environment' }`; every entry served before is served unchanged Metadata-protocol: none ## 维护者速读 - **改了什么:** 宿主交给 plugin-email 的自带投递方式(选项表叫不出名字,比如托管平台代发通道),现在在 `GET /api/settings/mail` 上报为 `live.provider = { value: null, source: 'environment' }`,即「在用、来自运行环境、选项表叫不出名」。spec 只改 `live` 的说明文字(形状不变),service-settings 判定放行 `environment + null` 这一种组合。 - **为什么改:** 按裁决 C(6942903820)。托管环境邮件一直在发,但设置清单读不到,邮件行显示未完成。 - **风险与回滚:** 低。只多放行一种组合;`settings + null`、无选项表的键照旧丢弃;内置 smtp/resend/postmark 读数不变。回滚即 revert 本 PR。控制台 `isMailDelivering` 目前把 `environment + null` 读成未完成,要等 ui 跟进卡 #34749 才会打勾。 - **先看:** `packages/services/service-settings/src/settings-service.ts`(`judgeLiveValue` 新增一行)、`packages/plugins/plugin-email/src/live-transport-status.ts`(新增一个分支)、`packages/spec/src/system/settings-manifest.zod.ts`(`live` 说明)。 - **两分钟验证:** `pnpm --filter @objectstack/plugin-email exec vitest run src/live-transport-status.pin.test.ts`,预期 21 个通过,其中「environment: the host's own transport …」一条读到 `{ value: null, source: 'environment' }`。 - **需要你做的:** 待契约复审(L2)通过后,由席位请你批准这个 spec 面 PR。 ## What changes - **`@objectstack/spec`** — `SettingsNamespacePayloadSchema.live`: the docblock and the `value`/`source` describes now say a non-null `value` is one of the key's options, and `value` is `null` under `'none'` (nothing in use) or `'environment'` (in use, supplied by the boot environment or host, named by no option). In-use is read from `source`, never from `value === null`; `'settings'` always names an option. Shape unchanged. Generated `content/docs/references/system/settings-manifest.mdx` regenerated. - **`@objectstack/service-settings`** — `judgeLiveValue` serves `{ value: null, source: 'environment' }`. `settings` + `null` and any entry on a key with no option table stay dropped. `SettingsLiveValue` / `SettingsLiveStatus.values` docs follow. - **`@objectstack/plugin-email`** — `describeLiveMailTransport` states `{ value: null, source: 'environment' }` for an `environment`-origin transport no `provider` option names (a plain `IEmailTransport` the host hands over). Stock transports read as before; a transport swapped in through `setTransport` is still not stated; a `settings` origin with no option is still not stated. - Root changeset `.changeset/32799-host-mail-transport-live-environment.md` (patch × 3). ## Tests - `packages/plugins/plugin-email/src/live-transport-status.pin.test.ts` — **changed existing test**: "states nothing for a transport no option names, or one this plugin did not install" split in two. The host's-own-transport half now asserts `{ value: null, source: 'environment' }` through the served door (real `SettingsService` + mail manifest, body parsed by `SettingsNamespacePayloadSchema`), as ruling C requires. The swapped-transport half keeps "not stated", plus a host-own transport swapped through `setTransport`. New unit pin: a no-option transport is stated only under `environment` (not `settings`, not without an origin). - `packages/services/service-settings/src/settings-routes.live-status.pin.test.ts` — new: `environment` + `null` served on the mail page with no warn; new drop row: a key with no option table as `environment` + `null`. The existing `settings` + `null` drop row is relabelled ("no value under source \"settings\""). - `packages/spec/src/system/settings-manifest.test.ts` — the payload parses `environment` + `null`. ## Acceptance notes - Console follow-up owed (`domain:ui`, not in this claim, ruling C's "另立 ui 卡"): `ui/apps/console/src/pages/settings/firstRunChecklistLogic.ts` `isMailDelivering` treats `environment` as done only with a non-empty string `value`, so `{ value: null, source: 'environment' }` reads not done (before this PR the absent statement fell back to `isMailConfigured(values)`). `ui/apps/console/src/pages/settings/types.ts` still documents "`null` exactly when `source` is `'none'`". Filed #34749. ## Verification At head `9e70d11b5a453c4a787655c649a0284c4f29f896` (merge base origin/main `dc66d330`); full report: card comment 6944198803. - Package suites under `os-verify-lock`: `@objectstack/service-settings` 76 files / 1516 passed; `@objectstack/plugin-email` 54 / 1025 passed; `@objectstack/spec` `src/system` 73 / 2577 passed. - Typecheck: spec, service-settings, plugin-email exit 0. - `dispatch-gates --commands` derives 117; `--ran`: 117 run, 0 NOT-MEASURED, 0 UNRUN. <details><summary>Ablations (scripts/ablation-replace.mjs; each restored blob == HEAD, git diff HEAD empty)</summary> - Judge line `if (source === 'environment' && value === null) …` removed: service-settings pin 1 failed / 23 passed. The plugin-email pins resolve the service-settings dist built before the mutation, so no dist leg was taken there. - plugin-email branch `else if (!option && origin === 'environment') …` removed: plugin-email pin 2 failed / 19 passed (the unit pin and the served-door pin). </details> <details><summary>Gate re-runs</summary> The first pass ran beside a locked build on a shared box. Four commands were non-zero and each passed when re-run: `check-plugin-teardown-shape --self-test` exited 3 until the pinned commit was fetched; spec `check:generated` and spec `typecheck` hit a tsc out-of-memory and passed alone; `check:skill-examples` and `check:dual-build-cjs-loads` exited 3 (no built dist) and passed after a turbo build of `./packages/**`. </details> CI at this head: 68 check-runs, 58 success, 10 skipped, 0 failed. <!-- signed: repo:objectstack#2 · os-steve · session_01ADHkmTBjYWuaUonx8DhAbB --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 0afe509 commit 64c4285

9 files changed

Lines changed: 110 additions & 25 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@objectstack/spec': patch
3+
'@objectstack/service-settings': patch
4+
'@objectstack/plugin-email': patch
5+
---
6+
7+
fix(plugin-email): a host's own mail transport now reads as in use on `GET /api/settings/mail` (`live.provider` is `{ value: null, source: 'environment' }`)
8+
9+
Clause-②: yes (widening) — the served `live` entry of `GET /api/settings/:namespace` now also admits `{ value: null, source: 'environment' }`; every entry served before is served unchanged
10+
Metadata-protocol: none
11+
12+
A transport the host application hands to `@objectstack/plugin-email` that no `provider` option names (a plain `IEmailTransport`, such as a hosted platform's mail channel) used to leave `live.provider` unstated, so the first-run checklist read mail as not set up while mail was being delivered. The plugin now states it as `{ value: null, source: 'environment' }`: in use, supplied by the environment or host, named by no option.
13+
14+
- `@objectstack/spec`: `SettingsNamespacePayloadSchema.live` documents the reading. A non-null `value` is still always one of the key's options. `value` is `null` when `source` is `'none'` (nothing in use) or `'environment'` (in use, named by no option). Read whether something is in use from `source`, never from `value === null`. `'settings'` always names an option. The schema's shape is unchanged.
15+
- `@objectstack/service-settings`: the live-value judge serves `environment` with a `null` value. `settings` with a `null` value is still dropped, and so is any entry on a key with no option table.
16+
- `@objectstack/plugin-email`: the stock transports (`smtp`, `resend`, `postmark`) read as before. A transport swapped in through `EmailService.setTransport` is still not stated.
17+
18+
A reader that took `value === null` to mean "nothing is in use" should read `source` instead: `source: 'none'` is the only "nothing is in use".

‎content/docs/references/system/settings-manifest.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ const result = ResolvedSettingValueSchema.parse(data);
177177

178178
| Property | Type | Required | Description |
179179
| :--- | :--- | :--- | :--- |
180-
| **value** | `string \| null` | ✅ | The option in use; null exactly when source is 'none' |
181-
| **source** | `Enum<'settings' \| 'environment' \| 'none'>` | ✅ | Where the running system took it from: these settings, its own boot environment, or nothing in use |
180+
| **value** | `string \| null` | ✅ | The option in use; null when source is 'none', or when source is 'environment' and no option names what is in use. Read in-use from source, never from a null value |
181+
| **source** | `Enum<'settings' \| 'environment' \| 'none'>` | ✅ | Where the running system took it from: these settings, its own boot environment or host, or nothing in use |
182182

183183

184184
---

‎packages/plugins/plugin-email/src/live-transport-status.pin.test.ts‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ describe('describeLiveMailTransport — the reading of isConfigured()', () => {
101101
expect(s.label).toBe('Mail is delivered through SMTP (smtp.example.test:2525)');
102102
});
103103

104+
it("a transport no option names is stated only as 'environment': 'settings' always names an option", () => {
105+
const own: IEmailTransport = { send: async () => ({ messageId: 'host-own-0' }) } as never;
106+
const svc = { isConfigured: () => true, options: { transport: own } };
107+
expect(describeLiveMailTransport(svc, 'en', 'environment').values)
108+
.toEqual({ provider: { value: null, source: 'environment' } });
109+
expect(describeLiveMailTransport(svc, 'en', 'settings').values).toBeUndefined();
110+
expect(describeLiveMailTransport(svc, 'en').values).toBeUndefined();
111+
});
112+
104113
it('the branch is isConfigured(), not the transport class', () => {
105114
const smtp = new SmtpTransport({ host: 'smtp.example.test' });
106115
expect(describeLiveMailTransport({ isConfigured: () => false, options: { transport: smtp } }).label)
@@ -342,16 +351,27 @@ describe('GET /api/settings/mail — live.provider states the provider in use',
342351
expect(banner(data)).toEqual({ label: 'No mail leaves this machine', bannerSeverity: 'warning' });
343352
});
344353

345-
it("states nothing for a transport no option names, or one this plugin did not install: unknown is not 'none'", async () => {
354+
it("environment: the host's own transport, which no option names, reads { value: null, source: 'environment' }", async () => {
355+
// A hosted platform's mail channel reaches the plugin this way: a plain
356+
// IEmailTransport handed over as the constructor default, no stock class.
346357
const own: IEmailTransport = { send: async () => ({ messageId: 'host-own-1' }) } as never;
347358
const hosted = await serve({}, { transport: own });
348359
const data = await hosted.read();
349-
expect('live' in data).toBe(false);
350-
// The banner still names the host's transport.
351-
expect(banner(data).bannerSeverity).toBe('info');
360+
expect(data.live).toEqual({ provider: { value: null, source: 'environment' } });
361+
// In use, so it is not 'none'; the banner still names the host's transport.
362+
expect(banner(data)).toEqual({
363+
label: 'Mail is delivered through a transport supplied by the host application', bannerSeverity: 'info',
364+
});
365+
});
352366

367+
it("states nothing for a transport this plugin did not install: unknown is not 'none'", async () => {
353368
const swapped = await serve({}, { provider: 'smtp', providerOptions: { host: 'smtp.boot.test' } });
354369
swapped.service.setTransport(new SmtpTransport({ host: 'smtp.elsewhere.test' }));
355370
expect('live' in (await swapped.read())).toBe(false);
371+
372+
const own: IEmailTransport = { send: async () => ({ messageId: 'host-own-2' }) } as never;
373+
const hostedSwapped = await serve({}, { transport: own });
374+
hostedSwapped.service.setTransport({ send: async () => ({ messageId: 'other-1' }) } as never);
375+
expect('live' in (await hostedSwapped.read())).toBe(false);
356376
});
357377
});

‎packages/plugins/plugin-email/src/live-transport-status.ts‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ export interface LiveMailTransportStatus {
2626
* The provider in use, machine-readable, for a reader that needs the answer
2727
* and not the banner's prose (the console's first-run checklist). The
2828
* settings `GET` route serves it as the page's `live.provider`, the shape the
29-
* `ai` namespace's runtime states its provider in. Absent = not stated: the
30-
* live transport is one the `provider` options cannot name (a host's own
31-
* transport class), or the plugin cannot say where it came from.
29+
* `ai` namespace's runtime states its provider in. A transport the host
30+
* handed over that no `provider` option names (a host's own transport class,
31+
* such as a hosted platform's mail channel) is stated as
32+
* `{ value: null, source: 'environment' }`: in use, supplied by the host,
33+
* named by no option. Absent = not stated: the plugin cannot say where the
34+
* live transport came from.
3235
*/
3336
values?: { provider: LiveMailProviderValue };
3437
}
@@ -45,8 +48,9 @@ export type LiveMailTransportOrigin = 'settings' | 'environment';
4548

4649
/**
4750
* The `provider` key's value in the running system: one of its options, or
48-
* `null` when nothing delivers. Typed from the spec's served `live` entry, so a
49-
* change to that shape fails this package's type-check.
51+
* `null` when nothing delivers (`none`) or when the host's own transport, which
52+
* no option names, delivers (`environment`). Typed from the spec's served
53+
* `live` entry, so a change to that shape fails this package's type-check.
5054
*/
5155
export type LiveMailProviderValue = NonNullable<SettingsNamespacePayload['live']>[string];
5256

@@ -335,8 +339,11 @@ function transportName(transport: IEmailTransport, copy: MailDeliveryCopy): stri
335339
*
336340
* `values.provider` states the provider in use: `{ value: null, source: 'none' }`
337341
* when nothing delivers, else the option naming the transport with the `origin`
338-
* the caller holds for it. With no `origin`, or a transport no option names, the
339-
* provider is not stated, which a reader tells from `none`.
342+
* the caller holds for it. A transport no option names that came from the
343+
* environment (the host handed it over) is `{ value: null, source: 'environment' }`:
344+
* it delivers, and the spec's `live` entry reads in-use from `source`. With no
345+
* `origin`, or a `settings` origin no option names, the provider is not stated,
346+
* which a reader tells from `none`.
340347
*/
341348
export function describeLiveMailTransport(
342349
source: LiveMailTransportSource,
@@ -356,5 +363,6 @@ export function describeLiveMailTransport(
356363
};
357364
const option = providerOptionOf(source.options.transport);
358365
if (option && origin) status.values = { provider: { value: option, source: origin } };
366+
else if (!option && origin === 'environment') status.values = { provider: { value: null, source: 'environment' } };
359367
return status;
360368
}

‎packages/services/service-settings/src/settings-routes.live-status.pin.test.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,20 @@ describe('GET /api/settings/:namespace — the live values the runtime states',
163163
expect(SettingsNamespacePayloadSchema.safeParse(body.data).success).toBe(true);
164164
});
165165

166+
it('serves "environment" with no value: in use, supplied by the host, named by no option', async () => {
167+
const { svc, read, logger } = rig();
168+
svc.registerLiveStatus('mail', () => ({
169+
label: 'Mail is delivered through a transport supplied by the host application',
170+
bannerText: 'In use.', bannerSeverity: 'info',
171+
values: { provider: { value: null, source: 'environment' } },
172+
}));
173+
const { status, body } = await read();
174+
expect(status).toBe(200);
175+
expect(body.data.live).toEqual({ provider: { value: null, source: 'environment' } });
176+
expect(logger.warn).not.toHaveBeenCalled();
177+
expect(SettingsNamespacePayloadSchema.safeParse(body.data).success).toBe(true);
178+
});
179+
166180
it('⛔ serves only the value and its source: a credential the runtime attaches never leaves', async () => {
167181
const { svc, read } = rig(aiSettingsManifest);
168182
svc.registerLiveStatus('ai', () => ({
@@ -204,7 +218,8 @@ describe('GET /api/settings/:namespace — the live values the runtime states',
204218
['a key the namespace does not declare', { api_key: { value: 'openai', source: 'environment' } }],
205219
['a source outside the closed set', { provider: { value: 'openai', source: 'env' } }],
206220
['a value under source "none"', { provider: { value: 'openai', source: 'none' } }],
207-
['no value under a source other than "none"', { provider: { value: null, source: 'settings' } }],
221+
['no value under source "settings"', { provider: { value: null, source: 'settings' } }],
222+
['a key with no option table, even as "environment" with no value', { openai_model: { value: null, source: 'environment' } }],
208223
['an entry that is not { value, source }', { provider: 'openai' }],
209224
])('leaves out an entry naming %s, keeping the stated banner', async (_what, values) => {
210225
const { svc, read, logger } = rig(aiSettingsManifest);

‎packages/services/service-settings/src/settings-service.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2276,7 +2276,9 @@ export class SettingsService {
22762276
* is not servable is left out and named in `dropped`, by its key and why,
22772277
* never by its value: the key is not an option-bearing key of the
22782278
* namespace, the value is not one its option table admits, or `value` and
2279-
* `source` disagree about "none". The value is kept out of `dropped`
2279+
* `source` disagree about "none" (only `'environment'` may also carry a null
2280+
* value: in use, supplied by the host, named by no option; `'settings'`
2281+
* always names one). The value is kept out of `dropped`
22802282
* because an entry this wrong may be carrying the very credential the rule
22812283
* keeps off the page.
22822284
*/
@@ -2319,6 +2321,10 @@ export class SettingsService {
23192321
if (source === 'none') {
23202322
return value === null ? { served: { value: null, source } } : { why: "states a value under source 'none'" };
23212323
}
2324+
// In use, supplied by the runtime's environment or host, and named by no
2325+
// option (a host's own mail transport). Only 'environment' may say this:
2326+
// what 'settings' resolves is always one of the options.
2327+
if (source === 'environment' && value === null) return { served: { value: null, source } };
23222328
if (typeof value !== 'string' || table.judge(value) !== null) {
23232329
return { why: 'states a value that is not one of its options' };
23242330
}

‎packages/services/service-settings/src/settings-service.types.ts‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,9 @@ export interface SettingsLiveStatus {
503503
*
504504
* Only an option-bearing key may be named, and only with a value its option
505505
* table admits (the declared `options`, or a registered option source's
506-
* answer), so what is served is always one of the page's own options and
507-
* never free text a runtime might fill with a credential. Each entry is
506+
* answer), so what is served is always one of the page's own options (or
507+
* `null`, under `'none'` or `'environment'` alone) and never free text a
508+
* runtime might fill with a credential. Each entry is
508509
* served as `{ value, source }` and nothing else. An entry that breaks this
509510
* is left out, so its key reads as not stated, and the server logs it once
510511
* per read without the value; the banner and the other entries stand.
@@ -517,13 +518,18 @@ export interface SettingsLiveStatus {
517518

518519
/** One key's value in the running system — see {@link SettingsLiveStatus.values}. */
519520
export interface SettingsLiveValue {
520-
/** The value in use, one of the key's options; `null` exactly when `source` is `'none'`. */
521+
/**
522+
* The value in use, one of the key's options; `null` when `source` is
523+
* `'none'`, or when `source` is `'environment'` and no option names what is
524+
* in use (a transport the host hands over). Whether something is in use is
525+
* read from `source`, never from a `null` value.
526+
*/
521527
value: string | null;
522528
/**
523529
* Where the running system took it from: `'settings'` (what this namespace
524-
* resolves, saved or `OS_*`-locked), `'environment'` (detected by the
525-
* runtime itself from its own boot environment, outside this namespace), or
526-
* `'none'` (nothing is in use).
530+
* resolves, saved or `OS_*`-locked; always names an option), `'environment'`
531+
* (detected by the runtime itself from its own boot environment, or handed
532+
* over by its host, outside this namespace), or `'none'` (nothing is in use).
527533
*/
528534
source: 'settings' | 'environment' | 'none';
529535
}

‎packages/spec/src/system/settings-manifest.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,9 @@ describe('SettingsNamespacePayloadSchema', () => {
795795
expect(parsed.live?.provider).toEqual({ value: 'openai', source: 'environment' });
796796
expect(SettingsNamespacePayloadSchema.parse({ ...aiPage, live: { provider: { value: null, source: 'none' } } }).live)
797797
.toEqual({ provider: { value: null, source: 'none' } });
798+
// In use, supplied by the environment or host, named by no option (a host's own mail transport).
799+
expect(SettingsNamespacePayloadSchema.parse({ ...aiPage, live: { provider: { value: null, source: 'environment' } } }).live)
800+
.toEqual({ provider: { value: null, source: 'environment' } });
798801
expect(SettingsNamespacePayloadSchema.parse(aiPage).live).toBeUndefined();
799802
});
800803

‎packages/spec/src/system/settings-manifest.zod.ts‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -969,17 +969,26 @@ export const SettingsNamespacePayloadSchema = lazySchema(() => z.object({
969969
* this says what is in use, which may come from elsewhere: the AI runtime
970970
* detects a provider from its own boot environment when nothing is saved.
971971
* Absent, or a key absent from it, means not stated (unknown), which is not
972-
* `source: 'none'`. Only `value` and `source` are served, and `value` is
973-
* always one of the key's options, never a credential.
972+
* `source: 'none'`. Only `value` and `source` are served, and a non-null
973+
* `value` is always one of the key's options, never a credential.
974+
* `value` is null in two cases: nothing is in use (`source: 'none'`), or
975+
* something is in use that the runtime's boot environment or host supplied
976+
* and no option names (`source: 'environment'`, e.g. a mail transport the
977+
* host application hands over). So whether something is in use is read from
978+
* `source` alone, never from `value === null`; `source: 'settings'` always
979+
* names an option.
974980
*/
975981
live: z
976982
.record(
977983
z.string(),
978984
z.object({
979-
value: z.string().nullable().describe("The option in use; null exactly when source is 'none'"),
985+
value: z
986+
.string()
987+
.nullable()
988+
.describe("The option in use; null when source is 'none', or when source is 'environment' and no option names what is in use. Read in-use from source, never from a null value"),
980989
source: z
981990
.enum(['settings', 'environment', 'none'])
982-
.describe("Where the running system took it from: these settings, its own boot environment, or nothing in use"),
991+
.describe("Where the running system took it from: these settings, its own boot environment or host, or nothing in use"),
983992
}),
984993
)
985994
.optional()

0 commit comments

Comments
 (0)