Skip to content

feat: 配置备份恢复 - #83

Open
clansty wants to merge 2 commits into
mainfrom
feat/backupRecovery
Open

clansty wants to merge 2 commits into
mainfrom
feat/backupRecovery

Conversation

@clansty

@clansty clansty commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

View guided diff

Sourcery 摘要

为模组配置编辑器添加 AquaMai 配置历史比较和恢复控件。

新功能:

  • 为 AquaMai 配置添加备份与恢复视图,显示历史备份和差异,并提供恢复单个设置、整个分区或所有差异以及撤销更改的选项。
  • 添加 API 端点,用于列出配置备份文件,并提供解析后的覆盖数据和解析错误。

改进:

  • 在备份比较中使用本地化标签格式化配置值,包括布尔值、按键代码、I/O 映射和音频通道。
  • 确保配置加载与备份列表中的签名验证行为一致;对于未安装的 AquaMai DLL 路径,自动跳过签名验证。

杂项:

  • 添加英文、简体中文和繁体中文的备份与恢复翻译。
Original summary in English

Summary by Sourcery

Add historical AquaMai configuration comparison and restore controls to the mod configuration editor.

New Features:

  • Add a backup-and-restore view for AquaMai configuration, showing historical backups and differences with options to restore individual settings, sections, or all differences and undo changes.
  • Add an API endpoint that lists configuration backup files with parsed override data and parse errors.

Enhancements:

  • Format configuration values in backup comparisons using localized labels for booleans, key codes, I/O mappings, and sound channels.
  • Keep signature verification behavior consistent between configuration loading and backup listing, with automatic bypass for non-installed AquaMai DLL paths.

Chores:

  • Add backup-and-restore translations in English, Simplified Chinese, and Traditional Chinese.

- 将备份恢复入口移至顶栏最右并改为链接按钮,进入后显示返回

- 将弹窗改为下方区域的左右滑动切换内联视图(新增 ConfigEditor.module.sass,将 BackupRestoreModal 重构为 BackupRestoreView)

- 统一差异列表与表头的 rem 网格列宽与内边距,修复「备份」表头与数据列未对齐问题

- 对调备份(红)与当前(绿)配色,移除栏目边框并改用 listItem 背景

- 将栏目启用状态变化直接展示在 section 标题行右侧,并清理各语言包中不再使用的 mod.backup.sectionEnabled
@sourcery-ai

sourcery-ai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

审阅者指南

数据结构

定义供端点和编辑器使用的备份响应结构。

  • MaiChartManager/Controllers/Mod/ModConfigService.cs L10-17

API

通过配置控制器及其生成的客户端 API 提供备份列表。

  • MaiChartManager/Controllers/Mod/ConfigurationController.cs L32-41
  • MaiChartManager/Front/src/client/apiGen.ts L110-118, L1387-1408, L1916-1930(另有 2 处小改动)

API 的使用方式

让备份请求能够使用签名检查设置,并使配置编辑器辅助函数可供备份视图使用。

  • AquaMai.Config.Editor/src/index.ts L4-7
  • MaiChartManager/Front/src/views/ModManager/editorAdapter.ts L24
  • MaiChartManager/Front/src/views/ModManager/refs.ts L12, L67

实现

根据当前配置接口加载并解析备份文件,推导各分区和条目的覆盖值,并报告每个文件的解析错误。

  • MaiChartManager/Controllers/Mod/ModConfigService.cs L112-117, L127-133, L166-263(另有 1 处小改动)

提供可复用的声音通道选项,以及用于格式化备份差异中所显示配置值的易读格式。

  • AquaMai.Config.Editor/src/components/ConfigEntry.tsx L47-97(另有 3 处小改动)

规范化备份 DTO,并计算备份与当前配置之间的分区开关及条目值差异。

  • MaiChartManager/Front/src/views/ModManager/backupDiff.ts L1-160

界面

添加内嵌式备份浏览器和差异视图,包含恢复、撤销和值格式化交互。

  • MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx L1-616

添加顶部栏入口,并在配置编辑器与备份恢复视图之间加入动画过渡效果。

  • MaiChartManager/Front/src/views/ModManager/ConfigEditor.module.sass L1-34
  • MaiChartManager/Front/src/views/ModManager/ConfigEditor.tsx L100-105, L181-193, L205-219(另有 3 处小改动)

添加用于浏览备份和执行恢复操作的本地化标签及状态消息。

  • MaiChartManager/Front/src/locales/en.yaml L440-456
  • MaiChartManager/Front/src/locales/zh-TW.yaml L405-421
  • MaiChartManager/Front/src/locales/zh.yaml L399-415

提示和命令

与 Sourcery 交互

  • 触发新的审阅: 在拉取请求中评论 @sourcery-ai review。
  • 继续讨论: 直接回复 Sourcery 的审阅评论。
  • 根据审阅评论创建 GitHub issue: 回复审阅评论,请 Sourcery 根据该评论创建 issue。你也可以回复审阅评论并发送 @sourcery-ai issue,以此创建 issue。
  • 生成拉取请求标题: 在拉取请求标题中的任意位置输入 @sourcery-ai,即可随时生成标题。你也可以在拉取请求中评论 @sourcery-ai title,以便随时重新生成标题。
  • 生成拉取请求摘要: 在拉取请求正文中你希望插入摘要的位置输入 @sourcery-ai summary,即可随时生成 PR 摘要。你也可以在拉取请求中评论 @sourcery-ai summary,以便随时重新生成摘要。
  • 生成审阅者指南: 在拉取请求中评论 @sourcery-ai guide,即可随时重新生成审阅者指南。
  • 解决所有 Sourcery 评论: 在拉取请求中评论 @sourcery-ai resolve,即可解决所有 Sourcery 评论。如果你已处理完所有评论且不想再看到它们,这个功能会很有用。
  • 忽略所有 Sourcery 审阅: 在拉取请求中评论 @sourcery-ai dismiss,即可忽略所有现有的 Sourcery 审阅。如果你想从头开始进行新的审阅,这尤其有用——别忘了评论 @sourcery-ai review 来触发新的审阅!

自定义使用体验

访问你的控制面板,以便:

  • 启用或禁用审阅功能,例如 Sourcery 生成的拉取请求摘要、审阅者指南等。
  • 更改审阅语言。
  • 添加、移除或编辑自定义审阅说明。
  • 调整其他审阅设置。

获取帮助

Original review guide in English

Reviewer's Guide

Data structures

Define the backup response shape consumed by the endpoint and the editor.

  • MaiChartManager/Controllers/Mod/ModConfigService.cs L10-17

API

Expose backup listing through the configuration controller and its generated client API.

  • MaiChartManager/Controllers/Mod/ConfigurationController.cs L32-41
  • MaiChartManager/Front/src/client/apiGen.ts L110-118, L1387-1408, L1916-1930 (+2 small edits)

Uses of the API

