Protect against uncheck race condition

This commit is contained in:
Jack Kingsman
2026-03-23 18:27:42 -07:00
parent 7c988ae3d0
commit 36eeeae64d
2 changed files with 28 additions and 1 deletions

View File

@@ -55,6 +55,12 @@ export function SecurityWarningModal({ health }: SecurityWarningModalProps) {
}
}, [shouldWarn]);
useEffect(() => {
if (health?.bots_disabled !== true) {
setBotsDisabledLocally(false);
}
}, [health?.bots_disabled, health?.bots_disabled_source]);
if (!shouldWarn) {
return null;
}

View File

@@ -1,4 +1,4 @@
import { render, screen } from '@testing-library/react';
import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { beforeEach, describe, expect, it, vi } from 'vitest';
@@ -95,4 +95,25 @@ describe('SecurityWarningModal', () => {
expect(mocks.toast.success).toHaveBeenCalledWith('Bots disabled until restart');
expect(screen.queryByText('Unprotected bot execution is enabled')).not.toBeInTheDocument();
});
it('shows the warning again after temporary bot disable disappears on a later health update', async () => {
const user = userEvent.setup();
const { rerender } = render(<SecurityWarningModal health={baseHealth} />);
await user.click(screen.getByRole('button', { name: 'Disable Bots Until Server Restart' }));
expect(screen.queryByText('Unprotected bot execution is enabled')).not.toBeInTheDocument();
rerender(
<SecurityWarningModal
health={{ ...baseHealth, bots_disabled: true, bots_disabled_source: 'until_restart' }}
/>
);
expect(screen.queryByText('Unprotected bot execution is enabled')).not.toBeInTheDocument();
rerender(<SecurityWarningModal health={baseHealth} />);
await waitFor(() => {
expect(screen.getByText('Unprotected bot execution is enabled')).toBeInTheDocument();
});
});
});