diff options
| author | user <user@clank> | 2026-08-13 13:06:44 +0200 |
|---|---|---|
| committer | user <user@clank> | 2026-08-13 13:06:44 +0200 |
| commit | 6d9e46274c0d7613441338e10fea6972e4d335dd (patch) | |
| tree | 02a22eeb155f1a9e3182eb9a21caf034a0bb8d40 /cli/test | |
| parent | cli: create sessions by attaching, to dodge the phantom-client bug (diff) | |
| download | sl0ppi-6d9e46274c0d7613441338e10fea6972e4d335dd.tar.gz sl0ppi-6d9e46274c0d7613441338e10fea6972e4d335dd.tar.xz sl0ppi-6d9e46274c0d7613441338e10fea6972e4d335dd.zip | |
cli: keep the status bar, so other projects are visible
Reported: only one tab for proj_a, where was proj_b? Both tabs existed --
list-tabs showed proj_b at position 1 the whole time -- but there was nothing on
screen to say so, because a generated session had NO tab bar and NO status bar.
sl0ppi passes its own `--layout` when creating a session, which replaces the
user's default layout, and the shipped config gets its chrome from
`layouts/default.kdl`'s `default_tab_template` (the zjstatus pane, which is what
draws the tab names). So a root with five projects looked exactly like a root
with one.
The obvious fix is to emit that `default_tab_template` into the generated
layout. It does not work: a templated tab comes back with `purpose=None`,
because the fork hangs a tab's purpose on the tab's root layout and templating
replaces it. Identity is load-bearing here -- with no purposes `sl0ppi ls` sees
no project tabs and `up` would happily create a second set of them. Caught by
checking list-tabs after the change rather than trusting the tab bar appearing.
So the template is INLINED instead: its body is taken, the project's panes are
substituted for its `children` node, and the result becomes the tab's contents.
The `tab` node keeps its own name/purpose/cwd, and the status bar comes along.
A template with no `children` node is skipped rather than mangled.
The extractor brace-matches by hand but respects strings and comments: a real
zjstatus template is full of `{index}` and `{name}` inside quoted format
strings, and counting those would truncate the block and emit a layout that does
not parse. It reads the live config, so a user's own default.kdl is honoured.
Verified on the test box: tab bar reads "1 proj_a 2 proj_b", tab purposes are
project:proj_a / project:proj_b, `sl0ppi ls` sees both, `up` still says "up to
date", and no phantom-client marker.
Diffstat (limited to 'cli/test')
| -rw-r--r-- | cli/test/layout.test.ts | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/cli/test/layout.test.ts b/cli/test/layout.test.ts index 4d8f7ce..7a3cf69 100644 --- a/cli/test/layout.test.ts +++ b/cli/test/layout.test.ts @@ -85,3 +85,84 @@ describe("layout wrappers", () => { expect(open).toBe(close); }); }); + +describe("extractDefaultTabTemplate", () => { + // Without the template a generated session has no tab bar at all, so a root + // with several projects looks identical to a root with one. That is what + // "shouldn't there be a proj_b tab?" turned out to be. + test("pulls the block out of a layout file", async () => { + const { extractDefaultTabTemplate } = await import("../src/core/layout.ts"); + const kdl = `layout { + default_tab_template { + children + pane size=1 borderless=true { + plugin location="file:~/x.wasm" + } + } + tab name="a" { pane } +}`; + const template = extractDefaultTabTemplate(kdl); + expect(template).toContain("children"); + expect(template).toContain("x.wasm"); + expect(template).not.toContain('tab name="a"'); + }); + + // The real zjstatus config is full of {index} / {name} inside quoted format + // strings. Counting those as braces truncates the block mid-way and yields a + // layout that will not parse. + test("ignores braces inside strings and comments", async () => { + const { extractDefaultTabTemplate } = await import("../src/core/layout.ts"); + const kdl = `layout { + default_tab_template { + children + pane { + plugin location="file:~/z.wasm" { + tab_normal "#[bg=$bg] {index} {name} {floating_indicator} " + // a comment with an unbalanced { brace + tab_active "#[fg=$bg]{index}}}{name}" + } + } + } + tab name="real" { pane } +}`; + const template = extractDefaultTabTemplate(kdl); + expect(template).toBeDefined(); + expect(template).toContain("tab_active"); + // the whole template, and nothing past it + expect(template).not.toContain('tab name="real"'); + expect(template!.startsWith("default_tab_template {")).toBe(true); + expect(template!.trimEnd().endsWith("}")).toBe(true); + // (a raw brace count would be meaningless here: the format strings contain + // {index} and }}} on purpose, which is exactly what the scanner must skip) + }); + + test("returns undefined when there is no template", async () => { + const { extractDefaultTabTemplate } = await import("../src/core/layout.ts"); + expect(extractDefaultTabTemplate('layout {\n tab name="a" { pane }\n}')).toBeUndefined(); + }); + + test("returns undefined rather than a truncated block when unbalanced", async () => { + const { extractDefaultTabTemplate } = await import("../src/core/layout.ts"); + expect(extractDefaultTabTemplate("layout {\n default_tab_template {\n children\n")).toBeUndefined(); + }); + + // A templated tab loses its purpose (the fork hangs tab purpose on the tab's + // root layout, which templating replaces), and purpose IS identity here. So + // the template is inlined into each tab rather than emitted as + // default_tab_template. + test("the template is inlined, and the tab keeps its identity", () => { + const template = 'default_tab_template {\n children\n pane size=1 { plugin location="file:~/z.wasm" }\n}'; + const kdl = sessionLayoutKdl([spec], template); + + expect(kdl).not.toContain("default_tab_template"); + expect(kdl).toContain('purpose="project:foo"'); // identity survives + expect(kdl).toContain("z.wasm"); // status bar came along + expect(kdl).toContain('purpose="agent:main"'); // the project's own panes + expect(kdl.indexOf('purpose="project:foo"')).toBeLessThan(kdl.indexOf("z.wasm")); + }); + + test("a template without a children node is skipped rather than mangled", async () => { + const { applyTemplate } = await import("../src/core/layout.ts"); + expect(applyTemplate("pane", "default_tab_template {\n pane\n}")).toBeUndefined(); + }); +}); |
