Start ssh-agent when adding a key and none is running

ysm starts its own agent on $XDG_RUNTIME_DIR/ysm-agent.sock, reconnects
to it on later runs, and shows agent status in the header.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aleksey ShakhmatovandClaude Opus 5.5 committed 2026-10-30 15:18:59 +03:00
1 parent 9408ab31a9
commit f680bf3b9d
4 files changed
+119 -7

No files matched your search

+22
View File
@@ -40,3 +40,25 @@ func TestLoadKeysAndValidate(t *testing.T) {
}
}
}
func TestEnsureAgent(t *testing.T) {
t.Setenv("XDG_RUNTIME_DIR", t.TempDir())
t.Setenv("SSH_AUTH_SOCK", "/nonexistent/agent.sock")
t.Setenv("SSH_AGENT_PID", "")
started, err := ensureAgent()
if err != nil || !started || !agentRunning() {
t.Fatalf("started=%v err=%v running=%v", started, err, agentRunning())
}
pid := os.Getenv("SSH_AGENT_PID")
defer exec.Command("kill", pid).Run()
if started, err := ensureAgent(); err != nil || started {
t.Fatalf("second call started=%v err=%v", started, err)
}
// A new ysm run without SSH_AUTH_SOCK finds the agent it started before.
os.Unsetenv("SSH_AUTH_SOCK")
if !connectAgent() || os.Getenv("SSH_AUTH_SOCK") != agentSocket() {
t.Fatal("did not reconnect to ysm's agent")
}
}