feat: enhance global settings update with data loss prevention

- Added safeguards to prevent overwriting non-empty arrays with empty arrays during global settings updates, specifically for the 'projects' field.
- Implemented logging for updates to assist in diagnosing accidental wipes of critical settings.
- Updated tests to verify that projects are preserved during logout transitions and that theme changes are ignored if a project wipe is attempted.
- Enhanced the settings synchronization logic to ensure safe handling during authentication state changes.
This commit is contained in:
webdevcody
2026-01-07 21:38:46 -05:00
parent 8c68c24716
commit d8cdb0bf7a
7 changed files with 190 additions and 13 deletions

View File

@@ -104,4 +104,36 @@ test.describe('Settings startup sync race', () => {
expect(settingsAfterHydration.projects?.length).toBeGreaterThan(0);
expect(settingsAfterHydration.projects?.[0]?.path).toBe(FIXTURE_PROJECT_PATH);
});
test('does not wipe projects during logout transition', async ({ page }) => {
// Ensure authenticated and app is loaded at least to welcome/board.
await authenticateForTests(page);
await page.goto('/');
await page
.locator('[data-testid="welcome-view"], [data-testid="board-view"]')
.first()
.waitFor({ state: 'visible', timeout: 30000 });
// Confirm settings.json currently has projects (precondition).
const beforeLogout = JSON.parse(fs.readFileSync(SETTINGS_PATH, 'utf-8')) as {
projects?: Array<unknown>;
};
expect(beforeLogout.projects?.length).toBeGreaterThan(0);
// Navigate to settings and click logout.
await page.goto('/settings');
await page.locator('[data-testid="logout-button"]').click();
// Ensure we landed on logged-out or login (either is acceptable).
await page
.locator('text=Youve been logged out, text=Authentication Required')
.first()
.waitFor({ state: 'visible', timeout: 30000 });
// The server settings file should still have projects after logout.
const afterLogout = JSON.parse(fs.readFileSync(SETTINGS_PATH, 'utf-8')) as {
projects?: Array<unknown>;
};
expect(afterLogout.projects?.length).toBeGreaterThan(0);
});
});