Skip to content

refactor(cli): add runtime port seam#135

Open
2233admin wants to merge 1 commit into
VirtualHotBar:mainfrom
2233admin:codex/upstream-cli-runtime
Open

refactor(cli): add runtime port seam#135
2233admin wants to merge 1 commit into
VirtualHotBar:mainfrom
2233admin:codex/upstream-cli-runtime

Conversation

@2233admin

Copy link
Copy Markdown

Summary

  • Add a small runtime port layer for filesystem, command, platform, and sidecar operations.
  • Move Tauri-specific calls behind the runtime adapter.
  • Keep existing GUI behavior unchanged while making non-GUI CLI entrypoints possible.

Why

This is the first step toward a headless NetMount CLI that automation tools and coding agents can call without launching the GUI or reading internal config files directly.

Test Plan

  • pnpm run typecheck
  • pnpm run lint
  • pnpm exec vitest run

@VirtualHotBar

Copy link
Copy Markdown
Owner

测试过可用吗?

@VirtualHotBar

Copy link
Copy Markdown
Owner

解决下冲突

@VirtualHotBar

Copy link
Copy Markdown
Owner

整体方向是合理的:通过 Runtime 抽象层解耦业务逻辑与 Tauri GUI,为后续 CLI/headless 模式提供了基础。但当前还有几个问题需要在合并前处理。

必须修复

  1. notify() 丢失了原有通知行为

mount.ts 原先使用:

Notification.error({
  title: '挂载失败',
  content: errorMsg,
  duration: 10000,
})

现在改成了:

getRuntime().notify('error', '挂载失败: ' + errorMsg)

这会丢失标题、正文结构和 10 秒显示时长。src/runtime/tauri.ts:114-118 中也只是调用 Message.error(msg),因此挂载失败等重要错误会恢复成默认时长的普通消息。

建议让 notify() 支持结构化参数,例如:

notify(level, message, options?: {
  title?: string
  duration?: number
})

并保留 GUI 模式下原有的显示行为。

  1. Runtime 适配器缺少测试

新增的 src/runtime/port.tssrc/runtime/tauri.tssrc/runtime/node.ts 没有对应的单元测试,但它们已经接管了错误通知、配置读写、sidecar 调用和 Windows 驱动器检测等关键路径。

至少需要补充以下测试:

  • Runtime 方法是否正确转发到对应实现;
  • tauriRuntimenodeRuntime 的行为;
  • 默认 Runtime 未初始化时的错误处理;
  • 配置读写和 sidecar 调用路径。
  1. 测试断言被删除,但没有看到等价覆盖

TaskRepository.test.tsMountRepository.test.ts 中移除了 expect(saveNmConfig).toHaveBeenCalled()。如果配置保存职责确实已经转移到 addMountConfig,应在 addMountConfig 的测试中补充等价断言,否则这部分回归保护会下降。

建议修复

  1. WinFsp 路径只检查了 32 位安装目录

src/runtime/node.ts:232 只检查:

C:/Program Files (x86)/WinFsp

还需要支持常见的 64 位安装路径:

C:/Program Files/WinFsp

最好通过多个候选路径或系统环境/注册表进行检测。

  1. 需要解决当前合并冲突并重新运行 CI

Owner 已经留言要求“解决下冲突”。此外,PR 的 Checks 页面显示 workflow 完成但没有实际 job 执行,需要确认 fork 分支的 workflow 是否正确,以及是否只是 GitHub 对 fork PR 的手动批准限制。冲突解决后应重新运行 typecheck、lint 和 Vitest,并附上实际结果。

全局 setRuntime() / getRuntime() 作为迁移阶段方案可以接受,但建议在接口文档中说明初始化要求,并避免未来在运行过程中重复替换 Runtime。

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