Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): follow what runs when a built-in flag is not stored

Yudhi Armyndharis1d69eb946271
diff --git a/dashboard/src/hooks/useInfraConfigForm.test.ts b/dashboard/src/hooks/useInfraConfigForm.test.ts
index 62fc90c12..ebcc899df 100644
--- a/dashboard/src/hooks/useInfraConfigForm.test.ts
+++ b/dashboard/src/hooks/useInfraConfigForm.test.ts
@@ -182,6 +182,15 @@ const shownFlags = (form: ReturnType<typeof renderForm>['result']['current']) =>
form.storageConfig.builtIn,
];
+// A deployment that pins DATABASE_HOST=postgres (REDIS_HOST=redis, S3_ENDPOINT) in .env never writes the flags:
+// /config reports builtIn false and builtInSet false, and only /status knows a bundled container runs.
+const UNSTORED_BUILTIN: SavedConfig = {
+ ...SAVED,
+ database: { ...SAVED.database, builtIn: false, builtInSet: false },
+ redis: { ...SAVED.redis, builtIn: false, builtInSet: false },
+ storage: { ...SAVED.storage, builtIn: false, builtInSet: false },
+};
+
// The toggles are the saved choice like every other selection. Shown from what runs, one that reads "external"
// invites typing an external host and credentials that the gateway then drops under the stored bundled mode.
test('the built-in toggles show what was saved, not what runs', () => {
@@ -202,6 +211,36 @@ for (const order of ['status first', 'config first'] as const) {
});
}
+test('a built-in flag nothing stores follows what runs, so a save does not claim a switch', () => {
+ const { result } = renderForm({ status: RUNNING_BUILTIN, saved: UNSTORED_BUILTIN });
+
+ assert.deepEqual(shownFlags(result.current), [true, true, true]);
+ const { database, redis, storage } = result.current.buildSavePayload();
+ assert.deepEqual([database?.builtIn, redis?.builtIn, storage?.builtIn], [true, true, true]);
+});
+
+for (const order of ['status first', 'config first'] as const) {
+ test(`a built-in flag nothing stores follows what runs when the reads settle ${order}`, () => {
+ const { result, rerender } = renderForm(
+ order === 'status first' ? { status: RUNNING_BUILTIN } : { saved: UNSTORED_BUILTIN },
+ );
+ rerender({ status: RUNNING_BUILTIN, saved: UNSTORED_BUILTIN });
+
+ assert.deepEqual(shownFlags(result.current), [true, true, true]);
+ });
+}
+
+test('each built-in flag is judged on its own: a stored one wins, an unstored one follows what runs', () => {
+ const mixed: SavedConfig = {
+ ...UNSTORED_BUILTIN,
+ database: { ...SAVED.database, builtIn: false, builtInSet: true },
+ storage: { ...SAVED.storage, builtIn: true, builtInSet: true },
+ };
+ const { result } = renderForm({ status: RUNNING_BUILTIN, saved: mixed });
+
+ assert.deepEqual(shownFlags(result.current), [false, true, true]);
+});
+
test('a save carries the built-in flag the form shows', () => {
for (const [status, saved] of [
[RUNNING_BUILTIN, SAVED],
diff --git a/dashboard/src/hooks/useInfraConfigForm.ts b/dashboard/src/hooks/useInfraConfigForm.ts
index 98d196df8..d5a4abd31 100644
--- a/dashboard/src/hooks/useInfraConfigForm.ts
+++ b/dashboard/src/hooks/useInfraConfigForm.ts
@@ -59,6 +59,14 @@ export interface InfraConfigForm {
buildSavePayload: () => SaveConfigPayload;
}
+/**
+ * The Use Built-in flag as saved. A flag the config does not store says nothing (a Compose deployment that pins
+ * DATABASE_HOST=postgres, REDIS_HOST=redis or S3_ENDPOINT never writes it), so what runs stands in for it: there
+ * is no pending switch, and a save keeps sending the mode that runs.
+ */
+export const savedBuiltIn = (saved: { builtIn: boolean; builtInSet: boolean }, running: boolean): boolean =>
+ saved.builtInSet ? saved.builtIn : running;
+
/**
* Owns the editable infrastructure form: dbConfig/redisConfig/storageConfig/engineConfig, the
* redis-enabled/queue-enabled toggles, and the hydration that seeds them from the two server
@@ -141,7 +149,7 @@ export function useInfraConfigForm(
// Built-in toggles too: shown from what runs, one that reads "external" invites typing an external host
// and credentials that the gateway drops under the stored bundled mode. What is running is reported by the
// badges and the pending-restart notes. Only a host, port or path nothing has saved comes from the live
- // /status. One effect once both exist also keeps the result from depending on which read settled last.
+ // /status, and so does a built-in flag nothing stores. 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(() => {
@@ -159,13 +167,13 @@ export function useInfraConfigForm(
poolSize: database.poolSize,
sslEnabled: database.sslEnabled,
sslRejectUnauthorized: database.sslRejectUnauthorized,
- builtIn: database.builtIn,
+ builtIn: savedBuiltIn(database, infraStatus.database.builtIn),
}));
setRedisConfig(prev => ({
...prev,
host: redis.host || infraStatus.redis.host,
port: redis.port || String(infraStatus.redis.port),
- builtIn: redis.builtIn,
+ builtIn: savedBuiltIn(redis, infraStatus.redis.builtIn),
}));
setRedisEnabledState(redis.enabled);
setQueueEnabled(queue.enabled);
@@ -176,7 +184,7 @@ export function useInfraConfigForm(
s3Bucket: storage.s3Bucket || prev.s3Bucket,
s3Region: storage.s3Region || prev.s3Region,
s3Endpoint: storage.s3Endpoint || prev.s3Endpoint,
- builtIn: storage.builtIn,
+ builtIn: savedBuiltIn(storage, infraStatus.storage.builtIn),
}));
setEngineConfig(prev => ({
...prev,
diff --git a/dashboard/src/pages/Infrastructure.test.ts b/dashboard/src/pages/Infrastructure.test.ts
index fb4728932..da7636d5f 100644
--- a/dashboard/src/pages/Infrastructure.test.ts
+++ b/dashboard/src/pages/Infrastructure.test.ts
@@ -90,6 +90,8 @@ let overrides: {
statusFails?: boolean;
currentEngine?: { engineType: string };
restart?: () => Response;
+ // The Docker profiles the save answers with.
+ saveProfiles?: string[];
readyFails?: boolean;
} = {};
@@ -164,9 +166,14 @@ function installFetchStub(): void {
if (method === 'GET' && path === '/api/infra/engines/current')
return Promise.resolve(jsonResponse(overrides.currentEngine ?? CURRENT_ENGINE));
if (method === 'PUT' && path === '/api/infra/config') {
- return Promise.resolve(
- jsonResponse({ message: 'Configuration saved', saved: true, envPath: '.env.generated', profiles: [] }),
- );
+ const answer = () =>
+ jsonResponse({
+ message: 'Configuration saved',
+ saved: true,
+ envPath: '.env.generated',
+ profiles: overrides.saveProfiles ?? [],
+ });
+ return Promise.resolve(answer());
}
if (method === 'POST' && path === '/api/infra/restart') {
if (overrides.restart) return Promise.resolve(overrides.restart());
@@ -861,6 +868,56 @@ test('no built-in note while the toggles agree with what runs', async () => {
assert.equal(screen.queryByText(PENDING_BUILT_IN_NOTE) === null, true, 'a note beside a toggle that agrees');
});
+// The documented .env route: DATABASE_HOST=postgres, REDIS_HOST=redis and S3_ENDPOINT are pinned and compose never
+// forwards the flags, so /config holds none and only /status knows the bundled containers run. Nothing was saved, so
+// no toggle, note or warning may claim a switch, and a save must keep sending the running mode.
+const UNSTORED_BUILT_IN: SavedConfig = {
+ ...SAVED_EXTERNAL,
+ database: { ...SAVED_EXTERNAL.database, builtIn: false, builtInSet: false },
+ redis: { ...SAVED_EXTERNAL.redis, builtIn: false, builtInSet: false },
+ storage: { ...SAVED_EXTERNAL.storage, builtIn: false, builtInSet: false },
+};
+
+test('bundled containers running with no flag stored show the toggles on and claim no switch', async () => {
+ const { screen, waitFor, fireEvent, within } = rtl;
+ resetFetchCalls();
+ overrides = {
+ status: RUNNING_BUNDLED,
+ saved: UNSTORED_BUILT_IN,
+ // What the gateway answers for bundled flags: the profiles of the containers that stay.
+ saveProfiles: ['postgres', 'redis', 'minio'],
+ };
+ const { container } = renderInfrastructure();
+
+ await screen.findByText('Database Configuration');
+ await awaitSeeded(container);
+ assert.equal(toggleInput(container, 'Use Built-in PostgreSQL Container').checked, true);
+ assert.equal(toggleInput(container, 'Use Built-in Redis Container').checked, true);
+ assert.equal(toggleInput(container, 'Use Built-in MinIO Container').checked, true);
+ assert.equal(screen.queryByText(PENDING_EXTERNAL_NOTE) === null, true, 'a switch claimed with nothing saved');
+ assert.equal(screen.queryByText(PENDING_BUILT_IN_NOTE) === null, true, 'a switch claimed with nothing saved');
+
+ fireEvent.click(toggleInput(container, 'Headless Mode'));
+ fireEvent.click(screen.getByRole('button', { name: 'Save Configuration' }));
+
+ const dialog = await screen.findByRole('dialog');
+ assert.equal(within(dialog).queryByText(DB_SWITCH_WARNING, { exact: false }) === null, true, 'a warning, no switch');
+ assert.equal(within(dialog).queryByText(STORAGE_WARNING, { exact: false }) === null, true, 'a warning, no switch');
+ const body = findFetchCall('PUT', '/api/infra/config')!.body as {
+ database?: { builtIn?: boolean };
+ redis?: { builtIn?: boolean };
+ storage?: { builtIn?: boolean };
+ };
+ assert.deepEqual([body.database?.builtIn, body.redis?.builtIn, body.storage?.builtIn], [true, true, true]);
+
+ fireEvent.click(within(dialog).getByRole('button', { name: 'Restart Now' }));
+ await waitFor(() => assert.ok(findFetchCall('POST', '/api/infra/restart'), 'expected the restart POST'));
+ assert.deepEqual(findFetchCall('POST', '/api/infra/restart')!.body, {
+ profiles: ['postgres', 'redis', 'minio'],
+ profilesToRemove: [],
+ });
+});
+
// SQLite runs and bundled PostgreSQL is saved: the database note names the type change, and a running
// "external" flag would be a claim about a database that is not running.
test('no built-in note beside a pending database type', async () => {
diff --git a/dashboard/src/pages/Infrastructure.tsx b/dashboard/src/pages/Infrastructure.tsx
index 6c5b8de20..cff36127c 100644
--- a/dashboard/src/pages/Infrastructure.tsx
+++ b/dashboard/src/pages/Infrastructure.tsx
@@ -18,7 +18,7 @@ import { API_BASE_URL, type SavedConfig } from '../services/api';
import { copyToClipboard } from '../utils/clipboard';
import { useDocumentTitle } from '../hooks/useDocumentTitle';
import { useInfraStatusQuery, useInfraConfigQuery, useEnginesQuery, useCurrentEngineQuery } from '../hooks/queries';
-import { useInfraConfigForm } from '../hooks/useInfraConfigForm';
+import { savedBuiltIn, useInfraConfigForm } from '../hooks/useInfraConfigForm';
import { useConfigSave } from '../hooks/useConfigSave';
import { useRestartFlow } from '../hooks/useRestartFlow';
import { useDataBackup } from '../hooks/useDataBackup';
@@ -297,7 +297,7 @@ export function Infrastructure() {
{builtInNote(
infraStatus.database.type === 'postgres' && savedConfig.database.type === 'postgres',
infraStatus.database.builtIn,
- savedConfig.database.builtIn,
+ savedBuiltIn(savedConfig.database, infraStatus.database.builtIn),
)}
{!configForm.dbConfig.builtIn && (
@@ -600,7 +600,7 @@ export function Infrastructure() {
{builtInNote(
infraStatus.redis.enabled && savedConfig.redis.enabled,
infraStatus.redis.builtIn,
- savedConfig.redis.builtIn,
+ savedBuiltIn(savedConfig.redis, infraStatus.redis.builtIn),
)}
{!configForm.redisConfig.builtIn && (
@@ -799,7 +799,7 @@ export function Infrastructure() {
{builtInNote(
infraStatus.storage.type === 's3' && savedConfig.storage.type === 's3',
infraStatus.storage.builtIn,
- savedConfig.storage.builtIn,
+ savedBuiltIn(savedConfig.storage, infraStatus.storage.builtIn),
)}
{!configForm.storageConfig.builtIn && (