Download tests/test_harness.py from hermescures1/splitbit-llm: direct link, hf CLI and curl.
- Browser
- Download file 3.08 kB
-
https://huggingface.co/hermescures1/splitbit-llm/resolve/main/tests/test_harness.py
- Command line
-
hf download hf://hermescures1/splitbit-llm/tests/test_harness.py
-
curl -L -o test_harness.py https://huggingface.co/hermescures1/splitbit-llm/resolve/main/tests/test_harness.py
3.08 kB
| """Test harness: chat, tools, skills, stats.""" | |
| import sys | |
| import os | |
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) | |
| from splitbit_llm.harness.harness import SplitBitHarness | |
| from splitbit_llm.harness.tools import ToolRegistry, get_default_tools, tool_loop, parse_tool_calls | |
| def test_harness_chat(): | |
| """Test harness chat functionality.""" | |
| harness = SplitBitHarness() | |
| result = harness.chat("Hello there", channel="cli") | |
| assert "response" in result, "No response in result" | |
| assert "elapsed_s" in result, "No elapsed time" | |
| assert "stats" in result, "No stats" | |
| print(f" Response: {result['response'][:60]}") | |
| print(f" Elapsed: {result['elapsed_s']}s") | |
| def test_harness_stats(): | |
| """Test harness stats aggregation.""" | |
| harness = SplitBitHarness() | |
| stats = harness.get_stats() | |
| assert "model" in stats, "No model stats" | |
| assert "skills" in stats, "No skills stats" | |
| assert "recursive_links" in stats, "No link stats" | |
| assert "auto_sizer" in stats, "No auto_sizer stats" | |
| print(f" Model params: {stats['model']['param_count']:,}") | |
| print(f" Tier: {stats['auto_sizer']['tier']}") | |
| def test_tool_registry(): | |
| """Test tool registry and execution.""" | |
| registry = ToolRegistry() | |
| for tool in get_default_tools(): | |
| registry.register(tool) | |
| assert len(registry.list_tools()) == 9, f"Wrong tool count: {len(registry.list_tools())}" | |
| print(f" Tools: {len(registry.list_tools())}") | |
| # Test calculate tool | |
| result = registry.execute("calculate", "2 + 2") | |
| assert result.success, f"Calculate failed: {result.error}" | |
| assert "4" in result.output, f"Wrong result: {result.output}" | |
| print(f" calculate(2+2) = {result.output}") | |
| def test_tool_loop(): | |
| """Test tool execution loop.""" | |
| registry = ToolRegistry() | |
| for tool in get_default_tools(): | |
| registry.register(tool) | |
| text = "Let me calculate: [TOOL: calculate(3 * 7)]" | |
| final_text, results = tool_loop(text, registry) | |
| assert len(results) == 1, f"Expected 1 result, got {len(results)}" | |
| assert results[0].success, "Tool execution failed" | |
| assert "21" in results[0].output, f"Wrong output: {results[0].output}" | |
| print(f" Tool loop: {len(results)} calls, output: {results[0].output}") | |
| def test_parse_tool_calls(): | |
| """Test parsing tool calls from text.""" | |
| text = "I will [TOOL: calculate(1 + 1)] and then [TOOL: calculate(2 + 2)]" | |
| calls = parse_tool_calls(text) | |
| assert len(calls) == 2, f"Expected 2 calls, got {len(calls)}" | |
| assert calls[0][0] == "calculate", f"Wrong tool name: {calls[0][0]}" | |
| print(f" Parsed {len(calls)} tool calls") | |
| if __name__ == "__main__": | |
| print("Running harness tests...") | |
| test_harness_chat() | |
| print(" ✓ test_harness_chat") | |
| test_harness_stats() | |
| print(" ✓ test_harness_stats") | |
| test_tool_registry() | |
| print(" ✓ test_tool_registry") | |
| test_tool_loop() | |
| print(" ✓ test_tool_loop") | |
| test_parse_tool_calls() | |
| print(" ✓ test_parse_tool_calls") | |
| print("\nAll harness tests passed!") | |