Commit Graph
2 Commits
Author SHA1 Message Date
yetone 7d0c68b187 proc: the mise-hangs test gives up on its fake mise once it has written its pid, not after 300ms a loaded machine passes first (#1838)
What: the context an ask of mise runs under comes from miseAsk (a var;
production keeps miseWait = 5s, now a const). The "hangs" case of
TestFindToolKeepsWrapperWhenMiseDoesntSay cancels it once the fake mise
has written its pid (polled, with a minute's cap), then checks that
FindTool returns the wrapper within 30s of that (the fake sleeps 60s) and
that the fake's process is gone. The other wrapper tests give an
answering fake a minute instead of the production 5s.

Why: the test set miseWait to 300ms; at load average ~20 the fake's shell
hadn't written its pid by then, was killed, and the test said "mise
wasn't asked" though FindTool had asked. Under the same load the "fails"
case took 4.5s of the 5s budget here, so the answering fakes got room too.

Run (go1.26.8, sandbox HOME, private GOCACHE, load avg ~20):
- repro on old code: a 0.5s sleep injected before the fake writes its pid
  -> hangs FAIL "mise wasn't asked".
- new code with a 2s sleep injected: pass (hangs 2.2s). Removed after.
- break check: miseWhich ignoring the context -> FAIL "FindTool returned
  1m0s after mise was given up on". Restored: pass.
- gofmt -l clean; go vet ./... darwin, linux -tags nogui, windows: clean.
- go test -tags nogui ./internal/proc: ok; -race -count=5 -run
  'TestFindTool|TestParseMiseWrapper': ok.
Not run: the full go test ./...; Linux CI's run of this test.
2026-10-12 23:56:20 +08:00
yetone 1bf722e289 proc, provider, agent: a claude (or other agent CLI) that is a mise wrapper script is run as the program mise names, and a Claude sign-in that gets no link says which program it ran (deluxe on Discord)
deluxe (Omarchy Linux, magpie started from the desktop) never saw the
Claude sign-in link. ~/.local/bin/claude was a script ending
`exec mise x "claude" -- "claude" "$@"`; without the shell's mise
environment, `mise x` looks claude up on PATH, finds the same script
(~/.local/bin is before mise's shims) and it runs itself for ever.

What changed:
- proc.Unwrap / proc.LookPath (internal/proc/wrapper.go): a small #!
  script whose line is `[exec] mise|rtx x|exec [opts] [tool] -- <name>`
  is resolved with `mise which <name>` (then `mise which --tool <tool>
  <name>`), run as a probe (process group killed) with a 5s timeout,
  magpie's environment and the home folder as cwd. The answer must be an
  executable file that isn't the wrapper or another wrapper; otherwise,
  or with no mise, the old path is kept. Answers are cached per file
  (path, mtime, size); a failed ask is retried after a minute.
  Windows is unchanged.
- proc.FindTool (claude via claudecode.Find: the sign-in, the gateway's
  Claude subscription, `magpie claude-code`) unwraps what it finds.
- The siblings that looked an agent CLI up with exec.LookPath use
  proc.LookPath: agent.binAt (detection, CLI version/update), codex,
  kiro-cli, devin, cursor-agent, Air's opencode, nativemodels' npm
  package lookup.
- The Claude sign-in already gave up after linkWait (30s) with "claude
  auth login gave no link to open". It now adds the last line the CLI
  printed, or, when it printed nothing, the program it ran and to run
  `<path> auth login` in a terminal to see what it does.

asdf shims (`exec asdf exec "claude" "$@"`) are left alone: asdf exec
resolves the real program itself and doesn't recurse.

Verified (macOS, sandbox HOME, Go caches pinned):
- New tests: internal/proc/wrapper_test.go (wrapper -> mise's program;
  no mise -> wrapper; mise fails / names the wrapper / names a folder /
  hangs -> wrapper, and the hung mise's pid is gone; deluxe's own fixed
  script, a node launcher, a wrapper of another command, a commented
  line -> unchanged and mise never asked; parse cases; --tool retry),
  internal/provider/signin_claude_wrapper_test.go (the full Claude
  sign-in through the wrapper with a fake mise that really recurses:
  link shown, account added; with no `mise which`, the sign-in fails in
  linkWait naming the wrapper).
- Break checks: with find.go put back, TestFindToolUnwrapsMiseWrapper and
  TestFindToolAsksWithWrappersTool FAIL (FindTool = the wrapper), and
  TestClaudeSignInThroughMiseWrapper FAILs with "claude auth login gave
  no link to open: .../local-bin/claude printed nothing in 5s". With the
  old error string, TestClaudeSignInWrapperThatNeverStarts FAILs.
- gofmt -l clean; go vet ./...; GOOS=linux go vet -tags nogui ./...;
  GOOS=windows go vet ./...; GOOS=linux go build -tags nogui;
  GOOS=windows go build.
- go test -tags nogui ./...: every package ok except internal/agent and
  internal/gateway, which hit the default 10m timeout with the machine
  at load ~45 (different tests each run, none in the new code). Those
  two were rerun with -timeout 40m; origin/main 217d2f8f2's
  internal/agent alone took 2094s under the same load.
- Rebased on 9964535ad, -timeout 40m: internal/agent ok (1689s),
  internal/proc ok, internal/provider ok (681s), internal/claudecode ok;
  internal/gateway FAIL in one test, TestCodexHeardWithinItsIdleTimeout
  (3.78s against its 3s wall-clock bound, body right, no retry taken).
  Alone with -count=5 it passes 5 of 5. Filed as #1800; unrelated to
  binary lookup.

Not verified: no real mise or the reporter's Omarchy machine; the fake
mise stands in for mise's which/x. The wrapper fixture is the line the
reporter quoted, not their whole file.
2026-10-12 19:52:37 +08:00