mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-01 08:13:37 +00:00
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:
@@ -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=You’ve 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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user