Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions bin/omarchy-agent-account-state
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,16 @@ def link_shared(provider: str, home: Path) -> None:
home.mkdir(parents=True, exist_ok=True)
os.chmod(home, 0o700)
for name in spec["shared_dirs"]:
(primary / name).mkdir(parents=True, exist_ok=True)
shared = primary / name
# A dangling symlink is the person's own setup, such as a dotfiles link
# whose target hasn't synced yet, so leave it for its target to appear.
# mkdir would fail on it. A link to a file or a loop still fails here.
if shared.is_symlink() and not shared.exists():
try:
shared.resolve(strict=True)
except FileNotFoundError:
continue
shared.mkdir(parents=True, exist_ok=True)
for name in spec["shared_dirs"] + spec["shared_files"]:
target = home / name
if target.exists() or target.is_symlink():
Expand Down Expand Up @@ -350,8 +359,12 @@ def begin(provider: str, label: str = "", owner: int = 0) -> Path:
pending.mkdir(parents=True, exist_ok=True)
os.chmod(pending.parent, 0o700)
home = Path(tempfile.mkdtemp(prefix="login-", dir=str(pending)))
link_shared(provider, home)
write_receipt(home, {"label": label, "owner": owner, "started": process_start(owner) if owner else ""})
try:
link_shared(provider, home)
write_receipt(home, {"label": label, "owner": owner, "started": process_start(owner) if owner else ""})
except Exception:
shutil.rmtree(home, ignore_errors=True)
raise
return home


Expand Down
29 changes: 28 additions & 1 deletion test/shell.d/agent-account-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,14 @@ pass "the existing login is listed as the primary account"

# ------------------------------------------------------------------------- add

# A shared folder can be the person's own symlink that points nowhere yet, such
# as a dotfiles link whose target hasn't synced. Adding an account must leave it
# alone rather than fail on it.
ln -s "$test_tmp/dotfiles/claude-skills" "$HOME/.claude/skills"

OMARCHY_TEST_LOGIN_UUID=u-work OMARCHY_TEST_LOGIN_EMAIL=work@example.com \
omarchy-agent-account-add claude Work </dev/null >"$test_tmp/add-output"
omarchy-agent-account-add claude Work </dev/null >"$test_tmp/add-output" 2>&1 ||
fail "adding an account works when a shared folder is a dangling symlink" "$(cat "$test_tmp/add-output")"
grep -q "Added Work (work@example.com)" "$test_tmp/add-output" || fail "adding an account reports who signed in" "$(cat "$test_tmp/add-output")"
grep -q "private window that opens" "$test_tmp/add-output" || fail "adding an account says to sign in within the private window"
[[ $(head -1 "$OMARCHY_TEST_BROWSER_LOG") == "--private https://claude.com/oauth/authorize" ]] ||
Expand All @@ -135,8 +141,29 @@ work="$accounts/claude/work"
fail "a shared file the primary doesn't have yet is linked, so it's written there when it is"
[[ $(jq -c .mcpServers "$work/.claude.json") == '{"docs":{"command":"docs-mcp"}}' ]] || fail "an added account carries the primary's MCP servers"
[[ $(stat -c %a "$work") == 700 && $(stat -c %a "$accounts/claude.json") == 600 ]] || fail "account homes and the registry are private"
[[ $(readlink "$HOME/.claude/skills") == "$test_tmp/dotfiles/claude-skills" && $(readlink "$work/skills") == "$HOME/.claude/skills" ]] ||
fail "a dangling shared symlink is left alone and still shared"
[[ -z $(find "$accounts/claude/.pending" -mindepth 1 -print -quit 2>/dev/null) ]] || fail "adding an account leaves no pending login behind"
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
pass "an added account shares everything but its login with the primary"

# A shared folder that isn't a folder at all (here a regular file) is still an
# error, and the half-made login home is cleaned up rather than left behind.
mv "$HOME/.claude/commands" "$test_tmp/commands-dir" 2>/dev/null || true
touch "$HOME/.claude/commands"
if OMARCHY_TEST_LOGIN_UUID=u-broken OMARCHY_TEST_LOGIN_EMAIL=broken@example.com \
omarchy-agent-account-add claude Broken </dev/null >"$test_tmp/broken-output" 2>&1; then
fail "a shared folder that is a file stops the add"
fi
grep -Fq "Couldn't set up a home for the new account." "$test_tmp/broken-output" ||
fail "the failed add reports the shared-folder setup error" "$(cat "$test_tmp/broken-output")"
[[ -z $(find "$accounts/claude/.pending" -mindepth 1 -print -quit 2>/dev/null) ]] ||
fail "a failed account setup leaves no pending login behind" "$(ls -A "$accounts/claude/.pending")"
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
rm "$HOME/.claude/commands"
if [[ -d $test_tmp/commands-dir ]]; then
mv "$test_tmp/commands-dir" "$HOME/.claude/commands"
fi
pass "a failed account setup is refused and cleans up after itself"

if OMARCHY_TEST_LOGIN_UUID=u-work OMARCHY_TEST_LOGIN_EMAIL=work@example.com \
omarchy-agent-account-add claude Again </dev/null >"$test_tmp/dup-output" 2>&1; then
fail "adding the same account twice fails"
Expand Down
Loading