Files
image-workbench-desktop/tests/plugin-manifest-hashes-test.js
qiqi ea1e865426 fix(promptlib): 1.14.1 修正 manifest.files 哈希(1.14.0 市场安装报完整性校验失败)
1.14.0 改了 main.js,但 manifest.files 仍写着旧哈希 720b8aaa,客户端装载时
比对真实字节 e6e9ec6a 直接拒绝,界面显示「未加载 · 完整性校验失败」。

- plugins/promptlib/manifest.json:版本 1.14.1,files 按真实字节重算
- plugins/index.json:同步版本与三处哈希
- scripts/gen-market.js:生成市场包前断言 manifest.files == 实际字节,不符即中断
- tests/plugin-manifest-hashes-test.js:门禁守住 manifest.files / index.json 哈希与版本一致
2026-11-27 12:08:35 +08:00

55 lines
2.6 KiB
JavaScript
Raw Permalink 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'
// 插件清单哈希守卫:manifest.files / plugins/index.json 的 sha256 必须等于真实字节。
// 背景(v3.26.109):promptlib 1.14.0 改了 main.js 但 manifest.files 还写着上一版的哈希,
// 市场装下来直接「完整性校验失败(main.js 的 sha256 不符)」,用户装不上插件。
// 这里在门禁里盯住源码侧,gen-market.js 里还有一道生成期断言。
const fs = require('fs')
const path = require('path')
const crypto = require('crypto')
const ROOT = path.join(__dirname, '..')
const PLUGINS = path.join(ROOT, 'plugins')
const sha = (buf) => crypto.createHash('sha256').update(buf).digest('hex')
let pass = 0
let fail = 0
function ok (name, cond, extra) {
if (cond) { pass++; console.log(' ✅ ' + name) } else { fail++; console.log(' ❌ ' + name + (extra ? ' —— ' + extra : '')) }
}
console.log('===== 插件清单哈希:manifest.files 必须等于真实字节 =====')
const index = JSON.parse(fs.readFileSync(path.join(PLUGINS, 'index.json'), 'utf8'))
const byId = new Map(index.map((e) => [e.id, e]))
for (const id of fs.readdirSync(PLUGINS)) {
const dir = path.join(PLUGINS, id)
if (!fs.statSync(dir).isDirectory()) continue
const manifestPath = path.join(dir, 'manifest.json')
if (!fs.existsSync(manifestPath)) continue
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'))
const bad = []
for (const [name, expect] of Object.entries(manifest.files || {})) {
const p = path.join(dir, name)
if (!fs.existsSync(p)) { bad.push(name + ' 缺失'); continue }
const actual = sha(fs.readFileSync(p))
if (actual !== String(expect).toLowerCase()) bad.push(name + ' 期望 ' + String(expect).slice(0, 8) + ' 实际 ' + actual.slice(0, 8))
}
ok('manifest.files 与字节一致:' + id, bad.length === 0, bad.join(';'))
const entry = byId.get(id)
if (!entry) continue
const badIdx = []
for (const [name, expect] of Object.entries(entry.files || {})) {
const p = path.join(dir, name)
if (!fs.existsSync(p)) { badIdx.push(name + ' 缺失'); continue }
const actual = sha(fs.readFileSync(p))
if (actual !== String(expect).toLowerCase()) badIdx.push(name + ' 期望 ' + String(expect).slice(0, 8) + ' 实际 ' + actual.slice(0, 8))
}
ok('plugins/index.json 与字节一致:' + id, badIdx.length === 0, badIdx.join(';'))
ok('版本两处一致:' + id, String(entry.version) === String(manifest.version), 'index=' + entry.version + ' manifest=' + manifest.version)
}
console.log('\nplugin manifest hash checks: ' + pass + ' 通过 / ' + fail + ' 失败')
process.exit(fail ? 1 : 0)