fix: remove stale test skips, fix regex backtracking, file search bug, and test flakiness#4766
fix: remove stale test skips, fix regex backtracking, file search bug, and test flakiness#4766LucidPaths wants to merge 1 commit intoNousResearch:mainfrom
Conversation
…, and test flakiness Bug fixes: - agent/redact.py: catastrophic regex backtracking in _ENV_ASSIGN_RE — removed re.IGNORECASE and changed [A-Z_]* to [A-Z0-9_]* to restrict matching to actual env var name chars. Without this, the pattern backtracks exponentially on large strings (e.g. 100K tool output), causing test_file_read_guards to time out. - tools/file_operations.py: over-escaped newline in find -printf format string produced literal backslash-n instead of a real newline, breaking file search result parsing (total_count always 1, paths concatenated). Test fixes: - Remove stale pytestmark.skip from 4 test modules that were blanket-skipped as 'Hangs in non-interactive environments' but actually run fine: - test_413_compression.py (12 tests, 25s) - test_file_tools_live.py (71 tests, 24s) - test_code_execution.py (61 tests, 99s) - test_agent_loop_tool_calling.py (has proper OPENROUTER_API_KEY skip already) - test_413_compression.py: fix threshold values in 2 preflight compression tests where context_length was too small for the compressed output to fit in one pass. - test_mcp_probe.py: add missing _MCP_AVAILABLE mock so tests work without MCP SDK. - test_mcp_tool_issue_948.py: inject MCP symbols (StdioServerParameters etc.) when SDK is not installed so patch() targets exist. - test_approve_deny_commands.py: replace time.sleep(0.3) with deterministic polling of _gateway_queues — fixes race condition where resolve fires before threads register their approval entries, causing the test to hang indefinitely. Net effect: +256 tests recovered from skip, 8 real failures fixed.
Code Review: PR #4766Thank you for this PR addressing multiple issues. I've reviewed the changes and have the following feedback: ✅ Changes Look Good
Minor Suggestions
Security Considerations
OverallThis is a solid bugfix PR that addresses real issues. The changes are well-thought-out and the test improvements should reduce flakiness. LGTM! |
Code Review - PR #4766Overall: APPROVED - Good set of fixes addressing real bugs and test issues. Bug Fixes✅ agent/redact.py - Regex Backtracking (ReDoS)
✅ tools/file_operations.py - File Search Bug
✅ tests/gateway/test_approve_deny_commands.py - Test Flakiness
Test Improvements✅ Stale Skip Removal
✅ MCP Test Fixes
Minor Suggestions
Overall, these are solid fixes. Nice work! |
|
Merged via PR #4969. Your commit was cherry-picked onto current main with your authorship preserved in git log. Conflict in redact.py resolved by combining your IGNORECASE removal with main's {0,50} length bound. Both bug fixes E2E verified. Thanks @LucidPaths! |
Summary
Fix 2 real bugs and remove stale test skips that were hiding 256 passing tests.
Bug Fixes
agent/redact.py— catastrophic regex backtracking in_ENV_ASSIGN_REThe pattern
[A-Z_]*withre.IGNORECASEmatches any letter, causing exponential backtracking on large strings (100K+ tool output). Removedre.IGNORECASEand changed to[A-Z0-9_]*to restrict to actual env var name characters. This was causingtest_file_read_guardsto time out.tools/file_operations.py— over-escaped newline infind -printfThe format string had
\\\\n(4 backslashes) which produced literal\nin shell output instead of a real newline. File search results were concatenated into one entry, breakingtotal_countand path resolution.Test Fixes
Remove stale blanket skips from 4 test modules:
All were marked
pytestmark = pytest.mark.skip(reason="Hangs in non-interactive environments")but run fine:test_413_compression.py(12 tests, 25s)test_file_tools_live.py(71 tests, 24s)test_code_execution.py(61 tests, 99s)test_agent_loop_tool_calling.py(already has properOPENROUTER_API_KEYskip)Fix 4 test issues:
test_413_compression.py: Threshold values too small for compressed output to fit in one passtest_mcp_probe.py: Missing_MCP_AVAILABLEmock — tests returned early without MCP SDKtest_mcp_tool_issue_948.py:patch()targets don't exist without MCP SDK — inject symbolstest_approve_deny_commands.py: Race condition —time.sleep(0.3)replaced with deterministic polling of_gateway_queuesto wait for threads to register before resolvingImpact
+256 tests recovered from skip, 8 failures fixed. Tested on Ubuntu 24.04 / Python 3.12.
Checklist