Skip to content

Commit 6e9d5d6

Browse files
fix(console): a host's own mail transport ticks the setup checklist's mail row (#34867)
Fixes #34749 Clause-②: no Metadata-protocol: none ## 维护者速读 - **改了什么:** 控制台首次设置清单按 `source` 判断「在用」:`live.provider` 为 `{ value: null, source: 'environment' }`(宿主自带、选项表叫不出名字的投递方式)时,邮件行算完成;内置 AI 行同一规则,保留 `environment` 来源。`types.ts` 注释改成 spec 现行说法。 - **为什么改:** #34731 已让托管平台把自带邮件通道报成 `environment` + null,但控制台还要求 value 非空,托管环境的邮件行一直不打勾(#32799 裁决 C 的 ui 半边)。 - **风险与回滚:** 低。只多认一种组合(environment + null);`none`、`settings` + 空串、没有 `live` 时回落到已保存值,这些读数都不变。回滚即 revert 本 PR。 - **先看:** `ui/apps/console/src/pages/settings/firstRunChecklistLogic.ts`(新 `liveValueInUse` 与 `aiProviderState` 的 null 分支)、`FirstRunChecklist.tsx`(AI 行无名字时的文案)、`__tests__/firstRunChecklistLogic.test.ts` 末尾新增的 describe。 - **两分钟验证:** `pnpm --dir ui exec vitest run apps/console/src/pages/settings/__tests__/firstRunChecklistLogic.test.ts`,预期全绿,其中「in use is read from the stated source, never from a null value」下 6 条通过。 - **需要你做的:** 无,席位落地。 ## What changes - **`isMailDelivering`** now reads in-use from the stated `source`, as the settings contract that #34731 landed says (`SettingsLiveValue` in service-settings and the spec's `live` describe: "Read in-use from source, never from a null value"). One private helper, `liveValueInUse`, holds the rule for both rows. The only new cell is `environment` + `null`, which is in use. The other cells read as before: `none` is not in use, `settings`/`environment` with a non-empty string is in use, and `settings`/`environment` with an empty string is not in use. An entry that is no statement falls back to the saved values (`isMailConfigured`), as before. - **N1 (addendum 6944462303).** A host-own transport whose saved values pass `isMailConfigured` now reads done from the statement. Before this change it read not done after #34731. - **N2: `aiProviderState`** takes the same rule. `environment` + `null` is now `{ done: true, value: null, source: 'environment' }`, with the stated source kept. Before this change it was rewritten to `{ done: false, source: 'none' }`. The `optionLabel` is absent, because no option names the provider. - **What the AI row shows for `environment` + `null`.** `FirstRunChecklist.tsx` has no provider name to put into `doneEnvironment` ("{{provider}}, detected from the server environment."), which would render as a sentence starting with a comma. The row uses the existing, fully translated `console.settingsView.aiProviderManaged` ("The AI provider, its model and credentials are managed by the platform.") instead. The Settings page already shows that sentence for a platform-managed AI provider. No new i18n key was added, so the file surface stays `ui/apps/console/src/pages/settings/**`. No runtime emits this AI entry today (addendum N2). - **`types.ts`.** The `SettingsLiveValue` comment now carries the spec rule: `null` when `source` is `none`, or when `source` is `environment` and no option names what is in use. In-use is read from `source`. - Changeset `.changeset/34749-mail-delivering-environment.md`: `@object-ui/console` patch. ## Tests The pins requested by the dispatch are in `__tests__/firstRunChecklistLogic.test.ts`, in a new top-level describe, "in use is read from the stated source, never from a null value (objectstack#34749)": - mail: `environment` + `null` is done; `none` is not done; `settings` + `''` is not done. - mail N1: saved values that pass `isMailConfigured`, under `environment` + `null`, read done. - CONTROL mail: a payload without the statement still falls back to the saved values. - ai: `environment` + `null` is done with the source kept as `environment`; `none` is not done. - CONTROL ai: a provider named by an option keeps its value, source and label. The render pins go into the existing harness, `__tests__/FirstRunChecklist.test.tsx`. That file gains a `mailLive` statement for the mail page. - "managed, the host's own transport (live provider environment, null) with nothing saved: mail is drawn, done". This is the card's Done-when, shown on the rendered checklist. - "handed over by the host and named by no option (environment, null): done, and says the platform manages it". <details><summary>Targeted run at 772eafd: 2 files, 77/77</summary> ``` pnpm --dir ui exec vitest run --maxWorkers=2 apps/console/src/pages/settings/__tests__/firstRunChecklistLogic.test.ts apps/console/src/pages/settings/__tests__/FirstRunChecklist.test.tsx Test Files 2 passed (2) Tests 77 passed (77) os-verify-lock: VERDICT command-exit 0 ``` </details> <details><summary>Whole settings directory at 772eafd: 43 files, 432/432</summary> ``` pnpm --dir ui exec vitest run --maxWorkers=2 apps/console/src/pages/settings/ Test Files 43 passed (43) Tests 432 passed (432) os-verify-lock: VERDICT command-exit 0 ``` </details> <details><summary>Ablations: one per source-rule change, each red, each restored to HEAD by byte comparison</summary> Each ablation was run with `scripts/ablation-replace.mjs` on the committed head. The console tests resolve `src/` directly, so no `dist/` step is involved. 1. Deleted `if (source === 'environment' && value === null) return true;` from `liveValueInUse`. Anchor x1 to x0, blob b179599 to 361413faa503. **5 failed / 72 passed:** both mail cells, N1, the ai cell, and both render pins. Restored: blob == HEAD, `git diff HEAD` empty. 2. Put the old N2 mapping back in `aiProviderState`: the `value === null` branch returns `{ done: false, value: null, source: 'none' }`. Anchor x1 to x0, blob b179599 to 3ecd03f4e973. **2 failed / 75 passed:** the ai cell and the AI render pin. Restored: blob == HEAD. 3. Put the renderer back to `doneEnvironment` with an empty provider. Anchor x1 to x0, blob 0d56897 to 128c62adf365. **1 failed / 76 passed:** the AI render pin. Restored: blob == HEAD. </details> ## Acceptance notes - **Producer side.** Nothing was changed upstream. The server (`judgeLiveValue` in service-settings) already serves `environment` + `null`, and plugin-email emits it (both from #34731). The console was the only reader that still required a value. - **Merge state.** `origin/main` moved 10 commits since the base e9f65a3, and none of them touches `ui/apps/console/src/pages/settings/**`. `scripts/pm/overlap-check.mjs` reports a clean merge against `origin/main` 7752cac. No merge of main was made. - **Not run locally, left to CI.** The full Console suite and the repo-wide lint. ESLint was run on the five touched ui files and exited 0. ## Verification <details><summary>Local gate subset: dispatch-gates --commands, 37 families, all exit 0; --ran reconciliation clean</summary> The 37 families were derived by `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` from commit 772eafd. Each family ran and exited 0, including `pnpm --dir ui exec vitest run scripts/` (171 files passed, 2 skipped; 5077 tests passed). `--ran` with exit codes reported: "37 derived famil(ies) accounted for — 37 run, 0 NOT-MEASURED (a DERIVED zero …)". Other local checks: - `pnpm --filter @object-ui/console run type-check` exited 0. Both touched test files are in that program (`--listFilesOnly` counts 2). - `ui/scripts/check-new-cross-file-line-citations.mjs` reported 0 new citations. The type-check lanes and the wide-population families are CI's. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_012MmDsS4GoHCgYwA2uv3n3C)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 842b468 commit 6e9d5d6

6 files changed

Lines changed: 147 additions & 24 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@object-ui/console': patch
3+
---
4+
5+
fix(console): the setup checklist reads a host's own mail transport as delivering
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
`GET /api/settings/mail` states a transport that the host hands over, which no provider option names, as `live.provider = { value: null, source: 'environment' }`. The settings contract says in-use is read from `source`, never from a `null` value. The first-run checklist still required a non-empty `value`, so on a hosted environment its Email delivery row stayed not done while mail was being delivered. This included a deployment whose saved mail values would pass on their own.
11+
12+
The checklist now reads in-use from `source`. `environment` with a `null` value is in use, `none` is not, and a page without the statement still falls back to the saved mail values. The built-in AI row follows the same rule. If the server ever states its provider as `environment` with a `null` value, the row is done, keeps the `environment` source and says the platform manages the provider, because there is no option name to show.

‎ui/apps/console/src/pages/settings/FirstRunChecklist.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,11 @@ export function FirstRunChecklist({ placement = 'top' }: { placement?: FirstRunC
762762
!ai.done
763763
? t('console.firstRunChecklist.aiProvider.todo')
764764
: ai.source === 'environment'
765-
? t('console.firstRunChecklist.aiProvider.doneEnvironment', { provider })
765+
? provider
766+
? t('console.firstRunChecklist.aiProvider.doneEnvironment', { provider })
767+
: // In use, handed over by the host, and named by no option:
768+
// there is no provider name to put in the sentence.
769+
t('console.settingsView.aiProviderManaged')
766770
: t('console.firstRunChecklist.aiProvider.doneSettings', { provider })
767771
}
768772
action={

‎ui/apps/console/src/pages/settings/__tests__/FirstRunChecklist.test.tsx‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ function freshLocalization(): Record<string, ReturnType<typeof resolved>> {
149149

150150
let localizationValues = freshLocalization();
151151
let mailValues: Record<string, ReturnType<typeof resolved>> = { provider: resolved('smtp') };
152+
// The mail page's `live` statement, when the test serves one.
153+
let mailLive: Record<string, unknown> | null = null;
152154
let putRefusal: unknown = null;
153155
// Manifests listed beside localization and mail (the `ai` one, for the built-in AI row), and the `ai` page.
154156
let extraManifests: unknown[] = [];
@@ -169,7 +171,9 @@ function routeFetch() {
169171
if (url === '/api/settings/localization' && method === 'GET') {
170172
return ok({ manifest: LOCALIZATION_MANIFEST, values: localizationValues });
171173
}
172-
if (url === '/api/settings/mail' && method === 'GET') return ok({ manifest: MAIL_MANIFEST, values: mailValues });
174+
if (url === '/api/settings/mail' && method === 'GET') {
175+
return ok({ manifest: MAIL_MANIFEST, values: mailValues, ...(mailLive ? { live: mailLive } : {}) });
176+
}
173177
if (url === '/api/settings/localization' && method === 'PUT') {
174178
if (putRefusal) {
175179
return { ok: false, status: 400, statusText: 'Bad Request', json: async () => putRefusal } as unknown as Response;
@@ -246,6 +250,7 @@ beforeEach(() => {
246250
localStorage.clear();
247251
localizationValues = freshLocalization();
248252
mailValues = { provider: resolved('smtp') };
253+
mailLive = null;
249254
putRefusal = null;
250255
extraManifests = [];
251256
aiPayload = null;
@@ -686,6 +691,16 @@ describe('the built-in AI: the provider the server runs, from live.provider (obj
686691
expect(within(r).getByText('DeepSeek (OpenAI-compatible), detected from the server environment.')).toBeTruthy();
687692
});
688693

694+
it('handed over by the host and named by no option (environment, null): done, and says the platform manages it (objectstack#34749)', async () => {
695+
serveAi({ value: null, source: 'environment' }, null);
696+
renderChecklist(ADMIN);
697+
await showDone();
698+
const r = await screen.findByTestId('first-run-checklist-row-ai_provider');
699+
expect(r.getAttribute('data-done')).toBe('true');
700+
expect(within(r).getByText('The AI provider, its model and credentials are managed by the platform.')).toBeTruthy();
701+
expect(within(r).queryByText(/detected from the server environment/)).toBeNull();
702+
});
703+
689704
it('a saved provider the running system does not use is not done: live decides, not values', async () => {
690705
serveAi({ value: null, source: 'none' }, 'openai');
691706
renderChecklist(ADMIN);
@@ -1018,6 +1033,17 @@ describe('the host profile: a managed environment adds the first-app and first-r
10181033
expect(row('mail').getAttribute('data-done')).toBe('true');
10191034
});
10201035

1036+
it("managed, the host's own transport (live provider environment, null) with nothing saved: mail is drawn, done (objectstack#34749)", async () => {
1037+
MANAGED();
1038+
mailLive = { provider: { value: null, source: 'environment' } };
1039+
SHELL.apps = [SETUP_APP];
1040+
activityAdapter([]);
1041+
renderChecklist(ADMIN);
1042+
await screen.findByTestId('first-run-checklist-row-first_record');
1043+
await showDone();
1044+
expect(row('mail').getAttribute('data-done')).toBe('true');
1045+
});
1046+
10211047
it('managed, every required row done and no record yet: the checklist draws nothing', async () => {
10221048
MANAGED();
10231049
localizationValues = {

‎ui/apps/console/src/pages/settings/__tests__/firstRunChecklistLogic.test.ts‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import { describe, it, expect } from 'vitest';
1111
import {
1212
DEFAULT_ORGANIZATION_NAME,
13+
aiProviderState,
1314
browserRegion,
1415
checklistCompletion,
1516
dismissRecordKey,
@@ -243,3 +244,60 @@ describe('completion counts the required rows; email delivery is optional (objec
243244
expect(checklistCompletion([{ id: 'connect_assistant', done: false }]).complete).toBe(false);
244245
});
245246
});
247+
248+
describe('in use is read from the stated source, never from a null value (objectstack#34749)', () => {
249+
// A host's own transport, which no option names, is stated `{ value: null, source: 'environment' }`.
250+
const HOST_OWN = { value: null, source: 'environment' } as const;
251+
const SAVED = { provider: fromTenant('smtp'), from_email: fromTenant('a@b.co'), smtp_host: fromTenant('mx') };
252+
253+
it('mail: environment with a null value delivers; none does not; settings with an empty value does not', () => {
254+
expect(isMailDelivering({ values: {}, live: { provider: HOST_OWN } })).toBe(true);
255+
expect(isMailDelivering({ values: {}, live: { provider: { value: null, source: 'none' } } })).toBe(false);
256+
expect(isMailDelivering({ values: SAVED, live: { provider: { value: '', source: 'settings' } } })).toBe(false);
257+
});
258+
259+
it('mail: saved values that would pass, under a host-own transport, read done from the statement', () => {
260+
expect(isMailConfigured(SAVED)).toBe(true);
261+
expect(isMailDelivering({ values: SAVED, live: { provider: HOST_OWN } })).toBe(true);
262+
// The statement decides, not the saved values: the same host-own statement over nothing that would pass.
263+
expect(isMailDelivering({ values: { provider: fromTenant('log') }, live: { provider: HOST_OWN } })).toBe(true);
264+
});
265+
266+
it('CONTROL mail: a payload without the statement still falls back to the saved values', () => {
267+
expect(isMailDelivering({ values: SAVED })).toBe(true);
268+
expect(isMailDelivering({ values: {} })).toBe(false);
269+
});
270+
271+
const AI_MANIFEST = {
272+
namespace: 'ai',
273+
label: 'AI',
274+
scope: 'global',
275+
writePermission: 'manage_platform_settings',
276+
specifiers: [{ type: 'select', key: 'provider', label: 'Provider', options: [{ value: 'openai', label: 'OpenAI' }] }],
277+
} as unknown as SettingsManifest;
278+
279+
it('ai: environment with a null value is done, its source kept, with no option to name it by', () => {
280+
expect(aiProviderState({ manifest: AI_MANIFEST, live: { provider: HOST_OWN } })).toEqual({
281+
done: true,
282+
value: null,
283+
source: 'environment',
284+
});
285+
});
286+
287+
it('ai: none is not done', () => {
288+
expect(aiProviderState({ manifest: AI_MANIFEST, live: { provider: { value: null, source: 'none' } } })).toEqual({
289+
done: false,
290+
value: null,
291+
source: 'none',
292+
});
293+
});
294+
295+
it('CONTROL ai: a provider named by an option keeps its value, source and label', () => {
296+
expect(aiProviderState({ manifest: AI_MANIFEST, live: { provider: { value: 'openai', source: 'environment' } } })).toEqual({
297+
done: true,
298+
value: 'openai',
299+
source: 'environment',
300+
optionLabel: 'OpenAI',
301+
});
302+
});
303+
});

‎ui/apps/console/src/pages/settings/firstRunChecklistLogic.ts‎

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -498,27 +498,40 @@ export function isMailConfigured(values: Record<string, ResolvedSettingValue>):
498498
return true;
499499
}
500500

501+
/**
502+
* Is the stated live value one in use? Read from `source`, never from a `null`
503+
* value ({@link SettingsLiveValue}): `'none'` is nothing in use; `'settings'`
504+
* is in use and always names an option; `'environment'` is in use, naming an
505+
* option or, with `value: null`, a provider the host hands over that no option
506+
* names (a hosting platform's own mail transport). `undefined` when the entry
507+
* is no statement the server serves, so the caller decides as if unstated.
508+
*/
509+
function liveValueInUse(stated: SettingsLiveValue | undefined): boolean | undefined {
510+
if (!stated || typeof stated !== 'object') return undefined;
511+
const { value, source } = stated;
512+
if (source === 'none') return false;
513+
if (source === 'environment' && value === null) return true;
514+
if (source === 'settings' || source === 'environment') return typeof value === 'string' && value !== '';
515+
return undefined;
516+
}
517+
501518
/**
502519
* The mail row from the `mail` namespace's payload: done when the running
503520
* system delivers mail.
504521
*
505522
* The server's statement (`live.provider` of `GET /api/settings/mail`) decides
506-
* first: a provider in use, taken from the settings or from the deployment's
507-
* own boot environment, is done; `source: 'none'` (the development log, which
508-
* delivers nothing) is not done, whatever was saved. Mail set up through the
509-
* environment saves nothing, so the saved values alone would keep that row not
510-
* done for good. A payload without the statement (a server older than it, or
511-
* one that cannot state the provider) falls back to the saved values
512-
* ({@link isMailConfigured}), never to "not set".
523+
* first, read from its `source` ({@link liveValueInUse}): a provider in use,
524+
* taken from the settings or from the deployment's own boot environment or
525+
* host (a host's own transport is stated with a `null` value), is done;
526+
* `source: 'none'` (the development log, which delivers nothing) is not done,
527+
* whatever was saved. Mail set up through the environment saves nothing, so
528+
* the saved values alone would keep that row not done for good. A payload
529+
* without the statement (a server older than it, or one that cannot state the
530+
* provider) falls back to the saved values ({@link isMailConfigured}), never
531+
* to "not set".
513532
*/
514533
export function isMailDelivering(payload: Pick<SettingsNamespacePayload, 'values' | 'live'>): boolean {
515-
const stated = payload.live?.[MAIL_PROVIDER_KEY];
516-
if (stated && typeof stated === 'object') {
517-
const { value, source } = stated;
518-
if (source === 'none') return false;
519-
if (source === 'settings' || source === 'environment') return typeof value === 'string' && value !== '';
520-
}
521-
return isMailConfigured(payload.values);
534+
return liveValueInUse(payload.live?.[MAIL_PROVIDER_KEY]) ?? isMailConfigured(payload.values);
522535
}
523536

524537
/** Has the organization been given a name of its own? */
@@ -545,9 +558,12 @@ export function hasInvitedColleagues(
545558
* names it.
546559
*/
547560
export interface AiProviderState {
548-
/** A provider is in use: the stated value is one, from the settings or the boot environment. */
561+
/** A provider is in use, read from the stated `source`: from the settings, or from the boot environment or host. */
549562
done: boolean;
550-
/** The stated value, or `null` when none is in use. */
563+
/**
564+
* The stated value: `null` when none is in use, or when the provider in use
565+
* comes from the environment and no option names it.
566+
*/
551567
value: string | null;
552568
/** Where the running system took it from. */
553569
source: SettingsLiveValue['source'];
@@ -568,10 +584,13 @@ export interface AiProviderState {
568584
export function aiProviderState(payload: Pick<SettingsNamespacePayload, 'manifest' | 'live'>): AiProviderState | undefined {
569585
const stated = payload.live?.[AI_PROVIDER_KEY];
570586
if (!stated || typeof stated !== 'object') return undefined;
571-
const { value, source } = stated;
572-
if (source !== 'settings' && source !== 'environment' && source !== 'none') return undefined;
573-
const inUse = source !== 'none' && typeof value === 'string' && value !== '';
587+
const inUse = liveValueInUse(stated);
588+
if (inUse === undefined) return undefined;
574589
if (!inUse) return { done: false, value: null, source: 'none' };
590+
const { value, source } = stated;
591+
// In use from the environment, named by no option: done, the stated source
592+
// kept, and no option to name it by.
593+
if (value === null) return { done: true, value: null, source };
575594
const spec = payload.manifest.specifiers.find((s) => s.key === AI_PROVIDER_KEY);
576595
const option = (spec?.options ?? []).find((o) => String(o.value) === value);
577596
const label = option ? resolveLabel(option.label) : undefined;

‎ui/apps/console/src/pages/settings/types.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,13 @@ export interface ResolvedSettingValue<T = unknown> {
176176

177177
/**
178178
* One key's value in the RUNNING system, as the namespace's owner states it
179-
* (service-settings `SettingsLiveValue`). `value` is one of the key's options,
180-
* `null` exactly when `source` is `'none'`; `'environment'` means the runtime
181-
* detected it from its own boot environment, outside the namespace.
179+
* (service-settings `SettingsLiveValue`). `value` is one of the key's options;
180+
* `null` when `source` is `'none'`, or when `source` is `'environment'` and no
181+
* option names what is in use (a transport the host hands over). Whether
182+
* something is in use is read from `source`, never from a `null` value.
183+
* `'settings'` always names an option; `'environment'` means the runtime
184+
* detected it from its own boot environment, or its host handed it over,
185+
* outside the namespace.
182186
*/
183187
export interface SettingsLiveValue {
184188
value: string | null;

0 commit comments

Comments
 (0)