summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-21 12:42:42 -0300
committerGabriel Schneider <[email protected]>2026-11-21 20:57:35 -0300
commit8c2c07bb4b991fde28b9af6207c7eb7418540130 (patch)
tree2b797eb300ce9b0434d62d7ca7f5a242b74fd5bd
parent2de6284791f30ecb3bcc45fa58571418a07ac6e5 (diff)
downloadpardes-8c2c07bb4b991fde28b9af6207c7eb7418540130.tar.gz
pardes-8c2c07bb4b991fde28b9af6207c7eb7418540130.zip
test/daemon.py: every mode can run as a user who exported PARDES_PAIR (`--with-pair` before the mode: `base_env` sets it in every process a mode starts, in place of 26 identical environment lines), and what the variable changes by P36 is expected so (`listed_as`: `--ps` lists a session born detached, or Detached in its own frontend, as `kept`, a tty launch as a pair `(tty)`; manage's machine records `tty kept`; the gui mode waits for the second window's pid to go, a pair's own window being a client too); `restore_client` follows P44 (a Restore's replica client is told and joins again by itself, nothing said in its terminal, its keys reach the restored core and it agrees; the 9P connection is cut and dialled again; a second attach after agrees); with the variable (Debug and ReleaseSafe): clients, far, restore, attach-upgrading, pair, games pass, manage and launch pass, relink fails on ReleaseSafe at the adopted shell's `echo $$` (the known flake pardes-rows' `adopted_pid` fixes), window-clients and gui fail on the window pair's session (listed `tty`, the window's child), upgrade fails reading a pair's session screen over 9P (reports/pardes-pair-8.md, item 3); `--restore` without the variable passes on both builds
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
-rw-r--r--test/daemon.py143
1 files changed, 93 insertions, 50 deletions
diff --git a/test/daemon.py b/test/daemon.py
index 23189578..d53e6182 100644
--- a/test/daemon.py
+++ b/test/daemon.py
@@ -29,6 +29,8 @@ private HOME and runtime directory:
`pardes new --detach` returns once its session runs
python3 -B test/daemon.py --pair <pardes>
PARDES_PAIR: a terminal's session and its first client
+ python3 -B test/daemon.py --with-pair <mode> ...
+ any mode with PARDES_PAIR set in every process it starts
python3 -B test/daemon.py --attach-upgrading <pardes>
an attach started as its session upgrades, and two clients' views
across an Upgrade (in plain and --pair too)
@@ -67,6 +69,28 @@ from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent))
from ninep import Client # noqa: E402
+# `--with-pair` before a mode: that mode as a user who exported PARDES_PAIR.
+WITH_PAIR = False
+
+
+def base_env():
+ """This process's environment without the caller's PARDES_* (a session
+ of the user's) or a pager; under `--with-pair`, PARDES_PAIR set in it, as
+ for a user who exported it: every mode run with the variable."""
+ env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k}
+ if WITH_PAIR:
+ env['PARDES_PAIR'] = '1'
+ return env
+
+
+def listed_as(word, kind='tty'):
+ """How `--ps` lists a session `detached` (started so, or Detached in its
+ own frontend) or that `has a frontend`: under the variable the first is
+ kept (from birth, or at the Detach) and the second a pair (P36)."""
+ if WITH_PAIR:
+ return f'({kind}, kept)' if word == 'detached' else f'({kind})'
+ return f'({kind}, {word})'
+
def wait_for(what, check, timeout=10):
deadline = time.monotonic() + timeout
@@ -424,7 +448,7 @@ def clients(binary):
scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn'
scratch.mkdir(parents=True, exist_ok=True)
root = Path(tempfile.mkdtemp(prefix='rc-', dir=scratch))
- env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k}
+ env = base_env()
env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'),
TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1')
(root / 'config' / 'pardes').mkdir(parents=True)
@@ -566,7 +590,7 @@ def launch(binary):
scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn'
scratch.mkdir(parents=True, exist_ok=True)
root = Path(tempfile.mkdtemp(prefix='rl-', dir=scratch))
- env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k}
+ env = base_env()
env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'),
TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1')
(root / 'config' / 'pardes').mkdir(parents=True)
@@ -593,12 +617,12 @@ def launch(binary):
assert (root / 'pardes-9p-work.sock').exists(), list(root.iterdir())
pid = status_pid('work')
listed = cli('ps').stdout.decode()
- assert f'session work {pid} (tty, detached)' in listed, listed
+ assert f'session work {pid} {listed_as('detached')}' in listed, listed
assert alive(pid) and os.getsid(pid) == pid, (pid, os.getsid(pid))
out = cli('new', '--detach')
assert out.returncode == 0 and out.stdout.strip().isdigit(), out
unnamed = int(out.stdout)
- assert status_pid(str(unnamed)) == unnamed and f'session {unnamed} {unnamed} (tty, detached)' in cli('ps').stdout.decode()
+ assert status_pid(str(unnamed)) == unnamed and f'session {unnamed} {unnamed} {listed_as('detached')}' in cli('ps').stdout.decode()
taken = cli('new', '--detach=work')
assert taken.returncode == 1 and taken.stderr == b'pardes: a session named work is already running\n', taken
# The flag alone runs the session in this process, as a supervisor
@@ -634,7 +658,7 @@ def pair(binary):
scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn'
scratch.mkdir(parents=True, exist_ok=True)
root = Path(tempfile.mkdtemp(prefix='rp-', dir=scratch))
- env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k}
+ env = base_env()
env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'),
TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1', PARDES_PAIR='1')
(root / 'config' / 'pardes').mkdir(parents=True)
@@ -708,7 +732,7 @@ def pair_rows(binary):
scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn'
scratch.mkdir(parents=True, exist_ok=True)
root = Path(tempfile.mkdtemp(prefix='rq-', dir=scratch))
- env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k}
+ env = base_env()
env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'),
TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1', PARDES_PAIR='1')
(root / 'config' / 'pardes').mkdir(parents=True)
@@ -898,7 +922,7 @@ def attach_upgrading(binary, rounds=6, dump=True):
scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn'
scratch.mkdir(parents=True, exist_ok=True)
root = Path(tempfile.mkdtemp(prefix='ru-', dir=scratch))
- env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k}
+ env = base_env()
env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'),
TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1')
(root / 'config' / 'pardes').mkdir(parents=True)
@@ -988,7 +1012,7 @@ def pair_upgrade_views(binary):
scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn'
scratch.mkdir(parents=True, exist_ok=True)
root = Path(tempfile.mkdtemp(prefix='rv-', dir=scratch))
- env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k}
+ env = base_env()
env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'),
TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1', PARDES_PAIR='1')
(root / 'config' / 'pardes').mkdir(parents=True)
@@ -1094,7 +1118,7 @@ def pair_exec_reaps(old, new):
scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn'
scratch.mkdir(parents=True, exist_ok=True)
root = Path(tempfile.mkdtemp(prefix='rpx-', dir=scratch))
- env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k}
+ env = base_env()
env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'),
TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1', PARDES_PAIR='1')
(root / 'config' / 'pardes').mkdir(parents=True)
@@ -1155,7 +1179,7 @@ def far_exec(old, new):
scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn'
scratch.mkdir(parents=True, exist_ok=True)
root = Path(tempfile.mkdtemp(prefix='rfx-', dir=scratch))
- env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k}
+ env = base_env()
env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'),
TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1')
(root / 'config' / 'pardes').mkdir(parents=True)
@@ -1221,7 +1245,7 @@ def pair_window_geometry(gui_binary, new_gui):
scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn'
scratch.mkdir(parents=True, exist_ok=True)
root = Path(tempfile.mkdtemp(prefix='rgg-', dir=scratch))
- env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k}
+ env = base_env()
env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'),
SHELL='/bin/bash', PARDES_NOTIME='1', PARDES_DAEMON='on', TERM='xterm-256color', PARDES_PAIR='1',
SDL_VIDEO_DRIVER='offscreen')
@@ -1293,7 +1317,7 @@ def manage(binary):
scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn'
scratch.mkdir(parents=True, exist_ok=True)
root = Path(tempfile.mkdtemp(prefix='rm-', dir=scratch))
- env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k}
+ env = base_env()
env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'),
TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1')
(root / 'config' / 'pardes').mkdir(parents=True)
@@ -1329,14 +1353,14 @@ def manage(binary):
listed = out.stdout.decode()
assert f'pardes daemon {daemon}' in listed, listed
for name in ('one', 'two'):
- assert f'session {name} {sessions[name]} (tty, detached)' in listed, listed
+ assert f'session {name} {sessions[name]} {listed_as('detached')}' in listed, listed
assert f'shell {shells[name]}' in listed, listed
# The same, a record a line, in each session's /sessions.
with Client(root / 'pardes-9p-one.sock') as c:
records = c.read('/sessions').decode().splitlines()
assert records[0] == f'daemon {daemon}', records
for name in ('one', 'two'):
- at = records.index(f'session {sessions[name]} tty detached {name}')
+ at = records.index(f'session {sessions[name]} tty {"kept" if WITH_PAIR else "detached"} {name}')
assert records[at + 1] == f'shell {shells[name]}', records
print('manage: /sessions read over 9P listed the daemon, both sessions and their shells')
os.kill(sessions['two'], signal.SIGKILL)
@@ -1397,7 +1421,7 @@ def relink(binary):
scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn'
scratch.mkdir(parents=True, exist_ok=True)
root = Path(tempfile.mkdtemp(prefix='rr-', dir=scratch))
- env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k}
+ env = base_env()
env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'),
TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1')
(root / 'config' / 'pardes').mkdir(parents=True)
@@ -1439,7 +1463,7 @@ def relink(binary):
own_shell = terminals(own)[0]
own_shell_pid = int(run(own, own_shell, b'echo $$\n').split(b'\n')[1])
started.append(own_shell_pid)
- expected = [f'session work {session} (tty, detached)', f'session own {own_pid} (tty, has a frontend)',
+ expected = [f'session work {session} {listed_as("detached")}', f'session own {own_pid} {listed_as("has a frontend")}',
f'shell {shell_pid}', f'shell {own_shell_pid}']
assert all(row in listed() for row in expected), listed()
daemon = daemons()[0]
@@ -1502,7 +1526,7 @@ def answer_late(binary):
scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn'
scratch.mkdir(parents=True, exist_ok=True)
root = Path(tempfile.mkdtemp(prefix='ra-', dir=scratch))
- env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k}
+ env = base_env()
env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'),
TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1')
(root / 'config' / 'pardes').mkdir(parents=True)
@@ -1619,7 +1643,7 @@ def pdf_window(binary, gui_binary):
scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn'
scratch.mkdir(parents=True, exist_ok=True)
root = Path(tempfile.mkdtemp(prefix='pdfw-', dir=os.environ.get('TMPDIR') or scratch))
- env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k}
+ env = base_env()
env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'),
TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1')
env.pop('XDG_DATA_HOME', None)
@@ -1685,7 +1709,7 @@ def window_clients(binary, gui_binary):
scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn'
scratch.mkdir(parents=True, exist_ok=True)
root = Path(tempfile.mkdtemp(prefix='wc-', dir=os.environ.get('TMPDIR') or scratch))
- env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k}
+ env = base_env()
env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'),
TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1')
(root / 'config' / 'pardes').mkdir(parents=True)
@@ -1737,7 +1761,7 @@ def window_clients(binary, gui_binary):
if not rtt:
# Its clients are no sessions of the daemon's.
listed = sessions_listed(binary, env, root)
- assert [(n, k) for n, _, k in listed] == [('files', '(tty, detached)')], listed
+ assert [(n, k) for n, _, k in listed] == [('files', listed_as('detached'))], listed
# Moved and scrolled, its own view only: agreed again.
n = len(checks(check))
w.keys(b'jjjjjkkk\x06\x06\x02')
@@ -1907,7 +1931,7 @@ def far(binary):
scratch.mkdir(parents=True, exist_ok=True)
root = Path(tempfile.mkdtemp(prefix='rf-', dir=scratch))
cache = root / 'cache'
- env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k}
+ env = base_env()
env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'),
XDG_CACHE_HOME=str(cache), TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash',
PARDES_NOTIME='1', PARDES_REPLICA_FAR='1')
@@ -2074,7 +2098,7 @@ def far_flood(binary):
scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn'
scratch.mkdir(parents=True, exist_ok=True)
root = Path(tempfile.mkdtemp(prefix='fl-', dir=os.environ.get('TMPDIR') or scratch))
- env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k}
+ env = base_env()
env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'),
XDG_CACHE_HOME=str(root / 'cache'), TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash',
PARDES_NOTIME='1')
@@ -2149,7 +2173,7 @@ def by_hash(binary):
scratch.mkdir(parents=True, exist_ok=True)
root = Path(tempfile.mkdtemp(prefix='rh-', dir=scratch))
cache = root / 'cache'
- env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k}
+ env = base_env()
env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'),
XDG_CACHE_HOME=str(cache), TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1')
(root / 'config' / 'pardes').mkdir(parents=True)
@@ -2235,7 +2259,7 @@ def games(binary, libs, secs=10):
scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn'
scratch.mkdir(parents=True, exist_ok=True)
root = Path(tempfile.mkdtemp(prefix='rg-', dir=scratch))
- env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k}
+ env = base_env()
env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'), XDG_DATA_HOME=str(root / 'data'),
TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1')
(root / 'config' / 'pardes').mkdir(parents=True)
@@ -2346,7 +2370,7 @@ def far_find(binary):
scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn'
scratch.mkdir(parents=True, exist_ok=True)
root = Path(tempfile.mkdtemp(prefix='rq-', dir=scratch))
- env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k}
+ env = base_env()
env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'), XDG_DATA_HOME=str(root / 'data'),
TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1', PARDES_REPLICA_FAR='1')
(root / 'config' / 'pardes').mkdir(parents=True)
@@ -2406,14 +2430,16 @@ def far_find(binary):
def restore_client(binary):
- """A Restore while a client is attached: the client is let go (its link
- ends), the replacement core is the session's (its tape adopts it, its
- options keep none), and a client attached after agrees with it, its
- keys reaching it."""
+ """A Restore while a client is attached: the client is told and joins
+ the restored session again by itself (P44, as at an Upgrade), saying
+ nothing on its screen; its keys reach the replacement core (the
+ session's: its tape adopts it, its options keep none) and it agrees with
+ it, as does a client attached after. A 9P connection is the old core's:
+ cut, dialled again."""
scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn'
scratch.mkdir(parents=True, exist_ok=True)
root = Path(tempfile.mkdtemp(prefix='rr-', dir=scratch))
- env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k}
+ env = base_env()
env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'), XDG_DATA_HOME=str(root / 'data'),
TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1')
(root / 'config' / 'pardes').mkdir(parents=True)
@@ -2438,23 +2464,36 @@ def restore_client(binary):
wait_for(f'client {name}\'s first frame', lambda: b'line 3 of the notes' in t.text(), timeout=30)
time.sleep(.3)
return t, c
- t, c = client('a')
+ ta, ca = client('a')
nine.write(f'/pane/{text}/exec', b'Dump\n')
nine.write(f'/pane/{text}/exec', b'Restore\n')
- wait_for('client a let go at the Restore', lambda: c.poll() is not None, timeout=30)
- # The 9P link was the old core's.
+
+ def cut():
+ try:
+ nine.read('/index')
+ return False
+ except (OSError, EOFError):
+ return True
+ wait_for('the 9P connection cut at the Restore', cut, timeout=30)
nine.socket.close()
nine = reconnect(root / 'pardes-9p-back.sock')
text = next(int(row.split()[0]) for row in nine.read('/index').splitlines() if row.split()[1] == b'text')
- t, c = client('r')
- os.write(t.master, b'Oafter the restore\x1b')
texts = lambda: b''.join(nine.read(f'/pane/{row.split()[0].decode()}/body') for row in nine.read('/index').splitlines()
if row.split()[1] == b'text')
- wait_for('the client\'s keys in the restored session', lambda: b'after the restore' in texts(), timeout=30)
+ # Client a, joined again by itself: its keys in the restored core.
+ os.write(ta.master, b'Oa after the restore\x1b')
+ wait_for('client a\'s keys in the restored session', lambda: b'a after the restore' in texts(), timeout=30)
+ assert ca.poll() is None, 'client a ended at the Restore'
+ seen = len(checks(root / 'a.check'))
+ wait_for('client a agrees once quiet', lambda: agreed(root / 'a.check', seen), timeout=60)
+ assert b'joined again' not in ta.text(), ('a notice left on client a\'s screen', ta.text())
+ tr, cr = client('r')
+ os.write(tr.master, b'Or after the restore\x1b')
+ wait_for('client r\'s keys in the restored session', lambda: b'r after the restore' in texts(), timeout=30)
seen = len(checks(root / 'r.check'))
- wait_for('the client agrees once quiet', lambda: agreed(root / 'r.check', seen), timeout=60)
- assert c.poll() is None, 'the client ended'
- print(f'daemon: a Restore with a client attached: it was let go, and one attached after agreed ({len(checks(root / "r.check"))} checks), its keys in the restored session')
+ wait_for('client r agrees once quiet', lambda: agreed(root / 'r.check', seen), timeout=60)
+ assert ca.poll() is None and cr.poll() is None, 'a client ended'
+ print(f'daemon: a Restore with a client attached: it joined again by itself, saying nothing, its keys in the restored session and agreeing ({len(checks(root / "a.check"))} checks); the 9P connection cut; one attached after agreed ({len(checks(root / "r.check"))} checks)')
exit_session(nine, text)
sess.wait(timeout=60)
nine.socket.close()
@@ -2538,7 +2577,7 @@ def main(binary, cycles):
scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn'
scratch.mkdir(parents=True, exist_ok=True)
root = Path(tempfile.mkdtemp(prefix='rt-', dir=scratch))
- env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k}
+ env = base_env()
env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'),
TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1')
(root / 'config' / 'pardes').mkdir(parents=True)
@@ -2597,7 +2636,7 @@ def main(binary, cycles):
wait_for('the client\'s first frame', lambda: b'\x1b[?1049h' in term.text())
listed = wait_for('the client in --ps', lambda: (lambda out: f'client {c.pid} ' in out and out)(
subprocess.run([binary, '--ps'], env=env, capture_output=True, timeout=30).stdout.decode()))
- assert f'session work {session} (tty, detached)' in listed, listed
+ assert f'session work {session} {listed_as("detached")}' in listed, listed
os.write(term.master, f'echo {typed}\r'.encode())
wait_for('its keys in the shell', lambda: typed.encode() in client.read(f'/pane/{shell}/body'))
return c
@@ -2730,7 +2769,7 @@ def main(binary, cycles):
wait_for('the client\'s first frame', lambda: b'\x1b[?1049h' in term.text())
listed = wait_for('the client in --ps', lambda: (lambda out: f'client {stub.pid} ' in out and out)(
subprocess.run([binary, '--ps'], env=env, capture_output=True, timeout=30).stdout.decode()))
- assert f'session fresh {session} (tty, detached)' in listed, listed
+ assert f'session fresh {session} {listed_as("detached")}' in listed, listed
print('daemon: a session whose stub was killed outright detached, and was attached again, as a client')
# The end: the session quits, its shells hang up, its client and
@@ -2773,7 +2812,7 @@ def gui(binary, cycles):
scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn'
scratch.mkdir(parents=True, exist_ok=True)
root = Path(tempfile.mkdtemp(prefix='rtg-', dir=scratch))
- env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k}
+ env = base_env()
(root / 'caps').mkdir()
env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'),
SHELL='/bin/bash', PARDES_NOTIME='1', PARDES_TEST='1', PARDES_TEST_CAPTURE_DIR=str(root / 'caps'),
@@ -2801,7 +2840,8 @@ def gui(binary, cycles):
wait_for('the second window drawn', lambda: (root / 'second' / 'latest.ppm').exists(), timeout=20)
assert f'client {second.pid} ' in listed(), listed()
second.close()
- wait_for('the client gone from --ps', lambda: 'client ' not in listed())
+ # (a pair's own window is a client too: the second's pid is what goes)
+ wait_for('the client gone from --ps', lambda: f'client {second.pid} ' not in listed())
assert not sized(client), 'the first window stays'
assert proc.poll() is None
print('daemon: a second window on a window session a client of it (in --ps), closed alone')
@@ -2810,13 +2850,13 @@ def gui(binary, cycles):
client.write(f'/pane/{shell}/exec', b'Detach\n')
wait_for('the window closed', lambda: sized(client))
assert proc.poll() is None, 'the process carries on with no window'
- assert f'session win {proc.pid} (gui, detached)' in listed(), listed()
+ assert f'session win {proc.pid} {listed_as("detached", "gui")}' in listed(), listed()
baseline = None
for cycle in range(cycles):
w = Window(root, f'w{cycle}', [binary, 'attach'] if cycle % 2 else [binary, '--attach=win'], env)
wait_for('the client window drawn', lambda: (root / f'w{cycle}' / 'latest.ppm').exists(), timeout=20)
wait_for('the client in --ps', lambda: f'client {w.pid} ' in listed())
- assert f'session win {proc.pid} (gui, detached)' in listed(), listed()
+ assert f'session win {proc.pid} {listed_as("detached", "gui")}' in listed(), listed()
now = (fds(proc.pid), len(processes(root)))
baseline = baseline or now
assert now == baseline, (cycle, now, baseline)
@@ -2868,7 +2908,7 @@ def gui_pair(gui_binary):
scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn'
scratch.mkdir(parents=True, exist_ok=True)
root = Path(tempfile.mkdtemp(prefix='rgp-', dir=scratch))
- env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k}
+ env = base_env()
env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'),
SHELL='/bin/bash', PARDES_NOTIME='1', PARDES_DAEMON='on', TERM='xterm-256color', PARDES_PAIR='1')
(root / 'config' / 'pardes').mkdir(parents=True)
@@ -3039,7 +3079,7 @@ def upgrades(old, new):
scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn'
scratch.mkdir(parents=True, exist_ok=True)
root = Path(tempfile.mkdtemp(prefix='rtu-', dir=scratch))
- env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k}
+ env = base_env()
env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'),
TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1')
(root / 'config' / 'pardes').mkdir(parents=True)
@@ -3323,7 +3363,7 @@ def upgrade_clients(old, new):
scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn'
scratch.mkdir(parents=True, exist_ok=True)
root = Path(tempfile.mkdtemp(prefix='ruc-', dir=scratch))
- env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k}
+ env = base_env()
env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'),
TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1')
(root / 'config' / 'pardes').mkdir(parents=True)
@@ -3425,7 +3465,7 @@ def gui_upgrades(old, new):
another build."""
scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn'
root = Path(tempfile.mkdtemp(prefix='rtgu-', dir=scratch))
- env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k}
+ env = base_env()
display = Path(os.environ.get('WAYLAND_DISPLAY', 'wayland-0'))
if not display.is_absolute():
display = Path(os.environ.get('XDG_RUNTIME_DIR', f'/run/user/{os.getuid()}')) / display
@@ -3516,6 +3556,9 @@ def gui_upgrades(old, new):
if __name__ == '__main__':
+ WITH_PAIR = sys.argv[1:2] == ['--with-pair']
+ if WITH_PAIR:
+ del sys.argv[1]
# A session's state file is its HOME's, never the user's: the dumps a
# test makes there would push the user's out.
os.environ.pop('XDG_DATA_HOME', None)