fix(settings): validate git identity emails only on the request path

A stored identity email that failed the stricter rule made every settings
read fall back to defaults, and the next save persisted that reset.

- the stored preferences schema accepts any email string again
- PATCH /api/settings rejects an invalid gitIdentity or gitIdentities email
  with a field path, and saves the trimmed address
- the rule accepts local hosts such as root@localhost
This commit is contained in:
Chris Scott committed 2026-10-23 15:45:36 -04:00
1 parent d089dde466
commit 0c4c024dcc
4 files changed
+157 -17

No files matched your search

+53
View File
@@ -26,4 +26,57 @@ describe('SettingsService', () => {
expect(settings.preferences.activityWindowMinutes).toBe(DEFAULT_ACTIVITY_WINDOW_MINUTES)
expect(settings.preferences.autoScroll).toBe(false)
})
it('reads a stored git identity email that the request pattern rejects', () => {
db.prepare(
`INSERT INTO user_preferences (user_id, preferences, updated_at)
VALUES (?, ?, ?)`
).run(
'default',
JSON.stringify({ mode: 'plan', gitIdentity: { name: 'Root', email: 'root@box' } }),
Date.now()
)
const settings = settingsService.getSettings()
expect(settings.preferences.mode).toBe('plan')
expect(settings.preferences.gitIdentity).toEqual({ name: 'Root', email: 'root@box' })
})
it('keeps a stored git identity and other preferences when an unrelated field is updated', () => {
db.prepare(
`INSERT INTO user_preferences (user_id, preferences, updated_at)
VALUES (?, ?, ?)`
).run(
'default',
JSON.stringify({ mode: 'plan', gitIdentity: { name: 'Root', email: 'root@box' } }),
Date.now()
)
const settings = settingsService.updateSettings({ theme: 'light' })
expect(settings.preferences.theme).toBe('light')
expect(settings.preferences.mode).toBe('plan')
expect(settings.preferences.gitIdentity).toEqual({ name: 'Root', email: 'root@box' })
})
it('keeps a stored legacy identity email that no current pattern accepts', () => {
db.prepare(
`INSERT INTO user_preferences (user_id, preferences, updated_at)
VALUES (?, ?, ?)`
).run(
'default',
JSON.stringify({ mode: 'plan', gitIdentity: { name: 'Root', email: 'not an email' } }),
Date.now()
)
const settings = settingsService.getSettings()
const updated = settingsService.updateSettings({ autoScroll: false })
expect(settings.preferences.mode).toBe('plan')
expect(settings.preferences.gitIdentity).toEqual({ name: 'Root', email: 'not an email' })
expect(updated.preferences.autoScroll).toBe(false)
expect(updated.preferences.mode).toBe('plan')
expect(updated.preferences.gitIdentity).toEqual({ name: 'Root', email: 'not an email' })
})
})