Compare commits
1 Commits
fix/673
...
burn/667-1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3b273f1345 |
290
scripts/codebase_test_generator.py
Executable file
290
scripts/codebase_test_generator.py
Executable file
@@ -0,0 +1,290 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Codebase Test Generator — Fill Coverage Gaps (#667)."""
|
||||
|
||||
import ast
|
||||
import os
|
||||
import sys
|
||||
import argparse
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
from typing import Dict, List, Optional, Set, Tuple
|
||||
|
||||
|
||||
@dataclass
|
||||
class FunctionInfo:
|
||||
name: str
|
||||
module_path: str
|
||||
class_name: Optional[str] = None
|
||||
lineno: int = 0
|
||||
args: List[str] = field(default_factory=list)
|
||||
is_async: bool = False
|
||||
is_private: bool = False
|
||||
is_property: bool = False
|
||||
docstring: Optional[str] = None
|
||||
has_return: bool = False
|
||||
raises: List[str] = field(default_factory=list)
|
||||
decorators: List[str] = field(default_factory=list)
|
||||
|
||||
@property
|
||||
def qualified_name(self):
|
||||
if self.class_name:
|
||||
return f"{self.class_name}.{self.name}"
|
||||
return self.name
|
||||
|
||||
@property
|
||||
def test_name(self):
|
||||
safe_mod = self.module_path.replace("/", "_").replace(".py", "").replace("-", "_")
|
||||
safe_cls = self.class_name + "_" if self.class_name else ""
|
||||
return f"test_{safe_mod}_{safe_cls}{self.name}"
|
||||
|
||||
|
||||
@dataclass
|
||||
class CoverageGap:
|
||||
func: FunctionInfo
|
||||
reason: str
|
||||
test_priority: int
|
||||
|
||||
|
||||
class SourceAnalyzer(ast.NodeVisitor):
|
||||
def __init__(self, module_path: str):
|
||||
self.module_path = module_path
|
||||
self.functions: List[FunctionInfo] = []
|
||||
self._class_stack: List[str] = []
|
||||
|
||||
def visit_ClassDef(self, node):
|
||||
self._class_stack.append(node.name)
|
||||
self.generic_visit(node)
|
||||
self._class_stack.pop()
|
||||
|
||||
def visit_FunctionDef(self, node):
|
||||
self._collect(node, False)
|
||||
self.generic_visit(node)
|
||||
|
||||
def visit_AsyncFunctionDef(self, node):
|
||||
self._collect(node, True)
|
||||
self.generic_visit(node)
|
||||
|
||||
def _collect(self, node, is_async):
|
||||
cls = self._class_stack[-1] if self._class_stack else None
|
||||
args = [a.arg for a in node.args.args if a.arg not in ("self", "cls")]
|
||||
has_ret = any(isinstance(c, ast.Return) and c.value for c in ast.walk(node))
|
||||
raises = []
|
||||
for c in ast.walk(node):
|
||||
if isinstance(c, ast.Raise) and c.exc:
|
||||
if isinstance(c.exc, ast.Call) and isinstance(c.exc.func, ast.Name):
|
||||
raises.append(c.exc.func.id)
|
||||
decos = []
|
||||
for d in node.decorator_list:
|
||||
if isinstance(d, ast.Name): decos.append(d.id)
|
||||
elif isinstance(d, ast.Attribute): decos.append(d.attr)
|
||||
self.functions.append(FunctionInfo(
|
||||
name=node.name, module_path=self.module_path, class_name=cls,
|
||||
lineno=node.lineno, args=args, is_async=is_async,
|
||||
is_private=node.name.startswith("_") and not node.name.startswith("__"),
|
||||
is_property="property" in decos,
|
||||
docstring=ast.get_docstring(node), has_return=has_ret,
|
||||
raises=raises, decorators=decos))
|
||||
|
||||
|
||||
def analyze_file(filepath, base_dir):
|
||||
module_path = os.path.relpath(filepath, base_dir)
|
||||
try:
|
||||
with open(filepath, "r", errors="replace") as f:
|
||||
tree = ast.parse(f.read(), filename=filepath)
|
||||
except (SyntaxError, UnicodeDecodeError):
|
||||
return []
|
||||
a = SourceAnalyzer(module_path)
|
||||
a.visit(tree)
|
||||
return a.functions
|
||||
|
||||
|
||||
def find_source_files(source_dir):
|
||||
exclude = {"__pycache__", ".git", "venv", ".venv", "node_modules", ".tox", "build", "dist"}
|
||||
files = []
|
||||
for root, dirs, fs in os.walk(source_dir):
|
||||
dirs[:] = [d for d in dirs if d not in exclude and not d.startswith(".")]
|
||||
for f in fs:
|
||||
if f.endswith(".py") and f != "__init__.py" and not f.startswith("test_"):
|
||||
files.append(os.path.join(root, f))
|
||||
return sorted(files)
|
||||
|
||||
|
||||
def find_existing_tests(test_dir):
|
||||
existing = set()
|
||||
for root, dirs, fs in os.walk(test_dir):
|
||||
for f in fs:
|
||||
if f.startswith("test_") and f.endswith(".py"):
|
||||
try:
|
||||
with open(os.path.join(root, f)) as fh:
|
||||
tree = ast.parse(fh.read())
|
||||
for node in ast.walk(tree):
|
||||
if isinstance(node, ast.FunctionDef) and node.name.startswith("test_"):
|
||||
existing.add(node.name)
|
||||
except (SyntaxError, UnicodeDecodeError):
|
||||
pass
|
||||
return existing
|
||||
|
||||
|
||||
def identify_gaps(functions, existing_tests):
|
||||
gaps = []
|
||||
for func in functions:
|
||||
if func.name.startswith("__") and func.name != "__init__":
|
||||
continue
|
||||
covered = func.name in str(existing_tests)
|
||||
if not covered:
|
||||
pri = 3 if func.is_private else (1 if (func.raises or func.has_return) else 2)
|
||||
gaps.append(CoverageGap(func=func, reason="no test found", test_priority=pri))
|
||||
gaps.sort(key=lambda g: (g.test_priority, g.func.module_path, g.func.name))
|
||||
return gaps
|
||||
|
||||
|
||||
def generate_test(gap):
|
||||
func = gap.func
|
||||
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", "")
|
||||
|
||||
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: 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)
|
||||
|
||||
if func.is_async:
|
||||
lines.append(" @pytest.mark.asyncio")
|
||||
lines.append(f" def {func.test_name}(self):")
|
||||
lines.append(f' """Test {func.qualified_name} -- auto-generated."""')
|
||||
|
||||
if func.class_name:
|
||||
lines.append(f" try:")
|
||||
lines.append(f" from {mod_imp} import {func.class_name}")
|
||||
if func.is_private:
|
||||
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)})):")
|
||||
lines.append(f" {func.class_name}().{func.name}({args_str})")
|
||||
else:
|
||||
lines.append(f" obj = {func.class_name}()")
|
||||
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(f" try:")
|
||||
lines.append(f" from {mod_imp} import {func.name}")
|
||||
if func.is_private:
|
||||
lines.append(f" pytest.skip('Private function')")
|
||||
else:
|
||||
if func.raises:
|
||||
lines.append(f" with pytest.raises(({', '.join(func.raises)})):")
|
||||
lines.append(f" {func.name}({args_str})")
|
||||
else:
|
||||
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)
|
||||
|
||||
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("")
|
||||
|
||||
return chr(10).join(lines)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Codebase Test Generator")
|
||||
parser.add_argument("--source", default=".")
|
||||
parser.add_argument("--output", default="tests/test_genome_generated.py")
|
||||
parser.add_argument("--max-tests", type=int, default=50)
|
||||
parser.add_argument("--dry-run", action="store_true")
|
||||
parser.add_argument("--include-private", action="store_true")
|
||||
args = parser.parse_args()
|
||||
|
||||
source_dir = os.path.abspath(args.source)
|
||||
test_dir = os.path.join(source_dir, "tests")
|
||||
|
||||
print(f"Scanning: {source_dir}")
|
||||
source_files = find_source_files(source_dir)
|
||||
print(f"Source files: {len(source_files)}")
|
||||
|
||||
all_funcs = []
|
||||
for f in source_files:
|
||||
all_funcs.extend(analyze_file(f, source_dir))
|
||||
print(f"Functions/methods: {len(all_funcs)}")
|
||||
|
||||
existing = find_existing_tests(test_dir)
|
||||
print(f"Existing tests: {len(existing)}")
|
||||
|
||||
gaps = identify_gaps(all_funcs, existing)
|
||||
if not args.include_private:
|
||||
gaps = [g for g in gaps if not g.func.is_private]
|
||||
print(f"Coverage gaps: {len(gaps)}")
|
||||
|
||||
by_pri = {1: 0, 2: 0, 3: 0}
|
||||
for g in gaps:
|
||||
by_pri[g.test_priority] += 1
|
||||
print(f" High: {by_pri[1]}, Medium: {by_pri[2]}, Low: {by_pri[3]}")
|
||||
|
||||
if args.dry_run:
|
||||
for g in gaps[:10]:
|
||||
print(f" {g.func.module_path}:{g.func.lineno} {g.func.qualified_name}")
|
||||
return
|
||||
|
||||
if gaps:
|
||||
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:
|
||||
f.write(content)
|
||||
print(f"Generated {min(len(gaps), args.max_tests)} tests -> {args.output}")
|
||||
else:
|
||||
print("No gaps found!")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,35 +0,0 @@
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def _content() -> str:
|
||||
return Path("the-door-GENOME.md").read_text()
|
||||
|
||||
|
||||
def test_the_door_genome_exists() -> None:
|
||||
assert Path("the-door-GENOME.md").exists()
|
||||
|
||||
|
||||
def test_the_door_genome_has_required_sections() -> None:
|
||||
content = _content()
|
||||
assert "# GENOME.md — the-door" in content
|
||||
assert "## Project Overview" in content
|
||||
assert "## Architecture" in content
|
||||
assert "```mermaid" in content
|
||||
assert "## Entry Points" in content
|
||||
assert "## Data Flow" in content
|
||||
assert "## Key Abstractions" in content
|
||||
assert "## API Surface" in content
|
||||
assert "## Test Coverage Gaps" in content
|
||||
assert "## Security Considerations" in content
|
||||
assert "## Dependencies" in content
|
||||
assert "## Deployment" in content
|
||||
assert "## Technical Debt" in content
|
||||
|
||||
|
||||
def test_the_door_genome_captures_repo_specific_findings() -> None:
|
||||
content = _content()
|
||||
assert "lastUserMessage" in content
|
||||
assert "localStorage" in content
|
||||
assert "crisis-offline.html" in content
|
||||
assert "hermes-gateway.service" in content
|
||||
assert "/api/v1/chat/completions" in content
|
||||
737
tests/test_genome_generated.py
Normal file
737
tests/test_genome_generated.py
Normal file
@@ -0,0 +1,737 @@
|
||||
"""Auto-generated test suite -- Codebase Genome (#667).
|
||||
|
||||
Generated by scripts/codebase_test_generator.py
|
||||
Coverage gaps identified from AST analysis.
|
||||
|
||||
These tests are starting points. Review before merging.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
|
||||
# AUTO-GENERATED -- DO NOT EDIT WITHOUT REVIEW
|
||||
|
||||
class TestAngbandMcpServerGenerated:
|
||||
"""Auto-generated tests for angband/mcp_server.py."""
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: angband/mcp_server.py:319
|
||||
# Function: call_tool
|
||||
|
||||
@pytest.mark.asyncio
|
||||
def test_angband_mcp_server_call_tool(self):
|
||||
"""Test call_tool -- auto-generated."""
|
||||
try:
|
||||
from angband.mcp_server import call_tool
|
||||
result = call_tool(name='test', arguments=None)
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: angband/mcp_server.py:64
|
||||
# Function: capture_screen
|
||||
|
||||
def test_angband_mcp_server_capture_screen(self):
|
||||
"""Test capture_screen -- auto-generated."""
|
||||
try:
|
||||
from angband.mcp_server import capture_screen
|
||||
result = capture_screen(lines=None, session_name='test')
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: angband/mcp_server.py:74
|
||||
# Function: has_save
|
||||
|
||||
def test_angband_mcp_server_has_save(self):
|
||||
"""Test has_save -- auto-generated."""
|
||||
try:
|
||||
from angband.mcp_server import has_save
|
||||
result = has_save(user=None)
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: angband/mcp_server.py:234
|
||||
# Function: keypress
|
||||
|
||||
def test_angband_mcp_server_keypress(self):
|
||||
"""Test keypress -- auto-generated."""
|
||||
try:
|
||||
from angband.mcp_server import keypress
|
||||
result = keypress(key='test_id', wait_ms=None)
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: angband/mcp_server.py:141
|
||||
# Function: launch_game
|
||||
|
||||
def test_angband_mcp_server_launch_game(self):
|
||||
"""Test launch_game -- auto-generated."""
|
||||
try:
|
||||
from angband.mcp_server import launch_game
|
||||
result = launch_game(user=None, new_game=None, continue_splash=None, width='test_id', height=None)
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: angband/mcp_server.py:253
|
||||
# Function: list_tools
|
||||
|
||||
@pytest.mark.asyncio
|
||||
def test_angband_mcp_server_list_tools(self):
|
||||
"""Test list_tools -- auto-generated."""
|
||||
try:
|
||||
from angband.mcp_server import list_tools
|
||||
result = list_tools()
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: angband/mcp_server.py:130
|
||||
# Function: maybe_continue_splash
|
||||
|
||||
def test_angband_mcp_server_maybe_continue_splash(self):
|
||||
"""Test maybe_continue_splash -- auto-generated."""
|
||||
try:
|
||||
from angband.mcp_server import maybe_continue_splash
|
||||
result = maybe_continue_splash(session_name='test')
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: angband/mcp_server.py:226
|
||||
# Function: observe
|
||||
|
||||
def test_angband_mcp_server_observe(self):
|
||||
"""Test observe -- auto-generated."""
|
||||
try:
|
||||
from angband.mcp_server import observe
|
||||
result = observe(lines=None)
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: angband/mcp_server.py:57
|
||||
# Function: pane_id
|
||||
|
||||
def test_angband_mcp_server_pane_id(self):
|
||||
"""Test pane_id -- auto-generated."""
|
||||
try:
|
||||
from angband.mcp_server import pane_id
|
||||
result = pane_id(session_name='test')
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: angband/mcp_server.py:108
|
||||
# Function: send_key
|
||||
|
||||
def test_angband_mcp_server_send_key(self):
|
||||
"""Test send_key -- auto-generated."""
|
||||
try:
|
||||
from angband.mcp_server import send_key
|
||||
with pytest.raises((RuntimeError)):
|
||||
send_key(key='test_id', session_name='test')
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: angband/mcp_server.py:123
|
||||
# Function: send_text
|
||||
|
||||
def test_angband_mcp_server_send_text(self):
|
||||
"""Test send_text -- auto-generated."""
|
||||
try:
|
||||
from angband.mcp_server import send_text
|
||||
with pytest.raises((RuntimeError)):
|
||||
send_text(text='test msg', session_name='test')
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: angband/mcp_server.py:53
|
||||
# Function: session_exists
|
||||
|
||||
def test_angband_mcp_server_session_exists(self):
|
||||
"""Test session_exists -- auto-generated."""
|
||||
try:
|
||||
from angband.mcp_server import session_exists
|
||||
result = session_exists(session_name='test')
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: angband/mcp_server.py:203
|
||||
# Function: stop_game
|
||||
|
||||
def test_angband_mcp_server_stop_game(self):
|
||||
"""Test stop_game -- auto-generated."""
|
||||
try:
|
||||
from angband.mcp_server import stop_game
|
||||
result = stop_game()
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: angband/mcp_server.py:46
|
||||
# Function: tmux
|
||||
|
||||
def test_angband_mcp_server_tmux(self):
|
||||
"""Test tmux -- auto-generated."""
|
||||
try:
|
||||
from angband.mcp_server import tmux
|
||||
with pytest.raises((RuntimeError)):
|
||||
tmux(args=None, check=None)
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: angband/mcp_server.py:243
|
||||
# Function: type_and_observe
|
||||
|
||||
def test_angband_mcp_server_type_and_observe(self):
|
||||
"""Test type_and_observe -- auto-generated."""
|
||||
try:
|
||||
from angband.mcp_server import type_and_observe
|
||||
result = type_and_observe(text='test msg', wait_ms=None)
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
|
||||
class TestEvenniaTimmyWorldGameGenerated:
|
||||
"""Auto-generated tests for evennia/timmy_world/game.py."""
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: evennia/timmy_world/game.py:495
|
||||
# Function: ActionSystem.get_available_actions
|
||||
|
||||
def test_evennia_timmy_world_game_ActionSystem_get_available_actions(self):
|
||||
"""Test ActionSystem.get_available_actions -- auto-generated."""
|
||||
try:
|
||||
from evennia.timmy_world.game import ActionSystem
|
||||
obj = ActionSystem()
|
||||
result = obj.get_available_actions(char_name='test', world=None)
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: evennia/timmy_world/game.py:1485
|
||||
# Function: PlayerInterface.get_available_actions
|
||||
|
||||
def test_evennia_timmy_world_game_PlayerInterface_get_available_actions(self):
|
||||
"""Test PlayerInterface.get_available_actions -- auto-generated."""
|
||||
try:
|
||||
from evennia.timmy_world.game import PlayerInterface
|
||||
obj = PlayerInterface()
|
||||
result = obj.get_available_actions()
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: evennia/timmy_world/game.py:55
|
||||
# Function: get_narrative_phase
|
||||
|
||||
def test_evennia_timmy_world_game_get_narrative_phase(self):
|
||||
"""Test get_narrative_phase -- auto-generated."""
|
||||
try:
|
||||
from evennia.timmy_world.game import get_narrative_phase
|
||||
result = get_narrative_phase(tick=None)
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: evennia/timmy_world/game.py:65
|
||||
# Function: get_phase_transition_event
|
||||
|
||||
def test_evennia_timmy_world_game_get_phase_transition_event(self):
|
||||
"""Test get_phase_transition_event -- auto-generated."""
|
||||
try:
|
||||
from evennia.timmy_world.game import get_phase_transition_event
|
||||
result = get_phase_transition_event(old_phase=None, new_phase=None)
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: evennia/timmy_world/game.py:347
|
||||
# Function: World.get_room_desc
|
||||
|
||||
def test_evennia_timmy_world_game_World_get_room_desc(self):
|
||||
"""Test World.get_room_desc -- auto-generated."""
|
||||
try:
|
||||
from evennia.timmy_world.game import World
|
||||
obj = World()
|
||||
result = obj.get_room_desc(room_name='test', char_name='test')
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: evennia/timmy_world/game.py:1045
|
||||
# Function: GameEngine.load_game
|
||||
|
||||
def test_evennia_timmy_world_game_GameEngine_load_game(self):
|
||||
"""Test GameEngine.load_game -- auto-generated."""
|
||||
try:
|
||||
from evennia.timmy_world.game import GameEngine
|
||||
obj = GameEngine()
|
||||
result = obj.load_game()
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: evennia/timmy_world/game.py:556
|
||||
# Function: NPCAI.make_choice
|
||||
|
||||
def test_evennia_timmy_world_game_NPCAI_make_choice(self):
|
||||
"""Test NPCAI.make_choice -- auto-generated."""
|
||||
try:
|
||||
from evennia.timmy_world.game import NPCAI
|
||||
obj = NPCAI()
|
||||
result = obj.make_choice(char_name='test')
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: evennia/timmy_world/game.py:1454
|
||||
# Function: GameEngine.play_turn
|
||||
|
||||
def test_evennia_timmy_world_game_GameEngine_play_turn(self):
|
||||
"""Test GameEngine.play_turn -- auto-generated."""
|
||||
try:
|
||||
from evennia.timmy_world.game import GameEngine
|
||||
obj = GameEngine()
|
||||
result = obj.play_turn(action=None)
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: evennia/timmy_world/game.py:1076
|
||||
# Function: GameEngine.run_tick
|
||||
|
||||
def test_evennia_timmy_world_game_GameEngine_run_tick(self):
|
||||
"""Test GameEngine.run_tick -- auto-generated."""
|
||||
try:
|
||||
from evennia.timmy_world.game import GameEngine
|
||||
obj = GameEngine()
|
||||
result = obj.run_tick(timmy_action=None)
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
|
||||
class TestEvenniaTimmyWorldServerConfWebPluginsGenerated:
|
||||
"""Auto-generated tests for evennia/timmy_world/server/conf/web_plugins.py."""
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: evennia/timmy_world/server/conf/web_plugins.py:31
|
||||
# Function: at_webproxy_root_creation
|
||||
|
||||
def test_evennia_timmy_world_server_conf_web_plugins_at_webproxy_root_creation(self):
|
||||
"""Test at_webproxy_root_creation -- auto-generated."""
|
||||
try:
|
||||
from evennia.timmy_world.server.conf.web_plugins import at_webproxy_root_creation
|
||||
result = at_webproxy_root_creation(web_root=None)
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: evennia/timmy_world/server/conf/web_plugins.py:6
|
||||
# Function: at_webserver_root_creation
|
||||
|
||||
def test_evennia_timmy_world_server_conf_web_plugins_at_webserver_root_creation(self):
|
||||
"""Test at_webserver_root_creation -- auto-generated."""
|
||||
try:
|
||||
from evennia.timmy_world.server.conf.web_plugins import at_webserver_root_creation
|
||||
result = at_webserver_root_creation(web_root=None)
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
|
||||
class TestEvenniaTimmyWorldWorldGameGenerated:
|
||||
"""Auto-generated tests for evennia/timmy_world/world/game.py."""
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: evennia/timmy_world/world/game.py:400
|
||||
# Function: ActionSystem.get_available_actions
|
||||
|
||||
def test_evennia_timmy_world_world_game_ActionSystem_get_available_actions(self):
|
||||
"""Test ActionSystem.get_available_actions -- auto-generated."""
|
||||
try:
|
||||
from evennia.timmy_world.world.game import ActionSystem
|
||||
obj = ActionSystem()
|
||||
result = obj.get_available_actions(char_name='test', world=None)
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: evennia/timmy_world/world/game.py:1289
|
||||
# Function: PlayerInterface.get_available_actions
|
||||
|
||||
def test_evennia_timmy_world_world_game_PlayerInterface_get_available_actions(self):
|
||||
"""Test PlayerInterface.get_available_actions -- auto-generated."""
|
||||
try:
|
||||
from evennia.timmy_world.world.game import PlayerInterface
|
||||
obj = PlayerInterface()
|
||||
result = obj.get_available_actions()
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: evennia/timmy_world/world/game.py:254
|
||||
# Function: World.get_room_desc
|
||||
|
||||
def test_evennia_timmy_world_world_game_World_get_room_desc(self):
|
||||
"""Test World.get_room_desc -- auto-generated."""
|
||||
try:
|
||||
from evennia.timmy_world.world.game import World
|
||||
obj = World()
|
||||
result = obj.get_room_desc(room_name='test', char_name='test')
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: evennia/timmy_world/world/game.py:880
|
||||
# Function: GameEngine.load_game
|
||||
|
||||
def test_evennia_timmy_world_world_game_GameEngine_load_game(self):
|
||||
"""Test GameEngine.load_game -- auto-generated."""
|
||||
try:
|
||||
from evennia.timmy_world.world.game import GameEngine
|
||||
obj = GameEngine()
|
||||
result = obj.load_game()
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: evennia/timmy_world/world/game.py:461
|
||||
# Function: NPCAI.make_choice
|
||||
|
||||
def test_evennia_timmy_world_world_game_NPCAI_make_choice(self):
|
||||
"""Test NPCAI.make_choice -- auto-generated."""
|
||||
try:
|
||||
from evennia.timmy_world.world.game import NPCAI
|
||||
obj = NPCAI()
|
||||
result = obj.make_choice(char_name='test')
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: evennia/timmy_world/world/game.py:1258
|
||||
# Function: GameEngine.play_turn
|
||||
|
||||
def test_evennia_timmy_world_world_game_GameEngine_play_turn(self):
|
||||
"""Test GameEngine.play_turn -- auto-generated."""
|
||||
try:
|
||||
from evennia.timmy_world.world.game import GameEngine
|
||||
obj = GameEngine()
|
||||
result = obj.play_turn(action=None)
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: evennia/timmy_world/world/game.py:911
|
||||
# Function: GameEngine.run_tick
|
||||
|
||||
def test_evennia_timmy_world_world_game_GameEngine_run_tick(self):
|
||||
"""Test GameEngine.run_tick -- auto-generated."""
|
||||
try:
|
||||
from evennia.timmy_world.world.game import GameEngine
|
||||
obj = GameEngine()
|
||||
result = obj.run_tick(timmy_action=None)
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: evennia/timmy_world/world/game.py:749
|
||||
# Function: DialogueSystem.select
|
||||
|
||||
def test_evennia_timmy_world_world_game_DialogueSystem_select(self):
|
||||
"""Test DialogueSystem.select -- auto-generated."""
|
||||
try:
|
||||
from evennia.timmy_world.world.game import DialogueSystem
|
||||
obj = DialogueSystem()
|
||||
result = obj.select(char_name='test', listener=None)
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
|
||||
class TestEvenniaToolsLayoutGenerated:
|
||||
"""Auto-generated tests for evennia_tools/layout.py."""
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: evennia_tools/layout.py:58
|
||||
# Function: grouped_exits
|
||||
|
||||
def test_evennia_tools_layout_grouped_exits(self):
|
||||
"""Test grouped_exits -- auto-generated."""
|
||||
try:
|
||||
from evennia_tools.layout import grouped_exits
|
||||
result = grouped_exits()
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: evennia_tools/layout.py:54
|
||||
# Function: room_keys
|
||||
|
||||
def test_evennia_tools_layout_room_keys(self):
|
||||
"""Test room_keys -- auto-generated."""
|
||||
try:
|
||||
from evennia_tools.layout import room_keys
|
||||
result = room_keys()
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
|
||||
class TestEvenniaToolsTelemetryGenerated:
|
||||
"""Auto-generated tests for evennia_tools/telemetry.py."""
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: evennia_tools/telemetry.py:8
|
||||
# Function: telemetry_dir
|
||||
|
||||
def test_evennia_tools_telemetry_telemetry_dir(self):
|
||||
"""Test telemetry_dir -- auto-generated."""
|
||||
try:
|
||||
from evennia_tools.telemetry import telemetry_dir
|
||||
result = telemetry_dir(base_dir='/tmp/test')
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
|
||||
class TestEvenniaToolsTrainingGenerated:
|
||||
"""Auto-generated tests for evennia_tools/training.py."""
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: evennia_tools/training.py:18
|
||||
# Function: example_eval_path
|
||||
|
||||
def test_evennia_tools_training_example_eval_path(self):
|
||||
"""Test example_eval_path -- auto-generated."""
|
||||
try:
|
||||
from evennia_tools.training import example_eval_path
|
||||
result = example_eval_path(repo_root=None)
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: evennia_tools/training.py:14
|
||||
# Function: example_trace_path
|
||||
|
||||
def test_evennia_tools_training_example_trace_path(self):
|
||||
"""Test example_trace_path -- auto-generated."""
|
||||
try:
|
||||
from evennia_tools.training import example_trace_path
|
||||
result = example_trace_path(repo_root=None)
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
|
||||
class TestEvolutionBitcoinScripterGenerated:
|
||||
"""Auto-generated tests for evolution/bitcoin_scripter.py."""
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: evolution/bitcoin_scripter.py:18
|
||||
# Function: BitcoinScripter.generate_script
|
||||
|
||||
def test_evolution_bitcoin_scripter_BitcoinScripter_generate_script(self):
|
||||
"""Test BitcoinScripter.generate_script -- auto-generated."""
|
||||
try:
|
||||
from evolution.bitcoin_scripter import BitcoinScripter
|
||||
obj = BitcoinScripter()
|
||||
result = obj.generate_script(requirements=None)
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
|
||||
class TestEvolutionLightningClientGenerated:
|
||||
"""Auto-generated tests for evolution/lightning_client.py."""
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: evolution/lightning_client.py:18
|
||||
# Function: LightningClient.plan_payment_route
|
||||
|
||||
def test_evolution_lightning_client_LightningClient_plan_payment_route(self):
|
||||
"""Test LightningClient.plan_payment_route -- auto-generated."""
|
||||
try:
|
||||
from evolution.lightning_client import LightningClient
|
||||
obj = LightningClient()
|
||||
result = obj.plan_payment_route(destination=None, amount_sats=None)
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
|
||||
class TestEvolutionSovereignAccountantGenerated:
|
||||
"""Auto-generated tests for evolution/sovereign_accountant.py."""
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: evolution/sovereign_accountant.py:17
|
||||
# Function: SovereignAccountant.generate_financial_report
|
||||
|
||||
def test_evolution_sovereign_accountant_SovereignAccountant_generate_financial_report(self):
|
||||
"""Test SovereignAccountant.generate_financial_report -- auto-generated."""
|
||||
try:
|
||||
from evolution.sovereign_accountant import SovereignAccountant
|
||||
obj = SovereignAccountant()
|
||||
result = obj.generate_financial_report(transaction_history=None)
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
|
||||
class TestInfrastructureTimmyBridgeClientTimmyClientGenerated:
|
||||
"""Auto-generated tests for infrastructure/timmy-bridge/client/timmy_client.py."""
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: infrastructure/timmy-bridge/client/timmy_client.py:108
|
||||
# Function: TimmyClient.create_artifact
|
||||
|
||||
def test_infrastructure_timmy_bridge_client_timmy_client_TimmyClient_create_artifact(self):
|
||||
"""Test TimmyClient.create_artifact -- auto-generated."""
|
||||
try:
|
||||
from infrastructure.timmy_bridge.client.timmy_client import TimmyClient
|
||||
obj = TimmyClient()
|
||||
result = obj.create_artifact()
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: infrastructure/timmy-bridge/client/timmy_client.py:167
|
||||
# Function: TimmyClient.create_event
|
||||
|
||||
def test_infrastructure_timmy_bridge_client_timmy_client_TimmyClient_create_event(self):
|
||||
"""Test TimmyClient.create_event -- auto-generated."""
|
||||
try:
|
||||
from infrastructure.timmy_bridge.client.timmy_client import TimmyClient
|
||||
obj = TimmyClient()
|
||||
result = obj.create_event(kind=None, content=None, tags=None)
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: infrastructure/timmy-bridge/client/timmy_client.py:74
|
||||
# Function: TimmyClient.generate_observation
|
||||
|
||||
def test_infrastructure_timmy_bridge_client_timmy_client_TimmyClient_generate_observation(self):
|
||||
"""Test TimmyClient.generate_observation -- auto-generated."""
|
||||
try:
|
||||
from infrastructure.timmy_bridge.client.timmy_client import TimmyClient
|
||||
obj = TimmyClient()
|
||||
result = obj.generate_observation()
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
|
||||
class TestInfrastructureTimmyBridgeMlxMlxIntegrationGenerated:
|
||||
"""Auto-generated tests for infrastructure/timmy-bridge/mlx/mlx_integration.py."""
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: infrastructure/timmy-bridge/mlx/mlx_integration.py:122
|
||||
# Function: MLXInference.available
|
||||
|
||||
def test_infrastructure_timmy_bridge_mlx_mlx_integration_MLXInference_available(self):
|
||||
"""Test MLXInference.available -- auto-generated."""
|
||||
try:
|
||||
from infrastructure.timmy_bridge.mlx.mlx_integration import MLXInference
|
||||
obj = MLXInference()
|
||||
_ = obj.available
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: infrastructure/timmy-bridge/mlx/mlx_integration.py:125
|
||||
# Function: MLXInference.get_stats
|
||||
|
||||
def test_infrastructure_timmy_bridge_mlx_mlx_integration_MLXInference_get_stats(self):
|
||||
"""Test MLXInference.get_stats -- auto-generated."""
|
||||
try:
|
||||
from infrastructure.timmy_bridge.mlx.mlx_integration import MLXInference
|
||||
obj = MLXInference()
|
||||
result = obj.get_stats()
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: infrastructure/timmy-bridge/mlx/mlx_integration.py:30
|
||||
# Function: MLXInference.load_model
|
||||
|
||||
def test_infrastructure_timmy_bridge_mlx_mlx_integration_MLXInference_load_model(self):
|
||||
"""Test MLXInference.load_model -- auto-generated."""
|
||||
try:
|
||||
from infrastructure.timmy_bridge.mlx.mlx_integration import MLXInference
|
||||
obj = MLXInference()
|
||||
result = obj.load_model(model_path='/tmp/test')
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: infrastructure/timmy-bridge/mlx/mlx_integration.py:93
|
||||
# Function: MLXInference.reflect
|
||||
|
||||
def test_infrastructure_timmy_bridge_mlx_mlx_integration_MLXInference_reflect(self):
|
||||
"""Test MLXInference.reflect -- auto-generated."""
|
||||
try:
|
||||
from infrastructure.timmy_bridge.mlx.mlx_integration import MLXInference
|
||||
obj = MLXInference()
|
||||
result = obj.reflect()
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
|
||||
# AUTO-GENERATED -- review before merging
|
||||
# Source: infrastructure/timmy-bridge/mlx/mlx_integration.py:108
|
||||
# Function: MLXInference.respond_to
|
||||
|
||||
def test_infrastructure_timmy_bridge_mlx_mlx_integration_MLXInference_respond_to(self):
|
||||
"""Test MLXInference.respond_to -- auto-generated."""
|
||||
try:
|
||||
from infrastructure.timmy_bridge.mlx.mlx_integration import MLXInference
|
||||
obj = MLXInference()
|
||||
result = obj.respond_to(message='test msg', context='test msg')
|
||||
assert result is not None or result is None # Placeholder
|
||||
except ImportError:
|
||||
pytest.skip('Module not importable')
|
||||
@@ -1,419 +0,0 @@
|
||||
# GENOME.md — the-door
|
||||
|
||||
Generated: 2026-04-15 00:03:16 EDT
|
||||
Repo: Timmy_Foundation/the-door
|
||||
Issue: timmy-home #673
|
||||
|
||||
## Project Overview
|
||||
|
||||
The Door is a crisis-first front door to Timmy: one URL, no account wall, no app install, and a permanently visible 988 escape hatch. The repo combines a static browser UI, a local Hermes API gateway behind nginx, and a Python crisis package that duplicates and enriches the frontend's safety logic.
|
||||
|
||||
What the codebase actually contains today:
|
||||
- 1 primary browser app: `index.html`
|
||||
- 4 companion browser assets/pages: `about.html`, `testimony.html`, `crisis-offline.html`, `sw.js`
|
||||
- 17 Python files across canonical crisis logic, legacy shims, wrappers, and tests
|
||||
- 2 Gitea workflows: `smoke.yml`, `sanity.yml`
|
||||
- 1 systemd unit: `deploy/hermes-gateway.service`
|
||||
- full test suite currently passing: `115 passed, 3 subtests passed`
|
||||
|
||||
The repo is small, but it is not simple. The true architecture is a layered safety system:
|
||||
1. immediate browser-side crisis escalation
|
||||
2. OpenAI-compatible streaming chat through Hermes
|
||||
3. canonical Python crisis detection and response modules
|
||||
4. nginx hardening, rate limiting, and localhost-only gateway exposure
|
||||
5. service-worker offline fallback for crisis resources
|
||||
|
||||
The strongest pattern in this codebase is safety redundancy: the UI, prompt layer, offline fallback, and backend detection all try to catch the same sacred failure mode from different directions.
|
||||
|
||||
## Architecture
|
||||
|
||||
```mermaid
|
||||
graph TD
|
||||
U[User in browser] --> I[index.html chat app]
|
||||
I --> K[Client-side crisis detection\ncrisisKeywords + explicitPhrases]
|
||||
K --> P[Inline crisis panel]
|
||||
K --> O[Fullscreen crisis overlay]
|
||||
I --> L[localStorage\nchat history + safety plan]
|
||||
I --> SW[sw.js service worker]
|
||||
SW --> OFF[crisis-offline.html]
|
||||
|
||||
I --> API[/POST /api/v1/chat/completions/]
|
||||
API --> NGINX[nginx reverse proxy]
|
||||
NGINX --> H[Hermes Gateway :8644]
|
||||
NGINX --> HC[/health proxy]
|
||||
|
||||
H --> G[crisis/gateway.py]
|
||||
G --> D[crisis/detect.py]
|
||||
G --> R[crisis/response.py]
|
||||
D --> CR[CrisisDetectionResult]
|
||||
R --> RESP[CrisisResponse]
|
||||
D --> LEG[Legacy shims\ncrisis_detector.py\ncrisis_responder.py\ndying_detection]
|
||||
|
||||
DEP[deploy/playbook.yml\ndeploy/deploy.sh\nhermes-gateway.service] --> NGINX
|
||||
DEP --> H
|
||||
CI[.gitea/workflows\nsmoke.yml + sanity.yml] --> I
|
||||
CI --> D
|
||||
```
|
||||
|
||||
## Entry Points
|
||||
|
||||
### Browser / user-facing entry points
|
||||
- `index.html`
|
||||
- the main product
|
||||
- contains inline CSS, inline JS, embedded `SYSTEM_PROMPT`, chat UI, crisis panel, fullscreen overlay, and safety-plan modal
|
||||
- `about.html`
|
||||
- static about page
|
||||
- linked from the chat footer, though the main app currently links to `/about` while the repo ships `about.html`
|
||||
- `testimony.html`
|
||||
- static companion content page
|
||||
- `crisis-offline.html`
|
||||
- offline crisis resource page served by the service worker when navigation cannot reach the network
|
||||
- `manifest.json`
|
||||
- PWA metadata and shortcuts, including `/?safetyplan=true` and `tel:988`
|
||||
- `sw.js`
|
||||
- network-first service worker with offline crisis fallback
|
||||
|
||||
### Backend / Python entry points
|
||||
- `crisis/detect.py`
|
||||
- canonical detection engine and public detection API
|
||||
- `crisis/response.py`
|
||||
- canonical response generator, UI flags, prompt modifier, grounding helpers
|
||||
- `crisis/gateway.py`
|
||||
- integration layer for `check_crisis()` and `get_system_prompt()`
|
||||
- `crisis/compassion_router.py`
|
||||
- profile-based prompt routing abstraction parallel to `response.py`
|
||||
- `crisis_detector.py`
|
||||
- root legacy shim exposing canonical detection in older shapes
|
||||
- `crisis_responder.py`
|
||||
- root legacy response module with a richer compatibility response contract
|
||||
- `dying_detection/__init__.py`
|
||||
- deprecated wrapper around canonical detection
|
||||
|
||||
### Operational entry points
|
||||
- `deploy/deploy.sh`
|
||||
- most complete one-command operational bootstrap path in the repo
|
||||
- `deploy/playbook.yml`
|
||||
- Ansible provisioning path for swap, packages, nginx, firewall, and site files
|
||||
- `deploy/hermes-gateway.service`
|
||||
- systemd unit running `hermes gateway --platform api_server --port 8644`
|
||||
- `.gitea/workflows/smoke.yml`
|
||||
- parse/syntax checks and secret scan
|
||||
- `.gitea/workflows/sanity.yml`
|
||||
- basic repo sanity grep checks for 988/system-prompt presence
|
||||
|
||||
## Data Flow
|
||||
|
||||
### Happy path: user message to streamed response
|
||||
1. User types into `#msg-input` in `index.html`.
|
||||
2. `sendMessage()`:
|
||||
- trims text
|
||||
- appends a user bubble to the DOM
|
||||
- pushes `{role: 'user', content: text}` into the in-memory `messages` array
|
||||
- runs client-side `checkCrisis(text)`
|
||||
- clears the input and starts streaming
|
||||
3. `streamResponse()` builds the request payload:
|
||||
- prepends a synthetic system message from `getSystemPrompt(lastUserMessage || '')`
|
||||
- posts JSON to `/api/v1/chat/completions`
|
||||
4. nginx proxies `/api/*` to `127.0.0.1:8644`.
|
||||
5. Hermes streams OpenAI-style SSE chunks back to the browser.
|
||||
6. The browser reads `choices[0].delta.content` and incrementally renders the assistant message.
|
||||
7. When streaming ends, the assistant turn is pushed into `messages`, saved to `localStorage`, and passed through `checkCrisis(fullText)` again.
|
||||
|
||||
### Immediate local crisis escalation path
|
||||
1. `checkCrisis(text)` scans substrings against two client-side lists.
|
||||
2. Low-tier/soft crisis text reveals the inline crisis panel.
|
||||
3. Explicit intent text triggers the fullscreen overlay and delayed-dismiss flow.
|
||||
4. The user still remains in the conversation flow rather than being hard-redirected away.
|
||||
|
||||
### Offline / failure path
|
||||
1. `sw.js` precaches static routes and the crisis fallback page.
|
||||
2. Navigation uses a network-first strategy with timeout fallback.
|
||||
3. If network and cache both fail, the service worker tries `crisis-offline.html`.
|
||||
4. If API streaming fails, `index.html` inserts a static emergency message with 988 and 741741 instead of a blank error.
|
||||
|
||||
## Key Abstractions
|
||||
|
||||
### 1. `SYSTEM_PROMPT`
|
||||
Embedded directly in `index.html`, not loaded at runtime from `system-prompt.txt`. The browser treats the prompt as part of the application runtime contract.
|
||||
|
||||
### 2. `COMPASSION_PROFILES`
|
||||
Frontend prompt-state profiles for `CRITICAL`, `HIGH`, `MEDIUM`, `LOW`, and `NONE`. They encode tone and directive shifts, but the current `levelMap` only maps browser levels to `NONE`, `MEDIUM`, and `CRITICAL`, leaving `HIGH` and `LOW` effectively unused in the main prompt-building path.
|
||||
|
||||
### 3. Client-side crisis detector
|
||||
In `index.html`, the browser uses:
|
||||
- `crisisKeywords` for panel escalation
|
||||
- `explicitPhrases` for hard overlay escalation
|
||||
- `checkCrisis(text)` for UI behavior
|
||||
- `getCrisisLevel(text)` for prompt shaping
|
||||
|
||||
This is fast and local, but it is also a separate detector from the canonical Python package.
|
||||
|
||||
### 4. `CrisisDetectionResult`
|
||||
The core canonical backend dataclass from `crisis/detect.py`:
|
||||
- `level`
|
||||
- `indicators`
|
||||
- `recommended_action`
|
||||
- `score`
|
||||
- `matches`
|
||||
|
||||
This is the canonical representation shared by the main Python crisis stack.
|
||||
|
||||
### 5. `CrisisResponse`
|
||||
In `crisis/response.py`, the canonical response dataclass ties backend detection to frontend/UI needs:
|
||||
- `timmy_message`
|
||||
- `show_crisis_panel`
|
||||
- `show_overlay`
|
||||
- `provide_988`
|
||||
- `escalate`
|
||||
|
||||
### 6. Legacy compatibility layer
|
||||
The repo still carries older interfaces:
|
||||
- `crisis_detector.py`
|
||||
- `crisis_responder.py`
|
||||
- `dying_detection/__init__.py`
|
||||
|
||||
These preserve compatibility, but they also create drift risk:
|
||||
- `MEDIUM` vs `MODERATE`
|
||||
- two different `CrisisResponse` contracts
|
||||
- two prompt-routing paths (`response.py` vs `compassion_router.py`)
|
||||
|
||||
### 7. Browser persistence contract
|
||||
`localStorage` is a real part of runtime state despite some docs claiming otherwise.
|
||||
Keys:
|
||||
- `timmy_chat_history`
|
||||
- `timmy_safety_plan`
|
||||
|
||||
That means The Door is not truly “close tab = gone” in its current implementation.
|
||||
|
||||
## API Surface
|
||||
|
||||
### Browser -> Hermes API contract
|
||||
`index.html` sends:
|
||||
|
||||
```json
|
||||
{
|
||||
"model": "timmy",
|
||||
"messages": [
|
||||
{"role": "system", "content": "...prompt..."},
|
||||
{"role": "assistant", "content": "..."},
|
||||
{"role": "user", "content": "..."}
|
||||
],
|
||||
"stream": true
|
||||
}
|
||||
```
|
||||
|
||||
Endpoint:
|
||||
- `/api/v1/chat/completions`
|
||||
|
||||
Expected response shape:
|
||||
- streaming SSE lines beginning with `data: `
|
||||
- chunk payloads with `choices[0].delta.content`
|
||||
- `[DONE]` terminator
|
||||
|
||||
### Canonical Python API
|
||||
- `crisis.detect.detect_crisis(text)`
|
||||
- `crisis.response.generate_response(detection)`
|
||||
- `crisis.response.process_message(text)`
|
||||
- `crisis.response.get_system_prompt_modifier(detection)`
|
||||
- `crisis.gateway.check_crisis(text)`
|
||||
- `crisis.gateway.get_system_prompt(base_prompt, text="")`
|
||||
- `crisis.gateway.format_gateway_response(text, pretty=True)`
|
||||
|
||||
### Legacy / compatibility API
|
||||
- `CrisisDetector.scan()`
|
||||
- `detect_crisis_legacy()`
|
||||
- root `crisis_responder.generate_response()`
|
||||
- deprecated `dying_detection.detect()` and helpers
|
||||
|
||||
## Test Coverage Gaps
|
||||
|
||||
### Current state
|
||||
Verified on fresh `main` clone of `the-door`:
|
||||
- `python3 -m pytest -q` -> `115 passed, 3 subtests passed`
|
||||
|
||||
What is already covered well:
|
||||
- canonical crisis detection tiers
|
||||
- response flags and gateway structure
|
||||
- many false-positive regressions
|
||||
- service-worker offline crisis fallback
|
||||
- crisis overlay focus trap string-level assertions
|
||||
- deprecated wrapper behavior
|
||||
|
||||
### High-value gaps that still matter
|
||||
1. No real browser test of the actual send path in `index.html`.
|
||||
- The repo currently contains a concrete scope bug:
|
||||
- `sendMessage()` defines `var lastUserMessage = text;`
|
||||
- `streamResponse()` later uses `getSystemPrompt(lastUserMessage || '')`
|
||||
- `lastUserMessage` is not in `streamResponse()` scope
|
||||
- Existing passing tests do not execute this real path.
|
||||
|
||||
2. No DOM-true test for overlay background locking.
|
||||
- The overlay code targets `document.querySelector('.app')` and `getElementById('chat')`.
|
||||
- The main document uses `id="app"`, not `.app`, and does not expose a `#chat` node.
|
||||
- Current tests assert code presence, not selector correctness.
|
||||
|
||||
3. No route validation for `/about` vs `about.html`.
|
||||
- The footer links to `/about`.
|
||||
- The repo ships `about.html`.
|
||||
- With current nginx `try_files`, this looks like a drift bug.
|
||||
|
||||
4. Legacy responder path remains largely untested.
|
||||
- `crisis_responder.py` is still present and meaningful but lacks direct tests for its richer response payloads.
|
||||
|
||||
5. CI does not run pytest.
|
||||
- The repo has a substantial suite, but Gitea workflows only do syntax/grep checks.
|
||||
|
||||
### Generated missing tests for critical paths
|
||||
These are the three most important tests this codebase still needs.
|
||||
|
||||
#### A. Browser send-path smoke test
|
||||
Goal: catch the `lastUserMessage` regression and ensure the chat request actually builds.
|
||||
|
||||
```python
|
||||
# Example Playwright/browser test
|
||||
async def test_send_message_builds_stream_request(page):
|
||||
await page.goto("file:///.../index.html")
|
||||
await page.fill("#msg-input", "hello")
|
||||
await page.click("#send-btn")
|
||||
# Expect no ReferenceError and one request to /api/v1/chat/completions
|
||||
```
|
||||
|
||||
#### B. Overlay selector correctness test
|
||||
Goal: prove the inert/background lock hits real DOM nodes, not dead selectors.
|
||||
|
||||
```python
|
||||
def test_overlay_background_selectors_match_real_dom():
|
||||
html = Path("index.html").read_text()
|
||||
assert 'id="app"' in html
|
||||
assert "querySelector('.app')" not in html
|
||||
assert "getElementById('chat')" not in html
|
||||
```
|
||||
|
||||
#### C. Legacy responder contract test
|
||||
Goal: keep compatibility layers honest until they are deleted.
|
||||
|
||||
```python
|
||||
from crisis_responder import process_message
|
||||
|
||||
def test_legacy_responder_returns_resources_for_high_risk():
|
||||
response = process_message("I want to kill myself")
|
||||
assert response.escalate is True
|
||||
assert response.show_overlay is True
|
||||
assert any("988" in r for r in response.resources)
|
||||
```
|
||||
|
||||
## Security Considerations
|
||||
|
||||
### Strengths
|
||||
- Browser message bubbles use `textContent`, not unsafe inner HTML, for chat content.
|
||||
- API calls are same-origin and proxied through nginx.
|
||||
- Service worker does not cache `/api/*` responses.
|
||||
- nginx includes CSP, HSTS, and localhost-only gateway exposure.
|
||||
- UFW/docs expect only `22`, `80`, and `443` to be public.
|
||||
- systemd unit hardening is present in `hermes-gateway.service`.
|
||||
|
||||
### Risks
|
||||
1. `localStorage` persistence contradicts the privacy story.
|
||||
- chat history and safety plan are stored in plaintext on the device
|
||||
- shared-device risk is real
|
||||
|
||||
2. `script-src 'unsafe-inline'` is required by the current architecture.
|
||||
- all runtime logic and CSS are inline in `index.html`
|
||||
- this weakens CSP/XSS posture
|
||||
|
||||
3. Safety enforcement is still heavily client-shaped.
|
||||
- the frontend always embeds the crisis-aware prompt
|
||||
- deployment does not clearly prove that all callers are forced through server-side crisis middleware
|
||||
- direct API clients may bypass browser-supplied context
|
||||
|
||||
4. Client and server detection logic can drift.
|
||||
- the browser uses substring lists
|
||||
- the backend uses canonical regex tiers in `crisis/detect.py`
|
||||
- parity is not tested
|
||||
|
||||
5. Deprecated wrapper emits a deterministic session hash.
|
||||
- `dying_detection` exposes a truncated SHA-256 fingerprint of text
|
||||
- useful for correlation, but still privacy-sensitive
|
||||
|
||||
## Dependencies
|
||||
|
||||
### Runtime
|
||||
- Hermes binary at `/usr/local/bin/hermes`
|
||||
- nginx
|
||||
- certbot + python certbot nginx plugin
|
||||
- ufw
|
||||
- curl
|
||||
- Python 3
|
||||
- browser with JavaScript, service-worker, and `localStorage` support
|
||||
|
||||
### Test / operator dependencies
|
||||
- pytest
|
||||
- PyYAML (used implicitly by smoke workflow checks)
|
||||
- ansible / ansible-playbook
|
||||
- rsync, ssh, scp
|
||||
- openssl
|
||||
- dig / dnsutils
|
||||
|
||||
### In-repo dependency style
|
||||
- Python code is effectively stdlib-first
|
||||
- no `requirements.txt`, `pyproject.toml`, or `package.json`
|
||||
- operational dependencies live mostly in docs and scripts rather than a declared manifest
|
||||
|
||||
## Deployment
|
||||
|
||||
### Intended production path
|
||||
Browser -> nginx TLS -> static webroot + `/api/*` reverse proxy -> Hermes on `127.0.0.1:8644`
|
||||
|
||||
### Main deployment commands
|
||||
- `make deploy`
|
||||
- `make deploy-bash`
|
||||
- `make push`
|
||||
- `make check`
|
||||
- `bash deploy/deploy.sh`
|
||||
- `cd deploy && ansible-playbook -i inventory.ini playbook.yml`
|
||||
|
||||
### Operational files
|
||||
- `deploy/nginx.conf`
|
||||
- `deploy/playbook.yml`
|
||||
- `deploy/deploy.sh`
|
||||
- `deploy/hermes-gateway.service`
|
||||
- `resilience/health-check.sh`
|
||||
- `resilience/service-restart.sh`
|
||||
|
||||
### Deployment reality check
|
||||
The repo's deploy surface is not fully coherent:
|
||||
- `deploy/deploy.sh` is the most complete operational path
|
||||
- `deploy/playbook.yml` provisions nginx/site/firewall/SSL but does not manage `hermes-gateway.service`
|
||||
- resilience scripts still target port `8000`, not the real gateway at `8644`
|
||||
- `crisis-offline.html` is required by `sw.js`, but full deploy paths do not appear to ship it consistently
|
||||
|
||||
## Technical Debt
|
||||
|
||||
### Highest-priority debt
|
||||
1. Fix the `lastUserMessage` scope bug in `index.html`.
|
||||
2. Fix overlay background selector drift (`.app` vs `#app`, missing `#chat`).
|
||||
3. Fix `/about` route drift.
|
||||
4. Add pytest to Gitea CI.
|
||||
5. Make deploy paths ship the same artifact set, including `crisis-offline.html`.
|
||||
6. Make the recommended Ansible path actually manage `hermes-gateway.service`.
|
||||
7. Align or remove resilience scripts targeting the wrong port/service.
|
||||
8. Resolve doc drift:
|
||||
- ARCHITECTURE says “close tab = gone,” but implementation uses `localStorage`
|
||||
- BACKEND_SETUP still says 49 tests, while current verified suite is 115 + 3 subtests
|
||||
- audit docs understate current automation coverage
|
||||
|
||||
### Strategic debt
|
||||
- Duplicate crisis logic across browser and backend
|
||||
- Parallel prompt-routing mechanisms (`response.py` and `compassion_router.py`)
|
||||
- Legacy compatibility layers that still matter but are not first-class tested
|
||||
- No declared dependency manifest for operator tooling
|
||||
- No true E2E browser validation of the core conversation loop
|
||||
|
||||
## Bottom Line
|
||||
|
||||
The Door is not just a static landing page. It is a small but layered safety system with three cores:
|
||||
- a browser-first crisis chat UI
|
||||
- a canonical Python crisis package
|
||||
- a thin nginx/Hermes deployment shell
|
||||
|
||||
Its design is morally serious and operationally pragmatic. Its main weaknesses are not missing ambition; they are drift, duplication, and shallow verification at the exact seams where the browser, backend, and deploy layer meet.
|
||||
Reference in New Issue
Block a user