From bb204f2c6c88158bb81a6d94801282cbd5e84283 Mon Sep 17 00:00:00 2001 From: Shivering Ocelot Date: Sat, 6 Jun 2026 15:03:04 -0500 Subject: [PATCH] cleanup, future database sketches --- backend/src/database.py | 13 ++++++ backend/test_cancellation.py | 74 ---------------------------------- simple_test_cancellation.py | 78 ------------------------------------ test_cancellation.py | 49 ---------------------- 4 files changed, 13 insertions(+), 201 deletions(-) delete mode 100644 backend/test_cancellation.py delete mode 100644 simple_test_cancellation.py delete mode 100644 test_cancellation.py diff --git a/backend/src/database.py b/backend/src/database.py index 48520ed..d53f6c2 100644 --- a/backend/src/database.py +++ b/backend/src/database.py @@ -63,6 +63,7 @@ class Agent(models.Model): agentname = fields.CharField(max_length=100, null=True) visibility = fields.IntField(default=0) permissions = fields.TextField(default="") + # DEPRECATED: Use AgentResources instead main_chat = fields.ForeignKeyField("models.Chat", related_name="main_agents",null=True) name = fields.CharField(max_length=255) @@ -137,6 +138,17 @@ class AgentResource(models.Model): class Meta: table = "agent_resources" +# class UserResource(models.Model): +# id = fields.IntField(pk=True) +# user = fields.ForeignKeyField("models.User", related_name="resources") + +# kind = fields.CharField(max_length=50) +# key = fields.CharField(max_length=100) +# value = fields.JSONField(null=True) + +# class Meta: +# table = "user_resources" + class MessageDatum(models.Model): id = fields.IntField(pk=True) message = fields.ForeignKeyField("models.Message", related_name="data") @@ -148,6 +160,7 @@ class MessageDatum(models.Model): class Model(models.Model): id = fields.IntField(pk=True) + #user = fields.ForeignKeyField("models.User", null=True) name = fields.CharField(max_length=255) kind = fields.CharField(max_length=50) value = fields.JSONField(null=True) \ No newline at end of file diff --git a/backend/test_cancellation.py b/backend/test_cancellation.py deleted file mode 100644 index 3259190..0000000 --- a/backend/test_cancellation.py +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/env python3 -""" -Simple test script to verify agent run cancellation functionality. -""" - -import sys -import os -import time - -# Mock the dependencies we don't need -class MockApp: - def __init__(self): - self.data_directory = "/tmp/horde_test" - self.tmp = MockTmpState() - self.event_listeners = [] - - def emit_event(self, name, data=None): - pass - -class MockTmpState: - def __init__(self): - self.runs = {} - -# Mock the generate_tmp_id function -def mock_generate_tmp_id(app): - return f"tmp-run-{int(time.time())}" - -# Monkey patch the temporary module -import temporary -temporary.generate_tmp_id = mock_generate_tmp_id - -from agent import AgentRun - -async def test_cancellation(): - print("Testing agent run cancellation...") - - # Create a mock app - app = MockApp() - - # Create an agent run - run = AgentRun.create(app, agent_id="test-agent", user_id="test-user") - print(f"Created agent run: {run.id}") - - # Test that the run is not cancelled initially - assert not run.cancelled, "Run should not be cancelled initially" - print("✓ Run is not cancelled initially") - - # Test cancellation - run.cancel() - assert run.cancelled, "Run should be cancelled after calling cancel()" - assert run.done, "Run should be marked as done after cancellation" - print("✓ Run is cancelled and marked as done") - - # Test that calling cancel again doesn't cause issues - run.cancel() - print("✓ Multiple cancel calls work correctly") - - # Test that the run has the expected attributes - assert hasattr(run, 'task'), "Run should have a task attribute" - assert hasattr(run, 'thread'), "Run should have a thread attribute" - assert hasattr(run, 'cancelled'), "Run should have a cancelled attribute" - print("✓ Run has all required cancellation attributes") - - # Test serialization - serialized = run.serialize() - assert serialized['id'] == run.id, "Serialized run should have correct ID" - assert serialized['done'] == True, "Serialized run should be marked as done" - print("✓ Run serialization works correctly") - - print("All tests passed! Cancellation functionality is working correctly.") - -if __name__ == "__main__": - import asyncio - asyncio.run(test_cancellation()) \ No newline at end of file diff --git a/simple_test_cancellation.py b/simple_test_cancellation.py deleted file mode 100644 index 24d5c4d..0000000 --- a/simple_test_cancellation.py +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/env python3 -""" -Simple test script to verify agent run cancellation functionality. -""" - -import sys -import os -import time -import json - -# Add the backend directory to the path -sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'backend')) - -# Mock the dependencies we don't need -class MockApp: - def __init__(self): - self.data_directory = "/tmp/horde_test" - self.tmp = MockTmpState() - self.event_listeners = [] - - def emit_event(self, name, data=None): - pass - -class MockTmpState: - def __init__(self): - self.runs = {} - -# Mock the generate_tmp_id function -def mock_generate_tmp_id(app): - return f"tmp-run-{int(time.time())}" - -# Monkey patch the temporary module -import backend.src.temporary as temp_module -temp_module.generate_tmp_id = mock_generate_tmp_id - -from backend.src.agent import AgentRun - -async def test_cancellation(): - print("Testing agent run cancellation...") - - # Create a mock app - app = MockApp() - - # Create an agent run - run = AgentRun.create(app, agent_id="test-agent", user_id="test-user") - print(f"Created agent run: {run.id}") - - # Test that the run is not cancelled initially - assert not run.cancelled, "Run should not be cancelled initially" - print("✓ Run is not cancelled initially") - - # Test cancellation - run.cancel() - assert run.cancelled, "Run should be cancelled after calling cancel()" - assert run.done, "Run should be marked as done after cancellation" - print("✓ Run is cancelled and marked as done") - - # Test that calling cancel again doesn't cause issues - run.cancel() - print("✓ Multiple cancel calls work correctly") - - # Test that the run has the expected attributes - assert hasattr(run, 'task'), "Run should have a task attribute" - assert hasattr(run, 'thread'), "Run should have a thread attribute" - assert hasattr(run, 'cancelled'), "Run should have a cancelled attribute" - print("✓ Run has all required cancellation attributes") - - # Test serialization - serialized = run.serialize() - assert serialized['id'] == run.id, "Serialized run should have correct ID" - assert serialized['done'] == True, "Serialized run should be marked as done" - print("✓ Run serialization works correctly") - - print("All tests passed! Cancellation functionality is working correctly.") - -if __name__ == "__main__": - import asyncio - asyncio.run(test_cancellation()) \ No newline at end of file diff --git a/test_cancellation.py b/test_cancellation.py deleted file mode 100644 index 4b10107..0000000 --- a/test_cancellation.py +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env python3 -""" -Simple test script to verify agent run cancellation functionality. -""" - -import asyncio -import sys -import os - -# Add the backend directory to the path -sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'backend')) - -from src.app import App -from src.agent import AgentRun - -async def test_cancellation(): - print("Testing agent run cancellation...") - - # Create a mock app - app = App(data_directory="/tmp/horde_test") - - # Create an agent run - run = AgentRun.create(app, agent_id="test-agent", user_id="test-user") - print(f"Created agent run: {run.id}") - - # Test that the run is not cancelled initially - assert not run.cancelled, "Run should not be cancelled initially" - print("✓ Run is not cancelled initially") - - # Test cancellation - run.cancel() - assert run.cancelled, "Run should be cancelled after calling cancel()" - assert run.done, "Run should be marked as done after cancellation" - print("✓ Run is cancelled and marked as done") - - # Test that calling cancel again doesn't cause issues - run.cancel() - print("✓ Multiple cancel calls work correctly") - - # Test that the run has the expected attributes - assert hasattr(run, 'task'), "Run should have a task attribute" - assert hasattr(run, 'thread'), "Run should have a thread attribute" - assert hasattr(run, 'cancelled'), "Run should have a cancelled attribute" - print("✓ Run has all required cancellation attributes") - - print("All tests passed! Cancellation functionality is working correctly.") - -if __name__ == "__main__": - asyncio.run(test_cancellation()) \ No newline at end of file