Commit ab9bcab
authored
Fix: omit --setting-sources flag when setting_sources is empty or unset (#778)
## Summary
When `setting_sources` was not provided (`None`) or was an empty list,
the SDK always passed `--setting-sources ""` to the CLI. The empty
string argument causes the CLI argument parser to consume the next flag
(e.g. `--permission-mode`) as the `--setting-sources` value, producing:
```
Error processing --setting-sources: Invalid setting source: --permission-mode.
Valid options are: user, project, local
```
This blocked all default SDK usage without an explicit `setting_sources`
workaround.
## Fix
Only add `--setting-sources` when `setting_sources` is a non-empty list,
matching the pattern used by other array-typed flags (`allowed_tools`,
`disallowed_tools`, `betas`).
**Before:**
```python
sources_value = (
",".join(self._options.setting_sources)
if self._options.setting_sources is not None
else ""
)
cmd.extend(["--setting-sources", sources_value]) # always emitted
```
**After:**
```python
if self._options.setting_sources:
cmd.extend(["--setting-sources", ",".join(self._options.setting_sources)])
```
## Testing
- Added 3 unit tests verifying the fix:
- `test_build_command_setting_sources_omitted_when_not_provided` — no
`setting_sources` → no `--setting-sources` flag
- `test_build_command_setting_sources_omitted_when_empty` — empty `[]` →
no `--setting-sources` flag
- `test_build_command_setting_sources_included_when_provided` —
`["user", "project"]` → `--setting-sources user,project`
- All 427 existing tests pass
- Lint clean
Fixes anthropics/claude-agent-sdk-typescript#252
<!-- NO CHANGELOG -->1 parent bd3b7a6 commit ab9bcab
File tree
3 files changed
+37
-14
lines changed- e2e-tests
- src/claude_agent_sdk/_internal/transport
- tests
3 files changed
+37
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
215 | 215 | | |
216 | 216 | | |
217 | 217 | | |
218 | | - | |
| 218 | + | |
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
| |||
226 | 226 | | |
227 | 227 | | |
228 | 228 | | |
229 | | - | |
| 229 | + | |
| 230 | + | |
230 | 231 | | |
231 | 232 | | |
232 | 233 | | |
| |||
235 | 236 | | |
236 | 237 | | |
237 | 238 | | |
238 | | - | |
| 239 | + | |
239 | 240 | | |
240 | 241 | | |
241 | 242 | | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
| 243 | + | |
| 244 | + | |
247 | 245 | | |
248 | 246 | | |
249 | 247 | | |
| |||
Lines changed: 2 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
280 | 280 | | |
281 | 281 | | |
282 | 282 | | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
| 283 | + | |
| 284 | + | |
289 | 285 | | |
290 | 286 | | |
291 | 287 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
389 | 389 | | |
390 | 390 | | |
391 | 391 | | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
392 | 421 | | |
393 | 422 | | |
394 | 423 | | |
| |||
0 commit comments