-
Notifications
You must be signed in to change notification settings - Fork 754
[utils] Use Boost.JSON for AliasDict
#4566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
a538b6e to
8cdd5c3
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4566 +/- ##
==========================================
+ Coverage 87.18% 87.19% +0.01%
==========================================
Files 247 249 +2
Lines 14273 14276 +3
==========================================
+ Hits 12443 12446 +3
Misses 1830 1830 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
8cdd5c3 to
0222fd0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR migrates AliasDict from Qt's JSON library to Boost.JSON. The key changes include:
- Separating construction from file loading by introducing a static
load_filemethod - Implementing Boost.JSON serialization/deserialization using
tag_invokefunctions - Introducing a
sorted_maputility to maintain sorted key order in JSON output - Refactoring test cases to use direct JSON parsing instead of file operations where appropriate
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/client/common/alias_dict.cpp | Replaced Qt JSON serialization with Boost.JSON, refactored constructor and load logic |
| src/utils/alias_definition.cpp | Added Boost.JSON serialization functions for AliasDefinition and AliasContext |
| include/multipass/cli/alias_dict.h | Updated constructor signatures, added JSONContext struct and load_file static method |
| include/multipass/alias_definition.h | Added Boost.JSON tag_invoke function declarations |
| include/multipass/json_utils.h | Added SortJsonKeys struct for maintaining sorted JSON key order |
| include/multipass/utils/sorted_map.h | New utility for creating sorted copies of unordered maps |
| tests/test_alias_dict.cpp | Updated tests to use new constructor and direct JSON parsing |
| tests/test_json_utils.cpp | Added tests for SortJsonKeys functionality |
| tests/test_argparser.cpp | Updated to use load_file method |
| tests/fake_alias_config.h | Updated to use new constructor signature |
| src/client/cli/formatter/*.cpp | Replaced sort_dict calls with sorted_map utility |
| include/multipass/cli/formatter.h | Removed sort_dict template method |
| src/client/cli/client.cpp | Updated to use load_file method |
| src/client/cli/cmd/unalias.cpp | Removed unused Qt JSON includes |
| src/utils/CMakeLists.txt | Added alias_definition.cpp to build |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
0222fd0 to
7e4c746
Compare
sharder996
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see anything out of the ordinary here. I expect that merging in #4515 ironed out some of the details beforehand.
Otherwise, just one optionally improvement that could be done, but good for merging either way.
tests/test_alias_dict.cpp
Outdated
| " \"llp\": {\n" | ||
| " \"command\": \"ls\",\n" | ||
| " \"instance\": \"primary\",\n" | ||
| " \"command\": \"ls\",\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know its out of scope for this PR, but seeing as how we're here already, do you feel its worth it to move these string literals out into golden test files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a good idea to me. Done.
tobe2098
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good work Jim! LGTM mostly, just a couple nitpicks/questions.
Rather than copying all the elements, instead make a view holding references to each element.
b88b0e3 to
0ddd4d4
Compare
tobe2098
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just one small thing. Great work Jim!
0ddd4d4 to
895226e
Compare
| @@ -0,0 +1,4 @@ | |||
| *.csv -text | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also have a .gitattributes in the top level directory. I don't have a preference whether we maintain one project level gitattributes file or scatter them where they are need in the test data. Just that we maintain an approach. So, I'd like to either see them combined or have the other one moved to tests/test_data/formatters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I moved this to the top-level .gitattributes since that's the precedent we already established.
895226e to
5f5c3ed
Compare
sharder996
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks @jimporter
|
(Trying a second merge since I'm pretty sure the first one failed due to a runner dying. Not sure if our builds are just brittle or if it's Microsoft's infra being flaky...) |
Description
(Recreating this from #4558, since Github auto-closed that one after I merged the parent PR, and won't let me change the base branch to
main...)This changes
AliasDictto use Boost.JSON. Functionally, everything should be the same as before, but there are a few notable differences now:AliasDictconstructor used to load the data from a file; now, the constructor just initializes the data structure, and to load a file, you callAliasDict::load_file. This makes it easier to unit testAliasDictwithout having to write temp files.Testing
Manual testing steps:
./bin/multipass alias plucky-tortoise:whoami whoisplucky~/.local/share/multipass/bin/whoispluckyChecklist