Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
fix: unsafe state mutation for notification test button
Kyle Mendell44613150bf64
diff --git a/frontend/src/lib/utils/form.utils.ts b/frontend/src/lib/utils/form.utils.tsindex 6c44750c0..84f14d987 100644--- a/frontend/src/lib/utils/form.utils.ts+++ b/frontend/src/lib/utils/form.utils.ts@@ -74,8 +74,8 @@ export function createForm<T extends z.ZodType<any, any>>(schema: T, initialValuconst values = Object.fromEntries(Object.entries(inputs).map(([key, input]) => {- input.value = trimValue(input.value);- return [key, input.value];+ // Trim values for submission, but don't mutate the store value in-place.+ return [key, trimValue(input.value)];})) as z.infer<T>;diff --git a/frontend/src/routes/(app)/settings/notifications/+page.svelte b/frontend/src/routes/(app)/settings/notifications/+page.svelteindex 15f764073..ad3afb547 100644--- a/frontend/src/routes/(app)/settings/notifications/+page.svelte+++ b/frontend/src/routes/(app)/settings/notifications/+page.svelte@@ -65,14 +65,8 @@containerUpdateTag: ''});- const hasUnsavedChanges = $derived.by(() => {- const formData = form.validate();- if (!formData) return false;-- const formChanged = JSON.stringify(formData) !== JSON.stringify(currentSettings);- const appriseChanged = JSON.stringify(appriseSettings) !== JSON.stringify(savedAppriseSettings);- return formChanged || appriseChanged;- });+ // IMPORTANT: don't call `form.validate()` inside a `$derived` — it updates stores and will throw+ // `state_unsafe_mutation`, which can make buttons appear unresponsive until refresh.let currentSettings = $state<FormNotificationSettings>({discordEnabled: false,discordWebhookUrl: '',@@ -379,7 +373,7 @@}async function testNotification(provider: 'discord' | 'email', testType: string = 'simple') {- if (hasUnsavedChanges) {+ if (formHasChanges) {pendingTestAction = () => executeTest(provider, testType);showUnsavedDialog = true;return;@@ -400,7 +394,7 @@}}async function testAppriseNotification() {- if (hasUnsavedChanges) {+ if (formHasChanges) {pendingTestAction = executeAppriseTest;showUnsavedDialog = true;return;diff --git a/greptile.json b/greptile.jsonindex 1df7399f8..199b11a5c 100644--- a/greptile.json+++ b/greptile.json@@ -2,7 +2,7 @@"labels": [],"comment": "**Disclaimer** Greptiles Reviews use AI, make sure to check over its work","fixWithAI": true,- "strictness": 2,+ "strictness": 1,"statusCheck": true,"commentTypes": ["syntax", "logic", "style"],"instructions": "",diff --git a/tests/spec/containers.spec.ts b/tests/spec/containers.spec.tsindex 3ac147966..b4aae88c6 100644--- a/tests/spec/containers.spec.ts+++ b/tests/spec/containers.spec.ts@@ -51,7 +51,7 @@ test.describe('Containers Page', () => {const firstRow = page.locator('tbody tr').first();await firstRow.getByRole('button', { name: 'Open menu' }).click();- await page.getByRole('menuitem', { name: 'Inspect' }).click();+ await page.getByRole('menuitem', { name: 'Inspect', exact: true }).click();await expect(page).toHaveURL(/\/containers\/.+/);await expect(page.getByRole('heading', { name: 'Container Details', level: 2 }).first()).toBeVisible();@@ -66,8 +66,8 @@ test.describe('Containers Page', () => {if (running) {const row = page.locator(`tr:has(a[href="/containers/${running.id}"])`);await row.getByRole('button', { name: 'Open menu' }).click();- await expect(page.getByRole('menuitem', { name: 'Restart' })).toBeVisible();- await expect(page.getByRole('menuitem', { name: 'Stop' })).toBeVisible();+ await expect(page.getByRole('menuitem', { name: 'Restart', exact: true })).toBeVisible();+ await expect(page.getByRole('menuitem', { name: 'Stop', exact: true })).toBeVisible();await page.keyboard.press('Escape');} else {test.info().annotations.push({ type: 'note', description: 'No running container to validate actions' });@@ -76,7 +76,7 @@ test.describe('Containers Page', () => {if (stopped) {const row = page.locator(`tr:has(a[href="/containers/${stopped.id}"])`);await row.getByRole('button', { name: 'Open menu' }).click();- await expect(page.getByRole('menuitem', { name: 'Start' })).toBeVisible();+ await expect(page.getByRole('menuitem', { name: 'Start', exact: true })).toBeVisible();await page.keyboard.press('Escape');} else {test.info().annotations.push({ type: 'note', description: 'No stopped container to validate actions' });@@ -91,7 +91,7 @@ test.describe('Containers Page', () => {const row = page.locator(`tr:has(a[href="/containers/${any.id}"])`);await row.getByRole('button', { name: 'Open menu' }).click();- await page.getByRole('menuitem', { name: 'Remove' }).click();+ await page.getByRole('menuitem', { name: 'Remove', exact: true }).click();const dialog = page.locator('div[role="heading"][aria-level="2"][data-dialog-title]:has-text("Confirm Container Removal")');await expect(dialog).toBeVisible();diff --git a/tests/spec/project.spec.ts b/tests/spec/project.spec.tsindex f6d4dff1f..a2431cec8 100644--- a/tests/spec/project.spec.ts+++ b/tests/spec/project.spec.ts@@ -130,6 +130,28 @@ test.describe('New Compose Project Page', () => {await page.getByRole('textbox', { name: 'My New Project' }).press('Enter');});+ test('should enable Create Project after entering a valid name', async ({ page }) => {+ const observedErrors: string[] = [];+ page.on('pageerror', (err) => observedErrors.push(String(err?.message ?? err)));+ page.on('console', (msg) => {+ if (msg.type() === 'error') observedErrors.push(msg.text());+ });++ const createProjectButton = page.getByRole('button', { name: 'Create Project', exact: true });+ await expect(createProjectButton).toBeVisible();++ // Open the inline name editor and set a valid name.+ await page.getByRole('button', { name: 'My New Project' }).click();+ await page.getByRole('textbox', { name: 'My New Project' }).fill('test-project');+ await page.getByRole('textbox', { name: 'My New Project' }).press('Enter');++ // The button should become enabled once name + compose content are present.+ await expect(createProjectButton).toBeEnabled();++ const stateUnsafe = observedErrors.filter((e) => e.includes('state_unsafe_mutation'));+ expect(stateUnsafe, `Unexpected state_unsafe_mutation errors: ${stateUnsafe.join('\n')}`).toHaveLength(0);+ });+test('should create a new project successfully', async ({ page }) => {const projectName = `test-project-${Date.now()}`;let createdProjectId: string | null = null;diff --git a/tests/spec/settings-notifications.spec.ts b/tests/spec/settings-notifications.spec.tsnew file mode 100644index 000000000..d71eb2785--- /dev/null+++ b/tests/spec/settings-notifications.spec.ts@@ -0,0 +1,78 @@+import { test, expect } from '@playwright/test';++test.describe('Notification settings', () => {+ test('should allow testing email notifications without state_unsafe_mutation errors', async ({ page }) => {+ const observedErrors: string[] = [];++ page.on('pageerror', (err) => {+ observedErrors.push(String(err?.message ?? err));+ });++ page.on('console', (msg) => {+ if (msg.type() === 'error') {+ observedErrors.push(msg.text());+ }+ });++ let saveEndpointCalled = false;+ let testEndpointCalled = false;++ // Stub "save settings" so we don't depend on a real backend/DB for this flow.+ await page.route('**/api/environments/*/notifications/settings', async (route) => {+ const req = route.request();+ if (req.method() === 'POST') {+ saveEndpointCalled = true;+ await route.fulfill({+ status: 200,+ contentType: 'application/json',+ body: JSON.stringify({ success: true }),+ });+ return;+ }+ await route.continue();+ });++ // Stub the test endpoint so no SMTP server is required.+ await page.route('**/api/environments/*/notifications/test/email**', async (route) => {+ testEndpointCalled = true;+ await route.fulfill({+ status: 200,+ contentType: 'application/json',+ body: JSON.stringify({ success: true }),+ });+ });++ await page.goto('/settings/notifications');+ await page.waitForLoadState('networkidle');++ // Enable email notifications (the test button only appears when enabled).+ await page.locator('#email-enabled').click();++ // Fill the minimum required fields so "Save and Test" is valid.+ await page.getByPlaceholder('smtp.example.com').fill('smtp.example.com');+ await page.getByPlaceholder('[email protected]').fill('[email protected]');++ // The dropdown trigger uses an internal button wrapper; target the trigger attribute to avoid strict-mode ambiguity.+ await page.locator('[data-dropdown-menu-trigger]').filter({ hasText: 'Test Email' }).click();+ await page.getByRole('menuitem', { name: 'Simple Test Email', exact: true }).click();++ // If we have unsaved changes, the page will prompt to save before testing.+ const saveAndTestButton = page.getByRole('button', { name: 'Save & Test', exact: true });+ const didClickSaveAndTest = await saveAndTestButton.isVisible().catch(() => false);+ if (didClickSaveAndTest) {+ await saveAndTestButton.click();+ }++ await expect.poll(() => testEndpointCalled, { timeout: 10_000 }).toBe(true);++ // If the modal path was taken, we should have attempted to save.+ // (Not strictly required for this bug, but it's a helpful sanity check.)+ if (didClickSaveAndTest) {+ await expect.poll(() => saveEndpointCalled, { timeout: 10_000 }).toBe(true);+ }++ const stateUnsafe = observedErrors.filter((e) => e.includes('state_unsafe_mutation'));+ expect(stateUnsafe, `Unexpected state_unsafe_mutation errors: ${stateUnsafe.join('\n')}`).toHaveLength(0);+ });+});