A local-first multi-agent app development platform, built on PenguinHarness
test(server): the terminal stream suite kills each test's shells before the next (#558)
Myriad-Dreamin9ad71b559225
diff --git a/changelog/unreleased/2026-08-30-terminal-stream-test-isolation.md b/changelog/unreleased/2026-08-30-terminal-stream-test-isolation.mdnew file mode 100644index 00000000..6c45f7b1--- /dev/null+++ b/changelog/unreleased/2026-08-30-terminal-stream-test-isolation.md@@ -0,0 +1,10 @@+# The terminal stream suite kills each test's shells before the next test++- **Date:** 2026-08-30+- **Type:** process+- **Scope:** `server`, `tooling`+- **PR:** [#558](https://github.com/Prism-Shadow/penguin-harness/pull/558)++[中文版](2026-08-30-terminal-stream-test-isolation.zh.md)++`terminal-stream.test.ts` shares one app across its tests and opened fourteen `/bin/sh` shells that nothing closed, against a registry that caps a user at twelve live shells. It fit under the cap only when enough earlier shells had exited on their own, so it passed on one runner and answered `429` on a slower one. Each test's terminals are now deleted after it, and the next test waits until the registry reports none alive.diff --git a/changelog/unreleased/2026-08-30-terminal-stream-test-isolation.zh.md b/changelog/unreleased/2026-08-30-terminal-stream-test-isolation.zh.mdnew file mode 100644index 00000000..18a80cea--- /dev/null+++ b/changelog/unreleased/2026-08-30-terminal-stream-test-isolation.zh.md@@ -0,0 +1,10 @@+# 终端流测试套件在下一条测试开始前杀掉上一条的 shell++- **Date:** 2026-08-30+- **Type:** process+- **Scope:** `server`, `tooling`+- **PR:** [#558](https://github.com/Prism-Shadow/penguin-harness/pull/558)++[English](2026-08-30-terminal-stream-test-isolation.md)++`terminal-stream.test.ts` 的所有测试共用一个 app,一共开了十四个没人关闭的 `/bin/sh`,而注册表限制每个用户最多十二个存活 shell。只有当前面足够多的 shell 恰好自行退出时才装得下,于是它在一台 runner 上通过、在更慢的一台上答 `429`。现在每条测试结束后删除它的终端,下一条测试等注册表报告没有存活的再开始。diff --git a/packages/server/test/terminal-stream.test.ts b/packages/server/test/terminal-stream.test.tsindex 2fcbcd96..d7c9f827 100644--- a/packages/server/test/terminal-stream.test.ts+++ b/packages/server/test/terminal-stream.test.ts@@ -7,7 +7,7 @@* and hostile-input tolerance. These are the promises the web dock and /terminal page are* built on.*/-import { afterAll, beforeAll, describe, expect, it } from "vitest";+import { afterAll, afterEach, beforeAll, describe, expect, it } from "vitest";import { serve } from "@hono/node-server";import type { Server as HttpServer } from "node:http";import { WebSocket } from "ws";@@ -59,6 +59,31 @@ beforeAll(async () => {});});+/**+ * Every test's shells are killed before the next one starts. The suite shares one app, and+ * the terminal registry caps a user at MAX_TERMINALS_PER_USER LIVE shells: fourteen tests+ * each opening a /bin/sh that nothing closes only fit under that cap when enough earlier+ * shells happened to exit first — which is why the suite passed on one runner and answered+ * 429 on a slower one. A kill is a signal, not an exit, so this waits for the registry to+ * report none alive rather than trusting the DELETE.+ */+afterEach(async () => {+ if (IS_WINDOWS) return;+ const listed = (await (await api.get("/api/terminals")).json()) as {+ terminals: TerminalInfoJson[];+ };+ for (const terminal of listed.terminals) await api.delete(`/api/terminals/${terminal.id}`);+ const deadline = Date.now() + 5000;+ for (;;) {+ const now = (await (await api.get("/api/terminals")).json()) as {+ terminals: TerminalInfoJson[];+ };+ if (!now.terminals.some((terminal) => terminal.alive)) return;+ if (Date.now() > deadline) throw new Error("terminals from the previous test are still alive");+ await new Promise((resolve) => setTimeout(resolve, 50));+ }+});+afterAll(async () => {if (IS_WINDOWS) return;await new Promise<void>((resolve) => server.close(() => resolve()));