Skip to content

Commit 2492dca

Browse files
shiraynerclaude
andcommitted
fix: address CodeRabbit review issues on PR #3312
- SetActiveTab: verify tab belongs to workspace before auto-pinning - UpdateWorkspacePinnedTabIds: validate and deduplicate input against TabIds - git subprocess commands: add 10s timeout via context.WithTimeout - RPC response validation: check resp structure before accessing properties Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c61ca59 commit 2492dca

3 files changed

Lines changed: 29 additions & 4 deletions

File tree

frontend/app/view/gitstatus/gitstatus.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ export class GitStatusViewModel implements ViewModel {
107107
);
108108
if (this.disposed || this.fetchEpoch !== epoch) return;
109109

110-
if (resp.error) {
110+
if (resp == null || typeof resp !== "object") {
111+
globalStore.set(this.errorAtom, "Invalid RPC response");
112+
globalStore.set(this.filesAtom, []);
113+
globalStore.set(this.branchAtom, "");
114+
} else if (resp.error) {
111115
globalStore.set(this.errorAtom, resp.error);
112116
globalStore.set(this.filesAtom, []);
113117
globalStore.set(this.branchAtom, "");

pkg/wcore/workspace.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ func SetActiveTab(ctx context.Context, workspaceId string, tabId string) error {
369369
return fmt.Errorf("tab not found: %q", tabId)
370370
}
371371
workspace.ActiveTabId = tabId
372-
if utilfn.FindStringInSlice(workspace.PinnedTabIds, tabId) == -1 {
372+
if utilfn.FindStringInSlice(workspace.TabIds, tabId) != -1 && utilfn.FindStringInSlice(workspace.PinnedTabIds, tabId) == -1 {
373373
workspace.PinnedTabIds = append(workspace.PinnedTabIds, tabId)
374374
}
375375
wstore.DBUpdate(ctx, workspace)
@@ -433,7 +433,19 @@ func UpdateWorkspacePinnedTabIds(ctx context.Context, workspaceId string, pinned
433433
if ws == nil {
434434
return fmt.Errorf("workspace not found: %q", workspaceId)
435435
}
436-
ws.PinnedTabIds = pinnedTabIds
436+
tabSet := make(map[string]bool, len(ws.TabIds))
437+
for _, id := range ws.TabIds {
438+
tabSet[id] = true
439+
}
440+
seen := make(map[string]bool, len(pinnedTabIds))
441+
var filtered []string
442+
for _, id := range pinnedTabIds {
443+
if tabSet[id] && !seen[id] {
444+
seen[id] = true
445+
filtered = append(filtered, id)
446+
}
447+
}
448+
ws.PinnedTabIds = filtered
437449
wstore.DBUpdate(ctx, ws)
438450
return nil
439451
}

pkg/wshrpc/wshremote/gitstatus.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ import (
1212
"regexp"
1313
"strconv"
1414
"strings"
15+
"time"
1516

1617
"github.com/wavetermdev/waveterm/pkg/wshrpc"
1718
)
1819

20+
const GitCommandTimeout = 10 * time.Second
21+
1922
func (impl *ServerImpl) RemoteGitStatusCommand(ctx context.Context, data wshrpc.CommandRemoteGitStatusData) (*wshrpc.GitStatusResponse, error) {
2023
cwd := data.Cwd
2124
if cwd == "" {
@@ -39,6 +42,8 @@ func (impl *ServerImpl) RemoteGitStatusCommand(ctx context.Context, data wshrpc.
3942
}
4043

4144
func getGitBranch(ctx context.Context, cwd string) (string, error) {
45+
ctx, cancel := context.WithTimeout(ctx, GitCommandTimeout)
46+
defer cancel()
4247
cmd := exec.CommandContext(ctx, "git", "branch", "--show-current")
4348
cmd.Dir = cwd
4449
out, err := cmd.Output()
@@ -49,6 +54,8 @@ func getGitBranch(ctx context.Context, cwd string) (string, error) {
4954
}
5055

5156
func getGitStatusFiles(ctx context.Context, cwd string) ([]wshrpc.GitStatusFile, error) {
57+
ctx, cancel := context.WithTimeout(ctx, GitCommandTimeout)
58+
defer cancel()
5259
cmd := exec.CommandContext(ctx, "git", "status", "--porcelain")
5360
cmd.Dir = cwd
5461
out, err := cmd.Output()
@@ -91,7 +98,9 @@ func (impl *ServerImpl) RemoteGitLineDiffCommand(ctx context.Context, data wshrp
9198
}
9299
}
93100

94-
cmd := exec.CommandContext(ctx, "git", "diff", "HEAD", "--unified=0", "--", relPath)
101+
gitCtx, cancel := context.WithTimeout(ctx, GitCommandTimeout)
102+
defer cancel()
103+
cmd := exec.CommandContext(gitCtx, "git", "diff", "HEAD", "--unified=0", "--", relPath)
95104
cmd.Dir = data.Cwd
96105
out, err := cmd.Output()
97106
if err != nil {

0 commit comments

Comments
 (0)