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/34749-mail-delivering-environment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@object-ui/console': patch
---

fix(console): the setup checklist reads a host's own mail transport as delivering

Clause-②: no
Metadata-protocol: none

`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.

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.
6 changes: 5 additions & 1 deletion ui/apps/console/src/pages/settings/FirstRunChecklist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,11 @@ export function FirstRunChecklist({ placement = 'top' }: { placement?: FirstRunC
!ai.done
? t('console.firstRunChecklist.aiProvider.todo')
: ai.source === 'environment'
? t('console.firstRunChecklist.aiProvider.doneEnvironment', { provider })
? provider
? t('console.firstRunChecklist.aiProvider.doneEnvironment', { provider })
: // In use, handed over by the host, and named by no option:
// there is no provider name to put in the sentence.
t('console.settingsView.aiProviderManaged')
: t('console.firstRunChecklist.aiProvider.doneSettings', { provider })
}
action={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ function freshLocalization(): Record<string, ReturnType<typeof resolved>> {

let localizationValues = freshLocalization();
let mailValues: Record<string, ReturnType<typeof resolved>> = { provider: resolved('smtp') };
// The mail page's `live` statement, when the test serves one.
let mailLive: Record<string, unknown> | null = null;
let putRefusal: unknown = null;
// Manifests listed beside localization and mail (the `ai` one, for the built-in AI row), and the `ai` page.
let extraManifests: unknown[] = [];
Expand All @@ -169,7 +171,9 @@ function routeFetch() {
if (url === '/api/settings/localization' && method === 'GET') {
return ok({ manifest: LOCALIZATION_MANIFEST, values: localizationValues });
}
if (url === '/api/settings/mail' && method === 'GET') return ok({ manifest: MAIL_MANIFEST, values: mailValues });
if (url === '/api/settings/mail' && method === 'GET') {
return ok({ manifest: MAIL_MANIFEST, values: mailValues, ...(mailLive ? { live: mailLive } : {}) });
}
if (url === '/api/settings/localization' && method === 'PUT') {
if (putRefusal) {
return { ok: false, status: 400, statusText: 'Bad Request', json: async () => putRefusal } as unknown as Response;
Expand Down Expand Up @@ -246,6 +250,7 @@ beforeEach(() => {
localStorage.clear();
localizationValues = freshLocalization();
mailValues = { provider: resolved('smtp') };
mailLive = null;
putRefusal = null;
extraManifests = [];
aiPayload = null;
Expand Down Expand Up @@ -686,6 +691,16 @@ describe('the built-in AI: the provider the server runs, from live.provider (obj
expect(within(r).getByText('DeepSeek (OpenAI-compatible), detected from the server environment.')).toBeTruthy();
});

it('handed over by the host and named by no option (environment, null): done, and says the platform manages it (objectstack#34749)', async () => {
serveAi({ value: null, source: 'environment' }, null);
renderChecklist(ADMIN);
await showDone();
const r = await screen.findByTestId('first-run-checklist-row-ai_provider');
expect(r.getAttribute('data-done')).toBe('true');
expect(within(r).getByText('The AI provider, its model and credentials are managed by the platform.')).toBeTruthy();
expect(within(r).queryByText(/detected from the server environment/)).toBeNull();
});

it('a saved provider the running system does not use is not done: live decides, not values', async () => {
serveAi({ value: null, source: 'none' }, 'openai');
renderChecklist(ADMIN);
Expand Down Expand Up @@ -1018,6 +1033,17 @@ describe('the host profile: a managed environment adds the first-app and first-r
expect(row('mail').getAttribute('data-done')).toBe('true');
});

it("managed, the host's own transport (live provider environment, null) with nothing saved: mail is drawn, done (objectstack#34749)", async () => {
MANAGED();
mailLive = { provider: { value: null, source: 'environment' } };
SHELL.apps = [SETUP_APP];
activityAdapter([]);
renderChecklist(ADMIN);
await screen.findByTestId('first-run-checklist-row-first_record');
await showDone();
expect(row('mail').getAttribute('data-done')).toBe('true');
});

it('managed, every required row done and no record yet: the checklist draws nothing', async () => {
MANAGED();
localizationValues = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import { describe, it, expect } from 'vitest';
import {
DEFAULT_ORGANIZATION_NAME,
aiProviderState,
browserRegion,
checklistCompletion,
dismissRecordKey,
Expand Down Expand Up @@ -243,3 +244,60 @@ describe('completion counts the required rows; email delivery is optional (objec
expect(checklistCompletion([{ id: 'connect_assistant', done: false }]).complete).toBe(false);
});
});

describe('in use is read from the stated source, never from a null value (objectstack#34749)', () => {
// A host's own transport, which no option names, is stated `{ value: null, source: 'environment' }`.
const HOST_OWN = { value: null, source: 'environment' } as const;
const SAVED = { provider: fromTenant('smtp'), from_email: fromTenant('a@b.co'), smtp_host: fromTenant('mx') };

it('mail: environment with a null value delivers; none does not; settings with an empty value does not', () => {
expect(isMailDelivering({ values: {}, live: { provider: HOST_OWN } })).toBe(true);
expect(isMailDelivering({ values: {}, live: { provider: { value: null, source: 'none' } } })).toBe(false);
expect(isMailDelivering({ values: SAVED, live: { provider: { value: '', source: 'settings' } } })).toBe(false);
});

it('mail: saved values that would pass, under a host-own transport, read done from the statement', () => {
expect(isMailConfigured(SAVED)).toBe(true);
expect(isMailDelivering({ values: SAVED, live: { provider: HOST_OWN } })).toBe(true);
// The statement decides, not the saved values: the same host-own statement over nothing that would pass.
expect(isMailDelivering({ values: { provider: fromTenant('log') }, live: { provider: HOST_OWN } })).toBe(true);
});

it('CONTROL mail: a payload without the statement still falls back to the saved values', () => {
expect(isMailDelivering({ values: SAVED })).toBe(true);
expect(isMailDelivering({ values: {} })).toBe(false);
});

const AI_MANIFEST = {
namespace: 'ai',
label: 'AI',
scope: 'global',
writePermission: 'manage_platform_settings',
specifiers: [{ type: 'select', key: 'provider', label: 'Provider', options: [{ value: 'openai', label: 'OpenAI' }] }],
} as unknown as SettingsManifest;

it('ai: environment with a null value is done, its source kept, with no option to name it by', () => {
expect(aiProviderState({ manifest: AI_MANIFEST, live: { provider: HOST_OWN } })).toEqual({
done: true,
value: null,
source: 'environment',
});
});

it('ai: none is not done', () => {
expect(aiProviderState({ manifest: AI_MANIFEST, live: { provider: { value: null, source: 'none' } } })).toEqual({
done: false,
value: null,
source: 'none',
});
});

it('CONTROL ai: a provider named by an option keeps its value, source and label', () => {
expect(aiProviderState({ manifest: AI_MANIFEST, live: { provider: { value: 'openai', source: 'environment' } } })).toEqual({
done: true,
value: 'openai',
source: 'environment',
optionLabel: 'OpenAI',
});
});
});
57 changes: 38 additions & 19 deletions ui/apps/console/src/pages/settings/firstRunChecklistLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,27 +498,40 @@ export function isMailConfigured(values: Record<string, ResolvedSettingValue>):
return true;
}

/**
* Is the stated live value one in use? Read from `source`, never from a `null`
* value ({@link SettingsLiveValue}): `'none'` is nothing in use; `'settings'`
* is in use and always names an option; `'environment'` is in use, naming an
* option or, with `value: null`, a provider the host hands over that no option
* names (a hosting platform's own mail transport). `undefined` when the entry
* is no statement the server serves, so the caller decides as if unstated.
*/
function liveValueInUse(stated: SettingsLiveValue | undefined): boolean | undefined {
if (!stated || typeof stated !== 'object') return undefined;
const { value, source } = stated;
if (source === 'none') return false;
if (source === 'environment' && value === null) return true;
if (source === 'settings' || source === 'environment') return typeof value === 'string' && value !== '';
return undefined;
}

/**
* The mail row from the `mail` namespace's payload: done when the running
* system delivers mail.
*
* The server's statement (`live.provider` of `GET /api/settings/mail`) decides
* first: a provider in use, taken from the settings or from the deployment's
* own boot environment, is done; `source: 'none'` (the development log, which
* delivers nothing) is not done, whatever was saved. Mail set up through the
* environment saves nothing, so the saved values alone would keep that row not
* done for good. A payload without the statement (a server older than it, or
* one that cannot state the provider) falls back to the saved values
* ({@link isMailConfigured}), never to "not set".
* first, read from its `source` ({@link liveValueInUse}): a provider in use,
* taken from the settings or from the deployment's own boot environment or
* host (a host's own transport is stated with a `null` value), is done;
* `source: 'none'` (the development log, which delivers nothing) is not done,
* whatever was saved. Mail set up through the environment saves nothing, so
* the saved values alone would keep that row not done for good. A payload
* without the statement (a server older than it, or one that cannot state the
* provider) falls back to the saved values ({@link isMailConfigured}), never
* to "not set".
*/
export function isMailDelivering(payload: Pick<SettingsNamespacePayload, 'values' | 'live'>): boolean {
const stated = payload.live?.[MAIL_PROVIDER_KEY];
if (stated && typeof stated === 'object') {
const { value, source } = stated;
if (source === 'none') return false;
if (source === 'settings' || source === 'environment') return typeof value === 'string' && value !== '';
}
return isMailConfigured(payload.values);
return liveValueInUse(payload.live?.[MAIL_PROVIDER_KEY]) ?? isMailConfigured(payload.values);
}

/** Has the organization been given a name of its own? */
Expand All @@ -545,9 +558,12 @@ export function hasInvitedColleagues(
* names it.
*/
export interface AiProviderState {
/** A provider is in use: the stated value is one, from the settings or the boot environment. */
/** A provider is in use, read from the stated `source`: from the settings, or from the boot environment or host. */
done: boolean;
/** The stated value, or `null` when none is in use. */
/**
* The stated value: `null` when none is in use, or when the provider in use
* comes from the environment and no option names it.
*/
value: string | null;
/** Where the running system took it from. */
source: SettingsLiveValue['source'];
Expand All @@ -568,10 +584,13 @@ export interface AiProviderState {
export function aiProviderState(payload: Pick<SettingsNamespacePayload, 'manifest' | 'live'>): AiProviderState | undefined {
const stated = payload.live?.[AI_PROVIDER_KEY];
if (!stated || typeof stated !== 'object') return undefined;
const { value, source } = stated;
if (source !== 'settings' && source !== 'environment' && source !== 'none') return undefined;
const inUse = source !== 'none' && typeof value === 'string' && value !== '';
const inUse = liveValueInUse(stated);
if (inUse === undefined) return undefined;
if (!inUse) return { done: false, value: null, source: 'none' };
const { value, source } = stated;
// In use from the environment, named by no option: done, the stated source
// kept, and no option to name it by.
if (value === null) return { done: true, value: null, source };
const spec = payload.manifest.specifiers.find((s) => s.key === AI_PROVIDER_KEY);
const option = (spec?.options ?? []).find((o) => String(o.value) === value);
const label = option ? resolveLabel(option.label) : undefined;
Expand Down
10 changes: 7 additions & 3 deletions ui/apps/console/src/pages/settings/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,13 @@ export interface ResolvedSettingValue<T = unknown> {

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