Repository navigation
Conversation
|
Thanks for submitting a PR! Maybe @larsewi can review this? |
larsewi
requested changes
Nov 3, 2026
larsewi
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the contribution 🚀 Could you also add tests for:
- Two unversioned, reported once
- An unversioned record never replaces an existing one
- A versioned record replaces a unversioned one
- First is higher version, keep first
- Last is higher version, keep last
- Same version, reported once
| } | ||
|
|
||
| return msg; | ||
| } |
Contributor
There was a problem hiding this comment.
Maybe you could break this up a bit so that it is easier to read for a human? E.g.:
Suggested change
| } | |
| static bool PkgRecordShouldBeReplaced(const PkgOperationRecord *prev_record, | |
| const char *new_ver) | |
| { | |
| if (prev_record == NULL) | |
| { | |
| /* Nothing recorded yet */ | |
| return true; | |
| } | |
| if (NULL_OR_EMPTY(new_ver)) | |
| { | |
| /* An unversioned record never replaces an existing one */ | |
| return false; | |
| } | |
| if (NULL_OR_EMPTY(prev_record->pkg_ver)) | |
| { | |
| /* A versioned record is more specific than an unversioned one */ | |
| return true; | |
| } | |
| /* Both are versioned, keep the higher version */ | |
| return PkgVersionIsGreater(new_ver, prev_record->pkg_ver); | |
| } |
Then use this function as the if condition.
| assert_true(call_with_captured_stdout(&DiffPkgOperations, output, sizeof(output))); | ||
|
|
||
| const char *msg = "Package 'foo' would be installed"; | ||
| const char *first = strstr(output, msg); |
Contributor
There was a problem hiding this comment.
Could you replace the strstr() function calls with StringContains from string_lib.h?
…talls DiffPkgOperations() compared the versions of two recorded installations of the same package without checking that both were set, which PkgVersionIsGreater() asserts. The diff report now keeps the record the way the manifest report does: a versioned record over an unversioned one, otherwise the higher version, otherwise the first one recorded. Ticket: none Changelog: Title Signed-off-by: Daniel JB Clark <djbclark@gmail.com> Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
djbclark
force-pushed
the
fix/simulate-pkg-unversioned-install-assert
branch
from
November 3, 2026 11:23
d5052b7 to
fdad2cd
Compare
Contributor
Author
|
Added unit tests for all requested cases in
|
Contributor
Author
|
K will do thanks for the clear actionable suggestions
…On Tue, Nov 3, 2026, 5:12 AM Lars Erik Wik ***@***.***> wrote:
***@***.**** requested changes on this pull request.
Thanks for the contribution 🚀 Could you also add tests for:
- Two unversioned, reported once
- An unversioned record never replaces an existing one
- A versioned record replaces a unversioned one
- First is higher version, keep first
- Last is higher version, keep last
- Same version, reported once
------------------------------
In cf-agent/simulate_mode.c
<#6424 (comment)>:
>
Maybe you could break this up a bit so that it is easier to read for a
human? E.g.:
⬇️ Suggested change
+}
+
+static bool PkgRecordShouldBeReplaced(const PkgOperationRecord *prev_record,
+ const char *new_ver)
+{
+ if (prev_record == NULL)
+ {
+ /* Nothing recorded yet */
+ return true;
+ }
+
+ if (NULL_OR_EMPTY(new_ver))
+ {
+ /* An unversioned record never replaces an existing one */
+ return false;
+ }
+
+ if (NULL_OR_EMPTY(prev_record->pkg_ver))
+ {
+ /* A versioned record is more specific than an unversioned one */
+ return true;
+ }
+
+ /* Both are versioned, keep the higher version */
+ return PkgVersionIsGreater(new_ver, prev_record->pkg_ver);
+}
Then use this function as the if condition.
------------------------------
In tests/unit/simulate_mode_test.c
<#6424 (comment)>:
> @@ -147,6 +147,40 @@ static void test_manifest_install_cancels_removal(void)
unlink(ToChangesChroot(CHROOT_PKGS_OPS_FILE));
}
+/* Two recorded installations of the same package without a version must be
+ * reported once, not abort on comparing the empty versions. */
+static void test_diff_repeated_unversioned_install(void)
+{
+ write_pkgs_ops("i,foo,,\r\n"
+ "i,foo,,\r\n");
+
+ char output[4096];
+ assert_true(call_with_captured_stdout(&DiffPkgOperations, output, sizeof(output)));
+
+ const char *msg = "Package 'foo' would be installed";
+ const char *first = strstr(output, msg);
Could you replace the strstr() function calls with StringContains from
string_lib.h?
—
Reply to this email directly, view it on GitHub
<#6424?email_source=notifications&email_token=AABAGYAH4O25Z3BRPC5TVSD5XGVRLA5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTKNZVGAYTSOJVGQZKM4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KYZTPN52GK4S7MNWGSY3L#pullrequestreview-5750199542>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABAGYA7N7PTBKIFWE7RNZD5XGVRLAVCNFSNUABDKJSXA33TNF2G64TZHMZTKNBTGU2DQO2JONZXKZJ3GU4TGOJTHE4TONBRUF3AE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
--simulate=diffaborted an assert-enabledcf-agentwhen the same package was recorded as installed twice without a version:DiffPkgOperations()passed the two empty versions toPkgVersionIsGreater(), which asserts both non-empty.ManifestPkgOperations()already guards that comparison; the diff branch now uses the same guard and keeps the same record (versioned over unversioned, otherwise the higher version, otherwise the first). Release builds compile the assert out and already picked the same record, so nothing changes for them. Two unit tests; the first aborts on the unguarded code (library built with asserts on):Ubuntu 24.04 (
--enable-debug):make -C tests/unit check→All 76 tests passed;tests/acceptance/29_simulate_mode/as root → 4 of 4 Pass. Fork CI: djbclark#45AI-assisted. I can't vouch for the C syntax beyond a basic level, but I did look at the logic and it seemed sound.
🤖 Generated with Claude Code