-
Notifications
You must be signed in to change notification settings - Fork 52.6k
feat(kanban): add audited update-body command #76765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Jeffgithub0029
wants to merge
1
commit into
NousResearch:main
Choose a base branch
from
Jeffgithub0029:feat/kanban-update-body
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+203
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| """Regression tests for audited canonical Kanban task-body updates.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import json | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from hermes_cli import kanban as kc | ||
| from hermes_cli import kanban_db as kb | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def kanban_home(tmp_path, monkeypatch): | ||
| home = tmp_path / ".hermes" | ||
| home.mkdir() | ||
| monkeypatch.setenv("HERMES_HOME", str(home)) | ||
| monkeypatch.setattr(Path, "home", lambda: tmp_path) | ||
| kb.init_db() | ||
| return home | ||
|
|
||
|
|
||
| def test_update_task_body_is_atomic_audited_and_idempotent(kanban_home): | ||
| with kb.connect_closing() as conn: | ||
| task_id = kb.create_task( | ||
| conn, | ||
| title="body drift", | ||
| body="historical body", | ||
| initial_status="blocked", | ||
| ) | ||
|
|
||
| first = kb.update_task_body( | ||
| conn, | ||
| task_id, | ||
| "current canonical body", | ||
| author="p0-kanban-sync", | ||
| ) | ||
| assert first is not None | ||
| assert first["changed"] is True | ||
| assert first["old_length"] == len("historical body") | ||
| assert first["new_length"] == len("current canonical body") | ||
|
|
||
| task = kb.get_task(conn, task_id) | ||
| assert task is not None | ||
| assert task.body == "current canonical body" | ||
| assert task.status == "blocked" | ||
| assert task.assignee is None | ||
| assert task.current_run_id is None | ||
|
|
||
| event = conn.execute( | ||
| "SELECT kind, payload FROM task_events " | ||
| "WHERE task_id = ? AND kind = 'body_updated'", | ||
| (task_id,), | ||
| ).fetchone() | ||
| assert event is not None | ||
| assert json.loads(event["payload"])["author"] == "p0-kanban-sync" | ||
|
|
||
| second = kb.update_task_body( | ||
| conn, | ||
| task_id, | ||
| "current canonical body", | ||
| author="p0-kanban-sync", | ||
| ) | ||
| assert second is not None | ||
| assert second["changed"] is False | ||
| assert conn.execute( | ||
| "SELECT COUNT(*) FROM task_events " | ||
| "WHERE task_id = ? AND kind = 'body_updated'", | ||
| (task_id,), | ||
| ).fetchone()[0] == 1 | ||
|
|
||
|
|
||
| def test_update_body_cli_emits_machine_readable_result(kanban_home, capsys): | ||
| with kb.connect_closing() as conn: | ||
| task_id = kb.create_task(conn, title="cli body", body="old") | ||
|
|
||
| parser = argparse.ArgumentParser(prog="hermes", add_help=False) | ||
| sub = parser.add_subparsers(dest="command") | ||
| kc.build_parser(sub) | ||
| args = parser.parse_args( | ||
| [ | ||
| "kanban", | ||
| "--board", | ||
| "default", | ||
| "update-body", | ||
| task_id, | ||
| "--body", | ||
| "new from cli", | ||
| "--author", | ||
| "p0-kanban-sync", | ||
| "--json", | ||
| ] | ||
| ) | ||
|
|
||
| assert kc.kanban_command(args) == 0 | ||
| payload = json.loads(capsys.readouterr().out) | ||
| assert payload["task_id"] == task_id | ||
| assert payload["changed"] is True | ||
| assert payload["body_length"] == len("new from cli") | ||
|
|
||
| with kb.connect_closing() as conn: | ||
| task = kb.get_task(conn, task_id) | ||
| assert task is not None | ||
| assert task.body == "new from cli" | ||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please assert the full audit/privacy contract here: expected old/new SHA-256 values and lengths, plus that the decoded payload has no body-text fields. The current assertion only verifies
author, so a later regression could persist canonical task text in the event log undetected.