From 4f32c459a68bc216483baf8610d78bc480907cac Mon Sep 17 00:00:00 2001 From: Cole Lashley Date: Fri, 26 Apr 2024 11:11:03 -0700 Subject: [PATCH 1/5] Small aux view fixes that make cmdinput focus work a bit better (#594) * added some more fixes for aichat and cmdinput * removed comments and fixed up merge conflicts * small fix * fixed bug --- src/app/workspace/cmdinput/aichat.tsx | 1 + src/models/input.ts | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/app/workspace/cmdinput/aichat.tsx b/src/app/workspace/cmdinput/aichat.tsx index 3296704b7..544210b0b 100644 --- a/src/app/workspace/cmdinput/aichat.tsx +++ b/src/app/workspace/cmdinput/aichat.tsx @@ -145,6 +145,7 @@ class AIChat extends React.Component<{}, {}> { currentRef.value = ""; } else { inputModel.grabCodeSelectSelection(); + inputModel.setAuxViewFocus(false); } } diff --git a/src/models/input.ts b/src/models/input.ts index 39657922d..c10b5c943 100644 --- a/src/models/input.ts +++ b/src/models/input.ts @@ -464,9 +464,6 @@ class InputModel { // Sets the focus state of the auxiliary view. If true, the view will get focus. Otherwise, the main input will get focus. setAuxViewFocus(focus: boolean): void { - if (this.getAuxViewFocus() == focus) { - return; - } mobx.action(() => { this.auxViewFocus.set(focus); })(); @@ -479,6 +476,9 @@ class InputModel { if (view != null && this.getActiveAuxView() != view) { return false; } + if (view != null && !this.getAuxViewFocus()) { + return false; + } if (view == null && this.hasFocus() && !this.getAuxViewFocus()) { return true; } @@ -687,6 +687,7 @@ class InputModel { openAIAssistantChat(): void { this.setActiveAuxView(appconst.InputAuxView_AIChat); + this.setAuxViewFocus(true); this.globalModel.sendActivity("aichat-open"); } From 22c5d224bdd448be0714a86456197b8efca7043e Mon Sep 17 00:00:00 2001 From: Ian Jennings Date: Fri, 26 Apr 2024 13:11:30 -0500 Subject: [PATCH 2/5] TestDriver: Update to 2.9.4 (#607) * update to 2.9.4 * move prerun to action file * update v * migrate prompt * bunk update to trigger re-run --- .github/workflows/regression.yml | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/.github/workflows/regression.yml b/.github/workflows/regression.yml index 2d6e43f9a..0a50189f5 100644 --- a/.github/workflows/regression.yml +++ b/.github/workflows/regression.yml @@ -1,4 +1,4 @@ -name: TestDriver.ai Regression Testing +name: TestDriver.ai Regression Testing (test) on: push: @@ -18,8 +18,27 @@ jobs: id: testdriver # note that .testdriver/prerun.sh runs before this, so the app has launched already with: + version: v2.9.4 + prerun: | + rm ~/Desktop/WITH-LOVE-FROM-AMERICA.txt + cd ~/actions-runner/_work/testdriver/testdriver/ + brew install go + brew tap scripthaus-dev/scripthaus + brew install scripthaus + npm install -g yarn + scripthaus run build-backend + echo "Yarn" + yarn + echo "Rebuild" + scripthaus run electron-rebuild + echo "Webpack" + scripthaus run webpack-build + echo "Starting Electron" + scripthaus run electron 1>/dev/null 2>&1 & + echo "Electron Done" + exit prompt: | - 2. click "Continue" + 2. click "Create new tab" 2. focus the Wave input with the keyboard shorcut Command + I 3. type 'ls' into the input 4. press return From db557e0b6901347a6c6e9f0c614639fd906c3472 Mon Sep 17 00:00:00 2001 From: Evan Simkowitz Date: Fri, 26 Apr 2024 11:23:09 -0700 Subject: [PATCH 3/5] Validate config dir path to resolve security warning (#611) * Attempt to validate config path to resolve security warning * move above fullpath * make sure path does not reference parent dir --- wavesrv/cmd/main-server.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/wavesrv/cmd/main-server.go b/wavesrv/cmd/main-server.go index ef07a022e..d1b608154 100644 --- a/wavesrv/cmd/main-server.go +++ b/wavesrv/cmd/main-server.go @@ -1018,6 +1018,11 @@ func doShutdown(reason string) { func configDirHandler(w http.ResponseWriter, r *http.Request) { configPath := r.URL.Path + if !fs.ValidPath(configPath) && !strings.Contains(configPath, "..") { + w.WriteHeader(http.StatusInternalServerError) + w.Write([]byte(fmt.Sprintf("invalid path: %s", configPath))) + return + } configFullPath := path.Join(scbase.GetWaveHomeDir(), configPath) dirFile, err := os.Open(configFullPath) if err != nil { From 25b77c7feefc7225e69558248c350506d089a04a Mon Sep 17 00:00:00 2001 From: Evan Simkowitz Date: Fri, 26 Apr 2024 12:00:11 -0700 Subject: [PATCH 4/5] Attempt 2 to resolve security warning (#612) * replace path with filepath * remove configPath from error * remove unnecessary printf * replace more paths with filepath * remove unnecessary abs path call * bad commit --- wavesrv/cmd/main-server.go | 35 +++++++++++++++-------------------- wavesrv/pkg/scbase/scbase.go | 28 ++++++++++++++-------------- 2 files changed, 29 insertions(+), 34 deletions(-) diff --git a/wavesrv/cmd/main-server.go b/wavesrv/cmd/main-server.go index d1b608154..17f27aa9d 100644 --- a/wavesrv/cmd/main-server.go +++ b/wavesrv/cmd/main-server.go @@ -17,7 +17,6 @@ import ( "net/http" "os" "os/signal" - "path" "path/filepath" "regexp" "runtime" @@ -798,26 +797,21 @@ func HandleRunEphemeralCommand(w http.ResponseWriter, r *http.Request) { } } -func CheckIsDir(dirHandler http.Handler, fileHandler http.Handler) http.Handler { +// Checks if the /config request is for a specific file or a directory. Passes the request to the appropriate handler. +func ConfigHandlerCheckIsDir(dirHandler http.Handler, fileHandler http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { configPath := r.URL.Path - configAbsPath, err := filepath.Abs(configPath) - if err != nil { + configBaseDir := filepath.Join(scbase.GetWaveHomeDir(), "config") + configFullPath, err := filepath.Abs(filepath.Join(scbase.GetWaveHomeDir(), configPath)) + if err != nil || !strings.HasPrefix(configFullPath, configBaseDir) { w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte(fmt.Sprintf("error getting absolute path: %v", err))) - return - } - configBaseDir := path.Join(scbase.GetWaveHomeDir(), "config") - configFullPath := path.Join(scbase.GetWaveHomeDir(), configAbsPath) - if !strings.HasPrefix(configFullPath, configBaseDir) { - w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte(fmt.Sprintf("error: path is not in config folder"))) + w.Write([]byte("error: path is not in config folder")) return } fstat, err := os.Stat(configFullPath) if errors.Is(err, fs.ErrNotExist) { w.WriteHeader(http.StatusNotFound) - w.Write([]byte(fmt.Sprintf("file not found: %v", configAbsPath))) + w.Write([]byte(fmt.Sprintf("file not found: %v", err))) return } else if err != nil { w.WriteHeader(http.StatusInternalServerError) @@ -864,7 +858,7 @@ func AuthKeyWrapAllowHmac(fn WebFnType) WebFnType { hmacOk, err := waveenc.ValidateUrlHmac([]byte(scbase.WaveAuthKey), r.URL.Path, qvals) if err != nil || !hmacOk { w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte(fmt.Sprintf("error validating hmac"))) + w.Write([]byte("error validating hmac")) return } // fallthrough (hmac is valid) @@ -1018,12 +1012,13 @@ func doShutdown(reason string) { func configDirHandler(w http.ResponseWriter, r *http.Request) { configPath := r.URL.Path - if !fs.ValidPath(configPath) && !strings.Contains(configPath, "..") { + homeDir := scbase.GetWaveHomeDir() + configFullPath, err := filepath.Abs(filepath.Join(homeDir, configPath)) + if err != nil || !strings.HasPrefix(configFullPath, homeDir) { w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte(fmt.Sprintf("invalid path: %s", configPath))) + w.Write([]byte(fmt.Sprintf("Invalid path: %v", err))) return } - configFullPath := path.Join(scbase.GetWaveHomeDir(), configPath) dirFile, err := os.Open(configFullPath) if err != nil { w.WriteHeader(http.StatusInternalServerError) @@ -1185,11 +1180,11 @@ func main() { gr.HandleFunc("/api/log-active-state", AuthKeyWrap(HandleLogActiveState)) gr.HandleFunc("/api/read-file", AuthKeyWrapAllowHmac(HandleReadFile)) gr.HandleFunc("/api/write-file", AuthKeyWrap(HandleWriteFile)).Methods("POST") - configPath := path.Join(scbase.GetWaveHomeDir(), "config") + "/" + configPath := filepath.Join(scbase.GetWaveHomeDir(), "config") log.Printf("[wave] config path: %q\n", configPath) - isFileHandler := http.StripPrefix("/config/", http.FileServer(http.Dir(configPath))) + isFileHandler := http.StripPrefix("/config/", http.FileServer(http.Dir(configPath)+"/")) isDirHandler := http.HandlerFunc(configDirHandler) - gr.PathPrefix("/config/").Handler(CheckIsDir(isDirHandler, isFileHandler)) + gr.PathPrefix("/config/").Handler(ConfigHandlerCheckIsDir(isDirHandler, isFileHandler)) serverAddr := MainServerAddr if scbase.IsDevMode() { diff --git a/wavesrv/pkg/scbase/scbase.go b/wavesrv/pkg/scbase/scbase.go index 60daad85e..8e52fb453 100644 --- a/wavesrv/pkg/scbase/scbase.go +++ b/wavesrv/pkg/scbase/scbase.go @@ -12,7 +12,7 @@ import ( "log" "os" "os/exec" - "path" + "path/filepath" "regexp" "runtime" "strconv" @@ -64,9 +64,9 @@ func GetWaveHomeDir() string { } pdev := os.Getenv(WaveDevVarName) if pdev != "" { - scHome = path.Join(homeVar, WaveDevDirName) + scHome = filepath.Join(homeVar, WaveDevDirName) } else { - scHome = path.Join(homeVar, WaveDirName) + scHome = filepath.Join(homeVar, WaveDirName) } } @@ -78,7 +78,7 @@ func MShellBinaryDir() string { if appPath == "" { appPath = "." } - return path.Join(appPath, "bin", "mshell") + return filepath.Join(appPath, "bin", "mshell") } func MShellBinaryPath(version string, goos string, goarch string) (string, error) { @@ -91,7 +91,7 @@ func MShellBinaryPath(version string, goos string, goarch string) (string, error return "", fmt.Errorf("invalid mshell version: %q", version) } fileName := fmt.Sprintf("mshell-%s-%s.%s", versionStr, goos, goarch) - fullFileName := path.Join(binaryDir, fileName) + fullFileName := filepath.Join(binaryDir, fileName) return fullFileName, nil } @@ -134,7 +134,7 @@ func InitializeWaveAuthKey() error { if err != nil { return fmt.Errorf("cannot find/create WAVETERM_HOME directory %q", homeDir) } - fileName := path.Join(homeDir, WaveAuthKeyFileName) + fileName := filepath.Join(homeDir, WaveAuthKeyFileName) fd, err := os.Open(fileName) if err != nil && errors.Is(err, fs.ErrNotExist) { return createWaveAuthKeyFile(fileName) @@ -162,7 +162,7 @@ func AcquireWaveLock() (*os.File, error) { if err != nil { return nil, fmt.Errorf("cannot find/create WAVETERM_HOME directory %q", homeDir) } - lockFileName := path.Join(homeDir, WaveLockFile) + lockFileName := filepath.Join(homeDir, WaveLockFile) log.Printf("[base] acquiring lock on %s\n", lockFileName) fd, err := os.OpenFile(lockFileName, os.O_RDWR|os.O_CREATE, 0600) if err != nil { @@ -188,7 +188,7 @@ func EnsureSessionDir(sessionId string) (string, error) { return sdir, nil } scHome := GetWaveHomeDir() - sdir = path.Join(scHome, SessionsDirBaseName, sessionId) + sdir = filepath.Join(scHome, SessionsDirBaseName, sessionId) err := ensureDir(sdir) if err != nil { return "", err @@ -202,7 +202,7 @@ func EnsureSessionDir(sessionId string) (string, error) { // deprecated (v0.1.8) func GetSessionsDir() string { waveHome := GetWaveHomeDir() - sdir := path.Join(waveHome, SessionsDirBaseName) + sdir := filepath.Join(waveHome, SessionsDirBaseName) return sdir } @@ -217,7 +217,7 @@ func EnsureScreenDir(screenId string) (string, error) { return sdir, nil } scHome := GetWaveHomeDir() - sdir = path.Join(scHome, ScreensDirBaseName, screenId) + sdir = filepath.Join(scHome, ScreensDirBaseName, screenId) err := ensureDir(sdir) if err != nil { return "", err @@ -230,18 +230,18 @@ func EnsureScreenDir(screenId string) (string, error) { func GetScreensDir() string { waveHome := GetWaveHomeDir() - sdir := path.Join(waveHome, ScreensDirBaseName) + sdir := filepath.Join(waveHome, ScreensDirBaseName) return sdir } func EnsureConfigDirs() (string, error) { scHome := GetWaveHomeDir() - configDir := path.Join(scHome, "config") + configDir := filepath.Join(scHome, "config") err := ensureDir(configDir) if err != nil { return "", err } - keybindingsFile := path.Join(configDir, "keybindings.json") + keybindingsFile := filepath.Join(configDir, "keybindings.json") keybindingsFileObj, err := ensureFile(keybindingsFile) if err != nil { return "", err @@ -250,7 +250,7 @@ func EnsureConfigDirs() (string, error) { keybindingsFileObj.WriteString("[]\n") keybindingsFileObj.Close() } - terminalThemesDir := path.Join(configDir, "terminal-themes") + terminalThemesDir := filepath.Join(configDir, "terminal-themes") err = ensureDir(terminalThemesDir) if err != nil { return "", err From d0867477ff4d6bb5e0a4d0dd5b3d8ca0d41ca11b Mon Sep 17 00:00:00 2001 From: Evan Simkowitz Date: Fri, 26 Apr 2024 12:08:10 -0700 Subject: [PATCH 5/5] add path separator for config dir handler (#613) --- wavesrv/cmd/main-server.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wavesrv/cmd/main-server.go b/wavesrv/cmd/main-server.go index 17f27aa9d..b4e3228de 100644 --- a/wavesrv/cmd/main-server.go +++ b/wavesrv/cmd/main-server.go @@ -1180,9 +1180,9 @@ func main() { gr.HandleFunc("/api/log-active-state", AuthKeyWrap(HandleLogActiveState)) gr.HandleFunc("/api/read-file", AuthKeyWrapAllowHmac(HandleReadFile)) gr.HandleFunc("/api/write-file", AuthKeyWrap(HandleWriteFile)).Methods("POST") - configPath := filepath.Join(scbase.GetWaveHomeDir(), "config") + configPath := filepath.Join(scbase.GetWaveHomeDir(), "config") + strconv.QuoteRune(filepath.Separator) log.Printf("[wave] config path: %q\n", configPath) - isFileHandler := http.StripPrefix("/config/", http.FileServer(http.Dir(configPath)+"/")) + isFileHandler := http.StripPrefix("/config/", http.FileServer(http.Dir(configPath))) isDirHandler := http.HandlerFunc(configDirHandler) gr.PathPrefix("/config/").Handler(ConfigHandlerCheckIsDir(isDirHandler, isFileHandler))