104 lines
2.9 KiB
Python
104 lines
2.9 KiB
Python
import pytest
|
|
import time
|
|
import tomli_w
|
|
import os
|
|
import json
|
|
from pathlib import Path
|
|
from src.api_hook_client import ApiHookClient
|
|
|
|
def test_preset_switching(live_gui):
|
|
client = ApiHookClient()
|
|
|
|
# Paths for presets
|
|
temp_workspace = Path("tests/artifacts/live_gui_workspace")
|
|
global_presets_path = temp_workspace / "presets.toml"
|
|
project_presets_path = temp_workspace / "project_presets.toml"
|
|
manual_slop_path = temp_workspace / "manual_slop.toml"
|
|
|
|
# Cleanup before test
|
|
if global_presets_path.exists(): global_presets_path.unlink()
|
|
if project_presets_path.exists(): project_presets_path.unlink()
|
|
|
|
try:
|
|
# Create a global preset
|
|
global_presets_path.write_text(tomli_w.dumps({
|
|
"presets": {
|
|
"TestGlobal": {
|
|
"system_prompt": "Global Prompt",
|
|
"temperature": 0.7
|
|
}
|
|
}
|
|
}))
|
|
|
|
# Create a project preset
|
|
project_presets_path.write_text(tomli_w.dumps({
|
|
"presets": {
|
|
"TestProject": {
|
|
"system_prompt": "Project Prompt",
|
|
"temperature": 0.3
|
|
},
|
|
"TestGlobal": { # Override
|
|
"system_prompt": "Overridden Prompt",
|
|
"temperature": 0.5
|
|
}
|
|
}
|
|
}))
|
|
|
|
# Switch to the local project to ensure context is correct
|
|
client.push_event("custom_callback", {
|
|
"callback": "_switch_project",
|
|
"args": [str(manual_slop_path.absolute())]
|
|
})
|
|
time.sleep(2)
|
|
|
|
# Trigger reload of presets (just in case)
|
|
client.push_event("custom_callback", {
|
|
"callback": "_refresh_from_project",
|
|
"args": []
|
|
})
|
|
time.sleep(2) # Wait for processing
|
|
|
|
# Verify where it thinks the project is
|
|
state = client.get_gui_state()
|
|
print(f"DEBUG: ui_files_base_dir={state.get('files_base_dir')}")
|
|
|
|
# Apply Global Preset (should use override from project if available in merged list)
|
|
client.push_event("custom_callback", {
|
|
"callback": "_apply_preset",
|
|
"args": ["TestGlobal", "global"]
|
|
})
|
|
time.sleep(1)
|
|
|
|
# Verify state
|
|
state = client.get_gui_state()
|
|
assert state["global_preset_name"] == "TestGlobal"
|
|
assert state["global_system_prompt"] == "Overridden Prompt"
|
|
assert state["temperature"] == 0.5
|
|
|
|
# Apply Project Preset
|
|
client.push_event("custom_callback", {
|
|
"callback": "_apply_preset",
|
|
"args": ["TestProject", "project"]
|
|
})
|
|
time.sleep(1)
|
|
|
|
state = client.get_gui_state()
|
|
assert state["project_preset_name"] == "TestProject"
|
|
assert state["project_system_prompt"] == "Project Prompt"
|
|
assert state["temperature"] == 0.3
|
|
# Select "None"
|
|
client.push_event("custom_callback", {
|
|
"callback": "_apply_preset",
|
|
"args": ["None", "global"]
|
|
})
|
|
time.sleep(1)
|
|
state = client.get_gui_state()
|
|
assert not state.get("global_preset_name") # Should be None or ""
|
|
|
|
# Prompt remains from previous application
|
|
assert state["global_system_prompt"] == "Overridden Prompt"
|
|
finally:
|
|
# Cleanup
|
|
if global_presets_path.exists(): global_presets_path.unlink()
|
|
if project_presets_path.exists(): project_presets_path.unlink()
|