From 341b4723beeac2572dd87d7ae8500e96326bbe75 Mon Sep 17 00:00:00 2001 From: AWRZN038 Date: Wed, 18 Mar 2026 08:50:17 +0100 Subject: [PATCH 1/5] Fix chocolatey.installed forcing reinstall chocolatey.installed compared variables which are not the same type this behaviour causes chocolatey force package reinstall even when the target version is the same as current. --- salt/states/chocolatey.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/states/chocolatey.py b/salt/states/chocolatey.py index eba3f8bb2526..131e62920519 100644 --- a/salt/states/chocolatey.py +++ b/salt/states/chocolatey.py @@ -131,7 +131,7 @@ def installed( if name.lower() == pkg.lower(): full_name = pkg - installed_version = pre_install[full_name] + installed_version = pre_install[full_name][0] if version: if salt.utils.versions.compare( From ff7a06d052dee5201cdb06f15575f26e16556a2a Mon Sep 17 00:00:00 2001 From: Foklan Date: Wed, 15 Apr 2026 12:17:00 +0200 Subject: [PATCH 2/5] Add changelog --- changelog/68827.fixed.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 changelog/68827.fixed.md diff --git a/changelog/68827.fixed.md b/changelog/68827.fixed.md new file mode 100644 index 000000000000..e69de29bb2d1 From a5a190b1d8321141575dc24d844091e83281654a Mon Sep 17 00:00:00 2001 From: Foklan Date: Wed, 15 Apr 2026 12:21:18 +0200 Subject: [PATCH 3/5] Add changelog content --- changelog/68827.fixed.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog/68827.fixed.md b/changelog/68827.fixed.md index e69de29bb2d1..f8d69a7954ce 100644 --- a/changelog/68827.fixed.md +++ b/changelog/68827.fixed.md @@ -0,0 +1 @@ +Fixed an issue in chocolatey.installed state where packages were always reinstalled. \ No newline at end of file From 4594e456706d921c8279a0a80c33ad8f8fbb77f6 Mon Sep 17 00:00:00 2001 From: Foklan <34000783+foklan@users.noreply.github.com> Date: Fri, 24 Apr 2026 23:23:29 +0200 Subject: [PATCH 4/5] Update changelog for chocolatey.installed fix --- changelog/68827.fixed.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/68827.fixed.md b/changelog/68827.fixed.md index f8d69a7954ce..791c19f8ddd8 100644 --- a/changelog/68827.fixed.md +++ b/changelog/68827.fixed.md @@ -1 +1 @@ -Fixed an issue in chocolatey.installed state where packages were always reinstalled. \ No newline at end of file +Fixed an issue in chocolatey.installed state where packages were always reinstalled. From 4ed7c0fa4d2277a2b552fd4e9980d63d7cea5be2 Mon Sep 17 00:00:00 2001 From: "Daniel A. Wozniak" Date: Sun, 7 Jun 2026 16:43:23 -0700 Subject: [PATCH 5/5] Add regression test for chocolatey.installed forcing reinstall (#68827) --- .../test_chocolatey_installed_version.py | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tests/pytests/unit/states/test_chocolatey_installed_version.py diff --git a/tests/pytests/unit/states/test_chocolatey_installed_version.py b/tests/pytests/unit/states/test_chocolatey_installed_version.py new file mode 100644 index 000000000000..dc3a00b326ce --- /dev/null +++ b/tests/pytests/unit/states/test_chocolatey_installed_version.py @@ -0,0 +1,51 @@ +""" +Regression test for chocolatey.installed forcing reinstall (#68827). + +chocolatey.list returns ``{name: [version, ...]}`` (lists per package), +so indexing the dict gave the state a list where a string was expected. +``salt.utils.versions.compare(ver1=[ver], oper="==", ver2=ver)`` then +returned False, the "matches installed version" branch never fired, +and force=True was set causing reinstall every run. +""" + +import pytest + +import salt.modules.chocolatey as chocolatey_mod +import salt.states.chocolatey as chocolatey +from tests.support.mock import MagicMock, patch + + +@pytest.fixture +def configure_loader_modules(minion_opts): + minion_opts["test"] = True + return { + chocolatey: { + "__opts__": minion_opts, + "__salt__": {}, + "__context__": {}, + }, + chocolatey_mod: { + "__opts__": minion_opts, + "__context__": {}, + }, + } + + +def test_installed_does_not_reinstall_when_version_matches(): + """ + chocolatey.installed must report "already installed" and not + trigger an install when the requested version matches what + chocolatey.list reports as installed. + """ + list_return = {"vim": ["9.0.1672"]} + install_mock = MagicMock(return_value="installed ok") + salt_dunder = { + "chocolatey.list": MagicMock(return_value=list_return), + "chocolatey.install": install_mock, + } + with patch.dict(chocolatey.__salt__, salt_dunder): + ret = chocolatey.installed(name="vim", version="9.0.1672") + assert ret["result"] is None + assert "is already installed" in ret["comment"] + assert "will be installed over" not in ret["comment"] + install_mock.assert_not_called()