aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authoruser <user@clank>2026-08-15 16:13:46 +0200
committeruser <user@clank>2026-08-15 16:13:46 +0200
commitee6288a7eadeb43c83a5ab78f6c65cffa4748a53 (patch)
tree8fc137687f47a7f20f0a2766bca17cd53e0400dc /tests
parentmake coverage: a number, cheaply (diff)
downloadslosh-ee6288a7eadeb43c83a5ab78f6c65cffa4748a53.tar.gz
slosh-ee6288a7eadeb43c83a5ab78f6c65cffa4748a53.tar.xz
slosh-ee6288a7eadeb43c83a5ab78f6c65cffa4748a53.zip
sl0ppty: C-a e opens the config, in a pane, in your editor
The config watcher's whole point is the loop -- edit, save, watch the session change under you, edit again -- and the loop had a hole in the middle of it: you had to leave the session, or remember where the file lives, to start. So: one keystroke opens `$EDITOR <config>` in a new pane, down rather than across because a config file is lines and half the height beats half the width for reading them. `editor` in the config beats $EDITOR, and vi is the fallback, being the one editor a POSIX system must have -- a wrong guess you can see and change beats a pane that opens empty. The interesting part is what kind of pane it is. Panes given a command keep their corpse (D14), which is right for a dev server and wrong for this: quit the editor and you would be left dismissing a dead pane you opened thirty seconds ago. Rather than gaming that policy by giving the pane no command -- which would be a lie in the one field dump-layout and re-run read -- panes can now be *ephemeral*: a task rather than part of the session's shape. An ephemeral pane keeps no corpse and is not written into a dumped layout, so a restart does not reopen somebody's editor on a file they had finished with. That concept is the reusable half of this commit; the keybinding is the part you notice.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_edit_config.py130
1 files changed, 130 insertions, 0 deletions
diff --git a/tests/test_edit_config.py b/tests/test_edit_config.py
new file mode 100644
index 0000000..516e5da
--- /dev/null
+++ b/tests/test_edit_config.py
@@ -0,0 +1,130 @@
+#!/usr/bin/env python3
+"""C-a e opens the config in $EDITOR, in a pane of its own.
+
+The point is the loop: edit, save, watch the session change under you, edit
+again. Anything that makes you leave the session to do it — another terminal,
+or remembering where the file lives — is friction in the middle of the one
+workflow the config watcher exists for.
+
+The pane is *ephemeral*: quit the editor and it is gone. You asked for an
+editor, not for a record of having had one.
+"""
+import os
+import sys
+import tempfile
+
+from harness import Session, check, report
+
+SH = ["/bin/sh", "-c", 'printf "\\033]2;p\\007"; read x']
+
+# An "editor" that shows the file and stays up, and one that quits when told.
+SHOWS = "tail -f"
+QUITS = "sh -c 'read x; exit' --"
+
+
+def conf(text='shell "x"\n'):
+ f = tempfile.NamedTemporaryFile("w", suffix=".kdl", delete=False)
+ f.write(text)
+ f.close()
+ return f.name
+
+
+def test_it_opens_the_config_in_a_pane():
+ c = conf('shell "a-marker-only-this-test-writes"\n')
+ with Session(SH, cols=70, rows=24, config=c,
+ env={"EDITOR": SHOWS}) as s:
+ s.settle()
+ check("one pane to start", len(s.panes()) == 1)
+ s.key("e")
+ snap = s.until_text("a-marker-only-this-test-writes")
+ check("a second pane opened", len(s.panes()) == 2, str(s.panes()))
+ check("with the config file in it",
+ "a-marker-only-this-test-writes" in snap.screen(), snap.screen())
+ os.unlink(c)
+
+
+def test_the_editor_pane_goes_when_the_editor_does():
+ c = conf()
+ with Session(SH, cols=70, rows=24, config=c, env={"EDITOR": QUITS}) as s:
+ s.settle()
+ s.key("e")
+ s.settle(60)
+ check("the editor is up", len(s.panes()) == 2, str(s.panes()))
+ s.raw("q\\n")
+ s.until(lambda _: len(s.panes()) == 1)
+ check("quitting it closes the pane", len(s.panes()) == 1, str(s.panes()))
+ check("and leaves no corpse to dismiss",
+ "[process exited" not in s.snapshot().screen(),
+ s.snapshot().screen())
+ os.unlink(c)
+
+
+def test_the_config_can_name_the_editor():
+ """`editor` beats $EDITOR, for the person whose $EDITOR is something they
+ do not want a terminal pane to run."""
+ c = conf('editor "tail -f"\nshell "picked-by-the-config"\n')
+ with Session(SH, cols=70, rows=24, config=c,
+ env={"EDITOR": "definitely-not-an-editor"}) as s:
+ s.settle()
+ s.key("e")
+ snap = s.until_text("picked-by-the-config")
+ check("the config's editor is used",
+ "picked-by-the-config" in snap.screen(), snap.screen())
+ os.unlink(c)
+
+
+def test_it_is_not_written_into_a_dumped_layout():
+ """A dump is the session's shape. An editor someone had open while it was
+ taken is not part of that shape — restoring it would reopen their editor
+ on a file they had finished with."""
+ c = conf()
+ with Session(SH, cols=70, rows=24, config=c, env={"EDITOR": SHOWS}) as s:
+ s.settle()
+ s.key("e")
+ s.settle(60)
+ check("the editor is up", len(s.panes()) == 2, str(s.panes()))
+ dumped = s.api("dump-layout")["kdl"]
+ check("the dump does not carry the editor command",
+ "tail -f" not in dumped, dumped)
+ os.unlink(c)
+
+
+def test_no_room_says_so_rather_than_splitting_anyway():
+ c = conf()
+ with Session(SH, cols=70, rows=10, config=c, env={"EDITOR": SHOWS}) as s:
+ s.settle()
+ s.key("e")
+ s.settle(40)
+ check("still one pane", len(s.panes()) == 1, str(s.panes()))
+ check("and it said why", "no room" in s.snapshot().screen(),
+ s.snapshot().screen())
+ os.unlink(c)
+
+
+def test_the_cheatsheet_lists_it():
+ c = conf()
+ with Session(SH, cols=92, rows=28, config=c) as s:
+ s.settle()
+ s.send(r"\x01?")
+ s.settle()
+ screen = s.snapshot().screen()
+ check("it is on the sheet", "edit the config" in screen, screen)
+ check("under a key", "e " in screen, screen)
+ os.unlink(c)
+
+
+def test_the_control_api_can_do_it_too():
+ c = conf('shell "from-the-api"\n')
+ with Session(SH, cols=70, rows=24, config=c, env={"EDITOR": SHOWS}) as s:
+ s.settle()
+ r = s.api("edit-config")
+ check("the api reports ok", r.get("ok") is True, str(r))
+ snap = s.until_text("from-the-api")
+ check("and opened it", "from-the-api" in snap.screen(), snap.screen())
+ os.unlink(c)
+
+
+for name, fn in sorted(list(globals().items())):
+ if name.startswith("test_"):
+ fn()
+sys.exit(report())