Search GitHub for a shell script that tests a zellij plugin:
gh api -X GET search/code \
-f q='zellij plugin test wasm in:file filename:*.sh' \
--jq '.total_count'
Zero.
topic:zellij-plugin returns 89 repositories as of 27 November 2026. I found no test
script in any of them, and the search above returns zero across all of GitHub. That is
not laziness, and I say that as the author of two of them. The reason is structural,
and it takes about thirty seconds to hit.
Why cargo test does not work
A zellij plugin compiles to wasm32-wasip1 and calls zellij’s host functions:
focus_or_create_tab, switch_session_with_focus, hide_self, request_permission.
Those are imports the runtime provides. Outside wasm they do not exist.
So the host target type-checks:
$ cargo check --target aarch64-apple-darwin
Finished `dev` profile [unoptimized + debuginfo] target(s) in 9.63s
And then refuses to link:
error: linking with `cc` failed: exit status: 1
= note: Undefined symbols for architecture arm64:
ld: symbol(s) not found for architecture arm64
cargo test builds a test harness binary, which links, which fails. You cannot write a
unit test for the tree logic without first decoupling it from every host call. One of
the few projects I found that tests at all,
cc-deck, documents that “The Rust tests run
natively (not on wasm32-wasip1) since the Zellij plugin SDK is not available in the test
environment”,
which is the same wall from the other side.
So the test plan, for every plugin in that list including mine, is: build it, load it, press some keys, look at the screen.
That works until you want an agent to do it. An agent needs the screen as data. I wrote about the general shape of that problem, including why plain text is not enough. This post is the zellij-specific half: the setup, the four traps that fail quietly, and the bug it found.
Standing up a session
A zellij session needs a pty. Start one under script and leave it running:
TERM=xterm-256color script -q /dev/null zellij --session test &
Then drive it from outside with the zellij CLI, which talks to the running server.
To load your plugin you need a layout file, because plugin configuration has no command-line path. Options only reach the plugin through a layout:
layout {
pane {
plugin location="file:/abs/path/to/plugin.wasm" {
expanded true
}
}
}
zellij -s test action new-tab --layout ./plugin.kdl
On first load the plugin requests permissions and the pane shows a prompt:
Plugin /path/to/plugin.wasm asks permission to:
1. Access Zellij state (Panes, Tabs and UI)
2. Change Zellij state (Panes, Tabs and UI) and run commands
3. Run commands
4. Control command line pipes and output
5. Send messages to and launch other plugins
Allow? (y/n)
Answer it, and the plugin renders.
Four traps, all silent
KDL children need their own lines. This parses:
plugin location="file:/abs/path.wasm" {
expanded true
}
This does not:
plugin location="file:/abs/path.wasm" { expanded true }
The error names a deserialization failure and points at the node, not the line break. What makes it expensive is the aftermath: the layout does not load, the session shows zellij’s startup tip pane instead, and your assertions run against that. You get a plausible failure about the wrong surface. Wait for a known string from your plugin before asserting anything.
Creating a session is not the same as attaching to one. zellij -s NAME -n layout.kdl creates a session from a layout. zellij --session X --layout Y attaches,
and fails if the session does not exist. I lost a run to this, with the session list
printed back at me as if I had asked for it.
The permission prompt appears once per plugin URL. A harness that always waits for
Allow? (y/n) hangs on the second run. Check for it, do not assume it.
zellij action launch-or-focus-plugin hangs. It never returns. I killed it after two
and a half minutes, while the same action bound to a key returned immediately. Use a
keybind.
Two input channels
This is the zellij-specific thing that cost me the most time. Input has two paths and they are not interchangeable.
Keys meant for the plugin go through zellij’s API:
zellij -s test action write-chars j
Keys meant for zellij itself, like a LaunchOrFocusPlugin binding, do not. The client
consumes those before any pane sees them, so they have to arrive as real terminal
input:
tui-test key press --session tt alt+o
Note press. tui-test key requires a subcommand, and tui-test key j writes nothing
and reports nothing.
Send a keybind through write-chars and it lands in the pane as a literal character.
Send a plugin key as terminal input and the client may eat it. Both failures look like
a plugin that ignores input.
Reading the tree
tui-test 0.1.1, released 23 October 2026,
runs your session and exposes the screen as cells rather than text. Prebuilt binaries, so
no Rust build; the download, extract and PATH steps are in
the install step of the vision post.
tui-test run --session tt --cols 90 --rows 20 -- zellij --session test
tui-test cells --session tt --json 2 2 20 1
For a tree picker the useful property is selection, which is a background colour:
y=2 SELECTED bg=['238', 'default'] > (0) zct-a
y=3 bg=['default'] - (1) Tab #1
y=4 bg=['default'] > (2) zct-b
y=5 bg=['default'] - (3) Tab #1
y=6 bg=['default'] > (4) zct-main (attached)
Press j, scan again, and the marker moves to y=3. That is a cursor test, and it is
not expressible in plain text at all.
What it found
The payoff was a bug that had been in zellij-choose-tree since a refactor, and that no
amount of looking at the screen would have revealed.
Each row in the picker gets a number shortcut. The mapping from displayed number to tree
node lives in a vector called quick_find, filled during render
(src/sessiontree.rs:204 at v0.4.2):
for (i, node) in self.nodes.iter().enumerate()
.filter(|(_, node)| node.borrow().is_shown())
{
let text = node
.borrow()
.render(keybind_generator.next(), i == self.cursor as usize);
lines.push(text);
self.quick_find.push(i);
}
It pushes. It never clears. Every render appends another copy, and switch_by_index
reads from the front.
That is harmless while the first render enumerates everything in order, because then
quick_find[i] == i. It stops being harmless when the first render shows a subset,
which is the default collapsed state.
Three sessions, plugin opened collapsed. First render shows sessions only, so
quick_find is [0, 2, 4]:
> (0) zct-a
> (1) zct-b
> (2) zct-main (attached)
Press l to expand the first session. Labels regenerate from what is now shown, but
quick_find has grown to [0, 2, 4, 0, 1, 2, 4]:
> (0) zct-a
- (1) Tab #1
> (2) zct-b
> (3) zct-main (attached)
Press 1. The label reads zct-a Tab #1, which is node 1. quick_find[1] is still
2, which is node 2, which is zct-b. The terminal title after that keypress read
Zellij (zct-b).
Every row rendered correctly. The labels renumbered correctly. Reading the screen could not have caught this in either form, cells or text: the rendered state tells you what is present, not what acting on it does. The defect was only observable by pressing a shortcut and checking where you ended up, which is the first thing you stop doing by hand. The web has its own version of that gap, where an accessibility tree called a post title and its date healthy while they rendered with 0 pixels between them.
The fix is one line, at
src/sessiontree.rs:254,
shipped in v0.5.0 on 27 November 2026:
self.quick_find.clear();
Where that leaves the 89 repos
The harness is a shell script. It starts a session under script, loads a plugin from a
generated layout, answers the permission prompt once, drives two different input
channels, and reads cell attributes back as JSON.
None of that is elegant, and none of it required a test framework that does not exist yet. If you maintain a zellij plugin, the pieces above are enough to write the first test your repo has ever had.
I packaged the zellij-specific parts as a skill so I stop rediscovering them:
zellij-plugin-testing
in laperlej/skills, installable with
claude plugin marketplace add laperlej/skills. tui-test ships its own agent guide,
which you should install rather than trust my summary of it:
tui-test skill --add