Expose the signature-check setting to backup requests and make the config editor helpers available to the backup view.

  • AquaMai.Config.Editor/src/index.ts L4-7
  • MaiChartManager/Front/src/views/ModManager/editorAdapter.ts L24
  • MaiChartManager/Front/src/views/ModManager/refs.ts L12, L67

Implementation

Load and parse backup files against the current config interface, deriving section and entry overrides while reporting per-file parse errors.

  • MaiChartManager/Controllers/Mod/ModConfigService.cs L112-117, L127-133, L166-263 (+1 small edits)

Provide reusable sound-channel options and human-readable formatting for config values displayed in backup diffs.

  • AquaMai.Config.Editor/src/components/ConfigEntry.tsx L47-97 (+3 small edits)

Normalize backup DTOs and compute section-switch and entry-value differences against the live config.

  • MaiChartManager/Front/src/views/ModManager/backupDiff.ts L1-160

UI

Add the inline backup browser and diff view, including restore, undo, and value formatting interactions.

  • MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx L1-616

Add a top-bar entry and animated inline transition between the config editor and backup-restore view.

  • MaiChartManager/Front/src/views/ModManager/ConfigEditor.module.sass L1-34
  • MaiChartManager/Front/src/views/ModManager/ConfigEditor.tsx L100-105, L181-193, L205-219 (+3 small edits)

Add localized labels and status messages for backup browsing and restore actions.

  • MaiChartManager/Front/src/locales/en.yaml L440-456
  • MaiChartManager/Front/src/locales/zh-TW.yaml L405-421
  • MaiChartManager/Front/src/locales/zh.yaml L399-415

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嘿——我发现了 9 个问题

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="MaiChartManager/Controllers/Mod/ConfigurationController.cs" line_range="39" />
<code_context>
+    [HttpGet]
+    public async Task<IReadOnlyList<AquaMaiConfigBackupDto>> GetAquaMaiConfigBackups(bool skipSignatureCheck = false, CancellationToken ct = default)
+    {
+        return await modConfigService.GetAquaMaiConfigBackups(skipSignatureCheck, ct);
+    }
+
</code_context>
<issue_to_address>
**Historical settings exposed over LAN**

When the application is running in export mode with authentication disabled and backup files contain historical overrides, an unauthenticated LAN client can call this endpoint when export mode is enabled and `UseAuth` is false; the service returns parsed override values from every backup, exposing historical configuration that is no longer present in the current config.

Require authentication for this endpoint or otherwise prevent unauthenticated LAN clients from retrieving backup contents.
</issue_to_address>

### Comment 2
<location path="MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx" line_range="279" />
<code_context>
+        },
+      };
+      entryState.value = backupValue;
+      entryState.isDefault = backupValue === entryState.defaultValue;
+    };
+
</code_context>
<issue_to_address>
**Older save overwrites restored settings**

When a prior save is still running when a restore triggers another save, a debounced save for the previous editor state is still in flight when this assignment triggers a save of the restored state; the requests can complete out of order, and the older `SetAquaMaiConfig` request writes last, so the restored settings disappear.

Serialize config-save requests or reject stale saves using a monotonically increasing revision.
</issue_to_address>

