Skip to content

fix: handle missing optional doctor binaries#36

Merged
mizchi merged 2 commits into
mizchi:mainfrom
ubugeeei-forks:fix/doctor-missing-optional-bin
May 26, 2026
Merged

fix: handle missing optional doctor binaries#36
mizchi merged 2 commits into
mizchi:mainfrom
ubugeeei-forks:fix/doctor-missing-optional-bin

Conversation

@ubugeeei
Copy link
Copy Markdown
Contributor

Summary

  • Check whether each doctor binary exists before invoking --version.
  • Keep missing required tools as errors.
  • Report missing optional tools as not found (optional) instead of aborting on OSError.

Validation

  • moon fmt
  • moon build --target native src/cmd/actrun
  • moon test --target native
  • moon run src/cmd/actrun --target native -- doctor

@ubugeeei ubugeeei force-pushed the fix/doctor-missing-optional-bin branch from 4595a3c to b9f3ae4 Compare May 25, 2026 15:56
Copy link
Copy Markdown
Owner

@mizchi mizchi left a comment

Choose a reason for hiding this comment

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

LGTM 主旨で、小さい指摘 2 つ。

nit: "not found" メッセージが 2 箇所に重複

新規の pre-check ブロック (L5405–) と既存の --version 失敗 fallback (L5440+ あたり) で、 optional の hint 文字列構築 + -- name: not found ... 出力が 行単位で同じ になってる。 小さい helper に纏めると差分が読みやすいかも:

fn doctor_print_not_found(check : DoctorCheck) -> Unit {
  if check.required {
    println("ERR " + check.name + ": not found (required)")
  } else {
    let hint = if check.env_override.length() > 0 {
      " (optional, override with " + check.env_override + ")"
    } else {
      " (optional)"
    }
    println("--  " + check.name + ": not found" + hint)
  }
}

その上で pre-check と post---version-fail の両方からこれを呼ぶ。 helper 化と本 PR を 1 commit で混ぜず separate にしたいなら follow-up でも全然 OK。

nit: "not found" の意味が pre/post で違う

PR 後の挙動:

シナリオ 表示 実際
bin 自体が PATH に無い not found bin missing (正しい)
bin はあるが --version が exit ≠ 0 not found bin exists but flag rejected

後者は厳密には version probe failed (exit N) 的に書き分けた方が、 doctor を読んだ人がトラブルシュート時に迷わない (bin はあるのに not found って言われた!? を防げる)。 pre-existing なので blocker ではないけど、 今回触ったついでに分けても良い。

(informational) Windows portability

bin.contains("/") が absolute path 判定として使われてる。 C:\Tools\node.exe は \ なので fall through して which 呼び出しになる。 actrun が native Windows をターゲットにしてるなら where.exe も検討余地。 POSIX 専用なら無視で OK。


機能面は意図通り動くはずで、 これで node / docker / wasmtime 等が未インストールの環境でも doctor が abort せず動くようになるのは良い改善。

Address review feedback on mizchi#36:

- Extract `doctor_optional_hint`, `doctor_print_not_found`, and
  `doctor_print_version_probe_failed` helpers so the "not found" /
  optional-hint formatting is no longer duplicated between the
  pre-check and the post `--version` failure branches.
- Distinguish "binary not found" (pre-check) from
  "version probe failed (exit N)" (binary present but `--version`
  exits non-zero) so doctor output points operators at the right
  troubleshooting path.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ubugeeei
Copy link
Copy Markdown
Contributor Author

レビューありがとうございます 🙏 2 点の nit に対応しました (2182eb3)。

  • helper 化: doctor_optional_hint / doctor_print_not_found / doctor_print_version_probe_failed を抽出して、pre-check と post---version-fail の重複を解消。
  • 意味の書き分け: post---version-fail 側は version probe failed (exit N) を表示するように変更。pre-check は従来通り not found で、bin の不在 vs --version 失敗 が一目で区別できるようにしました。

Windows portability の informational 指摘は今回はスコープ外として見送り、必要があれば別 PR で対応します。

Validation

  • moon fmt (ok)
  • moon build --target native src/cmd/actrun / moon check --deny-warn --target native は当方ローカルで moonc v0.8.3+cd28f524e の依存パッケージ (mizchi/crater, moonbitlang/quickcheck, moonbit-community/yaml) で ICE (Moonc.Stype.extract_tpath_exn) が出ており、PR 前の commit でも同じく再現するため、今回の変更とは無関係の環境/ツールチェイン由来のようです。CI 側で結果を確認させてください 🙇

@ubugeeei
Copy link
Copy Markdown
Contributor Author

Claude にコメントさせたら自分が絶対に送らない文面でわろた

@mizchi mizchi merged commit 579d871 into mizchi:main May 26, 2026
3 of 7 checks passed
mizchi added a commit that referenced this pull request May 26, 2026
* test: strip absolute repo root from expect snapshots

The previous PR (#36) merge landed but 14 of 861 tests fail on CI
because expect snapshots in executor_test.mbt / lib_test.mbt /
compat_docs_test.mbt baked in the developer's local absolute path
(`/Users/mz/ghq/github.com/mizchi/actrun/_build/...`). On the CI
runner the path is `/home/runner/work/actrun/actrun/_build/...` or
`/Users/runner/work/actrun/actrun/_build/...`, so the diff is
verbatim:

  -"/Users/mz/ghq/github.com/mizchi/actrun/_build/test-workspaces/..."
  +"/home/runner/work/actrun/actrun/_build/test-workspaces/..."

Fix: add `executor_test_strip_repo_root(s)` that replaces the `$PWD`
prefix with the placeholder `<repo>`, and wrap every affected
`debug_inspect`'s first arg with it (17 call sites across 3 files).
Expect content updated to use `<repo>/_build/...`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* test: moon fmt pass on the path-strip wrap calls

* ci: restore moon.mod.json + scope wasi-node-sidecar to CJS

Two pre-existing failures uncovered alongside the path-strip fix in
this PR — neither related to the test snapshots, but both need to go
in for the branch to be CI-green:

1. nix-build (`flake.nix` / `package.nix` reference
   `./moon.mod.json`, which the MoonBit fmt-driven migration in
   7405811 deleted in favor of `moon.mod`). moonbit-overlay's
   `buildMoonPackage.nix` still reads `moonModJson` via
   `builtins.readFile`, so it errors with
   `Path 'moon.mod.json' does not exist`.

   Fix: restore `moon.mod.json` (kept in sync with the current
   `moon.mod`). Dual-maintenance is the cheapest path until the
   overlay supports the new TOML format. Tracked there:
   https://github.com/moonbit-community/moonbit-overlay

2. compat-wasi-gha — sidecar `dist/index.js` uses CommonJS
   (`require("node:fs")`), but the root `package.json` has
   `"type": "module"`, so Node treats every `.js` under the repo
   as ESM and throws
   `ReferenceError: require is not defined in ES module scope`.

   Fix: a one-line local `package.json` in
   `.github/actions/wasi-node-sidecar/dist/` with
   `"type": "commonjs"`. Scopes the CJS interpretation to this
   prebuilt artifact without touching the root project's ESM
   policy.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* ci: scope wasi-node-sidecar/dist to CommonJS

Drop a local `package.json` with `"type": "commonjs"` next to the
sidecar's `dist/index.js` so it's interpreted as CJS regardless of
the root project's `"type": "module"`. Needed because the
prebuilt sidecar uses `require("node:fs")`, and without this scope
override compat-wasi-gha fails with
`ReferenceError: require is not defined in ES module scope`.

`-f` because `dist/` is gitignored but the sidecar's compiled
artifacts are tracked the same way (existing index.js / index.wasm
are also under the same exemption).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* ci: nix flake update moonbit-overlay for newer moonc

The pinned moonbit-overlay (50118f5 / 2026-03-31) shipped a moonc
that rejects the type-inference-friendly `with fn output(self,
logger)` syntax produced by the current `moon fmt`:

  Error: Missing type annotation for the parameter self.
  Error: Missing type annotation for the parameter logger.

Local moonc accepts it; nix-build doesn't because the toolchain
is older. Bumping the overlay to d7386ba (2026-05-26) pulls in a
moonc that matches the local one and the build goes green.

Verified locally with `nix build .#actrun` — succeeds end-to-end
(only the standard uncommitted-changes warning, no errors).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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