跳到主要内容

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

浏览文件

cage-wheel.test.mjs

58 行 · 2.3 KB历史下载
1import assert from "node:assert/strict";
2import test from "node:test";
3import CageWheel, { cageWheelLimit, cageWheelMessage, cageWheelPacket } from "../vendor/novnc/core/cage-wheel.js";
4
5function fixture() {
6 const sent = [], frames = [];
7 const wheel = new CageWheel((...message) => sent.push(message), callback => frames.push(callback), handle => { frames[handle - 1] = null; });
8 // One display frame: run what was scheduled for it.
9 const frame = () => { for (const callback of frames.splice(0)) callback?.(); };
10 return { wheel, sent, frames, frame };
11}
12
13test("the first distance is sent at once and later ones once per frame", () => {
14 const { wheel, sent, frame } = fixture();
15 wheel.add(10, 20, 0, 120);
16 assert.deepEqual(sent, [[10, 20, 0, 120]]);
17 // A trackpad reports many small distances between two frames.
18 for (const distance of [3, 4.5, 2.25, 7]) wheel.add(11, 21, 0, distance);
19 assert.equal(sent.length, 1);
20 frame();
21 assert.deepEqual(sent[1], [11, 21, 0, 17]);
22 // The fraction of a pixel is kept, and an idle frame ends the series.
23 frame();
24 assert.equal(sent.length, 2);
25 wheel.add(12, 22, 0, 0.75);
26 assert.deepEqual(sent[2], [12, 22, 0, 1]);
27});
28
29test("distance beyond one message is carried into the next frames", () => {
30 const { wheel, sent, frame } = fixture();
31 wheel.add(1, 2, -5000, 3000);
32 frame();
33 frame();
34 frame();
35 assert.deepEqual(sent, [[1, 2, -cageWheelLimit, cageWheelLimit], [1, 2, -cageWheelLimit, 952], [1, 2, -904, 0]]);
36});
37
38test("less than a pixel waits, and stopping discards what was not sent", () => {
39 const { wheel, sent, frame, frames } = fixture();
40 wheel.add(1, 2, 0.2, 0.2);
41 assert.equal(sent.length, 0);
42 assert.equal(frames.length, 0);
43 wheel.add(1, 2, 0.4, 0);
44 assert.deepEqual(sent, [[1, 2, 1, 0]]);
45 wheel.add(1, 2, 0, 300);
46 wheel.stop();
47 frame();
48 assert.equal(sent.length, 1);
49 wheel.add(3, 4, 0, -40);
50 assert.deepEqual(sent[1], [3, 4, 0, -40]);
51});
52
53test("a message carries its position and signed distances", () => {
54 const packet = cageWheelPacket(513, 1026, -720, 2048), view = new DataView(packet.buffer);
55 assert.equal(packet.length, 14);
56 assert.deepEqual([packet[0], packet[1]], [cageWheelMessage, 0]);
57 assert.deepEqual([view.getUint16(2), view.getUint16(4), view.getInt32(6), view.getInt32(10)], [513, 1026, -720, 2048]);
58});