Skip to content

Fix windows_bootstrap_context_spec flakiness on windows-2025 CI - #188

Merged
jaymzh merged 1 commit into
mainfrom
sanjain/fix-windows-bootstrap-context-spec-flakiness
Jul 15, 2026
Merged

Fix windows_bootstrap_context_spec flakiness on windows-2025 CI#188
jaymzh merged 1 commit into
mainfrom
sanjain/fix-windows-bootstrap-context-spec-flakiness

Conversation

@sanjain-progress

Copy link
Copy Markdown
Contributor

Summary

Fixes intermittent unit test failures in windows_bootstrap_context_spec.rb on the windows-2025 GitHub Actions runner.

Problem

The following tests fail on windows-2025 but pass on all other platforms (ubuntu, macos, windows-2022):

  • spec/unit/knife/core/windows_bootstrap_context_spec.rb:164 - config_content generates the config file data
  • spec/unit/knife/core/windows_bootstrap_context_spec.rb:192 - start_chef returns expected string with default values
  • spec/unit/knife/core/windows_bootstrap_context_spec.rb:201 - start_chef returns expected string with license_id
  • spec/unit/knife/core/windows_bootstrap_context_spec.rb:212 - start_chef exclude license key when disable_license_activation is true
  • spec/unit/knife/core/windows_bootstrap_context_spec.rb:232 - start_chef with bootstrap_url and chef-ice

Root Cause

The tests hardcode expected paths like C:\chef and C:\opscode\chef, but the source code resolves these dynamically via ChefConfig::Config.etc_chef_dir(windows: true) and ChefConfig::Config.c_opscode_dir.

These class methods use windows_installation_drive which detects the drive letter at runtime from the gem installation path (File.expand_path(__FILE__).split("/", 2)[0]). The memoized result is stored as a class-level instance variable (@etc_chef_dir) that is NOT cleared by Chef::Config.reset between tests.

When the windows-2025 runner image was updated by GitHub (they deploy weekly updates to runner images), the system configuration changed in a way that affected path resolution, causing these tests to fail.

Evidence

  • Tests passed on windows-2025 in PR #186 (run ~July 1, 2026)
  • Tests failed on windows-2025 in PR #187 (run ~July 10, 2026)
  • Neither PR modifies any test code or source code — both are dependabot bumps
  • The windows-2022 runner is unaffected in both cases
  • A runner image update occurred in the interval between the two runs

Fix

Stub ChefConfig::Config.etc_chef_dir(windows: true) and ChefConfig::Config.c_opscode_dir in a top-level before block to return deterministic values (C:\chef and C:\opscode\chef). This ensures the tests validate the logic of config generation and path construction, not the platform-specific drive letter detection.

References

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:
  - #187
  - https://github.com/actions/runner-images (weekly image updates)
Signed-off-by: Sachin Jain <Sachin.jain@chef.io>
@sanjain-progress
sanjain-progress requested review from a team and jaymzh as code owners July 15, 2026 11:36
@sanjain-progress
sanjain-progress marked this pull request as draft July 15, 2026 11:37
@sanjain-progress sanjain-progress added the ai-assisted Work completed with AI assistance following Progress AI policies label Jul 15, 2026
@sanjain-progress
sanjain-progress marked this pull request as ready for review July 15, 2026 19:04

@jaymzh jaymzh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work, thanks!

@jaymzh
jaymzh merged commit bcaeb25 into main Jul 15, 2026
48 checks passed
@jaymzh
jaymzh deleted the sanjain/fix-windows-bootstrap-context-spec-flakiness branch July 15, 2026 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-assisted Work completed with AI assistance following Progress AI policies

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants