Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): show restart service failures when readiness times out
Yudhi Armyndharisab1b0ab3cfbd
diff --git a/dashboard/src/pages/Infrastructure.test.ts b/dashboard/src/pages/Infrastructure.test.tsindex f41acb12a..09e8f7c50 100644--- a/dashboard/src/pages/Infrastructure.test.ts+++ b/dashboard/src/pages/Infrastructure.test.ts@@ -88,6 +88,7 @@ let overrides: {statusFails?: boolean;currentEngine?: { engineType: string };restart?: () => Response;+ readyFails?: boolean;} = {};// ENGINE_TYPE supplied by the container environment, so the dashboard cannot change it.@@ -172,6 +173,7 @@ function installFetchStub(): void {);}if (method === 'GET' && path === '/api/health/ready') {+ if (overrides.readyFails) return Promise.resolve(jsonResponse({ status: 'error', details: {} }, 503));return Promise.resolve(jsonResponse({ status: 'ok', details: {} }));}if (method === 'GET' && path === '/api/infra/export-data') {@@ -750,3 +752,40 @@ test(}},);++test(+ 'services that failed to start stay on screen when the server never becomes ready',+ { timeout: 15_000 },+ async () => {+ const { screen, fireEvent, within } = rtl;+ const failure = 'Failed to start postgres: image pull failed';+ overrides = {+ readyFails: true,+ restart: () =>+ jsonResponse({+ message: 'restarting',+ restarting: true,+ profiles: ['postgres'],+ profilesToRemove: [],+ estimatedTime: 5,+ orchestration: { success: false, message: 'Some services failed', errors: [failure] },+ }),+ };+ renderInfrastructure();+ await screen.findByText('Database Configuration');+ fireEvent.click(screen.getByRole('button', { name: 'Save Configuration' }));+ const dialog = await screen.findByRole('dialog');+ // The readiness poll gives up after a minute of 1s retries; shorten only those waits. Every+ // lookup below passes its own timeout, since the default 1s one would be shortened too.+ const realSetTimeout = globalThis.setTimeout;+ globalThis.setTimeout = ((fn: () => void, ms?: number, ...rest: unknown[]) =>+ realSetTimeout(fn, ms === 1000 || ms === 3000 ? 1 : ms, ...rest)) as typeof setTimeout;+ try {+ fireEvent.click(within(dialog).getByRole('button', { name: 'Restart Now' }));+ await within(dialog).findByText('Restart failed', {}, { timeout: 5_000 });+ } finally {+ globalThis.setTimeout = realSetTimeout;+ }+ assert.ok(within(dialog).getByText(failure), 'the failure that explains the restart is not shown');+ },+);diff --git a/dashboard/src/pages/Infrastructure.tsx b/dashboard/src/pages/Infrastructure.tsxindex 916338f6c..5a82388b2 100644--- a/dashboard/src/pages/Infrastructure.tsx+++ b/dashboard/src/pages/Infrastructure.tsx@@ -197,6 +197,19 @@ export function Infrastructure() {) : null;};+ // Built-in services the restart failed to start or stop. Shown whether or not the server came back:+ // a service that failed to start is the likeliest reason it did not.+ const restartWarningBox = restartFlow.restartWarnings.length > 0 && (+ <div className="migration-warning" role="alert">+ <AlertTriangle size={18} />+ <div>+ {restartFlow.restartWarnings.map((warning, index) => (+ <p key={index}>{warning}</p>+ ))}+ </div>+ </div>+ );+return (<div className="infrastructure-page"><PageHeader title={t('infrastructure.title')} subtitle={t('infrastructure.subtitle')} />@@ -880,14 +893,7 @@ export function Infrastructure() {<p className="restart-success-msg">{t('infrastructure.restart.successMsg')}</p>) : (<>- <div className="migration-warning" role="alert">- <AlertTriangle size={18} />- <div>- {restartFlow.restartWarnings.map((warning, index) => (- <p key={index}>{warning}</p>- ))}- </div>- </div>+ {restartWarningBox}<button className="btn-primary" onClick={() => window.location.reload()}>{t('infrastructure.restart.reload')}</button>@@ -899,6 +905,7 @@ export function Infrastructure() {{restartFlow.restartStatus === 'error' && (<><p className="restart-error-msg">{restartFlow.restartError ?? t('infrastructure.restart.errorMsg')}</p>+ {restartWarningBox}<button className="btn-primary" onClick={() => window.location.reload()}>{t('infrastructure.restart.reload')}</button>