File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 []
Original file line number Diff line number Diff line change 1- import sys
1+ import importlib . util
22from pathlib import Path
33
44import 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
1317def test_load_command_whitelist (tmp_path ):
You can’t perform that action at this time.
0 commit comments