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 | |
| 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.
| -rw-r--r-- | Makefile | 1 | ||||
| -rw-r--r-- | cli/src/commands/workspace.ts | 41 | ||||
| -rw-r--r-- | cli/src/core/layout.ts | 145 | ||||
| -rw-r--r-- | cli/test/layout.test.ts | 96 | ||||
| -rw-r--r-- | docs/HANDOVER.md | 8 | ||||
| -rw-r--r-- | docs/roadmap.md | 30 | ||||
| -rw-r--r-- | packaging/checks/__pycache__/status-bar-live.cpython-314.pyc | bin | 0 -> 29305 bytes | |||
| -rwxr-xr-x | packaging/checks/sl0ppi-up-live.py | 214 |
8 files changed, 485 insertions, 50 deletions
@@ -110,6 +110,7 @@ check-live: dev ## Drive real sessions and check what the UI actually does packaging/checks/split-button-live.py $(FORK)/target/fastdev/$(BIN_NAME) config/config.kdl packaging/checks/plugin-permissions-live.py $(FORK)/target/fastdev/$(BIN_NAME) packaging/checks/status-bar-live.py $(FORK)/target/fastdev/$(BIN_NAME) + packaging/checks/sl0ppi-up-live.py $(FORK)/target/fastdev/$(BIN_NAME) ##@ Package diff --git a/cli/src/commands/workspace.ts b/cli/src/commands/workspace.ts index f688ce4..4724e46 100644 --- a/cli/src/commands/workspace.ts +++ b/cli/src/commands/workspace.ts @@ -15,7 +15,7 @@ import { checkFragment } from "./doctor.ts"; import { discoverProjects, LAYOUT_FILE, MARKER_DIR } from "../core/discover.ts"; import { UserError } from "../core/errors.ts"; import { - defaultTabTemplateFrom, + templatesFrom, sessionLayoutKdl, singleTabLayoutKdl, type TabSpec, @@ -39,6 +39,8 @@ export interface Context { deferCreate?: boolean; /** Cached tab template; "" means "looked, found none". */ tabTemplate?: string; + /** Cached pane_template definitions the tab template may refer to. */ + paneTemplates?: string[]; log: (message: string) => void; } @@ -48,12 +50,29 @@ export interface Context { * session shows no tab bar at all and the other projects are invisible. */ function tabTemplate(ctx: Context): string | undefined { - if (ctx.tabTemplate === undefined) { - ctx.tabTemplate = defaultTabTemplateFrom(sl0ppijConfigDir()) ?? ""; - } + loadTemplates(ctx); return ctx.tabTemplate === "" ? undefined : ctx.tabTemplate; } +/** + * The `pane_template` definitions the tab template refers to. + * + * A generated layout is a file of its own: if the template body says + * `sl0pbar size=3`, the definition has to travel with it or the session fails + * to parse with "Invalid tab property: sl0pbar". + */ +function paneTemplates(ctx: Context): string[] { + loadTemplates(ctx); + return ctx.paneTemplates ?? []; +} + +function loadTemplates(ctx: Context): void { + if (ctx.tabTemplate !== undefined) return; + const templates = templatesFrom(sl0ppijConfigDir()); + ctx.tabTemplate = templates.tabTemplate ?? ""; + ctx.paneTemplates = templates.paneTemplates; +} + export function sl0ppijConfigDir(env: NodeJS.ProcessEnv = process.env): string { if (env.SL0PPIJ_CONFIG_DIR) return env.SL0PPIJ_CONFIG_DIR; return join(env.HOME ?? "", ".config", "sl0ppij"); @@ -189,7 +208,7 @@ export function up(ctx: Context): UpResult { // one rather than an error, so `sl0ppi` still gives you a terminal. const layout = specs.length > 0 - ? sessionLayoutKdl(specs, tabTemplate(ctx)) + ? sessionLayoutKdl(specs, tabTemplate(ctx), paneTemplates(ctx)) : "layout {\n tab name=\"scratch\" {\n pane\n }\n}\n"; const dir = mkdtempSync(join(tmpdir(), "sl0ppi-layout-")); const layoutPath = join(dir, "session.kdl"); @@ -241,7 +260,7 @@ export function up(ctx: Context): UpResult { for (const spec of specs) { try { - client.newTab(singleTabLayoutKdl(spec, tabTemplate(ctx))); + client.newTab(singleTabLayoutKdl(spec, tabTemplate(ctx), paneTemplates(ctx))); ctx.log(`+ ${spec.relPath}`); } catch (error) { const message = error instanceof Error ? error.message.split("\n")[0] : String(error); @@ -323,7 +342,9 @@ export function open(ctx: Context, name: string): TabInfo { const purpose = projectPurpose(relPath); let tab = client.listTabs().find((t) => t.purpose === purpose); if (!tab) { - const position = client.newTab(singleTabLayoutKdl(specFor(root, relPath), tabTemplate(ctx))); + const position = client.newTab( + singleTabLayoutKdl(specFor(root, relPath), tabTemplate(ctx), paneTemplates(ctx)), + ); ctx.log(`+ ${relPath}`); tab = client.listTabs().find((t) => t.position === position) ?? { position, @@ -377,5 +398,9 @@ function emptyPlan(): Plan { /** The layout sl0ppi would use for a project — for eyeballing and debugging. */ export function print(ctx: Context, name: string): string { const relPath = resolveProjectName(ctx, name); - return singleTabLayoutKdl(specFor(ctx.resolved.root, relPath), tabTemplate(ctx)); + return singleTabLayoutKdl( + specFor(ctx.resolved.root, relPath), + tabTemplate(ctx), + paneTemplates(ctx), + ); } diff --git a/cli/src/core/layout.ts b/cli/src/core/layout.ts index ec5f0da..6c2319e 100644 --- a/cli/src/core/layout.ts +++ b/cli/src/core/layout.ts @@ -35,57 +35,101 @@ export function kdlString(value: string): string { * middle and produces a layout that will not parse. */ export function extractDefaultTabTemplate(layoutKdl: string): string | undefined { - const marker = /(^|\n)\s*default_tab_template\s*\{/.exec(layoutKdl); - if (!marker) return undefined; + const found = extractBlocks(layoutKdl, /(^|\n)[ \t]*default_tab_template[ \t]*\{/g); + return found[0]; +} - const start = marker.index + marker[0].length - 1; // at the '{' - let depth = 0; - let inString = false; - let inComment = false; +/** + * Find `<head> { ... }` nodes matching `marker`, with their braces balanced. + * + * Brace-matched by hand rather than parsed, but it must respect strings and + * comments: a zjstatus template is full of `{index}` and `{name}` inside quoted + * format strings, and counting those as braces truncates the block in the + * middle and produces a layout that will not parse. + */ +function extractBlocks(layoutKdl: string, marker: RegExp): string[] { + const blocks: string[] = []; + for (const match of layoutKdl.matchAll(marker)) { + const head = match[0].replace(/^\n/, "").trim(); // e.g. `pane_template name="x" {` + const start = (match.index ?? 0) + match[0].length - 1; // at the '{' + let depth = 0; + let inString = false; + let inComment = false; - for (let i = start; i < layoutKdl.length; i++) { - const ch = layoutKdl[i] as string; - const next = layoutKdl[i + 1]; + for (let i = start; i < layoutKdl.length; i++) { + const ch = layoutKdl[i] as string; + const next = layoutKdl[i + 1]; - if (inComment) { - if (ch === "\n") inComment = false; - continue; - } - if (inString) { - if (ch === "\\") i++; // skip the escaped character - else if (ch === '"') inString = false; - continue; - } - if (ch === "/" && next === "/") { - inComment = true; - continue; - } - if (ch === '"') { - inString = true; - continue; - } - if (ch === "{") depth++; - else if (ch === "}") { - depth--; - if (depth === 0) { - return `default_tab_template ${layoutKdl.slice(start, i + 1)}`; + if (inComment) { + if (ch === "\n") inComment = false; + continue; + } + if (inString) { + if (ch === "\\") i++; // skip the escaped character + else if (ch === '"') inString = false; + continue; + } + if (ch === "/" && next === "/") { + inComment = true; + continue; + } + if (ch === '"') { + inString = true; + continue; + } + if (ch === "{") depth++; + else if (ch === "}") { + depth--; + if (depth === 0) { + const body = layoutKdl.slice(start, i + 1); + blocks.push(`${head.slice(0, -1).trim()} ${body}`); + break; + } } } + // unbalanced: better to drop this block than to emit a broken layout } - return undefined; // unbalanced: better no template than a broken layout + return blocks; } -/** The template from the user's own default layout, if they have one. */ -export function defaultTabTemplateFrom(configDir: string): string | undefined { +/** + * The `pane_template` definitions from a layout file. + * + * A generated session layout is a FILE OF ITS OWN: it does not inherit + * anything from `layouts/default.kdl`, so a template body that says `sl0pbar + * size=3` produces "Invalid tab property: sl0pbar" unless the definition comes + * along with it. That is exactly how `sl0ppi up` broke the day the status bar + * became a pane_template -- the tab template referenced a name only the + * original file knew. + */ +export function extractPaneTemplates(layoutKdl: string): string[] { + return extractBlocks(layoutKdl, /(^|\n)[ \t]*pane_template[ \t][^\n{]*\{/g); +} + +/** The tab template and the pane templates it may reference. */ +export interface LayoutTemplates { + tabTemplate?: string; + paneTemplates: string[]; +} + +/** The templates from the user's own default layout, if they have one. */ +export function templatesFrom(configDir: string): LayoutTemplates { try { - return extractDefaultTabTemplate( - readFileSync(join(configDir, "layouts", "default.kdl"), "utf8"), - ); + const kdl = readFileSync(join(configDir, "layouts", "default.kdl"), "utf8"); + return { + tabTemplate: extractDefaultTabTemplate(kdl), + paneTemplates: extractPaneTemplates(kdl), + }; } catch { - return undefined; + return { paneTemplates: [] }; } } +/** The template from the user's own default layout, if they have one. */ +export function defaultTabTemplateFrom(configDir: string): string | undefined { + return templatesFrom(configDir).tabTemplate; +} + /** * What a project gets when it has a `.sl0ppi/` marker but no `layout.kdl`. * @@ -166,13 +210,30 @@ export function tabKdl(spec: TabSpec, indentBy = 4, template?: string): string { return indent(`${head}\n${indent(fragment, 4)}\n}`, indentBy); } +/** + * Definitions the generated tabs refer to, emitted once at the top of the + * layout. Anything a tab body names has to be defined in the same file. + */ +function preamble(paneTemplates?: string[]): string { + if (!paneTemplates || paneTemplates.length === 0) return ""; + return `${paneTemplates.map((template) => indent(template, 4)).join("\n")}\n`; +} + /** A whole-session layout: what `up` passes to `--layout` when creating. */ -export function sessionLayoutKdl(specs: TabSpec[], template?: string): string { +export function sessionLayoutKdl( + specs: TabSpec[], + template?: string, + paneTemplates?: string[], +): string { const tabs = specs.map((spec) => tabKdl(spec, 4, template)).join("\n"); - return `layout {\n${tabs}\n}\n`; + return `layout {\n${preamble(paneTemplates)}${tabs}\n}\n`; } /** A one-tab layout: what `up` passes to `new-tab --layout-string`. */ -export function singleTabLayoutKdl(spec: TabSpec, template?: string): string { - return `layout {\n${tabKdl(spec, 4, template)}\n}\n`; +export function singleTabLayoutKdl( + spec: TabSpec, + template?: string, + paneTemplates?: string[], +): string { + return `layout {\n${preamble(paneTemplates)}${tabKdl(spec, 4, template)}\n}\n`; } 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}"`); + } + }); +}); diff --git a/docs/HANDOVER.md b/docs/HANDOVER.md index b1dc84e..641ac12 100644 --- a/docs/HANDOVER.md +++ b/docs/HANDOVER.md @@ -172,6 +172,14 @@ bar. See `docs/roadmap.md` for each with its measurements. template into each tab instead of emitting `default_tab_template`. - **The tab test harness does no rendering**, so `panes_to_hide` is always empty and stack-related bugs cannot be reproduced in it. Use a scripted pty. +- **`action list-panes` hides borderless plugin panes once a client attaches.** + The status bar vanishes from its output while being drawn on screen the whole + time. `dump-layout` and the screen are the truth; an hour went into a bug that + only existed in that JSON. +- **The generated layout is a file of its own.** Anything `layouts/default.kdl` + refers to -- pane templates especially -- has to be copied into it, and its + swap layouts must NOT be (see roadmap: the bar disappears when auto_layout + swaps a tab that has no `default_tab_template`). - **A hit-test that never consults the renderer is not evidence of anything.** The split button "worked" for two releases while being invisible. If an affordance is drawn, the check has to *find the glyph* and click where it diff --git a/docs/roadmap.md b/docs/roadmap.md index 4f7cfb6..068129f 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -355,6 +355,36 @@ render half a box. That one function also returns where the content line starts, and click routing reads it — which is why a click on the new box's border hits nothing instead of the widget underneath. +### `sl0ppi up` and the generated layout + +Making the bar a `pane_template` broke `sl0ppi up` outright: + +``` +× 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 its identity), +so a name the template body refers to has to travel with it. `extractPaneTemplates` +does that now, and the generated layout is smaller than before as a bonus: one +copy of the bar's configuration instead of one per tab. + +**Do not "fix" the collapsed bar in generated sessions by copying the user's +`default.swap.kdl` next to the generated layout.** It looks right — at 70 +columns the bar becomes one line — 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 completely. Measured on screen, both ways. So in a generated session +the bar stays framed on a narrow terminal; the panes still collapse, via the +synthesized stack layout. + +That measurement is also a warning about `action list-panes`: once a client is +attached it stops reporting the borderless plugin pane, which had me believing +the bar was gone in cases where it was on screen the whole time. `dump-layout` +and the screen agree; `list-panes` does not. + ### Still open on the bar Content and further click targets: a close-`x` per tab, session name → session diff --git a/packaging/checks/__pycache__/status-bar-live.cpython-314.pyc b/packaging/checks/__pycache__/status-bar-live.cpython-314.pyc Binary files differnew file mode 100644 index 0000000..0053be0 --- /dev/null +++ b/packaging/checks/__pycache__/status-bar-live.cpython-314.pyc diff --git a/packaging/checks/sl0ppi-up-live.py b/packaging/checks/sl0ppi-up-live.py new file mode 100755 index 0000000..82b84b9 --- /dev/null +++ b/packaging/checks/sl0ppi-up-live.py @@ -0,0 +1,214 @@ +#!/usr/bin/env python3 +"""Live check: `sl0ppi up` creates a real session from the SHIPPED config. + +The CLI writes its own layout file and hands it to the binary, so anything the +shipped `layouts/default.kdl` refers to has to be copied into that file. When +the status bar became a `pane_template`, every `sl0ppi up` died with + + × Failed to parse Zellij configuration + 43 │ sl0pbar size=3 + · ╰── Invalid tab property: sl0pbar + +and the CLI's own unit tests were all green, because they check strings rather +than whether zellij will parse the result. This runs the real thing. + +Usage: sl0ppi-up-live.py [path-to-sl0ppij] [path-to-zjstatus.wasm] +""" + +import fcntl +import json +import os +import pty +import shutil +import struct +import subprocess +import sys +import tempfile +import termios +import time + +HERE = os.path.dirname(os.path.abspath(__file__)) + + +def bar_on_screen(binary, session, env, cols, marker="alpha"): + """Attach a client at `cols` and report (visible, framed, last few rows). + + Borrows the screen reader from the status bar check rather than growing a + third copy of it. + """ + import importlib.util + + spec = importlib.util.spec_from_file_location( + "status_bar_live", os.path.join(HERE, "status-bar-live.py") + ) + screen = importlib.util.module_from_spec(spec) + spec.loader.exec_module(screen) + screen.COLS, screen.ROWS = cols, 30 + + pid, fd = pty.fork() + if pid == 0: + os.execvpe(binary, [binary, "attach", session], env) + fcntl.ioctl(fd, termios.TIOCSWINSZ, struct.pack("HHHH", 30, cols, 0, 0)) + os.set_blocking(fd, False) + time.sleep(4) + try: + _, rows = screen.read_screen(fd, screen.repaint(fd), seconds=10) + finally: + try: + os.close(fd) + except OSError: + pass + os.waitpid(pid, os.WNOHANG) + # the tab strip, not the mode indicator: `format_hide_on_overlength` drops + # the bar's left section first, so on a narrow terminal LOCKED is gone while + # the bar is very much there + visible = any(marker in row for row in rows[-4:]) + framed = any("\u256d" in row for row in rows[-4:]) and any("\u2570" in row for row in rows[-2:]) + return visible, framed, [row.rstrip()[:100] for row in rows if row.strip()][-4:] +REPO = os.path.abspath(os.path.join(HERE, "../..")) +BIN = os.path.abspath(sys.argv[1] if len(sys.argv) > 1 else f"{REPO}/sl0ppij/target/fastdev/sl0ppij") +WASM = os.path.abspath( + sys.argv[2] + if len(sys.argv) > 2 + else f"{REPO}/sl0pstatus/target/wasm32-wasip1/release/zjstatus.wasm" +) +CLI = f"{REPO}/cli/src/index.ts" +# the session is named after the root directory: one root, one session +SESSION = f"sl0ptest-up-{os.getpid()}" +PROJECTS = ["alpha", "beta"] + + +def main(): + for path in (BIN, WASM, CLI): + if not os.path.exists(path): + print(f"FAIL: missing {path}") + return 1 + if shutil.which("bun") is None: + print("FAIL: bun is needed to run the CLI from source") + return 1 + + tmp = tempfile.mkdtemp(prefix="sl0p-up-") + config_dir = os.path.join(tmp, "config") + shutil.copytree(os.path.join(REPO, "config"), config_dir) + os.makedirs(os.path.join(config_dir, "plugins"), exist_ok=True) + shutil.copy(WASM, os.path.join(config_dir, "plugins", "zjstatus.wasm")) + for name in ("config.kdl", "layouts/default.kdl", "layouts/default.swap.kdl"): + path = os.path.join(config_dir, name) + if os.path.isfile(path): + with open(path) as f: + text = f.read() + with open(path, "w") as f: + f.write(text.replace("~/.config/sl0ppij", config_dir)) + + root = os.path.join(tmp, SESSION) + for project in PROJECTS: + os.makedirs(os.path.join(root, project, ".sl0ppi"), exist_ok=True) + + env = dict(os.environ) + env.update( + { + "SL0PPI_BIN": BIN, + "SL0PPIJ_CONFIG_DIR": config_dir, + "SL0PPIJ_CONFIG_FILE": os.path.join(config_dir, "config.kdl"), + "SL0PPIJ_SOCKET_DIR": os.path.join(tmp, "sock"), + "SL0PPIJ_CACHE_DIR": os.path.join(tmp, "cache"), + "XDG_CACHE_HOME": os.path.join(tmp, "cache"), + "HOME": tmp, + "TERM": "xterm-256color", + "SHELL": "/bin/sh", + } + ) + + failures = [] + try: + up = subprocess.run( + ["bun", CLI, "up", "--root", root], + env=env, + capture_output=True, + text=True, + timeout=120, + ) + output = up.stdout + up.stderr + print(output.strip()[:1200]) + + # the failure mode this exists for prints a parse error and still exits 0 + for marker in ("Failed to parse", "Invalid tab property", "error:"): + if marker in output: + failures.append(f"`sl0ppi up` reported {marker!r}") + if up.returncode != 0: + failures.append(f"`sl0ppi up` exited {up.returncode}") + + tabs = subprocess.run( + [BIN, "-s", SESSION, "action", "list-tabs", "--json"], + env=env, + capture_output=True, + text=True, + timeout=60, + ).stdout + try: + names = [tab.get("name", "") for tab in json.loads(tabs)] + except Exception: + names = [] + print(f"tabs: {names}") + for project in PROJECTS: + if not any(project in name for name in names): + failures.append(f"no tab for project {project!r} (got {names})") + + # identity: the fork hangs a tab's purpose on its root layout, and the + # CLI inlines the template precisely so templating cannot eat it + # The bar has to survive a client attaching, a resize, and auto_layout + # swapping the tab around. Read from the SCREEN: `list-panes` stops + # reporting the borderless plugin pane once a client is attached, which + # is a fine way to convince yourself of a bug that is not there. + for cols, expect_framed in ((100, True), (70, True)): + visible, framed, tail = bar_on_screen(BIN, SESSION, env, cols) + print(f"at {cols} columns: bar visible={visible} framed={framed}") + if not visible: + failures.append(f"at {cols} columns the generated session shows no status bar") + print("\n".join(f" {line}" for line in tail)) + elif framed != expect_framed: + failures.append( + f"at {cols} columns the bar framed={framed}, expected {expect_framed}" + ) + + # KNOWN GAP: a generated layout has no sibling .swap.kdl, so the + # responsive collapse falls back to a synthesized stack and the bar + # keeps its full height instead of collapsing to one row. Copying the + # user's swap layouts in is NOT the fix: their `tab` nodes expect a + # default_tab_template, which the CLI does not emit (templating a tab + # destroys its purpose, and purpose is identity here), so as soon as + # auto_layout swaps the tab the bar vanishes entirely. Measured, both + # ways, on screen. + subprocess.run([BIN, "-s", SESSION, "action", "new-pane"], env=env, capture_output=True) + time.sleep(1.5) + subprocess.run([BIN, "-s", SESSION, "action", "new-pane"], env=env, capture_output=True) + time.sleep(1.5) + visible, _, tail = bar_on_screen(BIN, SESSION, env, 100) + print(f"after adding panes: bar visible={visible}") + if not visible: + failures.append("the status bar disappeared once the tab was rearranged") + print("\n".join(f" {line}" for line in tail)) + + return failures + finally: + subprocess.run([BIN, "-s", SESSION, "kill-session"], env=env, capture_output=True) + ps = subprocess.run(["ps", "-eo", "pid,comm,args"], capture_output=True, text=True).stdout + for line in ps.splitlines(): + fields = line.split(None, 2) + if len(fields) == 3 and fields[1] == os.path.basename(BIN) and tmp in fields[2]: + try: + os.kill(int(fields[0]), 15) + except (ProcessLookupError, ValueError, PermissionError): + pass + shutil.rmtree(tmp, ignore_errors=True) + + +if __name__ == "__main__": + problems = main() + if problems == 1: + sys.exit(1) + for p in problems: + print(f"FAIL: {p}") + if not problems: + print("ok: `sl0ppi up` builds a session the binary accepts") + sys.exit(1 if problems else 0) |
