fix(schema): give Task.open_query a proper default and add schema tests#49
fix(schema): give Task.open_query a proper default and add schema tests#49wustwyh wants to merge 1 commit into
Conversation
- Replace the FIXME comment on Task.open_query with an explicit default=False so callers can construct a Task without specifying it. - Add unit tests for Task and TaskObjective covering defaults, overrides, optional fields, and serialization roundtrip.
There was a problem hiding this comment.
Code Review
This pull request sets a default value of False for the open_query field in the Task schema and introduces a comprehensive suite of unit tests in tests/test_schema.py to verify the behavior of Task and TaskObjective. The review feedback recommends removing dynamic sys.path modifications and unused imports from the test file, replacing the Pydantic v2 model_dump() call with the Pydantic v1 .dict() method to ensure backward compatibility, and removing the outdated if __name__ == '__main__': pytest.main(...) boilerplate.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| import sys | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| ROOT_DIR = Path(__file__).resolve().parents[1] | ||
| if str(ROOT_DIR) not in sys.path: | ||
| sys.path.insert(0, str(ROOT_DIR)) |
There was a problem hiding this comment.
Modifying sys.path dynamically within test files is an anti-pattern that can mask import issues and make tests behave inconsistently. Since the recommended way to run tests is via python -m pytest (as mentioned in the PR description), the project root is automatically added to sys.path by Python. Therefore, this dynamic path insertion and the unused sys and pathlib imports can be safely removed.
| import sys | |
| from pathlib import Path | |
| import pytest | |
| ROOT_DIR = Path(__file__).resolve().parents[1] | |
| if str(ROOT_DIR) not in sys.path: | |
| sys.path.insert(0, str(ROOT_DIR)) | |
| import pytest |
| data = objective.model_dump() | ||
| restored = TaskObjective(**data) |
There was a problem hiding this comment.
The rest of the codebase (e.g., task_manager.py) consistently uses Pydantic v1 APIs such as .dict(), .json(), parse_obj(), and parse_raw(). Using model_dump() (a Pydantic v2 API) here will cause an AttributeError if the environment is running Pydantic v1. To maintain compatibility with the rest of the codebase, use .dict() instead.
| data = objective.model_dump() | |
| restored = TaskObjective(**data) | |
| data = objective.dict() | |
| restored = TaskObjective(**data) |
| if __name__ == "__main__": | ||
| pytest.main([__file__, "-v"]) |
What changed\n\n- Replaced the FIXME comment on Task.open_query with an explicit default=False so callers can construct a Task without having to supply the new attribute.\n- Added ests/test_schema.py with unit tests for Task and TaskObjective covering defaults, overrides, optional fields, and serialization roundtrip.\n\n## Why\n\nThe Task schema currently required every instantiation site to provide open_query, even though the intent (per the FIXME) was for it to default to False. Giving it a proper default reduces boilerplate and avoids accidental breakage at call sites that haven't been updated yet. The new tests lock in the expected schema behavior and will catch future regressions.\n\n## Verification\n\n
�ash\npython -m pytest tests/test_schema.py -v\n\n\nAll 10 tests pass.