From 108b04f1f7a8315d4ab5bbf2624104c0495b8fc4 Mon Sep 17 00:00:00 2001 From: Protocol Zero <257158451+Protocol-zero-0@users.noreply.github.com> Date: Fri, 12 Jun 2026 22:40:47 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20Tier1=20=E5=9C=A8=20Postgr?= =?UTF-8?q?es=20=E4=B8=8A=E5=B4=A9=E6=BA=83:=E4=BF=A1=E5=8F=B7=E8=A1=8C?= =?UTF-8?q?=E5=90=AB=20datetime=20=E6=97=A0=E6=B3=95=20JSON=20=E5=BA=8F?= =?UTF-8?q?=E5=88=97=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _build_structure_prompt 对原始 DB 行 json.dumps 时,PG 返回的 datetime 对象(SQLite 为字符串)抛 TypeError,Tier1 发现整体失败。 加 default=str 保持双后端一致;附回归测试(datetime 行能进 prompt)。 --- agents/paradigm_agent.py | 4 +++- tests/test_paradigm_prompt.py | 39 +++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/test_paradigm_prompt.py diff --git a/agents/paradigm_agent.py b/agents/paradigm_agent.py index 30c7dfc..1f785c1 100644 --- a/agents/paradigm_agent.py +++ b/agents/paradigm_agent.py @@ -263,7 +263,9 @@ def _build_structure_prompt(signals: dict) -> str: continue sections.append(f"\n## {title}") for row in rows[:10]: - sections.append(f"- {json.dumps(row, ensure_ascii=True)[:220]}") + # Postgres rows carry datetime objects (SQLite returns strings); + # default=str keeps prompt building backend-agnostic. + sections.append(f"- {json.dumps(row, ensure_ascii=True, default=str)[:220]}") return "\n".join(sections) diff --git a/tests/test_paradigm_prompt.py b/tests/test_paradigm_prompt.py new file mode 100644 index 0000000..e514e86 --- /dev/null +++ b/tests/test_paradigm_prompt.py @@ -0,0 +1,39 @@ +"""_build_structure_prompt must handle DB rows from both backends. + +Postgres returns datetime objects in signal rows where SQLite returns +strings; prompt building must not crash on either.""" + +from __future__ import annotations + +import os +import unittest +from datetime import datetime + +os.environ["DEEPGRAPH_DATABASE_URL"] = "" # force SQLite tmpdir; never touch a real DB from the environment + + +class StructurePromptTest(unittest.TestCase): + def test_rows_with_datetime_values(self): + from agents.paradigm_agent import _build_structure_prompt + + signals = { + "entity_overlaps": [], + "pattern_matches": [], + "contradiction_clusters": [], + "taxonomy_map": [], + "hidden_variable_bridges": [ + { + "entity": "gaussian splatting", + "node_a": "cv.3d", + "node_b": "cv.sfm", + "created_at": datetime(2026, 6, 12, 12, 0, 0), + } + ], + } + prompt = _build_structure_prompt(signals) + self.assertIn("gaussian splatting", prompt) + self.assertIn("2026-06-12", prompt) + + +if __name__ == "__main__": + unittest.main()