Files
image-workbench-desktop/tests/plugin-loader-test.js
T
qiqi 3211beb706 fix(plugin): 外置旧版本不再盖住内置升级(高版本胜)v3.25.44
真实事故:资料目录 plugins/ 残留 browser 1.6.0,内置已有 1.7.0,但合并规则是外置无条件覆盖
⇒ 设置里永远显示 1.6.0 且无更新入口。

- loader 新增 compareVersions(数字分段、缺段补 0)
- 合并规则:ext / 目录插件 只在版本 >= 当前时覆盖(同版本外置胜,允许本地打补丁)
- 新增 tests/plugin-loader-test.js(1.6<1.7 / 1.10>1.9 / 1.20.6>1.9.0 / 空版本)
2026-11-20 10:00:25 +08:00

29 lines
1.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use strict'
// 插件加载器纯函数测试(src/runtime-plugin-loader.js,v3.25.44)
//
// 为什么要有:外置插件与内置同 id 时按版本取高者。
// 若比较写错(字符串比较 / 少段位 / 预发布后缀),会出现「用户资料目录里的旧插件永久盖住内置升级」——
// browser 1.6.0 盖住内置 1.7.0 的真实事故就是这条规则缺失导致的。
const assert = require('assert')
const fs = require('fs')
const path = require('path')
const vm = require('vm')
const root = path.resolve(__dirname, '..')
const sandbox = { crypto: require('crypto').webcrypto, TextEncoder, btoa: (s) => Buffer.from(s, 'binary').toString('base64') }
vm.runInNewContext(fs.readFileSync(path.join(root, 'src', 'runtime-plugin-loader.js'), 'utf8'), sandbox)
const L = sandbox.IWBRuntimePluginLoader
assert.ok(L && typeof L.compareVersions === 'function', 'compareVersions 未导出')
const cmp = L.compareVersions
assert.strictEqual(cmp('1.6.0', '1.7.0'), -1, '1.6.0 < 1.7.0')
assert.strictEqual(cmp('1.7.0', '1.6.0'), 1)
assert.strictEqual(cmp('1.7.0', '1.7.0'), 0)
assert.strictEqual(cmp('1.10.0', '1.9.9'), 1, '按数字比较而非字符串(1.10 > 1.9)')
assert.strictEqual(cmp('2', '2.0.0'), 0, '缺段按 0 补齐')
assert.strictEqual(cmp('', '1.0.0'), -1, '空版本视为 0')
assert.strictEqual(cmp('1.20.6', '1.9.0'), 1, 'annotate 这类两位数版本也要正确')
assert.strictEqual(cmp('1.0.0', '1.0'), 0)
console.log('plugin-loader checks passed(版本比较:数字分段 / 缺段补齐 / 两位数)')