refactor(promptlib): 收藏入口归插件(宿主不再自带,随插件启停)
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 43s
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 43s
按项目所有人要求:提示词库插件负责「管理与收集」的完整能力,宿主只保留基础接口。
宿主侧移除(全部 4 处入口 + 实现):
- 节点气泡星标(app.js 单选气泡的「添加到提示词库」)
- 「选中操作 ▸ 添加到提示词库」、「该节点 ▸ 添加该提示词」
- 提示词节点标题栏星标(src/ui-node-card.js)
- src/runtime-workbench-logic.js 的 addPromptToLibrary(约 45 行)与 ui-canvas-nodes 的 onFavorite 注入
宿主侧保留:promptlib 能力(list/save/insert/copy/notify/onChanged/file*)、prompts 状态与 api('prompts')(备份/迁移)、插件数据通道。
宿主侧补回(此前缺失):右键菜单重新渲染 ctx.commands 注册的插件命令(「插件命令」分区)。
插件 promptlib 1.13.1 → 1.14.0:
- capabilities 增 nodeActions / commands
- nodeActions「收藏为提示词」:仅对 type=prompt 且 text 非空的节点出现(气泡按钮)
- commands「收藏选中的提示词」:右键「插件命令」入口
- 收藏写入插件数据 plugin-data/promptlib.json(以现有数据为基底,保留 cover:{img} 与分组),
新条目 group:'' 即未分组,并 notify 回执
测试:
- tests/iwb-prompt-collect.spec.js 改为 3 条新契约:插件提供气泡入口 + 宿主无自带入口;
右键插件命令可用且宿主旧条目已移除;插件停用后两个入口同时消失
- canvas-meta-notice 的旧「点按钮报错回执」用例改为「宿主不得再渲染该入口」
- tests/_helpers/wait.js openDockPanel 加固(等插件宿主初始化,修并行偶发)
- 棘轮下调:app.js 8324 / Workbench 2178
验证:npm run verify:ci 全绿(含 e2e 冒烟 31 条)。
This commit is contained in:
1 parent
31a89401ff
commit
2cd52d1d4e
14 files changed
+122
-145
No files matched your search
@@ -107,11 +107,13 @@ async function openCanvas (page, opts) {
|
||||
// 停靠栏面板(2026-11-26):v3.25.82 起「资源中心」浮窗被停靠栏插件面板取代。
|
||||
// 图库 = 右栏 .iwb-dock-btn[data-panel="gallery"];提示词库 = "prompts";节点组 = "groups";浏览器 = "browser"。
|
||||
async function openDockPanel (page, panelId) {
|
||||
const btn = page.locator('.iwb-dock-btn[data-panel="' + panelId + '"]').first()
|
||||
if (!(await btn.count())) {
|
||||
// 面板所在侧默认可能是关的:先开右栏再找(找不到右栏开关就开左栏)
|
||||
const rightToggle = page.locator('.iwb-top-nav-icon[title="显示 / 隐藏右栏"]').first()
|
||||
if (await rightToggle.count()) { await rightToggle.click(); await page.waitForTimeout(300) }
|
||||
// 2026-11-27:插件面板清单按 PluginHost.list() 过滤,插件还没注册完时按钮不存在 ⇒
|
||||
// 先等宿主初始化,再开栏;找不到就轮询(并行跑时首屏更慢,固定 300ms 会偶发失败)。
|
||||
await page.waitForFunction(() => Boolean(window.IWBPluginHost) && window.IWBPluginHost.snapshot().initialized === true, null, { timeout: 15000 }).catch(() => {})
|
||||
const rightToggle = page.locator('.iwb-top-nav-icon[title="显示 / 隐藏右栏"]').first()
|
||||
if (!(await page.locator('.iwb-dock[data-side="right"]').count()) && (await rightToggle.count())) {
|
||||
await rightToggle.click()
|
||||
await page.waitForTimeout(200)
|
||||
}
|
||||
const target = page.locator('.iwb-dock-btn[data-panel="' + panelId + '"]').first()
|
||||
await expect(target).toBeVisible({ timeout: 10000 })
|
||||
|
||||
@@ -125,34 +125,14 @@ async function enterCanvas(window) {
|
||||
assert.equal(window.document.querySelectorAll('.iwb-home-card').length, 0,
|
||||
'切到画布视图后首页卡片应已卸载(实际仍有残留 ⇒ 视图切换不干净)')
|
||||
|
||||
// ── 6. 保存失败必须变成用户看得见的回执(2026-11-12)──────────────────────
|
||||
// 为什么加:`api('prompts', …)` 在配额不足时 **resolve** { ok:false, error:'提示词库保存失败:…' },
|
||||
// 不是 reject。历史上调用点写 `.catch(() => {})` ⇒ 既抓不到失败,也把 api 造好的文案丢掉,
|
||||
// 用户看到的是「顺利加进去了」,刷新后数据消失 —— 与 v3.24.67~70 反复修的「没反应」同一类。
|
||||
// 这里用**真实渲染**钉住:让存储写入返回失败,点「添加到提示词库」,必须出现红色回执。
|
||||
const waitFor = async (fn, ms = 4000) => {
|
||||
const t0 = Date.now()
|
||||
while (Date.now() - t0 < ms) { if (fn()) return true; await sleep(20) }
|
||||
return false
|
||||
}
|
||||
const rt = window.IWBStorageRuntime
|
||||
assert.ok(rt && typeof rt.set === 'function', '应能拿到 IWBStorageRuntime.set 以模拟写入失败')
|
||||
const origSet = rt.set
|
||||
rt.set = () => false
|
||||
const addBtn = Array.from(window.document.querySelectorAll('button')).find((b) => b.title === '添加到提示词库')
|
||||
assert.ok(addBtn, '应能找到提示词卡片上的「添加到提示词库」按钮')
|
||||
addBtn.dispatchEvent(new window.MouseEvent('click', { bubbles: true, cancelable: true }))
|
||||
const gotToast = await waitFor(() => !!window.document.querySelector('.iwb-toast-err'))
|
||||
rt.set = origSet
|
||||
assert.ok(gotToast, '存储写入失败时,点「添加到提示词库」必须弹出 .iwb-toast-err —— ' +
|
||||
'一个都没有说明失败又被静默吞掉了(用户会以为已保存)')
|
||||
const toastText = String(window.document.querySelector('.iwb-toast-err').textContent || '')
|
||||
assert.ok(/保存失败/.test(toastText), '失败 toast 的文案要能说明是「保存失败」,实际:' + JSON.stringify(toastText))
|
||||
const meta2 = window.document.querySelector('.iwb-canvas-meta')
|
||||
const errInMeta2 = Array.from(meta2.querySelectorAll('.iwb-status-err')).map((el) => String(el.textContent || '')).join(' | ')
|
||||
assert.ok(/保存失败/.test(errInMeta2), '顶栏状态栏也要出现「保存失败」(首页/画布都要可见),实际:' + JSON.stringify(errInMeta2))
|
||||
// ── 6. 提示词收藏入口已归插件(2026-11-27)──────────────────────────────
|
||||
// 宿主的「添加到提示词库」按钮已移除:收集能力由 promptlib 插件注册(nodeActions / 插件命令),插件停用即消失。
|
||||
// 原先「点按钮 → 存储失败 → 红色回执」的宿主契约随之不存在,保存失败可见性改由插件负责。
|
||||
// 这里只钉「宿主不得再自带入口」。
|
||||
assert.equal(Array.from(window.document.querySelectorAll('button')).filter((b) => b.title === '添加到提示词库').length, 0,
|
||||
'宿主不应再渲染「添加到提示词库」入口(收集入口归插件)')
|
||||
|
||||
console.log('canvas meta / error notice checks passed(真实渲染:错误提示对用户可见 + 挂载位置正确 + 保存失败有红色回执)')
|
||||
console.log('canvas meta / error notice checks passed(真实渲染:错误提示对用户可见 + 挂载位置正确 + 收集入口已归插件)')
|
||||
window.close()
|
||||
// jsdom 里的 React 定时器会让事件循环不空 ⇒ 必须显式退出(见规则库 §13.44)
|
||||
process.exit(0)
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
// 提示词收藏(宿主 → 提示词库插件):2026-11-27 修复的回归守护
|
||||
// 提示词收藏(2026-11-27 起归插件):入口随插件启停,宿主不再自带
|
||||
//
|
||||
// 背景:提示词库插件 1.13 起「唯一真源 = plugin-data/promptlib.json」,宿主 localStorage 只在插件首次迁移时被读。
|
||||
// 旧实现只写宿主 ⇒ 条目「加进去了但面板看不见」。现在走插件能力:以插件数据为基底追加到未分组,再写回 + 通知刷新。
|
||||
// 契约:
|
||||
// ① 提示词节点选中后,气泡里的「收藏为提示词」由 promptlib 插件注册(nodeActions);
|
||||
// ② 右键菜单出现插件命令「收藏选中的提示词」(ctx.commands);
|
||||
// ③ 宿主不得保留自带的入库入口(气泡星标 / 右键「添加该提示词」/「添加到提示词库」);
|
||||
// ④ 收藏写入插件数据(plugin-data/promptlib.json),默认 group 为空(未分组);
|
||||
// ⑤ 插件停用 → 两个入口同时消失。
|
||||
const { test, expect } = require('./_pw-coverage')
|
||||
const W = require('./_helpers/wait')
|
||||
|
||||
@@ -20,15 +24,8 @@ async function boot (page) {
|
||||
await W.waitHomeReady(page)
|
||||
await page.locator('.iwb-home-card:not(.iwb-home-new)').first().dblclick()
|
||||
await page.waitForSelector('.iwb-canvas-topbar', { timeout: 20000 })
|
||||
await page.waitForTimeout(600)
|
||||
}
|
||||
|
||||
async function openPromptPanel (page) {
|
||||
await page.locator('.iwb-top-nav-icon[title="显示 / 隐藏右栏"]').first().click()
|
||||
await page.waitForTimeout(300)
|
||||
await page.locator('.iwb-dock-btn[data-panel="prompts"]').first().click()
|
||||
await expect(page.locator('.iwb-dock-body[data-panel="prompts"]')).toBeVisible({ timeout: 10000 })
|
||||
await page.waitForTimeout(600)
|
||||
await page.waitForFunction(() => Boolean(window.IWBPluginHost) && window.IWBPluginHost.snapshot().initialized === true)
|
||||
await page.waitForTimeout(800)
|
||||
}
|
||||
|
||||
const readData = (page) => page.evaluate(async () => {
|
||||
@@ -36,47 +33,46 @@ const readData = (page) => page.evaluate(async () => {
|
||||
return { prompts: (d && d.prompts) || [], groups: (d && d.groups) || [] }
|
||||
})
|
||||
|
||||
test('节点气泡收藏:写进插件数据、默认未分组、面板立刻可见', async ({ page }) => {
|
||||
const pluginAction = (page) => page.locator('.iwb-node-floatbar-plugin[data-tip="收藏为提示词"]')
|
||||
const hostEntry = (page) => page.locator('.iwb-node-floatbar button[aria-label="添加到提示词库"]')
|
||||
|
||||
test('气泡入口由插件提供;宿主不再自带;收藏进未分组', async ({ page }) => {
|
||||
await boot(page)
|
||||
await openPromptPanel(page)
|
||||
await page.locator('[data-node-id="p1"] .iwb-node-head').click()
|
||||
await page.locator('.iwb-node-floatbar button[aria-label="添加到提示词库"]').first().click()
|
||||
await expect(page.locator('.iwb-plp-card'), '收藏后面板应立刻出现该条目').toHaveCount(1, { timeout: 8000 })
|
||||
await expect(pluginAction(page), '插件应提供「收藏为提示词」气泡按钮').toBeVisible({ timeout: 10000 })
|
||||
await expect(hostEntry(page), '宿主不应再有自带收藏入口').toHaveCount(0)
|
||||
await pluginAction(page).click()
|
||||
await expect.poll(async () => (await readData(page)).prompts.length, { timeout: 8000 }).toBe(1)
|
||||
const d = await readData(page)
|
||||
expect(d.prompts.length, '插件数据应写入 1 条').toBe(1)
|
||||
expect(d.prompts[0].text).toBe('收藏用提示词')
|
||||
expect(String(d.prompts[0].group || ''), '默认应落在未分组(group 为空)').toBe('')
|
||||
expect(String(d.prompts[0].group || ''), '默认未分组').toBe('')
|
||||
})
|
||||
|
||||
test('右键「添加该提示词」:同样写入插件数据且未分组', async ({ page }) => {
|
||||
test('右键「插件命令」里有收藏入口,且宿主菜单无旧条目', async ({ page }) => {
|
||||
await boot(page)
|
||||
await page.locator('[data-node-id="p1"] .iwb-node-head').click()
|
||||
await page.locator('[data-node-id="p1"]').click({ button: 'right' })
|
||||
await page.locator('.iwb-ctxmenu:not(.iwb-ctx-sub) .iwb-ctx-item', { hasText: '该节点' }).first().hover()
|
||||
await page.locator('.iwb-ctxmenu.iwb-ctx-sub .iwb-ctx-item', { hasText: '添加该提示词' }).first().click()
|
||||
const main = '.iwb-ctxmenu:not(.iwb-ctx-sub)'
|
||||
await expect(page.locator(main)).toBeVisible({ timeout: 8000 })
|
||||
const cmd = page.locator(main + ' .iwb-ctx-item', { hasText: '收藏选中的提示词' })
|
||||
await expect(cmd, '插件命令应出现在右键菜单').toHaveCount(1)
|
||||
await expect(page.locator(main + ' .iwb-ctx-item', { hasText: '添加该提示词' }), '宿主旧条目应已移除').toHaveCount(0)
|
||||
await cmd.click()
|
||||
await expect.poll(async () => (await readData(page)).prompts.length, { timeout: 8000 }).toBe(1)
|
||||
const d = await readData(page)
|
||||
expect(String(d.prompts[0].group || '')).toBe('')
|
||||
expect(String((await readData(page)).prompts[0].group || '')).toBe('')
|
||||
})
|
||||
|
||||
test('追加不破坏既有条目(cover 引用原样保留,分组不被清空)', async ({ page }) => {
|
||||
test('插件停用后两个入口同时消失', async ({ page }) => {
|
||||
await boot(page)
|
||||
// 预置插件数据:一条带 cover:{img} 引用、且在「G」分组里
|
||||
await page.evaluate(async () => {
|
||||
await window.IWBPluginData.create('promptlib').write({
|
||||
schemaVersion: 3,
|
||||
prompts: [{ id: 'q0', name: '旧条目', text: '旧文案', tags: ['收藏'], group: 'G', cover: { img: 'old.jpg' } }],
|
||||
groups: [{ id: 'G', name: 'G' }],
|
||||
updatedAt: 1,
|
||||
})
|
||||
})
|
||||
await openPromptPanel(page)
|
||||
await page.locator('[data-node-id="p1"] .iwb-node-head').click()
|
||||
await page.locator('.iwb-node-floatbar button[aria-label="添加到提示词库"]').first().click()
|
||||
await expect.poll(async () => (await readData(page)).prompts.length, { timeout: 8000 }).toBe(2)
|
||||
const d = await readData(page)
|
||||
expect(d.prompts[0].cover && d.prompts[0].cover.img, '既有条目的封面引用不能被压平').toBe('old.jpg')
|
||||
expect(d.prompts[0].group, '既有条目分组不变').toBe('G')
|
||||
expect(String(d.prompts[1].group || ''), '新条目进未分组').toBe('')
|
||||
expect(d.groups.length, '分组表不被清空').toBe(1)
|
||||
await expect(pluginAction(page)).toBeVisible({ timeout: 10000 })
|
||||
await page.evaluate(() => window.IWBPluginHost.setEnabled('promptlib', false))
|
||||
await page.waitForTimeout(400)
|
||||
await page.locator('.iwb-canvas').click({ position: { x: 1200, y: 800 } })
|
||||
await page.locator('[data-node-id="p1"] .iwb-node-head').click()
|
||||
await expect(pluginAction(page), '停用后气泡入口应消失').toHaveCount(0)
|
||||
await page.locator('[data-node-id="p1"]').click({ button: 'right' })
|
||||
const main = '.iwb-ctxmenu:not(.iwb-ctx-sub)'
|
||||
await expect(page.locator(main)).toBeVisible({ timeout: 8000 })
|
||||
await expect(page.locator(main + ' .iwb-ctx-item', { hasText: '收藏选中的提示词' }), '停用后右键命令应消失').toHaveCount(0)
|
||||
})
|
||||
@@ -70,7 +70,7 @@ test('② 节点气泡:单选时图标显示 2 字功能名(改名/复制)
|
||||
const single = page.locator('.iwb-node-floatbar:not(.iwb-node-floatbar-group)')
|
||||
await expect(single).toBeVisible()
|
||||
|
||||
// 2026-11-27:单选气泡现为 解组/并入分组/放大编辑/改名/复制/添加到提示词库/替换/粘贴/下载;
|
||||
// 2026-11-27:单选气泡现为 解组/并入分组/放大编辑/改名/复制/替换/粘贴/下载(收藏入口已归 promptlib 插件);
|
||||
// 「删除」「收藏」只在多选气泡(单选删除走 Delete 键 / 右键菜单)——这里守 2 字提示,也守「不该出现」。
|
||||
for (const label of ['改名', '复制']) {
|
||||
const btn = single.locator(`button[aria-label="${label}"]`).first()
|
||||
|
||||
@@ -170,7 +170,7 @@ const MAX_SRC_COMPONENT_LINES = 531
|
||||
// · 图标解析统一(右键菜单 + 设置页走同一解析器,2 行) +2
|
||||
// 通用件(pick/grant/stat/readDataUrl/readBlob/参数校验)全部在 src/image-file-ref.js
|
||||
// 与 src/plugin-api-images.js,app.js 只做装配。
|
||||
const MAX_APP_JS_LINES = 8326 // +11(2026-11-27:停靠栏就绪后按新占位重新适应的监听;app.js 8315→8326) // +15(2026-11-26 复制/粘贴通道重写:DOM copy 事件装配、pasteCtx 增补实时选择/剪贴板读写、⌘V 改为主动粘贴;逻辑在 src/clipboard-graph.js 的 bindCopy 与 src/clipboard-paste.js 的 pasteFromKey) // +1(2026-11-26 相册外部路径重启复授权装配;逻辑在 src/image-file-ref.js) // +5(2026-11-26 标注覆盖保存:桌面端不再生成死 __cache(4 行)+ 插件 saveNodeImage 装配(1 行);事务逻辑在 src/runtime-workbench-logic.js)
|
||||
const MAX_APP_JS_LINES = 8324 // +11(2026-11-27:停靠栏就绪后按新占位重新适应的监听;app.js 8315→8326) // +15(2026-11-26 复制/粘贴通道重写:DOM copy 事件装配、pasteCtx 增补实时选择/剪贴板读写、⌘V 改为主动粘贴;逻辑在 src/clipboard-graph.js 的 bindCopy 与 src/clipboard-paste.js 的 pasteFromKey) // +1(2026-11-26 相册外部路径重启复授权装配;逻辑在 src/image-file-ref.js) // +5(2026-11-26 标注覆盖保存:桌面端不再生成死 __cache(4 行)+ 插件 saveNodeImage 装配(1 行);事务逻辑在 src/runtime-workbench-logic.js)
|
||||
const MAX_APP_JS_SHARE = 0.40
|
||||
|
||||
// ── 历史记账(供回溯,逐条保留)──────────────────────────────────────────────
|
||||
@@ -213,7 +213,7 @@ const MAX_APP_JS_SHARE = 0.40
|
||||
// 需要实时读 .iwb-world 变换 + 按同类型实测高度校正视觉中心;属装配层的 DOM 读取,
|
||||
// 放 src 会引入新的全局读取与边界快照改动,权衡后留在 app.js // +10(2026-11-01):背景色「悬停预览」的 DOM 补丁助手(纯 DOM,不写数据/不进撤销栈);
|
||||
// 属装配层最小的 DOM 操作,放 src 会引入新的全局读取与边界快照改动,权衡后留在 app.js
|
||||
const MAX_WORKBENCH_LINES = 2180 // +11(2026-11-27:同上,Workbench 2169→2180) // 2026-11-26 复制/粘贴通道重写(+14:refs 新增粘贴时间戳/系统剪贴板可信标记、pasteCtx 增补 ids/clipboardOf/stageClip/readNativeText、bindCopy 装配)
|
||||
const MAX_WORKBENCH_LINES = 2178 // +11(2026-11-27:同上,Workbench 2169→2180) // 2026-11-26 复制/粘贴通道重写(+14:refs 新增粘贴时间戳/系统剪贴板可信标记、pasteCtx 增补 ids/clipboardOf/stageClip/readNativeText、bindCopy 装配)
|
||||
// 2026-11-18 v3.25.21:模态层指针守卫(2 行)
|
||||
// 实测 3090 → 2998(省 92):① 生成取消族 cancelRunsFor/cancelRun/cancelTaskJobs
|
||||
// → src/runtime-workbench-logic.js 的 createCancelActions(−53);② 工作区列表写回族
|
||||
|
||||
Reference in new issue
Block a user