Files
qiqi 31a89401ff
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 40s
fix(promptlib): 提示词收藏写进插件数据(面板立刻可见,默认未分组)
根因:提示词库插件 1.13 起「唯一真源 = plugin-data/promptlib.json」,宿主 localStorage 只在插件
首次迁移时被读一次。而节点气泡的「添加到提示词库」与右键的「添加该提示词」仍只写宿主侧
(refs.promptLibrary + api('prompts'))⇒ 条目写进了 localStorage,插件面板读 data.json 看不到,
刷新后依旧不显示(2026-11-27 用户实测:两个入口都"好像不可用")。

修法(src/runtime-workbench-logic.js addPromptToLibrary):
- 有提示词库插件时:先读插件数据为基底(保住 cover:{img} 引用与既有分组),追加一条
  group:'' 的条目(= 未分组),写回插件数据,再走插件 save 同步宿主镜像并通知面板刷新;
- 没有插件时保留原宿主存储路径(旧行为不变)。
- app.js 注入 promptLib(window.IWBPluginPromptLib.api())与 pluginData(IWBPluginData.create),
  均为同一行内新增属性,app.js 行数不变。

回归用例 tests/iwb-prompt-collect.spec.js(3 条):气泡收藏、右键添加、追加不破坏既有条目
(cover 引用与分组原样保留)。门禁 spec 数 52 → 53。

验证:npm run verify:ci 全绿(含 e2e 冒烟 31 条);新 spec 3/3 通过。
2026-11-27 09:49:56 +08:00

75 lines
5.0 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'
// 契约测试:e2e 门禁 spec 必须**自动发现**,不允许再出现"新 spec 被静默漏跑"。
// 见 scripts/list-e2e-specs.js 与 docs/standards/project-engineering-standards.md §13.20。
const assert = require('assert')
const fs = require('fs')
const os = require('os')
const path = require('path')
const { discoverSpecs, PROBE_MARKER } = require('../scripts/list-e2e-specs')
const root = path.resolve(__dirname, '..')
const testsDir = path.join(root, 'tests')
const all = fs.readdirSync(testsDir).filter((name) => name.endsWith('.spec.js')).sort()
const expectedSpecs = all.filter((name) => !name.startsWith('_'))
const expectedExcluded = all.filter((name) => name.startsWith('_'))
const result = discoverSpecs(testsDir)
const specsBase = result.specs.map((file) => path.basename(file))
const excludedBase = result.excluded.map((file) => path.basename(file))
// 门禁集合 = 磁盘上全部「非下划线前缀」spec(逐个核对,顺序也钉住)
assert.deepStrictEqual(specsBase, expectedSpecs, '门禁 spec 必须等于全部非下划线前缀的 spec')
// 当前门禁规模钉死:若新增 spec 请同步更新此数字(它让"门禁悄悄变小"立刻可见)
// 45 = 44 + iwb-plugin-panel-tab-leak(插件面板切 tab 残留守护)
// 51 = 50 + iwb-tabs-release(多标签释放语义:回首页不降级 / 关标签先保存再关 / 彻底删除连带关标签)
// 52 = 51 + iwb-lod(LOD 判据:fit 大画布不渲染完整节点体 / 放大后恢复 / 常规画布不 LOD)
// 54 = 52 + iwb-inherit-text(v3.24.81 上游继承文本)+ iwb-plugin-node-coldstart(v3.24.82 插件节点体异步注册)
// —— 这两条 spec 随 v3.24.81/82 一起进仓库时没同步更新本数字,门禁从那时起是红的(2026-11-14 补记)
// 55 = 54 + iwb-multi-tab(v3.24.85:跨标签页契约 —— A 页 flush 落盘后 B 页靠 rev 轮询可见 / 图库归档受跨进程锁保护)
// 53 = 55 − iwb-csp-gate − iwb-functions-headers(v3.25.15:网页版部署面删除,两条只测 _headers/Functions 的 spec 一并删除)
// 52 = 53 − iwb-groups-sidebar(v3.25.56 节点组库改为插件 grouplib,宿主侧栏组件删除,其 e2e 一并移除)
// 53 = 52 + iwb-default-gen-model(v3.26.71:通用 tab 设置新建配置节点默认模型)
// 54 = 53 + iwb-album-thumbs(相册 1.1.6:宫格重建后缩略图丢 src / 透明图黑底的回归)
// 52 = 54 − iwb-lib-panel-ux − iwb-full-window-resize(2026-11-27 退役:测的是已下线的「资源中心」浮窗 UI,
// 面板 UI 归插件仓;退役原因记在 tests/fixtures/e2e-known-red.json 的 retired 段)
// 53 = 52 + iwb-prompt-collect(2026-11-27:提示词收藏走插件数据,覆盖气泡/右键两个入口 + 不破坏封面引用)
assert.strictEqual(result.specs.length, 53, '当前门禁应自动发现 53 个 spec')
// 排除集合 = 全部人工 dev 探针,且都必须已声明标记
// 4 = 3 + _probe-tab-switch(切画布标签耗时归因:四轮对照实验,只读诊断)
// 5 = 4 + _visual-tokens(设计 token 视觉基线:像素受字体/DPR 影响,不入 CI,本地 0 diff 验收用)
assert.deepStrictEqual(excludedBase, ['_perf-baseline.spec.js', '_plugin-host-probe.spec.js', '_probe-drag.spec.js', '_probe-tab-switch.spec.js', '_visual-tokens.spec.js'], '被排除的应是全部带 iwb-dev-probe 标记的 dev 探针')
// 结构不变量:两集合无交集 + 并集 == 磁盘上全部 spec
assert.strictEqual(result.specs.length + result.excluded.length, all.length, 'specs + excluded 必须等于磁盘全部')
const union = new Set([...specsBase, ...excludedBase])
assert.strictEqual(union.size, all.length, 'specs ∪ excluded 必须恰好等于磁盘全部 spec(无重复、无遗漏)')
// 回归护栏:加入一个「未声明标记」的 _ 前缀 spec 必须让 discoverSpecs 抛错(否则"静默排除"会回来)
const fixture = fs.mkdtempSync(path.join(os.tmpdir(), 'iwb-e2e-specs-'))
try {
fs.writeFileSync(path.join(fixture, 'a.spec.js'), '// 正常 spec\n')
fs.writeFileSync(path.join(fixture, '_probe.spec.js'), '// 没有标记\n')
assert.throws(() => discoverSpecs(fixture), /iwb-dev-probe/, '未标记的 _ 前缀 spec 必须抛错')
} finally {
fs.rmSync(fixture, { recursive: true, force: true })
}
// 补上标记后应被"排除"而不是抛错
const fixture2 = fs.mkdtempSync(path.join(os.tmpdir(), 'iwb-e2e-specs-'))
try {
fs.writeFileSync(path.join(fixture2, 'a.spec.js'), '// 正常 spec\n')
fs.writeFileSync(path.join(fixture2, '_probe.spec.js'), `// ${PROBE_MARKER}: dev 探针\n`)
const discovered = discoverSpecs(fixture2)
assert.strictEqual(discovered.specs.length, 1, '带标记的探针不该进门禁')
assert.strictEqual(discovered.excluded.length, 1, '带标记的探针应被排除')
assert.strictEqual(path.basename(discovered.excluded[0]), '_probe.spec.js')
} finally {
fs.rmSync(fixture2, { recursive: true, force: true })
}
console.log('list-e2e-specs checks passed')