From f3e1b9a2ec87fc51a8b5f3876ed0a820ddcf3e46 Mon Sep 17 00:00:00 2001 From: Sachin Jain Date: Wed, 15 Jul 2026 17:04:23 +0530 Subject: [PATCH] Fix windows_bootstrap_context_spec flakiness on windows-2025 CI Stub ChefConfig::Config.etc_chef_dir and c_opscode_dir in the WindowsBootstrapContext spec to return deterministic path values (C:\chef and C:\opscode\chef) regardless of the platform. These class methods use ChefConfig::Config.windows_installation_drive which detects the drive letter at runtime from the gem installation path via File.expand_path(__FILE__). The memoized results persist as class-level instance variables (@etc_chef_dir) that are NOT cleared by Chef::Config.reset between tests. This caused intermittent failures on windows-2025 runners when the GitHub Actions runner image was updated (weekly cadence per https://github.com/actions/runner-images#image-releases), changing the system configuration in a way that affected path resolution. The tests passed on windows-2025 in PR #186 (run ~July 1) but began failing in PR #187 (run ~July 10) due to a runner image update in that interval. The windows-2022 runner was unaffected. Failing tests: - spec/unit/knife/core/windows_bootstrap_context_spec.rb:164 - spec/unit/knife/core/windows_bootstrap_context_spec.rb:192 - spec/unit/knife/core/windows_bootstrap_context_spec.rb:201 - spec/unit/knife/core/windows_bootstrap_context_spec.rb:212 - spec/unit/knife/core/windows_bootstrap_context_spec.rb:232 Reference: - https://github.com/chef/knife/pull/187 - https://github.com/actions/runner-images (weekly image updates) Signed-off-by: Sachin Jain --- spec/unit/knife/core/windows_bootstrap_context_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/unit/knife/core/windows_bootstrap_context_spec.rb b/spec/unit/knife/core/windows_bootstrap_context_spec.rb index afc42c95..91ec97af 100644 --- a/spec/unit/knife/core/windows_bootstrap_context_spec.rb +++ b/spec/unit/knife/core/windows_bootstrap_context_spec.rb @@ -23,6 +23,14 @@ let(:chef_config) { Chef::Config.save } # "dup" to a hash let(:bootstrap_context) { Chef::Knife::Core::WindowsBootstrapContext.new(config, nil, chef_config, nil) } + before do + # Stub path methods to return consistent values across all platforms. + # On actual Windows (e.g. windows-2025 CI), these methods may resolve + # to a different drive letter based on the gem installation path. + allow(ChefConfig::Config).to receive(:etc_chef_dir).with(windows: true).and_return("C:\\chef") + allow(ChefConfig::Config).to receive(:c_opscode_dir).and_return("C:\\opscode\\chef") + end + describe "fips" do context "when fips is set" do before do