Commit 96b1785
fix(load_module): re-execute when cached __file__ differs from requested path
CI hang on `tests/test_cli/test_run.py::TestRunFailsWhenConnectionClassNotPresent::test_run`
diagnosed after every platform_checks matrix run on this branch hit the
120-min workflow timeout cancel.
Symptom: the test overwrites a connection's `connection.py` with a stub
that lacks `HTTPClientConnection`, runs the agent via the CLI, and
expects `ClickException("Connection class 'HTTPClientConnection' not
found")`. After commit `a0d759e7c` (drop __file__ equality from
cache-hit check), `load_module` returns the cached real connection from
`sys.modules` regardless of which file the caller pointed it at. The
class IS found (from the cache), the agent boots, enters its asyncio
event loop, and runs forever.
Root cause: the `a0d759e7c` relaxation was too broad. It addressed the
"Found many classes with name 'EchoBehaviour'" CI failure by always
reusing the cache, but in doing so it silently bypasses any caller that
points `load_module` at a different physical file — which is exactly
what test fixtures that stub source files on disk do.
Fix: restore the `__file__` equality guard. Cache-hit only when the
cached module's `__file__` resolves to the same path as the requested
`filepath`. When paths differ, fall through to spec-from-file-location
and re-execute against the file the caller pointed us at. The
block-import sentinel (`sys.modules[k] is None`) still raises
`ImportError` as before. On exec failure the half-built stub is
popped — a stale prior entry (different `__file__`) is discarded
rather than restored, since the caller was asking us to load a
different file.
Tests:
- `test_load_module_reuses_cached_module_for_same_dotted_path` renamed
to `test_load_module_reuses_cached_module_for_same_file` and rewritten:
the "different file at the same dotted path" branch now asserts the
cache is bypassed and the new source is executed (Other defined,
Marker not), instead of the old "still reuse the cached module"
assertion.
Verified locally:
- `pytest tests/test_cli/test_run.py::test_run[None]
tests/test_cli/test_run.py::TestRunFailsWhenConnectionClassNotPresent::test_run`
passes in 1.4s (was hanging at 120s+).
- `pytest tests/test_skills/test_base.py
tests/test_contracts/test_base.py tests/test_connections/test_base.py`:
217 passed, 1 skipped, 1 error (Docker-related, unrelated).
- `pytest tests/test_cli/test_run.py tests/test_configurations/`:
377 passed, 5 skipped.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent 56ec6f2 commit 96b1785
2 files changed
Lines changed: 45 additions & 39 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
140 | 139 | | |
141 | 140 | | |
142 | 141 | | |
143 | 142 | | |
144 | 143 | | |
145 | 144 | | |
146 | | - | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
147 | 153 | | |
148 | 154 | | |
149 | 155 | | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
155 | 161 | | |
156 | 162 | | |
157 | 163 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
511 | 511 | | |
512 | 512 | | |
513 | 513 | | |
514 | | - | |
515 | | - | |
516 | | - | |
517 | | - | |
518 | | - | |
519 | | - | |
520 | | - | |
521 | | - | |
522 | | - | |
523 | | - | |
524 | | - | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
525 | 524 | | |
526 | 525 | | |
527 | 526 | | |
| |||
538 | 537 | | |
539 | 538 | | |
540 | 539 | | |
541 | | - | |
| 540 | + | |
542 | 541 | | |
543 | 542 | | |
544 | 543 | | |
545 | 544 | | |
546 | | - | |
547 | | - | |
548 | | - | |
549 | | - | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
550 | 548 | | |
551 | | - | |
552 | | - | |
553 | | - | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
554 | 552 | | |
555 | | - | |
556 | | - | |
| 553 | + | |
| 554 | + | |
557 | 555 | | |
558 | 556 | | |
559 | 557 | | |
| |||
1217 | 1215 | | |
1218 | 1216 | | |
1219 | 1217 | | |
1220 | | - | |
| 1218 | + | |
| 1219 | + | |
1221 | 1220 | | |
1222 | 1221 | | |
1223 | 1222 | | |
| |||
1241 | 1240 | | |
1242 | 1241 | | |
1243 | 1242 | | |
1244 | | - | |
| 1243 | + | |
| 1244 | + | |
1245 | 1245 | | |
1246 | 1246 | | |
1247 | 1247 | | |
| |||
0 commit comments