refactor(studio): extract settings persistence to src/prefs.js (step 4) - #19
Conversation
_loadSettings/_saveSettings (localStorage user name + input device, via the S container) move to src/prefs.js, imported by the same names. New tests/prefs.test.mjs (in-memory localStorage stub). Move-only. node 11/11, python 25/25. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughSettings persistence logic is moved from ChangesSettings persistence extraction
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
Refactors studio settings persistence by extracting the localStorage-backed _loadSettings / _saveSettings logic into a dedicated src/prefs.js module while keeping main.js call sites unchanged, and adds targeted Node test coverage for the persistence behavior.
Changes:
- Added
src/prefs.jsto own settings load/save logic via the sharedSstate container. - Updated
src/main.jsto import_loadSettings/_saveSettingsfromsrc/prefs.jsand removed the inline implementations. - Added
tests/prefs.test.mjsand updatedCHANGELOG.mdto document the migration step.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/prefs.test.mjs | Adds unit tests for settings persistence via S using an in-memory localStorage stub. |
| src/prefs.js | New module implementing _loadSettings / _saveSettings using S and localStorage. |
| src/main.js | Switches to importing settings persistence functions from src/prefs.js. |
| CHANGELOG.md | Documents ES-module migration step 4 and the new prefs tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/prefs.test.mjs (1)
45-51: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winStrengthen "userName left as-is" assertion.
Unlike
deviceId,S.userNameisn't seeded with a stale sentinel before calling_loadSettings()(it's already''frombeforeEach), so line 50 passes trivially and doesn't actually verify the "left as-is" behavior.✅ Proposed fix
test('_loadSettings applies an empty deviceId (deviceId !== undefined) but skips missing userName', () => { store.set('slopsmith_studio', JSON.stringify({ deviceId: '' })); S.selectedDeviceId = 'stale'; + S.userName = 'stale'; _loadSettings(); assert.equal(S.selectedDeviceId, ''); // '' is applied (!== undefined) - assert.equal(S.userName, ''); // absent userName left as-is + assert.equal(S.userName, 'stale'); // absent userName left as-is });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/prefs.test.mjs` around lines 45 - 51, The _loadSettings test currently does not really verify that a missing userName is left unchanged because S.userName starts as an empty string from beforeEach, so the assertion passes trivially. Update the test in prefs.test.mjs by seeding S.userName with a non-empty stale sentinel before calling _loadSettings(), then assert it remains unchanged when userName is absent from the stored settings, alongside the existing S.selectedDeviceId check.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests/prefs.test.mjs`:
- Around line 45-51: The _loadSettings test currently does not really verify
that a missing userName is left unchanged because S.userName starts as an empty
string from beforeEach, so the assertion passes trivially. Update the test in
prefs.test.mjs by seeding S.userName with a non-empty stale sentinel before
calling _loadSettings(), then assert it remains unchanged when userName is
absent from the stored settings, alongside the existing S.selectedDeviceId
check.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 5321a1a8-e50e-4c5c-8c93-86b9caefbc51
📒 Files selected for processing (4)
CHANGELOG.mdsrc/main.jssrc/prefs.jstests/prefs.test.mjs
…rtion meaningful Address Copilot on #19: capture/restore globalThis.localStorage via an after() hook; set S.userName to a non-empty value before loading a blob without userName so the 'left as-is' assertion actually exercises the skip path. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
What
Step 4. Moves
_loadSettings/_saveSettings(localStorage-backed user name + selected input device, now reading/writing theScontainer) intosrc/prefs.js, imported by the same names.main.jsunchanged at the call sites.Move-only, no behaviour change.
Tests
New
tests/prefs.test.mjs(in-memory localStorage stub): round-trip throughS, no-op when empty, corrupt-JSON tolerance, and thedeviceId !== undefinedapply rule.node --test11/11,pytest25/25. Codex preflight: 0.Summary by CodeRabbit