From 743d64cebbfb335e4e26a418b0d7bda4568cf413 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20Bene=C5=A1?= Date: Tue, 1 Dec 2026 19:30:27 +0000 Subject: [PATCH] terminal: lembas run --terminal-context end to end; the publisher's session reset said plainly Co-Authored-By: Claude Fable 5.2 --- src/terminal/uservars.ts | 6 ++++-- tests/terminal.test.ts | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/terminal/uservars.ts b/src/terminal/uservars.ts index 2fb8c37..038b231 100644 --- a/src/terminal/uservars.ts +++ b/src/terminal/uservars.ts @@ -94,8 +94,10 @@ export class StatePublisher { else if (e.type === "usage" && !e.child) { this.used = e.used ?? e.usage.input + e.usage.output this.total = e.context - } else if (e.type === "session" || e.type === "compacted") { - if (e.type === "session") (this.used = undefined), (this.total = undefined) + } else if (e.type === "session") { + // Another session: its window is not known yet. + this.used = undefined + this.total = undefined } else if (e.type === "done") this.phase = null else if (e.type === "task" && e.state === "end") this.readSpend() this.schedule() diff --git a/tests/terminal.test.ts b/tests/terminal.test.ts index e2107fa..5f14467 100644 --- a/tests/terminal.test.ts +++ b/tests/terminal.test.ts @@ -587,3 +587,21 @@ test("lembas --version is unchanged; --version --json is one object; run --termi expect(usage.status).toBe(2) expect(usage.out).toBe("") }) + +test("lembas run --terminal-context: the chip on the screen, the block in the message, the file gone", async () => { + const dir = setup([{ chunks: [delta({ content: "It failed in the oven test." }, "stop"), usage(50, 5)] }]) + const f = contextFile() + const { LLEMBAS_TTY_PANE: _b, LLEMBAS_TTY_EXECUTABLE: _c, TMUX: _t, ...rest } = process.env + const p = Bun.spawn(["bun", join(import.meta.dir, "..", "src", "cli.ts"), "run", "--no-store", "--terminal-context", f, "why did it fail?"], { cwd: dir, env: { ...rest, LLEMBAS_TTY: "1.0.0" } as Record, stdin: "ignore", stdout: "pipe", stderr: "pipe" }) + const [out, err, status] = await Promise.all([new Response(p.stdout).text(), new Response(p.stderr).text(), p.exited]) + expect({ status, err: err.includes("terminal context: 1 command from pane 7") }).toEqual({ status: 0, err: true }) + expect(out + err).toContain("It failed in the oven test.") + // The content is in the message, never on the screen. + expect(out + err).not.toContain("FAIL src/oven.test.ts") + const sent = fake!.requests.find((r) => JSON.stringify(r.messages).includes("why did it fail?"))! + expect(JSON.stringify(sent.messages.at(-1))).toContain("\\nWhat the person's terminal showed when they sent this (pane 7).") + expect(JSON.stringify(sent.messages.at(-1))).toContain("FAIL src/oven.test.ts") + // No program was named: the tools are in no list. + expect(names(sent)).not.toContain("terminal_run") + expect(existsSync(f)).toBe(false) +})