Skip to content

Commit 6fa3f5f

Browse files
CopilotBukeLy
andcommitted
chore: address review feedback
Co-authored-by: BukeLy <19304666+BukeLy@users.noreply.github.com>
1 parent dff0f7b commit 6fa3f5f

2 files changed

Lines changed: 18 additions & 15 deletions

File tree

agent-sdk-client/config.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ def extract_command(text: Optional[str]) -> Optional[str]:
1919
if not trimmed.startswith('/'):
2020
return None
2121

22-
parts = trimmed.split()
23-
if not parts:
24-
return None
25-
26-
command = parts[0]
22+
command = trimmed.split()[0]
2723
if '@' in command:
2824
command = command.split('@', 1)[0]
2925
if not command:
@@ -40,11 +36,14 @@ def load_command_whitelist(config_path: Path = DEFAULT_CONFIG_PATH) -> list[str]
4036
with config_path.open('rb') as f:
4137
data = tomllib.load(f)
4238
whitelist = data.get('white_list_commands', {}).get('whitelist', [])
43-
if isinstance(whitelist, list):
44-
commands = [cmd for cmd in whitelist if isinstance(cmd, str)]
45-
if len(commands) != len(whitelist):
46-
logger.warning("Ignoring non-string entries in command whitelist")
47-
return commands
39+
if not isinstance(whitelist, list):
40+
logger.warning("Command whitelist is not a list; ignoring configuration")
41+
return []
42+
43+
commands = [cmd for cmd in whitelist if isinstance(cmd, str)]
44+
if len(commands) != len(whitelist):
45+
logger.warning("Ignoring non-string entries in command whitelist")
46+
return commands
4847
except (OSError, tomllib.TOMLDecodeError) as exc: # pragma: no cover - defensive logging
4948
logger.warning("Failed to load command whitelist: %s", exc)
5049
return []

tests/test_command_whitelist.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
import sys
1+
import importlib.util
22
from pathlib import Path
33

44
import pytest
55

6-
CLIENT_DIR = Path(__file__).resolve().parent.parent / "agent-sdk-client"
7-
if str(CLIENT_DIR) not in sys.path:
8-
sys.path.append(str(CLIENT_DIR))
6+
CLIENT_CONFIG_PATH = Path(__file__).resolve().parent.parent / "agent-sdk-client" / "config.py"
97

10-
from config import Config, load_command_whitelist # noqa: E402
8+
spec = importlib.util.spec_from_file_location("client_config", CLIENT_CONFIG_PATH)
9+
config_module = importlib.util.module_from_spec(spec)
10+
assert spec and spec.loader
11+
spec.loader.exec_module(config_module)
12+
13+
Config = config_module.Config
14+
load_command_whitelist = config_module.load_command_whitelist
1115

1216

1317
def test_load_command_whitelist(tmp_path):

0 commit comments

Comments
 (0)