Skip to content

修复 6 处缺陷,新增 CI 工作流,并完成一轮去重清理 - #1

Merged
LSwzx merged 3 commits into
LSwzx:mainfrom
addsas222:fix/audit-bugs-ci-cleanup
Oct 25, 2026
Merged

LSwzx merged 3 commits into
LSwzx:mainfrom
addsas222:fix/audit-bugs-ci-cleanup

Conversation

@addsas222

Copy link
Copy Markdown
Contributor

概述

对代码库做了一轮完整审查,分三个提交交付:缺陷修复、CI 补充、内部重构。全部改动 +193 / −273 行(净减 80 行),构建 0 警告 0 错误,离线测试 185/185 通过;每个提交都可独立构建(bisect 友好)。

缺陷修复(d5f41e8)

问题 影响
CreatePersistableCopy 白名单漏掉 AutoCheckUpdates 「自动检查更新」开关每次重启都会复原为开启;已在 Stage11 增加反射往返测试,未来新增配置字段漏写白名单会直接测试报红
默认游戏目录是 CWD 相对路径 .minecraft,而非 README 承诺的 %AppData%\.minecraft 全新用户首次安装/启动会落在进程当前目录下;新增 GameDirectory.FromConfig 统一解析哨兵值
首页启动时把解析后的目录写回配置 临时参数 --game-dir(注释明确说不写回)被永久持久化
整合包 .mrpack 声明路径无包含性校验 恶意第三方整合包可向实例目录外任意写文件(zip-slip);复用项目内已有的 SafeCombine 模式拦截
ImageCache 的 catch 过滤器漏了 OperationCanceledException HttpClient 20s 超时异常从 fire-and-forget 溜走,图标静默加载失败
Java 自动下载后立即保存的是旧路径 依赖 500ms 防抖竞态补救;现在直接写配置再落盘

另有两处小修:设备码登录先请求再等待(授权已完成的用户省一个轮询间隔);--scan 诊断发现异常时正确返回非零退出码。

CI 工作流(17c224d)

新增 .github/workflows/ci.yml:push / PR 时在 windows-latest 上构建解决方案并跑离线测试套件(OML.Test --no-network)。此前只有打 tag 的发布流水线,日常推送没有任何构建或测试检查。

同时把 User-Agent 从硬编码 OML/0.1 改为动态读取入口程序集版本(当前上报 OML/1.1.2),发版不用再回头改代码(Modrinth 服务条款要求可识别的 UA)。

去重清理(73fe997)

  • 原子写文件(临时文件 + Move)5 处重复 → 统一为 AtomicFile.WriteAllTextAsync
  • OptiFine 安装流程在 InstallViewModel 里逐行重复两份 → 合并为 RunOptiFineInstallerAsync
  • LaunchSession 与 VersionInstaller 逐字相同的 Report / PhaseProgress 进度上报基础设施 → 提取共享;三个 ensure 方法保留各自实现,因为两边的权重、开关(CompleteAssets)、资源上限、重试与失败通知策略是真实语义差异,强行合并只会变成参数堆砌
  • 删除 10 处确认零引用的成员(InvalidateCache ×2、GetFastestUrlAsync、Rebase、DownloadSource.Priority 等)及仅覆盖这些死代码的 2 条测试断言(离线断言总数 187 → 185)

说明

  • MicrosoftAuthService(等待 Mojang 白名单)按现状保留未动。
  • 联网测试(真实下载/启动游戏)未在本机执行,CI 亦不包含;改动面已由离线套件覆盖。

…ck paths

- ConfigManager: include AutoCheckUpdates in the persistable copy (the
  whitelist silently dropped it, so the setting reset on every restart);
  Stage11 now round-trips every LauncherConfig property via reflection so
  a future field cannot be forgotten again.
- GameDirectory.FromConfig: the ".minecraft" default is a sentinel, not
  a CWD-relative path; both LauncherContext and LaunchSession now resolve
  it to %AppData%\.minecraft as documented in the README.
- HomeViewModel no longer writes the resolved game directory back to the
  config, which persisted the temporary --game-dir override.
- ModsViewModel: reject modrinth.index.json entries that escape the
  instance directory (zip-slip via SafeCombine).
- ImageCache: catch OperationCanceledException so HttpClient timeouts no
  longer escape the fire-and-forget icon load.
- SettingsViewModel: write the downloaded Java path directly into the
  config before saving instead of racing the 500ms debounced save.
- MicrosoftAuthService: poll the device-code token first and delay after,
  saving one interval when the user has already authorized.
- Tests: --scan now exits non-zero when issues are found.
Adds a windows-latest workflow that builds the solution and runs the
offline test suite (OML.Test --no-network); previously only tag-triggered
releases built anything.

Also report the real entry-assembly version in the User-Agent instead of
the stale hardcoded OML/0.1 (Modrinth's ToS asks for an identifiable UA).
- AtomicFile.WriteAllTextAsync replaces five copies of the
  temp-file-then-move pattern.
- RunOptiFineInstallerAsync consolidates the OptiFine install flow that
  was duplicated between RunOptiFineAsync and ImportOptiFinePackageAsync.
- LaunchProgressReporter shares the verbatim-identical Report helper and
  PhaseProgress adapter between LaunchSession and VersionInstaller; the
  three ensure-methods stay separate because their weights, toggles and
  failure policies genuinely differ.
- Delete confirmed-unreferenced members: DownloadUrls.Rebase,
  DownloadSource.Priority, InvalidateCache (JavaScanner,
  BmclApiSourceProvider), MirrorSpeedTester.GetFastestUrlAsync,
  VersionInheritor.EnumerateStringArguments,
  VersionRepository.GetLatestReleaseAsync/GetLatestSnapshotAsync,
  GameDirectory.GetSavesDirectory/GetModsDirectory,
  LauncherContext.IsInitialized and the never-subscribed ConfigChanged
  event, along with the test lines that only exercised them.
@LSwzx
LSwzx merged commit 85ba701 into LSwzx:main Oct 25, 2026
@addsas222
addsas222 deleted the fix/audit-bugs-ci-cleanup branch October 25, 2026 07:32
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.

2 participants