Engg. Hygiene: Introduce Extension Status Asserter and use in example Test class#352
Engg. Hygiene: Introduce Extension Status Asserter and use in example Test class#352kjohn-msft wants to merge 6 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a reusable ExtStatusAsserter helper for unit tests to validate extension status/substatus output by substatus name (not array position), and updates the ConfigurePatching processor tests to use these deterministic assertions instead of brittle index-based checks.
Changes:
- Added
ExtStatusAssertertest utility to load the status file once and provide higher-level assertion helpers (substatus, errors, patch presence, metadata). - Refactored portions of
Test_ConfigurePatchingProcessorto use the new asserter rather than hard-coded substatus ordering. - Minor logging/documentation tweaks in core logic (
ConfigurePatchingProcessor,ServiceManager).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| src/core/tests/Test_ConfigurePatchingProcessor.py | Replaces index-based status-file assertions with ExtStatusAsserter calls in several tests. |
| src/core/tests/library/ExtStatusAsserter.py | New helper implementing status/substatus parsing and assertion APIs for tests. |
| src/core/src/core_logic/ServiceManager.py | Adds a short docstring to remove_service(). |
| src/core/src/core_logic/ConfigurePatchingProcessor.py | Adds log prefixes/verbose logs and introduces a cleanup helper method (currently unused). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Constants.CONFIGURE_PATCHING_SUMMARY: Constants.STATUS_SUCCESS | ||
| }) | ||
| ext_status_asserter.assert_configure_patching_patch_mode_state(Constants.AutomaticOSPatchStates.DISABLED) | ||
| ext_status_asserter.assert_configure_patching_auto_assessment_state(Constants.AutomaticOSPatchStates.DISABLED) |
| ext_status_asserter.assert_status_file_substatus(Constants.CONFIGURE_PATCHING_SUMMARY, Constants.STATUS_ERROR) | ||
| ext_status_asserter.assert_operation_summary_has_error(Constants.CONFIGURE_PATCHING_SUMMARY, Constants.TELEMETRY_NOT_COMPATIBLE_ERROR_MSG) | ||
| ext_status_asserter.assert_operation_summary_has_error(Constants.CONFIGURE_PATCHING_SUMMARY, Constants.TELEMETRY_NOT_COMPATIBLE_ERROR_MSG, 'autoAssessmentStatus') | ||
| ext_status_asserter.assert_configure_patching_auto_assessment_state(Constants.STATUS_ERROR) |
| self.assertRaises(Exception, runtime.configure_patching_processor.start_configure_patching()) | ||
|
|
||
| # restore | ||
| runtime.configure_patching_processor.auto_assess_service_manager.systemd_exists = back_up_auto_assess_service_manager |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #352 +/- ##
==========================================
+ Coverage 94.01% 94.06% +0.04%
==========================================
Files 107 109 +2
Lines 19686 19840 +154
==========================================
+ Hits 18508 18662 +154
Misses 1178 1178
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Test harness improvement to allow unit tests to deterministically check extension status.
In this PR:
- Extensible beyond this
Future changes:
All code authors can rely on this for new tests.
Existing tests may be rewritten as a new-hire exercise.
(Note: This was previously bundled into the commit history of https://github.com/Azure/LinuxPatchExtension/pull/313/changes - moved it out separately as good practice)