Skip to content

Add WMI dependency service enforcement to agent lifecycle - #7

Merged
christaylorcodes merged 4 commits into
developfrom
feature/wmi-dependency-service
Jun 17, 2026
Merged

Add WMI dependency service enforcement to agent lifecycle#7
christaylorcodes merged 4 commits into
developfrom
feature/wmi-dependency-service

Conversation

@christaylorcodes

Copy link
Copy Markdown
Owner

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 own Get-CimInstance calls fail silently when winmgmt is disabled — so the dependency is now enforced up front.

Changes

  • New Confirm-CWAADependencyService (private) — sets each dependency service to Automatic and starts it if not running (Start-Service with sc.exe fallback), polling up to $Script:CWAAServiceWaitTimeoutSec. Honors -WhatIf; writes remediation events (IDs 2030–2039).
  • Wired into Install-CWAA, Repair-CWAA, and Start-CWAA.
  • Configurable via new $Script:CWAADependencyServiceNames in Initialize-CWAA (default winmgmt), so additional OS dependencies can be added later.
  • Test coverage across PrivateHelpers / Installation / ServiceOps / CrossCutting suites.

Drive-by fixes

  • Test-CWAAPort port-availability tests were inert. They mocked Invoke-Expression and a bare netstat function while the code calls netstat.exe by 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 into Get-CWAANetstat as a mockable seam and updated the three affected tests. This also makes the "port in use" test actually exercise that path.
  • CHANGELOG reconciliation: the released 2.0.0 was 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

christaylorcodes and others added 4 commits February 3, 2026 12:17
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>
@christaylorcodes
christaylorcodes merged commit fbf9ee8 into develop Jun 17, 2026
7 of 8 checks passed
@christaylorcodes
christaylorcodes deleted the feature/wmi-dependency-service branch June 17, 2026 22:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant