✨ 完善备份/还原/导入完整性:SC/TM/VM 自定义配置 + 设置备份 + 资源修复#1554
Open
CodFrm wants to merge 21 commits into
Open
Conversation
设置属于备份的一部分(#1533「扩大备份范围」),不应作为独立的 导出/导入配置功能存在。删除 Tools 页的「导出配置/导入配置」按钮、 独立配置文件流程、client.getConfigBundle 及其 group.on 注册、 以及 3 个孤立 i18n 键;保留设置随主备份 zip 往返(backup 内嵌 getConfigBundle)与导入页「同时还原设置」开关(restoreConfigBundle)。
Member
Author
人工验收清单
0. 环境
1. ScriptCat 自定义配置往返前置:脚本原始元数据含 match/include/exclude/connect/run-at,安装后在 ScriptCat 修改自定义规则。
2. 替换、合并和空列表
3. GM 值
4. Tampermonkey 合并语义
5. Tampermonkey 替换语义
6. Violentmonkey 导入
7. 设置随本地 ZIP 往返
8. 取消还原设置
9. 敏感配置排除使用唯一假标记
rg -n "MANUAL_TEST_SECRET_1554|cloud_sync|cat_file_storage" /path/to/unzipped-backup10. 覆盖导入前置:本地有 A~J,备份只有 A~E。
11. 默认合并导入
12. 文本资源
13. 二进制资源
14. 单资源失败提示
15. 兼容性
16. 导入页交互
17. 设置恢复异常隔离
18. 云端备份边界(有测试 WebDAV 时)
19. 最终结论
建议证据放在本地 |
Contributor
There was a problem hiding this comment.
Pull request overview
该 PR 系统性增强了 ScriptCat 的「备份 / 还原 / 导入」完整性:在脚本层面补齐 SC/TM/VM 三种来源的自定义配置往返与归一化导入;在设置层面把 SystemConfig 与 Agent(模型/MCP/任务)纳入同一个主备份 zip 往返;并修复资源导入落库与失败回显能力,配合导入页 UI 支持覆盖导入与按板块选择还原设置。
Changes:
- 新增
selfMetadata归一化管线:SC 备份无损往返;TM/VM 导入按 merge/replace 语义推导为 SC 形状后统一落库。 - 新增设置备份
scriptcat-config.json(ConfigBundle)并在导入页支持“同时还原设置”与按板块筛选还原(含 Agent 配置)。 - 资源导入改为
save以确保新资源可落库,并在导入 UI 中对“脚本已导入但部分资源失败”进行 warning 状态与逐项提示。
Reviewed changes
Copilot reviewed 34 out of 34 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/pkg/backup/struct.ts | 扩展备份结构:脚本 settings 增加 checkUpdate?、引入 selfMeta? 与 config?,新增 VM 根清单类型 |
| src/pkg/backup/self_metadata.ts | 新增 override/custom → selfMetadata 归一化与 VM values 键编码工具 |
| src/pkg/backup/self_metadata.test.ts | 覆盖 merge/replace 语义、VM custom 归一化与 values uri 编码测试 |
| src/pkg/backup/import.ts | 导入流程支持解析 scriptcat-config.json;增强 VM 根清单导入(enabled/position/selfMeta/values/file_url/checkUpdate) |
| src/pkg/backup/import.test.ts | VM 导入归一化与 config bundle 容错测试 |
| src/pkg/backup/export.ts | 备份导出时可选写入 scriptcat-config.json |
| src/pkg/backup/config_sections.ts | 新增设置板块划分与按板块过滤 ConfigBundle 的逻辑 |
| src/pkg/backup/config_sections.test.ts | 板块分类/计数与过滤逻辑测试 |
| src/pkg/backup/config_bundle.ts | 定义 ConfigBundle 结构、版本校验与过滤本机相关键(STORAGE_LOCAL_KEYS) |
| src/pkg/backup/config_bundle.test.ts | ConfigBundle 解析与过滤规则测试 |
| src/pkg/backup/backup.test.ts | 补充 selfMeta 与 config bundle 往返测试 |
| src/pages/import/mobile.tsx | 移动端导入页:资源失败 warning 回显;覆盖导入开关;设置还原板块选择(Sheet)与导入按钮文案/可用性更新 |
| src/pages/import/mobile.test.tsx | 移动端:设置板块选中时可导入;打开设置自定义面板的可访问性标题断言 |
| src/pages/import/logic.ts | 新增 deriveSelfMetadata:SC 直接用 selfMeta;TM 从 override 推导;VM 由 import.ts 预置 |
| src/pages/import/logic.test.ts | deriveSelfMetadata 行为测试 |
| src/pages/import/hooks.ts | 导入编排增强:覆盖导入(导入前清空脚本);导入时覆盖 selfMetadata;资源失败列表回显;设置板块选择与还原调用 |
| src/pages/import/hooks.test.ts | useImport:设置-only 备份可导入;板块默认不勾选;restoreConfigBundle 调用与 checkUpdate/selfMetadata 覆盖相关断言 |
| src/pages/import/components.tsx | 桌面端导入页:warning 状态与 tooltip;覆盖导入;设置板块 Popover 选择控件;导入按钮文案/可用性更新 |
| src/pages/import/components.test.tsx | 桌面端:设置板块选中可导入;设置触发器点击行为测试 |
| src/pages/components/ui/popover.tsx | UI 组件补充 PopoverAnchor 导出以支持自定义触发结构 |
| src/locales/zh-TW/install.json | 新增资源失败/覆盖导入/设置还原相关文案与按钮文案;调整 trust_hint |
| src/locales/zh-CN/install.json | 同上(简体中文) |
| src/locales/en-US/install.json | 同上(英文) |
| src/locales/de-DE/install.json | 同上(德文) |
| src/locales/ja-JP/install.json | 同上(日文) |
| src/locales/ru-RU/install.json | 同上(俄文) |
| src/locales/tr-TR/install.json | 同上(土耳其文) |
| src/locales/vi-VN/install.json | 同上(越南文) |
| src/app/service/service_worker/synchronize.ts | 备份导出可选包含 ConfigBundle;新增 get/restore ConfigBundle;资源导入返回失败清单;导出/云备份默认带设置;注册 restoreConfigBundle 消息 |
| src/app/service/service_worker/synchronize.test.ts | 覆盖“云端备份也带设置”、默认/摘要模型选择往返、systemConfig 过滤与写回 sync storage 测试 |
| src/app/service/service_worker/script.ts | 安装参数新增 overwriteSelfMetadata,用于备份导入覆盖本地自定义元数据 |
| src/app/service/service_worker/resource.ts | 资源导入支持二进制(base64);并改用 save 确保新资源可落库 |
| src/app/service/service_worker/resource.test.ts | 覆盖二进制/文本资源导入测试 |
| src/app/service/service_worker/client.ts | SynchronizeClient:importResources 改为返回失败列表;新增 restoreConfigBundle RPC |
Comment on lines
427
to
431
| async importResource(uuid: string, data: ResourceBackup, type: ResourceType) { | ||
| // 导入资源 | ||
| if (!data.source) { | ||
| // 导入资源:文本资源用 source,二进制资源(如图片/字体)只有 base64(dataURI) | ||
| if (!data.source && !data.base64) { | ||
| return undefined; | ||
| } |
Comment on lines
+145
to
+154
| const sync = new ChromeStorage("system", true); | ||
| const modelRepo = new AgentModelRepo(); | ||
| const mcpRepo = new MCPServerRepo(); | ||
| const taskRepo = new AgentTaskRepo(); | ||
| await Promise.all([ | ||
| ...Object.entries(bundle.systemConfig || {}).map(([k, v]) => sync.set(k, v)), | ||
| ...(bundle.agent?.models || []).map((m) => modelRepo.saveModel(m)), | ||
| ...(bundle.agent?.mcp || []).map((m) => mcpRepo.saveServer(m)), | ||
| ...(bundle.agent?.tasks || []).map((t) => taskRepo.saveTask(t)), | ||
| ]); |
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.
Checklist / 检查清单
Description / 描述
系统性完善备份 / 还原 / 导入的完整性,覆盖 ScriptCat / Tampermonkey / Violentmonkey 三种格式,并把「设置」纳入备份范围。不涉及云同步。
Closes #1483
Closes #1484
Closes #1529
Closes #1533
Closes #684
Closes #841
Closes #1150
脚本层
selfMeta。options.override.use_*+run_at/noframes按 merge 语义推导selfMetadata(替换 / 合并)。violentmonkey清单里的custom→selfMetadata、values(按编码 uri 解码)、enabled/position,全部归一化为 SC 形状后走统一落库逻辑。OverrideInput→overrideToSelfMetadata→ 同一种selfMetadata。设置层(#1533 / #684)
SystemConfig+ Agent 模型 / MCP / 定时任务,随主备份 zip 往返(scriptcat-config.json)。cloud_sync/backup/cat_file_storage)在序列化时排除,不随明文 zip 外泄。资源与覆盖
importResource由resourceDAO.update改为save(update在 key 不存在时返回 false 且不持久化 → 从备份导入的新资源从未落库),并支持二进制资源(base64)导入;导入逐项暴露资源失败(不再误标为「跳过」)。测试与验证
pnpm typecheck+ 改动文件lint全绿。dist/ext,一次性 scratch 脚本,不进 CI):5 个端到端场景全绿 —— SC 往返、VM 导入、TM 导入、设置往返、覆盖模式。Screenshots / 截图
本地 e2e 录屏(真实扩展驱动,git-ignored 本地证据)已覆盖全部 5 条操作流程:SC 备份往返、VM 导入归一化、TM
override→selfMetadata推导、设置随主备份往返、覆盖导入。合入前可补贴录屏 / 截图。backup-restore.zip