feat: add install-release package count support#2342
Conversation
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 199 |
| Duplication | 5 |
AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.
TIP This summary will be updated as you push new changes.
There was a problem hiding this comment.
Pull Request Overview
This pull request introduces detection support for the 'install-release' package manager on Linux systems by parsing its JSON state file. While the implementation follows the existing pattern and Codacy reports it is 'up to standards', there is a significant increase in cyclomatic complexity in src/detection/packages/packages_linux.c (delta 130) and src/modules/packages/packages.c (delta 69). These complex paths are currently uncovered by tests. Before merging, it is critical to ensure that the new JSON parsing logic is robust against malformed files and that the bitmask used for the new package manager flag does not collide with existing ones.
About this PR
- The changes in
packages_linux.candpackages.chave introduced high complexity (130 and 69 respectively). Without unit tests for the new parsing logic, the risk of regression or runtime failure in the presence of malformed JSON is high.
Test suggestions
- Verify 'install-release' packages are correctly counted when state.json contains multiple package entries.
- Ensure the application handles a missing state.json file without crashing or reporting errors.
- Verify that the 'install-release' package count is correctly excluded when the FF_PACKAGES_FLAG_INSTALLRELEASE_BIT flag is toggled off.
- Add unit tests for the JSON parsing logic in
src/detection/packages/packages_linux.cto cover complex conditional branches. - Validate output formatting and JSON serialization for the new package type in
src/modules/packages/packages.c.
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. Verify 'install-release' packages are correctly counted when state.json contains multiple package entries.
2. Ensure the application handles a missing state.json file without crashing or reporting errors.
3. Verify that the 'install-release' package count is correctly excluded when the FF_PACKAGES_FLAG_INSTALLRELEASE_BIT flag is toggled off.
4. Add unit tests for the JSON parsing logic in `src/detection/packages/packages_linux.c` to cover complex conditional branches.
5. Validate output formatting and JSON serialization for the new package type in `src/modules/packages/packages.c`.
Low confidence findings
- Please verify that the bit index '1ULL << 35' used for FF_PACKAGES_FLAG_INSTALLRELEASE_BIT is not already allocated to another package manager flag in 'option.h'.
TIP Improve review quality by adding custom instructions
TIP How was this review? Give us feedback
There was a problem hiding this comment.
Pull Request Overview
This PR adds 'install-release' package manager support by parsing its JSON state file. While the core functionality is present, the implementation introduces significant complexity to packages_linux.c (+130 delta) and contains logical inconsistencies. Notably, the PR description labels 'install-release' as a cross-platform manager, yet the detection logic is implemented exclusively for Linux.
There are specific bugs in path resolution and package count accumulation that should be addressed during a refactor. Additionally, no test cases were provided to verify the JSON parsing or handle potential file system edge cases. These structural and testing gaps should be addressed before merging to ensure maintainability and reliability across platforms.
About this PR
- No new test cases were added to verify the JSON parsing logic or file path construction. Given the reliance on external state files and JSON parsing, unit tests are necessary to ensure robustness against malformed or missing configuration files.
- The PR description mentions 'install-release' is a cross-platform binary package manager, but the implementation is restricted to 'packages_linux.c'. If this package manager is intended to support other platforms (e.g., macOS or Windows), detection logic is currently missing for those environments.
Test suggestions
- Verify package count is correctly parsed from a valid JSON object in state.json
- Verify no packages are reported if state.json is missing or inaccessible
- Verify the detector handles malformed JSON or a non-object root in state.json gracefully
- Verify 'install-release' detection is skipped when the corresponding bit flag is disabled
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. Verify package count is correctly parsed from a valid JSON object in state.json
2. Verify no packages are reported if state.json is missing or inaccessible
3. Verify the detector handles malformed JSON or a non-object root in state.json gracefully
4. Verify 'install-release' detection is skipped when the corresponding bit flag is disabled
TIP Improve review quality by adding custom instructions
TIP How was this review? Give us feedback
| if (!(options->disabled & FF_PACKAGES_FLAG_INSTALLRELEASE_BIT)) { | ||
| FF_STRBUF_AUTO_DESTROY path = ffStrbufCreateCopy(&baseDir); | ||
| ffStrbufAppendS(&path, ".config/install_release/state.json"); | ||
| if (ffPathExists(path.chars, FF_PATHTYPE_FILE)) { | ||
| yyjson_doc* doc = yyjson_read_file(path.chars, YYJSON_READ_NOFLAG, NULL, NULL); | ||
| if (doc != NULL) { | ||
| yyjson_val* root = yyjson_doc_get_root(doc); | ||
| if (yyjson_is_obj(root)) { | ||
| result->installrelease = (uint32_t) yyjson_obj_size(root); | ||
| } | ||
| yyjson_doc_free(doc); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
🟡 MEDIUM RISK
Suggestion: The logic for detecting 'install-release' packages should be extracted into a separate static helper function, such as getInstallReleasePackages(FFstrbuf* baseDir), to manage the high complexity delta (+130) and follow the file's existing pattern. Within this logic, please address two issues:
- Add a leading slash to the path to ensure valid absolute path formation:
ffStrbufAppendS(&path, "/.config/install_release/state.json"); - Use
+=to accumulate the package count rather than=to maintain consistency with other package manager detectors and prevent overwriting results.
| { "Total number of all hpkg packages", "hpkg-all" }, | ||
| { "Number of hpkg-system packages", "hpkg-system" }, | ||
| { "Number of hpkg-user packages", "hpkg-user" }, | ||
| { "Number of install-release packages", "install-release"}, |
There was a problem hiding this comment.
⚪ LOW RISK
Nitpick: Add a space before the closing brace for consistency with surrounding entries.
| { "Number of install-release packages", "install-release"}, | |
| { "Number of install-release packages", "install-release" }, |
| ffStrbufAppendS(baseDir, "/etc/pacman.conf"); | ||
|
|
||
| bool confFound = ffParsePropFileValues(baseDir->chars, 2, (FFpropquery[]) { | ||
| bool confFound = ffParsePropFileValues(baseDir->chars, 2, (FFpropquery[]){ |
There was a problem hiding this comment.
⚪ LOW RISK
Nitpick: This formatting change (removing a space before the curly brace) is out of scope for the current feature and should be moved to a separate cleanup PR to keep this diff focused.
Summary
Adds detection support for install-release, a cross-platform binary package manager that stores installed packages as keys in
$HOME/.config/install_release/state.json.Related issue
Closes #2306
Changes
packages.h— addeduint32_t installreleasetoFFPackagesResultoption.h— addedFF_PACKAGES_FLAG_INSTALLRELEASE_BIT = 1ULL << 35packages_linux.c— reads$HOME/.config/install_release/state.jsonvia yyjson, counts object keyspackages.c— added print, JSON output, flag test, count aggregation, and docs table entryChecklist