跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

quit.test.mjs

86 行 · 2.7 KB历史下载
1import test from "node:test";
2import assert from "node:assert/strict";
3import { stopExitState, stopAndExit } from "./quit.js";
4test("automatic exit waits for its own successful stop and confirmed VM shutdown", () => {
5 const status = {
6 vm_running: true,
7 job: { id: "old-stop", kind: "stop", running: false, error: "" },
8 };
9 assert.equal(stopExitState(status, null), "waiting");
10 assert.equal(stopExitState(status, "new-stop"), "waiting");
11 status.job.id = "new-stop";
12 status.job.running = true;
13 assert.equal(stopExitState(status, "new-stop"), "waiting");
14 status.job.running = false;
15 assert.equal(stopExitState(status, "new-stop"), "waiting");
16 status.vm_running = false;
17 assert.equal(stopExitState(status, "new-stop"), "exit");
18 status.job.error = "VM stop failed";
19 assert.equal(stopExitState(status, "new-stop"), "failed");
20});
21
22test("exit completes without the page polling status, and ignores an old stop", async () => {
23 let exits = 0,
24 reads = 0;
25 const statuses = [
26 { vm_running: false, job: { id: "old", kind: "stop", running: false } },
27 { vm_running: true, job: { id: "wanted", kind: "stop", running: true } },
28 { vm_running: true, job: { id: "wanted", kind: "stop", running: false } },
29 { vm_running: false, job: { id: "wanted", kind: "stop", running: false } },
30 ];
31 assert.equal(
32 await stopAndExit({
33 stop: async () => ({ id: "wanted" }),
34 readStatus: async () => {
35 reads++;
36 return statuses.shift();
37 },
38 exit: async () => {
39 exits++;
40 },
41 isCancelled: () => false,
42 onStatus: () => {},
43 delay: async () => {},
44 }),
45 true,
46 );
47 assert.equal(reads, 4);
48 assert.equal(exits, 1);
49});
50test("a failed stop leaves the app open and surfaces the error", async () => {
51 await assert.rejects(
52 stopAndExit({
53 stop: async () => ({ id: "wanted" }),
54 readStatus: async () => ({
55 vm_running: true,
56 job: {
57 id: "wanted",
58 kind: "stop",
59 running: false,
60 error: "stop failed",
61 },
62 }),
63 exit: () => assert.fail("must remain open"),
64 isCancelled: () => false,
65 onStatus: () => {},
66 }),
67 /stop failed/,
68 );
69});
70test("cancelling automatic exit during a status request prevents app termination", async () => {
71 let cancelled = false;
72 const result = await stopAndExit({
73 stop: async () => ({ id: "wanted" }),
74 readStatus: async () => {
75 cancelled = true;
76 return {
77 vm_running: false,
78 job: { id: "wanted", kind: "stop", running: false },
79 };
80 },
81 exit: () => assert.fail("cancelled exit"),
82 isCancelled: () => cancelled,
83 onStatus: () => assert.fail("cancelled update"),
84 });
85 assert.equal(result, false);
86});