From 3ddd34bcd94ba95d9cacbf6afcb9f89a16a414ce Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 1 Oct 2026 22:58:12 -0300 Subject: Edit's w to a file changed on disk since read is refused once, as Save is (w again to overwrite), the rest of an X/'/w written and the refused named; Edit filters get a pane command's environment ($PARDES_MOUNT, $PARDES_9P, $PARDES_PID, $winid); an Edit with no commands runs beside one whose commands run unless it touches a file that one changes, refused busy (EBUSY) as is a second Edit with commands Co-Authored-By: Claude Opus 5.5 --- test/fs.py | 21 +++++++++++++++++++++ test/selfmount.py | 7 +++++++ 2 files changed, 28 insertions(+) (limited to 'test') diff --git a/test/fs.py b/test/fs.py index b593981c..f954b508 100644 --- a/test/fs.py +++ b/test/fs.py @@ -1123,6 +1123,27 @@ def edit_commands(binary): assert (root / 'b.txt').read_bytes() == b'APPLE pie\n' client.write(f'/pane/{a}/ctl', b'Edit 1 w first.txt\n') assert (root / 'first.txt').read_bytes() == b'APPLE\n' + # A file changed on disk under unsaved edits: Edit's w refuses + # once, as Save does, and the next w overwrites it. + w1 = root / 'w1.txt' + w1.write_bytes(b'one\n') + w = look(client, str(w1)) + client.write(f'/pane/{w}/ctl', b'Edit $a/two/\n') + seen = client.read('/log').decode().count(f'\nchanged {w}') + with open(w1, 'ab') as f: + f.write(b'external\n') + deadline = time.monotonic() + 10 + while client.read('/log').decode().count(f'\nchanged {w}') == seen: + assert time.monotonic() < deadline, 'the change on disk was not heard' + time.sleep(.05) + try: + client.write(f'/pane/{w}/ctl', b'Edit w\n') + raise AssertionError('w overwrote a file changed on disk') + except OSError as why: + assert 'modified on disk since read (w again to overwrite)' in str(why), why + assert w1.read_bytes() == b'one\nexternal\n' + client.write(f'/pane/{w}/ctl', b'Edit w\n') + assert w1.read_bytes() == b'one\ntwo', w1.read_bytes() def test(binary, quic=False): diff --git a/test/selfmount.py b/test/selfmount.py index c8a81df9..347093e1 100644 --- a/test/selfmount.py +++ b/test/selfmount.py @@ -307,6 +307,13 @@ def run(binary): ran = run(f"echo 'Edit $ < cat {mount}/pane/{edited}/body' > {mount}/pane/{edited}/ctl\n".encode()) check(ran == '0' and client.read(f'/pane/{edited}/body') == b'apple\npear\napple\npear\n', f'an Edit whose command reads the session through its mount ({ran!r})') + # A filter gets what a pane's command gets: the session's mount, + # socket and pid. + env_pane = int(client.read('/pane/new')) + ran = run(f"echo 'Edit $ < printf \"%s|%s|%s\" \"$PARDES_MOUNT\" \"$PARDES_9P\" \"$PARDES_PID\"' > {mount}/pane/{env_pane}/ctl\n".encode()) + got_env = client.read(f'/pane/{env_pane}/body').decode().split('|') + check(ran == '0' and len(got_env) == 3 and got_env[0] == mount and got_env[1] == sock and got_env[2].isdigit(), + f'an Edit filter has $PARDES_MOUNT, $PARDES_9P and $PARDES_PID ({got_env!r})') # An interrupted Edit write is flushed: its command is stopped and # nothing changes, and the next Edit runs. flushed = Path(f'/tmp/{name}.flushed') -- cgit v1.3