返回 DeepSeek-Reasonix
shellStatus.test.ts
根目录 / desktop / electron / src / main / shellStatus.test.ts
1 import assert from "node:assert/strict";
2 import { test } from "node:test";
3 import { createConnection } from "node:net";
4 import { mkdtempSync, rmSync } from "node:fs";
5 import { tmpdir } from "node:os";
6 import { join } from "node:path";
7 import { once } from "node:events";
8 import { initialShellStatus, listenShellStatus, homeKey } from "./shellStatus.js";
9
10 test("status survives a dead service and is bounded to a read-only snapshot", async (t) => {
11 const dir = mkdtempSync(join(tmpdir(), "shell-status-"));
12 const address = process.platform === "win32" ? `\\\\.\\pipe\\reasonix-test-${process.pid}` : join(dir, "status.sock");
13 const status = initialShellStatus("C:\\Users\\Test\\desktop-shell", "v1.38.7");
14 status.lifecycle = "failed"; status.service = "exited";
15 const server = listenShellStatus(() => status, { info() {}, warn() {}, error() {} }, address);
16 t.after(() => { server.close(); rmSync(dir, { recursive: true, force: true }); });
17 await once(server, "listening");
18 const socket = createConnection(address);
19 let text = ""; socket.on("data", (data) => { text += data; });
20 await once(socket, "end");
21 assert.deepEqual(JSON.parse(text), status);
22 assert.equal(homeKey("C:\\Users\\TEST\\desktop-shell"), homeKey("c:/users/test/desktop-shell"));
23 assert.equal(Object.hasOwn(status, "token"), false);
24 });
25
25 lines TYPESCRIPT