Repository navigation
Conversation
|
Thanks for submitting a PR! Maybe @larsewi can review this? |
larsewi
left a comment
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
| assert_true(call_with_captured_stdout(&DiffPkgOperations, output, sizeof(output))); | ||
|
|
||
| const char *msg = "Package 'foo' would be installed"; | ||
| const char *first = strstr(output, msg); |
There was a problem hiding this comment.
Could you replace the strstr() function calls with StringContains from string_lib.h?
d5052b7 to
fdad2cd
Compare
|
Added unit tests for all requested cases in
|
|
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:
***@***.***>
|
…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> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
94b2157 to
ab0408f
Compare
|
Squashed and rebased onto master. |
|
@cf-bottom Jenkins please :) |
|
Alright, I triggered a build: Jenkins: https://ci.cfengine.com/job/pr-pipeline/15079/ Packages: http://buildcache.cfengine.com/packages/testing-pr/jenkins-pr-pipeline-15079/ |
|
Backport to 3.27.x failed, manual backport needed: https://github.com/cfengine/core/actions/runs/43192126799 |
|
Backport to 3.24.x failed, manual backport needed: https://github.com/cfengine/core/actions/runs/43192126799 |
--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