deploy ProspectOS workspace v7 final
This commit is contained in:
@@ -360,7 +360,12 @@ class BrowserOnlyAppTests(unittest.TestCase):
|
||||
status, body = self.request("POST", "/api/prospects/1/message", {"offer": "Gold Plus hosting at R119/month with a free one-page website.", "tone": "consultative", "goal": "review"})
|
||||
self.assertEqual(status, 200)
|
||||
request_payload = http_json.call_args.args[2]
|
||||
prompt = json.loads(request_payload["messages"][1]["content"])
|
||||
self.assertIn('"tone": "consultative"', request_payload["messages"][1]["content"])
|
||||
self.assertIn("client_specific_strategy", prompt["evidence"])
|
||||
self.assertIn("private planning notes", request_payload["messages"][0]["content"])
|
||||
self.assertIn("Do not mention Google", request_payload["messages"][0]["content"])
|
||||
self.assertEqual(request_payload["temperature"], 0.65)
|
||||
self.assertIn("consultative and helpful", request_payload["messages"][0]["content"])
|
||||
self.assertEqual(body["unknowns"], ["Confirm the preferred contact person"])
|
||||
self.assertEqual(body["evidence_used"], ["prospect_record", "public_maps_listing", "public_email_listing"])
|
||||
@@ -368,6 +373,17 @@ class BrowserOnlyAppTests(unittest.TestCase):
|
||||
self.assertEqual(json.loads(saved[0]), body["unknowns"])
|
||||
self.assertEqual(json.loads(saved[1]), body["evidence_used"])
|
||||
|
||||
def test_message_style_pass_removes_stock_openers_without_rewriting_facts(self):
|
||||
text = server._clean_generated_message(
|
||||
"Good day Acme Plumbing,\n\nI hope you are well. I noticed your business listing does not show a website.\n\nKind regards",
|
||||
"Acme Plumbing",
|
||||
)
|
||||
self.assertTrue(text.startswith("Hi Acme Plumbing,"))
|
||||
self.assertNotIn("I hope you are well", text)
|
||||
self.assertNotIn("I noticed your business", text)
|
||||
self.assertIn("does not show a website", text)
|
||||
self.assertIn("Kind regards", text)
|
||||
|
||||
def test_email_draft_can_include_latest_mockup_link(self):
|
||||
conn = server.db()
|
||||
conn.execute("INSERT INTO prospects(name,domain,category,discovered_at) VALUES(?,?,?,?)", ("Acme", "maps:acme", "plumber", server.now()))
|
||||
@@ -383,6 +399,52 @@ class BrowserOnlyAppTests(unittest.TestCase):
|
||||
self.assertIn("mockup_preview", body["evidence_used"])
|
||||
self.assertTrue(body["mockup_url"])
|
||||
|
||||
def test_email_draft_chat_revision_uses_current_text_and_persists(self):
|
||||
conn = server.db()
|
||||
conn.execute(
|
||||
"INSERT INTO prospects(name,domain,search_category,category,address,maps_url,website_status,emails,opportunity_score,ai_subject,ai_message,ai_offer,discovered_at) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)",
|
||||
("Acme Plumbing", "maps:chat", "plumbers", "Plumber", "Cape Town", "https://maps.example/acme", "no_detected_website", "acme@gmail.com", 88,
|
||||
"A practical website idea for Acme", "Good day Acme Plumbing,\n\nYour public listing does not show a dedicated website. We can help.\n\nKind regards", "Gold Plus hosting at R119/month with a free rebuild.", server.now()),
|
||||
)
|
||||
for key, value in (("AI_PROVIDER", "custom"), ("AI_BASE_URL", "https://ai.example/v1"), ("AI_MODEL", "test-model"), ("AI_API_KEY", "test-key")):
|
||||
conn.execute("INSERT INTO settings(key,value,updated_at) VALUES(?,?,?)", (key, value, server.now()))
|
||||
conn.commit(); conn.close()
|
||||
content = json.dumps({
|
||||
"subject": "A softer website idea for Acme",
|
||||
"message": "Good day Acme Plumbing,\n\nYour public listing does not show a dedicated website. We can help with Gold Plus hosting at R119/month and a free rebuild. Would a short chat be useful?\n\nKind regards",
|
||||
"rationale": "Shortened the opening and softened the call to action as requested.",
|
||||
"recommended_offer": "Gold Plus hosting at R119/month with a free rebuild.",
|
||||
"unknowns": ["Confirm the preferred contact person"],
|
||||
"evidence_used": ["prospect_record", "public_maps_listing", "public_email_listing"],
|
||||
"follow_up": "Check the wording and offer before sending.",
|
||||
})
|
||||
with patch("api.server.http_json", return_value={"choices": [{"message": {"content": content}}]}) as http_json:
|
||||
status, body = self.request("POST", "/api/prospects/1/message/edit", {
|
||||
"instruction": "Make it warmer, shorter, and use a softer call to action.",
|
||||
"current_subject": "A practical website idea for Acme",
|
||||
"current_message": "Good day Acme Plumbing,\n\nYour public listing does not show a dedicated website. We can help.\n\nKind regards",
|
||||
"offer": "Gold Plus hosting at R119/month with a free rebuild.",
|
||||
"tone": "warm",
|
||||
"goal": "conversation",
|
||||
"include_mockup": False,
|
||||
})
|
||||
self.assertEqual(status, 200)
|
||||
self.assertEqual(body["subject"], "A softer website idea for Acme")
|
||||
self.assertIn("softened", body["rationale"])
|
||||
request_payload = http_json.call_args.args[2]
|
||||
prompt = json.loads(request_payload["messages"][1]["content"])
|
||||
self.assertEqual(prompt["current_draft"]["subject"], "A practical website idea for Acme")
|
||||
self.assertIn("Make it warmer", prompt["edit_instruction"])
|
||||
self.assertEqual(request_payload["max_tokens"], 1000)
|
||||
self.assertIn("cannot add facts", request_payload["messages"][0]["content"])
|
||||
saved = server.db().execute("SELECT ai_subject,ai_message,ai_offer FROM prospects WHERE id=1").fetchone()
|
||||
self.assertEqual(saved[0], body["subject"])
|
||||
self.assertEqual(saved[1], body["message"])
|
||||
self.assertEqual(saved[2], "Gold Plus hosting at R119/month with a free rebuild.")
|
||||
status, logs = self.request("GET", "/api/logs?kind=ai")
|
||||
self.assertEqual(status, 200)
|
||||
self.assertTrue(any(item["event"] == "message_revision_completed" for item in logs["items"]))
|
||||
|
||||
def test_logs_capture_api_actions_and_redact_credentials(self):
|
||||
server.record_log("ai", "test_ai_call", details={"api_key": "do-not-store", "model": "test", "prompt": "hello"})
|
||||
status, body = self.request("POST", "/api/logs", {"action": "ui_test", "details": {"button": "test"}})
|
||||
|
||||
Reference in New Issue
Block a user