chore: 移除网页版遗留(KV 插件发布脚本 / verify-release / 旧域名引用),插件纯函数抽到 scripts/plugin-integrity.mjs
Verify (Gitea) / gate (build · unit · facts) (push) Canceled after 4s
Verify (Gitea) / gate (build · unit · facts) (push) Canceled after 4s
This commit is contained in:
1 parent
bf29d9f9d9
commit
142a13db36
8 files changed
+97
-247
No files matched your search
@@ -8,7 +8,7 @@ const path = require('path')
|
||||
const root = path.resolve(__dirname, '..')
|
||||
|
||||
;(async () => {
|
||||
const mod = await import(path.join(root, 'scripts', 'plugins-publish.mjs'))
|
||||
const mod = await import(path.join(root, 'scripts', 'plugin-integrity.mjs'))
|
||||
|
||||
// 已知向量:sha256('abc') 的 base64
|
||||
assert.strictEqual(mod.integrityOf(Buffer.from('abc')), 'sha256-ungWv48Bz+pBQUDeXa4iI7ADYaOWF3qctBD/YfIAFa0=')
|
||||
@@ -50,36 +50,6 @@ const root = path.resolve(__dirname, '..')
|
||||
assert.strictEqual(mod.mergeIndexes([], prevIdx).length, 2, '空既有清单时等同于全新发布')
|
||||
assert.strictEqual(mod.mergeIndexes(prevIdx, []).length, 2, '不传新条目时不应丢条目')
|
||||
|
||||
// 陈旧键判定(--gc 用):只认「plugins/ 下 + 线上清单不引用」,清单自身永不列为陈旧
|
||||
const gcKeys = [
|
||||
'plugins/index.json',
|
||||
'plugins/plugin-a-plugin.111111111111.js',
|
||||
'plugins/plugin-a-plugin.999999999999.js',
|
||||
'plugins/plugin-b-plugin.222222222222.js',
|
||||
'other/keep-me.js',
|
||||
]
|
||||
const gcIndex = [
|
||||
{ id: 'a-plugin', file: 'plugin-a-plugin.111111111111.js', version: '1.0.0', integrity: 'sha256-a' },
|
||||
{ id: 'b-plugin', file: 'plugin-b-plugin.222222222222.js', version: '1.0.0', integrity: 'sha256-b' },
|
||||
]
|
||||
const stale = mod.staleKeys(gcKeys, gcIndex)
|
||||
assert.deepStrictEqual(stale, ['plugins/plugin-a-plugin.999999999999.js'], '旧哈希键应判为陈旧,清单引用与 index.json 不应被判陈旧')
|
||||
assert.deepStrictEqual(mod.staleKeys(gcKeys, []), [
|
||||
'plugins/plugin-a-plugin.111111111111.js',
|
||||
'plugins/plugin-a-plugin.999999999999.js',
|
||||
'plugins/plugin-b-plugin.222222222222.js',
|
||||
], '空清单时所有插件键都陈旧(但 index.json 仍保留)')
|
||||
assert.deepStrictEqual(mod.staleKeys([], gcIndex), [], '空 KV 不应报陈旧')
|
||||
assert.deepStrictEqual(mod.staleKeys(null, null), [], '非法入参应安全返回空')
|
||||
// --keep:归档保留的插件(如 ai-chat 移出清单但字节留 KV)不得被判陈旧
|
||||
assert.deepStrictEqual(mod.staleKeys(gcKeys, gcIndex, ['a-plugin']), [], 'keep 传插件 id 时其全部哈希版本都保留')
|
||||
assert.deepStrictEqual(mod.staleKeys(gcKeys, gcIndex, ['plugins/plugin-a-plugin.999999999999.js']), [], 'keep 传完整键也应生效')
|
||||
|
||||
// 上传实现不得再依赖 wrangler(v3/v4 子命令名不同,spawnSync 必踩版本坑)
|
||||
const pubSrc = fs.readFileSync(path.join(root, 'scripts', 'plugins-publish.mjs'), 'utf8')
|
||||
assert.ok(!/spawnSync\('npx'/.test(pubSrc), '插件发布脚本不应再 spawn npx wrangler')
|
||||
assert.ok(/storage\/kv\/namespaces\//.test(pubSrc), '上传应走 Cloudflare REST API(storage/kv/namespaces)')
|
||||
|
||||
// 仓库清单本身必须是「多插件」形态的护栏:被单插件覆盖后此处直接红
|
||||
const repoIdx = JSON.parse(fs.readFileSync(path.join(root, 'plugins', 'index.json'), 'utf8'))
|
||||
assert.ok(Array.isArray(repoIdx) && repoIdx.length >= 6, 'plugins/index.json 应含全部已发布插件(当前 ≥6),被覆写成 1 个即视为事故')
|
||||
|
||||
Reference in new issue
Block a user