Add WMI dependency service enforcement to agent lifecycle - #7
Merged
Conversation
Release v1.0.0 — Major module overhaul with health checks, build pipeline, and test suite
Merge develop into main: CI fixes and local-first testing
Introduce Confirm-CWAADependencyService to ensure winmgmt (WMI) is set to Automatic startup and Running before install, repair, and service start. WMI underpins agent inventory, scripting, and check-in; when disabled, Get-CimInstance calls silently no-op. Wired into Install/Repair/Start, configurable via $Script:CWAADependencyServiceNames, respects -WhatIf. Reserves event IDs 2030-2039. Includes coverage across PrivateHelpers/Installation/ServiceOps/CrossCutting. Also fix Test-CWAAPort port-availability tests that mocked Invoke-Expression and a bare netstat function while the code called netstat.exe by full path, making the mocks inert. The tests passed only on machines with nothing on the tray port; on a box running the real agent (port 42000 in use) they returned false. Extract the external call into Get-CWAANetstat as a mockable seam and update the three affected tests to mock it. Reconcile CHANGELOG: the released 2.0.0 was mislabeled [1.0.0]; rename it and add the WMI feature under [Unreleased]. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The CrossCutting pipeline test mocked schtasks with a bare 'return $null', which does not set $LASTEXITCODE. Register-CWAAHealthCheckTask checks $LASTEXITCODE after the native /CREATE call, so the test inherited whatever exit code a prior native command left behind. It passed locally and on lucky CI runs but failed when the ambient code was non-zero (CI saw 1060). Use the same conditional mock pattern already established in the Installation tests, setting $global:LASTEXITCODE = 0 on the /CREATE branch. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ensures the OS services the Automate agent depends on (currently
winmgmt/WMI) are set to Automatic startup and Running before install, repair, and service-start operations. WMI underpins the agent's inventory, scripting, and check-in, and this module's ownGet-CimInstancecalls fail silently whenwinmgmtis disabled — so the dependency is now enforced up front.Changes
Confirm-CWAADependencyService(private) — sets each dependency service to Automatic and starts it if not running (Start-Servicewithsc.exefallback), polling up to$Script:CWAAServiceWaitTimeoutSec. Honors-WhatIf; writes remediation events (IDs 2030–2039).Install-CWAA,Repair-CWAA, andStart-CWAA.$Script:CWAADependencyServiceNamesinInitialize-CWAA(defaultwinmgmt), so additional OS dependencies can be added later.Drive-by fixes
Invoke-Expressionand a barenetstatfunction while the code callsnetstat.exeby full path, so the mocks never applied. They passed only on machines with nothing on the tray port; on a box running the real agent (port 42000 in use) they returned$false. Extracted the external call intoGet-CWAANetstatas a mockable seam and updated the three affected tests. This also makes the "port in use" test actually exercise that path.2.0.0was mislabeled[1.0.0]; renamed it and added the WMI feature under[Unreleased].Testing
./Tests/test-local.ps1— build + analyze + test all green (479 passed, 0 failed).🤖 Generated with Claude Code