Fix xfail tests - "args" attribute in ArchitectCoder#349
Fix xfail tests - "args" attribute in ArchitectCoder#349dwash96 merged 4 commits intocecli-dev:v0.92.0from
Conversation
Add defensive check for self.args which may not exist when ArchitectCoder is instantiated without full initialization. Use getattr to safely access the attribute and default to None.
- Remove xfail markers from 3 ArchitectCoder tests - Use AsyncMock for async generate() method - Fix assertions to include allow_tweak parameter - Handle SwitchCoder exception raised by reply_completed() - Add missing coder attributes (aider_commit_hashes, etc.) - Remove boilerplate comments
| return | ||
|
|
||
| tweak_responses = getattr(self.args, "tweak_responses", False) | ||
| args = getattr(self, "args", None) |
There was a problem hiding this comment.
I wonder if args shoud always be there on an instance of a coder, so that the getattr trickery here could be avoided.
There was a problem hiding this comment.
It's not really that you need to do trickery with getattr(), it's that the actual create function in base_coder should make sure anything that has a relevant from_coder passed to it should get the args (the object we parse from the configuration all the way at the beginning of main.py main_async method) is just passed down to children.
We already do this with the tui weakref and mcp_servers
Edit: and the args object itself already after checking!
There was a problem hiding this comment.
However, most tests don't instantiate an args object at all and that's the real problem with the harness. It's not a true state of affairs in the actual application that a coder will exist without an args object being passed into it first from main.py and then through SwitchCoder exceptions, by way of the from_coder argument
There was a problem hiding this comment.
did arrive there eventually, think the test case was mocking the init method and making it difficult for itself.
Tests patch AskCoder.__init__ which bypasses normal initialization. Fix the tests to properly set coder.args rather than adding defensive code to production that handles a test-only scenario.
Replace manual __init__ patching with proper Coder.create() factory. This reduces test maintenance burden by letting the coder initialize normally instead of manually setting 10+ attributes.
Fixing two tests of the AgentCoder to work again.
After looking into the code a bit deeper I got the idea that the tests should avoid to mock the
__init__method. It seems that creating the coder object in the regular way works, this should make the tests depend a lot less on the details of the init method.