Files
hermes-webui/tests
Nathan Esquenazi 709bd37e80 fix(tests): patch Session.save outside thread loop in issue798 test
test_concurrent_new_sessions_get_correct_profiles nests
`with patch.object(m.Session, 'save', return_value=None)` inside each of
two threads. unittest.mock has a known thread-safety bug here: if thread
B enters its `with` before thread A exits, thread A's __exit__ can capture
thread B's mock as the "original" and restore that. End state: the class
attribute is permanently a MagicMock, breaking every later test that
writes a real session file.

This was the root cause of the "pre-existing ordering-sensitive flaky
tests" observed in every prior review — test_issue856, test_sprint46,
test_provider_management all hit it with different symptoms.

Fix: apply the patch ONCE outside the thread loop, covering both workers.
Race being reproduced (explicit profile vs global) is unaffected — the
threads still run concurrently, they just share the single patch scope.

Full suite before: 2-4 ordering flakes depending on exact subset.
Full suite after: 1905 passed, 0 failed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-23 08:59:36 -07:00
..