### Comment 3
<location path="MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx" line_range="329-330" />
<code_context>
+      }
+      if (record.autoEnabledSection) {
+        const stillNeedsSection = Object.values(nextRecords).some(
+          (other) => other.kind === 'entry' && other.sectionPath === record.sectionPath && other.autoEnabledSection,
+        );
+        if (!stillNeedsSection) {
+          const sectionState = props.config.sectionStates[record.sectionPath];
</code_context>
<issue_to_address>
**Remaining restored entries are skipped**

When multiple entries in a disabled section are restored individually, then the entry that first enabled the section is undone, `undoRecord` counts only other entries with `autoEnabledSection`, so it disables the section even though other restored entries remain. `SetAquaMaiConfig` then skips those entries, and their restorations are not saved.

When undoing an auto-enabled entry, keep the section enabled while any restored entry in that section remains.
</issue_to_address>

### Comment 4
<location path="MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx" line_range="316" />
<code_context>
+      if (record.kind === 'section') {
+        const sectionState = props.config.sectionStates[record.sectionPath];
+        if (sectionState) {
+          sectionState.enabled = record.prevEnabled;
+          sectionState.isDefault = record.prevIsDefault;
+        }
</code_context>
<issue_to_address>
**Section undo leaves values unsaved**

When a section restore enables a disabled section, then the user undoes only the section switch while restored entries remain, `undoRecord` restores the section's previous disabled state but leaves the entry restores in place. `SetAquaMaiConfig` skips entries in disabled sections, so the UI shows values that are not written to the config.

When undoing a section switch, also undo dependent entry restores or keep the section enabled while they remain.

Also at `MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx:328-330`.
</issue_to_address>

### Comment 5
<location path="MaiChartManager/Front/src/views/ModManager/backupDiff.ts" line_range="93" />
<code_context>
+  currentState: EntryState,
+): ConfigValue => {
+  if (Object.prototype.hasOwnProperty.call(backup.entryOverrides, entryPath)) {
+    return backup.entryOverrides[entryPath] ?? currentState.defaultValue;
+  }
+  return currentState.defaultValue;
</code_context>
<issue_to_address>
**Explicit null restores as default**

When a backup contains a null override for an entry whose default is non-null, `getBackupEntryValue` uses `??` to replace the present null override with `currentState.defaultValue`, so the diff and restore use the default instead of the backed-up value.

Return the override whenever the entry path is present, including when its value is null.

Also at `MaiChartManager/Front/src/views/ModManager/backupDiff.ts:94`.
</issue_to_address>

### Comment 6
<location path="MaiChartManager/Front/src/views/ModManager/backupDiff.ts" line_range="45" />
<code_context>
+export const toNormalizedBackup = (dto: AquaMaiConfigBackupDto): NormalizedBackup => {
+  const entryOverrides: Record<string, ConfigValue> = {};
+  for (const [path, value] of Object.entries(dto.entryOverrides ?? {})) {
+    entryOverrides[path] = toConfigValue(value);
+  }
+  return {
</code_context>
<issue_to_address>
**Structured backup values become invalid**

When a backed-up configuration entry serializes to a JSON object rather than a scalar, `toConfigValue` converts object-valued JSON overrides to JavaScript’s default string, such as `[object Object]`. Restoring such an entry sends that string instead of the original value, so deserialization or saving fails for structured configuration values.

Preserve and support structured JSON values through backup comparison and restoration, or explicitly exclude unsupported value shapes from restore.
</issue_to_address>

### Comment 7
<location path="MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx" line_range="121" />
<code_context>
+      loading.value = true;
+      backups.value = [];
+      selectedFileName.value = null;
+      restoredRecords.value = {};
+      try {
+        const res = await api.GetAquaMaiConfigBackups({
</code_context>
<issue_to_address>
**Switching backups loses undo**

When the user restores one or more values and then selects a different backup, `watch(selectedFileName)` clears `restoredRecords` but leaves the restored values in the shared config; the config watcher still schedules those values for saving, while the view no longer has records to undo them, so switching backups permanently removes the restore actions for pending changes.

Preserve undo records across backup selection changes, or undo the staged changes before clearing their records.
</issue_to_address>

### Comment 8
<location path="MaiChartManager/Controllers/Mod/ModConfigService.cs" line_range="215" />
<code_context>
+
+            try
+            {
+                var toml = await File.ReadAllTextAsync(filePath, ct);
+                var config = configInterface.CreateConfig();
+                var view = configInterface.CreateConfigView(toml);
</code_context>
<issue_to_address>
**Valid backups appear malformed**

When the backup list reads a file while a config save is writing it, `GetAquaMaiConfigBackups` can read a partial TOML file and return a `ParseError` for a valid backup, so the UI shows it as failed until the list is reloaded.

Write backups atomically so the listing request reads only complete files.
</issue_to_address>

### Comment 9
<location path="MaiChartManager/Controllers/Mod/ModConfigService.cs" line_range="174" />
<code_context>
+            return [];
+        }
+
+        var files = Directory.GetFiles(ModPaths.AquaMaiConfigBackupDirPath, "*.toml");
+        if (files.Length == 0)
+        {
</code_context>
<issue_to_address>
**Large backup histories stall recovery**

When the backup directory contains many or large files, or the endpoint is called repeatedly, `GetAquaMaiConfigBackups` reads and parses every backup and returns all results on each request, making work and memory use grow with the uncapped history until the request slows or the service becomes unresponsive.

Limit backup history or paginate the listing so each request reads and returns a bounded set.

Also at `MaiChartManager/Controllers/Mod/ModConfigService.cs:206`.
</issue_to_address>

Sourcery 评估

需要人工审查。 需要先处理 9 项发现;恢复备份会将其中的分区和条目值复制到当前配置中,之后可以将其保存到配置文件。如果这些值有误,即使回退此代码,它们仍会保留,但可以通过编辑配置或恢复其他备份来修复。

阻塞性问题:MaiChartManager/Controllers/Mod/ConfigurationController.cs:39、MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx:279、MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx:330、MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx:316、MaiChartManager/Front/src/views/ModManager/backupDiff.ts:93,以及另外 4 项


Sourcery 对开源项目免费——如果您喜欢我们的审查结果,请考虑分享 ✨
Original comment in English

Hey - I've found 9 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="MaiChartManager/Controllers/Mod/ConfigurationController.cs" line_range="39" />
<code_context>
+    [HttpGet]
+    public async Task<IReadOnlyList<AquaMaiConfigBackupDto>> GetAquaMaiConfigBackups(bool skipSignatureCheck = false, CancellationToken ct = default)
+    {
+        return await modConfigService.GetAquaMaiConfigBackups(skipSignatureCheck, ct);
+    }
+
</code_context>
<issue_to_address>
**Historical settings exposed over LAN**

When the application is running in export mode with authentication disabled and backup files contain historical overrides, an unauthenticated LAN client can call this endpoint when export mode is enabled and `UseAuth` is false; the service returns parsed override values from every backup, exposing historical configuration that is no longer present in the current config.

Require authentication for this endpoint or otherwise prevent unauthenticated LAN clients from retrieving backup contents.
</issue_to_address>

### Comment 2
<location path="MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx" line_range="279" />
<code_context>
+        },
+      };
+      entryState.value = backupValue;
+      entryState.isDefault = backupValue === entryState.defaultValue;
+    };
+
</code_context>
<issue_to_address>
**Older save overwrites restored settings**

When a prior save is still running when a restore triggers another save, a debounced save for the previous editor state is still in flight when this assignment triggers a save of the restored state; the requests can complete out of order, and the older `SetAquaMaiConfig` request writes last, so the restored settings disappear.

Serialize config-save requests or reject stale saves using a monotonically increasing revision.
</issue_to_address>

### Comment 3
<location path="MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx" line_range="329-330" />
<code_context>
+      }
+      if (record.autoEnabledSection) {
+        const stillNeedsSection = Object.values(nextRecords).some(
+          (other) => other.kind === 'entry' && other.sectionPath === record.sectionPath && other.autoEnabledSection,
+        );
+        if (!stillNeedsSection) {
+          const sectionState = props.config.sectionStates[record.sectionPath];
</code_context>
<issue_to_address>
**Remaining restored entries are skipped**

When multiple entries in a disabled section are restored individually, then the entry that first enabled the section is undone, `undoRecord` counts only other entries with `autoEnabledSection`, so it disables the section even though other restored entries remain. `SetAquaMaiConfig` then skips those entries, and their restorations are not saved.

When undoing an auto-enabled entry, keep the section enabled while any restored entry in that section remains.
</issue_to_address>

### Comment 4
<location path="MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx" line_range="316" />
<code_context>
+      if (record.kind === 'section') {
+        const sectionState = props.config.sectionStates[record.sectionPath];
+        if (sectionState) {
+          sectionState.enabled = record.prevEnabled;
+          sectionState.isDefault = record.prevIsDefault;
+        }
</code_context>
<issue_to_address>
**Section undo leaves values unsaved**

When a section restore enables a disabled section, then the user undoes only the section switch while restored entries remain, `undoRecord` restores the section's previous disabled state but leaves the entry restores in place. `SetAquaMaiConfig` skips entries in disabled sections, so the UI shows values that are not written to the config.

When undoing a section switch, also undo dependent entry restores or keep the section enabled while they remain.

Also at `MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx:328-330`.
</issue_to_address>

### Comment 5
<location path="MaiChartManager/Front/src/views/ModManager/backupDiff.ts" line_range="93" />
<code_context>
+  currentState: EntryState,
+): ConfigValue => {
+  if (Object.prototype.hasOwnProperty.call(backup.entryOverrides, entryPath)) {
+    return backup.entryOverrides[entryPath] ?? currentState.defaultValue;
+  }
+  return currentState.defaultValue;
</code_context>
<issue_to_address>
**Explicit null restores as default**

When a backup contains a null override for an entry whose default is non-null, `getBackupEntryValue` uses `??` to replace the present null override with `currentState.defaultValue`, so the diff and restore use the default instead of the backed-up value.

Return the override whenever the entry path is present, including when its value is null.

Also at `MaiChartManager/Front/src/views/ModManager/backupDiff.ts:94`.
</issue_to_address>

### Comment 6
<location path="MaiChartManager/Front/src/views/ModManager/backupDiff.ts" line_range="45" />
<code_context>
+export const toNormalizedBackup = (dto: AquaMaiConfigBackupDto): NormalizedBackup => {
+  const entryOverrides: Record<string, ConfigValue> = {};
+  for (const [path, value] of Object.entries(dto.entryOverrides ?? {})) {
+    entryOverrides[path] = toConfigValue(value);
+  }
+  return {
</code_context>
<issue_to_address>
**Structured backup values become invalid**

When a backed-up configuration entry serializes to a JSON object rather than a scalar, `toConfigValue` converts object-valued JSON overrides to JavaScript’s default string, such as `[object Object]`. Restoring such an entry sends that string instead of the original value, so deserialization or saving fails for structured configuration values.

Preserve and support structured JSON values through backup comparison and restoration, or explicitly exclude unsupported value shapes from restore.
</issue_to_address>

### Comment 7
<location path="MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx" line_range="121" />
<code_context>
+      loading.value = true;
+      backups.value = [];
+      selectedFileName.value = null;
+      restoredRecords.value = {};
+      try {
+        const res = await api.GetAquaMaiConfigBackups({
</code_context>
<issue_to_address>
**Switching backups loses undo**

When the user restores one or more values and then selects a different backup, `watch(selectedFileName)` clears `restoredRecords` but leaves the restored values in the shared config; the config watcher still schedules those values for saving, while the view no longer has records to undo them, so switching backups permanently removes the restore actions for pending changes.

Preserve undo records across backup selection changes, or undo the staged changes before clearing their records.
</issue_to_address>

### Comment 8
<location path="MaiChartManager/Controllers/Mod/ModConfigService.cs" line_range="215" />
<code_context>
+
+            try
+            {
+                var toml = await File.ReadAllTextAsync(filePath, ct);
+                var config = configInterface.CreateConfig();
+                var view = configInterface.CreateConfigView(toml);
</code_context>
<issue_to_address>
**Valid backups appear malformed**

When the backup list reads a file while a config save is writing it, `GetAquaMaiConfigBackups` can read a partial TOML file and return a `ParseError` for a valid backup, so the UI shows it as failed until the list is reloaded.

Write backups atomically so the listing request reads only complete files.
</issue_to_address>

### Comment 9
<location path="MaiChartManager/Controllers/Mod/ModConfigService.cs" line_range="174" />
<code_context>
+            return [];
+        }
+
+        var files = Directory.GetFiles(ModPaths.AquaMaiConfigBackupDirPath, "*.toml");
+        if (files.Length == 0)
+        {
</code_context>
<issue_to_address>
**Large backup histories stall recovery**

When the backup directory contains many or large files, or the endpoint is called repeatedly, `GetAquaMaiConfigBackups` reads and parses every backup and returns all results on each request, making work and memory use grow with the uncapped history until the request slows or the service becomes unresponsive.

Limit backup history or paginate the listing so each request reads and returns a bounded set.

Also at `MaiChartManager/Controllers/Mod/ModConfigService.cs:206`.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 9 findings to address first, and restoring a backup copies its section and entry values into the live configuration, which can then be saved to the config file. If those values are wrong, they remain after reverting this code, but the configuration can be repaired by editing it or restoring another backup.

Blocking findings: MaiChartManager/Controllers/Mod/ConfigurationController.cs:39, MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx:279, MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx:330, MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx:316, MaiChartManager/Front/src/views/ModManager/backupDiff.ts:93, and 4 more


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

[HttpGet]
public async Task<IReadOnlyList<AquaMaiConfigBackupDto>> GetAquaMaiConfigBackups(bool skipSignatureCheck = false, CancellationToken ct = default)
{
return await modConfigService.GetAquaMaiConfigBackups(skipSignatureCheck, ct);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · 通过局域网暴露历史设置

当应用在禁用身份验证的导出模式下运行,且备份文件包含历史覆盖值时,未经过身份验证的局域网客户端可以在启用导出模式且 UseAuth 为 false 时调用此端点;该服务会返回所有备份中解析出的覆盖值,从而暴露当前配置中已不存在的历史配置。

请对此端点要求身份验证,或以其他方式阻止未经过身份验证的局域网客户端获取备份内容。

面向 AI 智能体的提示
在 `MaiChartManager/Controllers/Mod/ConfigurationController.cs` 第 39 行:

**通过局域网暴露历史设置**

当应用在禁用身份验证的导出模式下运行,且备份文件包含历史覆盖值时,未经过身份验证的局域网客户端可以在启用导出模式且 `UseAuth` 为 false 时调用此端点;该服务会返回所有备份中解析出的覆盖值,从而暴露当前配置中已不存在的历史配置。

请对此端点要求身份验证,或以其他方式阻止未经过身份验证的局域网客户端获取备份内容。
Original comment in English

🟡 Medium · Historical settings exposed over LAN

When the application is running in export mode with authentication disabled and backup files contain historical overrides, an unauthenticated LAN client can call this endpoint when export mode is enabled and UseAuth is false; the service returns parsed override values from every backup, exposing historical configuration that is no longer present in the current config.

Require authentication for this endpoint or otherwise prevent unauthenticated LAN clients from retrieving backup contents.

Prompt for AI agents
In `MaiChartManager/Controllers/Mod/ConfigurationController.cs` at line 39:

**Historical settings exposed over LAN**

When the application is running in export mode with authentication disabled and backup files contain historical overrides, an unauthenticated LAN client can call this endpoint when export mode is enabled and `UseAuth` is false; the service returns parsed override values from every backup, exposing historical configuration that is no longer present in the current config.

Require authentication for this endpoint or otherwise prevent unauthenticated LAN clients from retrieving backup contents.

},
};
entryState.value = backupValue;
entryState.isDefault = backupValue === entryState.defaultValue;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · 较早的保存操作会覆盖已恢复的设置

当先前的保存操作仍在进行时,恢复操作又触发了另一次保存,此时针对先前编辑器状态的防抖保存仍在执行,而这次赋值会触发对恢复后状态的保存;这些请求可能乱序完成,较早的 SetAquaMaiConfig 请求最后写入,导致恢复的设置消失。

请串行处理配置保存请求,或使用单调递增的版本号拒绝过期的保存操作。

面向 AI 智能体的提示
在 `MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx` 第 279 行:

**较早的保存操作会覆盖已恢复的设置**

当先前的保存操作仍在进行时,恢复操作又触发了另一次保存,此时针对先前编辑器状态的防抖保存仍在执行,而这次赋值会触发对恢复后状态的保存;这些请求可能乱序完成,较早的 `SetAquaMaiConfig` 请求最后写入,导致恢复的设置消失。

请串行处理配置保存请求,或使用单调递增的版本号拒绝过期的保存操作。
Original comment in English

🟡 Medium · Older save overwrites restored settings

When a prior save is still running when a restore triggers another save, a debounced save for the previous editor state is still in flight when this assignment triggers a save of the restored state; the requests can complete out of order, and the older SetAquaMaiConfig request writes last, so the restored settings disappear.

Serialize config-save requests or reject stale saves using a monotonically increasing revision.

Prompt for AI agents
In `MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx` at line 279:

**Older save overwrites restored settings**

When a prior save is still running when a restore triggers another save, a debounced save for the previous editor state is still in flight when this assignment triggers a save of the restored state; the requests can complete out of order, and the older `SetAquaMaiConfig` request writes last, so the restored settings disappear.

Serialize config-save requests or reject stale saves using a monotonically increasing revision.

Comment on lines +329 to +330
(other) => other.kind === 'entry' && other.sectionPath === record.sectionPath && other.autoEnabledSection,
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High · 其余已恢复条目会被跳过

当逐个恢复已禁用分区中的多个条目,然后撤销最先启用该分区的条目时,undoRecord 只统计其他具有 autoEnabledSection 的条目,因此即使该分区中仍有其他已恢复条目,也会将分区禁用。随后 SetAquaMaiConfig 会跳过这些条目,导致它们的恢复结果无法保存。

撤销自动启用分区的条目时,只要该分区中仍有已恢复条目,就应保持分区启用。

面向 AI 智能体的提示
在 `MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx` 第 329-330 行:

**其余已恢复条目会被跳过**

当逐个恢复已禁用分区中的多个条目,然后撤销最先启用该分区的条目时,`undoRecord` 只统计其他具有 `autoEnabledSection` 的条目,因此即使该分区中仍有其他已恢复条目,也会将分区禁用。随后 `SetAquaMaiConfig` 会跳过这些条目,导致它们的恢复结果无法保存。

撤销自动启用分区的条目时,只要该分区中仍有已恢复条目,就应保持分区启用。
Original comment in English

🟠 High · Remaining restored entries are skipped

When multiple entries in a disabled section are restored individually, then the entry that first enabled the section is undone, undoRecord counts only other entries with autoEnabledSection, so it disables the section even though other restored entries remain. SetAquaMaiConfig then skips those entries, and their restorations are not saved.

When undoing an auto-enabled entry, keep the section enabled while any restored entry in that section remains.

Prompt for AI agents
In `MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx` at lines 329-330:

**Remaining restored entries are skipped**

When multiple entries in a disabled section are restored individually, then the entry that first enabled the section is undone, `undoRecord` counts only other entries with `autoEnabledSection`, so it disables the section even though other restored entries remain. `SetAquaMaiConfig` then skips those entries, and their restorations are not saved.

When undoing an auto-enabled entry, keep the section enabled while any restored entry in that section remains.

if (record.kind === 'section') {
const sectionState = props.config.sectionStates[record.sectionPath];
if (sectionState) {
sectionState.enabled = record.prevEnabled;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · 撤销分区操作会导致值未保存

当恢复某个分区并启用原本已禁用的分区后,如果用户只撤销分区开关,而已恢复的条目仍保留,undoRecord 会将分区恢复为之前的禁用状态,但不会撤销条目恢复操作。SetAquaMaiConfig 会跳过已禁用分区中的条目,因此界面显示的值不会写入配置。

撤销分区开关时,也应撤销依赖于该操作的条目恢复,或在这些条目仍保留时保持分区启用。

另见 MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx:328-330。

面向 AI 智能体的提示
在 `MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx` 第 316 行:

**撤销分区操作会导致值未保存**

当恢复某个分区并启用原本已禁用的分区后,如果用户只撤销分区开关,而已恢复的条目仍保留,`undoRecord` 会将分区恢复为之前的禁用状态,但不会撤销条目恢复操作。`SetAquaMaiConfig` 会跳过已禁用分区中的条目,因此界面显示的值不会写入配置。

撤销分区开关时,也应撤销依赖于该操作的条目恢复,或在这些条目仍保留时保持分区启用。

另见 `MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx:328-330`。
Original comment in English

🟡 Medium · Section undo leaves values unsaved

When a section restore enables a disabled section, then the user undoes only the section switch while restored entries remain, undoRecord restores the section's previous disabled state but leaves the entry restores in place. SetAquaMaiConfig skips entries in disabled sections, so the UI shows values that are not written to the config.

When undoing a section switch, also undo dependent entry restores or keep the section enabled while they remain.

Also at MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx:328-330.

Prompt for AI agents
In `MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx` at line 316:

**Section undo leaves values unsaved**

When a section restore enables a disabled section, then the user undoes only the section switch while restored entries remain, `undoRecord` restores the section's previous disabled state but leaves the entry restores in place. `SetAquaMaiConfig` skips entries in disabled sections, so the UI shows values that are not written to the config.

When undoing a section switch, also undo dependent entry restores or keep the section enabled while they remain.

Also at `MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx:328-330`.

currentState: EntryState,
): ConfigValue => {
if (Object.prototype.hasOwnProperty.call(backup.entryOverrides, entryPath)) {
return backup.entryOverrides[entryPath] ?? currentState.defaultValue;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · 显式 null 会被恢复为默认值

当备份中某个条目的覆盖值为 null,而该条目的默认值非 null 时,getBackupEntryValue 使用 ?? 将这个实际存在的 null 覆盖值替换为 currentState.defaultValue,因此差异比较和恢复操作使用的是默认值,而不是备份中的值。

只要条目路径存在,就应返回覆盖值,包括其值为 null 的情况。

另见 MaiChartManager/Front/src/views/ModManager/backupDiff.ts:94。

面向 AI 智能体的提示
在 `MaiChartManager/Front/src/views/ModManager/backupDiff.ts` 第 93 行:

**显式 null 会被恢复为默认值**

当备份中某个条目的覆盖值为 null,而该条目的默认值非 null 时,`getBackupEntryValue` 使用 `??` 将这个实际存在的 null 覆盖值替换为 `currentState.defaultValue`,因此差异比较和恢复操作使用的是默认值,而不是备份中的值。

只要条目路径存在,就应返回覆盖值,包括其值为 null 的情况。

另见 `MaiChartManager/Front/src/views/ModManager/backupDiff.ts:94`。
Original comment in English

🟡 Medium · Explicit null restores as default

When a backup contains a null override for an entry whose default is non-null, getBackupEntryValue uses ?? to replace the present null override with currentState.defaultValue, so the diff and restore use the default instead of the backed-up value.

Return the override whenever the entry path is present, including when its value is null.

Also at MaiChartManager/Front/src/views/ModManager/backupDiff.ts:94.

Prompt for AI agents
In `MaiChartManager/Front/src/views/ModManager/backupDiff.ts` at line 93:

**Explicit null restores as default**

When a backup contains a null override for an entry whose default is non-null, `getBackupEntryValue` uses `??` to replace the present null override with `currentState.defaultValue`, so the diff and restore use the default instead of the backed-up value.

Return the override whenever the entry path is present, including when its value is null.

Also at `MaiChartManager/Front/src/views/ModManager/backupDiff.ts:94`.

export const toNormalizedBackup = (dto: AquaMaiConfigBackupDto): NormalizedBackup => {
const entryOverrides: Record<string, ConfigValue> = {};
for (const [path, value] of Object.entries(dto.entryOverrides ?? {})) {
entryOverrides[path] = toConfigValue(value);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High · 结构化备份值会变得无效

当备份的配置条目序列化为 JSON 对象而非标量时,toConfigValue 会将对象类型的 JSON 覆盖值转换为 JavaScript 的默认字符串,例如 [object Object]。恢复此类条目时会发送该字符串,而不是原始值,因此结构化配置值会在反序列化或保存时失败。

请在备份比较和恢复过程中保留并支持结构化 JSON 值,或明确排除不受支持的值形态,避免恢复这些值。

面向 AI 智能体的提示
在 `MaiChartManager/Front/src/views/ModManager/backupDiff.ts` 第 45 行:

**结构化备份值会变得无效**

当备份的配置条目序列化为 JSON 对象而非标量时,`toConfigValue` 会将对象类型的 JSON 覆盖值转换为 JavaScript 的默认字符串,例如 `[object Object]`。恢复此类条目时会发送该字符串,而不是原始值,因此结构化配置值会在反序列化或保存时失败。

请在备份比较和恢复过程中保留并支持结构化 JSON 值,或明确排除不受支持的值形态,避免恢复这些值。
Original comment in English

🟠 High · Structured backup values become invalid

When a backed-up configuration entry serializes to a JSON object rather than a scalar, toConfigValue converts object-valued JSON overrides to JavaScript’s default string, such as [object Object]. Restoring such an entry sends that string instead of the original value, so deserialization or saving fails for structured configuration values.

Preserve and support structured JSON values through backup comparison and restoration, or explicitly exclude unsupported value shapes from restore.

Prompt for AI agents
In `MaiChartManager/Front/src/views/ModManager/backupDiff.ts` at line 45:

**Structured backup values become invalid**

When a backed-up configuration entry serializes to a JSON object rather than a scalar, `toConfigValue` converts object-valued JSON overrides to JavaScript’s default string, such as `[object Object]`. Restoring such an entry sends that string instead of the original value, so deserialization or saving fails for structured configuration values.

Preserve and support structured JSON values through backup comparison and restoration, or explicitly exclude unsupported value shapes from restore.

});

watch(selectedFileName, () => {
restoredRecords.value = {};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · 切换备份会丢失撤销记录

当用户恢复一个或多个值后又选择其他备份时,watch(selectedFileName) 会清空 restoredRecords,但共享配置中的已恢复值仍然保留;配置监听器仍会安排保存这些值,而界面已没有可用于撤销它们的记录,因此切换备份会永久丢失对待处理更改的撤销操作。

请在切换备份时保留撤销记录,或在清除记录之前撤销暂存的更改。

面向 AI 智能体的提示
在 `MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx` 第 121 行:

**切换备份会丢失撤销记录**

当用户恢复一个或多个值后又选择其他备份时,`watch(selectedFileName)` 会清空 `restoredRecords`,但共享配置中的已恢复值仍然保留;配置监听器仍会安排保存这些值,而界面已没有可用于撤销它们的记录,因此切换备份会永久丢失对待处理更改的撤销操作。

请在切换备份时保留撤销记录,或在清除记录之前撤销暂存的更改。
Original comment in English

🟡 Medium · Switching backups loses undo

When the user restores one or more values and then selects a different backup, watch(selectedFileName) clears restoredRecords but leaves the restored values in the shared config; the config watcher still schedules those values for saving, while the view no longer has records to undo them, so switching backups permanently removes the restore actions for pending changes.

Preserve undo records across backup selection changes, or undo the staged changes before clearing their records.

Prompt for AI agents
In `MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx` at line 121:

**Switching backups loses undo**

When the user restores one or more values and then selects a different backup, `watch(selectedFileName)` clears `restoredRecords` but leaves the restored values in the shared config; the config watcher still schedules those values for saving, while the view no longer has records to undo them, so switching backups permanently removes the restore actions for pending changes.

Preserve undo records across backup selection changes, or undo the staged changes before clearing their records.


try
{
var toml = await File.ReadAllTextAsync(filePath, ct);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · 有效备份会被误判为格式错误

当备份列表在配置保存正在写入文件时读取该文件,GetAquaMaiConfigBackups 可能会读到不完整的 TOML 文件,并对有效备份返回 ParseError,导致界面将其显示为失败状态,直到重新加载列表。

请以原子方式写入备份,确保列表请求只读取完整文件。

面向 AI 智能体的提示
在 `MaiChartManager/Controllers/Mod/ModConfigService.cs` 第 215 行:

**有效备份会被误判为格式错误**

当备份列表在配置保存正在写入文件时读取该文件,`GetAquaMaiConfigBackups` 可能会读到不完整的 TOML 文件,并对有效备份返回 `ParseError`,导致界面将其显示为失败状态,直到重新加载列表。

请以原子方式写入备份,确保列表请求只读取完整文件。
Original comment in English

🟡 Medium · Valid backups appear malformed

When the backup list reads a file while a config save is writing it, GetAquaMaiConfigBackups can read a partial TOML file and return a ParseError for a valid backup, so the UI shows it as failed until the list is reloaded.

Write backups atomically so the listing request reads only complete files.

Prompt for AI agents
In `MaiChartManager/Controllers/Mod/ModConfigService.cs` at line 215:

**Valid backups appear malformed**

When the backup list reads a file while a config save is writing it, `GetAquaMaiConfigBackups` can read a partial TOML file and return a `ParseError` for a valid backup, so the UI shows it as failed until the list is reloaded.

Write backups atomically so the listing request reads only complete files.

return [];
}

var files = Directory.GetFiles(ModPaths.AquaMaiConfigBackupDirPath, "*.toml");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · 大量备份历史会拖慢恢复

当备份目录中存在许多或很大的文件,或者端点被反复调用时,GetAquaMaiConfigBackups 会在每次请求时读取并解析所有备份,然后返回全部结果;由于历史记录没有上限,工作量和内存用量会不断增长,最终导致请求变慢或服务无响应。

请限制备份历史记录的数量,或对列表进行分页,使每个请求读取并返回有界数量的结果。

另见 MaiChartManager/Controllers/Mod/ModConfigService.cs:206。

面向 AI 智能体的提示
在 `MaiChartManager/Controllers/Mod/ModConfigService.cs` 第 174 行:

**大量备份历史会拖慢恢复**

当备份目录中存在许多或很大的文件,或者端点被反复调用时,`GetAquaMaiConfigBackups` 会在每次请求时读取并解析所有备份,然后返回全部结果;由于历史记录没有上限,工作量和内存用量会不断增长,最终导致请求变慢或服务无响应。

请限制备份历史记录的数量,或对列表进行分页,使每个请求读取并返回有界数量的结果。

另见 `MaiChartManager/Controllers/Mod/ModConfigService.cs:206`。
Original comment in English

🟡 Medium · Large backup histories stall recovery

When the backup directory contains many or large files, or the endpoint is called repeatedly, GetAquaMaiConfigBackups reads and parses every backup and returns all results on each request, making work and memory use grow with the uncapped history until the request slows or the service becomes unresponsive.

Limit backup history or paginate the listing so each request reads and returns a bounded set.

Also at MaiChartManager/Controllers/Mod/ModConfigService.cs:206.

Prompt for AI agents
In `MaiChartManager/Controllers/Mod/ModConfigService.cs` at line 174:

**Large backup histories stall recovery**

When the backup directory contains many or large files, or the endpoint is called repeatedly, `GetAquaMaiConfigBackups` reads and parses every backup and returns all results on each request, making work and memory use grow with the uncapped history until the request slows or the service becomes unresponsive.

Limit backup history or paginate the listing so each request reads and returns a bounded set.

Also at `MaiChartManager/Controllers/Mod/ModConfigService.cs:206`.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10 issues found across 14 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx">

<violation number="1" location="MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx:87">
P2: 切换备份时这里会清空撤销记录,却保留共享配置中的已恢复值,用户因此失去撤销这些待保存更改的入口;请在清除记录前回滚暂存更改,或保留对应记录。</violation>

<violation number="2" location="MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx:255">
P2: 同一栏目下先后恢复两个条目后,撤销先恢复的那个会把栏目重新禁用,而另一个条目仍显示为已恢复,保存时该修改会被跳过。自动启用栏目的归属需要转交给同栏目仍存活的恢复记录,可在 `restoreEntry` 中让后续记录继承该归属。</violation>

<violation number="3" location="MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx:278">
P2: 此赋值会触发恢复后的配置保存,但先前的 `SetAquaMaiConfig` 请求仍可能在途并最后写入;请串行化保存或拒绝过期请求,避免恢复结果被覆盖。</violation>
</file>

<file name="MaiChartManager/Front/src/locales/zh-TW.yaml">

<violation number="1" location="MaiChartManager/Front/src/locales/zh-TW.yaml:416">
P3: 此按钮会恢复整个配置分区及其多个配置项,但繁体中文写成了“欄位”(字段),会误导用户操作范围。请改为“還原此分區”或其他表示区段的用语。</violation>
</file>

<file name="MaiChartManager/Front/src/views/ModManager/backupDiff.ts">

<violation number="1" location="MaiChartManager/Front/src/views/ModManager/backupDiff.ts:45">
P1: 备份中的对象型覆盖值会经 `toConfigValue` 转成字符串,恢复时发送的将不是原始 JSON 值;请在备份规范化、比较和恢复过程中保留结构化值,或明确阻止恢复不支持的值。</violation>

<violation number="2" location="MaiChartManager/Front/src/views/ModManager/backupDiff.ts:93">
P2: `getBackupEntryValue` 会把合法的 null 备份值错误地回退为默认值,导致该配置项显示差异错误且无法恢复为 null。键已确认存在时应直接返回覆盖值。</violation>
</file>

<file name="MaiChartManager/Front/src/views/ModManager/ConfigEditor.tsx">

<violation number="1" location="MaiChartManager/Front/src/views/ModManager/ConfigEditor.tsx:182">
P3: 备份恢复入口使用仅绑定 `onClick` 的 `<span>`,键盘用户无法访问该功能。请改用原生 `<button>`,或补充按钮语义、焦点和 Enter/Space 键处理。</violation>
</file>

<file name="MaiChartManager/Controllers/Mod/ConfigurationController.cs">

<violation number="1" location="MaiChartManager/Controllers/Mod/ConfigurationController.cs:39">
P1: 该端点会直接返回所有备份中的历史覆盖值;请在 `UseAuth` 关闭时限制未认证访问,避免局域网客户端读取当前配置中已不存在的设置。</violation>
</file>

<file name="MaiChartManager/Controllers/Mod/ModConfigService.cs">

<violation number="1" location="MaiChartManager/Controllers/Mod/ModConfigService.cs:197">
P2: 此列表会逐个读取并解析目录中的所有备份,历史规模会直接放大每次请求的 I/O、内存和响应体;请限制每次处理的数量或实现分页。</violation>

<violation number="2" location="MaiChartManager/Controllers/Mod/ModConfigService.cs:215">
P2: 列表读取可能与配置保存对同一备份文件的写入重叠,从而读到不完整 TOML 并暂时返回 `ParseError`;请原子写入备份或同步读写。</violation>
</file>

Tip: Get a Slack DM when cubic finishes reviewing your PRs. Connect Slack

View guided diff | Re-trigger cubic

[HttpGet]
public async Task<IReadOnlyList<AquaMaiConfigBackupDto>> GetAquaMaiConfigBackups(bool skipSignatureCheck = false, CancellationToken ct = default)
{
return await modConfigService.GetAquaMaiConfigBackups(skipSignatureCheck, ct);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: 该端点会直接返回所有备份中的历史覆盖值;请在 UseAuth 关闭时限制未认证访问,避免局域网客户端读取当前配置中已不存在的设置。

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At MaiChartManager/Controllers/Mod/ConfigurationController.cs, line 39:

<comment>该端点会直接返回所有备份中的历史覆盖值;请在 `UseAuth` 关闭时限制未认证访问,避免局域网客户端读取当前配置中已不存在的设置。</comment>

<file context>
@@ -29,11 +29,16 @@ public ConfigurationController(StaticSettings settings, ILogger<ConfigurationCon
+    [HttpGet]
+    public async Task<IReadOnlyList<AquaMaiConfigBackupDto>> GetAquaMaiConfigBackups(bool skipSignatureCheck = false, CancellationToken ct = default)
+    {
+        return await modConfigService.GetAquaMaiConfigBackups(skipSignatureCheck, ct);
+    }
+
</file context>

export const toNormalizedBackup = (dto: AquaMaiConfigBackupDto): NormalizedBackup => {
const entryOverrides: Record<string, ConfigValue> = {};
for (const [path, value] of Object.entries(dto.entryOverrides ?? {})) {
entryOverrides[path] = toConfigValue(value);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: 备份中的对象型覆盖值会经 toConfigValue 转成字符串,恢复时发送的将不是原始 JSON 值;请在备份规范化、比较和恢复过程中保留结构化值,或明确阻止恢复不支持的值。

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At MaiChartManager/Front/src/views/ModManager/backupDiff.ts, line 45:

<comment>备份中的对象型覆盖值会经 `toConfigValue` 转成字符串,恢复时发送的将不是原始 JSON 值;请在备份规范化、比较和恢复过程中保留结构化值,或明确阻止恢复不支持的值。</comment>

<file context>
@@ -0,0 +1,160 @@
+export const toNormalizedBackup = (dto: AquaMaiConfigBackupDto): NormalizedBackup => {
+  const entryOverrides: Record<string, ConfigValue> = {};
+  for (const [path, value] of Object.entries(dto.entryOverrides ?? {})) {
+    entryOverrides[path] = toConfigValue(value);
+  }
+  return {
</file context>


const prevSectionEnabled = sectionState.enabled;
const prevSectionIsDefault = sectionState.isDefault;
let autoEnabledSection = false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: 同一栏目下先后恢复两个条目后,撤销先恢复的那个会把栏目重新禁用,而另一个条目仍显示为已恢复,保存时该修改会被跳过。自动启用栏目的归属需要转交给同栏目仍存活的恢复记录,可在 restoreEntry 中让后续记录继承该归属。

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx, line 255:

<comment>同一栏目下先后恢复两个条目后,撤销先恢复的那个会把栏目重新禁用,而另一个条目仍显示为已恢复,保存时该修改会被跳过。自动启用栏目的归属需要转交给同栏目仍存活的恢复记录,可在 `restoreEntry` 中让后续记录继承该归属。</comment>

<file context>
@@ -0,0 +1,616 @@
+
+      const prevSectionEnabled = sectionState.enabled;
+      const prevSectionIsDefault = sectionState.isDefault;
+      let autoEnabledSection = false;
+      // 禁用栏目下的条目在保存时会被后端跳过,因此恢复其中条目时需一并启用栏目
+      if (!section.attribute.alwaysEnabled && !sectionState.enabled && backupEnabled) {
</file context>

currentState: EntryState,
): ConfigValue => {
if (Object.prototype.hasOwnProperty.call(backup.entryOverrides, entryPath)) {
return backup.entryOverrides[entryPath] ?? currentState.defaultValue;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: getBackupEntryValue 会把合法的 null 备份值错误地回退为默认值,导致该配置项显示差异错误且无法恢复为 null。键已确认存在时应直接返回覆盖值。

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At MaiChartManager/Front/src/views/ModManager/backupDiff.ts, line 93:

<comment>`getBackupEntryValue` 会把合法的 null 备份值错误地回退为默认值,导致该配置项显示差异错误且无法恢复为 null。键已确认存在时应直接返回覆盖值。</comment>

<file context>
@@ -0,0 +1,160 @@
+  currentState: EntryState,
+): ConfigValue => {
+  if (Object.prototype.hasOwnProperty.call(backup.entryOverrides, entryPath)) {
+    return backup.entryOverrides[entryPath] ?? currentState.defaultValue;
+  }
+  return currentState.defaultValue;
</file context>

loading.value = true;
backups.value = [];
selectedFileName.value = null;
restoredRecords.value = {};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: 切换备份时这里会清空撤销记录,却保留共享配置中的已恢复值,用户因此失去撤销这些待保存更改的入口;请在清除记录前回滚暂存更改,或保留对应记录。

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx, line 87:

<comment>切换备份时这里会清空撤销记录,却保留共享配置中的已恢复值,用户因此失去撤销这些待保存更改的入口;请在清除记录前回滚暂存更改,或保留对应记录。</comment>

<file context>
@@ -0,0 +1,616 @@
+      loading.value = true;
+      backups.value = [];
+      selectedFileName.value = null;
+      restoredRecords.value = {};
+      try {
+        const res = await api.GetAquaMaiConfigBackups({
</file context>

prevSectionIsDefault,
},
};
entryState.value = backupValue;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: 此赋值会触发恢复后的配置保存,但先前的 SetAquaMaiConfig 请求仍可能在途并最后写入;请串行化保存或拒绝过期请求,避免恢复结果被覆盖。

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At MaiChartManager/Front/src/views/ModManager/BackupRestoreView.tsx, line 278:

<comment>此赋值会触发恢复后的配置保存,但先前的 `SetAquaMaiConfig` 请求仍可能在途并最后写入;请串行化保存或拒绝过期请求,避免恢复结果被覆盖。</comment>

<file context>
@@ -0,0 +1,616 @@
+          prevSectionIsDefault,
+        },
+      };
+      entryState.value = backupValue;
+      entryState.isDefault = backupValue === entryState.defaultValue;
+    };
</file context>

})
.OrderByDescending(x => x.timestamp)
.ThenByDescending(x => x.fileName, StringComparer.OrdinalIgnoreCase)
.ToArray();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: 此列表会逐个读取并解析目录中的所有备份,历史规模会直接放大每次请求的 I/O、内存和响应体;请限制每次处理的数量或实现分页。

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At MaiChartManager/Controllers/Mod/ModConfigService.cs, line 197:

<comment>此列表会逐个读取并解析目录中的所有备份,历史规模会直接放大每次请求的 I/O、内存和响应体;请限制每次处理的数量或实现分页。</comment>

<file context>
@@ -146,4 +163,102 @@ public async Task<IConfig> GetCurrentAquaMaiConfig(bool forceDefault = false, bo
+            })
+            .OrderByDescending(x => x.timestamp)
+            .ThenByDescending(x => x.fileName, StringComparer.OrdinalIgnoreCase)
+            .ToArray();
+
+        var configInterface = await LoadConfigInterface(skipSignatureCheck, ct);
</file context>
Suggested change
.ToArray();
.Take(100).ToArray();


try
{
var toml = await File.ReadAllTextAsync(filePath, ct);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: 列表读取可能与配置保存对同一备份文件的写入重叠,从而读到不完整 TOML 并暂时返回 ParseError;请原子写入备份或同步读写。

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At MaiChartManager/Controllers/Mod/ModConfigService.cs, line 215:

<comment>列表读取可能与配置保存对同一备份文件的写入重叠,从而读到不完整 TOML 并暂时返回 `ParseError`;请原子写入备份或同步读写。</comment>

<file context>
@@ -146,4 +163,102 @@ public async Task<IConfig> GetCurrentAquaMaiConfig(bool forceDefault = false, bo
+
+            try
+            {
+                var toml = await File.ReadAllTextAsync(filePath, ct);
+                var config = configInterface.CreateConfig();
+                var view = configInterface.CreateConfigView(toml);
</file context>

backupValue: 備份
currentValue: 目前
restore: 還原
restoreSection: 還原此欄位

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: 此按钮会恢复整个配置分区及其多个配置项,但繁体中文写成了“欄位”(字段),会误导用户操作范围。请改为“還原此分區”或其他表示区段的用语。

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At MaiChartManager/Front/src/locales/zh-TW.yaml, line 416:

<comment>此按钮会恢复整个配置分区及其多个配置项,但繁体中文写成了“欄位”(字段),会误导用户操作范围。请改为“還原此分區”或其他表示区段的用语。</comment>

<file context>
@@ -402,6 +402,23 @@ mod:
+    backupValue: 備份
+    currentValue: 目前
+    restore: 還原
+    restoreSection: 還原此欄位
+    restoreAll: 全部還原
+    restored: 已還原
</file context>

</div>
)}
{editorConfig.value && !isBothModsPresent.value && (
<span

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: 备份恢复入口使用仅绑定 onClick 的 <span>,键盘用户无法访问该功能。请改用原生 <button>,或补充按钮语义、焦点和 Enter/Space 键处理。

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At MaiChartManager/Front/src/views/ModManager/ConfigEditor.tsx, line 182:

<comment>备份恢复入口使用仅绑定 `onClick` 的 `<span>`,键盘用户无法访问该功能。请改用原生 `<button>`,或补充按钮语义、焦点和 Enter/Space 键处理。</comment>

<file context>
@@ -169,6 +178,19 @@ export default defineComponent({
               </div>
             )}
+            {editorConfig.value && !isBothModsPresent.value && (
+              <span
+                class={[theme.value.lc, 'fl cursor-pointer ml-auto mr-1 shrink-0 select-none inline-flex items-center gap-1 z-0']}
+                onClick={() => { showBackupRestore.value = !showBackupRestore.value; }}
</file context>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant