Skip to content

Commit e623f8c

Browse files
committed
Add placeholders for test configuration
1 parent 69cbee7 commit e623f8c

File tree

3 files changed

+77
-16
lines changed

3 files changed

+77
-16
lines changed

test/acceptance_tests.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,17 @@ def _run_mcphost_command(prompt, config_path, model):
9898
return f"UNEXPECTED_ERROR: {str(e)}"
9999

100100

101-
def run_test_case(test_case, config_path, model):
101+
def run_test_case(prompt, config_path, model):
102102
"""Runs a single test case using the mcphost command.
103103
104104
Args:
105-
test_case (dict): The test case dictionary from the JSON file.
105+
prompt (str): The prompt to send to the model.
106106
config_path (str): Path to the mcphost config file.
107107
model (str): The model to use for the test.
108108
109109
Returns:
110110
str: The actual output from the command, or an error message.
111111
"""
112-
prompt = test_case.get("prompt")
113112
if not prompt:
114113
return "Error: 'prompt' not found in test case"
115114
return _run_mcphost_command(prompt, config_path, model)
@@ -162,6 +161,12 @@ def evaluate_test_case(expected, actual, config_path, judge_model):
162161
return "FAIL", f"LLM judge returned malformed JSON: '{judge_response_str}'"
163162

164163

164+
def _substitute_placeholders(text, placeholders):
165+
"""Substitutes placeholders in a string with their values."""
166+
if not isinstance(text, str):
167+
return text
168+
return text.format(**placeholders)
169+
165170
def main():
166171
"""Main function to run acceptance tests."""
167172
parser = argparse.ArgumentParser(
@@ -179,6 +184,12 @@ def main():
179184
default=Path(__file__).parent / "test_results.json",
180185
help="Path to the output JSON file for test results. Defaults to 'test_results.json' in the same directory.",
181186
)
187+
parser.add_argument(
188+
"--test-config",
189+
type=Path,
190+
default=None,
191+
help="Path to the JSON file with test configuration values (for placeholder substitution).",
192+
)
182193
parser.add_argument(
183194
"--config",
184195
type=str,
@@ -207,6 +218,22 @@ def main():
207218
)
208219
sys.exit(1)
209220

221+
placeholders = {}
222+
if args.test_config:
223+
if not args.test_config.is_file():
224+
print(
225+
f"Error: Test config file not found at '{args.test_config}'",
226+
file=sys.stderr,
227+
)
228+
sys.exit(1)
229+
with open(args.test_config, "r", encoding="utf-8") as f:
230+
config_data = json.load(f)
231+
if "systems" in config_data:
232+
for sys_key, sys_values in config_data["systems"].items():
233+
for attr_key, attr_value in sys_values.items():
234+
placeholders[f"{sys_key}_{attr_key}"] = attr_value
235+
print(f"Loaded {len(placeholders)} placeholders from '{args.test_config}'")
236+
210237
judge_model = args.judge_model if args.judge_model else args.model
211238
print(f"Using model for tests: {args.model}")
212239
print(f"Using model for judging: {judge_model}\n")
@@ -225,11 +252,11 @@ def main():
225252
for i, tc in enumerate(test_cases, 1):
226253
test_start_time = time.monotonic()
227254
print(f"--- [{i}/{total_tests}] RUNNING: {Colors.BOLD}{tc.get('id', 'N/A')}{Colors.ENDC} ---")
228-
prompt = tc.get("prompt")
229-
expected_output = tc.get("expected_output")
255+
prompt = _substitute_placeholders(tc.get("prompt"), placeholders)
256+
expected_output = _substitute_placeholders(tc.get("expected_output"), placeholders)
230257

231258
print(f" PROMPT : {prompt}")
232-
actual_output = run_test_case(tc, args.config, args.model)
259+
actual_output = run_test_case(prompt, args.config, args.model)
233260
print(f" EXPECTED: {expected_output}")
234261
print(f" ACTUAL : {actual_output}")
235262

test/test_cases_sys.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
[
22
{
33
"id": "TC-SYS-001",
4-
"prompt": "Can you get the name and system id of of the systems in the uyuni server?",
5-
"expected_output": "The systems in the uyuni server are build-host. deblike-minion. proxy. rhlike-minion. suse-minion. suse-sshminion., with system ids 1000010005 1000010004 1000010000 1000010003 1000010001 1000010002"
4+
"prompt": "Get the name and system id of all systems in the uyuni server.",
5+
"expected_output": "The systems in the uyuni server are {build_host_name}, {deblike_minion_name}, {proxy_name}, {rhlike_minion_name}, {suse_minion_name} and {suse_ssh_minion_name}, with system ids {build_host_id}, {deblike_minion_id}, {proxy_id}, {rhlike_minion_id}, {suse_minion_id} and {suse_ssh_minion_id}."
66
},
77
{
88
"id": "TC-SYS-002",
9-
"prompt": "Get CPU details for system ID 1000010000.",
10-
"expected_output": "Returns a message with CPU attributes with model name AMD EPYC-Milan Processor."
9+
"prompt": "Get CPU details for system ID {proxy_id}.",
10+
"expected_output": "Returns a message with CPU attributes with model name {proxy_cpu_model}."
1111
},
1212
{
1313
"id": "TC-SYS-003",
1414
"prompt": "Get CPU details for system ID 999999999.",
15-
"expected_output": "Returns a message that this system does not exist."
15+
"expected_output": "Returns a message that this system does not exist or an empty dictionary."
1616
},
1717
{
1818
"id": "TC-SYS-004",
1919
"prompt": "Show me the CPU information for all my systems.",
20-
"expected_output": "Returns a message with the CPU information of each system. Except for the proxy., all the rest at QEMU Virtual CPU."
20+
"expected_output": "Returns a message with the CPU information of each system. Except for the proxy ({proxy_cpu_model}), all the rest are {build_host_cpu_model}."
2121
},
2222
{
2323
"id": "TC-SYS-005",
24-
"prompt": "Do all active servers have the same CPU?",
25-
"expected_output": "No. All have QEMU Virtual CPU except proxy."
24+
"prompt": "Do all active servers have the same CPU? Use available tools to answer.",
25+
"expected_output": "No. All have {build_host_cpu_model} except proxy, which has {proxy_cpu_model}."
2626
},
2727
{
2828
"id": "TC-SYS-006",
29-
"prompt": "Get CPU details for system 'build-host.'.",
30-
"expected_output": "Returns a message with CPU attributes of model QEMU Virtual CPU."
29+
"prompt": "Get CPU details for system '{build_host_name}'.",
30+
"expected_output": "Returns a message with CPU attributes of model {build_host_cpu_model}."
3131
}
3232
]

test/test_config.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"systems": {
3+
"proxy": {
4+
"id": "1000010000",
5+
"name": "mlm-ref-head-proxy.mgr.suse.de",
6+
"cpu_model": "AMD EPYC-Milan Processor"
7+
},
8+
"build_host": {
9+
"id": "1000010005",
10+
"name": "mlm-ref-head-build-host.mgr.suse.de",
11+
"cpu_model": "QEMU Virtual CPU"
12+
},
13+
"deblike_minion": {
14+
"id": "1000010004",
15+
"name": "mlm-ref-head-deblike-minion.mgr.suse.de",
16+
"cpu_model": "QEMU Virtual CPU"
17+
},
18+
"rhlike_minion": {
19+
"id": "1000010003",
20+
"name": "mlm-ref-head-rhlike-minion.mgr.suse.de",
21+
"cpu_model": "QEMU Virtual CPU"
22+
},
23+
"suse_minion": {
24+
"id": "1000010001",
25+
"name": "mlm-ref-head-suse-minion.mgr.suse.de",
26+
"cpu_model": "QEMU Virtual CPU"
27+
},
28+
"suse_ssh_minion": {
29+
"id": "1000010002",
30+
"name": "mlm-ref-head-suse-sshminion.mgr.suse.de",
31+
"cpu_model": "QEMU Virtual CPU"
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)