mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-14 16:16:48 +00:00
feat(wiki): wiki_pages table + repository + targeted chunk delete
Migration 0023_wiki_pages (source-scoped; version/content_hash/embed_status; FK source_id->sources ON DELETE CASCADE; UNIQUE(source_id,path) + prefix index). WikiPagesRepository: path-keyed CRUD with content-hash short-circuit, version bump, and move-with-reject. BaseVectorStore.delete_chunks_by_source_path (loop default) + parameterized pgvector override (DELETE WHERE source_id=%s AND metadata->>'source'=%s). Unit 1 of F-Wiki.
This commit is contained in:
1 parent
a709b7ccdc
commit
8aa0facf4a
8 files changed
+576
No files matched your search
@@ -331,6 +331,41 @@ class TestPGVectorStoreDeleteChunk:
|
||||
assert result is False
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
class TestPGVectorStoreDeleteChunksBySourcePath:
|
||||
def test_targeted_delete_is_parameterized(self):
|
||||
store, mock_conn, mock_cursor, _ = _make_store(source_id="src1")
|
||||
mock_cursor.rowcount = 3
|
||||
|
||||
deleted = store.delete_chunks_by_source_path("/docs/page.md")
|
||||
|
||||
assert deleted == 3
|
||||
sql, params = mock_cursor.execute.call_args[0]
|
||||
# Single targeted DELETE; the path is a bound param, never interpolated.
|
||||
assert "/docs/page.md" not in sql
|
||||
assert "DELETE FROM" in sql
|
||||
assert "metadata->>'source' = %s" in sql
|
||||
assert "source_id = %s" in sql
|
||||
assert params == ("src1", "/docs/page.md")
|
||||
mock_conn.commit.assert_called_once()
|
||||
|
||||
def test_returns_zero_when_no_match(self):
|
||||
store, mock_conn, mock_cursor, _ = _make_store(source_id="src1")
|
||||
mock_cursor.rowcount = 0
|
||||
|
||||
assert store.delete_chunks_by_source_path("/missing.md") == 0
|
||||
mock_conn.commit.assert_called_once()
|
||||
|
||||
def test_rolls_back_and_raises_on_error(self):
|
||||
store, mock_conn, mock_cursor, _ = _make_store()
|
||||
mock_cursor.execute.side_effect = Exception("delete failed")
|
||||
|
||||
with pytest.raises(Exception, match="delete failed"):
|
||||
store.delete_chunks_by_source_path("/x.md")
|
||||
|
||||
mock_conn.rollback.assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
class TestPGVectorStoreConnection:
|
||||
def test_get_connection_creates_new_when_closed(self):
|
||||
|
||||
Reference in new issue
Block a user