Skip to content

Commit bbef5b9

Browse files
Sodawyxclaude
andcommitted
fix(agent_runtime): use effective config for workspace name resolution
PR #102 Copilot review surfaced two issues in the new workspace_name resolution path: 1. workspace_name resolution only used the method-level `config`, ignoring `self.config`. When a caller built `AgentRuntimeClient(config=...)` and then called `create(input)` without a method-level config, the resolver fell back to env credentials/region while the subsequent OpenAPI call used `self.config` — possibly resolving a workspace under the wrong account/region. Now passes `Config.with_configs(self.config, config)` to the resolver, matching the merge done in `ControlAPI._get_client`. 2. `if input.workspace_name:` silently skipped resolution for empty strings instead of surfacing the resolver's existing `ValueError("workspace_name must be non-empty")`. Switched the singular checks to `is not None` so empty strings now raise. Applied to create / create_async / list / list_async in client.py and mirrored into the codegen template. Plural `workspace_names` keeps the truthy check since empty-string plural is a benign "no filter". Added 8 unit tests covering effective-config propagation (client.config used when method config=None; method config overrides client.config) and empty-string ValueError across all four entry points. agent_runtime suite 262 passed / 2 skipped; `_workspace.py` 95.24% line/branch. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: Sodawyx <sodawyx@126.com>
1 parent 6cc91e1 commit bbef5b9

3 files changed

Lines changed: 302 additions & 44 deletions

File tree

agentrun/agent_runtime/__client_async_template.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@ async def create_async(
8888
"workspace_id and workspace_name are mutually exclusive; please"
8989
" only set one of them."
9090
)
91-
if input.workspace_name:
91+
if input.workspace_name is not None:
92+
cfg = Config.with_configs(self.config, config)
9293
input.workspace_id = await resolve_workspace_id_by_name_async(
93-
input.workspace_name, config
94+
input.workspace_name, cfg
9495
)
9596
input.workspace_name = None
9697

@@ -241,18 +242,22 @@ async def list_async(
241242
"workspace_ids and workspace_names are mutually exclusive;"
242243
" please only set one of them."
243244
)
244-
if input.workspace_name:
245-
input.workspace_id = await resolve_workspace_id_by_name_async(
246-
input.workspace_name, config
247-
)
248-
input.workspace_name = None
249-
if input.workspace_names:
250-
input.workspace_ids = (
251-
await resolve_workspace_ids_by_names_async(
252-
input.workspace_names, config
245+
if input.workspace_name is not None or input.workspace_names:
246+
cfg = Config.with_configs(self.config, config)
247+
if input.workspace_name is not None:
248+
input.workspace_id = (
249+
await resolve_workspace_id_by_name_async(
250+
input.workspace_name, cfg
251+
)
253252
)
254-
)
255-
input.workspace_names = None
253+
input.workspace_name = None
254+
if input.workspace_names:
255+
input.workspace_ids = (
256+
await resolve_workspace_ids_by_names_async(
257+
input.workspace_names, cfg
258+
)
259+
)
260+
input.workspace_names = None
256261

257262
results = await self.__control_api.list_agent_runtimes_async(
258263
ListAgentRuntimesRequest().from_map(input.model_dump()),

agentrun/agent_runtime/client.py

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ async def create_async(
9898
"workspace_id and workspace_name are mutually exclusive; please"
9999
" only set one of them."
100100
)
101-
if input.workspace_name:
101+
if input.workspace_name is not None:
102+
cfg = Config.with_configs(self.config, config)
102103
input.workspace_id = await resolve_workspace_id_by_name_async(
103-
input.workspace_name, config
104+
input.workspace_name, cfg
104105
)
105106
input.workspace_name = None
106107

@@ -156,9 +157,10 @@ def create(
156157
"workspace_id and workspace_name are mutually exclusive; please"
157158
" only set one of them."
158159
)
159-
if input.workspace_name:
160+
if input.workspace_name is not None:
161+
cfg = Config.with_configs(self.config, config)
160162
input.workspace_id = resolve_workspace_id_by_name(
161-
input.workspace_name, config
163+
input.workspace_name, cfg
162164
)
163165
input.workspace_name = None
164166

@@ -390,18 +392,22 @@ async def list_async(
390392
"workspace_ids and workspace_names are mutually exclusive;"
391393
" please only set one of them."
392394
)
393-
if input.workspace_name:
394-
input.workspace_id = await resolve_workspace_id_by_name_async(
395-
input.workspace_name, config
396-
)
397-
input.workspace_name = None
398-
if input.workspace_names:
399-
input.workspace_ids = (
400-
await resolve_workspace_ids_by_names_async(
401-
input.workspace_names, config
395+
if input.workspace_name is not None or input.workspace_names:
396+
cfg = Config.with_configs(self.config, config)
397+
if input.workspace_name is not None:
398+
input.workspace_id = (
399+
await resolve_workspace_id_by_name_async(
400+
input.workspace_name, cfg
401+
)
402402
)
403-
)
404-
input.workspace_names = None
403+
input.workspace_name = None
404+
if input.workspace_names:
405+
input.workspace_ids = (
406+
await resolve_workspace_ids_by_names_async(
407+
input.workspace_names, cfg
408+
)
409+
)
410+
input.workspace_names = None
405411

406412
results = await self.__control_api.list_agent_runtimes_async(
407413
ListAgentRuntimesRequest().from_map(input.model_dump()),
@@ -450,16 +456,18 @@ def list(
450456
"workspace_ids and workspace_names are mutually exclusive;"
451457
" please only set one of them."
452458
)
453-
if input.workspace_name:
454-
input.workspace_id = resolve_workspace_id_by_name(
455-
input.workspace_name, config
456-
)
457-
input.workspace_name = None
458-
if input.workspace_names:
459-
input.workspace_ids = resolve_workspace_ids_by_names(
460-
input.workspace_names, config
461-
)
462-
input.workspace_names = None
459+
if input.workspace_name is not None or input.workspace_names:
460+
cfg = Config.with_configs(self.config, config)
461+
if input.workspace_name is not None:
462+
input.workspace_id = resolve_workspace_id_by_name(
463+
input.workspace_name, cfg
464+
)
465+
input.workspace_name = None
466+
if input.workspace_names:
467+
input.workspace_ids = resolve_workspace_ids_by_names(
468+
input.workspace_names, cfg
469+
)
470+
input.workspace_names = None
463471

464472
results = self.__control_api.list_agent_runtimes(
465473
ListAgentRuntimesRequest().from_map(input.model_dump()),

0 commit comments

Comments
 (0)