Files
handler/tests/test_claude_config.py
T
Claude 24b8c44451 fix(mise-init): unblock the bootstrap agent + surface live agent output
The mise-init agent wedged on launch and the UI reported it green. Three
distinct problems, fixed together:

1. Onboarding wedge (the proximate bug). A freshly-installed claude opens
   interactive setup — theme picker, then a folder-trust prompt — before
   the REPL. A detached tmux agent has no one to answer it, so it sat on
   the theme picker forever while agents.status said 'working'. New
   control.claude_config.ensure_onboarded() marks onboarding complete and
   trusts the working dir in ~/.claude.json (merge-only, so the login
   flow's oauthAccount survives); spawn() calls it before launching.

2. Config-name gate. control/mise.py only recognized `.mise.toml`, so a
   repo shipping `mise.toml` (no dot) — or config under `.config/mise/` —
   failed the [tasks.test] gate even when healthy. It now accepts the
   filenames mise itself reads and scans them all for the test task.

3. "Done" != done (the design gap). A spawned agent's real state lives in
   its tmux pane, but the socket is control-container-only, so the API
   couldn't see it. The worker now snapshots each working agent's pane
   tail (last ~40 lines) into two new agents columns (last_output,
   output_at, migration 0007) on its existing poll loop; the API
   serializes them and AgentsSection renders a live-output <pre> under
   each running agent. A wedged agent now shows the theme picker instead
   of a misleading green badge.

Tests: home-dir writes are isolated to tmp in conftest; added coverage for
claude_config seeding/merge, the mise filename set, the worker capture
(including dead-session skip), and the API serialization.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BxKY28XKCM6o4ag3nmaVsZ
2026-07-16 19:30:58 +00:00

48 lines
1.8 KiB
Python

"""Seeding Claude Code onboarding so a detached agent boots straight to the REPL."""
from __future__ import annotations
import json
from pathlib import Path
from handler.control import claude_config
def _read(home: Path) -> dict:
return json.loads((home / ".claude.json").read_text())
def test_ensure_onboarded_seeds_defaults_on_fresh_home(tmp_path):
claude_config.ensure_onboarded(home=str(tmp_path))
data = _read(tmp_path)
assert data["hasCompletedOnboarding"] is True
assert data["theme"] == "dark"
def test_ensure_onboarded_merges_without_clobbering(tmp_path):
# The login flow's oauthAccount (and a chosen theme) must survive the seeding.
(tmp_path / ".claude.json").write_text(
json.dumps({"oauthAccount": {"emailAddress": "a@b.c"}, "theme": "light"})
)
claude_config.ensure_onboarded(home=str(tmp_path))
data = _read(tmp_path)
assert data["oauthAccount"] == {"emailAddress": "a@b.c"} # preserved
assert data["theme"] == "light" # operator's chosen theme untouched
assert data["hasCompletedOnboarding"] is True
def test_ensure_onboarded_forces_flag_and_trusts_working_dir(tmp_path):
# A stale false must not leave onboarding armed; the working dir gets trusted.
(tmp_path / ".claude.json").write_text(json.dumps({"hasCompletedOnboarding": False}))
wd = "/var/lib/handler/projects/x"
claude_config.ensure_onboarded(working_dir=wd, home=str(tmp_path))
data = _read(tmp_path)
assert data["hasCompletedOnboarding"] is True
assert data["projects"][wd]["hasTrustDialogAccepted"] is True
def test_ensure_onboarded_survives_corrupt_file(tmp_path):
(tmp_path / ".claude.json").write_text("{ not valid json")
claude_config.ensure_onboarded(home=str(tmp_path))
assert _read(tmp_path)["hasCompletedOnboarding"] is True