fix(headless): Apply review suggestions for track 'manual_slop_headless_20260225'

This commit is contained in:
2026-02-25 13:33:59 -05:00
parent 63fd391dff
commit 9b50bfa75e
2 changed files with 40 additions and 6 deletions

View File

@@ -11,6 +11,11 @@ class TestHeadlessAPI(unittest.TestCase):
patch('gui_2.ai_client.set_provider'), \
patch('gui_2.session_logger.close_session'):
self.app_instance = gui_2.App()
# Set a default API key for tests
self.test_api_key = "test-secret-key"
self.app_instance.config["headless"] = {"api_key": self.test_api_key}
self.headers = {"X-API-KEY": self.test_api_key}
# Clear any leftover state
self.app_instance._pending_actions = {}
self.app_instance._pending_dialog = None
@@ -51,7 +56,7 @@ class TestHeadlessAPI(unittest.TestCase):
}
}]
response = self.client.post("/api/v1/generate", json=payload)
response = self.client.post("/api/v1/generate", json=payload, headers=self.headers)
self.assertEqual(response.status_code, 200)
data = response.json()
self.assertEqual(data["text"], "Hello from Mock AI")
@@ -64,7 +69,7 @@ class TestHeadlessAPI(unittest.TestCase):
dialog = gui_2.ConfirmDialog("dir", ".")
self.app_instance._pending_actions[dialog._uid] = dialog
response = self.client.get("/api/v1/pending_actions")
response = self.client.get("/api/v1/pending_actions", headers=self.headers)
self.assertEqual(response.status_code, 200)
data = response.json()
self.assertEqual(len(data), 1)
@@ -77,7 +82,7 @@ class TestHeadlessAPI(unittest.TestCase):
self.app_instance._pending_actions[dialog._uid] = dialog
payload = {"approved": True}
response = self.client.post("/api/v1/confirm/test-confirm-id", json=payload)
response = self.client.post("/api/v1/confirm/test-confirm-id", json=payload, headers=self.headers)
self.assertEqual(response.status_code, 200)
self.assertTrue(dialog._done)
self.assertTrue(dialog._approved)
@@ -90,7 +95,7 @@ class TestHeadlessAPI(unittest.TestCase):
dummy_log.write_text("dummy content")
try:
response = self.client.get("/api/v1/sessions")
response = self.client.get("/api/v1/sessions", headers=self.headers)
self.assertEqual(response.status_code, 200)
data = response.json()
self.assertIn("test_session_api.log", data)
@@ -99,12 +104,19 @@ class TestHeadlessAPI(unittest.TestCase):
dummy_log.unlink()
def test_get_context_endpoint(self):
response = self.client.get("/api/v1/context")
response = self.client.get("/api/v1/context", headers=self.headers)
self.assertEqual(response.status_code, 200)
data = response.json()
self.assertIn("files", data)
self.assertIn("screenshots", data)
self.assertIn("files_base_dir", data)
def test_endpoint_no_api_key_configured(self):
# Test the security fix specifically
with patch.dict(self.app_instance.config, {"headless": {"api_key": ""}}):
response = self.client.get("/status", headers=self.headers)
self.assertEqual(response.status_code, 403)
self.assertEqual(response.json()["detail"], "API Key not configured on server")
if __name__ == "__main__":
unittest.main()