qwen-code/packages/sdk-python/tests/unit
juhuan 8e6a572562
Some checks are pending
E2E Tests / web-shell Browser Regression (push) Waiting to run
E2E Tests / E2E Test (Linux) - sandbox:docker (push) Waiting to run
E2E Tests / E2E Test (Linux) - sandbox:none (push) Waiting to run
E2E Tests / E2E Test - macOS (push) Waiting to run
SDK Python / Classify PR (push) Waiting to run
SDK Python / SDK Python (3.10) (push) Blocked by required conditions
SDK Python / SDK Python (3.11) (push) Blocked by required conditions
SDK Python / SDK Python (3.12) (push) Blocked by required conditions
feat(sdk): add control request methods for effort, models, usage, context (#6492)
* feat(sdk): add control request methods for effort, models, usage, context

Add 4 control request methods across CLI, Python SDK, and TypeScript SDK:

- set_effort: Set reasoning effort tier (low/medium/high/xhigh/max) at
  runtime via config.setReasoningEffort(), also accept initial effort
  in initialize payload
- get_available_models: Return models available for current auth type
  via config.getAvailableModels()
- get_usage_info: Return usage dashboard data via loadUsageDashboard()
  with optional range filter (today/week/month/all)
- get_context_usage: Add Python SDK method (TS SDK already has it)

CLI: Add request types, dispatcher routing, and SystemController handlers
with capability flags (can_set_effort, can_get_available_models,
can_get_usage_info).

TS SDK: Add ControlRequestType enum values, protocol interfaces,
QueryOptions.effort field, Zod schema, and Query methods.
Python SDK: Add Effort type, validation, protocol TypedDicts, and
Query methods.

* fix(sdk): address CI feedback for control request methods

- Fix TransportOptions.effort type to literal union instead of string
- Fix Python CLIControlGetUsageInfoRequest.range to Literal type
- Remove redundant signal.aborted checks in handleGetUsageInfo
- Add Python SDK tests for set_effort, get_available_models, get_context_usage, get_usage_info, effort in initialize
- Add TS SDK tests for setEffort, getAvailableModels, getUsageInfo

* fix(sdk): address review feedback for control request methods

- Remove dead effort field from TransportOptions (flows via QueryOptions)
- Throw on invalid effort in handleInitialize (matching handleSetEffort)
- Wrap setReasoningEffort in try/catch (matching addMcpServers pattern)
- Sanitize get_available_models response to exclude baseUrl/envKey
- Rename Python get_usage_info(range=) to time_range= to avoid shadowing built-in
- Use Effort type alias and Literal type in Python set_effort/get_usage_info
- Make set_effort/setEffort return None/void to match set_model/setModel
- Add TS test for effort in initialize payload

* fix(cli): add effort read-back check and CLI-level unit tests

- Add read-back check after setReasoningEffort() in both handleSetEffort
  and handleInitialize to detect silent no-op when thinking is disabled
- Return applied flag in set_effort response so SDK consumers can detect
  when effort was not applied
- Remove user input from error messages to match handleSetModel convention
- Add unit tests for set_effort, get_available_models, get_usage_info, and
  initialize with effort handlers

* fix(sdk): surface applied flag from setEffort, move effort validation before side effects

- Move effort validation in handleInitialize before MCP servers and
  subagents processing to prevent config-mutating side effects if
  effort is invalid
- Return applied boolean from setEffort/set_effort so SDK consumers can
  detect when effort was a no-op (thinking disabled)
- Fix spread order in handleGetUsageInfo to prevent subtype overwrite
- Update JSDoc to reflect actual behavior
2026-07-11 10:08:12 +00:00
..
test_query_core.py feat(sdk): add control request methods for effort, models, usage, context (#6492) 2026-07-11 10:08:12 +00:00
test_transport.py feat(SDK) Add Python SDK implementation for #3010 (#3494) 2026-04-25 07:02:58 +08:00
test_validation.py feat(sdk): add control request methods for effort, models, usage, context (#6492) 2026-07-11 10:08:12 +00:00