test: compare PowerShell working directory by file identity
- commit
- 94efc287e098e34632056e455aa5dc42287f71ea
- author
- patriceckhart · · 2026-09-06 18:18 UTC
- parent
- e5fc4d2
- signature
- unsigned
- refs
- tag: v0.3.66
1 file · +18 -1
M packages/agent/tools/powershell_test.go +18 -1
| @@ -6,6 +6,7 @@ import ( | |||
| 6 | 6 | "encoding/binary" | |
| 7 | 7 | "encoding/json" | |
| 8 | 8 | "fmt" | |
| 9 | + | "os" | |
| 9 | 10 | "os/exec" | |
| 10 | 11 | "reflect" | |
| 11 | 12 | "runtime" | |
| @@ -118,7 +119,7 @@ func TestPowerShellExecution(t *testing.T) { | |||
| 118 | 119 | timeout int | |
| 119 | 120 | }{ | |
| 120 | 121 | {"unicode and quoting", "Write-Output 'Grüße 世界'; Write-Output '\"quoted\"'", "Grüße 世界", false, 0}, | |
| 121 | - | {"cwd", "(Get-Location).Path", cwd, false, 0}, | |
| 122 | + | {"cwd", "(Get-Location).Path", "", false, 0}, | |
| 122 | 123 | {"stderr", "[Console]::Error.WriteLine('stderr output')", "stderr output", false, 0}, | |
| 123 | 124 | {"exit", "exit 7", "[exit 7]", true, 0}, | |
| 124 | 125 | {"error", "throw 'failure'", "failure", true, 0}, | |
| @@ -136,6 +137,22 @@ func TestPowerShellExecution(t *testing.T) { | |||
| 136 | 137 | if res.IsError != tc.failure || !strings.Contains(text, tc.want) || !strings.HasPrefix(text, "PS> ") { | |
| 137 | 138 | t.Fatalf("result: %+v, %s", res, text) | |
| 138 | 139 | } | |
| 140 | + | if tc.name == "cwd" { | |
| 141 | + | // Windows temp paths can use short names or different casing | |
| 142 | + | // than Get-Location. Compare directory identity, not spelling. | |
| 143 | + | gotPath := strings.TrimSpace(streamed.String()) | |
| 144 | + | gotInfo, err := os.Stat(gotPath) | |
| 145 | + | if err != nil { | |
| 146 | + | t.Fatalf("stat reported cwd %q (expected %q): %v", gotPath, cwd, err) | |
| 147 | + | } | |
| 148 | + | wantInfo, err := os.Stat(cwd) | |
| 149 | + | if err != nil { | |
| 150 | + | t.Fatal(err) | |
| 151 | + | } | |
| 152 | + | if !os.SameFile(gotInfo, wantInfo) { | |
| 153 | + | t.Fatalf("reported cwd %q is not the expected directory %q", gotPath, cwd) | |
| 154 | + | } | |
| 155 | + | } | |
| 139 | 156 | if tc.name == "unicode and quoting" && !strings.Contains(streamed.String(), "Grüße 世界") { | |
| 140 | 157 | t.Fatalf("stream: %q", streamed.String()) | |
| 141 | 158 | } | |
| @@ -6,6 +6,7 @@ import ( | |||||
| 6 | "encoding/binary" | 6 | "encoding/binary" | ||
| 7 | "encoding/json" | 7 | "encoding/json" | ||
| 8 | "fmt" | 8 | "fmt" | ||
| 9 | + | "os" | |||
| 9 | "os/exec" | 10 | "os/exec" | ||
| 10 | "reflect" | 11 | "reflect" | ||
| 11 | "runtime" | 12 | "runtime" | ||
| @@ -118,7 +119,7 @@ func TestPowerShellExecution(t *testing.T) { | |||||
| 118 | timeout int | 119 | timeout int | ||
| 119 | }{ | 120 | }{ | ||
| 120 | {"unicode and quoting", "Write-Output 'Grüße 世界'; Write-Output '\"quoted\"'", "Grüße 世界", false, 0}, | 121 | {"unicode and quoting", "Write-Output 'Grüße 世界'; Write-Output '\"quoted\"'", "Grüße 世界", false, 0}, | ||
| 121 | - | {"cwd", "(Get-Location).Path", cwd, false, 0}, | 122 | + | {"cwd", "(Get-Location).Path", "", false, 0}, |
| 122 | {"stderr", "[Console]::Error.WriteLine('stderr output')", "stderr output", false, 0}, | 123 | {"stderr", "[Console]::Error.WriteLine('stderr output')", "stderr output", false, 0}, | ||
| 123 | {"exit", "exit 7", "[exit 7]", true, 0}, | 124 | {"exit", "exit 7", "[exit 7]", true, 0}, | ||
| 124 | {"error", "throw 'failure'", "failure", true, 0}, | 125 | {"error", "throw 'failure'", "failure", true, 0}, | ||
| @@ -136,6 +137,22 @@ func TestPowerShellExecution(t *testing.T) { | |||||
| 136 | if res.IsError != tc.failure || !strings.Contains(text, tc.want) || !strings.HasPrefix(text, "PS> ") { | 137 | if res.IsError != tc.failure || !strings.Contains(text, tc.want) || !strings.HasPrefix(text, "PS> ") { | ||
| 137 | t.Fatalf("result: %+v, %s", res, text) | 138 | t.Fatalf("result: %+v, %s", res, text) | ||
| 138 | } | 139 | } | ||
| 140 | + | if tc.name == "cwd" { | |||
| 141 | + | // Windows temp paths can use short names or different casing | |||
| 142 | + | // than Get-Location. Compare directory identity, not spelling. | |||
| 143 | + | gotPath := strings.TrimSpace(streamed.String()) | |||
| 144 | + | gotInfo, err := os.Stat(gotPath) | |||
| 145 | + | if err != nil { | |||
| 146 | + | t.Fatalf("stat reported cwd %q (expected %q): %v", gotPath, cwd, err) | |||
| 147 | + | } | |||
| 148 | + | wantInfo, err := os.Stat(cwd) | |||
| 149 | + | if err != nil { | |||
| 150 | + | t.Fatal(err) | |||
| 151 | + | } | |||
| 152 | + | if !os.SameFile(gotInfo, wantInfo) { | |||
| 153 | + | t.Fatalf("reported cwd %q is not the expected directory %q", gotPath, cwd) | |||
| 154 | + | } | |||
| 155 | + | } | |||
| 139 | if tc.name == "unicode and quoting" && !strings.Contains(streamed.String(), "Grüße 世界") { | 156 | if tc.name == "unicode and quoting" && !strings.Contains(streamed.String(), "Grüße 世界") { | ||
| 140 | t.Fatalf("stream: %q", streamed.String()) | 157 | t.Fatalf("stream: %q", streamed.String()) | ||
| 141 | } | 158 | } | ||