dsh-desktop-statusbar 3.0.5 → 3.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client.js +614 -179
- package/lib/index.js +456 -93
- package/package.json +1 -1
- package/tests/helpers/client-harness.js +86 -0
- package/tests/verify-balance.js +55 -1
- package/tests/verify-context.js +23 -3
- package/tests/verify-copy.js +6 -2
- package/tests/verify-fixes.js +30 -0
- package/tests/verify-generic-relay.js +405 -6
- package/tests/verify-magpie-quota.mjs +24 -1
- package/tests/verify-modelrow-scroll.js +669 -0
- package/tests/verify-provider-fees.js +131 -1
- package/tests/verify-relay-settings.js +1166 -115
- package/tests/verify-render.js +7 -0
- package/tests/verify.js +23 -8
package/package.json
CHANGED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 共享的客户端测试替身:把 verify-modelrow-scroll.js 与 verify-relay-settings.js
|
|
3
|
+
* 中实质重复的 React/DOM/vm 加载骨架与 DOM 树查询工具集中于此。
|
|
4
|
+
* 只做无行为差异的搬移:各测试自己的 reactStub / fakeWindow 仍由测试自行组装。
|
|
5
|
+
*/
|
|
6
|
+
const vm = require('vm');
|
|
7
|
+
const assert = require('assert');
|
|
8
|
+
|
|
9
|
+
/** 归一化 className(props 缺失也安全)。 */
|
|
10
|
+
const classOf = (node) => (node.props !== null && node.props !== undefined && typeof node.props.className === 'string' ? node.props.className : '');
|
|
11
|
+
const hasClass = (node, name) => classOf(node).split(' ').indexOf(name) !== -1;
|
|
12
|
+
|
|
13
|
+
function findAll(node, pred) {
|
|
14
|
+
const out = [];
|
|
15
|
+
(function step(one) {
|
|
16
|
+
if (one === null || one === undefined || one === true || one === false) return;
|
|
17
|
+
if (Array.isArray(one)) { one.forEach(step); return; }
|
|
18
|
+
if (typeof one !== 'object') return;
|
|
19
|
+
if (pred(one)) out.push(one);
|
|
20
|
+
(one.children || []).forEach(step);
|
|
21
|
+
})(node);
|
|
22
|
+
return out;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function textOf(node) {
|
|
26
|
+
const out = [];
|
|
27
|
+
(function step(one) {
|
|
28
|
+
if (typeof one === 'string' || typeof one === 'number') { out.push(String(one)); return; }
|
|
29
|
+
if (one === null || one === undefined || one === false || one === true) return;
|
|
30
|
+
if (Array.isArray(one)) { one.forEach(step); return; }
|
|
31
|
+
if (typeof one !== 'object') return;
|
|
32
|
+
(one.children || []).forEach(step);
|
|
33
|
+
})(node);
|
|
34
|
+
return out.join('');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** 文档替身:记录 document 级 click 监听(「点别处」逻辑用)。 */
|
|
38
|
+
function makeFakeDocument() {
|
|
39
|
+
const docClicks = [];
|
|
40
|
+
const document = {
|
|
41
|
+
documentElement: { classList: { add() {}, remove() {} } },
|
|
42
|
+
querySelector: () => null,
|
|
43
|
+
querySelectorAll: () => [],
|
|
44
|
+
createElement: () => ({ dataset: {}, style: {}, appendChild() {}, setAttribute() {}, className: '' }),
|
|
45
|
+
body: {}, head: { appendChild() {} },
|
|
46
|
+
addEventListener: (type, fn) => { if (type === 'click' && docClicks.indexOf(fn) === -1) docClicks.push(fn); },
|
|
47
|
+
removeEventListener: (type, fn) => {
|
|
48
|
+
const at = docClicks.indexOf(fn);
|
|
49
|
+
if (at !== -1) docClicks.splice(at, 1);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
return { document: document, docClicks: docClicks };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** 在 vm 沙箱里加载插桩后的 client.js,并取回 __test 导出。 */
|
|
56
|
+
function runPlugin(source, reactStub, fakeWindow, fakeDocument, reactDom) {
|
|
57
|
+
let captured = null;
|
|
58
|
+
fakeWindow.__ModuleLoader__ = { load: (entry) => { captured = entry; } };
|
|
59
|
+
const sandbox = {
|
|
60
|
+
window: fakeWindow,
|
|
61
|
+
document: fakeDocument,
|
|
62
|
+
MutationObserver: class { observe() {} disconnect() {} },
|
|
63
|
+
react: reactStub,
|
|
64
|
+
console: console, Promise: Promise, Date: Date, Math: Math, JSON: JSON, Object: Object, Array: Array,
|
|
65
|
+
Number: Number, String: String, Boolean: Boolean, Symbol: Symbol, Set: Set, Map: Map, Error: Error,
|
|
66
|
+
setTimeout: setTimeout, clearTimeout: clearTimeout,
|
|
67
|
+
requestAnimationFrame: (fn) => { fn(); return 0; },
|
|
68
|
+
cancelAnimationFrame: () => {}
|
|
69
|
+
};
|
|
70
|
+
sandbox.globalThis = sandbox;
|
|
71
|
+
vm.createContext(sandbox);
|
|
72
|
+
vm.runInContext(source, sandbox, { filename: 'client.js' });
|
|
73
|
+
assert.ok(captured !== null && captured.factory !== undefined, '插件工厂没被捕获');
|
|
74
|
+
const api = captured.factory((name) => {
|
|
75
|
+
if (name === 'react') return reactStub;
|
|
76
|
+
if (name === 'react-dom') {
|
|
77
|
+
if (reactDom !== null && reactDom !== undefined) return reactDom;
|
|
78
|
+
throw new Error('no react-dom');
|
|
79
|
+
}
|
|
80
|
+
throw new Error('unexpected require: ' + name);
|
|
81
|
+
}).__test;
|
|
82
|
+
assert.ok(api !== undefined, '__test 插桩导出没拿到');
|
|
83
|
+
return api;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
module.exports = { findAll, hasClass, classOf, textOf, makeFakeDocument, runPlugin };
|
package/tests/verify-balance.js
CHANGED
|
@@ -670,6 +670,13 @@ process.env.DSH_HOME = HOME;
|
|
|
670
670
|
set: async (ref, value) => { relaySetCalls.push([ref, value]); relayStored.set(ref, value); },
|
|
671
671
|
unset: async (ref) => { relayUnsetCalls.push(ref); relayStored.delete(ref); }
|
|
672
672
|
};
|
|
673
|
+
/* 模型页 provider 配置:orbi 有 baseURL;空白地址保存时必须保持空(地址留给首次查询自动探测)。 */
|
|
674
|
+
const relaySettingsService = {
|
|
675
|
+
describe: () => [{
|
|
676
|
+
ns: 'include:llm-pi-ai',
|
|
677
|
+
value: { providers: { orbi: { baseURL: 'https://orbi.example/v1' } } }
|
|
678
|
+
}]
|
|
679
|
+
};
|
|
673
680
|
let relayHandler = null;
|
|
674
681
|
let trustedOrigin = 'http://127.0.0.1:19387';
|
|
675
682
|
mod.apply({
|
|
@@ -686,7 +693,11 @@ process.env.DSH_HOME = HOME;
|
|
|
686
693
|
}
|
|
687
694
|
},
|
|
688
695
|
credentials: relayCredentials,
|
|
689
|
-
get: (name) =>
|
|
696
|
+
get: (name) => {
|
|
697
|
+
if (name === 'credentials') return relayCredentials;
|
|
698
|
+
if (name === 'settings') return relaySettingsService;
|
|
699
|
+
return undefined;
|
|
700
|
+
}
|
|
690
701
|
});
|
|
691
702
|
assert.ok(relayHandler !== null, 'relay config prefix route registered');
|
|
692
703
|
const relayCall = async (method, route, body, origin) => {
|
|
@@ -810,6 +821,49 @@ process.env.DSH_HOME = HOME;
|
|
|
810
821
|
assert.strictEqual(invalidListenerOrigin.status, 403, 'invalid trusted listener origin fails closed');
|
|
811
822
|
console.log('= relay POST Origin: scheme, port, opaque, malformed and invalid listener cases');
|
|
812
823
|
|
|
824
|
+
/* ===== ③-6 删除平台后同名重建不残留 token/userId/header(task-25) ===== */
|
|
825
|
+
{
|
|
826
|
+
/* 第二个平台:验证“只清被删 channel,别的 channel 凭据仍在” */
|
|
827
|
+
const keeper = Object.assign({}, ordinaryRelay, {
|
|
828
|
+
channelKey: 'relay-keeper-channel',
|
|
829
|
+
token: 'keeper-token-sentinel', userId: 'keeper-user-sentinel',
|
|
830
|
+
headers: { 'x-keeper-secret': 'keeper-header-sentinel' }
|
|
831
|
+
});
|
|
832
|
+
const keeperCreate = await relayCall('POST', relayPath, keeper, undefined);
|
|
833
|
+
assert.strictEqual(keeperCreate.status, 200, '前置:第二个平台创建成功');
|
|
834
|
+
const refKeep = relaySetCalls[relaySetCalls.length - 1][0];
|
|
835
|
+
assert.strictEqual(relayStored.has(ref), false, '前置:被删平台的 credential ref 已不存在');
|
|
836
|
+
assert.strictEqual(relayStored.has(refKeep), true, '前置:第二平台凭据已存');
|
|
837
|
+
/* 同名空配置重新添加(模拟“删除后同名新建”,只填名字) */
|
|
838
|
+
const reAdd = await relayCall('POST', relayPath, { channelKey: ordinaryRelay.channelKey }, undefined);
|
|
839
|
+
assert.strictEqual(reAdd.status, 200, '同名空配置重新添加成功');
|
|
840
|
+
assert.strictEqual(relayStored.has(ref), true, '同名重建写入显式 envelope(不靠 ambient)');
|
|
841
|
+
assert.deepStrictEqual(JSON.parse(relayStored.get(ref)), { token: '', userId: '', headers: {} },
|
|
842
|
+
'同名重建不得继承 ambient/残留 token/userId/header');
|
|
843
|
+
const rebuiltGet = await relayCall('GET', relayPath);
|
|
844
|
+
const rebuilt = rebuiltGet.body.channels.find((one) => one.channelKey === ordinaryRelay.channelKey);
|
|
845
|
+
const kept = rebuiltGet.body.channels.find((one) => one.channelKey === keeper.channelKey);
|
|
846
|
+
assert.ok(rebuilt !== undefined && kept !== undefined, '两平台都在 GET 中');
|
|
847
|
+
assert.strictEqual(rebuilt.tokenConfigured, false, '同名重建后 tokenConfigured=false');
|
|
848
|
+
assert.strictEqual(rebuilt.userIdConfigured, false, '同名重建后 userIdConfigured=false');
|
|
849
|
+
assert.strictEqual(kept.tokenConfigured, true, '另一个平台 token 仍在');
|
|
850
|
+
assert.strictEqual(kept.userIdConfigured, true, '另一个平台 userId 仍在');
|
|
851
|
+
const rebuiltText = JSON.stringify(rebuiltGet.body);
|
|
852
|
+
for (const secret of ['ambient-token-sentinel', 'ambient-user-sentinel', 'ambient-header-sentinel']) {
|
|
853
|
+
assert.strictEqual(rebuiltText.includes(secret), false, '同名重建 GET 不暴露 ambient: ' + secret);
|
|
854
|
+
}
|
|
855
|
+
/* 清理:两平台都删掉,恢复空 Map,供后续「空白 endpoint」用例 */
|
|
856
|
+
const rmRebuilt = await relayCall('POST', relayPath, { remove: true, channelKey: ordinaryRelay.channelKey }, undefined);
|
|
857
|
+
const rmKeeper = await relayCall('POST', relayPath, { remove: true, channelKey: keeper.channelKey }, undefined);
|
|
858
|
+
assert.strictEqual(rmRebuilt.status, 200, '清理:删除同名重建平台');
|
|
859
|
+
assert.strictEqual(rmKeeper.status, 200, '清理:删除第二平台');
|
|
860
|
+
assert.strictEqual(relayStored.size, 0, '清理后 credential Map 清空');
|
|
861
|
+
console.log('= 删除后同名重建:token/userId/header 不残留,其他平台凭据保留');
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
/* 空白地址保存(endpoint 保持空、token/userId 不丢、只填部分字段也保存)是协议级用例,
|
|
865
|
+
已由 tests/verify-relay-settings.js ⑧ 统一覆盖(直接驱动 updateRelayConfig);此处不再重复断言。 */
|
|
866
|
+
|
|
813
867
|
/* ============= 第三方平台余额端到端:真实 HTTP stub 验证落库字段真的被用于查询 */
|
|
814
868
|
/* 预置当天汇率,避免 /balance 顺带拉一次外部汇率打乱请求计数 */
|
|
815
869
|
const relayRateDir = path.join(process.env.DSH_HOME, 'dsh-status-bar');
|
package/tests/verify-context.js
CHANGED
|
@@ -112,8 +112,12 @@ assert.deepStrictEqual(Array.from(dash.rows), [], '空态没有图例行');
|
|
|
112
112
|
assert.deepStrictEqual(Array.from(dash.segments), [], '空态没有分段');
|
|
113
113
|
assert.strictEqual(dash.compact, null, '空态没有压缩点缺口');
|
|
114
114
|
const dashRing = api.contextRing(dash.percent, 'idle');
|
|
115
|
-
assert.strictEqual(Array.from(dashRing.children).length,
|
|
115
|
+
assert.strictEqual(Array.from(dashRing.children).length, 3, '圆环 = 底环 + 进度弧 + 环心数字');
|
|
116
116
|
assert.strictEqual(Array.from(dashRing.children)[1].props.strokeDashoffset, 2 * Math.PI * 5.5, '0% 时进度弧整段留空');
|
|
117
|
+
assert.strictEqual(Array.from(dashRing.children)[2].props.className, 'dsb-ring-percent', '第三项是环心占用数字');
|
|
118
|
+
/* 空态(没有占用数据)环心留空:contextMeter.empty === true / 没有数据时都不显示数字 */
|
|
119
|
+
assert.strictEqual(String(Array.from(dashRing.children)[2].children[0]), '', '空态环心留空');
|
|
120
|
+
assert.strictEqual(Array.from(api.contextRing(0, 'idle', null, null).children)[2].children[0], '', '没有 labelPercent 数据时环心也留空');
|
|
117
121
|
console.log('= 缺占用数据 → 空环 + 横杠(不再整块消失)');
|
|
118
122
|
|
|
119
123
|
/* ------------------------------------------------------------- 段渲染 */
|
|
@@ -141,7 +145,7 @@ assert.strictEqual(contextMeter.compact, null, '没有 capacity 时压缩点为
|
|
|
141
145
|
console.log('= 圆环带上下文占用气泡;压缩点随模型自适应;token 计数段已并入总计,峰谷可点');
|
|
142
146
|
|
|
143
147
|
/* ------------------------------------------------------------- 圆环几何 */
|
|
144
|
-
const ring = api.contextRing(62, 'idle');
|
|
148
|
+
const ring = api.contextRing(62, 'idle', null, 62);
|
|
145
149
|
assert.strictEqual(ring.type, 'svg', '圆环是 svg');
|
|
146
150
|
assert.ok(String(ring.props.className).indexOf('dsb-ring') === 0, '圆环类名');
|
|
147
151
|
const circles = Array.from(ring.children);
|
|
@@ -150,6 +154,22 @@ assert.strictEqual(circles[1].props.className, 'dsb-ring-fill', '进度弧');
|
|
|
150
154
|
assert.strictEqual(circles[1].props.transform, 'rotate(-90 7 7)', '起点在 12 点方向(整体转 -90°)');
|
|
151
155
|
assert.strictEqual(Math.round(circles[1].props.strokeDasharray), Math.round(2 * Math.PI * 5.5), '周长 = 2πr');
|
|
152
156
|
assert.strictEqual(Math.round(circles[1].props.strokeDashoffset), Math.round(2 * Math.PI * 5.5 * 0.38), '62% 时留 38% 的缺口');
|
|
157
|
+
/* 环心数字:显示**主会话自己**的占用(第 4 参 labelPercent),与弧长(第 1 参 percent)不同源。
|
|
158
|
+
用户拍板:弧长在团队运行时切到成员/深层数据,环心数字永远只显示主会话自己的百分比。 */
|
|
159
|
+
assert.strictEqual(circles[2].props.className, 'dsb-ring-percent', '环心是占用数字 text');
|
|
160
|
+
assert.strictEqual(String(circles[2].children[0]), '62', '环心数字 = labelPercent(无 % 号)');
|
|
161
|
+
assert.strictEqual(circles[2].props.fontSize, undefined, '不再写动态 fontSize(字号只由 CSS 固定 6px)');
|
|
162
|
+
assert.strictEqual(circles[2].props['aria-hidden'], 'true', '环心数字对读屏隐藏(气泡已读百分比)');
|
|
163
|
+
/* 主会话百分比 vs 团队弧长不同源:弧长 55% 但环心数字显示主会话自己的 20 */
|
|
164
|
+
const mixed = Array.from(api.contextRing(55, 'teamRunning', null, 20).children);
|
|
165
|
+
assert.ok(Math.abs(mixed[1].props.strokeDashoffset - 2 * Math.PI * 5.5 * 0.45) < 1e-9, '弧长按第 1 参 55%(团队级)');
|
|
166
|
+
assert.strictEqual(String(mixed[2].children[0]), '20', '环心数字按第 4 参 20(主会话自己),不是团队的 55');
|
|
167
|
+
/* 小数取整:32.6 → 33(四舍五入,不显示小数点) */
|
|
168
|
+
assert.strictEqual(String(Array.from(api.contextRing(32.6, 'idle', null, 32.6).children)[2].children[0]), '33', '小数四舍五入成整数');
|
|
169
|
+
assert.strictEqual(String(Array.from(api.contextRing(33.4, 'idle', null, 33.4).children)[2].children[0]), '33', '33.4 向下取整为 33');
|
|
170
|
+
/* 100 留空:14px 环心塞不下三位 */
|
|
171
|
+
assert.strictEqual(String(Array.from(api.contextRing(100, 'idle', null, 100).children)[2].children[0]), '', '达到 100 时环心留空');
|
|
172
|
+
assert.strictEqual(String(Array.from(api.contextRing(99.6, 'idle', null, 99.6).children)[2].children[0]), '', '99.6 四舍五入成 100 后同样留空');
|
|
153
173
|
assert.ok(String(api.contextRing(62, 'running').props.className).includes('dsb-ring-running'), '运行中 → 绿色');
|
|
154
174
|
assert.ok(String(api.contextRing(62, 'error').props.className).includes('dsb-ring-error'), '报错 → 红色');
|
|
155
175
|
assert.ok(String(api.contextRing(62, 'approval').props.className).includes('dsb-ring-approval'), '待审批 → 黄色');
|
|
@@ -164,7 +184,7 @@ assert.strictEqual(notchDashes.length, 3, '缺口 = 画-空-画 三段');
|
|
|
164
184
|
assert.strictEqual(notchDashes[1], 3, '空洞 = 净宽 1 + 描边 2(圆头各向洞内啃半个线宽)');
|
|
165
185
|
assert.ok(Math.abs(notchDashes[0] + notchDashes[1] + notchDashes[2] - 2 * Math.PI * 5.5) < 1e-12, '三段之和精确等于周长');
|
|
166
186
|
assert.ok(Math.abs((notchDashes[0] + notchDashes[1] / 2) - 2 * Math.PI * 5.5 * 0.550464) < 1e-12, '缺口中心落在压缩点上');
|
|
167
|
-
console.log('= 圆环:12
|
|
187
|
+
console.log('= 圆环:12 点起、周长与进度正确、颜色随状态;压缩点处开圆头缺口;环心同源显示占用数字');
|
|
168
188
|
|
|
169
189
|
/* 点击与收起的契约:圆环包在按钮里(hover/展开有灰底),面板点别处收起 */
|
|
170
190
|
const source = fs.readFileSync(PLUGIN, 'utf8');
|
package/tests/verify-copy.js
CHANGED
|
@@ -218,7 +218,10 @@ const STYLES = [
|
|
|
218
218
|
['价格行不换行(「全时段」/高峰/低谷与价格框始终同一行)', 'dsb-tier{display:flex;align-items:center;gap:8px;flex-wrap:nowrap}'],
|
|
219
219
|
['价格输入框刚好显示 XXX.XX(calc(6ch + 18px) 宽、24px 高;选择器带 input[type] 才压得住通用规则)', 'dsb-field input[type=text],.dsb-settings .dsb-field input[type=number]{width:calc(6ch + 18px);min-width:calc(6ch + 18px);flex:none;height:24px;text-align:right}'],
|
|
220
220
|
['费用倍率输入框刚好显示 xx.xx(calc(5ch + 18px))', 'dsb-modelrow-fee input[type=number]{width:calc(5ch + 18px);min-width:calc(5ch + 18px);text-align:left}'],
|
|
221
|
-
['
|
|
221
|
+
['平台模型下拉 body portal 用非作用域选择器 + fixed 定位(不再被 .dsb-settings 裁切)', '.dsb-modelrow-menu{box-sizing:border-box;position:fixed;'],
|
|
222
|
+
['平台模型下拉最多 3 项完整高度(max-height 3×30px+8px=98px)+ 自身滚动 + overscroll contain', ';max-width:100%;max-height:calc(3 * 30px + 8px);overflow-y:auto;overscroll-behavior:contain;scrollbar-width:none}'],
|
|
223
|
+
['平台模型下拉选项整行(宽 100% / 高 30px / 单行省略)', '.dsb-modelrow-menu .dsb-select-item{display:flex;align-items:center;width:100%;height:30px;box-sizing:border-box;padding:0 10px;'],
|
|
224
|
+
['平台模型下拉选项 hover 统一普通灰底(与 hover 变量一致)', '.dsb-modelrow-menu .dsb-select-item:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.12))}'],
|
|
222
225
|
['平台模型下拉已被其他行占用的模型灰显不可点', 'dsb-select-item-disabled{opacity:.45;cursor:not-allowed}'],
|
|
223
226
|
['厂商名 summary 行高 38px、字号 14px(3.0.4 基线即如此)', 'dsb-catalog-summary{display:flex;align-items:center;justify-content:flex-start;gap:8px;box-sizing:border-box;min-height:38px;padding:7px 2px 3px 2px;line-height:20px;color:var(--dsw-alias-label-primary);font-size:14px;font-weight:500'],
|
|
224
227
|
['实验性功能胶囊样式(6px / 999px 圆角 / 1px 轻描边 / padding 1px 3px / line-height 10px)', 'dsb-experimental-badge{padding:1px 3px;border:1px solid var(--dsw-alias-separator-primary,rgba(127,127,127,.3));border-radius:999px;font-size:6px;line-height:10px;font-weight:400'],
|
|
@@ -297,7 +300,8 @@ const GONE = [
|
|
|
297
300
|
/* 厂商目录拖拽浮层从未在 3.0.4 基线实现(当前 lib 也无 dsb-catalog-drag-*),旧断言属于超前规格,改成负断言防误加。 */
|
|
298
301
|
['厂商目录拖拽浮层(3.0.4 基线即无此实现)', 'dsb-catalog-drag-card'],
|
|
299
302
|
['厂商目录拖拽 ghost wrapper(3.0.4 基线即无此实现)', 'dsb-catalog-drag-ghost'],
|
|
300
|
-
['厂商目录拖拽克隆原行 summary(3.0.4 基线即无此实现)', 'rowNode.querySelector(".dsb-catalog-summary")']
|
|
303
|
+
['厂商目录拖拽克隆原行 summary(3.0.4 基线即无此实现)', 'rowNode.querySelector(".dsb-catalog-summary")'],
|
|
304
|
+
['模型下拉旧的作用域样式(body portal 后菜单挂到 body,已改非作用域 .dsb-modelrow-menu)', '.dsb-settings .dsb-modelrow-menu{'],
|
|
301
305
|
];
|
|
302
306
|
GONE.forEach(([label, needle]) => {
|
|
303
307
|
if (raw.indexOf(needle) >= 0) {
|
package/tests/verify-fixes.js
CHANGED
|
@@ -513,6 +513,36 @@ const bookOf = (entry) => ({ x: entry });
|
|
|
513
513
|
}
|
|
514
514
|
}
|
|
515
515
|
|
|
516
|
+
console.log('\n===== ⑯ 官方状态栏只藏官方节点:官方选择器定位 + observer 过滤 =====');
|
|
517
|
+
/* 3.0.7 用户实测两条要求:
|
|
518
|
+
① 隐藏必须**只认官方节点**:旧的"从 .dsb-root 逐层向上把非本插件兄弟节点全 display:none"
|
|
519
|
+
会把第三方插件后插入的节点也误藏。改成与 CSS 相同的官方选择器精确定位、只藏官方节点。
|
|
520
|
+
② MutationObserver 只在新增节点匹配(或包含匹配)官方选择器时重扫一次,普通流式文字变化
|
|
521
|
+
不触发,避免卡顿;卸载只还原被我们藏过的官方节点。 */
|
|
522
|
+
assert.ok(/new MutationObserver\(/.test(clientCode), '藏官方底栏必须用 MutationObserver(不能只跑一次)');
|
|
523
|
+
assert.ok(/observer\.observe\(dock,\s*\{\s*childList:\s*true/.test(clientCode), '观察 dock 的 childList 变动(不观察 attributes,避免自激)');
|
|
524
|
+
assert.ok(/observer\.disconnect\(\)/.test(clientCode), '卸载时必须断开 observer');
|
|
525
|
+
assert.ok(/hidden\.forEach\(\(prev, el\) => \{ el\.style\.display = prev; \}\)/.test(clientCode),
|
|
526
|
+
'卸载时把藏过的节点逐个还原(关侧栏/关插件都不留异常)');
|
|
527
|
+
assert.ok(/typeof MutationObserver === "function"/.test(clientCode), '老环境无 MutationObserver 时要优雅降级(退回单次清扫)');
|
|
528
|
+
/* ① 只认官方选择器:三条官方选择器都在,且用 querySelectorAll 定位;
|
|
529
|
+
不许再出现"逐层向上扫兄弟节点"的 indexOf 循环(node = parent / parent.children)。 */
|
|
530
|
+
assert.ok(/aria-label\*="上下文"/.test(clientCode) && /aria-label\*="context used"/.test(clientCode),
|
|
531
|
+
'必须用官方上下文按钮的 aria-label 选择器定位');
|
|
532
|
+
assert.ok(/span\[class\$="_root"\]>button\[aria-haspopup="dialog"\]\[class\$="_trigger"\]/.test(clientCode),
|
|
533
|
+
'必须用官方用量按钮的结构选择器(span[class$=_root]>button[..._trigger])定位');
|
|
534
|
+
assert.ok(/const OFFICIAL_SELECTORS = \[/.test(clientCode), '官方选择器应集中成一个常量表,与 CSS 同源');
|
|
535
|
+
assert.ok(/dock\.querySelectorAll\(OFFICIAL\)/.test(clientCode), '只对官方选择器匹配的节点做隐藏(querySelectorAll(OFFICIAL))');
|
|
536
|
+
assert.ok(!/while \(node && node !== dock\)/.test(clientCode),
|
|
537
|
+
'不许再有"从 .dsb-root 逐层向上到 dock"的兄弟节点清扫循环(会误藏第三方插件节点)');
|
|
538
|
+
assert.ok(!/child\.contains\(barRoot\)/.test(clientCode),
|
|
539
|
+
'不许再用 child.contains(barRoot) 判断兄弟节点并整层 display:none');
|
|
540
|
+
/* ② observer 有官方节点过滤:回调里遍历 addedNodes,touchesOfficial(node) 命中才 sweep。 */
|
|
541
|
+
assert.ok(/const touchesOfficial = \(node\)/.test(clientCode), 'observer 回调必须有"是否牵涉官方节点"的过滤函数');
|
|
542
|
+
assert.ok(/record\.addedNodes/.test(clientCode), 'observer 只检查 addedNodes(新增节点)');
|
|
543
|
+
assert.ok(/if \(relevant\) sweep\(\);/.test(clientCode), '只有新增节点牵涉官方节点时才重扫(普通文字变化不触发)');
|
|
544
|
+
console.log(' 只认官方选择器、无兄弟全隐藏循环;observer 有官方节点过滤,卸载只还原官方节点');
|
|
545
|
+
|
|
516
546
|
console.log('\nFIX REGRESSION CHECKS PASSED');
|
|
517
547
|
})().catch((error) => {
|
|
518
548
|
console.error('FIX REGRESSION CHECKS FAILED:', error && error.message ? error.message : error);
|