Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): name only the stops the server makes on a failed read
Yudhi Armyndharis0095786a558d
diff --git a/dashboard/src/pages/Infrastructure.test.ts b/dashboard/src/pages/Infrastructure.test.tsindex e3c66294f..b13e611e2 100644--- a/dashboard/src/pages/Infrastructure.test.ts+++ b/dashboard/src/pages/Infrastructure.test.ts@@ -1972,6 +1972,64 @@ test('a built-in Redis switched off but left on the bundled host is neither stopassert.deepEqual(findFetchCall('POST', '/api/infra/restart')!.body, { profiles: [], profilesToRemove: [] });});+// The server reads the saved host from the file the save wrote. Without the read-back the page cannot know it, so it+// neither asks to stop that container nor names it: the dialog lists only what the server stops.+test('a built-in Redis left on the bundled host is neither stopped nor named when the read-back fails', async () => {+ const { screen, waitFor, fireEvent, within } = rtl;+ resetFetchCalls();+ const redis = { enabled: true, builtIn: true, builtInSet: true, host: 'redis', port: '6379', passwordSet: false };+ overrides = {+ status: {+ ...INFRA_STATUS,+ redis: { enabled: true, connected: true, host: 'redis', port: 6379, builtIn: true, running: true },+ },+ saved: { ...SAVED_CONFIG, redis },+ savedAfterSaveFails: true,+ };+ const { container } = renderInfrastructure();++ await screen.findByText('Database Configuration');+ await awaitConfigHydrated(container);+ const builtInRedis = toggleInput(container, 'Use Built-in Redis Container');+ await waitFor(() => assert.equal(builtInRedis.checked, true));+ fireEvent.click(builtInRedis);+ fireEvent.click(screen.getByRole('button', { name: 'Save Configuration' }));++ const dialog = await screen.findByRole('dialog');+ assert.doesNotMatch(dialog.textContent ?? '', /openwa-/);+ 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: [], profilesToRemove: [] });+});++// A pinned host is known without the read-back: one that reaches the container keeps it.+test('bundled containers the pinned hosts reach are neither stopped nor named when the read-back fails', async () => {+ resetFetchCalls();+ overrides = {+ status: { ...RUNNING_BUNDLED, envPinned: ['DATABASE_HOST', 'REDIS_HOST', 'S3_ENDPOINT'] },+ saved: {+ ...SAVED_CONFIG,+ database: { ...SAVED_CONFIG.database, builtIn: true, builtInSet: false, host: 'postgres' },+ redis: { enabled: true, builtIn: true, builtInSet: false, host: 'redis', port: '6379', passwordSet: false },+ storage: {+ ...SAVED_CONFIG.storage,+ type: 's3',+ builtIn: true,+ builtInSet: false,+ s3Bucket: 'openwa',+ s3Endpoint: 'http://minio:9000',+ },+ },+ savedAfterSaveFails: true,+ };++ const { dialogText, names, body } = await saveAndRestart();++ assert.deepEqual(names, []);+ assert.doesNotMatch(dialogText, /openwa-/);+ assert.deepEqual(body, { profiles: [], profilesToRemove: [] });+});+test('bundled containers the environment pins the hosts to are neither stopped nor named', async () => {const { screen, waitFor, fireEvent, within } = rtl;resetFetchCalls();diff --git a/dashboard/src/pages/Infrastructure.tsx b/dashboard/src/pages/Infrastructure.tsxindex 0a4074229..45530eeb3 100644--- a/dashboard/src/pages/Infrastructure.tsx+++ b/dashboard/src/pages/Infrastructure.tsx@@ -39,6 +39,9 @@ interface QueueStats {failed: number;}+// The key that holds each managed profile's host.+const HOST_KEY: Record<string, string> = { postgres: 'DATABASE_HOST', redis: 'REDIS_HOST', minio: 'S3_ENDPOINT' };+/** The host the next boot dials for a profile, as GET /config reports it: the environment's, else the saved one. */const nextBootHost = (profile: string, config: SavedConfig): string =>profile === 'postgres' ? config.database.host : profile === 'redis' ? config.redis.host : config.storage.s3Endpoint;@@ -125,15 +128,18 @@ 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, read from the file this save wrote, so the- // page reads that file back and asks for (and names) only the others. Without the read, the server decides.- // The form is seeded once, so the refetch keeps any edit in progress.+ // 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. It asks+ // for (and names) only the containers neither reaches, and none whose host it could not read, 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 toStop = [...running, ...pinnedAway].filter(- profile => !saved || !namesBundledContainer(profile, nextBootHost(profile, saved)),- );+ const next = (profile: string) => pinned(HOST_KEY[profile]) ?? saved;+ const toStop = [...running, ...pinnedAway].filter(profile => {+ const config = next(profile);+ return !!config && !namesBundledContainer(profile, nextBootHost(profile, config));+ });restartFlow.open({profiles: profiles.filter(p => !pinnedAway.includes(p)),running: toStop,diff --git a/src/modules/infra/infra-config.controller.ts b/src/modules/infra/infra-config.controller.tsindex 55fd76813..27c3f21e1 100644--- a/src/modules/infra/infra-config.controller.ts+++ b/src/modules/infra/infra-config.controller.ts@@ -480,9 +480,10 @@ export class InfraConfigController {// data/.env.generated carries POSTGRES_BUILTIN=false, so a bare compose-profile restart would// otherwise tear down the very backend the app is running on. The dashboard fills this list from the// live /infra/status at save time: the builtIn services minus the new profiles, plus a running container- // OpenWA created whose host the environment pins elsewhere, less any the saved config read back still- // reaches. A container is left running when that status read had failed, or when the next boot still- // dials it (dropped above).+ // OpenWA created whose host the environment pins elsewhere, less any whose next-boot host (the pinned one,+ // else the saved config read back) still reaches it, and less any whose host it could not read. A+ // container is left running when that status read had failed, or when the next boot still dials it+ // (dropped above).// Only ever tear down OpenWA-managed services. An arbitrary profile name (or the empty string)// would otherwise reach stopManagedService and, via container-name matching, could stop an unrelated// container — so constrain teardown to the managed allowlist and drop anything else.