feat: «Здесь» from a machine's file pane opens the terminal in that pane's folder (the agent starts the shell there; an older agent, or a folder gone, at home)

This commit is contained in:
redtea committed 2026-10-16 18:17:11 +03:00
1 parent 4fb26a9652
commit 57c2f1338f
10 files changed
+143 -12

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
package server
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
)
// A terminal opened with a folder asks the agent to start there; a folder
// that is not an absolute path is left out (the shell starts at home).
func TestPanelOpenDir(t *testing.T) {
s, cookie := newTestServer(t)
for body, want := range map[string]string{
`{"dir":"/srv/my app"}`: "/srv/my app",
`{"dir":"relative"}`: "",
``: "",
} {
req := httptest.NewRequest(http.MethodPost, "/api/panel/term/x1/open", strings.NewReader(body))
req.AddCookie(cookie)
w := httptest.NewRecorder()
s.Handler().ServeHTTP(w, req)
if w.Code != 200 {
t.Fatalf("%s: code %d %s", body, w.Code, w.Body)
}
s.hub.mu.Lock()
jobs := s.hub.jobs["x1"]
s.hub.jobs["x1"] = nil
s.hub.mu.Unlock()
if len(jobs) != 1 || jobs[0].Dir != want {
t.Fatalf("%s: jobs %+v, want dir %q", body, jobs, want)
}
}
}