From 7dc92aed56b51803e885a0b9268a00e9a6925d70 Mon Sep 17 00:00:00 2001 From: Dan Webb Date: Sun, 16 Aug 2026 20:59:53 +0100 Subject: [PATCH 1/4] ci: migrate tests to Policyfile --- .github/copilot-instructions.md | 10 +++++----- .github/workflows/copilot-setup-steps.yml | 2 +- .markdownlint-cli2.yaml | 2 ++ Berksfile | 9 --------- Policyfile.rb | 15 +++++++++++++++ README.md | 2 +- documentation/powershell_dsc.md | 4 ++-- documentation/powershell_lcm.md | 4 ++-- documentation/powershell_winrm.md | 4 ++-- documentation/powershell_wmf.md | 4 ++-- kitchen.exec.yml | 8 +++----- kitchen.yml | 8 +++----- spec/spec_helper.rb | 2 +- 13 files changed, 39 insertions(+), 35 deletions(-) delete mode 100644 Berksfile create mode 100644 Policyfile.rb diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 3cab8b4..d50c484 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -18,16 +18,16 @@ Windows Server 2019 (check `metadata.rb`, `kitchen.yml`, and `.github/workflows/ - `libraries/` - Library helpers to assist with the cookbook. May contain multiple files depending on complexity of the cookbook. - `templates/` - ERB templates that may be used in the cookbook - `files/` - files that may be used in the cookbook -- `metadata.rb`, `Berksfile` - Cookbook metadata and dependencies +- `metadata.rb`, `Policyfile.rb` - Cookbook metadata and test dependencies ## Build and Test System ### Environment Setup -**MANDATORY:** Install Chef Workstation first - provides chef, berks, cookstyle, kitchen tools. +**MANDATORY:** Install Chef Workstation first - provides chef, cookstyle, and kitchen tools. ### Essential Commands (strict order) ```bash -berks install # Install dependencies (always first) +chef install Policyfile.rb # Install dependencies (always first) cookstyle # Ruby/Chef linting yamllint . # YAML linting markdownlint-cli2 '**/*.md' # Markdown linting @@ -42,7 +42,7 @@ chef exec rspec # Unit tests (ChefSpec) - **License:** Set `CHEF_LICENSE=accept-no-persist` ### Common Issues and Solutions -- **Always run `berks install` first** - most failures are dependency-related +- **Always run `chef install Policyfile.rb` first** - most failures are dependency-related - **Chef Workstation required** - no workarounds, no alternatives - **Windows Vagrant provider availability matters** for local kitchen runs @@ -87,7 +87,7 @@ These instructions are validated for Sous Chefs cookbooks. **Do not search for b **Error Resolution Checklist:** 1. Verify Chef Workstation installation -2. Confirm `berks install` completed successfully +2. Confirm `chef install Policyfile.rb` completed successfully 3. Ensure the local Windows Vagrant provider can boot and expose WinRM before blaming cookbook code 4. Check for missing test data dependencies diff --git a/.github/workflows/copilot-setup-steps.yml b/.github/workflows/copilot-setup-steps.yml index d931cfe..78f0971 100644 --- a/.github/workflows/copilot-setup-steps.yml +++ b/.github/workflows/copilot-setup-steps.yml @@ -21,4 +21,4 @@ jobs: - name: Install Cinc Workstation uses: sous-chefs/.github/.github/actions/install-workstation@9.0.0 - name: Install cookbooks - run: berks install + run: chef install Policyfile.rb diff --git a/.markdownlint-cli2.yaml b/.markdownlint-cli2.yaml index ac5076b..baa5307 100644 --- a/.markdownlint-cli2.yaml +++ b/.markdownlint-cli2.yaml @@ -3,6 +3,8 @@ config: line-length: false # MD013 no-duplicate-heading: false # MD024 reference-links-images: false # MD052 + table-column-style: + style: compact # MD060 no-multiple-blanks: maximum: 2 ignores: diff --git a/Berksfile b/Berksfile deleted file mode 100644 index 4c37302..0000000 --- a/Berksfile +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -source 'https://supermarket.chef.io' - -metadata - -group :integration do - cookbook 'test', path: 'test/cookbooks/test' -end diff --git a/Policyfile.rb b/Policyfile.rb new file mode 100644 index 0000000..21d7f6d --- /dev/null +++ b/Policyfile.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +name 'powershell' + +run_list 'test::default' + +cookbook 'ms_dotnet', git: 'https://github.com/criteo-cookbooks/ms_dotnet.git', branch: 'master' +cookbook 'powershell', path: '.' +cookbook 'test', path: './test/cookbooks/test' + +Dir.children('./test/cookbooks/test/recipes').grep(/\.rb\z/).sort.each do |recipe| + recipe_name = File.basename(recipe, '.rb') + + named_run_list recipe_name.to_sym, "test::#{recipe_name}" +end diff --git a/README.md b/README.md index b97ac7c..31265de 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ end Local Vagrant runs use `kitchen.yml`. CI uses the exec driver with `kitchen.exec.yml`. ```shell -berks install +chef install Policyfile.rb cookstyle chef exec rspec --format documentation kitchen test default-windows-2019 --destroy=always diff --git a/documentation/powershell_dsc.md b/documentation/powershell_dsc.md index ef52aef..e17efbb 100644 --- a/documentation/powershell_dsc.md +++ b/documentation/powershell_dsc.md @@ -5,13 +5,13 @@ Installs the PowerShell prerequisites required for Desired State Configuration. ## Actions | Action | Description | -|--------|-------------| +| -------- | ------------- | | `:create` | Installs WMF 4.0 prerequisites and configures WinRM (default) | ## Properties | Property | Type | Default | Description | -|----------|------|---------|-------------| +| ---------- | ------ | --------- | ------------- | | `name` | String | name property | Resource name | | `enable_https_transport` | Boolean | `false` | Whether WinRM should expose an HTTPS listener | | `thumbprint` | String | `''` | Certificate thumbprint used for HTTPS transport | diff --git a/documentation/powershell_lcm.md b/documentation/powershell_lcm.md index 363b7a5..2db36a8 100644 --- a/documentation/powershell_lcm.md +++ b/documentation/powershell_lcm.md @@ -5,14 +5,14 @@ Configures the Windows Local Configuration Manager for Desired State Configurati ## Actions | Action | Description | -|--------|-------------| +| -------- | ------------- | | `:enable` | Generates and applies an LCM configuration (default) | | `:disable` | Disables LCM refresh mode | ## Properties | Property | Type | Default | Description | -|----------|------|---------|-------------| +| ---------- | ------ | --------- | ------------- | | `name` | String | name property | Resource name | | `temp_dir` | String | cached path | Temporary directory used for generated MOF files | | `config_mode` | String | `'ApplyOnly'` | LCM configuration mode | diff --git a/documentation/powershell_winrm.md b/documentation/powershell_winrm.md index 6e73e66..2d43c24 100644 --- a/documentation/powershell_winrm.md +++ b/documentation/powershell_winrm.md @@ -5,13 +5,13 @@ Configures WinRM for DSC and remote PowerShell usage. ## Actions | Action | Description | -|--------|-------------| +| -------- | ------------- | | `:create` | Enables WinRM and optionally creates an HTTPS listener (default) | ## Properties | Property | Type | Default | Description | -|----------|------|---------|-------------| +| ---------- | ------ | --------- | ------------- | | `name` | String | name property | Resource name | | `enable_https_transport` | Boolean | `false` | Whether to create an HTTPS listener | | `thumbprint` | String | `''` | Certificate thumbprint used for HTTPS transport | diff --git a/documentation/powershell_wmf.md b/documentation/powershell_wmf.md index 87839f0..2ef38f5 100644 --- a/documentation/powershell_wmf.md +++ b/documentation/powershell_wmf.md @@ -5,13 +5,13 @@ Installs a legacy Windows Management Framework release when the target platform ## Actions | Action | Description | -|--------|-------------| +| -------- | ------------- | | `:install` | Installs the requested WMF release (default) | ## Properties | Property | Type | Default | Description | -|----------|------|---------|-------------| +| ---------- | ------ | --------- | ------------- | | `version` | String | name property | WMF version to install (`2.0`, `3.0`, `4.0`, `5.1`) | | `download_url` | String | computed | Override the Microsoft package URL | | `checksum` | String | computed | Override the Microsoft package checksum | diff --git a/kitchen.exec.yml b/kitchen.exec.yml index 01511e2..d28efe7 100644 --- a/kitchen.exec.yml +++ b/kitchen.exec.yml @@ -15,6 +15,7 @@ provisioner: deprecations_as_errors: true enforce_idempotency: true multiple_converge: 2 + policyfile: Policyfile.rb verifier: name: inspec @@ -22,10 +23,6 @@ verifier: platforms: - name: windows-2019 -x-run_lists: - default: &default_run_list - - recipe[test::default] - x-verifiers: default: &default_verifier inspec_tests: @@ -33,5 +30,6 @@ x-verifiers: suites: - name: default - run_list: *default_run_list + provisioner: + named_run_list: default verifier: *default_verifier diff --git a/kitchen.yml b/kitchen.yml index fe9deb3..4581493 100644 --- a/kitchen.yml +++ b/kitchen.yml @@ -22,6 +22,7 @@ provisioner: enforce_idempotency: true multiple_converge: 2 deprecations_as_errors: true + policyfile: Policyfile.rb verifier: name: inspec @@ -31,10 +32,6 @@ platforms: driver: box: tas50/windows_2019 -x-run_lists: - default: &default_run_list - - recipe[test::default] - x-verifiers: default: &default_verifier inspec_tests: @@ -42,5 +39,6 @@ x-verifiers: suites: - name: default - run_list: *default_run_list + provisioner: + named_run_list: default verifier: *default_verifier diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 323ee1d..f6da6e9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'chefspec' -require 'chefspec/berkshelf' +require 'chefspec/policyfile' Dir[File.join(__dir__, '..', 'libraries', '*.rb')].sort.each { |f| require File.expand_path(f) } From eb7d5f436ce47cad04e264f7cf1639c7538109a8 Mon Sep 17 00:00:00 2001 From: Dan Webb Date: Sun, 16 Aug 2026 21:06:18 +0100 Subject: [PATCH 2/4] ci: install rake for Windows RSpec --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 196ca0b..decb673 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,6 +12,7 @@ jobs: uses: sous-chefs/.github/.github/workflows/lint-unit.yml@9.0.0 with: platform: windows-latest + gems: rake permissions: actions: write checks: write From 128e187b1b9749e7627c733f75e8eb914ed60d35 Mon Sep 17 00:00:00 2001 From: Dan Webb Date: Sun, 16 Aug 2026 22:12:10 +0100 Subject: [PATCH 3/4] test: bound PowerShell version check --- test/integration/default/controls/default_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/default/controls/default_spec.rb b/test/integration/default/controls/default_spec.rb index 399ef3f..486e86b 100644 --- a/test/integration/default/controls/default_spec.rb +++ b/test/integration/default/controls/default_spec.rb @@ -4,7 +4,7 @@ impact 1.0 title 'PowerShell 5.1 or newer is available' - describe powershell('(Get-Host).Version.ToString()') do + describe command('powershell.exe -NoLogo -NoProfile -NonInteractive -Command "$PSVersionTable.PSVersion.ToString()"', timeout: 30) do its('stdout') { should match(/^5\.1/) } end end From 2e77209712f6796bbdeac611d59da18f5ef7ec13 Mon Sep 17 00:00:00 2001 From: Dan Webb Date: Sun, 16 Aug 2026 22:34:21 +0100 Subject: [PATCH 4/4] ci: avoid hung Windows InSpec verifier --- kitchen.exec.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/kitchen.exec.yml b/kitchen.exec.yml index d28efe7..233e586 100644 --- a/kitchen.exec.yml +++ b/kitchen.exec.yml @@ -18,18 +18,17 @@ provisioner: policyfile: Policyfile.rb verifier: - name: inspec + name: shell + command: >- + powershell.exe -NoLogo -NoProfile -NonInteractive + -Command "$version = $PSVersionTable.PSVersion; Write-Output $version; if ($version -lt [version]'5.1') { exit 1 }" + shellout_opts: + timeout: 30 platforms: - name: windows-2019 -x-verifiers: - default: &default_verifier - inspec_tests: - - path: test/integration/default - suites: - name: default provisioner: named_run_list: default - verifier: *default_verifier