Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): seed the infrastructure form from the saved config
Yudhi Armyndharis1de877d259dc
diff --git a/dashboard/src/hooks/useInfraConfigForm.test.ts b/dashboard/src/hooks/useInfraConfigForm.test.tsnew file mode 100644index 000000000..cdbb40612--- /dev/null+++ b/dashboard/src/hooks/useInfraConfigForm.test.ts@@ -0,0 +1,222 @@+// The Infrastructure form's seeding and the payload a save sends, driven through renderHook so a test decides+// which of the two server reads is in, and when. Infrastructure.test.ts covers the same hook through the page.+import '../test-helpers/register-hooks.ts';+import { test, before, afterEach } from 'node:test';+import assert from 'node:assert/strict';+import type { InfraStatus, SavedConfig } from '../services/api';+import type { installJsdomGlobals as installJsdomGlobalsFn } from '../test-helpers/jsdom.ts';+import type { useInfraConfigForm as useInfraConfigFormFn } from './useInfraConfigForm.ts';++type RTL = typeof import('@testing-library/react');++let rtl: RTL;+let useInfraConfigForm: typeof useInfraConfigFormFn;++before(async () => {+ const { installJsdomGlobals } = (await import('../test-helpers/jsdom.ts')) as {+ installJsdomGlobals: typeof installJsdomGlobalsFn;+ };+ await installJsdomGlobals();+ rtl = await import('@testing-library/react');+ ({ useInfraConfigForm } = await import('./useInfraConfigForm.ts'));+});++afterEach(() => rtl.cleanup());++interface Reads {+ status?: InfraStatus;+ saved?: SavedConfig;+}++function renderForm(initial: Reads) {+ return rtl.renderHook(({ status, saved }: Reads) => useInfraConfigForm(status, saved), { initialProps: initial });+}++// What the gateway process runs: SQLite, local media, no Redis, no queue.+const RUNNING: InfraStatus = {+ database: { connected: true, type: 'sqlite', host: 'localhost', builtIn: false },+ redis: { enabled: false, connected: false, host: 'localhost', port: 6379, builtIn: false },+ queue: { enabled: false, webhooks: { pending: 0, completed: 0, failed: 0 } },+ storage: { type: 'local', path: './data/media', builtIn: false },+ engine: { type: 'whatsapp-web.js', headless: true },+};++// What the operator saved afterwards and has not restarted for: external PostgreSQL, Redis with the queue, S3.+const SAVED: SavedConfig = {+ database: {+ type: 'postgres',+ builtIn: false,+ host: 'pg.internal',+ port: '5433',+ username: 'openwa',+ database: 'openwa_prod',+ schema: 'app',+ poolSize: 20,+ sslEnabled: true,+ sslRejectUnauthorized: false,+ passwordSet: true,+ },+ redis: { enabled: true, builtIn: false, host: 'redis.internal', port: '6380', passwordSet: true },+ queue: { enabled: true },+ storage: {+ type: 's3',+ builtIn: false,+ localPath: '',+ s3Bucket: 'media',+ s3Region: 'eu-west-1',+ s3Endpoint: 'https://s3.internal',+ s3CredentialsSet: true,+ },+ engine: { type: 'whatsapp-web.js', headless: true, sessionDataPath: './data/sessions', browserArgs: '' },+};++test('a save after a reload keeps the selections that were saved and are waiting for a restart', () => {+ const { result } = renderForm({ status: RUNNING, saved: SAVED });++ const { database, redis, queue, storage } = result.current.buildSavePayload();++ assert.deepEqual(+ {+ database: database?.type,+ host: database?.host,+ redis: redis?.enabled,+ queue: queue?.enabled,+ storage: storage?.type,+ bucket: storage?.s3Bucket,+ },+ { database: 'postgres', host: 'pg.internal', redis: true, queue: true, storage: 's3', bucket: 'media' },+ );+});++// A running service that differs from the saved one still drives the live indicators, but the form is+// the saved choice: a save of an unrelated field must not write the running one back over it.+test('the form shows what was saved, not what runs', () => {+ const { result } = renderForm({ status: RUNNING, saved: SAVED });++ assert.equal(result.current.dbConfig.type, 'postgres');+ assert.equal(result.current.redisEnabled, true);+ assert.equal(result.current.queueEnabled, true);+ assert.equal(result.current.storageConfig.type, 's3');+});++const RUNNING_OLD: InfraStatus = {+ ...RUNNING,+ database: { ...RUNNING.database, type: 'postgres', host: 'old-running-db' },+ redis: { ...RUNNING.redis, enabled: true, host: 'old-running-redis', port: 6379 },+ storage: { ...RUNNING.storage, path: '/old/media' },+};+const SAVED_NEW: SavedConfig = {+ ...SAVED,+ database: { ...SAVED.database, host: 'new-saved-db' },+ redis: { ...SAVED.redis, host: 'new-saved-redis', port: '6380' },+ storage: { ...SAVED.storage, type: 'local', localPath: '/new/media' },+};++// /config is a file read and /status probes every backend, so which one settles last is not the page's to choose.+for (const order of ['status first', 'config first', 'together'] as const) {+ test(`the saved host, port and media path win when the reads settle ${order}`, () => {+ const initial: Reads =+ order === 'status first'+ ? { status: RUNNING_OLD }+ : order === 'config first'+ ? { saved: SAVED_NEW }+ : { status: RUNNING_OLD, saved: SAVED_NEW };+ const { result, rerender } = renderForm(initial);+ rerender({ status: RUNNING_OLD, saved: SAVED_NEW });++ const { database, redis, storage } = result.current.buildSavePayload();++ assert.deepEqual(+ { dbHost: database?.host, redisHost: redis?.host, redisPort: redis?.port, localPath: storage?.localPath },+ { dbHost: 'new-saved-db', redisHost: 'new-saved-redis', redisPort: '6380', localPath: '/new/media' },+ );+ });+}++test('a host, port and path nothing has saved are seeded from what runs', () => {+ // GET /config reports '' for a key the file does not hold.+ const unsaved: SavedConfig = {+ ...SAVED_NEW,+ database: { ...SAVED_NEW.database, host: '', port: '' },+ redis: { ...SAVED_NEW.redis, host: '', port: '' },+ storage: { ...SAVED_NEW.storage, localPath: '' },+ };+ const { result } = renderForm({ status: RUNNING_OLD, saved: unsaved });++ const { database, redis, storage } = result.current.buildSavePayload();++ assert.deepEqual(+ {+ dbHost: database?.host,+ dbPort: database?.port,+ redisHost: redis?.host,+ redisPort: redis?.port,+ path: storage?.localPath,+ },+ { dbHost: 'old-running-db', dbPort: '5432', redisHost: 'old-running-redis', redisPort: '6379', path: '/old/media' },+ );+});++// Bundled containers run now; the operator saved external services and has not restarted.+const RUNNING_BUILTIN: InfraStatus = {+ database: { connected: true, type: 'postgres', host: 'postgres', builtIn: true },+ redis: { enabled: true, connected: true, host: 'redis', port: 6379, builtIn: true },+ queue: { enabled: true, webhooks: { pending: 0, completed: 0, failed: 0 } },+ storage: { type: 's3', bucket: 'openwa', builtIn: true },+ engine: { type: 'whatsapp-web.js', headless: true },+};++test('a built-in flag the operator has not touched is saved as it is stored, not as it runs', () => {+ const { result } = renderForm({ status: RUNNING_BUILTIN, saved: SAVED });+ rtl.act(() => result.current.updateDbConfig('password', 'typed-db-secret'));++ const { database, redis, storage } = result.current.buildSavePayload();++ assert.deepEqual([database?.builtIn, redis?.builtIn, storage?.builtIn], [false, false, false]);+ // Still an external database, so what was typed for it is sent.+ assert.equal(database?.password, 'typed-db-secret');+});++test('a stored built-in container is kept when the page runs an external one, and never gets a typed password', () => {+ const storedBuiltIn: SavedConfig = {+ ...SAVED,+ database: { ...SAVED.database, builtIn: true },+ redis: { ...SAVED.redis, builtIn: true },+ storage: { ...SAVED.storage, builtIn: true },+ };+ const { result } = renderForm({ status: RUNNING, saved: storedBuiltIn });+ rtl.act(() => {+ result.current.updateDbConfig('password', 'typed-db-secret');+ result.current.updateRedisConfig('password', 'typed-redis-secret');+ });++ const { database, redis, storage } = result.current.buildSavePayload();++ assert.deepEqual([database?.builtIn, redis?.builtIn, storage?.builtIn], [true, true, true]);+ assert.deepEqual([database?.password, redis?.password], ['', '']);+});++test('a built-in flag the operator flipped is saved as flipped', () => {+ const { result } = renderForm({ status: RUNNING_BUILTIN, saved: SAVED });+ rtl.act(() => {+ result.current.updateDbConfig('builtIn', true);+ result.current.updateRedisConfig('builtIn', true);+ result.current.updateStorageConfig('builtIn', true);+ });++ const { database, redis, storage } = result.current.buildSavePayload();++ assert.deepEqual([database?.builtIn, redis?.builtIn, storage?.builtIn], [true, true, true]);+});++test('a refetch after the form is seeded does not overwrite an edit in progress', () => {+ const { result, rerender } = renderForm({ status: RUNNING, saved: SAVED });+ rtl.act(() => result.current.updateDbConfig('host', 'edited-host'));++ rerender({+ status: { ...RUNNING },+ saved: { ...SAVED, database: { ...SAVED.database, host: 'refetched-host' } },+ });++ assert.equal(result.current.buildSavePayload().database?.host, 'edited-host');+});diff --git a/dashboard/src/hooks/useInfraConfigForm.ts b/dashboard/src/hooks/useInfraConfigForm.tsindex 273473ce2..544226160 100644--- a/dashboard/src/hooks/useInfraConfigForm.ts+++ b/dashboard/src/hooks/useInfraConfigForm.ts@@ -122,6 +122,10 @@ export function useInfraConfigForm(// operator's in-progress, unsaved edits. A successful save restarts → full page reload, re-arming it.const formHydrated = useRef(false);+ // The built-in flags are seeded from what is RUNNING, so until the operator flips one it is an+ // observation, not a choice. A save then carries the stored flag instead (see builtInToSave).+ const builtInTouched = useRef({ database: false, redis: false, storage: false });+// The engine radio seeds ONCE from the saved file (see the effect below), then is never re-stamped by// a background refetch. `engineTouched` additionally wins over a late first resolution: if the// operator clicked a different engine before the seed resolved, the delayed seed must not revert@@ -133,78 +137,56 @@ export function useInfraConfigForm(* rather than the useState default — the save payload omits `type` when it doesn't. */const engineTypeKnown = (): boolean => engineHydrated.current || engineTouched.current;- // Seed the EDITABLE selections from live /status ONCE (the running selection), guarded so a refetch- // can't clobber an unsaved edit. These are also the badge sources, so on first paint they show what's- // actually running (#488 family).+ // Seed the editable form ONCE, when both reads are in. The saved config (data/.env.generated) is the+ // operator's intent, so it supplies every selection and detail field: the running process is stale from+ // the moment a change is saved until the server restarts, and a form seeded from it writes that stale+ // value back over the saved one on the next save of ANY field, deleting the stored settings of the+ // service it switched away from (the engine radio below learned the same, #1082). Only what the saved+ // config cannot say comes from the live /status: whether a bundled container is actually running (#488),+ // and a host, port or path nothing has saved. One effect once both exist also keeps the result from+ // depending on which read settled last. Secrets are never returned, so their inputs stay empty; an empty+ // submit preserves the stored secret on the backend (#226).useEffect(() => {- if (!infraStatus || formHydrated.current) return;+ if (!infraStatus || !savedConfig || formHydrated.current) return;+ formHydrated.current = true;+ const { database, redis, queue, storage, engine } = savedConfig;setDbConfig(prev => ({...prev,- type: (infraStatus.database.type as 'sqlite' | 'postgres') || 'sqlite',- host: infraStatus.database.host || 'localhost',+ type: database.type,+ host: database.host || infraStatus.database.host || 'localhost',+ port: database.port || prev.port,+ username: database.username || prev.username,+ database: database.database || prev.database,+ schema: database.schema || prev.schema,+ poolSize: database.poolSize,+ sslEnabled: database.sslEnabled,+ sslRejectUnauthorized: database.sslRejectUnauthorized,// builtIn reflects whether OpenWA's bundled container is actually running (live), not saved intent.builtIn: infraStatus.database.builtIn,}));setRedisConfig(prev => ({...prev,- host: infraStatus.redis.host,- port: String(infraStatus.redis.port),+ host: redis.host || infraStatus.redis.host,+ port: redis.port || String(infraStatus.redis.port),builtIn: infraStatus.redis.builtIn,}));- setRedisEnabledState(infraStatus.redis.enabled);+ setRedisEnabledState(redis.enabled);+ setQueueEnabled(queue.enabled);setStorageConfig(prev => ({...prev,- type: infraStatus.storage.type,- localPath: infraStatus.storage.path || './uploads',+ type: storage.type,+ localPath: storage.localPath || infraStatus.storage.path || './uploads',+ s3Bucket: storage.s3Bucket || prev.s3Bucket,+ s3Region: storage.s3Region || prev.s3Region,+ s3Endpoint: storage.s3Endpoint || prev.s3Endpoint,builtIn: infraStatus.storage.builtIn,}));- setQueueEnabled(infraStatus.queue.enabled);- }, [infraStatus]);-- // Hydrate the editable form from the saved config (data/.env.generated) ONCE — only the detail fields- // /status does not expose (username, pool size, SSL flags, S3 details, host/port). The "what's- // running" fields (type, redis enabled, storage type, built-in) are owned by the live /status effect- // above. Secrets are never returned, so their inputs stay empty; an empty submit preserves the stored- // secret on the backend (#226).- useEffect(() => {- if (!savedConfig || formHydrated.current) return;- // NOTE: builtIn for db/redis/storage is owned by the live /status effect above (it reflects the- // actually-running bundled container), so it is intentionally NOT set here from saved intent.- setDbConfig(prev => ({- ...prev,- host: savedConfig.database.host || prev.host,- port: savedConfig.database.port || prev.port,- username: savedConfig.database.username || prev.username,- database: savedConfig.database.database || prev.database,- schema: savedConfig.database.schema || prev.schema,- poolSize: savedConfig.database.poolSize,- sslEnabled: savedConfig.database.sslEnabled,- sslRejectUnauthorized: savedConfig.database.sslRejectUnauthorized,- }));- setRedisConfig(prev => ({- ...prev,- host: savedConfig.redis.host || prev.host,- port: savedConfig.redis.port || prev.port,- }));- setStorageConfig(prev => ({- ...prev,- localPath: savedConfig.storage.localPath || prev.localPath,- s3Bucket: savedConfig.storage.s3Bucket || prev.s3Bucket,- s3Region: savedConfig.storage.s3Region || prev.s3Region,- s3Endpoint: savedConfig.storage.s3Endpoint || prev.s3Endpoint,- }));setEngineConfig(prev => ({...prev,- headless: savedConfig.engine.headless,- sessionDataPath: savedConfig.engine.sessionDataPath || prev.sessionDataPath,- browserArgs: savedConfig.engine.browserArgs || prev.browserArgs,+ headless: engine.headless,+ sessionDataPath: engine.sessionDataPath || prev.sessionDataPath,+ browserArgs: engine.browserArgs || prev.browserArgs,}));- }, [savedConfig]);-- // Lock the editable form once both sources have seeded it, so later background refetches only refresh- // the live indicators above and never overwrite unsaved edits.- useEffect(() => {- if (infraStatus && savedConfig) formHydrated.current = true;}, [infraStatus, savedConfig]);// Seed the radio once from /config, and never after the operator has touched it (#735).@@ -223,12 +205,18 @@ export function useInfraConfigForm(setEngineConfig(prev => (prev.type === seed ? prev : { ...prev, type: seed }));}, [savedConfig]);- const updateDbConfig = (key: keyof DatabaseConfig, value: string | number | boolean) =>+ const updateDbConfig = (key: keyof DatabaseConfig, value: string | number | boolean) => {+ if (key === 'builtIn') builtInTouched.current.database = true;setDbConfig(prev => ({ ...prev, [key]: value }));- const updateRedisConfig = (key: keyof RedisConfig, value: string | boolean) =>+ };+ const updateRedisConfig = (key: keyof RedisConfig, value: string | boolean) => {+ if (key === 'builtIn') builtInTouched.current.redis = true;setRedisConfig(prev => ({ ...prev, [key]: value }));- const updateStorageConfig = (key: keyof StorageConfig, value: string | boolean) =>+ };+ const updateStorageConfig = (key: keyof StorageConfig, value: string | boolean) => {+ if (key === 'builtIn') builtInTouched.current.storage = true;setStorageConfig(prev => ({ ...prev, [key]: value }));+ };const updateEngineConfig = (key: keyof EngineConfig, value: string | boolean) => {if (key === 'type') engineTouched.current = true;setEngineConfig(prev => ({ ...prev, [key]: value }));@@ -242,21 +230,30 @@ export function useInfraConfigForm(const setRedisConnected = (connected: boolean) => setRedisConfig(prev => ({ ...prev, connected }));+ // The flag a save carries: the operator's flip, else the stored one. Until it is flipped, the flag shown+ // is what runs, and writing that back would turn a bundled service into an external one (or the reverse)+ // that was saved and is waiting for a restart, along with the credentials that service owns. It is always+ // sent, never left out: the backend builds the Docker profile list from it.+ const builtInToSave = (section: 'database' | 'redis' | 'storage', shown: boolean): boolean =>+ builtInTouched.current[section] ? shown : (savedConfig?.[section].builtIn ?? shown);+const buildSavePayload = (): SaveConfigPayload => ({// A bundled container never receives a typed password (the field is hidden once built-in is on,// but a value typed before the toggle survives in state). '' means "unchanged" on the backend.- database: dbConfig.builtIn ? { ...dbConfig, password: '' } : { ...dbConfig },+ database: builtInToSave('database', dbConfig.builtIn)+ ? { ...dbConfig, builtIn: true, password: '' }+ : { ...dbConfig, builtIn: false },// `connected` is runtime-only status, not persisted configuration. Keep it out of the// whitelisted backend DTO so a valid dashboard save cannot be rejected as an unknown field.redis: {enabled: redisEnabled,- builtIn: redisConfig.builtIn,+ builtIn: builtInToSave('redis', redisConfig.builtIn),host: redisConfig.host,port: redisConfig.port,- password: redisConfig.builtIn ? '' : redisConfig.password,+ password: builtInToSave('redis', redisConfig.builtIn) ? '' : redisConfig.password,},queue: { enabled: queueEnabled },- storage: { ...storageConfig },+ storage: { ...storageConfig, builtIn: builtInToSave('storage', storageConfig.builtIn) },// Only send `type` once we actually know it — either the radio seeded from /config or the// operator picked one. If /config never resolved, engineConfig.type still holds its useState// default, and sending that would persist ENGINE_TYPE and silently flip the engine on the nextdiff --git a/dashboard/src/pages/Infrastructure.test.ts b/dashboard/src/pages/Infrastructure.test.tsindex 6efb0b8a8..308b3cbf2 100644--- a/dashboard/src/pages/Infrastructure.test.ts+++ b/dashboard/src/pages/Infrastructure.test.ts@@ -18,11 +18,10 @@ import type { installJsdomGlobals as installJsdomGlobalsFn } from '../test-helpe// ── Fixtures + fetch stub ────────────────────────────────────────────────────-// database.host is kept IDENTICAL between /status and /config on purpose: both the live-seed-// effect (from infraStatus) and the saved-config hydrate effect write dbConfig.host, and which one-// wins depends on which query settles last — a race this test does not want to pin. username,-// database name, schema and pool size are written ONLY by the saved-config effect, so asserting on-// those (not host) is what actually proves /config hydration without being timing-sensitive.+// The form is seeded from /config, and from /status only for the built-in flags and for a host, port or+// path nothing has saved. database.host is the same in both here, so the stock fixtures do not say which+// one supplied it: username, database name, schema and pool size, which only /config carries, are what+// prove /config hydration.const INFRA_STATUS: InfraStatus = {database: { connected: true, type: 'postgres', host: 'shared-db-host', builtIn: false },redis: { enabled: false, connected: false, host: 'localhost', port: 6379, builtIn: false },@@ -266,13 +265,12 @@ test('Infrastructure renders and the config form hydrates from /status and /confawait screen.findByText('Database Configuration');await waitFor(() => {- // dbConfig.type comes ONLY from /status (the live-seed effect) — sqlite is the useState default,- // so a checked Postgres radio here proves /status actually hydrated the form.+ // dbConfig.type is seeded from the saved config: sqlite is the useState default, so a checked+ // Postgres radio here proves the form was hydrated.const dbRadios = container.querySelectorAll('input[name="dbType"]');assert.equal((dbRadios[1] as HTMLInputElement).checked, true, 'expected the Postgres radio to be selected');- // These fields are written ONLY by the saved-config hydrate effect (never by the /status- // effect), so they pin /config hydration specifically, without the host/port race.+ // Only /config carries these fields, so they pin /config hydration specifically.assert.equal(fieldInput(container, 'Username').value, 'openwa_admin');assert.equal(fieldInput(container, 'Database Name').value, 'openwa_prod');assert.equal(fieldInput(container, 'Schema').value, 'appschema');@@ -506,9 +504,9 @@ function engineRadios(container: HTMLElement): HTMLInputElement[] {return Array.from(container.querySelectorAll('input[name="engineType"]'));}-// Waits for the /config hydrate effect, which is the last of the two seeding effects to land. Uses a-// DATABASE field on purpose: the engine detail fields render only for whatsapp-web.js, so waiting on-// one of those would vanish the moment a test seeds the radio to baileys.+// Waits for the form to be seeded, which happens once both reads are in. Uses a DATABASE field on+// purpose: the engine detail fields render only for whatsapp-web.js, so waiting on one of those would+// vanish the moment a test seeds the radio to baileys.async function awaitConfigHydrated(container: HTMLElement): Promise<void> {await rtl.waitFor(() => assert.equal(fieldInput(container, 'Username').value, 'openwa_admin'));}@@ -572,6 +570,109 @@ test('an operator selection wins over the seed and is what gets saved', async ()});});+// ── A switch saved and not restarted for ─────────────────────────────────────+// The operator saved PostgreSQL, Redis with the queue, and S3, chose Restart Later, and reloaded: the+// gateway still runs SQLite, local media and no Redis. The form is the saved choice (a save of anything+// else must not write the running one back over it); the card badges report what runs.++const RUNNING_SQLITE: InfraStatus = {+ ...INFRA_STATUS,+ database: { connected: true, type: 'sqlite', host: 'localhost', builtIn: false },+};+const SAVED_SWITCH: SavedConfig = {+ ...SAVED_CONFIG,+ redis: { enabled: true, builtIn: false, host: 'redis.internal', port: '6380', passwordSet: true },+ queue: { enabled: true },+ storage: { ...SAVED_CONFIG.storage, type: 's3', s3Bucket: 'media', s3CredentialsSet: true },+};++// The saved headless flag is false and the useState default is true, so it reads false only once the form is seeded.+async function awaitSeeded(container: HTMLElement): Promise<void> {+ await rtl.waitFor(() => assert.equal(toggleInput(container, 'Headless Mode').checked, false));+}++function cardBadge(container: HTMLElement, heading: string): string | null | undefined {+ const card = Array.from(container.querySelectorAll('.infra-card')).find(+ c => c.querySelector('h2')?.textContent === heading,+ );+ return card?.querySelector('.card-header .status-indicator')?.textContent;+}++test('saving an unrelated field after a reload keeps a switch that was saved and is waiting for a restart', async () => {+ const { screen, waitFor, fireEvent } = rtl;+ resetFetchCalls();+ overrides = { status: RUNNING_SQLITE, saved: SAVED_SWITCH };+ const { container } = renderInfrastructure();++ await screen.findByText('Database Configuration');+ await awaitSeeded(container);+ // The stored headless flag is false; flipping it is the only edit.+ fireEvent.click(toggleInput(container, 'Headless Mode'));+ fireEvent.click(screen.getByRole('button', { name: 'Save Configuration' }));++ await waitFor(() => {+ const call = findFetchCall('PUT', '/api/infra/config');+ assert.ok(call, 'expected a PUT to /infra/config');+ const body = call!.body as {+ database?: { type?: string };+ redis?: { enabled?: boolean };+ queue?: { enabled?: boolean };+ storage?: { type?: string };+ engine?: { headless?: boolean };+ };+ assert.deepEqual(+ {+ database: body.database?.type,+ redis: body.redis?.enabled,+ queue: body.queue?.enabled,+ storage: body.storage?.type,+ headless: body.engine?.headless,+ },+ { database: 'postgres', redis: true, queue: true, storage: 's3', headless: true },+ );+ });+});++test('the card badges report what runs while the form shows what was saved', async () => {+ const { screen } = rtl;+ resetFetchCalls();+ overrides = { status: RUNNING_SQLITE, saved: SAVED_SWITCH };+ const { container } = renderInfrastructure();++ await screen.findByText('Database Configuration');+ await awaitSeeded(container);++ assert.equal(cardBadge(container, 'Database Configuration'), '● SQLite');+ assert.equal(cardBadge(container, 'Redis'), '● Disabled');+ assert.equal(cardBadge(container, 'Storage Configuration'), '● Local Filesystem');+ const selected = (name: string) =>+ container.querySelector(`input[name="${name}"]:checked`)?.closest('label')?.querySelector('span')?.textContent;+ assert.equal(selected('dbType'), 'PostgreSQL');+ assert.equal(toggleInput(container, 'Enable Redis').checked, true);+ assert.equal(selected('storageType'), 'Amazon S3');+});++test('a queue switch saved and left for a restart shows the pending-restart note', async () => {+ const { screen } = rtl;+ resetFetchCalls();+ // Redis already runs, so the only difference between running and saved is the queue.+ overrides = {+ status: {+ ...INFRA_STATUS,+ redis: { enabled: true, connected: true, host: 'redis.internal', port: 6380, builtIn: false },+ },+ saved: { ...SAVED_CONFIG, redis: { ...SAVED_SWITCH.redis }, queue: { enabled: true } },+ };+ const { container } = renderInfrastructure();++ await screen.findByText('Database Configuration');+ await awaitConfigHydrated(container);++ const queueRow = toggleInput(container, 'Enable BullMQ Queue System').closest('.toggle-row');+ assert.equal(queueRow?.nextElementSibling?.textContent?.trim(), PENDING_RESTART_NOTE);+ assert.equal(screen.getAllByText(PENDING_RESTART_NOTE).length, 1, 'the note belongs to the queue alone');+});+test('the pending-restart note survives a successful save', async () => {const { screen, waitFor, fireEvent } = rtl;resetFetchCalls();diff --git a/dashboard/src/pages/Infrastructure.tsx b/dashboard/src/pages/Infrastructure.tsxindex bd9eb2d8c..4a2a8c290 100644--- a/dashboard/src/pages/Infrastructure.tsx+++ b/dashboard/src/pages/Infrastructure.tsx@@ -234,8 +234,8 @@ export function Infrastructure() {<Database size={20} /><h2>{t('infrastructure.database.title')}</h2></div>- <span className={`status-indicator ${configForm.dbConfig.type === 'postgres' ? 'connected' : 'sqlite'}`}>- ● {configForm.dbConfig.type === 'postgres' ? 'PostgreSQL' : 'SQLite'}+ <span className={`status-indicator ${infraStatus.database.type === 'postgres' ? 'connected' : 'sqlite'}`}>+ ● {infraStatus.database.type === 'postgres' ? 'PostgreSQL' : 'SQLite'}</span></div>{settingNote('DATABASE_TYPE', infraStatus.database.type, savedConfig?.database.type)}@@ -518,11 +518,11 @@ export function Infrastructure() {</div><spanclassName={`status-indicator ${- configForm.redisEnabled && configForm.redisConfig.connected ? 'connected' : 'disconnected'+ infraStatus.redis.enabled && configForm.redisConfig.connected ? 'connected' : 'disconnected'}`}>●{' '}- {configForm.redisEnabled+ {infraStatus.redis.enabled? configForm.redisConfig.connected? t('infrastructure.statusLabels.connected'): t('infrastructure.statusLabels.disconnected')@@ -623,6 +623,7 @@ export function Infrastructure() {<span className="toggle-slider"></span></label></div>+ {settingNote('QUEUE_ENABLED', infraStatus.queue.enabled, savedConfig.queue.enabled)}{configForm.queueEnabled && (<div className="queue-stats">@@ -690,15 +691,13 @@ export function Infrastructure() {<h2>{t('infrastructure.storage.title')}</h2></div>{(() => {- // S3 selected but the backend isn't reachable → warn instead of a misleading green.- const s3Unreachable =- configForm.storageConfig.type === 's3' && infraStatus?.storage.s3Available === false;- const cls =- configForm.storageConfig.type !== 's3' ? 'sqlite' : s3Unreachable ? 'disconnected' : 'connected';+ // S3 running but the backend isn't reachable → warn instead of a misleading green.+ const s3Unreachable = infraStatus.storage.type === 's3' && infraStatus.storage.s3Available === false;+ const cls = infraStatus.storage.type !== 's3' ? 'sqlite' : s3Unreachable ? 'disconnected' : 'connected';return (<span className={`status-indicator ${cls}`}>●{' '}- {configForm.storageConfig.type === 's3'+ {infraStatus.storage.type === 's3'? s3Unreachable? t('infrastructure.storage.s3Unreachable'): 'S3'