atom-community / atom-community/sync-settings
Project-specific settings cause diff view to show wrong value
- Dominant language
- JavaScript
- Stars
- 1.1k
- Forks
- 99
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
Project-specific settings are a feature provided by both the [project-config](https://github.com/steelbrain/project-config) and [atomic-management](https://github.com/harmsk/atomic-management) packages. They do this not through monkeypatching or any similar trick, but via APIs that have been in Atom [since this PR landed](https://github.com/atom/atom/pull/16845) three years ago. (Other packages may use these APIs as well, but these are the ones I know of.) My point is that _this isn’t just a problem caused by a rogue package_; it could just as easily be triggered by a user with a clever init-file.
The effect of these APIs is that sync-settings can’t necessarily trust `atom.config.get` to return settings as they exist in the user’s `config.cson` file. Any such setting may be modulated through a project’s own specific config overrides — which sync-settings can safely ignore, since those settings come with their own synchronization mechanism.
It turns out that sync-settings largely does the right thing here by checking `atom.config.settings` directly when deciding if settings have changed — but [it still calls `atom.config.get` when building the diff view](https://github.com/atom-community/sync-settings/blob/master/lib/utils/utils.js#L358-L380) _if_ those settings have changed. So in the case where you change a setting in your `config.cson` but your local project window has overridden that setting, the diff view will retrieve that project’s value instead of the right one. This further means that the diff view can show different results based on which window you run “View Diff” from.
I haven’t gone so far as to try to backup from a view that’s doing the wrong thing — I don’t know if the wrong value is sync’d.
**To Reproduce**
Steps to reproduce the behavior:
1. Install [project-config](https://github.com/steelbrain/project-config).
2. Create an `.atom/config.json` file that overrides a setting in your `config.cson`. I’ll use this one as an example — assume the setting is `7` in both your `config.cson` and the remote backup:
```json
{
"zentabs": { "maximumOpenedTabs": 8 }
}
```
3. Reload the window for that project.
4. Open your `config.cson` and change the value to something completely new, like `9`.
5. Run the “Sync Settings: View Diff” command.
6. You’ll see `zentabs.maximumOpenedTabs: 8` as the local value.
**Expected behavior**
You ought to see `zentabs.maximumOpenedTabs: 9`.
**Versions**
- OS: macOS 11.6.3
- Atom: 1.59.0
- APM: 2.6.2
**Additional context**
As far as I can tell, the fix here is simply never to call `atom.config.get` directly, and instead to use a utility function that behaves like [Lodash’s `get` method](https://lodash.com/docs/4.17.15#get) but retrieves keys directly from `atom.config.settings`.
Contributor guide
Research direction
Start in lib/utils/utils.js around lines 358-380, where the diff view retrieves changed settings, and compare the project-config reproduction with the direct settings data described in the issue. Run the reproduction steps using project-config and verify that View Diff shows the config.cson value, 9, rather than the project override, 8.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100