Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): list the bundled containers a disabled datastore leaves
Yudhi Armyndharisacab841cd226
diff --git a/dashboard/src/pages/Infrastructure.test.ts b/dashboard/src/pages/Infrastructure.test.tsindex 004eefdb0..db62109f6 100644--- a/dashboard/src/pages/Infrastructure.test.ts+++ b/dashboard/src/pages/Infrastructure.test.ts@@ -2438,6 +2438,32 @@ test('a built-in Redis whose switch the environment pins is not stopped when theassert.deepEqual(body, { profiles: ['postgres', 'minio'], profilesToRemove: [] });});+for (const key of ['REDIS_ENABLED', 'QUEUE_ENABLED'] as const) {+ for (const enabled of [false, true]) {+ test(`a pinned ${key} uses its running value ${enabled} when the saved read fails`, async () => {+ resetFetchCalls();+ overrides = {+ status: {+ ...RUNNING_BUNDLED,+ envPinned: [key],+ redis: { ...RUNNING_BUNDLED.redis, enabled: key === 'REDIS_ENABLED' ? enabled : false },+ queue: { ...RUNNING_BUNDLED.queue, enabled: key === 'QUEUE_ENABLED' ? enabled : false },+ },+ saved: {+ ...READBACK_SAVED,+ redis: { ...READBACK_SAVED.redis, enabled: key === 'REDIS_ENABLED' ? !enabled : false },+ queue: { enabled: key === 'QUEUE_ENABLED' ? !enabled : false },+ },+ savedAfterSaveFails: true,+ saveProfiles: ['postgres', 'minio'],+ };+ const { names, body } = await saveAndRestart();+ assert.deepEqual(names, enabled ? [] : ['openwa-redis']);+ assert.deepEqual(body, { profiles: ['postgres', 'minio'], profilesToRemove: enabled ? [] : ['redis'] });+ });+ }+}+test('bundled containers the environment pins the hosts to are neither stopped nor named', async () => {const { screen, waitFor, fireEvent, within } = rtl;resetFetchCalls();@@ -3150,3 +3176,63 @@ test(assert.ok(within(dialog).getByText(failure), 'the failure that explains the restart is not shown');},);++test('disabled database and storage are stopped beneath bundled host pins', async () => {+ const { screen, waitFor, fireEvent, within } = rtl;+ resetFetchCalls();+ overrides = {+ status: { ...RUNNING_BUNDLED, envPinned: ['DATABASE_HOST', 'S3_ENDPOINT'] },+ saved: READBACK_SAVED,+ savedAfterSave: {+ ...READBACK_SAVED,+ database: { ...READBACK_SAVED.database, type: 'sqlite', builtIn: false },+ storage: { ...READBACK_SAVED.storage, type: 'local', builtIn: false },+ },+ saveProfiles: ['redis'],+ };+ const { container } = renderInfrastructure();+ await screen.findByText('Database Configuration');+ await awaitSeeded(container);+ fireEvent.click(container.querySelectorAll<HTMLInputElement>('input[name="dbType"]')[0]);+ fireEvent.click(container.querySelectorAll<HTMLInputElement>('input[name="storageType"]')[0]);+ fireEvent.click(screen.getByRole('button', { name: 'Save Configuration' }));+ const dialog = await screen.findByRole('dialog');+ assert.deepEqual(stopNames(dialog), ['openwa-postgres', 'openwa-minio']);+ fireEvent.click(within(dialog).getByRole('button', { name: 'Restart Now' }));+ await waitFor(() => assert.ok(findFetchCall('POST', '/api/infra/restart')));+ assert.deepEqual(findFetchCall('POST', '/api/infra/restart')!.body, {+ profiles: ['redis'],+ profilesToRemove: ['postgres', 'minio'],+ });+});++for (const cacheUsesRedis of [false, true]) {+ test(`a disabled Redis beneath its bundled host pin keeps an active cache: ${cacheUsesRedis}`, async () => {+ const { screen, waitFor, fireEvent, within } = rtl;+ resetFetchCalls();+ const profiles = ['postgres', 'minio', ...(cacheUsesRedis ? ['redis'] : [])];+ overrides = {+ status: { ...RUNNING_BUNDLED, envPinned: ['REDIS_HOST'] },+ saved: { ...READBACK_SAVED, queue: { enabled: false } },+ savedAfterSave: {+ ...READBACK_SAVED,+ redis: { ...READBACK_SAVED.redis, enabled: false },+ queue: { enabled: false },+ },+ saveProfiles: profiles,+ };+ const { container } = renderInfrastructure();+ await screen.findByText('Database Configuration');+ await awaitSeeded(container);+ fireEvent.click(toggleInput(container, 'Enable Redis'));+ fireEvent.click(screen.getByRole('button', { name: 'Save Configuration' }));+ const dialog = await screen.findByRole('dialog');+ assert.deepEqual(stopNames(dialog), cacheUsesRedis ? [] : ['openwa-redis']);+ fireEvent.click(within(dialog).getByRole('button', { name: 'Restart Now' }));+ await waitFor(() => assert.ok(findFetchCall('POST', '/api/infra/restart')));+ assert.deepEqual(findFetchCall('POST', '/api/infra/restart')!.body, {+ profiles,+ profilesToRemove: cacheUsesRedis ? [] : ['redis'],+ });+ });+}diff --git a/dashboard/src/pages/Infrastructure.tsx b/dashboard/src/pages/Infrastructure.tsxindex cc4369577..5210469ac 100644--- a/dashboard/src/pages/Infrastructure.tsx+++ b/dashboard/src/pages/Infrastructure.tsx@@ -72,12 +72,8 @@ const nextBootHost = (profile: string, config: SavedConfig): string =>function writtenHost(profile: string, sent: SaveConfigPayload): string | undefined {if (profile === 'postgres') return sent.database?.type === 'sqlite' ? '' : sent.database?.host;if (profile === 'minio') return sent.storage?.type === 'local' ? '' : sent.storage?.s3Endpoint;- // A built-in Redis switched off is dropped with its host unless the queue or the cache still uses it, which keeps its- // profile. The one case the page cannot see is CACHE_ENABLED true in the saved file beside an environment value that- // turns it off: the host stays. An external host is kept as sent; one on the bundled name is dropped only once- // nothing uses Redis, which the cache may, so the page does not ask to stop that container.- const redis = sent.redis;- return redis?.builtIn && redis.enabled === false ? '' : redis?.host;+ // Consumer pins and the retained cache profile decide whether Redis is unused below.+ return sent.redis?.host;}export function Infrastructure() {@@ -186,15 +182,33 @@ export function Infrastructure() {).filter(([profile, up, host]) => up && host !== undefined && !namesBundledContainer(profile, host)).map(([profile]): string => profile);- // The server never stops a container the next boot still reaches: the host the environment pins, else the one in- // the file this save wrote. A pinned host is the one the page loaded; the saved one the page reads back, or takes- // from what the save sent when that read fails. It asks for (and names) only the containers neither reaches, and- // none whose host it cannot tell, so the dialog lists what the server stops. The form is seeded once, so the- // refetch keeps any edit in progress.+ // The server keeps a container only while the next boot both uses its datastore and dials its host: the host the+ // environment pins, else the one in the file this save wrote. A pinned host is the one the page loaded; the saved+ // one the page reads back, or takes from what the save sent when that read fails. It asks for (and names) the+ // containers whose datastore is switched off, then those neither host reaches, and none whose host it cannot+ // tell, so the dialog lists what the server stops. The form is seeded once, so the refetch keeps any edit in+ // progress.const saved = await queryClient.fetchQuery({ queryKey: ['infra', 'config'], queryFn: infraApi.getConfig, staleTime: 0 }).catch(() => undefined);+ const redisEnabled = infraStatus?.envPinned?.includes('REDIS_ENABLED')+ ? infraStatus.redis.enabled+ : (saved?.redis.enabled ?? sent.redis?.enabled);+ const queueEnabled = infraStatus?.envPinned?.includes('QUEUE_ENABLED')+ ? infraStatus.queue.enabled+ : (saved?.queue.enabled ?? sent.queue?.enabled);const toStop = [...running, ...pinnedAway].filter(profile => {+ // An inactive datastore never dials its pinned host. A retained Redis profile may still serve the cache.+ const unused =+ profile === 'postgres'+ ? dbType !== 'postgres'+ : profile === 'minio'+ ? storageType !== 's3'+ : sent.redis?.builtIn === true &&+ redisEnabled === false &&+ queueEnabled === false &&+ !profiles.includes('redis');+ if (unused) return true;const config = pinned(HOST_KEY[profile]) ?? saved;const host = config ? nextBootHost(profile, config) : writtenHost(profile, sent);return host !== undefined && !namesBundledContainer(profile, host);