|
| 1 | +// Copyright 2026, Command Line Inc. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +package wshremote |
| 5 | + |
| 6 | +import ( |
| 7 | + "context" |
| 8 | + "os" |
| 9 | + "path/filepath" |
| 10 | + "testing" |
| 11 | + |
| 12 | + "github.com/wavetermdev/waveterm/pkg/wshrpc" |
| 13 | +) |
| 14 | + |
| 15 | +func TestRemoteFileMultiInfoCommand_PathResolution(t *testing.T) { |
| 16 | + homeDir := t.TempDir() |
| 17 | + t.Setenv("HOME", homeDir) |
| 18 | + |
| 19 | + cwdDir := filepath.Join(homeDir, "cwd") |
| 20 | + if err := os.MkdirAll(cwdDir, 0755); err != nil { |
| 21 | + t.Fatalf("mkdir cwd: %v", err) |
| 22 | + } |
| 23 | + relFile := filepath.Join(cwdDir, "rel.txt") |
| 24 | + if err := os.WriteFile(relFile, []byte("rel"), 0644); err != nil { |
| 25 | + t.Fatalf("write rel file: %v", err) |
| 26 | + } |
| 27 | + homeFile := filepath.Join(homeDir, "home.txt") |
| 28 | + if err := os.WriteFile(homeFile, []byte("home"), 0644); err != nil { |
| 29 | + t.Fatalf("write home file: %v", err) |
| 30 | + } |
| 31 | + |
| 32 | + impl := &ServerImpl{} |
| 33 | + resp, err := impl.RemoteFileMultiInfoCommand(context.Background(), wshrpc.CommandRemoteFileMultiInfoData{ |
| 34 | + Cwd: "~/cwd", |
| 35 | + Paths: []string{"rel.txt", "~/home.txt", filepath.Join(homeDir, "missing.txt")}, |
| 36 | + }) |
| 37 | + if err != nil { |
| 38 | + t.Fatalf("RemoteFileMultiInfoCommand returned error: %v", err) |
| 39 | + } |
| 40 | + |
| 41 | + if got := resp["rel.txt"].Path; got != "~/cwd/rel.txt" { |
| 42 | + t.Fatalf("relative path resolved incorrectly: got %q", got) |
| 43 | + } |
| 44 | + if got := resp["~/home.txt"].Path; got != "~/home.txt" { |
| 45 | + t.Fatalf("home path resolved incorrectly: got %q", got) |
| 46 | + } |
| 47 | + if !resp[filepath.Join(homeDir, "missing.txt")].NotFound { |
| 48 | + t.Fatalf("expected missing path to be marked NotFound") |
| 49 | + } |
| 50 | +} |
| 51 | + |
0 commit comments