fix: polish sanitizer and repair messaging

Agent-Logs-Url: https://github.com/MemPalace/mempalace/sessions/775f2fc4-3051-462e-8586-6d694b55da0d

Co-authored-by: igorls <4753812+igorls@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-04-12 22:24:41 +00:00
committed by Igor Lins e Silva
parent d2d4e62543
commit 248ecd98f1
3 changed files with 16 additions and 5 deletions
+2 -1
View File
@@ -228,7 +228,8 @@ def cmd_repair(args):
if os.path.exists(backup_path):
if not contains_palace_database(backup_path):
print(
" Cannot proceed: backup path exists but is not a valid palace database. "
" Cannot proceed: backup path exists but does not contain a valid palace backup "
"(expected chroma.sqlite3). "
f"Please remove or rename: {backup_path}"
)
return
+10 -2
View File
@@ -67,13 +67,21 @@ def sanitize_query(raw_query: str) -> dict:
raw_query = raw_query.strip()
original_length = len(raw_query)
def _strip_wrapping_quotes(candidate: str) -> str:
candidate = candidate.strip()
while candidate[:1] in {"'", '"'} or candidate[-1:] in {"'", '"'}:
candidate = candidate.strip("\"'")
if not candidate:
return ""
return candidate
def _trim_candidate(candidate: str) -> str:
candidate = candidate.strip().strip("\"'")
candidate = _strip_wrapping_quotes(candidate)
if len(candidate) <= MAX_QUERY_LENGTH:
return candidate
nested_fragments = [
frag.strip().strip("\"'") for frag in _SENTENCE_SPLIT.split(candidate) if frag.strip()
_strip_wrapping_quotes(frag) for frag in _SENTENCE_SPLIT.split(candidate) if frag.strip()
]
for frag in reversed(nested_fragments):
if MIN_QUERY_LENGTH <= len(frag) <= MAX_QUERY_LENGTH:
+4 -2
View File
@@ -22,8 +22,10 @@ def test_migrate_aborts_without_confirmation(tmp_path, capsys):
palace_dir.mkdir()
(palace_dir / "chroma.sqlite3").write_text("db")
mock_chromadb = SimpleNamespace(__version__="0.6.0", PersistentClient=MagicMock())
mock_chromadb.PersistentClient.side_effect = Exception("unreadable")
mock_chromadb = SimpleNamespace(
__version__="0.6.0",
PersistentClient=MagicMock(side_effect=Exception("unreadable")),
)
with (
patch.dict("sys.modules", {"chromadb": mock_chromadb}),