OPFS 存储适配器:可配置切换的持久化后端,CAS 语义与 IndexedDB 一致 (TML-90) - #5
Open
SeasonsChange422 wants to merge 1 commit into
Open
Conversation
- 新增共享存储抽象 project-storage.ts(StorageBackend/ProjectStorage/SaveOutcome 等)
- 新增 OpfsProjectStore:Web Locks 跨标签页互斥 + 临时文件 move 原子写,
CAS(期望基线/创建语义/无条件)与损坏记录策略对齐 IndexedDB 行为
- project-persistence/studio-runtime/LumoraStudio 支持 init({ storage: 'opfs' }),
嵌入式宿主经 ?storage=opfs 切换;缺省仍为 IndexedDB,既有功能不回归
- 单测:project-store-opfs(14)+ project-persistence-opfs(6),内存 OPFS shim
- e2e:?storage=opfs 下 AC1 导出→清空→导入恢复与 AC2 跨标签页 CAS 冲突
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
摘要
TML-53 范围项 TML-90:OPFS 存储适配器。实现与现有 IndexedDB 适配器可切换的 OPFS(Origin Private File System)持久化后端,经持久化门面
project-persistence.ts统一接入;行为与 IndexedDB 完全一致:项目保存/加载/删除/最近项目 + revision 防倒退(CAS) 语义,既有持久化功能(TML-53 AC1-AC4)不回归。实现
packages/studio/src/persistence/project-storage.ts(新)— 共享存储抽象:StorageBackend('indexeddb' | 'opfs')、ProjectStorage接口、SaveOutcome/RenameOutcome/DuplicateOutcome、estimateStorage、CAS 比对与配额错误判定等公共工具。packages/studio/src/persistence/project-store-opfs.ts(新)—OpfsProjectStore:<root>/projects/<encodeURIComponent(uri)>,记录与 IndexedDB 同形;根目录名同为lumora-studio,切换后端不混淆命名空间;move原子覆盖」,配额不足/中断时旧记录保持原样;create返回 null,持久化静默降级(与 IndexedDB 一致)。project-persistence.ts/studio-runtime.ts/LumoraStudio.tsx—init({ storage: 'opfs' | 'indexeddb' })可配置后端,缺省'indexeddb'(既有行为不变);新增persistence.backend只读属性。examples/embedded-host/src/App.tsx— 经?storage=opfs查询参数切换后端(演示宿主)。index.ts— 导出OpfsProjectStore与存储抽象类型。测试
project-store-opfs.test.ts(14,内存 OPFS shim,覆盖重开持久化、列表排序、CAS 全部语义、跨实例并发、损坏记录、配额原子性与临时文件清理、OPFS 不可用降级);project-persistence-opfs.test.ts(6,门面层切换、后端隔离、AC2 冲突锁存与「加载较新版本」解决)。e2e/persistence-opfs.spec.ts(真实 Chromium OPFS;AC1 导出→清空→导入→刷新重开全链路 + 直接断言数据落 OPFS 目录;AC2 双标签页 Web Locks 下 CAS 冲突与显式解决)。验证(本机)
npm run e2e;曾出现 4 个 WebGL/视口密集用例在整包并发下超时,单独重跑与整包重跑均通过,判定为资源争用性 flake,非回归)