Verify (Gitea) / gate (build · unit · facts) (push) Failing after 51s
背景:手工往 <资料目录>/plugins/ 拷文件、没更新同目录 index.json 时,加载器按索引里的旧哈希校验, 报「完整性校验失败(main.js 的 sha256 不符)」(2026-11-29 便利贴 1.0.8 实发)。 - scripts/plugin-index-doctor.js:扫描目录与索引,逐条报告 版本差异 / 哈希不符 / 文件缺失 / 未登记 / 孤儿条目; 默认只报告(有待修项时非 0 退出),--write 按实际文件重写索引并自动备份 index.json.bak-<时间戳> - package.json: npm run plugins:doctor(可带资料目录与 --write) - docs/standards/plugin-source-of-truth.md:命令表补该脚本,排错行的处置改为指向它 用法: npm run plugins:doctor # 默认扫 ~/Documents/ImageWorkbench npm run plugins:doctor -- /path/to/data # 指定资料目录(只报告) npm run plugins:doctor -- /path/to/data --write # 写入修复
108 lines
7.0 KiB
Markdown
108 lines
7.0 KiB
Markdown
# 插件两仓分工与同步规范(2026-11-29 定稿)
|
||
|
||
> 背景:2026-11-28 的图库/提示词库改动**直接改在桌面仓的产物层**,插件源仓没跟上,
|
||
> 于是源仓停在 gallery 1.7.5 / promptlib 1.13.1,市场却发了 1.9.x / 1.14.x —— 两仓分叉。
|
||
> 这份文档把「谁是真源、改哪、怎么发、怎么拦」写死,配套一条自动化守卫。
|
||
|
||
## 1. 两个仓库,各管什么
|
||
|
||
| 仓库 | 角色 | 可以手改吗 |
|
||
| --- | --- | --- |
|
||
| `iwb-plugins-desktop`(git.maqiart.eu.org/malongan/iwb-plugins-desktop) | **插件源码仓,唯一真源** | ✅ 只能改这里 |
|
||
| `image-workbench-desktop`(`plugins/`、`market/`) | 宿主 + 插件**构建产物** | ❌ 不要手改,会被下一次同步覆盖 |
|
||
|
||
目录对照(一个插件 = 源仓三件套 → 桌面仓两种产物形态):
|
||
|
||
| 源仓 | 桌面仓(目录形态,带 styles.css 的插件) | 桌面仓(单文件形态) |
|
||
| --- | --- | --- |
|
||
| `<id>/src/index.js` | `plugins/<id>/main.js` | `plugins/runtime/plugin-<id>.<sha12>.js` |
|
||
| `<id>/styles.css` | `plugins/<id>/styles.css` | (无) |
|
||
| `<id>/package.json` 的 `version` | `plugins/<id>/manifest.json` 的 `version` + `plugins/index.json` 的 `version` | 同上(index.json 条目) |
|
||
|
||
当前走目录形态的:`gallery`、`promptlib`(有 styles.css 会自动走目录形态)。
|
||
|
||
## 2. 三条红线
|
||
|
||
1. **插件代码只在源仓改**。桌面仓 `plugins/**` 是构建产物,手改等于改 dist,下一次 `sync-plugins-from-repo.js` 会覆盖。
|
||
2. **版本号成对**:源仓 `package.json.version` 与 `src/index.js` 里 `IWBPluginHost.register({ version })` 必须相等
|
||
(源仓 `npm run validate` 会拦;只在两处写,不要第三处)。
|
||
3. **发市场前必须过一致性守卫**:`npm run check:plugins`(`gen-market.js` 已内置,不一致直接中止)。
|
||
|
||
## 3. 日常流程:改一个插件
|
||
|
||
```bash
|
||
cd ../iwb-plugins-desktop
|
||
# 1) 改 <id>/src/index.js 与 <id>/styles.css,然后:
|
||
npm run validate # 13~15 个插件必须全绿(含版本/字段一致性)
|
||
npm run test:<id> # 有 harness 的跑一下(gallery / promptlib / album)
|
||
git commit -am 'fix(<id>): x.y.z …' && git push gitea main
|
||
|
||
cd ../image-workbench-desktop
|
||
# 2) 同步产物(幂等,内容不变时零 diff)
|
||
node scripts/sync-plugins-from-repo.js
|
||
npm run check:plugins # 期望:通过
|
||
git diff --stat # 只应有该插件相关的文件变化
|
||
|
||
# 3) 发市场
|
||
node scripts/gen-market.js && node scripts/gen-market-page.js
|
||
# 备份远端索引 → scp index.json / <id>-<ver>.zip / index.html → chmod -R a+rX → 回读校验
|
||
|
||
# 4) 提交(提交信息写「同步插件 <id>@<ver>」)
|
||
```
|
||
|
||
## 4. 门禁与命令
|
||
|
||
三道关卡,从「本地提交」到「发布」都拦:
|
||
|
||
| 关卡 | 位置 | 触发 | 行为 |
|
||
| --- | --- | --- | --- |
|
||
| pre-push 钩子 | `.git/hooks/pre-push`(源文件在 `scripts/git-hooks/pre-push`) | `git push` 桌面仓 | 两仓不一致直接拒绝推送 |
|
||
| 发布前置 | `scripts/release.sh` / `scripts/publish-update.sh` 开头 | 发版 | 不一致即退出,不发包、不传 NAS |
|
||
| 发布收尾 | 同上脚本末尾 | 发版结束 | 再核一次,防止发布过程中有人手改产物 |
|
||
| 市场前置 | `scripts/gen-market.js` 开头 | 发插件市场 | 不一致即中止 |
|
||
|
||
钩子安装(每台机器一次,clone 后执行):`npm run hooks:install`(等价 `bash scripts/install-git-hooks.sh`)。
|
||
钩子里的检查在「源仓不存在」时会跳过,所以别人机器/CI 不会被卡。
|
||
|
||
---
|
||
|
||
|
||
| 命令 | 作用 | 谁在用 |
|
||
| --- | --- | --- |
|
||
| `npm run validate`(源仓) | 源仓内部一致性:id/apiVersion/version 与 package.json 对齐 | 改插件的必跑 |
|
||
| `npm run check:plugins`(桌面仓) | 桌面仓产物 == 源仓源码,且版本一致 | 手动 / gen-market 内自动 |
|
||
| `node scripts/gen-market.js` | 生成市场索引与 zip,**开头先跑一致性检查** | 发市场时 |
|
||
| `npm run plugins:doctor`(`scripts/plugin-index-doctor.js`) | 体检**资料目录**的 `plugins/index.json` 与实际文件(版本/哈希/缺失/孤儿条目);默认只报告,`--write` 修复并备份 | 客户端报「完整性校验失败」或手工拷过插件时 |
|
||
|
||
`check-plugins-sync.js` 的行为:源仓不存在(CI、别人机器)时打印一行并跳过,不阻塞;存在时逐插件比对
|
||
`main.js`/`styles.css` 的 sha256、`manifest.json`/`index.json` 的版本,任何一项不符即非 0 退出并给出修复命令。
|
||
|
||
## 5. 应急:产物层已经被改过(真实案例)
|
||
|
||
2026-11-28 的情况就是这一类。补回源仓的做法:
|
||
|
||
1. 先看清「产物相对源仓多了什么、少了什么」:
|
||
`diff <(cat ../iwb-plugins-desktop/<id>/src/index.js) <(cat plugins/<id>/main.js)`
|
||
只用 `<` 开头的是源仓旧代码(正常,被新实现替换),用 `>` 的是产物新增实现。**确认没有源仓独有功能被覆盖**。
|
||
2. 反向同步:产物 → 源仓 `<id>/src/index.js` + `<id>/styles.css`;同时把 `package.json.version` 与 entry 内
|
||
`register({ version })` 一起升到新版本(升版本而不是原地改字节:市场按版本判断更新,同版本换字节客户端不会重下)。
|
||
3. 源仓 `npm run validate` 全绿 → commit/push。
|
||
4. 桌面仓 `node scripts/sync-plugins-from-repo.js` 重新生成产物(**不要**继续手改产物)+ `npm run check:plugins`。
|
||
5. 重新发市场。
|
||
|
||
## 6. 常见错误对照(都真实发生过)
|
||
|
||
| 现象 | 根因 | 正确做法 |
|
||
| --- | --- | --- |
|
||
| 源仓显示「最近更新 3 天前」,但市场已发新版 | 改动只在桌面仓产物层 | 按 §5 回写源仓,或按 §3 从源仓改起 |
|
||
| `validate` 报「entry 内 version 与 package.json 不一致」 | 只改了 package.json 或只改了 register 里的 version | 两处一起改 |
|
||
| `validate` 报「entry 内 id (q) 与 ibwPlugin.id 不一致」 | 校验器在整份源码里找第一个 `id:`,命中业务代码 `{ id: 'q' + Date.now() }` | 已修:先扫 `register(` 之后的 manifest 块,找不到再回退整份文件 |
|
||
| 插件显示「完整性校验失败(main.js 的 sha256 不符)」 | 手工往 `<资料目录>/plugins/` 拷文件,没同步更新同目录的 `index.json`(它带着旧哈希) | ①正确做法:一律走「设置 → 插件 → 检查更新」安装,安装器会同时写文件和索引;②已手工拷过的,跑一次 `npm run plugins:doctor -- <资料目录> --write`(先备份,再按实际文件重算版本与哈希) |
|
||
| 市场装完插件样式丢失 | 插件带 styles.css 但被当单文件同步 | 源仓放 `styles.css` 会自动走目录形态,不要手工拼单文件 |
|
||
|
||
## 7. 版本与发布的关系
|
||
|
||
- 插件版本独立于客户端版本:客户端 3.26.x 与插件 1.9.x/1.14.x 互不绑定。
|
||
- 插件改动**不需要**重打客户端(桌面包不含插件);发完市场,用户重启客户端即生效。
|
||
- 客户端需要新插件能力(新宿主 API)时,先在桌面仓实现并发布客户端,再升插件版本依赖它——顺序不能反。
|