Skip to content

Engg. Hygiene: Introduce Extension Status Asserter and use in example Test class#352

Open
kjohn-msft wants to merge 6 commits into
masterfrom
kjohn-extstatus
Open

Engg. Hygiene: Introduce Extension Status Asserter and use in example Test class#352
kjohn-msft wants to merge 6 commits into
masterfrom
kjohn-extstatus

Conversation

@kjohn-msft

Copy link
Copy Markdown
Collaborator

Test harness improvement to allow unit tests to deterministically check extension status.

In this PR:

  1. Addresses issues like widely broken tests if order of entries in the extension status output changes. Indexing is by name, not by order (so no brittle hardcoding).
  2. Has performant one-time memory load and evaluation.
  3. Assert mechanics:
  • Status validation - assert_status_file_substatus(operation, expected_status)
  • Batch status validation - assert_status_file_substatuses()
  • Patch-level validation - assert_operation_summary_has_patch(...)
  • Error validation - assert_operation_summary_has_error(...)
  • Metadata validations - assert_operation_summary_has_started_by(), assert_configure_patching_patch_mode_state(), assert_configure_patching_auto_assessment_state(), assert_healthstore_status_info()
    - Extensible beyond this
  1. Applies all this into the ConfigurePatching unit test flow.
  • This exercise revealed that a test written for auto-assessment for Arc wasn't guarding against everything it could guard against. I'm leaving that out of the scope of this PR.

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)

Copilot AI review requested due to automatic review settings June 15, 2026 20:50
@kjohn-msft kjohn-msft added the engg. hygiene Engineering hygiene related label Jun 15, 2026
@kjohn-msft kjohn-msft changed the title Engg. Hygiene: Introduce Extension Status Asserter and use in one Test class Engg. Hygiene: Introduce Extension Status Asserter and use in example Test class Jun 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 ExtStatusAsserter test utility to load the status file once and provide higher-level assertion helpers (substatus, errors, patch presence, metadata).
  • Refactored portions of Test_ConfigurePatchingProcessor to 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.

Comment thread src/core/tests/Test_ConfigurePatchingProcessor.py Outdated
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)
Comment on lines 331 to 332
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
Comment thread src/core/tests/library/ExtStatusAsserter.py
Comment thread src/core/tests/library/ExtStatusAsserter.py Outdated
Comment thread src/core/tests/library/ExtStatusAsserter.py Outdated
@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.58848% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 94.06%. Comparing base (ba18a31) to head (c95b305).

Files with missing lines Patch % Lines
src/core/tests/Test_ExtStatusAsserter.py 99.09% 1 Missing ⚠️
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              
Flag Coverage Δ
python27 94.06% <99.58%> (+0.04%) ⬆️
python312 94.02% <99.58%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engg. hygiene Engineering hygiene related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants