-
Notifications
You must be signed in to change notification settings - Fork 3.8k
fix(todo): stop json.loads corrupting bare numeric-looking todo ids #663
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
sean-kim05
wants to merge
2
commits into
usestrix:main
Choose a base branch
from
sean-kim05:fix/todo-id-json-scalar-corruption
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.
+113
−5
Open
Changes from 1 commit
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| """Tests for per-agent todo id normalization and resolution.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| import pytest | ||
|
|
||
| import strix.tools.todo.tools as todo_tools | ||
| from strix.tools.todo.tools import _normalize_todo_ids | ||
|
|
||
|
|
||
| if TYPE_CHECKING: | ||
| from collections.abc import Iterator | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def _reset_todos_storage(monkeypatch: pytest.MonkeyPatch) -> Iterator[None]: | ||
| monkeypatch.setattr(todo_tools, "_todos_path", None) | ||
| with todo_tools._todos_io_lock: | ||
| todo_tools._todos_storage.clear() | ||
| yield | ||
| with todo_tools._todos_io_lock: | ||
| todo_tools._todos_storage.clear() | ||
|
|
||
|
|
||
| def test_bare_numeric_looking_id_is_preserved() -> None: | ||
| # ids are `str(uuid.uuid4())[:6]` hex slugs; slugs like these are valid | ||
| # JSON numbers, so json.loads would turn "1e5230" into inf and "2363e0" | ||
| # into 2363.0. They must be kept verbatim as literal ids. | ||
| assert _normalize_todo_ids("1e5230") == ["1e5230"] | ||
| assert _normalize_todo_ids("2363e0") == ["2363e0"] | ||
| assert _normalize_todo_ids("0e4440") == ["0e4440"] | ||
|
|
||
|
|
||
| def test_plain_hex_and_digit_ids_are_preserved() -> None: | ||
| assert _normalize_todo_ids("a3f9c2") == ["a3f9c2"] | ||
| assert _normalize_todo_ids("123456") == ["123456"] | ||
|
|
||
|
|
||
| def test_json_array_of_ids_is_unpacked() -> None: | ||
| assert _normalize_todo_ids('["1e5230", "a3f9c2"]') == ["1e5230", "a3f9c2"] | ||
|
|
||
|
|
||
| def test_comma_separated_ids_are_split() -> None: | ||
| assert _normalize_todo_ids("1e5230, a3f9c2") == ["1e5230", "a3f9c2"] | ||
|
|
||
|
|
||
| def test_list_input_is_stringified_and_stripped() -> None: | ||
| assert _normalize_todo_ids([" 1e5230 ", "a3f9c2"]) == ["1e5230", "a3f9c2"] | ||
|
|
||
|
|
||
| def test_empty_and_none_inputs_yield_no_ids() -> None: | ||
| assert _normalize_todo_ids("") == [] | ||
| assert _normalize_todo_ids(" ") == [] | ||
| assert _normalize_todo_ids(None) == [] | ||
|
|
||
|
|
||
| def test_mark_resolves_a_bare_numeric_looking_id() -> None: | ||
| # End-to-end: marking a bare id whose slug is a valid JSON number must | ||
| # find and update the real todo, not fail with "Todo with ID 'inf' not | ||
| # found". | ||
| agent_id = "agent-1" | ||
| todos = todo_tools._get_agent_todos(agent_id) | ||
| todos["1e5230"] = { | ||
| "title": "probe /admin", | ||
| "description": None, | ||
| "priority": "normal", | ||
| "status": "pending", | ||
| "created_at": "2026-07-03T00:00:00+00:00", | ||
| "updated_at": "2026-07-03T00:00:00+00:00", | ||
| "completed_at": None, | ||
| } | ||
|
|
||
| result = json.loads(todo_tools._mark(agent_id=agent_id, todo_ids="1e5230", new_status="done")) | ||
|
|
||
| assert result["success"] is True | ||
| assert result["marked"] == ["1e5230"] | ||
| assert "errors" not in result | ||
| assert todos["1e5230"]["status"] == "done" |
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.
When a caller passes a single todo id as a JSON string scalar like
"a3f9c2",json.loadsstill succeeds but the parsed scalar is now ignored, so the lookup uses the literal value including quotes. This is an old-vs-new regression for the single-id fallback path: the todo stored asa3f9c2is reported as not found under"a3f9c2".Prompt To Fix With AI