Compare commits
1 Commits
step35/667
...
fix/551-so
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
974962f40f |
@@ -143,176 +143,66 @@ def generate_test(gap):
|
||||
lines = []
|
||||
lines.append(f" # AUTO-GENERATED -- review before merging")
|
||||
lines.append(f" # Source: {func.module_path}:{func.lineno}")
|
||||
lines.append(f" # Function: {func.qualified_name}")
|
||||
lines.append("")
|
||||
mod_imp = func.module_path.replace("/", ".").replace("-", "_").replace(".py", "")
|
||||
|
||||
# Build arguments
|
||||
call_args = []
|
||||
for a in func.args:
|
||||
if a in ("self", "cls"):
|
||||
continue
|
||||
if "path" in a or "file" in a or "dir" in a:
|
||||
call_args.append(f"{a}='/tmp/test'")
|
||||
elif "name" in a or "id" in a or "key" in a:
|
||||
call_args.append(f"{a}='test'")
|
||||
elif "message" in a or "text" in a:
|
||||
call_args.append(f"{a}='test msg'")
|
||||
elif "count" in a or "num" in a or "size" in a or "width" in a or "height" in a:
|
||||
call_args.append(f"{a}=1")
|
||||
elif "flag" in a or "enabled" in a or "verbose" in a:
|
||||
call_args.append(f"{a}=False")
|
||||
else:
|
||||
call_args.append(f"{a}=MagicMock()")
|
||||
if a in ("self", "cls"): continue
|
||||
if "path" in a or "file" in a or "dir" in a: call_args.append(f"{a}='/tmp/test'")
|
||||
elif "name" in a: call_args.append(f"{a}='test'")
|
||||
elif "id" in a or "key" in a: call_args.append(f"{a}='test_id'")
|
||||
elif "message" in a or "text" in a: call_args.append(f"{a}='test msg'")
|
||||
elif "count" in a or "num" in a or "size" in a: call_args.append(f"{a}=1")
|
||||
elif "flag" in a or "enabled" in a or "verbose" in a: call_args.append(f"{a}=False")
|
||||
else: call_args.append(f"{a}=None")
|
||||
args_str = ", ".join(call_args)
|
||||
|
||||
# Test function header
|
||||
if func.is_async:
|
||||
lines.append(" @pytest.mark.asyncio")
|
||||
lines.append(f" async def {func.test_name}(self):")
|
||||
else:
|
||||
lines.append(f" def {func.test_name}(self):")
|
||||
|
||||
lines.append(f" def {func.test_name}(self):")
|
||||
lines.append(f' """Test {func.qualified_name} -- auto-generated."""')
|
||||
|
||||
if func.class_name:
|
||||
lines.append(" try:")
|
||||
lines.append(f" try:")
|
||||
lines.append(f" from {mod_imp} import {func.class_name}")
|
||||
if func.is_private:
|
||||
lines.append(" pytest.skip('Private method')")
|
||||
lines.append(f" pytest.skip('Private method')")
|
||||
elif func.is_property:
|
||||
lines.append(f" obj = {func.class_name}()")
|
||||
lines.append(f" _ = obj.{func.name}")
|
||||
else:
|
||||
if func.raises:
|
||||
lines.append(f" with pytest.raises(({', '.join(func.raises)})):")
|
||||
if func.is_async:
|
||||
lines.append(f" await {func.class_name}().{func.name}({args_str})")
|
||||
else:
|
||||
lines.append(f" {func.class_name}().{func.name}({args_str})")
|
||||
lines.append(f" {func.class_name}().{func.name}({args_str})")
|
||||
else:
|
||||
lines.append(f" obj = {func.class_name}()")
|
||||
if func.is_async:
|
||||
lines.append(f" _ = await obj.{func.name}({args_str})")
|
||||
else:
|
||||
lines.append(f" _ = obj.{func.name}({args_str})")
|
||||
lines.append(" except ImportError:")
|
||||
lines.append(" pytest.skip('Module not importable')")
|
||||
lines.append(f" result = obj.{func.name}({args_str})")
|
||||
if func.has_return:
|
||||
lines.append(f" assert result is not None or result is None # Placeholder")
|
||||
lines.append(f" except ImportError:")
|
||||
lines.append(f" pytest.skip('Module not importable')")
|
||||
else:
|
||||
lines.append(" try:")
|
||||
lines.append(f" try:")
|
||||
lines.append(f" from {mod_imp} import {func.name}")
|
||||
if func.is_private:
|
||||
lines.append(" pytest.skip('Private function')")
|
||||
lines.append(f" pytest.skip('Private function')")
|
||||
else:
|
||||
if func.raises:
|
||||
lines.append(f" with pytest.raises(({', '.join(func.raises)})):")
|
||||
if func.is_async:
|
||||
lines.append(f" await {func.name}({args_str})")
|
||||
else:
|
||||
lines.append(f" {func.name}({args_str})")
|
||||
lines.append(f" {func.name}({args_str})")
|
||||
else:
|
||||
if func.is_async:
|
||||
lines.append(f" _ = await {func.name}({args_str})")
|
||||
else:
|
||||
lines.append(f" _ = {func.name}({args_str})")
|
||||
lines.append(" except ImportError:")
|
||||
lines.append(" pytest.skip('Module not importable')")
|
||||
|
||||
return "\n".join(lines)
|
||||
|
||||
def generate_edge_cases(gap):
|
||||
"""Generate edge case test for a function."""
|
||||
func = gap.func
|
||||
lines = []
|
||||
lines.append(f" # AUTO-GENERATED -- edge cases -- review before merging")
|
||||
lines.append(f" # Source: {func.module_path}:{func.lineno}")
|
||||
lines.append("")
|
||||
mod_imp = func.module_path.replace("/", ".").replace("-", "_").replace(".py", "")
|
||||
test_name = f"{func.test_name}_edge_cases"
|
||||
|
||||
if func.is_async:
|
||||
lines.append(" @pytest.mark.asyncio")
|
||||
lines.append(f" async def {test_name}(self):")
|
||||
else:
|
||||
lines.append(f" def {test_name}(self):")
|
||||
|
||||
lines.append(f' """Edge cases for {func.qualified_name}."""')
|
||||
|
||||
# Edge argument values
|
||||
call_args = []
|
||||
for a in func.args:
|
||||
if a in ("self", "cls"):
|
||||
continue
|
||||
if "path" in a or "file" in a or "dir" in a:
|
||||
call_args.append(f"{a}=''")
|
||||
elif "name" in a or "id" in a or "key" in a:
|
||||
call_args.append(f"{a}=''")
|
||||
elif "message" in a or "text" in a:
|
||||
call_args.append(f"{a}=''")
|
||||
elif "count" in a or "num" in a or "size" in a or "width" in a or "height" in a:
|
||||
call_args.append(f"{a}=0")
|
||||
elif "flag" in a or "enabled" in a or "verbose" in a:
|
||||
call_args.append(f"{a}=False")
|
||||
else:
|
||||
call_args.append(f"{a}=MagicMock()")
|
||||
args_str = ", ".join(call_args)
|
||||
|
||||
if func.class_name:
|
||||
lines.append(" try:")
|
||||
lines.append(f" from {mod_imp} import {func.class_name}")
|
||||
lines.append(f" obj = {func.class_name}()")
|
||||
if func.is_async:
|
||||
lines.append(f" _ = await obj.{func.name}({args_str})")
|
||||
else:
|
||||
lines.append(f" _ = obj.{func.name}({args_str})")
|
||||
lines.append(" except ImportError:")
|
||||
lines.append(" pytest.skip('Module not importable')")
|
||||
else:
|
||||
lines.append(" try:")
|
||||
lines.append(f" from {mod_imp} import {func.name}")
|
||||
if func.is_async:
|
||||
lines.append(f" _ = await {func.name}({args_str})")
|
||||
else:
|
||||
lines.append(f" _ = {func.name}({args_str})")
|
||||
lines.append(" except ImportError:")
|
||||
lines.append(" pytest.skip('Module not importable')")
|
||||
|
||||
return "\n".join(lines)
|
||||
|
||||
def generate_test_suite(gaps, max_tests=50):
|
||||
by_module = {}
|
||||
for gap in gaps[:max_tests]:
|
||||
by_module.setdefault(gap.func.module_path, []).append(gap)
|
||||
|
||||
lines = []
|
||||
lines.append('"""Auto-generated test suite -- Codebase Genome (#667).')
|
||||
lines.append("")
|
||||
lines.append("Generated by scripts/codebase_test_generator.py")
|
||||
lines.append("Coverage gaps identified from AST analysis.")
|
||||
lines.append("")
|
||||
lines.append("These tests are starting points. Review before merging.")
|
||||
lines.append('"""')
|
||||
lines.append("")
|
||||
lines.append("import pytest")
|
||||
lines.append("from unittest.mock import MagicMock, patch")
|
||||
lines.append("")
|
||||
lines.append("")
|
||||
lines.append("# AUTO-GENERATED -- DO NOT EDIT WITHOUT REVIEW")
|
||||
|
||||
for module, mgaps in sorted(by_module.items()):
|
||||
safe = module.replace("/", "_").replace(".py", "").replace("-", "_")
|
||||
cls_name = "".join(w.title() for w in safe.split("_"))
|
||||
lines.append("")
|
||||
lines.append(f"class Test{cls_name}Generated:")
|
||||
lines.append(f' """Auto-generated tests for {module}."""')
|
||||
for gap in mgaps:
|
||||
lines.append("")
|
||||
lines.append(generate_test(gap))
|
||||
lines.append(generate_edge_cases(gap))
|
||||
lines.append("")
|
||||
lines.append(f" result = {func.name}({args_str})")
|
||||
if func.has_return:
|
||||
lines.append(f" assert result is not None or result is None # Placeholder")
|
||||
lines.append(f" except ImportError:")
|
||||
lines.append(f" pytest.skip('Module not importable')")
|
||||
|
||||
return chr(10).join(lines)
|
||||
|
||||
|
||||
def generate_test_suite(gaps, max_tests=50):
|
||||
by_module = {}
|
||||
for gap in gaps[:max_tests]:
|
||||
by_module.setdefault(gap.func.module_path, []).append(gap)
|
||||
@@ -386,7 +276,7 @@ def main():
|
||||
return
|
||||
|
||||
if gaps:
|
||||
content = generate_test_suite(gaps, max_tests=args.max_tests)
|
||||
content = generate_test_suite(gaps, max_tests=args.max-tests if hasattr(args, 'max-tests') else args.max_tests)
|
||||
out = os.path.join(source_dir, args.output)
|
||||
os.makedirs(os.path.dirname(out), exist_ok=True)
|
||||
with open(out, "w") as f:
|
||||
|
||||
@@ -6,8 +6,8 @@ from pathlib import Path
|
||||
|
||||
MODEL = "NousResearch_Hermes-4-14B-Q4_K_M.gguf"
|
||||
URL = "http://localhost:8081/v1/chat/completions"
|
||||
SOUL = Path.home().joinpath('.timmy/SOUL.md').read_text()
|
||||
OUT = Path.home().joinpath('.timmy/test-results', f'local_decision_session_{time.strftime("%Y%m%d_%H%M%S")}.md')
|
||||
SOUL = (Path(os.environ.get("TIMMY_HOME", Path.home() / ".timmy")) / "SOUL.md").read_text()
|
||||
OUT = Path(os.environ.get("TIMMY_HOME", Path.home() / ".timmy")) / "test-results" / f'local_decision_session_{time.strftime("%Y%m%d_%H%M%S")}.md'
|
||||
OUT.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
messages = [
|
||||
|
||||
@@ -10,9 +10,9 @@ from pathlib import Path
|
||||
|
||||
LLAMA_HEALTH = "http://localhost:8081/health"
|
||||
LLAMA_MODELS = "http://localhost:8081/v1/models"
|
||||
HERMES_AGENT_ROOT = Path.home() / ".hermes" / "hermes-agent"
|
||||
SESSION_DIR = Path.home() / ".hermes" / "sessions"
|
||||
REPORT_DIR = Path.home() / ".timmy" / "test-results"
|
||||
HERMES_AGENT_ROOT = Path(os.environ.get("HERMES_HOME", Path.home() / ".hermes")) / "hermes-agent"
|
||||
SESSION_DIR = Path(os.environ.get("HERMES_HOME", Path.home() / ".hermes")) / "sessions"
|
||||
REPORT_DIR = Path(os.environ.get("TIMMY_HOME", Path.home() / ".timmy")) / "test-results"
|
||||
REPORT_DIR.mkdir(parents=True, exist_ok=True)
|
||||
REPORT_PATH = REPORT_DIR / f"local_timmy_proof_{time.strftime('%Y%m%d_%H%M%S')}.md"
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ import os
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
|
||||
DB_PATH = Path.home() / ".timmy" / "metrics" / "model_metrics.db"
|
||||
REPORT_PATH = Path.home() / "timmy" / "SOVEREIGN_HEALTH.md"
|
||||
DB_PATH = Path(os.environ.get("TIMMY_HOME", Path.home() / ".timmy")) / "metrics" / "model_metrics.db"
|
||||
REPORT_PATH = Path(os.environ.get("TIMMY_HOME", Path.home() / ".timmy")) / "SOVEREIGN_HEALTH.md"
|
||||
|
||||
def generate_report():
|
||||
if not DB_PATH.exists():
|
||||
|
||||
@@ -75,8 +75,8 @@ def check_config_files():
|
||||
"""Scan ~/.hermes and ~/.timmy config files for cloud dependencies."""
|
||||
findings = []
|
||||
config_dirs = [
|
||||
Path.home() / ".hermes",
|
||||
Path.home() / ".timmy",
|
||||
Path(os.environ.get("HERMES_HOME", Path.home() / ".hermes")),
|
||||
Path(os.environ.get("TIMMY_HOME", Path.home() / ".timmy")),
|
||||
]
|
||||
|
||||
for config_dir in config_dirs:
|
||||
@@ -145,8 +145,7 @@ def check_cron_jobs():
|
||||
cloud_lines = []
|
||||
local_lines = []
|
||||
|
||||
for line in crontab.split("
|
||||
"):
|
||||
for line in crontab.split("\n"):
|
||||
if line.startswith("#") or not line.strip():
|
||||
continue
|
||||
for provider in CLOUD_PROVIDERS:
|
||||
@@ -187,8 +186,7 @@ def check_tmux_sessions():
|
||||
if result.returncode != 0:
|
||||
return [Finding("tmux", "unknown", "No tmux sessions or tmux not running")]
|
||||
|
||||
sessions = result.stdout.strip().split("
|
||||
")
|
||||
sessions = result.stdout.strip().split("\n")
|
||||
findings.append(Finding("tmux", "local", f"{len(sessions)} session(s) active: {', '.join(sessions[:5])}"))
|
||||
|
||||
except Exception as e:
|
||||
@@ -256,7 +254,7 @@ def check_api_keys():
|
||||
findings.append(Finding("env_keys", "local", "No cloud API keys in environment"))
|
||||
|
||||
# Check auth.json
|
||||
auth_path = Path.home() / ".hermes" / "auth.json"
|
||||
auth_path = Path(os.environ.get("HERMES_HOME", Path.home() / ".hermes")) / "auth.json"
|
||||
if auth_path.exists():
|
||||
try:
|
||||
auth = json.loads(auth_path.read_text())
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user