chore: 移除网页版遗留(KV 插件发布脚本 / verify-release / 旧域名引用),插件纯函数抽到 scripts/plugin-integrity.mjs
Verify (Gitea) / gate (build · unit · facts) (push) Canceled after 4s

This commit is contained in:
qiqi committed 2026-12-01 07:42:33 +08:00
1 parent bf29d9f9d9
commit 142a13db36
8 files changed
+97 -247

No files matched your search

+5 -5
View File
@@ -66,12 +66,12 @@ npx serve dist
## 与独立版的关系
独立版 `image-workbench-app`(Node 服务,本地 data/ 存储)功能保持一致且仍受支持;本 Web 版面向免服务器 / 免运维的部署场景。
独立版 `image-workbench-app`(Node 服务,本地 data/ 存储)功能保持一致且仍受支持。
桌面版**不再提供网页版部署**:`functions/`、`wrangler.toml`、Cloudflare Pages 发布流程与 KV 插件通道均已移除;仓库里的 `npx serve dist` 只用于本地静态预览,不是发布形态。
## 生产版本确认
```bash
curl -fsSL https://iwb.maqiart.eu.org/version.json
```
安装包是唯一发布形态:下载站 <https://download.maqiart.eu.org> ,插件市场 <https://market.maqiart.eu.org> 。
正式域名:`https://iwb.maqiart.eu.org`。稳定回滚标签的**现行语义**(`vX.Y.Z` / `stable-vX.Y.Z` / 移动可变 `stable` / `stable-verified-YYYY-MM-DD`)见 [`docs/standards/architecture-current-state.md`](docs/standards/architecture-current-state.md);历史锚点示例:`stable-v3.1.0-stability3` 等。
客户端「检查更新」读 `https://download.maqiart.eu.org/updates/latest.json`(macOS)与 `latest-windows.json`(Windows);发布后按 `PUBLISHING.md` 回读 `latest.json` / `latest-windows.json` / 下载页三处一致。稳定回滚标签的**现行语义**(`vX.Y.Z` / `stable-vX.Y.Z` / 移动可变 `stable` / `stable-verified-YYYY-MM-DD`)见 [`docs/standards/architecture-current-state.md`](docs/standards/architecture-current-state.md)。
+44 -204
View File
@@ -1,222 +1,62 @@
# 插件发布契约(给插件源码项目的交接说明)
# 插件发布(桌面版)
> 适用对象:在**另一个项目**里写插件、需要发到 Image Workbench Web 线上的人 / agent。
> 权威实现:`scripts/plugins-publish.mjs`(发布脚本)、`functions/plugins/[[path]].js`(KV 分发)、`src/plugin-host.js` + `app.js:9214`(加载与注册)。
> 最后核对:2026-11-14(新增 §8 插件节点与自定义节点体)
> 2026-12-01 重写:网页版已停用,Cloudflare Pages / Functions / `PLUGINS` KV 通道一起下线,
> `scripts/plugins-publish.sh`、`scripts/plugins-publish.mjs` 已删除。桌面版插件只走**插件市场**。
---
## 两条链路
## 0. 一句话
插件是**一个经典脚本文件**,上传到 Cloudflare KV 的 `plugins/` 下,由同源 `/plugins/index.json` 清单 + SRI 完整性校验驱动加载。**发布只用一条命令,不要手写清单。**
---
## 1. 文件与命名(硬约束)
| 约束 | 说明 |
|---|---|
| 源文件名 | **必须** `plugin-<id>.js` —— 发布脚本从文件名解析 id,不符合直接报错 |
| id 规则 | `^[a-z][a-z0-9-]{2,31}$`(小写字母开头,3–32 字符,只含 `a-z 0-9 -`) |
| 模块形态 | **必须是经典脚本(IIFE),不能是 ES Module**。宿主用 `document.createElement('script')` 注入,没有 `type="module"`,`import`/`export` 会语法错误 |
| 存储名 | 由脚本生成:`plugin-<id>.<sha256前12位>.js`(内容寻址)。**不要自己造这个名字** |
| 注册 | 必须自我注册:`window.IWBPluginHost.register(manifest, factory)`;`manifest.id` 必须**等于**文件名里的 `<id>`,否则加载后状态是 `not-registered` |
| 样式 | 用 JS 注入 `<style>` 字符串(`style-src 'self' 'unsafe-inline'` 允许);不要外链 CSS |
### CSP 限制(线上 `_headers` 实测)
```
default-src 'self'; script-src 'self'; worker-src 'self' blob:;
style-src 'self' 'unsafe-inline'; img-src 'self' https: data: blob:;
connect-src 'self' https: http://127.0.0.1:30092 http://localhost:30092 http://127.0.0.1:3425 http://localhost:3425;
object-src 'none'; base-uri 'none'; frame-ancestors 'none'
```
结论:
- ❌ 不能用 `eval` / `new Function`(`script-src` 没有 `unsafe-eval`)
- ❌ 不能内联 `<script>`、不能从 CDN 引脚本
- ✅ 可以 `fetch` 同源与任意 `https://` 接口(`connect-src` 放行)
- ✅ 可以 `data:` / `blob:` / `https:` 图片
---
## 2. manifest 必填字段(真实插件示例)
```js
;(function (global) {
'use strict'
var STYLE_ID = 'iwb-myplugin-style'
// ... 插件实现 ...
global.IWBPluginHost.register({
id: 'my-plugin', // 必须等于文件名 plugin-my-plugin.js 里的 id
name: '我的插件', // 显示名
version: '1.0.0', // 见 §4:要与清单 version 保持一致
apiVersion: 1, // 正整数,<= 宿主 API_VERSION
capabilities: ['nodeActions', 'canvas', 'canvasWrite'],
}, function (ctx) {
// ctx 提供 storage / settings / 事件订阅等,按需使用
})
})(typeof window !== 'undefined' ? window : globalThis)
```
- `capabilities` 只允许宿主声明的能力名,写未知值会被 `register` 拒绝。
- `settings` 可选,用于在插件管理里生成配置项。
---
## 3. 发布:一条命令
```bash
# 在 Image Workbench Web 仓库根目录执行(脚本在这里,运行时在 KV)
node scripts/plugins-publish.mjs /path/to/plugin-<id>.js --version <id>=1.3.0 --upload
```
脚本会依次:
1. 按 `plugin-<id>.js` 解析 id,算 `sha256` → `integrity`
2. 生成内容寻址名 `plugin-<id>.<hash12>.js`(同字节同名 ⇒ **幂等**;字节变则名变 ⇒ 客户端永不命中旧缓存)
3. **合并**既有清单:本次没传的插件原样保留,同 id 由新条目覆盖
4. `PUT` 插件字节 + `PUT` 清单到 KV(走 Cloudflare REST API,不依赖 wrangler)
5. **回读校验**:把线上 `plugins/index.json` 拉回来与本地比对,不一致直接报错
凭据:`CLOUDFLARE_API_TOKEN`(需 `Account → Workers KV Storage → Edit`)+ `CLOUDFLARE_ACCOUNT_ID`。macOS 上缺失时脚本**自动读钥匙串**(`CLOUDFLARE_PAGES_TOKEN` / `CLOUDFLARE_ACCOUNT_ID`),本机可直接跑。
先看计划不上传:去掉 `--upload` 即 dry-run,打印将写入的键。
---
## 4. 版本号:两处要一起改
| 位置 | 谁改 |
|---|---|
| 插件源码里的 `manifest.version` | 你自己改(脚本读不到源码里的 manifest) |
| 清单里的 `version` | `--version <id>=x.y.z` 改 |
`--version` **只写清单,不会改你源码里的 version**。两处不一致不会报错,但插件管理页会显示清单版本、插件内部日志显示源码版本,排查时容易误判 ⇒ 发版时同时改。
---
## 5. 绝对不要做
| ❌ 禁止 | 原因 |
|---|---|
| 手写 / 手改 `plugins/index.json` 再上传 | 会**整份覆盖** KV 清单,把别人的插件从列表里抹掉(2026-11-03 真实事故:6 个插件只剩 1 个) |
| 手填 `integrity` | 错一个字符浏览器就拒绝执行,且表现为「脚本完整性校验失败」很难查 |
| 自己造 `plugin-<id>.<hash>.js` 名字直传 | 内容寻址名必须与字节绑死,手造会破坏缓存语义 |
| 加 `--prune` | 它会把「本次没传入的插件」全部从清单删掉,只在确定要下线全部未传插件时用 |
| 用 ESM / `import` / `eval` | 经典脚本 + CSP 双杀 |
---
## 6. 上线后怎么验(3 步)
```bash
# ① 清单里有没有你的条目
curl -fsSL https://iwb.maqiart.eu.org/plugins/index.json | python3 -m json.tool | grep -A2 '"my-plugin"'
# ② 字节取得到,且 SRI 与清单一致
curl -fsSL "https://iwb.maqiart.eu.org/plugins/plugin-my-plugin.<hash12>.js" -o /tmp/p.js
echo "sha256-$(openssl dgst -sha256 -binary /tmp/p.js | openssl base64 -A)" # 应与清单 integrity 完全相同
# ③ 页面:设置 → 插件管理,找到你的插件并勾选启用
```
插件管理页的状态含义:
| 状态 | 含义 | 常见原因 |
| 链路 | 说明 | 产物 |
|---|---|---|
| `远程` / `loaded` | 已加载并注册成功 | 正常 |
| `远程·未加载` | 清单里有,但没启用 | 勾选即按需下载 |
| `远程·not-registered` | 脚本执行了但没注册 | `manifest.id` 与文件名/id 不一致,或 `register` 被拒(capabilities 未知等) |
| `远程·bad-entry` | 清单条目不可信 | `integrity` 缺失或格式不合法(fail-closed,直接拒绝) |
| `远程·failed` | 下载/校验失败 | SRI 与字节不符、404、网络 |
| 内置插件 | 随安装包发布,启动即加载 | 桌面仓 `plugins/`(`plugin-<id>.<sha12>.js` + `index.json` 带 SRI `integrity`) |
| 市场插件 | 用户按需安装 | `market/plugins/<id>-<ver>.zip` + `market/index.json`,托管在 `market.maqiart.eu.org` |
---
纯函数(`integrityOf` / `storedNameOf` / `buildIndex` / `mergeIndexes`)在 `scripts/plugin-integrity.mjs`,
由同步脚本与测试共用;加载与注册仍由 `src/plugin-host.js` + `src/runtime-plugin-loader.js` 负责。
## 7. 清理陈旧字节(可选)
内容寻址 ⇒ 插件更新后旧哈希键仍留在 KV(不再被清单引用)。
## 发布步骤
```bash
npm run plugins:gc # 只列出,不删
node scripts/plugins-publish.mjs --gc --delete --keep ai-chat # 真删(保留归档插件)
# 1) 插件源仓:改版本(package.json 与 src/index.js 里 register 的 version 必须同时改)→ 校验 → 提交
cd ~/open/github/iwb-plugins-desktop
npm run build -- <需构建的插件> # 手写单文件跳过
npm run validate # 必须 15/15
# 2) 桌面仓:同步内置产物 + 生成市场
cd ~/open/github/image-workbench-desktop
node scripts/sync-plugins-from-repo.js
node scripts/gen-market.js
node scripts/gen-market-page.js
node scripts/gen-site.js # 复制成 site/plugins-index.json 并刷新首页/插件页版本号
npm run check:plugins # 13 个插件一致性门禁(发布脚本也会自动跑)
# 3) 上传 NAS(文件是只读位,覆盖前先 rm)
scp market/index.json market/index.html [email protected]:/vol8/web/iwb-market/
scp market/plugins/<id>-<ver>.zip [email protected]:/vol8/web/iwb-market/plugins/
scp site/index.html site/plugins-index.json [email protected]:/vol8/web/iwb-download/
scp site/plugins/index.html [email protected]:/vol8/web/iwb-download/plugins/
ssh [email protected] "chmod -R a+rX /vol8/web/iwb-market /vol8/web/iwb-download"
```
判定以**线上清单**为准,不用本地清单(本地落后时会误删)。`--keep` 是必需的:`ai-chat` 属「移出清单但字节留 KV 待启用」的归档态,不加 keep 会被当垃圾删掉,想启用就得重新上传字节。
## 必须回读核验
---
不能只看命令退出码,下载站与市场都要回读:
## 8. 插件自己的节点与节点体(`capabilities: ['nodeTypes']`)
插件可以注册**自己的节点类型**,并让节点体跑自己写的 DOM 表单(`style-source` 的「样式节点」就是这套,
2026-11-14 上线测试站)。
```js
global.IWBPluginHost.register({
id: 'my-plugin',
version: '1.3.0',
// ⚠️ 能力名是 nodeTypes,但挂到 ctx 上的 key 叫 nodes(CAPABILITY_API_KEYS 的映射)。
// 写成 ctx.nodeTypes 不会报错,只会静默失效 —— 排查时最容易踩的一条。
capabilities: ['canvas', 'canvasWrite', 'nodeTypes'],
}, function (ctx) {
if (!ctx.nodes || typeof ctx.nodes.register !== 'function') return {}
ctx.nodes.register({
id: 'style', // 类型 id = plugin:my-plugin:style
title: '样式节点',
defaults: {}, // 新节点的 data 初值
ports: { in: false, out: true }, // 可覆盖;不传 = in/out 都开(只出不入就靠这条)
height: 360, // 初始高度;内容超过时宿主按实测自适应
color: '#969696', // 可覆盖序号/边框色
render: renderMyNode, // 可选;不传 = 宿主默认节点体(标题 + 文本框 + 运行按钮)
// run: async (node, host) => {...} // 可选;不传 = 节点上没有「运行」按钮
})
return {}
})
```bash
curl -s "https://market.maqiart.eu.org/index.json?t=$(date +%s)" | head -c 200
curl -s "https://download.maqiart.eu.org/plugins-index.json?t=$(date +%s)" | head -c 200
```
### 8.1 `render` 契约(插件节点体)
- 市场索引条数正确(当前 13 个),改动插件版本已更新
- 每个新 zip 的 `bundleSha256` 与线上下载字节一致
- 解包 `main.js` 确认 manifest 的 `version` 真的变了(2026-12-01 就踩过:清单升版、产物没升版)
| 项 | 规则 |
|---|---|
| 签名 | `render(node, props, host)`。`node` 是最新节点对象,`props` 与内置节点体同款(`onUpdate(id, patch)` / `busy` / `progress` / `onPreview` 等),`host` 是一个**固定不变的 div** |
| 怎么画 | 直接往 `host` 里写真实 DOM。宿主**不会**用 React 重建这个 div ⇒ 输入框不会每帧失焦 |
| 会重调 | 节点数据一变就再调一次(同一个 `host`、同一个 `node` 引用会被替换)。请做**幂等同步**:缓存自己建的元素、只改内容,**不要**每次 `innerHTML = ''` 重建,否则光标和选中会丢 |
| 输入框 | `input` / `textarea` 上务必 `pointerdown` / `mousedown` 里 `stopPropagation()`,否则宿主把这次按下当成「拖节点」,框点不进去 |
| 写回 | 一律 `props.onUpdate(node.id, patch)`;高频输入自己做防抖(300ms)+ `blur` 立刻提交,避免每次按键都写存档 |
| 正在编辑 | 重调时若 `document.activeElement` 就是那个输入框,**跳过 value 覆盖**,不然用户正在打的字会被 data 顶回旧值 |
| 清理 | 可选 `render.dispose(host)`,节点卸载时调用(解绑 window/document 级监听、停定时器) |
| 抛错 | 宿主捕获后把该节点体降级成一行提示文本,画布其余部分继续可用(不会白屏) |
| 样式 | 自己注入 `<style>`(`style-src 'unsafe-inline'` 允许);类名请加插件前缀,避免污染内置节点体 |
## 客户端安装时的校验
### 8.2 节点自带参考图(不用连一张参考图节点)
`src/runtime-plugin-market.js` 对市场条目做:zip 整体 `bundleSha256` → 逐文件 sha256(`files[]`)→ 路径白名单 → 体积/数量上限;
内置清单的 `integrity` 交给浏览器 SRI 强制校验,缺失即拒载(开发者模式的 `plugins/local/` 例外)。
节点 `data.refOn === true` 且 `data.refUrl` 有值 ⇒ 宿主在**本节点参与的任务图**里补一个伪参考图节点
(`id = <节点id>:ref`,`x/y` 取本节点坐标 ⇒ 参与「图片按 X 轴排序」这条既有规则)。
## 版本号一致性(历史事故)
- 参考图**只存 URL**,不转 base64 —— 接收方认链接,转 base64 会让存档和请求体积翻几倍。
- 它对这个节点的所有下游生效:直连生图、经组合节点、经批量、经分层节点都算。
- 典型用法:样式节点上「☑ 示例图作参考」勾上 = 多一张参考图;取消勾选 = `refOn: false`,这张图在任何下游都消失。
### 8.3 连线的白名单
插件节点要连到生图 / 组合 / 批量节点,靠的是宿主 `connectReasonOf` 那 7 条白名单。
2026-11-14 起:**`data.outKind === 'prompt'` 的节点按「提示词节点」对待**,7 条规则全部放行
(此前 `plugin:*` 只能连到少数下游)。所以「这个节点产出的是提示词文本」就显式声明
`outKind: 'prompt'`,别指望宿主猜。
---
## 9. 给插件项目的自查清单
发版前逐条打勾:
- [ ] 文件名是 `plugin-<id>.js`,id 符合 `^[a-z][a-z0-9-]{2,31}$`
- [ ] 是 IIFE 经典脚本,全文没有 `import` / `export` / `eval` / `new Function`
- [ ] 调了 `IWBPluginHost.register(manifest, factory)`,`manifest.id` 与文件名一致
- [ ] `capabilities` 只用了宿主支持的能力名
- [ ] `manifest.version` 与将要传的 `--version` 一致
- [ ] 本地 `node --check plugin-<id>.js` 通过
- [ ] 注册了节点类型的话:`capabilities` 含 `nodeTypes`,且用的是 `ctx.nodes`(不是 `ctx.nodeTypes`)
- [ ] 自定义 `render` 是幂等同步(不每帧 `innerHTML=''`)、输入框 `pointerdown` 有 `stopPropagation`
- [ ] 发布后 §6 的 3 步验证全过
- `package.json` 与 `src/index.js` 里 register 的 `version` 是两处,只改一处会让客户端自报旧版本
- 需构建的插件(image-annotate / image-vectorize)**先确认 `<id>/plugin/` 源码不落后于已提交产物**再 build,
否则重建会回退手工补的补丁(2026-12-01 实测会丢 `getNodeImage(id,{max:4096/2048})`)
+2 -2
View File
@@ -511,7 +511,7 @@ LRU 上限 + 切画板/离开画布/卸载时回收;`revokeAll()` 幂等。
| 内存行为契约 | `tests/iwb-image-memory-parity.spec.js` |
| 新写入主通道契约(`{__blob}` / 存量 `{__cache}` 兼容 / A/B 开关) | `tests/iwb-blob-write.spec.js`(2 条) |
| 守护契约编号 | `120-1 … 142-1`(见 `tests/iwb-v32-web-test.js`) |
| 发布核验工具 | `scripts/verify-release.js`(`npm run verify:release`) |
| 发布核验工具 | `publish-update.sh` / `publish-windows-update.sh` 发布后回读 `latest.json` / `latest-windows.json` |
### 13.34.7 已知残留(明确记录,避免误以为已解决)
- **JS 堆 <120MB 未经真机堆快照确认**(仅有等价 A/B 代理证据:画布 base64 → 0 ✓)。
@@ -623,7 +623,7 @@ B-② 撤销/重做后图片真能解码显示,`naturalWidth=768`)· e2e `te
**规则(三条,硬性)**:
1. **插件 = 完全可信代码,只装自己审计过的**。文档/发布说明必须**明示**这一点;不得向用户暗示"插件有沙箱 / 有权限隔离"。
2. **信任锚是「谁能写 `PLUGINS` KV」,不是客户端 SRI**。`/plugins/index.json`(清单)与插件字节**由同一 KV 提供** ⇒ 能改 KV 者可同时改插件与其 `integrity`;客户端 fail-closed 的 `integrity` 校验**只防缓存/部分损坏,不防 KV 被攻陷**。因此 `PLUGINS` KV 写权限**只给发布脚本与本人**,不交给 CI、第三方或共享凭据;发布统一走 `scripts/plugins-publish.mjs`(算 SHA-256 + 写清单 + 上传,默认 dry-run,`--upload` 才落 KV)。
2. **信任锚是「谁能写插件市场」,不是客户端 SRI**:市场索引与本机安装/内置清单校验(zip `bundleSha256` + 逐文件 sha256 + SRI `integrity`)共同定界;网页版与 KV 发布脚本已于 2026-12-01 移除,发布只走「插件源仓 → 桌面仓 sync/gen-market → NAS `/vol8/web/iwb-market`」,凭据不进 CI。
3. **合入第三方插件前先审代码**。`scripts/plugins-sync.sh` 会把插件仓产物拷成 `src/plugin-<id>.js`(可执行可信代码);**同步前必须人工审计**(脚本已在运行时打印该显式提示)。
**验证方式**:`tests/plugin-host-test.js`(宿主契约)· `tests/plugin-integrity-test.js`(清单/integrity 生成)· `tests/_plugin-host-probe.spec.js`(真实浏览器探针,`_` 前缀 dev 探针,不进 34 门禁)。
@@ -253,7 +253,7 @@ npm run verify
- 发布后记录 commit 与版本;核验 `latest.json` / `latest-windows.json` / 下载页三处一致。
- **"部署成功"≠ 验收:部署后要在真实 URL 上跑关键 e2e**(本轮做法,测试地址与正式域名各跑一遍):
```bash
IWB_BASE_URL=https://iwb.maqiart.eu.org npx playwright test tests/<关键>.spec.js
# 网页版已停用;桌面版发布后在安装包上跑 npm run test:e2e:smoke
```
同时核验 `app.js` 里的 `APP_VERSION` 与 `version.json`——只看外层退出码或"Deployment complete"会漏掉真实故障(管道 `tail` 退出码恒为 0)。
- **文档 / 发布说明里的"地址"必须是完整可点 URL**:禁止用 `站点/#iwb-tools=<暗号>` 这类**占位符**充当地址(用户会直接粘进浏览器 → 白跑一趟并以为站点坏了)。若必须举例,明确标注"占位符,非真实地址"。
@@ -266,7 +266,7 @@ npm run verify
- **CI 红灯排查顺序**:`gh run view <id> --log-failed` 看具体 job;优先怀疑 action/依赖,而不是代码。
- **构建产物已压缩打包(应用版本 v3.1.1)**:`scripts/build.js` 改为 **esbuild 逐文件 minify 再拼接** 成单个 `dist/app.js`(**不再输出 `dist/src/*`**),`style.css` 一并 minify;vendor React 保持独立、不压缩。**逐文件 minify(`transformSync`,非 `bundle`)** 是关键:拼接前每个 IIFE 已封闭,避免"整文件拼接后顶层声明重复/改名"的解析级隐患。
- **产物体检进 `verify`**:`npm run verify` 增加 `node --check dist/app.js` 与 `node scripts/check-dist.js`(断言 banner 版本 == `version.json`、`index.html` 恰 3 个 `<script>` 且无 `src/`、压缩后内嵌 Worker 字面量标记仍在)。
- **`verify-release.js` 改读 `/version.json`**(**不再**抓 `app.js` 里的 `APP_VERSION`——压缩会破坏该字符串正则,导致假失败)。
- **发布核验读产物清单**:`latest.json` / `latest-windows.json` / 下载页三处一致;网页版时代的 `verify-release.js`(读 `/version.json`)已随网页版下线一并删除。
## 11. 分层与边界
-2
View File
@@ -13,7 +13,6 @@
"test:unit": "node tests/result-img-doubleclick-test.js && node tests/gallery-audit-test.js && node tests/plugin-files-policy-test.js && node tests/theme-plugin-tokens-test.js && node tests/design-tokens-component-doc-test.js && node tests/theme-static-snapshot-test.js && node tests/overlay-layer-test.js && node tests/settings-scope-test.js && node tests/node-scope-test.js && node tests/appearance-v2-test.js && node tests/image-prompt-cover-test.js && node tests/unit-test.js && node tests/canvas-actions-test.js && node tests/canvas-performance-test.js && node tests/canvas-drag-performance-test.js && node tests/resize-observer-performance-test.js && node tests/node-drag-jank-test.js && node tests/edge-graph-performance-test.js && node tests/persistence-export-images-test.js && node tests/settings-hotkeys-size-presets-test.js && node tests/custom-size-validation-test.js && node tests/image-node-performance-test.js && node tests/drag-frame-performance-test.js && node tests/canvas-edge-memo-test.js && node tests/canvas-node-transform-test.js && node tests/canvas-dot-zoom-test.js && node tests/duplicate-ws-fresh-source-test.js && node tests/single-canvas-shell-test.js && node tests/navigation-layout-test.js && node tests/home-canvas-library-test.js && node tests/left-resource-layout-test.js && node tests/interface-hierarchy-test.js && node tests/three-page-layout-test.js && node tests/page-chrome-regression-test.js && node tests/task-cache-test.js && node tests/album-task-graph-test.js && node tests/generation-endpoint-test.js && node tests/storage-config-shape-test.js && node tests/generation-default-model-test.js && node tests/storage-zip-test.js && node tests/canvas-node-factory-test.js && node tests/runtime-error-test.js && node tests/runtime-lifecycle-test.js && node tests/runtime-fetch-test.js && node tests/runtime-channel-test.js && node tests/runtime-boundary-test.js && node tests/runtime-record-test.js && node tests/runtime-recovery-test.js && node tests/runtime-diagnostic-record-test.js && node tests/runtime-metrics-test.js && node tests/runtime-run-context-test.js && node tests/runtime-execution-context-test.js && node tests/storage-gc-canvas-refs-test.js && node tests/storage-health-test.js && node tests/generation-state-test.js && node tests/canvas-store-test.js && node tests/storage-result-test.js && node tests/storage-local-test.js && node tests/storage-domain-test.js && node tests/storage-runtime-test.js && node tests/storage-indexeddb-test.js && node tests/generation-scheduler-test.js && node tests/gallery-query-test.js && node tests/gallery-hydration-test.js && node tests/gallery-sync-test.js && node tests/image-blob-store-test.js && node tests/image-format-test.js && node tests/clipboard-graph-test.js && node tests/clipboard-graph-fallback-test.js && node tests/image-admit-test.js && node tests/image-dedupe-test.js && node tests/clipboard-kind-test.js && node tests/clipboard-paste-test.js && node tests/clipboard-copy-test.js && node tests/clipboard-native-test.js && node tests/paste-once-test.js && node tests/list-e2e-specs-test.js && node tests/desktop-csp-loopback-test.js && node tests/architecture-boundary-guard-test.js && node tests/plugin-host-test.js && node tests/plugin-data-test.js && node tests/plugin-loader-test.js && node tests/plugin-bundle-test.js && node tests/plugin-install-test.js && node tests/plugin-gallery-render-test.js && node tests/plugin-gallery-recovery-test.js && node tests/plugin-gallery-ux-test.js && node tests/plugin-grouplib-render-test.js && node tests/plugin-promptlib-render-test.js && node tests/image-compress-test.js && node tests/storage-fallback-indexeddb-test.js && node tests/canvas-normalize-test.js && node tests/canvas-geometry-test.js && node tests/canvas-history-test.js && node tests/canvas-ops-test.js && node tests/canvas-text-test.js && node tests/history-store-test.js && node tests/plugin-integrity-test.js && node tests/workspace-sessions-store-test.js && node tests/workspace-list-test.js && node tests/workspace-purge-test.js && node tests/provider-ping-test.js && node tests/runtime-diagnostics-hotpath-test.js && node tests/storage-log-failure-test.js && node tests/storage-convergence-test.js && node tests/swallow-wiring-test.js && node tests/workbench-logic-test.js && node tests/storage-autobackup-test.js && node tests/storage-outputs-mutate-test.js && node tests/sync-facts-guard-test.js && node tests/e2e-fixed-waits-ratchet-test.js && node tests/shell-render-behavior-test.js && node tests/canvas-meta-notice-behavior-test.js && node tests/source-text-ratchet-test.js && node tests/plugin-theme-contract-test.js && node tests/prompt-md-roundtrip-test.js && node tests/generation-results-store-test.js && node tests/out-groups-order-test.js && node tests/native-overlay-park-test.js && node tests/ui-dock-sanitize-test.js && node tests/ui-minimap-fit-test.js && node tests/ui-workbench-hooks-test.js && node tests/plugin-scale-contract-test.js && node tesLine truncated
"test:diagnostics": "node tests/runtime-diagnostics-hotpath-test.js",
"test:facts": "node tests/architecture-facts-guard-test.js && node tests/release-records-test.js",
"plugins:gc": "node scripts/plugins-publish.mjs --gc",
"check:plugins": "node scripts/check-plugins-sync.js",
"plugins:doctor": "node scripts/plugin-index-doctor.js",
"hooks:install": "bash scripts/install-git-hooks.sh",
@@ -30,7 +29,6 @@
"e2e:known-red": "node scripts/e2e-known-red-report.js",
"verify:ci": "npm run build && node --check app.js && node --check dist/app.js && node scripts/check-dist.js && node scripts/ctx-menu-audit.js && npm run tokens:check && npm run lint:tokens && npm run lint && npm run typecheck && npm run test:unit && npm test && npm run test:facts && npm run test:e2e:smoke",
"verify": "npm run verify:ci && npm run test:e2e",
"verify:release": "node scripts/verify-release.js",
"coverage:e2e": "node scripts/coverage-e2e.js",
"sync:facts": "node scripts/sync-facts.js",
"sync:facts:write": "node scripts/sync-facts.js --write",
+42
View File
@@ -0,0 +1,42 @@
// 插件清单纯函数:内容寻址命名 + SRI integrity。
//
// 桌面端插件清单 plugins/index.json 由 scripts/sync-plugins-from-repo.js 生成,
// 市场 zip 由 scripts/gen-market.js 生成;两条链路都依赖这里的哈希/命名规则。
// 历史上这些函数长在 scripts/plugins-publish.mjs(直写 Cloudflare KV 的网页版发布脚本),
// 网页版已停用,脚本删除,纯函数留在此处给同步脚本与测试复用。
import { createHash } from 'node:crypto'
import { basename } from 'node:path'
export const integrityOf = (buffer) => 'sha256-' + createHash('sha256').update(buffer).digest('base64')
export const idFromFile = (file) => {
const base = basename(String(file))
const m = /^plugin-([a-z][a-z0-9-]{2,31})\.js$/.exec(base)
return m ? m[1] : ''
}
// 内容寻址存储名:同 id + 同字节 ⇒ 同名(幂等);字节变 ⇒ 名变 ⇒ 客户端永不拿到陈旧缓存
export const storedNameOf = (id, buffer) => {
if (!/^[a-z][a-z0-9-]{2,31}$/.test(String(id))) throw new Error('非法插件 id:' + id)
return 'plugin-' + id + '.' + createHash('sha256').update(buffer).digest('hex').slice(0, 12) + '.js'
}
export const buildIndex = (entries) => {
const seen = new Set()
const out = []
for (const e of entries) {
if (!e || !e.id || !e.file || !e.integrity) throw new Error('清单项缺字段:' + JSON.stringify(e))
if (seen.has(e.id)) throw new Error('插件 id 重复:' + e.id)
seen.add(e.id)
out.push({ id: e.id, file: e.file, version: e.version || '', integrity: e.integrity })
}
return out.sort((a, b) => a.id.localeCompare(b.id))
}
// 并入既有清单:本次**未提供**文件的插件予以保留(incoming 同 id 覆盖旧的)。
// 2026-11-03 事故:只按传入文件重建清单 ⇒ 单发一个插件就把其余插件从清单里抹掉。
export const mergeIndexes = (existing, incoming) => {
const incomingIds = new Set(incoming.map((e) => e.id))
const kept = (Array.isArray(existing) ? existing : []).filter((e) => e && e.id && e.file && e.integrity && !incomingIds.has(e.id))
return buildIndex([...incoming, ...kept])
}
+1 -1
View File
@@ -11,7 +11,7 @@ const PLUGIN_REPO = '/Users/qiqi/open/github/iwb-plugins'
// 清单缺 integrity 即拒载(bad-entry),所以 mock 清单必须像生产发布器一样带真 sha256。
let _integrityOf = null
async function integrityOf(buf) {
if (!_integrityOf) _integrityOf = (await import(path.join(__dirname, '..', 'scripts', 'plugins-publish.mjs'))).integrityOf
if (!_integrityOf) _integrityOf = (await import(path.join(__dirname, '..', 'scripts', 'plugin-integrity.mjs'))).integrityOf
return _integrityOf(buf)
}
+1 -31
View File
@@ -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 个即视为事故')