Commit 68d4f9f
authored
Fix Windows FileNotFoundError when invoking sf CLI (#121)
* Fix Windows FileNotFoundError when invoking sf CLI
On Windows, subprocess.run(["sf", ...]) raises FileNotFoundError because
sf is a .cmd wrapper, not a plain executable. Passing shell=True (only on
win32) lets cmd.exe resolve the .cmd extension. No-op on macOS/Linux.
* fix: use shutil.which to resolve sf path, remove shell=True
Addresses reviewer concern about command injection risk with shell=True.
shutil.which resolves the sf executable (falling back to sf.cmd on
Windows), keeping shell=False everywhere while still working on Windows.
* fix(tests): mock shutil.which so existing tests pass without sf installed
The previous commit replaced shell=True + "sf" string with shutil.which()
to resolve the sf executable path before calling subprocess.run. This
moved the "sf not found" check earlier — before _run_sf_command is even
defined — meaning tests that only mocked subprocess.run were now hitting
the shutil.which() call for real. On CI (Linux, no SF CLI), which()
returns None and raises immediately, causing all 11 SFCLITokenProvider
and SFCLIDataCloudReader tests to fail with "sf command was not found"
rather than exercising the error condition they were testing.
Fix: mock shutil.which alongside subprocess.run in each affected test,
using the same unittest.mock.patch pattern already used throughout the
test suite. return_value="sf" keeps the resolved path consistent with the
hardcoded "sf" string the command-list assertions in test_sf_cli.py
expect. The "sf not found" tests are updated to patch shutil.which
returning None instead of patching subprocess.run with FileNotFoundError,
since that FileNotFoundError path was removed from the production code.
No new test files, no new imports, no new patterns — all changes are
confined to existing test classes and follow the same nesting style used
in TestCredentialsTokenProvider and the rest of the suite.1 parent 16e8b86 commit 68d4f9f
3 files changed
Lines changed: 41 additions & 31 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| 100 | + | |
100 | 101 | | |
101 | 102 | | |
102 | 103 | | |
103 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
104 | 113 | | |
105 | 114 | | |
106 | 115 | | |
| |||
110 | 119 | | |
111 | 120 | | |
112 | 121 | | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | 122 | | |
120 | 123 | | |
121 | 124 | | |
| |||
142 | 145 | | |
143 | 146 | | |
144 | 147 | | |
145 | | - | |
| 148 | + | |
146 | 149 | | |
147 | 150 | | |
148 | 151 | | |
| |||
159 | 162 | | |
160 | 163 | | |
161 | 164 | | |
162 | | - | |
| 165 | + | |
163 | 166 | | |
164 | 167 | | |
165 | 168 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
76 | 81 | | |
77 | 82 | | |
78 | 83 | | |
| |||
118 | 123 | | |
119 | 124 | | |
120 | 125 | | |
121 | | - | |
| 126 | + | |
122 | 127 | | |
123 | 128 | | |
124 | 129 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
186 | 187 | | |
187 | | - | |
| 188 | + | |
188 | 189 | | |
189 | | - | |
190 | | - | |
191 | | - | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
192 | 193 | | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
199 | 200 | | |
200 | 201 | | |
201 | 202 | | |
| |||
224 | 225 | | |
225 | 226 | | |
226 | 227 | | |
227 | | - | |
228 | | - | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
229 | 231 | | |
230 | | - | |
231 | | - | |
232 | | - | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
233 | 235 | | |
234 | 236 | | |
235 | | - | |
| 237 | + | |
236 | 238 | | |
237 | 239 | | |
238 | | - | |
| 240 | + | |
239 | 241 | | |
240 | 242 | | |
0 commit comments