Skip to content

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
mainfrom
probe/issue-22
Closed

github-actions[bot] wants to merge 1 commit into
mainfrom
probe/issue-22

Conversation

@github-actions

@github-actions github-actions Bot commented Aug 22, 2026

Copy link
Copy Markdown

The ops "How to manage actions" doc has a "Write unit tests" section that shows this unit test:

assert 'snapshot-size' in ctx.action_results

But the very same doc's action handler (_on_snapshot_action) ends with event.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_results fails because the only key in the results is 'result'.

To test this adversarially, I added a snapshot action to the meteor charm (in charmcraft.yaml and src/charm.py) whose handler mirrors the doc faithfully — it logs Generating snapshot into {filename} and ends with event.set_results({'result': msg}). Then I added a unit test (tests/unit/test_snapshot_action.py) that runs the snapshot action 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 set event.set_results({'snapshot-size': ...}) or change the test to assert 'result' in ctx.action_results.

I ran tox -e format,lint,unit on meteor and all three environments pass: the new test (test_snapshot_action_results_key_is_result_not_snapshot_size) passes alongside the pre-existing test_start, ruff/codespell/pyright are clean, and the existing tests are not broken.

@github-actions

Copy link
Copy Markdown
Author

This PR is a draft. Inspect the changes, then mark it ready for review to run CI.

@github-actions github-actions Bot changed the title verify: The ops "How to manage actions" doc shows a snapshot action handler verify: The ops "How to manage actions" doc shows a snapshot action handler th Aug 22, 2026
@github-actions

Copy link
Copy Markdown
Author

This PR is a draft. Inspect the changes, then mark it ready for review to run CI.

@github-actions github-actions Bot changed the title verify: The ops "How to manage actions" doc shows a snapshot action handler th verify: The ops "How to manage actions" doc presents a snapshot action handl Aug 22, 2026
@github-actions

Copy link
Copy Markdown
Author

This PR is a draft. Inspect the changes, then mark it ready for review to run CI.

@github-actions github-actions Bot changed the title verify: The ops "How to manage actions" doc presents a snapshot action handl verify: The ops "How to manage actions" doc has a "Write unit tests" section t Aug 22, 2026
@github-actions

Copy link
Copy Markdown
Author

This PR is a draft. Inspect the changes, then mark it ready for review to run CI.

@dwilding
dwilding marked this pull request as ready for review August 23, 2026 22:59
@dwilding dwilding closed this Aug 25, 2026
@dwilding
dwilding deleted the probe/issue-22 branch August 25, 2026 10:52
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