verify: The ops "How to manage actions" doc has a "Write unit tests" section t - #31
Closed
github-actions[bot] wants to merge 1 commit into
Closed
github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
Author
|
This PR is a draft. Inspect the changes, then mark it ready for review to run CI. |
github-actions
Bot
force-pushed
the
probe/issue-22
branch
from
August 22, 2026 15:25
fe3389f to
c008f83
Compare
snapshot action handler
Author
|
This PR is a draft. Inspect the changes, then mark it ready for review to run CI. |
github-actions
Bot
force-pushed
the
probe/issue-22
branch
from
August 22, 2026 16:34
c008f83 to
1cba342
Compare
snapshot action handl
Author
|
This PR is a draft. Inspect the changes, then mark it ready for review to run CI. |
github-actions
Bot
force-pushed
the
probe/issue-22
branch
from
August 22, 2026 17:12
1cba342 to
78c296c
Compare
snapshot action handl
Author
|
This PR is a draft. Inspect the changes, then mark it ready for review to run CI. |
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.
The ops "How to manage actions" doc has a "Write unit tests" section that shows this unit test:
But the very same doc's action handler (
_on_snapshot_action) ends withevent.set_results({'result': msg}). So the action results dict carries the key'result', not'snapshot-size'. I believe the doc is wrong: if you construct the action handler exactly as the doc presents it and run the doc's unit test,assert 'snapshot-size' in ctx.action_resultsfails because the only key in the results is'result'.To test this adversarially, I added a
snapshotaction to themeteorcharm (incharmcraft.yamlandsrc/charm.py) whose handler mirrors the doc faithfully — it logsGenerating snapshot into {filename}and ends withevent.set_results({'result': msg}). Then I added a unit test (tests/unit/test_snapshot_action.py) that runs thesnapshotaction with the same params the doc uses and asserts what I believe is true: the results equal{'result': 'Stored snapshot in db-snapshot.tar.gz.'}, the key'result'is present, and the key'snapshot-size'is not present. This is the opposite of the doc's claim, and I expect it to pass.If CI is green, the doc is incorrect — the doc's unit test would fail against the action handler it itself presents, because the handler sets
'result'while the test looks for'snapshot-size'. The fix for the doc is to either change the handler to setevent.set_results({'snapshot-size': ...})or change the test to assert'result' in ctx.action_results.I ran
tox -e format,lint,unitonmeteorand all three environments pass: the new test (test_snapshot_action_results_key_is_result_not_snapshot_size) passes alongside the pre-existingtest_start, ruff/codespell/pyright are clean, and the existing tests are not broken.