diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c80a55..e105cab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,15 @@ > 3. 核验正式地址版本 → 之后才移动 `stable` / `stable-verified-<日期>` 标签、更新本 CHANGELOG、写 GitHub Release(`gh release create`)。 > 测试发现问题 → 改 → 再 `deploy:test`,正式环境不受影响。回滚点 `git reset --hard stable`。 +## v3.26.84(2026-11-26)图库落盘自检:先在诊断页看清「图在哪一层」 + +- 设置 → 诊断 →「存储体检」新增**图库落盘自检**:逐条判定 **原图 OK / 仅缩略图 / 全丢**。桌面端会真的去 `images/gallery` 查文件是否存在(只查存在性,不读字节,避免诊断本身把堆顶撑高)。 +- 报告包含:资料目录、索引条数、**未被任何条目引用的原图**、本次会话原图写入成功/失败与失败原因;可一键复制,不含 Key 与图片内容。 +- 写入侧只在存储层加会话计数(`out_orig_` 成功/失败),**不改生成与归档流程**;浏览器路径按 IDB 键集合判定。 +- 新增 `src/gallery-audit.js`(纯函数 + 可注入事实)与 `tests/gallery-audit-test.js`;app.js 只多 1 行装配(棘轮 9182 → 9183,已在代码内记账)。 + +> 这是只读诊断,先拿到「你机器上属于哪一类」再动落盘逻辑;修复批次在后续版本。 + ## v3.26.83(2026-11-26)相册格子 hover 动效 + 输出节点双击预览 - 相册节点:格子 hover 只做 1.06 缩放 + 阴影 + 品牌描边(网格内不位移,避免相邻格子抖动),尊重 reduced-motion。 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e8c9ddb..a571686 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -40,7 +40,7 @@ build esbuild 打包到 dist/(单 dist/app.js = src/ 模块按序 node --check app.js 与 dist/app.js 语法 check-dist.js 产物体检 lint ESLint(src/ + app.js,正确性规则) -test:unit 129 个单测文件(jsdom 契约测试;2026-11-07 新增 sync-facts-guard(事实一致性)/ _helpers/source(统一源文本);2026-11-12 新增 provider-ping(测速 no-cors 兜底)) +test:unit 130 个单测文件(jsdom 契约测试;2026-11-07 新增 sync-facts-guard(事实一致性)/ _helpers/source(统一源文本);2026-11-12 新增 provider-ping(测速 no-cors 兜底)) test relay-task-graph-fixture + iwb-v32-web-test test:facts 事实基线守门(见 §5) typecheck 渐进类型检查(tsc --noEmit;范围 = src/*.js,不含 app.js) @@ -102,7 +102,7 @@ IWB_WRITE_BOUNDARY_SNAPSHOT=1 node tests/architecture-boundary-guard-test.js # | 守卫 | 位置 | 现在的上限 | |---|---|---| -| `app.js` 总行数 | `tests/source-text-ratchet-test.js` `MAX_APP_JS_LINES` | **9,182**(另守「占总源码 ≤ 40%」,见 `MAX_APP_JS_SHARE`) | +| `app.js` 总行数 | `tests/source-text-ratchet-test.js` `MAX_APP_JS_LINES` | **9,183**(另守「占总源码 ≤ 40%」,见 `MAX_APP_JS_SHARE`) | | `Workbench()` 行数 | 同上 `MAX_WORKBENCH_LINES` | **3,046** | | 单组件行数(不含 Workbench)| 同上 `MAX_APP_COMPONENT_LINES` | **423** | diff --git a/app.js b/app.js index 38a6cce..7994118 100644 --- a/app.js +++ b/app.js @@ -2863,6 +2863,7 @@ try { if (window.IWBMiniMapFit && typeof window.IWBMiniMapFit.install === 'funct const outputs = lsGet(OUT_KEY, []) const res = StorageHealth.audit({ idbKeys, outputsIndex: Array.isArray(outputs) ? outputs : [], prefixes: { blob: IMG_BLOB_PREFIX, ref: IDB_REF_PREFIX, out: IDB_OUT_PREFIX, orig: IDB_ORIG_PREFIX } }) try { const PD = window.IWBPluginData; if (PD && PD.totalSize) { const t = await PD.totalSize(); res.pluginDataBytes = t.bytes; res.pluginDataCount = t.count } } catch (e) { /* M2:插件数据纳入体检 */ } + res.gallery = await (window.IWBGalleryAudit ? window.IWBGalleryAudit.run({ index: outputs, storageFile: window.IWBStorageFile, idbKeys }) : null) // 图库落盘三态(src/gallery-audit.js) return res } // 一键安全回收:复用保存路径的 wCleanIdb(带活引用 keep-set),绕过 30s 节流手动触发一次。 diff --git a/docs/standards/architecture-current-state.md b/docs/standards/architecture-current-state.md index d6de7ed..d337694 100644 --- a/docs/standards/architecture-current-state.md +++ b/docs/standards/architecture-current-state.md @@ -22,7 +22,7 @@ - 图片**新写入主通道 = IndexedDB Blob `{__blob}` / key `imgblob__`** (A) `app.js:2143`;`{__cache}`(Cache Storage)为兜底;\`ref_\`(`app.js` 内定义的 `IDB_REF_PREFIX = 'ref_'`)为 legacy 形态 (A)。 - 大图判定:`isBigDataUrl` = `data:` 且 `length > 3000` (A) `app.js:2018`;**画布保存保留阈值** `< 16384` 才原样保留 (A) `app.js:2182`。**两处阈值并存,含义不同**。 - 单测是**源码契约测试**:`tests/` 目录共 **493** 处源码文本钉点(`source.includes` / `source.indexOf` / `/re/.test(source)`),分布在 **20** 个文件(其中 `iwb-v32-web-test.js` 一个就占 **407**)→ **结构性重构会先打红测试**。**该数字已由 `tests/source-text-ratchet-test.js` 的「只减不增」棘轮守门**(2026-10-20 起守卫范围从 1 个文件扩到全目录:新增任何一处源码文本钉点都会打红)。**2026-11-12 复算**(`npm run audit:pins`,v3.24.76):二分 STRUCT **417** / NAME **76**;形态 **POS 403 / NEG 87 / COUNT 3**;难度 **易 62 / 中 316 / 难 115**。钉点减法第一批(v3.24.72)把 **537 → 505**:8 条探针钉点改为「门禁内 spec 是否真的读该计数器」、5 条改为运行时断言(生产态 `window` 上无探针)、10 条改为 DOM 断言(质量档位禁用 / 传输页无三模式按钮 / 模型项 title)、4 条改为运行时对象断言(健康检查两域、策略对象冻结)、其余 9 条有同文件 DOM 等价断言或仅剩 NEG。第二批(v3.24.76)把 **505 → 493**:94-5~7 三条「多标签释放语义」(10 处正则)换成 `tests/iwb-tabs-release.spec.js` 的 3 条真 e2e,剩 1 条「消费方契约」(断言该 spec 在门禁内且 spec 源码真的读两个探针);另 2 条 `wPurgeIntent.add` 钉点改为读 `src/workspace-purge.js`。**这一批一换就查出 3 个真缺陷**(objectURL 从未释放 / 彻底删除留孤儿标签 · session / 刷新后误回收打开标签的图)—— 见 CHANGELOG v3.24.76。 -- `app.js` = 单 IIFE **9,182 行**(**双层预算**:绝对上限 9,182 / 占总源码 ≤ 40%,现 **29.9%**,2026-11-12 起;此前为单一上限 8,509、零余量);`Workbench()` = **3,043 行**(上限 **3,046**,余量 3;2026-11-16 把生成取消族 `cancelRunsFor`/`cancelRun`/`cancelTaskJobs` 与工作区列表写回族 `persistWs`/`duplicateWs` 搬进 `src/runtime-workbench-logic.js`(`createCancelActions` / `createWorkspaceListActions`),并删掉全仓零调用的 `runAll`,3090 → 2,998);大量逻辑已抽到 `src/*.js`(现 **111** 个模块 / 21,520 行,`sourceModules` 111 项;v3.24.68 新增 `clipboard-graph.js`,v3.24.74 新增 `image-admit.js`,v3.24.75 新增 `image-dedupe.js`,v3.24.76 新增 `workspace-purge.js`,v3.24.79 新增 `generation-provider-ping.js`,v3.24.80 删除无调用的 `createWBFlushViewport` 17 行)。 +- `app.js` = 单 IIFE **9,183 行**(**双层预算**:绝对上限 9,183 / 占总源码 ≤ 40%,现 **29.7%**,2026-11-12 起;此前为单一上限 8,509、零余量);`Workbench()` = **3,043 行**(上限 **3,046**,余量 3;2026-11-16 把生成取消族 `cancelRunsFor`/`cancelRun`/`cancelTaskJobs` 与工作区列表写回族 `persistWs`/`duplicateWs` 搬进 `src/runtime-workbench-logic.js`(`createCancelActions` / `createWorkspaceListActions`),并删掉全仓零调用的 `runAll`,3090 → 2,998);大量逻辑已抽到 `src/*.js`(现 **112** 个模块 / 21,777 行,`sourceModules` 112 项;v3.24.68 新增 `clipboard-graph.js`,v3.24.74 新增 `image-admit.js`,v3.24.75 新增 `image-dedupe.js`,v3.24.76 新增 `workspace-purge.js`,v3.24.79 新增 `generation-provider-ping.js`,v3.24.80 删除无调用的 `createWBFlushViewport` 17 行)。 - 门禁:`npm run verify` = `verify:ci`(`build` → `node --check app.js` → `node --check dist/app.js` → `check-dist.js` → `lint`(ESLint 正确性规则,`src/` + `app.js`,P4-16a)→ `test:unit` → `test` → `test:facts`)+ `test:e2e` (A) `package.json`。 ## 2. 门禁与环境现状 @@ -167,7 +167,7 @@ - 同一张图被 3 个节点引用、hydrate 成 3 个不同 objectURL 时,preview/display 缓存各自 miss → 重复解码(与 F2 相邻)。 - **F10|`refs.genScheduler` 是桩** (A) → 未接线,暂无运行时影响(P3)。 - **F11|已建但未接线的模块层(2026-10-17 接线审计;2026-10-18 复核更正)** (A) - - **判定法**:`global.X =` / `root.X =` 判「导出」;跨文件裸引用判「读」;排除自合并(`src/runtime-constants.js:9`)。`app.js` 是**唯一生产消费者**(无 HTML 入口;`sw.js` 不引用模块全局)。**111 个模块中 59 个导出**被 `app.js` 读取;其余为未接线 / 仅测试 / 零引用(见下)。 + - **判定法**:`global.X =` / `root.X =` 判「导出」;跨文件裸引用判「读」;排除自合并(`src/runtime-constants.js:9`)。`app.js` 是**唯一生产消费者**(无 HTML 入口;`sw.js` 不引用模块全局)。**112 个模块中 59 个导出**被 `app.js` 读取;其余为未接线 / 仅测试 / 零引用(见下)。 - **仅被测试引用(9 模块 + 2 导出)**:`canvas-domain`、`generation-retry`、`generation-service`、`runtime-recovery-runner`、`runtime-state-bridge`、`runtime-store`、`storage-reconcile`、`storage-result`、`workspace-service`;导出 `IWBStorageHealthFactory`、`IWBPluginHostFactory`。(`storage-result` 是**存储层共享结果类型**,被 6 个存储模块读取,**非死代码**;`runtime-store` 为状态模型 epic 地基。) - **app.js 零引用(1 模块 + 3 导出)**:模块 `generation-controller`;导出 `IWBRuntimeMetricsFactory`、`IWBStorageRuntimeFactory`、`IWBUIComponents`。`canvas-relations` 已随 `06cf211` 删除(本文档早前把它列为"唯一可删者",实际已删)。零引用证据 = `grep -rn "<名字>" .`(排除 `node_modules|dist|vendor|test-results`)**只命中其自身赋值行**。 - **半接线 / 未接线**:`IWBRuntimeStateBridge` **无 app.js 引用(仅测试)**;`IWBRuntimeRunContext` **已接线**(`runNode` 读取运行上下文);`IWBGenerationController` 是完整但**从未被调用**的工厂;`ModularWorkspaceStore`(`app.js` 内)是 `storage-workspace` 的**预留接线 seam**(当前无下游使用,保留);`window.IWBImageFolder` 自注册后读回(装载路径)。 @@ -183,7 +183,7 @@ | `storage-reconcile` | 存储对账(`createReconciler`/`check`) | 内联对账 | 存储层收口 | | `runtime-recovery-runner` | 执行恢复候选(`candidate`/`valid`/`run`) | 内联恢复 | 断点恢复 | | `canvas-domain` | 画布域模型(`commit`/`updateNode`/`deleteNodes`…) | `CanvasStore` 那一套 | Workbench 解耦(P2-9) | - - **耦合面已冻结**:`tests/architecture-boundary-guard-test.js`(进 `npm run test:unit` 末环)冻结 app.js↔src 耦合面(**92** 项)与 `sourceModules` 顺序(**111** 项);命名例外由第 5 组冻结,新增非 `IWB` 前缀导出即打红。 + - **耦合面已冻结**:`tests/architecture-boundary-guard-test.js`(进 `npm run test:unit` 末环)冻结 app.js↔src 耦合面(**93** 项)与 `sourceModules` 顺序(**112** 项);命名例外由第 5 组冻结,新增非 `IWB` 前缀导出即打红。 ## 12. 易踩的坑 @@ -254,7 +254,7 @@ **信任模型(必须明示)**:形态 A 的插件是**可信代码**(与核心同权限、无沙箱);启停与设置是 UX 与可维护性手段,**不是安全边界**(同 §13.27 教训:前端开关一定可被绕过)。 -**守门与快照**:`tests/architecture-boundary-guard-test.js` 冻结「app.js ↔ src 耦合面」(**92** 项)与 `sourceModules` 顺序(**111** 项);新增模块、新增耦合、新增 dev 探针都**必须有意重生成对应快照**(`IWB_WRITE_BOUNDARY_SNAPSHOT=1`)。契约与行为的可执行验证在 `tests/plugin-host-test.js`(宿主单测)与 `tests/_plugin-host-probe.spec.js`(真实浏览器探针,`_` 前缀 + `iwb-dev-probe`,不进 34 门禁)。 +**守门与快照**:`tests/architecture-boundary-guard-test.js` 冻结「app.js ↔ src 耦合面」(**93** 项)与 `sourceModules` 顺序(**112** 项);新增模块、新增耦合、新增 dev 探针都**必须有意重生成对应快照**(`IWB_WRITE_BOUNDARY_SNAPSHOT=1`)。契约与行为的可执行验证在 `tests/plugin-host-test.js`(宿主单测)与 `tests/_plugin-host-probe.spec.js`(真实浏览器探针,`_` 前缀 + `iwb-dev-probe`,不进 34 门禁)。 **关键陷阱**:`normalizeNodes`(现位于 `src/canvas-normalize.js`)会**静默丢弃**不在 `NODE_H` 里的节点类型 ⇒ 新增节点类型必须先登记 `NODE_H`,否则节点一刷新就消失(§13.27 规则三的同一失败模式)。 diff --git a/package.json b/package.json index 259458a..e12e531 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "image-workbench-web", "private": true, - "version": "3.26.83", + "version": "3.26.84", "description": "Browser-based node canvas image workbench", "scripts": { "build": "node scripts/build.js && node scripts/copy-plugins.js", @@ -10,7 +10,7 @@ "app:build": "tauri build", "lint": "eslint src app.js", "test": "node tests/relay-task-graph-fixture-test.js && node tests/plugin-style-node-test.js && node tests/inherit-text-test.js", - "test:unit": "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 tests/design-token-ratchet-test.js && node tests/theme-contrast-test.js && node tests/image-file-ref-preview-test.js", + "test:unit": "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 tests/design-token-ratchet-test.js && node tests/theme-contrast-test.js && node tests/image-file-ref-preview-test.js", "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", diff --git a/scripts/build.js b/scripts/build.js index b93b960..2b1c94e 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -63,6 +63,7 @@ const sourceModules = [ 'image-blob-store.js', 'runtime-crash-log.js', 'storage-health.js', + 'gallery-audit.js', 'storage-config-shape.js', 'generation-default-model.js', 'storage-indexeddb.js', diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index d218cf0..4b49cda 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "image-workbench" -version = "3.26.83" +version = "3.26.84" description = "无限画布 · 生图工作台桌面版" authors = ["malongan"] license = "" diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 123e634..2422519 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "../node_modules/@tauri-apps/cli/config.schema.json", "productName": "image-workbench", - "version": "3.26.83", + "version": "3.26.84", "identifier": "com.malongan.imageworkbench", "build": { "frontendDist": "../dist", diff --git a/src/gallery-audit.js b/src/gallery-audit.js new file mode 100644 index 0000000..27b5731 --- /dev/null +++ b/src/gallery-audit.js @@ -0,0 +1,181 @@ +/* gallery-audit.js —— 图库落盘自检(2026-11-26,只读) + * + * 为什么单独成模块:用户报障「图库面板有图,但资料目录 images/gallery 里找不到」。 + * 这句话可能对应三种完全不同的状态,靠猜会修错地方: + * ① 原图已落盘(out_orig_ 有键、磁盘有文件) + * ② 仅缩略图(只有 out_ 的 320px 副本;原图从未写,或写了但文件被删) + * ③ 全丢(索引条目在,缩略图与原图都没有,只剩远程 URL) + * 这里只做判定与报告,不改任何存储;写入侧用 noteWrite() 记本次会话的成功/失败。 + * + * 判定输入刻意是可注入的事实(磁盘登记 + IDB 键集合),便于单测: + * run({ index, storageFile, idbKeys }) + * · storageFile = IWBStorageFile.galleryAudit(index) 的结果(桌面端才有真实磁盘文件) + * · idbKeys = IDB.keys()(浏览器/兜底路径只有键集合) + */ +;(function (global) { + 'use strict' + + const STATES = { orig: 'orig', thumb: 'thumb', lost: 'lost' } + const LABELS = { orig: '原图 OK', thumb: '仅缩略图', lost: '全丢' } + + const origKeyOf = (item) => String((item && item.origIdb) || ('out_orig_' + String((item && item.name) || ''))) + const thumbKeyOf = (item) => String((item && item.idb) || ('out_' + String((item && item.name) || ''))) + + // 单条判定。fact 由 storageFile.galleryAudit 或键集合归一而来: + // { orig: bool, thumb: bool, origPath: string, thumbPath: string, origKeyKnown: bool } + function classify (item, fact) { + const f = fact || {} + const hasOrig = !!f.orig + const hasThumb = !!f.thumb + let state = STATES.lost + let reason = '原图和缩略图都不在本地(只剩远程 URL)' + if (hasOrig) { + state = STATES.orig + reason = '原图已落盘' + } else if (hasThumb) { + state = STATES.thumb + if (f.origPath) reason = '原图文件缺失(登记还在,磁盘没有)' + else if (f.origKeyKnown === false) reason = '原图键未登记(生成后没有写入 out_orig_)' + else reason = '原图未落盘(只有 320px 缩略图)' + } + return { + name: String((item && item.name) || ''), + url: String((item && item.url) || ''), + state, + label: LABELS[state], + reason, + origKey: origKeyOf(item), + thumbKey: thumbKeyOf(item), + origPath: String(f.origPath || ''), + thumbPath: String(f.thumbPath || ''), + } + } + + function summarize (rows) { + const list = Array.isArray(rows) ? rows : [] + const out = { total: list.length, orig: 0, thumb: 0, lost: 0, pending: 0 } + for (const r of list) { + if (!r) continue + if (r.state === STATES.orig) out.orig++ + else if (r.state === STATES.thumb) out.thumb++ + else out.lost++ + } + return out + } + + function deduceFactsFromKeys (item, keySet) { + const keys = keySet || new Set() + const ok = origKeyOf(item) + const tk = thumbKeyOf(item) + return { + orig: keys.has(ok), + thumb: keys.has(tk), + origPath: '', + thumbPath: '', + origKeyKnown: !!(item && item.origIdb), + } + } + + function fileFacts (item, fileRows) { + const name = String((item && item.name) || '') + const f = fileRows && fileRows[name] + if (!f) return deduceFactsFromKeys(item, new Set()) + return { + orig: !!f.orig, + thumb: !!f.thumb, + origPath: String(f.origPath || ''), + thumbPath: String(f.thumbPath || ''), + origKeyKnown: !!f.origKey, + } + } + + async function run (opts) { + const o = opts || {} + const index = Array.isArray(o.index) ? o.index : [] + let facts = null + let dir = '' + let galleryFiles = [] + let deskError = '' + const sf = o.storageFile + if (sf && typeof sf.galleryAudit === 'function') { + try { + const r = await sf.galleryAudit(index) + if (r && r.ok) { + facts = {} + for (const row of (r.rows || [])) if (row && row.name) facts[String(row.name)] = row + dir = String(r.dir || '') + galleryFiles = Array.isArray(r.galleryFiles) ? r.galleryFiles.slice() : [] + } else if (r && r.error) deskError = String(r.error) + } catch (e) { deskError = String((e && e.message) || e) } + } + const keySet = new Set(Array.isArray(o.idbKeys) ? o.idbKeys.map(String) : []) + const rows = index.map((it) => classify(it, facts ? fileFacts(it, facts) : deduceFactsFromKeys(it, keySet))) + // 磁盘上有、但没有任何索引条目引用的原图:删图只清了索引时留下的孤儿 + let orphans = [] + if (facts && galleryFiles.length) { + const used = new Set() + for (const r of rows) if (r.origPath) used.add(String(r.origPath).split('/').pop()) + orphans = galleryFiles.filter((n) => !used.has(String(n))) + } + return { + at: Date.now(), + dir, + desktop: !!facts, + error: deskError, + summary: summarize(rows), + rows, + orphans, + session: stats(), + } + } + + // 本次会话写入计数:挂在存储层(storage-file / storage-runtime),不改生成流程。 + const session = { origOk: 0, origFail: 0, reasons: {} } + function noteWrite (key, ok, error) { + const k = String(key || '') + if (k.indexOf('out_orig_') !== 0) return + if (ok) { session.origOk++; return } + session.origFail++ + const why = String((error && (error.message || error.error)) || error || '未知原因').slice(0, 120) + session.reasons[why] = (session.reasons[why] || 0) + 1 + } + function stats () { + const reasons = Object.keys(session.reasons).map((k) => ({ reason: k, count: session.reasons[k] })).sort((a, b) => b.count - a.count) + return { origOk: session.origOk, origFail: session.origFail, reasons } + } + function resetSession () { + session.origOk = 0; session.origFail = 0; session.reasons = {} + } + + function report (result) { + const r = result || {} + const s = r.summary || summarize(r.rows) + const lines = [] + lines.push('图库落盘自检' + (r.at ? ' · ' + new Date(r.at).toISOString() : '')) + if (r.dir) lines.push('资料目录:' + r.dir) + lines.push('索引 ' + s.total + ' 条:原图 OK ' + s.orig + ' / 仅缩略图 ' + s.thumb + ' / 全丢 ' + s.lost) + if (r.desktop) lines.push('磁盘上未被索引引用的原图:' + (r.orphans ? r.orphans.length : 0) + ' 个') + if (!r.desktop) lines.push('未读取磁盘文件(浏览器环境或资料目录未就绪),判定依据仅为 IDB 键集合' + (r.error ? ':' + r.error : '')) + lines.push('本次会话原图写入:成功 ' + ((r.session && r.session.origOk) || 0) + ' / 失败 ' + ((r.session && r.session.origFail) || 0)) + for (const why of ((r.session && r.session.reasons) || []).slice(0, 5)) lines.push(' · 失败原因 ×' + why.count + ':' + why.reason) + lines.push('') + lines.push('明细(前 20 条):') + for (const row of (Array.isArray(r.rows) ? r.rows : []).slice(0, 20)) { + lines.push(' [' + row.label + '] ' + row.name + ' — ' + row.reason + (row.origPath ? ' · ' + row.origPath : '')) + } + if (!Array.isArray(r.rows) || !r.rows.length) lines.push(' (图库索引为空)') + return lines.join('\n') + } + + global.IWBGalleryAudit = { + STATES: STATES, + LABELS: LABELS, + classify: classify, + summarize: summarize, + run: run, + report: report, + noteWrite: noteWrite, + stats: stats, + resetSession: resetSession, + } +})(typeof window !== 'undefined' ? window : globalThis) diff --git a/src/storage-file.js b/src/storage-file.js index 6664378..98b6661 100644 --- a/src/storage-file.js +++ b/src/storage-file.js @@ -196,6 +196,7 @@ // 立即落盘:登记表只存在 data.json 里,晚 800ms 就可能被强杀丢掉, // 而画布文件是即时写的 ⇒ 引用还在、登记没了,GC 会把在用图片当孤儿。 await flush() + try { global.IWBGalleryAudit && global.IWBGalleryAudit.noteWrite(key, true) } catch (e) { /* 计数失败不影响写入 */ } return true } const s = String(value) @@ -211,6 +212,7 @@ assets[String(key)] = { f: rel, k: 'dataurl', m: dec.mime } schedule() await flush() + try { global.IWBGalleryAudit && global.IWBGalleryAudit.noteWrite(key, true) } catch (e) { /* 计数失败不影响写入 */ } return true } } @@ -219,6 +221,7 @@ return true } catch (e) { try { global.IWBMetricsSwallow && global.IWBMetricsSwallow('file-kv-put', e) } catch (e2) { /* ignore */ } + try { global.IWBGalleryAudit && global.IWBGalleryAudit.noteWrite(key, false, e) } catch (e2) { /* ignore */ } return { ok: false, error: String((e && e.message) || e) } } }, @@ -1332,6 +1335,48 @@ } catch (e) { return { ok: false, error: String((e && e.message) || e) } } } + // 图库落盘自检(2026-11-26):只读。按索引条目查 assets 登记 + 磁盘文件是否真的存在, + // 并顺带列出 images/gallery 里没被任何条目引用的文件(删图只清索引时的孤儿)。 + // 只做 exists,不读字节 —— 几百张原图读回 base64 会把堆顶撑高(诊断页点一下不该更卡)。 + async function galleryAudit (index) { + if (!enabled() || !dir) return { ok: false, error: '资料目录未就绪(浏览器环境)' } + const list = Array.isArray(index) ? index : [] + const rows = new Array(list.length) + let cursor = 0 + const existsAt = async (rel) => { + if (!rel) return false + try { return !!(await fs().exists(await join(dir, rel))) } catch (e) { return false } + } + const worker = async () => { + while (true) { + const i = cursor++ + if (i >= list.length) return + const it = list[i] || {} + const name = String(it.name || '') + const origKey = String(it.origIdb || ('out_orig_' + name)) + const thumbKey = String(it.idb || ('out_' + name)) + const oa = assets[origKey] + const ta = assets[thumbKey] + const origPath = (oa && oa.f) || '' + const thumbPath = (ta && ta.f) || '' + rows[i] = { + name, origKey: !!oa, thumbKey: !!ta, + origPath, thumbPath, + orig: await existsAt(origPath), + thumb: await existsAt(thumbPath), + } + } + } + // 并发 4:几十条是常态,串行会让诊断页点一下等好几秒;再高会把 IPC 打满。 + await Promise.all([worker(), worker(), worker(), worker()]) + let galleryFiles = [] + try { + const ents = await fs().readDir(await join(dir, IMG_DIR, IMG_CAT.gallery)) + galleryFiles = (ents || []).filter((e) => e && !e.isDirectory).map((e) => String(e.name || '')).filter(Boolean) + } catch (e) { galleryFiles = [] } + return { ok: true, dir: dir, rows: rows, galleryFiles: galleryFiles } + } + // 2026-11-24:按图库条目名删字节 —— app.js 只传 names + 索引,逻辑留在这里(app.js 行数棘轮)。 async function deleteGalleryBytesFor (names, index) { const wanted = Array.isArray(names) ? names : [] @@ -1346,7 +1391,7 @@ } global.IWBStorageFile = { - enabled, ready: init, flush, runtime, pickDir, switchTo, migrateTo, deleteImageBytes, deleteGalleryBytesFor, gcImages, rotateTrash, galleryThumb, readDisplayThumb, readDisplayThumbUrl, writeDisplayThumb, writeDisplayThumbBlob, pruneThumbs, cleanupLegacy, maintain, + enabled, ready: init, flush, runtime, pickDir, switchTo, migrateTo, deleteImageBytes, deleteGalleryBytesFor, galleryAudit, gcImages, rotateTrash, galleryThumb, readDisplayThumb, readDisplayThumbUrl, writeDisplayThumb, writeDisplayThumbBlob, pruneThumbs, cleanupLegacy, maintain, plugins: { manifest: pluginManifest, read: pluginRead, write: pluginWrite, remove: pluginRemove, dir: pluginDir, listLocal: pluginListLocal, listDirs: pluginListDirs, readFile: pluginReadFile, writeFile: pluginWriteFile, writeBinary: pluginWriteBinary, mkdir: pluginMkdir, removeDir: pluginRemoveDir, renameDir: pluginRenameDir, existsDir: pluginExistsDir }, pluginData: { read: pluginDataRead, write: pluginDataWrite, remove: pluginDataRemove, list: pluginDataList }, pluginFiles: { put: pluginFilePut, get: pluginFileGet, list: pluginFileList, remove: pluginFileRemove, stat: pluginFileStat, dir: pluginFilesDir, readBytes: pluginFileReadBytes, listAll: pluginFilesListAll }, diff --git a/src/storage-runtime.js b/src/storage-runtime.js index 9ec26e1..b4dd2c0 100644 --- a/src/storage-runtime.js +++ b/src/storage-runtime.js @@ -86,7 +86,12 @@ } catch (e) { finish(false) } }) }) - const write = (store, key, value) => request(store, 'readwrite', (objectStore) => objectStore.put(value, key)).then((v) => v === true) + const write = (store, key, value) => request(store, 'readwrite', (objectStore) => objectStore.put(value, key)).then((v) => { + const ok = v === true + // 图库落盘自检的会话计数(只认 out_orig_,其它键会被 noteWrite 自己忽略) + try { global.IWBGalleryAudit && global.IWBGalleryAudit.noteWrite(key, ok, ok ? null : 'IndexedDB 写入失败') } catch (e) { /* 计数失败不影响写入 */ } + return ok + }) const remove = (store, key) => request(store, 'readwrite', (objectStore) => objectStore.delete(key)).then((v) => v === true) const read = (store, key) => request(store, 'readonly', (objectStore) => objectStore.get(key)) return { diff --git a/src/ui-settings-tab-diag.js b/src/ui-settings-tab-diag.js index 0ca3b91..12d5a5f 100644 --- a/src/ui-settings-tab-diag.js +++ b/src/ui-settings-tab-diag.js @@ -28,6 +28,15 @@ const fmtKB = (n) => (Number(n) || 0) >= 1024 ? (Math.round((Number(n) / 1024) * 10) / 10) + 'MB' : Math.round(Number(n) || 0) + 'KB' // v3.24.67:旧实现在 writeText() 之后**不 await 也不 catch**,下一行无条件提示「已复制」—— // 权限被拒 / 非 https / 浏览器不给写剪贴板时是**假成功**,用户以为拿到了其实没有。 + const copyGallery = async () => { + const g = storageAudit && storageAudit.gallery + if (!g) { setMsg({ type: 'err', text: '请先点「存储体检」' }); return } + const text = (typeof window !== 'undefined' && window.IWBGalleryAudit && window.IWBGalleryAudit.report) ? window.IWBGalleryAudit.report(g) : JSON.stringify(g, null, 2) + const C = (typeof window !== 'undefined') ? window.IWBClipboardCopy : null + if (!C || typeof C.copyText !== 'function') { setMsg({ type: 'err', text: '当前环境不支持复制,请用「导出 JSON」' }); return } + const ok = await C.copyText(text) + setMsg(ok ? { type: 'ok', text: '图库落盘报告已复制' } : { type: 'err', text: '复制失败(权限被拒或非安全上下文)' }) + } const copyDiag = async () => { let text = '' try { @@ -118,6 +127,22 @@ el('div', { className: 'iwb-diag-extra' }, '存放于资料目录 plugin-data/(与插件代码分离,卸载插件默认保留)'), ) : null, ) : el('div', { className: 'iwb-hint' }, '点「存储体检」查看一致性;发现悬空 / 孤儿再决定是否回收。'), + el('div', { className: 'iwb-section-sub' }, '图库落盘自检(随存储体检一起读取)'), + el('div', { className: 'iwb-hint' }, '逐条判断:原图已落盘 / 仅缩略图 / 全丢。桌面端会真的去 images/gallery 查文件是否存在(只查存在性,不读字节);报告不含 Key 与图片内容。'), + (storageAudit && storageAudit.gallery) ? el('div', null, + el('div', { className: 'iwb-diag-list' }, + el('div', { className: 'iwb-diag-item' }, + el('div', { className: 'iwb-diag-head' }, '索引 ' + storageAudit.gallery.summary.total + ' 条:原图 OK ' + storageAudit.gallery.summary.orig + ' / 仅缩略图 ' + storageAudit.gallery.summary.thumb + ' / 全丢 ' + storageAudit.gallery.summary.lost), + el('div', { className: 'iwb-diag-extra' }, (storageAudit.gallery.desktop ? ('资料目录:' + (storageAudit.gallery.dir || '未知') + ' · 未被索引引用的原图 ' + (storageAudit.gallery.orphans || []).length + ' 个') : ('未读到磁盘文件' + (storageAudit.gallery.error ? ':' + storageAudit.gallery.error : ',仅按 IDB 键判定'))) + + ' · 本次会话原图写入 成功 ' + ((storageAudit.gallery.session && storageAudit.gallery.session.origOk) || 0) + ' / 失败 ' + ((storageAudit.gallery.session && storageAudit.gallery.session.origFail) || 0)), + ), + (storageAudit.gallery.rows || []).slice(0, 20).map((row, i) => el('div', { key: 'g' + i, className: 'iwb-diag-item' }, + el('div', { className: 'iwb-diag-head' }, '[' + row.label + '] ' + row.name), + el('div', { className: 'iwb-diag-extra' }, row.reason + (row.origPath ? ' · ' + row.origPath : '') + (row.url ? ' · 远程 URL 作兜底' : '')), + )), + ), + el('div', { className: 'iwb-row' }, el('button', { className: 'iwb-btn iwb-btn-sm', onClick: copyGallery }, '复制落盘报告')), + ) : el('div', { className: 'iwb-hint' }, '点上面的「存储体检」后在这里看结果。'), el('div', { className: 'iwb-section-sub' }, '画板找回(索引里没有、但本体还在 · ' + orphanRows.length + ' 个)'), orphanRows.length ? el('div', { className: 'iwb-diag-list' }, orphanRows.map((row, i) => el('div', { key: 'or' + i, className: 'iwb-diag-item' }, el('div', { className: 'iwb-diag-head' }, row.name + ' · ' + row.nodes + ' 个节点 · ' + row.id), diff --git a/tests/fixtures/iwb-app-global-reads.json b/tests/fixtures/iwb-app-global-reads.json index 8d808e3..b14bf37 100644 --- a/tests/fixtures/iwb-app-global-reads.json +++ b/tests/fixtures/iwb-app-global-reads.json @@ -13,6 +13,7 @@ "IWBDesktop", "IWBDesktopHelpers", "IWBDockArea", + "IWBGalleryAudit", "IWBGalleryHydration", "IWBGallerySync", "IWBGenerationEndpoint", diff --git a/tests/fixtures/iwb-source-modules-order.json b/tests/fixtures/iwb-source-modules-order.json index f0116ff..d826d28 100644 --- a/tests/fixtures/iwb-source-modules-order.json +++ b/tests/fixtures/iwb-source-modules-order.json @@ -35,6 +35,7 @@ "image-blob-store.js", "runtime-crash-log.js", "storage-health.js", + "gallery-audit.js", "storage-config-shape.js", "generation-default-model.js", "storage-indexeddb.js", diff --git a/tests/gallery-audit-test.js b/tests/gallery-audit-test.js new file mode 100644 index 0000000..67d07e5 --- /dev/null +++ b/tests/gallery-audit-test.js @@ -0,0 +1,84 @@ +'use strict' + +const assert = require('assert') +const fs = require('fs') +const path = require('path') +const vm = require('vm') + +const root = path.resolve(__dirname, '..') +const sandbox = {} +vm.runInNewContext(fs.readFileSync(path.join(root, 'src', 'gallery-audit.js'), 'utf8'), sandbox) +const A = sandbox.IWBGalleryAudit + +// 1) 三态判定:原图 / 仅缩略图 / 全丢 +const orig = A.classify({ name: 'a.png', url: 'http://x/a.png', origIdb: 'out_orig_a.png', idb: 'out_a.png' }, { orig: true, thumb: true, origPath: 'images/gallery/aaa.png' }) +assert.strictEqual(orig.state, 'orig') +assert.strictEqual(orig.label, '原图 OK') +const thumb = A.classify({ name: 'b.png', url: 'http://x/b.png' }, { orig: false, thumb: true, origPath: '', origKeyKnown: true }) +assert.strictEqual(thumb.state, 'thumb') +assert.ok(/原图未落盘/.test(thumb.reason)) +assert.strictEqual(thumb.origKey, 'out_orig_b.png') +const lost = A.classify({ name: 'c.png', url: 'http://x/c.png' }, { orig: false, thumb: false }) +assert.strictEqual(lost.state, 'lost') +assert.ok(/只剩远程 URL/.test(lost.reason)) +// 登记了但磁盘没有:原因必须与「从未写」区分开 +const missingFile = A.classify({ name: 'd.png' }, { orig: false, thumb: true, origPath: 'images/gallery/ddd.png', origKeyKnown: true }) +assert.ok(/文件缺失/.test(missingFile.reason)) +// 只在磁盘有原图、没有缩略图:仍算已落盘 +const origOnly = A.classify({ name: 'e.png' }, { orig: true, thumb: false }) +assert.strictEqual(origOnly.state, 'orig') + +const sum = A.summarize([orig, thumb, lost, missingFile, origOnly]) +assert.deepStrictEqual({ total: sum.total, orig: sum.orig, thumb: sum.thumb, lost: sum.lost }, { total: 5, orig: 2, thumb: 2, lost: 1 }) + +// 2) run:桌面端以磁盘事实为准,并找出未被索引引用的原图 +const index = [ + { name: 'x.png', url: 'https://cdn/x.png', origIdb: 'out_orig_x.png', idb: 'out_x.png' }, + { name: 'y.png', url: 'https://cdn/y.png', idb: 'out_y.png' }, +] +const fakeFile = { + async galleryAudit () { + return { + ok: true, + dir: '/tmp/iwb', + rows: [ + { name: 'x.png', orig: true, thumb: true, origPath: 'images/gallery/x.png', thumbPath: 'images/thumbs/x.jpg', origKey: true }, + { name: 'y.png', orig: false, thumb: true, origPath: '', thumbPath: 'images/thumbs/y.jpg', origKey: false }, + ], + galleryFiles: ['x.png', 'orphan.png'], + } + }, +} +;(async () => { + const r = await A.run({ index, storageFile: fakeFile, idbKeys: [] }) + assert.strictEqual(r.desktop, true) + assert.strictEqual(r.dir, '/tmp/iwb') + assert.strictEqual(r.summary.orig, 1) + assert.strictEqual(r.summary.thumb, 1) + assert.strictEqual(r.rows[1].reason.indexOf('未登记') >= 0, true) + assert.deepStrictEqual(r.orphans, ['orphan.png']) + + // 3) 浏览器路径:只看键集合 + const web = await A.run({ index, storageFile: null, idbKeys: ['out_orig_x.png', 'out_x.png', 'out_y.png'] }) + assert.strictEqual(web.desktop, false) + assert.strictEqual(web.summary.orig, 1) + assert.strictEqual(web.summary.thumb, 1) + + // 4) 会话计数:只认 out_orig_,失败原因聚合 + A.resetSession() + A.noteWrite('out_orig_a.png', true) + A.noteWrite('out_orig_b.png', false, 'quota exceeded') + A.noteWrite('out_c.png', false, '忽略:不是原图') + const st = A.stats() + assert.strictEqual(st.origOk, 1) + assert.strictEqual(st.origFail, 1) + assert.strictEqual(st.reasons[0].reason, 'quota exceeded') + const text = A.report(Object.assign({}, r, { session: A.stats() })) + assert.ok(/图库落盘自检/.test(text)) + assert.ok(/原图 OK 1/.test(text)) + assert.ok(/仅缩略图 1/.test(text)) + assert.ok(/失败 1/.test(text)) + assert.ok(!/https:\/\//.test(text), '报告不得包含远程 URL') + + console.log('gallery-audit: 全部通过') +})().catch((e) => { console.error(e); process.exit(1) }) diff --git a/tests/source-text-ratchet-test.js b/tests/source-text-ratchet-test.js index 482ef5d..4a45524 100644 --- a/tests/source-text-ratchet-test.js +++ b/tests/source-text-ratchet-test.js @@ -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 = 9182 +const MAX_APP_JS_LINES = 9183 // +1(2026-11-26 图库落盘自检装配:诊断页需要把 storage-file 的磁盘事实接进 wStorageAudit;逻辑在 src/gallery-audit.js) const MAX_APP_JS_SHARE = 0.40 // ── 历史记账(供回溯,逐条保留)────────────────────────────────────────────── diff --git a/types/iwb-globals.d.ts b/types/iwb-globals.d.ts index 4da85ba..7835301 100644 --- a/types/iwb-globals.d.ts +++ b/types/iwb-globals.d.ts @@ -18,6 +18,7 @@ interface Window { IWBStorageContract?: any IWBStorageResult?: any IWBStorageHealth?: any + IWBGalleryAudit?: any IWBStorageBackup?: any IWBStorageGroups?: any IWBStorageWorkspace?: any