返回 DeepSeek-Reasonix
shell-css.test.mjs
根目录 / desktop / frontend / scripts / shell-css.test.mjs
1 import assert from "node:assert/strict";
2 import { readFileSync } from "node:fs";
3 import { dirname, resolve } from "node:path";
4 import { test } from "node:test";
5 import { fileURLToPath } from "node:url";
6 import { rewriteDragRegions, shellFromEnv } from "./shell-css.mjs";
7
8 const stylesPath = resolve(dirname(fileURLToPath(import.meta.url)), "../src/styles.css");
9
10 test("browser build keeps the custom property byte-for-byte", () => {
11 const css = ".tabbar{--reasonix-draggable:drag}.tabbar *{--reasonix-draggable: no-drag}";
12 assert.equal(rewriteDragRegions(css, "browser"), css);
13 });
14
15 test("electron build rewrites every drag declaration", () => {
16 const css = ".tabbar{--reasonix-draggable:drag}.tabbar *{--reasonix-draggable: no-drag}/* --reasonix-draggable marks */";
17 assert.equal(
18 rewriteDragRegions(css, "electron"),
19 ".tabbar{-webkit-app-region:drag}.tabbar *{-webkit-app-region: no-drag}/* --reasonix-draggable marks */",
20 );
21 });
22
23 test("electron keeps chrome no-drag but does not punch the titlebar with transcript boxes", () => {
24 const css = [
25 ".topicbar{--reasonix-draggable:drag}",
26 ".topicbar button{--reasonix-draggable:no-drag}",
27 ".topicbar__title-edit{--reasonix-draggable:no-drag}",
28 ".topicbar__title-input{--reasonix-draggable:no-drag}",
29 ".msg{--reasonix-draggable:no-drag}",
30 ".reasoning__head{-webkit-app-region:no-drag}",
31 ".tool__head{-webkit-app-region:no-drag}",
32 ".management-screen{--reasonix-draggable:no-drag}",
33 ".settings-modal-backdrop{--reasonix-draggable:no-drag}",
34 ".workbench-dock__tools{--reasonix-draggable:no-drag}",
35 ].join("");
36 const out = rewriteDragRegions(css, "electron");
37 assert.match(out, /\.topicbar\{-webkit-app-region:\s*drag\}/);
38 assert.match(out, /\.topicbar button\{-webkit-app-region:\s*no-drag\}/);
39 assert.match(out, /\.topicbar__title-edit\{-webkit-app-region:\s*no-drag\}/);
40 assert.match(out, /\.topicbar__title-input\{-webkit-app-region:\s*no-drag\}/);
41 assert.match(out, /\.management-screen\{-webkit-app-region:\s*no-drag\}/);
42 assert.match(out, /\.settings-modal-backdrop\{-webkit-app-region:\s*no-drag\}/);
43 assert.doesNotMatch(out, /\.msg\{[^}]*-webkit-app-region/);
44 assert.doesNotMatch(out, /\.reasoning__head\{[^}]*-webkit-app-region/);
45 assert.doesNotMatch(out, /\.tool__head\{[^}]*-webkit-app-region/);
46 assert.doesNotMatch(out, /\.workbench-dock__tools\{[^}]*-webkit-app-region/);
47 });
48
49 test("chrome selector does not match unrelated topicbar or topbar class names", () => {
50 const css = ".topicbarfoo{--reasonix-draggable:no-drag}.topbar2{--reasonix-draggable:no-drag}";
51 const out = rewriteDragRegions(css, "electron");
52 assert.equal(out, css);
53 });
54
55 test("electron stylesheet rewrite leaves transcript boxes out of app-region", () => {
56 const out = rewriteDragRegions(readFileSync(stylesPath, "utf8"), "electron");
57 assert.match(out, /\.topicbar\s*\{[^}]*-webkit-app-region:\s*drag/);
58 assert.match(out, /\.topicbar button\s*\{[^}]*-webkit-app-region:\s*no-drag/);
59 assert.match(out, /\.topicbar__title-edit\s*\{[^}]*-webkit-app-region:\s*no-drag/);
60 assert.match(out, /\.topicbar__title-input\s*\{[^}]*-webkit-app-region:\s*no-drag/);
61 assert.doesNotMatch(out, /\.msg\s*\{[^}]*-webkit-app-region/);
62 assert.doesNotMatch(out, /\.reasoning__head\s*\{[^}]*-webkit-app-region/);
63 assert.doesNotMatch(out, /\.tool__head\s*\{[^}]*-webkit-app-region/);
64 assert.doesNotMatch(out, /\.process-card__head\s*\{[^}]*-webkit-app-region/);
65 assert.doesNotMatch(out, /\.composer-modebar\s*\{[^}]*-webkit-app-region/);
66 assert.doesNotMatch(out, /\.transcript__jump-bottom[^{]*\{[^}]*-webkit-app-region/);
67 });
68
69 test("shell selection is explicit", () => {
70 assert.equal(shellFromEnv({}), "browser");
71 assert.equal(shellFromEnv({ REASONIX_SHELL: "electron" }), "electron");
72 assert.throws(() => shellFromEnv({ REASONIX_SHELL: "wails" }), "the Wails shell is retired");
73 assert.throws(() => shellFromEnv({ REASONIX_SHELL: "tauri" }));
74 });
75
75 lines Plain Text