|
16 | 16 | file carries the edit; a clean buffer reloads silently, cursor kept; a |
17 | 17 | save over a file that moved underneath is refused `stale` and asks before |
18 | 18 | overwriting (the "changed on disk" dialog, stubbed), the file untouched |
19 | | -until Overwrite; a deleted file is told and marked dirty; a closed tab's |
| 19 | +until Overwrite; a deleted file is told and marked dirty; a change that |
| 20 | +waited for a reload is judged even when the reload fails; a closed tab's |
20 | 21 | watch is gone. The pane never opens a file itself. |
21 | 22 |
|
22 | 23 | This is a script, not a pytest test, on purpose: tests/conftest.py blocks |
|
64 | 65 | Adw.init() |
65 | 66 |
|
66 | 67 | from collins import dialogs, remotefiles # noqa: E402 |
| 68 | +from collins.api import protocol # noqa: E402 |
| 69 | +from collins.api.protocol import RequestRefused # noqa: E402 |
67 | 70 | from collins.editor import EditorPane # noqa: E402 |
68 | 71 |
|
69 | 72 | PASSED = 0 |
@@ -269,6 +272,36 @@ def fake_confirm(parent, heading, body, confirm_label, on_confirm, on_dismiss=No |
269 | 272 | check("and its buffer is dirty, so nothing saves over nothing silently", other.buffer.get_modified()) |
270 | 273 | check("its mtime is forgotten", other.mtime is None) |
271 | 274 |
|
| 275 | + # -- a change that waited for a reload is judged even when the reload fails ------ |
| 276 | + # Two external changes racing one reload: the second is queued while the |
| 277 | + # read is in flight, and the read then fails (the file went away between |
| 278 | + # the monitor and the read). The queued `gone` is still judged, so the |
| 279 | + # buffer is told and marked dirty (the review of PR 609). |
| 280 | + third = os.path.join(root, "third.txt") |
| 281 | + with open(third, "w") as fh: |
| 282 | + fh.write("third\n") |
| 283 | + pane.open_file(third) |
| 284 | + racing = pane._open[third] |
| 285 | + if not wait_for(lambda: not racing.loading): |
| 286 | + print("FAIL the third read never landed") |
| 287 | + return 1 |
| 288 | + pane._banner.set_revealed(False) |
| 289 | + racing.loading = True # a reload in flight... |
| 290 | + racing.reloading = True |
| 291 | + pane._check_external( |
| 292 | + racing, {"handle": racing.watch_handle, "path": third, "mtime": None, "size": None, "gone": True} |
| 293 | + ) |
| 294 | + check("a change during a reload waits for it", racing.pending_change is not None and not racing.buffer.get_modified()) |
| 295 | + pane._on_loaded( |
| 296 | + racing, racing.load_id, "refused", RequestRefused(protocol.ERROR_GONE, "{name} is not there", {"name": "third.txt"}) |
| 297 | + ) |
| 298 | + check("the failed reload is told", pane._banner.get_revealed()) |
| 299 | + check( |
| 300 | + "and the waiting change is judged after it", |
| 301 | + racing.pending_change is None and racing.mtime is None and racing.buffer.get_modified(), |
| 302 | + (racing.pending_change, racing.mtime, racing.buffer.get_modified()), |
| 303 | + ) |
| 304 | + |
272 | 305 | # -- closing a tab drops its watch ----------------------------------------------- |
273 | 306 | handle = other.watch_handle |
274 | 307 | pane._close_confirmed.add(pane._pages[second]) |
|
0 commit comments