summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-30 21:00:30 -0300
committerGabriel Schneider <[email protected]>2026-10-30 21:53:52 -0300
commitd00c40694dc239854263616f710b4a197d25d145 (patch)
tree3e7a980510e6c37507e0b60f1632cefc67d1c364 /test
parente6a114eed043dd1ca50be1cab912662fa9150fda (diff)
downloadpardes-d00c40694dc239854263616f710b4a197d25d145.tar.gz
pardes-d00c40694dc239854263616f710b4a197d25d145.zip
views: a client that joins again has its own view back, layout, focus and the panes opened in it: an Upgrade's clients and one whose bye says it joins again (a divergence's, wire 19's `bye.again`) leave their view kept for them (`views_away`, digested and dumped, so an Upgrade's new build has it; taped `awayView`), the client names it in its next hello (`Hello.view`, handed on by the daemon with the connection) and its join takes it back (taped `rejoinView`) rather than a copy of the session's; the live view is never a kept one, `views.count` counts the others, and a join with every view taken lets one go (every Upgrade made each client's own panes leave its view: the hunt's 80 ms cell lost `+Search` and `+New`)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'test')
-rw-r--r--test/daemon.py90
1 files changed, 67 insertions, 23 deletions
diff --git a/test/daemon.py b/test/daemon.py
index 8633238f..bf575fd7 100644
--- a/test/daemon.py
+++ b/test/daemon.py
@@ -208,7 +208,7 @@ class Replica:
"""A replica's connection (src/detached/wire.zig): length-prefixed
messages, a tag byte and a little-endian u32 length. It is a near
client: its first word after the hello says so."""
- WIRE = 18
+ WIRE = 19
def __init__(self, path, timeout=10):
self.s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
@@ -235,7 +235,7 @@ class Replica:
"""('welcome', pid, name) or ('refused', why); a welcome's dump
is read, whole."""
name = session.encode()
- self.send(0x01, struct.pack('<HQH', self.WIRE, build, len(name)) + name)
+ self.send(0x01, struct.pack('<HQH', self.WIRE, build, len(name)) + name + b'\xff')
self.send(0x06, b'\x00')
tag, body = self.read()
if tag == 0x01:
@@ -333,6 +333,23 @@ def agreed(path, after):
return len(lines) > after
+def made_live(term, check):
+ """A key in a replica client's terminal (`gg`), stepped by its session
+ (a check after it agreed): its view is the live one, the one /layout
+ reads and /exec runs in, until the next input. A client asks one check
+ at a time, and checks come on (each answer wakes its session): the
+ first after the key may have been asked before it, the second was not."""
+ seen = len(checks(check))
+ os.write(term.master, b'gg')
+ wait_for('the client\'s key stepped', lambda: agreed(check, seen + 1), timeout=20)
+
+
+def view_panes(client):
+ """The panes the live view lays out (/layout's pane serials)."""
+ return {int(x) for line in client.read('/layout').decode().splitlines()
+ if line.split()[:1] != ['active'] for x in line.split()[6:]}
+
+
def clients(binary):
"""Replica clients of a detached session: one on the replica socket,
one through the delay relay; each one's keys in the session's text and
@@ -388,23 +405,31 @@ def clients(binary):
wait_for('the attached terminal\'s frame', lambda: b'line 3 of the notes' in tt.text(), timeout=20)
stub.send_signal(signal.SIGHUP)
stub.wait(timeout=10)
- # One put off the session's state (PARDES_TEST_DIVERGE): the next
- # unit's digest finds it, it says so in a line and joins again, and
- # its keys after go in and it agrees.
+ # One put off the session's state (PARDES_TEST_DIVERGE, at its
+ # 100th unit): the next unit's digest finds it, it says so in a line
+ # and joins again for its view, a pane of its own in it, its keys
+ # after go into that pane and it agrees.
td = Term(24, 90)
terms.append(td)
- d = td.spawn([binary, f'--attach={sock}:files'], dict(env, PARDES_REPLICA_CHECK=str(root / 'd.check'), PARDES_TEST_DIVERGE='1'))
+ d = td.spawn([binary, f'--attach={sock}:files'], dict(env, PARDES_REPLICA_CHECK=str(root / 'd.check'), PARDES_TEST_DIVERGE='100'))
started.append(d.pid)
wait_for('client D\'s first frame', lambda: b'line 3 of the notes' in td.text(), timeout=20)
- os.write(td.master, b'jj')
- time.sleep(.5)
- # Another's unit, replayed on D's core: its digest finds it.
- os.write(ta.master, b'jj')
- wait_for('client D diverged and joined again', lambda: b'joined again' in td.text(), timeout=20)
+ made_live(td, root / 'd.check')
+ shown = view_panes(nine)
+ nine.write('/exec', b'New\n')
+ mine = wait_for('a pane in client D\'s view', lambda: view_panes(nine) - shown).pop()
+ # Others' units, replayed on D's core: one after its 100th finds it.
+ deadline = time.monotonic() + 60
+ while b'joined again' not in td.text():
+ assert time.monotonic() < deadline, 'client D diverged and joined again'
+ os.write(ta.master, b'jk')
+ time.sleep(.2)
assert d.poll() is None
+ made_live(td, root / 'd.check')
+ assert mine in view_panes(nine), ('client D in its own view again', mine, nine.read('/layout'))
seen = len(checks(root / 'd.check'))
os.write(td.master, b'Oafter-rejoin-D\x1b')
- wait_for('client D\'s keys after its rejoin', lambda: b'after-rejoin-D' in nine.read(f'/pane/{pane}/body'))
+ wait_for('client D\'s keys after its rejoin', lambda: b'after-rejoin-D' in nine.read(f'/pane/{mine}/body'))
wait_for('client D out of insert mode', lambda: normal_again(td))
wait_for('client D agrees after its rejoin', lambda: agreed(root / 'd.check', seen))
os.write(td.master, b' sD')
@@ -446,7 +471,7 @@ def clients(binary):
wait_for('the session\'s fds level', lambda: fds(sess.pid) == alone, timeout=10)
print(f'daemon: two replica clients (one through a 40 ms relay) typed into a detached session; '
f'digests agreed {len(checks(root / "a.check"))} and {len(checks(root / "b.check"))} times; '
- f'one put off the session\'s state joined again and agreed {len(checks(root / "d.check"))} times; '
+ f'one put off the session\'s state joined again in its own view and agreed {len(checks(root / "d.check"))} times; '
f'one killed, the other typed on and detached; a third typed into a shell, agreed '
f'{len(checks(root / "c.check"))} times, and was hung up')
exit_session(nine, pane)
@@ -980,7 +1005,7 @@ def far_joins(sock, session, binary, n):
def join():
r = Replica(sock, timeout=30)
name = session.encode()
- r.send(0x01, struct.pack('<HQH', Replica.WIRE, build, len(name)) + name)
+ r.send(0x01, struct.pack('<HQH', Replica.WIRE, build, len(name)) + name + b'\xff')
r.send(0x06, b'\x01')
tag, body = r.read()
assert tag == 0x01, (tag, body)
@@ -1509,19 +1534,38 @@ def upgrades(old, new):
dict(env, PARDES_REPLICA_CHECK=str(root / 'e.check')))
started.append(again.pid)
wait_for('the client of the build running drawn', lambda: b'\x1b[?1049h' in term4.text() and b'one' in term4.text())
+ # A second, and each a pane of its own in its own view: the
+ # Upgrade's rejoin gives each its own view back, its pane in it,
+ # not a new one (a copy of the session's, without it).
+ term5 = Term(30, 100)
+ again5 = term5.spawn([str(new), f'--attach={root / "pardes-replica.sock"}:work'],
+ dict(env, PARDES_REPLICA_CHECK=str(root / 'f.check')))
+ started.append(again5.pid)
+ wait_for('the second client of the build running drawn', lambda: b'\x1b[?1049h' in term5.text() and b'one' in term5.text())
+ owners = ((term4, root / 'e.check'), (term5, root / 'f.check'))
+ mine = []
+ for t, check in owners:
+ made_live(t, check)
+ shown = view_panes(client)
+ client.write('/exec', b'New\n')
+ mine.append(wait_for('a pane in the client\'s view', lambda: view_panes(client) - shown).pop())
refusing('1')
client.write(f'/pane/{shell}/exec', b'Upgrade\n')
client.socket.close()
client = saying(sock, 'it goes on as')
- wait_for('the client joined again', lambda: b'joined again: the session is upgrading' in term4.text(), timeout=30)
- assert again.poll() is None
- seen = len(checks(root / 'e.check'))
- os.write(term4.master, b'gg')
- wait_for('the client agrees after it joined again', lambda: agreed(root / 'e.check', seen), timeout=20)
- again.send_signal(signal.SIGHUP)
- again.wait(timeout=10)
- term4.close()
- print('upgrade: a replica client of the build running joined again after the upgrade, said so and agreed')
+ for t, _ in owners:
+ wait_for('the client joined again', lambda: b'joined again: the session is upgrading' in t.text(), timeout=30)
+ assert again.poll() is None and again5.poll() is None
+ for (t, check), pane, theirs in zip(owners, mine, reversed(mine)):
+ made_live(t, check)
+ shown = view_panes(client)
+ assert pane in shown and theirs not in shown, ('its own view again', pane, theirs, client.read('/layout'))
+ for c, t in ((again, term4), (again5, term5)):
+ c.send_signal(signal.SIGHUP)
+ c.wait(timeout=10)
+ t.close()
+ print('upgrade: two replica clients of the build running joined again after the upgrade, said so and agreed, '
+ 'each in its own view again, its own pane in it')
assert os.stat(f'/proc/{session}/exe').st_ino == running, 'back on the build that ran'
assert alive(shell_pid) and ppid(shell_pid) == session and stub.poll() is None
assert client.read(f'/pane/{text}/body') == b'one\ntwo\n'