diff options
| author | user <user@clank> | 2026-08-13 21:19:22 +0200 |
|---|---|---|
| committer | user <user@clank> | 2026-08-13 21:19:22 +0200 |
| commit | 94a1fd85e524bbe079b6ce3c8bb17295b706834c (patch) | |
| tree | cea7cd815ebb15ebac204155b4873a02bd350a52 /cli/test | |
| parent | sl0p(bar): draw the bar as a framed box, and a single line when collapsed (diff) | |
| download | sl0ppi-94a1fd85e524bbe079b6ce3c8bb17295b706834c.tar.gz sl0ppi-94a1fd85e524bbe079b6ce3c8bb17295b706834c.tar.xz sl0ppi-94a1fd85e524bbe079b6ce3c8bb17295b706834c.zip | |
cli: carry pane templates into the generated layout
`sl0ppi up` died on every session:
× Failed to parse Zellij configuration
43 │ sl0pbar size=3
· ╰── Invalid tab property: sl0pbar
The CLI writes its own layout file and inlines the tab template into each tab
-- a default_tab_template would destroy the tab purposes that are the CLI's
notion of identity -- so the generated file is standalone. The moment the
status bar became a pane_template, the inlined body referred to a name only
layouts/default.kdl knew about.
extractPaneTemplates pulls those definitions out with the same brace scanner
that already had to respect strings and comments, and both generated layouts
emit them once at the top. The result is smaller than before, too: one copy of
the bar's configuration per session instead of one per tab.
packaging/checks/sl0ppi-up-live.py runs the real thing -- CLI, binary, session,
attached client -- because the CLI's own tests are string assertions and were
all green while this was broken. It fails with exactly the user's error on the
parent commit.
Not done, deliberately, and the check says why in a comment: copying the user's
default.swap.kdl next to the generated layout to make the bar collapse on a
narrow terminal. It appears to work, and then auto_layout swaps the tab to one
of the other swap layouts, whose bare `tab` nodes expect a default_tab_template
that a generated layout does not have -- and the bar disappears entirely.
Measured on screen both ways, and the check now pins "the bar survives a
rearrangement" so nobody re-derives it from JSON.
Which is the other lesson: `action list-panes` stops reporting the borderless
plugin pane once a client is attached. It had me chasing a bar that was on
screen the whole time. dump-layout and the screen agree; list-panes does not.
Diffstat (limited to 'cli/test')
| -rw-r--r-- | cli/test/layout.test.ts | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/cli/test/layout.test.ts b/cli/test/layout.test.ts index 7a3cf69..1910529 100644 --- a/cli/test/layout.test.ts +++ b/cli/test/layout.test.ts @@ -166,3 +166,99 @@ describe("extractDefaultTabTemplate", () => { expect(applyTemplate("pane", "default_tab_template {\n pane\n}")).toBeUndefined(); }); }); + +// REGRESSION: the shipped layout moved the status bar into a `pane_template` +// (so the collapsed layout could reuse it at a different height) and every +// `sl0ppi up` died with: +// +// × Failed to parse Zellij configuration +// 43 │ sl0pbar size=3 +// · ╰── Invalid tab property: sl0pbar +// +// The generated layout is its own file: a name the template body refers to has +// to be defined in it, not merely in layouts/default.kdl. +describe("pane templates travel with the generated layout", () => { + const layoutWithPaneTemplate = `layout { + pane_template name="sl0pbar" borderless=true { + plugin location="file:~/.config/sl0ppij/plugins/zjstatus.wasm" { + format_left "{mode} {tabs} {new_tab}" + tab_active "#[fg=$bg]{index}}}{name}" + // a comment with an unbalanced { brace + } + } + + default_tab_template { + children + sl0pbar size=3 + } +}`; + + test("extracts the definition, braces and strings and all", async () => { + const { extractPaneTemplates } = await import("../src/core/layout.ts"); + const templates = extractPaneTemplates(layoutWithPaneTemplate); + + expect(templates).toHaveLength(1); + expect(templates[0]).toContain('pane_template name="sl0pbar"'); + expect(templates[0]).toContain("zjstatus.wasm"); + expect(templates[0]).not.toContain("default_tab_template"); + }); + + test("every name the tabs use is defined in the same layout", async () => { + const { extractDefaultTabTemplate, extractPaneTemplates } = await import( + "../src/core/layout.ts" + ); + const kdl = sessionLayoutKdl( + [spec], + extractDefaultTabTemplate(layoutWithPaneTemplate), + extractPaneTemplates(layoutWithPaneTemplate), + ); + + expect(kdl).toContain("sl0pbar size=3"); // the tab still uses it + expect(kdl).toContain('pane_template name="sl0pbar"'); // and it is defined here + expect(kdl.indexOf("pane_template")).toBeLessThan(kdl.indexOf("sl0pbar size=3")); + expect(kdl).toContain('purpose="project:foo"'); // identity still survives + }); + + test("single-tab layouts carry them too, for `new-tab --layout-string`", async () => { + const { extractDefaultTabTemplate, extractPaneTemplates } = await import( + "../src/core/layout.ts" + ); + const kdl = singleTabLayoutKdl( + spec, + extractDefaultTabTemplate(layoutWithPaneTemplate), + extractPaneTemplates(layoutWithPaneTemplate), + ); + expect(kdl).toContain('pane_template name="sl0pbar"'); + }); + + test("no pane templates means no preamble, as before", () => { + const kdl = sessionLayoutKdl([spec], undefined, []); + expect(kdl).not.toContain("pane_template"); + expect(kdl.trimStart().startsWith("layout {")).toBe(true); + }); + + // The one that would actually have caught it: our own shipped layout. + test("THE SHIPPED LAYOUT generates a self-contained session layout", async () => { + const { readFileSync } = await import("node:fs"); + const { extractDefaultTabTemplate, extractPaneTemplates } = await import( + "../src/core/layout.ts" + ); + const shipped = readFileSync( + new URL("../../config/layouts/default.kdl", import.meta.url), + "utf8", + ); + const kdl = sessionLayoutKdl( + [spec], + extractDefaultTabTemplate(shipped), + extractPaneTemplates(shipped), + ); + + // every bare identifier a tab body uses must be defined in this file + const used = [...kdl.matchAll(/^\s{8}([a-z_][a-z_0-9]*)\s/gm)] + .map((match) => match[1] as string) + .filter((name) => !["pane", "children", "plugin", "tab"].includes(name)); + for (const name of new Set(used)) { + expect(kdl).toContain(`pane_template name="${name}"`); + } + }); +}); |
