diff --git a/.tmp/proof/document-delete-api.txt b/.tmp/proof/document-delete-api.txt new file mode 100644 index 0000000..549f970 --- /dev/null +++ b/.tmp/proof/document-delete-api.txt @@ -0,0 +1,168 @@ +Local SQLite and Chroma, fixed embeddings, Slack authentication mocked and API calls blocked. +No real tokens, remote databases, model calls or paid embeddings. Distances are fixture squared L2 values. +$ curl -sS -X GET http://127.0.0.1:18055/health -w ' +%{http_code}' +HTTP 200 +{ + "status": "healthy" +} + +$ curl -sS -X POST http://127.0.0.1:18055/api/documents -H 'Content-Type: application/json' -d '{"title": "VPN guide", "content": "Reset VPN via IT portal.", "source": "api"}' -w ' +%{http_code}' +HTTP 200 +{ + "id": 1, + "message": "Document added successfully" +} + +$ curl -sS -X POST http://127.0.0.1:18055/api/documents -H 'Content-Type: application/json' -d '{"title": "VPN guide", "content": "Reset VPN via IT portal.", "source": "api"}' -w ' +%{http_code}' +HTTP 200 +{ + "id": 2, + "message": "Document added successfully" +} + +$ curl -sS -X POST http://127.0.0.1:18055/api/retrieval/preview -H 'Content-Type: application/json' -d '{"question": "How do I reset VPN?"}' -w ' +%{http_code}' +HTTP 200 +{ + "question": "How do I reset VPN?", + "channel_id": null, + "top_k": 5, + "max_distance": null, + "items": [ + { + "content": "Reset VPN via IT portal.", + "metadata": { + "chunk": 0, + "document_id": 2, + "source": "api", + "title": "VPN guide" + }, + "distance": 1.0 + }, + { + "content": "Reset VPN via IT portal.", + "metadata": { + "chunk": 0, + "document_id": 1, + "source": "api", + "title": "VPN guide" + }, + "distance": 1.0 + } + ] +} + +Inject fixture Chroma deletion outage. +$ curl -sS -X DELETE http://127.0.0.1:18055/api/documents/1 -w ' +%{http_code}' +HTTP 503 +{ + "detail": { + "message": "Document deletion is unavailable", + "document_id": 1 + } +} + +$ curl -sS -X GET http://127.0.0.1:18055/api/documents/1 -w ' +%{http_code}' +HTTP 200 +{ + "id": 1, + "title": "VPN guide", + "content": "Reset VPN via IT portal.", + "source": "api", + "created_at": "2026-11-16T07:41:58.529092", + "updated_at": "2026-11-16T07:41:58.529098" +} + +Remove fixture outage and retry the same saved ID. +$ curl -sS -X DELETE http://127.0.0.1:18055/api/documents/1 -w ' +%{http_code}' +HTTP 200 +{ + "id": 1, + "message": "Document deleted successfully" +} + +$ curl -sS -X GET http://127.0.0.1:18055/api/documents/1 -w ' +%{http_code}' +HTTP 404 +{ + "detail": "Document not found" +} + +$ curl -sS -X POST http://127.0.0.1:18055/api/documents/1/index -w ' +%{http_code}' +HTTP 404 +{ + "detail": "Document not found" +} + +$ curl -sS -X DELETE http://127.0.0.1:18055/api/documents/1 -w ' +%{http_code}' +HTTP 404 +{ + "detail": "Document not found" +} + +$ curl -sS -X GET http://127.0.0.1:18055/api/documents -w ' +%{http_code}' +HTTP 200 +{ + "items": [ + { + "id": 2, + "title": "VPN guide", + "source": "api", + "created_at": "2026-11-16T07:41:58.577149", + "content_preview": "Reset VPN via IT portal." + } + ], + "total": 1, + "limit": 50, + "offset": 0 +} + +$ curl -sS -X POST http://127.0.0.1:18055/api/retrieval/preview -H 'Content-Type: application/json' -d '{"question": "How do I reset VPN?"}' -w ' +%{http_code}' +HTTP 200 +{ + "question": "How do I reset VPN?", + "channel_id": null, + "top_k": 5, + "max_distance": null, + "items": [ + { + "content": "Reset VPN via IT portal.", + "metadata": { + "chunk": 0, + "document_id": 2, + "source": "api", + "title": "VPN guide" + }, + "distance": 1.0 + } + ] +} + +$ curl -sS -X DELETE http://127.0.0.1:18055/api/documents/invalid -w ' +%{http_code}' +HTTP 422 +{ + "detail": [ + { + "type": "int_parsing", + "loc": [ + "path", + "document_id" + ], + "msg": "Input should be a valid integer, unable to parse string as an integer", + "input": "invalid" + } + ] +} + +All curl status, ownership, saved-record and raw-distance assertions passed. diff --git a/.tmp/proof/document-delete-backend-start.txt b/.tmp/proof/document-delete-backend-start.txt new file mode 100644 index 0000000..3d52d14 --- /dev/null +++ b/.tmp/proof/document-delete-backend-start.txt @@ -0,0 +1,50 @@ +[dev-backend] $ uv run uvicorn app.main:app --reload --host 127.0.0.1 --port 18… +/Users/johnny/.paseo/worktrees/0x03bguv/happy-whale/.tmp/offline-delete/sitecustomize.py:39: LangChainDeprecationWarning: The class `Chroma` was deprecated in LangChain 0.2.9 and will be removed in 1.0. An updated version of the class exists in the `langchain-chroma package and should be used instead. To use it run `pip install -U `langchain-chroma` and import as `from `langchain_chroma import Chroma``. + vector_store.vector_store = Chroma( +INFO: Will watch for changes in these directories: ['/Users/johnny/.paseo/worktrees/0x03bguv/happy-whale/backend'] +INFO: Uvicorn running on http://127.0.0.1:18055 (Press CTRL+C to quit) +INFO: Started reloader process [87286] using WatchFiles +/Users/johnny/.paseo/worktrees/0x03bguv/happy-whale/.tmp/offline-delete/sitecustomize.py:39: LangChainDeprecationWarning: The class `Chroma` was deprecated in LangChain 0.2.9 and will be removed in 1.0. An updated version of the class exists in the `langchain-chroma package and should be used instead. To use it run `pip install -U `langchain-chroma` and import as `from `langchain_chroma import Chroma``. + vector_store.vector_store = Chroma( +/Users/johnny/.paseo/worktrees/0x03bguv/happy-whale/.tmp/offline-delete/sitecustomize.py:39: LangChainDeprecationWarning: The class `Chroma` was deprecated in LangChain 0.2.9 and will be removed in 1.0. An updated version of the class exists in the `langchain-chroma package and should be used instead. To use it run `pip install -U `langchain-chroma` and import as `from `langchain_chroma import Chroma``. + vector_store.vector_store = Chroma( +INFO: Started server process [87737] +INFO: Waiting for application startup. +{"timestamp": "2026-11-16T07:41:52.160300+00:00", "level": "INFO", "service_name": "wingman-backend", "environment": "development", "service_version": "0.1.0", "logger": "app.main", "message": "Starting Wingman backend...", "event_type": "log", "request_id": null, "trace_id": null} +{"timestamp": "2026-11-16T07:41:52.239284+00:00", "level": "INFO", "service_name": "wingman-backend", "environment": "development", "service_version": "0.1.0", "logger": "app.main", "message": "Database initialized", "event_type": "log", "request_id": null, "trace_id": null} +INFO: Application startup complete. +INFO: 127.0.0.1:62699 - "GET /health HTTP/1.1" 200 OK +{"timestamp": "2026-11-16T07:41:58.493973+00:00", "level": "INFO", "service_name": "wingman-backend", "environment": "development", "service_version": "0.1.0", "logger": "wingman.wide_event", "message": "http_request", "event_type": "http_request", "request_id": "7a144586dd4f4bdf9b14585e02941495", "trace_id": "7a144586dd4f4bdf9b14585e02941495", "request_method": "GET", "request_path": "/health", "route": "/health", "status_code": 200, "duration_ms": 0.38, "error_class": null, "error_message": null, "sample_reason": "RANDOM"} +INFO: 127.0.0.1:62701 - "POST /api/documents HTTP/1.1" 200 OK +{"timestamp": "2026-11-16T07:41:58.559223+00:00", "level": "INFO", "service_name": "wingman-backend", "environment": "development", "service_version": "0.1.0", "logger": "wingman.wide_event", "message": "http_request", "event_type": "http_request", "request_id": "0c32a5e8891146d09f46a39bf5abb195", "trace_id": "0c32a5e8891146d09f46a39bf5abb195", "request_method": "POST", "request_path": "/api/documents", "route": "/api/documents", "status_code": 200, "duration_ms": 37.63, "error_class": null, "error_message": null, "sample_reason": "RANDOM"} +INFO: 127.0.0.1:62702 - "POST /api/documents HTTP/1.1" 200 OK +{"timestamp": "2026-11-16T07:41:58.581342+00:00", "level": "INFO", "service_name": "wingman-backend", "environment": "development", "service_version": "0.1.0", "logger": "wingman.wide_event", "message": "http_request", "event_type": "http_request", "request_id": "cd41ac9830af49e8b82be15c8c8d4af8", "trace_id": "cd41ac9830af49e8b82be15c8c8d4af8", "request_method": "POST", "request_path": "/api/documents", "route": "/api/documents", "status_code": 200, "duration_ms": 4.82, "error_class": null, "error_message": null, "sample_reason": "RANDOM"} +{"timestamp": "2026-11-16T07:41:58.601498+00:00", "level": "WARNING", "service_name": "wingman-backend", "environment": "development", "service_version": "0.1.0", "logger": "chromadb.segment.impl.vector.local_persistent_hnsw", "message": "Number of requested results 5 is greater than number of elements in index 2, updating n_results = 2", "event_type": "log", "request_id": "bfb92b5aa41f4174a40a7ad9a2b0fd0c", "trace_id": "bfb92b5aa41f4174a40a7ad9a2b0fd0c"} +INFO: 127.0.0.1:62703 - "POST /api/retrieval/preview HTTP/1.1" 200 OK +{"timestamp": "2026-11-16T07:41:58.602815+00:00", "level": "INFO", "service_name": "wingman-backend", "environment": "development", "service_version": "0.1.0", "logger": "wingman.wide_event", "message": "http_request", "event_type": "http_request", "request_id": "bfb92b5aa41f4174a40a7ad9a2b0fd0c", "trace_id": "bfb92b5aa41f4174a40a7ad9a2b0fd0c", "request_method": "POST", "request_path": "/api/retrieval/preview", "route": "/api/retrieval/preview", "status_code": 200, "duration_ms": 2.32, "error_class": null, "error_message": null, "sample_reason": "RANDOM"} +{"timestamp": "2026-11-16T07:41:58.634815+00:00", "level": "ERROR", "service_name": "wingman-backend", "environment": "development", "service_version": "0.1.0", "logger": "app.main", "message": "Deleting saved document 1 failed", "event_type": "log", "request_id": "b0ad8b4da6614333b4bfd99593b0a3f7", "trace_id": "b0ad8b4da6614333b4bfd99593b0a3f7", "error_class": "RuntimeError", "error_message": "Fixture Chroma deletion outage", "error_stack_hash": "973fea20d9548f56"} +INFO: 127.0.0.1:62704 - "DELETE /api/documents/1 HTTP/1.1" 503 Service Unavailable +{"timestamp": "2026-11-16T07:41:58.636470+00:00", "level": "INFO", "service_name": "wingman-backend", "environment": "development", "service_version": "0.1.0", "logger": "wingman.wide_event", "message": "http_request", "event_type": "http_request", "request_id": "b0ad8b4da6614333b4bfd99593b0a3f7", "trace_id": "b0ad8b4da6614333b4bfd99593b0a3f7", "request_method": "DELETE", "request_path": "/api/documents/1", "route": "/api/documents/1", "status_code": 503, "duration_ms": 6.17, "error_class": null, "error_message": null, "sample_reason": "ERROR"} +INFO: 127.0.0.1:62705 - "GET /api/documents/1 HTTP/1.1" 200 OK +{"timestamp": "2026-11-16T07:41:58.655289+00:00", "level": "INFO", "service_name": "wingman-backend", "environment": "development", "service_version": "0.1.0", "logger": "wingman.wide_event", "message": "http_request", "event_type": "http_request", "request_id": "a5861f85e1fe4e88839082ac547b3030", "trace_id": "a5861f85e1fe4e88839082ac547b3030", "request_method": "GET", "request_path": "/api/documents/1", "route": "/api/documents/1", "status_code": 200, "duration_ms": 1.4, "error_class": null, "error_message": null, "sample_reason": "RANDOM"} +INFO: 127.0.0.1:62706 - "DELETE /api/documents/1 HTTP/1.1" 200 OK +{"timestamp": "2026-11-16T07:41:58.674830+00:00", "level": "INFO", "service_name": "wingman-backend", "environment": "development", "service_version": "0.1.0", "logger": "wingman.wide_event", "message": "http_request", "event_type": "http_request", "request_id": "b35ccada3c1048ddaf8779e3365b0b68", "trace_id": "b35ccada3c1048ddaf8779e3365b0b68", "request_method": "DELETE", "request_path": "/api/documents/1", "route": "/api/documents/1", "status_code": 200, "duration_ms": 5.49, "error_class": null, "error_message": null, "sample_reason": "RANDOM"} +INFO: 127.0.0.1:62708 - "GET /api/documents/1 HTTP/1.1" 404 Not Found +{"timestamp": "2026-11-16T07:41:58.692042+00:00", "level": "INFO", "service_name": "wingman-backend", "environment": "development", "service_version": "0.1.0", "logger": "wingman.wide_event", "message": "http_request", "event_type": "http_request", "request_id": "b33891bb22db4a31a5912b4fcb7ab52e", "trace_id": "b33891bb22db4a31a5912b4fcb7ab52e", "request_method": "GET", "request_path": "/api/documents/1", "route": "/api/documents/1", "status_code": 404, "duration_ms": 1.15, "error_class": null, "error_message": null, "sample_reason": "RANDOM"} +INFO: 127.0.0.1:62709 - "POST /api/documents/1/index HTTP/1.1" 404 Not Found +{"timestamp": "2026-11-16T07:41:58.710124+00:00", "level": "INFO", "service_name": "wingman-backend", "environment": "development", "service_version": "0.1.0", "logger": "wingman.wide_event", "message": "http_request", "event_type": "http_request", "request_id": "b0cd35c3dfc34f379a245c5f06590b14", "trace_id": "b0cd35c3dfc34f379a245c5f06590b14", "request_method": "POST", "request_path": "/api/documents/1/index", "route": "/api/documents/1/index", "status_code": 404, "duration_ms": 1.17, "error_class": null, "error_message": null, "sample_reason": "RANDOM"} +INFO: 127.0.0.1:62710 - "DELETE /api/documents/1 HTTP/1.1" 404 Not Found +{"timestamp": "2026-11-16T07:41:58.729168+00:00", "level": "INFO", "service_name": "wingman-backend", "environment": "development", "service_version": "0.1.0", "logger": "wingman.wide_event", "message": "http_request", "event_type": "http_request", "request_id": "1ff5261a18d5454d9b6273ec15a34854", "trace_id": "1ff5261a18d5454d9b6273ec15a34854", "request_method": "DELETE", "request_path": "/api/documents/1", "route": "/api/documents/1", "status_code": 404, "duration_ms": 1.14, "error_class": null, "error_message": null, "sample_reason": "RANDOM"} +INFO: 127.0.0.1:62711 - "GET /api/documents HTTP/1.1" 200 OK +{"timestamp": "2026-11-16T07:41:58.745716+00:00", "level": "INFO", "service_name": "wingman-backend", "environment": "development", "service_version": "0.1.0", "logger": "wingman.wide_event", "message": "http_request", "event_type": "http_request", "request_id": "090cbe7790714dd0b32d2a561314b97f", "trace_id": "090cbe7790714dd0b32d2a561314b97f", "request_method": "GET", "request_path": "/api/documents", "route": "/api/documents", "status_code": 200, "duration_ms": 3.25, "error_class": null, "error_message": null, "sample_reason": "RANDOM"} +{"timestamp": "2026-11-16T07:41:58.760629+00:00", "level": "WARNING", "service_name": "wingman-backend", "environment": "development", "service_version": "0.1.0", "logger": "chromadb.segment.impl.vector.local_persistent_hnsw", "message": "Number of requested results 5 is greater than number of elements in index 1, updating n_results = 1", "event_type": "log", "request_id": "c9ba233af74043d3b1367762dc607a62", "trace_id": "c9ba233af74043d3b1367762dc607a62"} +INFO: 127.0.0.1:62712 - "POST /api/retrieval/preview HTTP/1.1" 200 OK +{"timestamp": "2026-11-16T07:41:58.761697+00:00", "level": "INFO", "service_name": "wingman-backend", "environment": "development", "service_version": "0.1.0", "logger": "wingman.wide_event", "message": "http_request", "event_type": "http_request", "request_id": "c9ba233af74043d3b1367762dc607a62", "trace_id": "c9ba233af74043d3b1367762dc607a62", "request_method": "POST", "request_path": "/api/retrieval/preview", "route": "/api/retrieval/preview", "status_code": 200, "duration_ms": 2.13, "error_class": null, "error_message": null, "sample_reason": "RANDOM"} +INFO: 127.0.0.1:62713 - "DELETE /api/documents/invalid HTTP/1.1" 422 Unprocessable Content +{"timestamp": "2026-11-16T07:41:58.791505+00:00", "level": "INFO", "service_name": "wingman-backend", "environment": "development", "service_version": "0.1.0", "logger": "wingman.wide_event", "message": "http_request", "event_type": "http_request", "request_id": "29e0eeb1b8424ce08e7559ed3474c0df", "trace_id": "29e0eeb1b8424ce08e7559ed3474c0df", "request_method": "DELETE", "request_path": "/api/documents/invalid", "route": "/api/documents/invalid", "status_code": 422, "duration_ms": 0.6, "error_class": null, "error_message": null, "sample_reason": "RANDOM"} +INFO: Shutting down +INFO: Waiting for application shutdown. +{"timestamp": "2026-11-16T07:42:10.218428+00:00", "level": "INFO", "service_name": "wingman-backend", "environment": "development", "service_version": "0.1.0", "logger": "app.main", "message": "Shutting down Wingman backend...", "event_type": "log", "request_id": null, "trace_id": null} +INFO: Application shutdown complete. +INFO: Finished server process [87737] +INFO: Stopping reloader process [87286] diff --git a/.tmp/proof/document-delete-backend-tests.txt b/.tmp/proof/document-delete-backend-tests.txt new file mode 100644 index 0000000..673c002 --- /dev/null +++ b/.tmp/proof/document-delete-backend-tests.txt @@ -0,0 +1,294 @@ +[test-backend] $ uv run pytest tests/test_file_extraction_units.py tests/test_l… +============================= test session starts ============================== +platform darwin -- Python 3.13.13, pytest-9.0.2, pluggy-1.6.0 -- /Users/johnny/.paseo/worktrees/0x03bguv/happy-whale/backend/.venv/bin/python +cachedir: .pytest_cache +rootdir: /Users/johnny/.paseo/worktrees/0x03bguv/happy-whale/backend +configfile: pytest.ini (WARNING: ignoring pytest config in pyproject.toml!) +plugins: langsmith-0.5.2, anyio-4.12.0, asyncio-1.3.0 +asyncio: mode=Mode.STRICT, debug=False, asyncio_default_fixture_loop_scope=None, asyncio_default_test_loop_scope=function +collecting ... collected 221 items + +tests/test_file_extraction_units.py::test_extract_plain_text PASSED [ 0%] +tests/test_file_extraction_units.py::test_extract_markdown PASSED [ 0%] +tests/test_file_extraction_units.py::test_extract_python_file PASSED [ 1%] +tests/test_file_extraction_units.py::test_extract_json PASSED [ 1%] +tests/test_file_extraction_units.py::test_extract_csv PASSED [ 2%] +tests/test_file_extraction_units.py::test_extract_html PASSED [ 2%] +tests/test_file_extraction_units.py::test_extract_html_removes_scripts PASSED [ 3%] +tests/test_file_extraction_units.py::test_extract_with_encoding_errors PASSED [ 3%] +tests/test_file_extraction_units.py::test_extract_xml PASSED [ 4%] +tests/test_file_extraction_units.py::test_extract_yaml PASSED [ 4%] +tests/test_file_extraction_units.py::test_javascript_file_extraction PASSED [ 4%] +tests/test_file_extraction_units.py::test_typescript_file_extraction PASSED [ 5%] +tests/test_file_extraction_units.py::test_shell_script_extraction PASSED [ 5%] +tests/test_file_extraction_units.py::TestConversationIds::test_thread_conversation_id_format PASSED [ 6%] +tests/test_file_extraction_units.py::TestConversationIds::test_dm_conversation_id_format PASSED [ 6%] +tests/test_file_extraction_units.py::TestConversationIds::test_mention_conversation_id_format PASSED [ 7%] +tests/test_logging_config.py::test_json_schema_and_redaction_variants PASSED [ 7%] +tests/test_logging_config.py::test_error_hash_not_stack PASSED [ 8%] +tests/test_logging_config.py::test_wide_event_one_per_request PASSED [ 8%] +tests/test_logging.py::test_json_stdout_preserves_controls_and_avoids_duplicate_handlers[wingman-backend] PASSED [ 9%] +tests/test_logging.py::test_json_stdout_preserves_controls_and_avoids_duplicate_handlers[wingman-bot] PASSED [ 9%] +tests/test_logging.py::test_text_format_and_configured_level PASSED [ 9%] +tests/test_logging.py::test_api_keeps_backend_service_when_importing_bot PASSED [ 10%] +tests/test_agent_runtime.py::test_transport_retry_keeps_request_id PASSED [ 10%] +tests/test_agent_runtime.py::test_rag_routes_retrieved_context_and_stable_slack_identity PASSED [ 11%] +tests/test_agent_runtime.py::test_failed_job_surfaces_error PASSED [ 11%] +tests/test_rules.py::TestMatching::test_contains_is_case_insensitive PASSED [ 12%] +tests/test_rules.py::TestMatching::test_contains_needs_the_keyword PASSED [ 12%] +tests/test_rules.py::TestMatching::test_any_keyword_can_match PASSED [ 13%] +tests/test_rules.py::TestMatching::test_exact_needs_the_whole_question PASSED [ 13%] +tests/test_rules.py::TestMatching::test_regex_match PASSED [ 14%] +tests/test_rules.py::TestMatching::test_blank_question_never_matches PASSED [ 14%] +tests/test_rules.py::TestMatching::test_no_rules_is_a_no_op PASSED [ 14%] +tests/test_rules.py::TestOrderingAndEnabled::test_higher_priority_wins PASSED [ 15%] +tests/test_rules.py::TestOrderingAndEnabled::test_config_order_breaks_priority_ties PASSED [ 15%] +tests/test_rules.py::TestOrderingAndEnabled::test_disabled_rule_never_matches PASSED [ 16%] +tests/test_rules.py::TestConfigLoading::test_parse_valid_rules PASSED [ 16%] +tests/test_rules.py::TestConfigLoading::test_parse_skips_invalid_entries PASSED [ 17%] +tests/test_rules.py::TestConfigLoading::test_parse_skips_bad_regex PASSED [ 17%] +tests/test_rules.py::TestConfigLoading::test_parse_rejects_non_list PASSED [ 18%] +tests/test_rules.py::TestConfigLoading::test_load_from_json_text PASSED [ 18%] +tests/test_rules.py::TestConfigLoading::test_load_invalid_json_is_empty PASSED [ 19%] +tests/test_rules.py::TestConfigLoading::test_load_from_file_and_file_wins PASSED [ 19%] +tests/test_rules.py::TestConfigLoading::test_load_missing_file_is_empty PASSED [ 19%] +tests/test_rules.py::TestConfigLoading::test_from_settings_reads_both_fields PASSED [ 20%] +tests/test_rules.py::TestRagShortCircuit::test_matched_question_skips_retrieval_and_generation PASSED [ 20%] +tests/test_rules.py::TestRagShortCircuit::test_unmatched_question_still_uses_generation PASSED [ 21%] +tests/test_rules.py::TestSlackShortCircuit::test_matched_slack_question_skips_retrieval_and_carries_pinned_answer PASSED [ 21%] +tests/test_rules.py::TestSlackShortCircuit::test_unmatched_slack_question_uses_retrieval_without_pinned_answer PASSED [ 22%] +tests/test_conversations.py::TestListConversations::test_lists_summaries_most_recent_first PASSED [ 22%] +tests/test_conversations.py::TestListConversations::test_summary_counts_and_preview PASSED [ 23%] +tests/test_conversations.py::TestListConversations::test_pagination PASSED [ 23%] +tests/test_conversations.py::TestListConversations::test_channel_filter PASSED [ 23%] +tests/test_conversations.py::TestListConversations::test_channel_filter_scopes_preview_for_shared_conversation[C1] PASSED [ 24%] +tests/test_conversations.py::TestListConversations::test_channel_filter_scopes_preview_for_shared_conversation[C2] PASSED [ 24%] +tests/test_conversations.py::TestListConversations::test_unfiltered_preview_includes_latest_turn_across_channels PASSED [ 25%] +tests/test_conversations.py::TestListConversations::test_scoped_preview_breaks_timestamp_ties_by_latest_id PASSED [ 25%] +tests/test_conversations.py::TestListConversations::test_invalid_pagination_rejected PASSED [ 26%] +tests/test_conversations.py::TestListConversations::test_empty_database PASSED [ 26%] +tests/test_conversations.py::TestConversationDetail::test_returns_turns_in_chronological_order PASSED [ 27%] +tests/test_conversations.py::TestConversationDetail::test_detail_pagination PASSED [ 27%] +tests/test_conversations.py::TestConversationDetail::test_missing_conversation_is_404 PASSED [ 28%] +tests/test_conversations.py::TestConversationDetail::test_detail_invalid_pagination_rejected PASSED [ 28%] +tests/test_documents.py::TestListDocuments::test_lists_documents_most_recent_first PASSED [ 28%] +tests/test_documents.py::TestListDocuments::test_preview_and_fields PASSED [ 29%] +tests/test_documents.py::TestListDocuments::test_pagination PASSED [ 29%] +tests/test_documents.py::TestListDocuments::test_source_filter PASSED [ 30%] +tests/test_documents.py::TestListDocuments::test_invalid_pagination_rejected PASSED [ 30%] +tests/test_documents.py::TestListDocuments::test_empty_database PASSED [ 31%] +tests/test_documents.py::TestSearchDocuments::test_matches_title_case_insensitively_and_trims_query[vpn] PASSED [ 31%] +tests/test_documents.py::TestSearchDocuments::test_matches_title_case_insensitively_and_trims_query[VpN] PASSED [ 32%] +tests/test_documents.py::TestSearchDocuments::test_matches_title_case_insensitively_and_trims_query[ \tVPN\n ] PASSED [ 32%] +tests/test_documents.py::TestSearchDocuments::test_matches_content_beyond_the_preview PASSED [ 33%] +tests/test_documents.py::TestSearchDocuments::test_filters_before_counting_and_paginating PASSED [ 33%] +tests/test_documents.py::TestSearchDocuments::test_treats_sql_wildcards_and_escape_characters_literally[title-%] PASSED [ 33%] +tests/test_documents.py::TestSearchDocuments::test_treats_sql_wildcards_and_escape_characters_literally[title-_] PASSED [ 34%] +tests/test_documents.py::TestSearchDocuments::test_treats_sql_wildcards_and_escape_characters_literally[title-/] PASSED [ 34%] +tests/test_documents.py::TestSearchDocuments::test_treats_sql_wildcards_and_escape_characters_literally[title-100%] PASSED [ 35%] +tests/test_documents.py::TestSearchDocuments::test_treats_sql_wildcards_and_escape_characters_literally[title-setup_notes] PASSED [ 35%] +tests/test_documents.py::TestSearchDocuments::test_treats_sql_wildcards_and_escape_characters_literally[title-a/b] PASSED [ 36%] +tests/test_documents.py::TestSearchDocuments::test_treats_sql_wildcards_and_escape_characters_literally[title-' OR 1=1 --] PASSED [ 36%] +tests/test_documents.py::TestSearchDocuments::test_treats_sql_wildcards_and_escape_characters_literally[content-%] PASSED [ 37%] +tests/test_documents.py::TestSearchDocuments::test_treats_sql_wildcards_and_escape_characters_literally[content-_] PASSED [ 37%] +tests/test_documents.py::TestSearchDocuments::test_treats_sql_wildcards_and_escape_characters_literally[content-/] PASSED [ 38%] +tests/test_documents.py::TestSearchDocuments::test_treats_sql_wildcards_and_escape_characters_literally[content-100%] PASSED [ 38%] +tests/test_documents.py::TestSearchDocuments::test_treats_sql_wildcards_and_escape_characters_literally[content-setup_notes] PASSED [ 38%] +tests/test_documents.py::TestSearchDocuments::test_treats_sql_wildcards_and_escape_characters_literally[content-a/b] PASSED [ 39%] +tests/test_documents.py::TestSearchDocuments::test_treats_sql_wildcards_and_escape_characters_literally[content-' OR 1=1 --] PASSED [ 39%] +tests/test_documents.py::TestSearchDocuments::test_blank_query_preserves_source_filter_and_existing_list[] PASSED [ 40%] +tests/test_documents.py::TestSearchDocuments::test_blank_query_preserves_source_filter_and_existing_list[ \t\n ] PASSED [ 40%] +tests/test_documents.py::TestSearchDocuments::test_blank_query_preserves_source_filter_and_existing_list[\u2003\xa0] PASSED [ 41%] +tests/test_documents.py::TestSearchDocuments::test_no_matches_return_an_empty_page[params0] PASSED [ 41%] +tests/test_documents.py::TestSearchDocuments::test_no_matches_return_an_empty_page[params1] PASSED [ 42%] +tests/test_documents.py::TestDocumentDetail::test_returns_full_content PASSED [ 42%] +tests/test_documents.py::TestDocumentDetail::test_missing_document_is_404 PASSED [ 42%] +tests/test_documents.py::TestCreateDocument::test_rejects_invalid_fields_without_writes_or_indexing[-title] PASSED [ 43%] +tests/test_documents.py::TestCreateDocument::test_rejects_invalid_fields_without_writes_or_indexing[-content] PASSED [ 43%] +tests/test_documents.py::TestCreateDocument::test_rejects_invalid_fields_without_writes_or_indexing[-source] PASSED [ 44%] +tests/test_documents.py::TestCreateDocument::test_rejects_invalid_fields_without_writes_or_indexing[ \n\t -title] PASSED [ 44%] +tests/test_documents.py::TestCreateDocument::test_rejects_invalid_fields_without_writes_or_indexing[ \n\t -content] PASSED [ 45%] +tests/test_documents.py::TestCreateDocument::test_rejects_invalid_fields_without_writes_or_indexing[ \n\t -source] PASSED [ 45%] +tests/test_documents.py::TestCreateDocument::test_rejects_invalid_fields_without_writes_or_indexing[\u2003\xa0-title] PASSED [ 46%] +tests/test_documents.py::TestCreateDocument::test_rejects_invalid_fields_without_writes_or_indexing[\u2003\xa0-content] PASSED [ 46%] +tests/test_documents.py::TestCreateDocument::test_rejects_invalid_fields_without_writes_or_indexing[\u2003\xa0-source] PASSED [ 47%] +tests/test_documents.py::TestCreateDocument::test_rejects_invalid_fields_without_writes_or_indexing[None-title] PASSED [ 47%] +tests/test_documents.py::TestCreateDocument::test_rejects_invalid_fields_without_writes_or_indexing[None-content] PASSED [ 47%] +tests/test_documents.py::TestCreateDocument::test_rejects_invalid_fields_without_writes_or_indexing[None-source] PASSED [ 48%] +tests/test_documents.py::TestCreateDocument::test_rejects_invalid_fields_without_writes_or_indexing[123-title] PASSED [ 48%] +tests/test_documents.py::TestCreateDocument::test_rejects_invalid_fields_without_writes_or_indexing[123-content] PASSED [ 49%] +tests/test_documents.py::TestCreateDocument::test_rejects_invalid_fields_without_writes_or_indexing[123-source] PASSED [ 49%] +tests/test_documents.py::TestCreateDocument::test_rejects_missing_required_fields[title] PASSED [ 50%] +tests/test_documents.py::TestCreateDocument::test_rejects_missing_required_fields[content] PASSED [ 50%] +tests/test_documents.py::TestCreateDocument::test_creates_readable_document_and_indexes_preserved_content[None] PASSED [ 51%] +tests/test_documents.py::TestCreateDocument::test_creates_readable_document_and_indexes_preserved_content[ \tdocs\n ] PASSED [ 51%] +tests/test_retrieval.py::test_invalid_chunk_settings_are_rejected[config0] PASSED [ 52%] +tests/test_retrieval.py::test_invalid_chunk_settings_are_rejected[config1] PASSED [ 52%] +tests/test_retrieval.py::test_invalid_chunk_settings_are_rejected[config2] PASSED [ 52%] +tests/test_retrieval.py::test_invalid_chunk_settings_are_rejected[config3] PASSED [ 53%] +tests/test_retrieval.py::test_invalid_chunk_settings_are_rejected[config4] PASSED [ 53%] +tests/test_retrieval.py::test_valid_chunk_settings_are_accepted[1000-200] PASSED [ 54%] +tests/test_retrieval.py::test_valid_chunk_settings_are_accepted[1-0] PASSED [ 54%] +tests/test_retrieval.py::test_valid_chunk_settings_are_accepted[10-0] PASSED [ 55%] +tests/test_retrieval.py::test_valid_chunk_settings_are_accepted[10-9] PASSED [ 55%] +tests/test_retrieval.py::test_document_chunks_stop_after_covering_content[-5-2-expected0] PASSED [ 56%] +tests/test_retrieval.py::test_document_chunks_stop_after_covering_content[a-5-2-expected1] PASSED [ 56%] +tests/test_retrieval.py::test_document_chunks_stop_after_covering_content[abcd-5-2-expected2] PASSED [ 57%] +tests/test_retrieval.py::test_document_chunks_stop_after_covering_content[abcde-5-2-expected3] PASSED [ 57%] +tests/test_retrieval.py::test_document_chunks_stop_after_covering_content[abcdef-5-2-expected4] PASSED [ 57%] +tests/test_retrieval.py::test_document_chunks_stop_after_covering_content[abcdefgh-5-2-expected5] PASSED [ 58%] +tests/test_retrieval.py::test_document_chunks_stop_after_covering_content[abcdefghi-5-2-expected6] PASSED [ 58%] +tests/test_retrieval.py::test_document_chunks_stop_after_covering_content[abcdefghij-5-0-expected7] PASSED [ 59%] +tests/test_retrieval.py::test_document_chunks_stop_after_covering_content[abcdef-5-4-expected8] PASSED [ 59%] +tests/test_retrieval.py::test_document_chunks_stop_after_covering_content[abc-1-0-expected9] PASSED [ 60%] +tests/test_retrieval.py::test_document_indexing_avoids_redundant_tail_chunks PASSED [ 60%] +tests/test_retrieval.py::test_repeated_thread_indexing_preserves_distinct_top_k PASSED [ 61%] +tests/test_retrieval.py::test_thread_reindex_updates_content_and_embedding PASSED [ 61%] +tests/test_retrieval.py::test_thread_chunk_ids_are_scoped_by_channel PASSED [ 61%] +tests/test_retrieval.py::test_thread_indexing_omits_absent_optional_metadata PASSED [ 62%] +tests/test_retrieval.py::test_thread_indexing_uses_last_duplicate_in_batch PASSED [ 62%] +tests/test_retrieval.py::test_thread_indexing_skips_unusable_messages[messages0] PASSED [ 63%] +tests/test_retrieval.py::test_thread_indexing_skips_unusable_messages[messages1] PASSED [ 63%] +tests/test_retrieval.py::test_thread_indexing_skips_unusable_messages[messages2] PASSED [ 64%] +tests/test_retrieval.py::test_thread_indexing_skips_unusable_messages[messages3] PASSED [ 64%] +tests/test_retrieval.py::test_thread_indexing_skips_unusable_messages[messages4] PASSED [ 65%] +tests/test_retrieval.py::test_thread_indexing_skips_unusable_messages[messages5] PASSED [ 65%] +tests/test_retrieval.py::test_thread_indexing_skips_unusable_messages[messages6] PASSED [ 66%] +tests/test_retrieval.py::test_search_empty_collection_returns_no_matches[None-None] PASSED [ 66%] +tests/test_retrieval.py::test_search_empty_collection_returns_no_matches[None-CTARGET] PASSED [ 66%] +tests/test_retrieval.py::test_search_empty_collection_returns_no_matches[1.0-None] PASSED [ 67%] +tests/test_retrieval.py::test_search_empty_collection_returns_no_matches[1.0-CTARGET] PASSED [ 67%] +tests/test_retrieval.py::test_first_document_can_be_indexed_and_retrieved PASSED [ 68%] +tests/test_retrieval.py::test_missing_adapter_still_raises[add] PASSED [ 68%] +tests/test_retrieval.py::test_missing_adapter_still_raises[search] PASSED [ 69%] +tests/test_retrieval.py::test_channel_filter_runs_before_top_k PASSED [ 69%] +tests/test_retrieval.py::test_unscoped_search_preserves_global_ranking_and_explicit_k PASSED [ 70%] +tests/test_retrieval.py::test_distance_cutoff_is_inclusive_and_preserves_channel_scope PASSED [ 70%] +tests/test_retrieval.py::test_zero_distance_cutoff_keeps_only_exact_vector_matches PASSED [ 71%] +tests/test_retrieval.py::test_invalid_distance_config_is_rejected[-1] PASSED [ 71%] +tests/test_retrieval.py::test_invalid_distance_config_is_rejected[nan] PASSED [ 71%] +tests/test_retrieval.py::test_invalid_distance_config_is_rejected[inf] PASSED [ 72%] +tests/test_retrieval.py::test_invalid_distance_config_is_rejected[-inf] PASSED [ 72%] +tests/test_retrieval.py::test_invalid_distance_config_is_rejected[invalid] PASSED [ 73%] +tests/test_retrieval.py::test_distance_config_accepts_unset_or_nonnegative_finite_values[None] PASSED [ 73%] +tests/test_retrieval.py::test_distance_config_accepts_unset_or_nonnegative_finite_values[0] PASSED [ 74%] +tests/test_retrieval.py::test_distance_config_accepts_unset_or_nonnegative_finite_values[1.5] PASSED [ 74%] +tests/test_retrieval.py::test_empty_channel_does_not_fall_back_to_global_results PASSED [ 75%] +tests/test_retrieval.py::test_rag_payload_uses_scoped_matches[None-2-api] PASSED [ 75%] +tests/test_retrieval.py::test_rag_payload_uses_scoped_matches[None-2-slack] PASSED [ 76%] +tests/test_retrieval.py::test_rag_payload_uses_scoped_matches[1.0-1-api] PASSED [ 76%] +tests/test_retrieval.py::test_rag_payload_uses_scoped_matches[1.0-1-slack] PASSED [ 76%] +tests/test_retrieval.py::test_rag_payload_uses_scoped_matches[0.0-0-api] PASSED [ 77%] +tests/test_retrieval.py::test_rag_payload_uses_scoped_matches[0.0-0-slack] PASSED [ 77%] +tests/test_thread_indexing.py::test_saved_thread_includes_root_and_replies_in_timestamp_order PASSED [ 78%] +tests/test_thread_indexing.py::test_saved_root_only_thread_is_indexed_once[None] PASSED [ 78%] +tests/test_thread_indexing.py::test_saved_root_only_thread_is_indexed_once[1700000000.000001] PASSED [ 79%] +tests/test_thread_indexing.py::test_saved_replies_can_be_indexed_without_a_saved_root PASSED [ 79%] +tests/test_thread_indexing.py::test_missing_saved_thread_returns_404_without_indexing[CTARGET-1700000098.000001] PASSED [ 80%] +tests/test_thread_indexing.py::test_missing_saved_thread_returns_404_without_indexing[CEMPTY-1700000000.000001] PASSED [ 80%] +tests/test_thread_indexing.py::test_saved_thread_channel_filter_also_applies_to_root_lookup PASSED [ 80%] +tests/test_thread_indexing.py::test_saved_thread_indexing_failure_remains_500 PASSED [ 81%] +tests/test_thread_indexing.py::test_saved_thread_retrieval_includes_original_question PASSED [ 81%] +tests/test_retrieval_preview.py::test_preview_returns_ranked_chunks_metadata_distances_and_settings PASSED [ 82%] +tests/test_retrieval_preview.py::test_preview_applies_channel_scope_before_top_k PASSED [ 82%] +tests/test_retrieval_preview.py::test_preview_exposes_inclusive_distance_cutoff_with_transcript PASSED [ 83%] +tests/test_retrieval_preview.py::test_preview_returns_success_for_empty_results[collection] PASSED [ 83%] +tests/test_retrieval_preview.py::test_preview_returns_success_for_empty_results[channel] PASSED [ 84%] +tests/test_retrieval_preview.py::test_preview_returns_success_for_empty_results[cutoff] PASSED [ 84%] +tests/test_retrieval_preview.py::test_preview_rejects_invalid_input_before_search[payload0] PASSED [ 85%] +tests/test_retrieval_preview.py::test_preview_rejects_invalid_input_before_search[payload1] PASSED [ 85%] +tests/test_retrieval_preview.py::test_preview_rejects_invalid_input_before_search[payload2] PASSED [ 85%] +tests/test_retrieval_preview.py::test_preview_rejects_invalid_input_before_search[payload3] PASSED [ 86%] +tests/test_retrieval_preview.py::test_preview_rejects_invalid_input_before_search[payload4] PASSED [ 86%] +tests/test_retrieval_preview.py::test_preview_rejects_invalid_input_before_search[payload5] PASSED [ 87%] +tests/test_retrieval_preview.py::test_preview_rejects_invalid_input_before_search[payload6] PASSED [ 87%] +tests/test_retrieval_preview.py::test_preview_trims_question_and_channel PASSED [ 88%] +tests/test_retrieval_preview.py::test_preview_reports_unavailable_retrieval_without_exposing_error PASSED [ 88%] +tests/test_document_indexing.py::test_create_and_retry_keep_one_owned_chunk_and_preserve_saved_record PASSED [ 89%] +tests/test_document_indexing.py::test_retry_recovers_saved_document_after_embedding_failure_with_transcript PASSED [ 89%] +tests/test_document_indexing.py::test_retry_rechunks_and_removes_only_obsolete_owned_chunks PASSED [ 90%] +tests/test_document_indexing.py::test_retry_reads_latest_saved_content_title_and_source PASSED [ 90%] +tests/test_document_indexing.py::test_retry_failure_keeps_previous_chunks_and_saved_content[lookup] PASSED [ 90%] +tests/test_document_indexing.py::test_retry_failure_keeps_previous_chunks_and_saved_content[embed] PASSED [ 91%] +tests/test_document_indexing.py::test_retry_failure_keeps_previous_chunks_and_saved_content[upsert] PASSED [ 91%] +tests/test_document_indexing.py::test_cleanup_failure_is_reported_and_retry_finishes_without_duplicates PASSED [ 92%] +tests/test_document_indexing.py::test_missing_saved_document_does_not_initialise_vector_store PASSED [ 92%] +tests/test_document_indexing.py::test_invalid_legacy_document_is_rejected_without_changing_chunks[content- \n\t ] PASSED [ 93%] +tests/test_document_indexing.py::test_invalid_legacy_document_is_rejected_without_changing_chunks[content-None] PASSED [ 93%] +tests/test_document_indexing.py::test_invalid_legacy_document_is_rejected_without_changing_chunks[title-] PASSED [ 94%] +tests/test_document_indexing.py::test_invalid_legacy_document_is_rejected_without_changing_chunks[source-None] PASSED [ 94%] +tests/test_document_deletion.py::test_delete_removes_only_owned_chunks_with_retrieval_transcript PASSED [ 95%] +tests/test_document_deletion.py::test_missing_or_invalid_delete_does_not_initialise_vector_store[999-404] PASSED [ 95%] +tests/test_document_deletion.py::test_missing_or_invalid_delete_does_not_initialise_vector_store[-1-404] PASSED [ 95%] +tests/test_document_deletion.py::test_missing_or_invalid_delete_does_not_initialise_vector_store[invalid-422] PASSED [ 96%] +tests/test_document_deletion.py::test_missing_or_invalid_delete_does_not_initialise_vector_store[1.5-422] PASSED [ 96%] +tests/test_document_deletion.py::test_delete_unindexed_legacy_record_needs_no_valid_content_or_embeddings PASSED [ 97%] +tests/test_document_deletion.py::test_vector_delete_failure_retains_saved_record_and_allows_retry[initialise] PASSED [ 97%] +tests/test_document_deletion.py::test_vector_delete_failure_retains_saved_record_and_allows_retry[delete] PASSED [ 98%] +tests/test_document_deletion.py::test_vector_delete_failure_retains_saved_record_and_allows_retry[lost-acknowledgement] PASSED [ 98%] +tests/test_document_deletion.py::test_database_delete_failure_rolls_back_saved_record_and_can_retry[delete] PASSED [ 99%] +tests/test_document_deletion.py::test_database_delete_failure_rolls_back_saved_record_and_can_retry[commit] PASSED [ 99%] +tests/test_document_deletion.py::test_delete_still_requires_an_initialised_adapter PASSED [100%] + +=============================== warnings summary =============================== +app/main.py:97 + /Users/johnny/.paseo/worktrees/0x03bguv/happy-whale/backend/app/main.py:97: PydanticDeprecatedSince20: Support for class-based `config` is deprecated, use ConfigDict instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.12/migration/ + class MessageResponse(BaseModel): + +app/main.py:124 + /Users/johnny/.paseo/worktrees/0x03bguv/happy-whale/backend/app/main.py:124: PydanticDeprecatedSince20: Support for class-based `config` is deprecated, use ConfigDict instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.12/migration/ + class ConversationTurn(BaseModel): + +app/main.py:161 + /Users/johnny/.paseo/worktrees/0x03bguv/happy-whale/backend/app/main.py:161: PydanticDeprecatedSince20: Support for class-based `config` is deprecated, use ConfigDict instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.12/migration/ + class DocumentDetail(BaseModel): + +app/main.py:174 + /Users/johnny/.paseo/worktrees/0x03bguv/happy-whale/backend/app/main.py:174: DeprecationWarning: + on_event is deprecated, use lifespan event handlers instead. + + Read more about it in the + [FastAPI docs for Lifespan Events](https://fastapi.tiangolo.com/advanced/events/). + + @app.on_event("startup") + +.venv/lib/python3.13/site-packages/fastapi/applications.py:4576 +.venv/lib/python3.13/site-packages/fastapi/applications.py:4576 + /Users/johnny/.paseo/worktrees/0x03bguv/happy-whale/backend/.venv/lib/python3.13/site-packages/fastapi/applications.py:4576: DeprecationWarning: + on_event is deprecated, use lifespan event handlers instead. + + Read more about it in the + [FastAPI docs for Lifespan Events](https://fastapi.tiangolo.com/advanced/events/). + + return self.router.on_event(event_type) + +app/main.py:187 + /Users/johnny/.paseo/worktrees/0x03bguv/happy-whale/backend/app/main.py:187: DeprecationWarning: + on_event is deprecated, use lifespan event handlers instead. + + Read more about it in the + [FastAPI docs for Lifespan Events](https://fastapi.tiangolo.com/advanced/events/). + + @app.on_event("shutdown") + +tests/test_documents.py: 4 warnings +tests/test_thread_indexing.py: 92 warnings +tests/test_document_indexing.py: 31 warnings +tests/test_document_deletion.py: 16 warnings + /Users/johnny/.paseo/worktrees/0x03bguv/happy-whale/backend/.venv/lib/python3.13/site-packages/sqlalchemy/sql/schema.py:3624: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC). + return util.wrap_callable(lambda ctx: fn(), fn) # type: ignore + +tests/test_retrieval.py::test_document_chunks_stop_after_covering_content[-5-2-expected0] + /Users/johnny/.paseo/worktrees/0x03bguv/happy-whale/backend/tests/test_retrieval.py:122: LangChainDeprecationWarning: The class `Chroma` was deprecated in LangChain 0.2.9 and will be removed in 1.0. An updated version of the class exists in the `langchain-chroma package and should be used instead. To use it run `pip install -U `langchain-chroma` and import as `from `langchain_chroma import Chroma``. + store.vector_store = Chroma( + +tests/test_retrieval.py: 384 warnings +tests/test_thread_indexing.py: 27 warnings +tests/test_retrieval_preview.py: 216 warnings +tests/test_document_indexing.py: 166 warnings +tests/test_document_deletion.py: 89 warnings + /Users/johnny/.paseo/worktrees/0x03bguv/happy-whale/backend/.venv/lib/python3.13/site-packages/chromadb/types.py:144: PydanticDeprecatedSince211: Accessing the 'model_fields' attribute on the instance is deprecated. Instead, you should access this attribute from the model class. Deprecated in Pydantic V2.11 to be removed in V3.0. + return self.model_fields # pydantic 2.x + +-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html +===================== 221 passed, 1033 warnings in 39.29s ====================== diff --git a/.tmp/proof/document-delete-capture.py b/.tmp/proof/document-delete-capture.py new file mode 100644 index 0000000..e50122c --- /dev/null +++ b/.tmp/proof/document-delete-capture.py @@ -0,0 +1,57 @@ +"""Capture only loopback fixture API behaviour using curl.""" +import json +import shlex +import subprocess +from pathlib import Path + +base = "http://127.0.0.1:18055" +marker = Path(__file__).resolve().parents[1] / "offline-delete/fail-delete" + +def request(method, path, expected, payload=None): + args = ["curl", "-sS", "-X", method, base + path] + if payload is not None: + args += ["-H", "Content-Type: application/json", "-d", json.dumps(payload)] + args += ["-w", "\n%{http_code}"] + print("$ " + shlex.join(args), flush=True) + result = subprocess.run(args, capture_output=True, text=True, check=True) + body, status = result.stdout.rsplit("\n", 1) + value = json.loads(body) + print("HTTP " + status) + print(json.dumps(value, indent=2)) + print() + assert int(status) == expected, (body, status, expected) + return value + +print("Local SQLite and Chroma, fixed embeddings, Slack authentication mocked and API calls blocked.") +print("No real tokens, remote databases, model calls or paid embeddings. Distances are fixture squared L2 values.") +request("GET", "/health", 200) +payload = {"title": "VPN guide", "content": "Reset VPN via IT portal.", "source": "api"} +first = request("POST", "/api/documents", 200, payload)["id"] +second = request("POST", "/api/documents", 200, payload)["id"] +query = {"question": "How do I reset VPN?"} +before = request("POST", "/api/retrieval/preview", 200, query) +assert len(before["items"]) == 2 +assert {item["metadata"]["document_id"] for item in before["items"]} == {first, second} +assert [item["distance"] for item in before["items"]] == [1.0, 1.0] +print("Inject fixture Chroma deletion outage.") +marker.touch() +try: + failed = request("DELETE", f"/api/documents/{first}", 503) + assert failed["detail"]["document_id"] == first + request("GET", f"/api/documents/{first}", 200) +finally: + marker.unlink() +print("Remove fixture outage and retry the same saved ID.") +request("DELETE", f"/api/documents/{first}", 200) +request("GET", f"/api/documents/{first}", 404) +request("POST", f"/api/documents/{first}/index", 404) +request("DELETE", f"/api/documents/{first}", 404) +remaining = request("GET", "/api/documents", 200) +assert [item["id"] for item in remaining["items"]] == [second] +after = request("POST", "/api/retrieval/preview", 200, query) +assert len(after["items"]) == 1 +assert after["items"][0]["metadata"]["document_id"] == second +assert after["items"][0]["content"] == payload["content"] +assert after["items"][0]["distance"] == 1.0 +request("DELETE", "/api/documents/invalid", 422) +print("All curl status, ownership, saved-record and raw-distance assertions passed.") diff --git a/.tmp/proof/document-delete-frontend-tests.txt b/.tmp/proof/document-delete-frontend-tests.txt new file mode 100644 index 0000000..9214789 --- /dev/null +++ b/.tmp/proof/document-delete-frontend-tests.txt @@ -0,0 +1,51 @@ +[test-frontend] $ bun run test +$ bun test --preload ./tests/setup.ts +bun test v1.3.5 (1e86cebd) + +tests/documents.test.tsx: +(pass) documents load on opening the tab, search only on submit, and retain the applied query while paging [2702.66ms] +(pass) document client encodes literal search text, keeps source filters, and omits blank queries [0.37ms] +(pass) documents show loading, retry the submitted query after a list error, and distinguish empty searches [373.87ms] +(pass) documents render saved content as text and retry detail failures without losing results [145.86ms] +(pass) documents ignore stale successful and failed list responses after a newer search [116.11ms] +(pass) documents ignore late details after another selection, a page change, and clearing a search [956.85ms] +(pass) documents abort requests on leaving the tab and ignore late responses when reopened [184.73ms] + +tests/document-indexing.test.tsx: +(pass) re-indexing requires an explicit click, posts the saved ID once while pending, and keeps the content visible [306.08ms] +(pass) re-indexing reports a safe failure for 404 and retries the same saved document [416.96ms] +(pass) re-indexing reports a safe failure for 422 and retries the same saved document [331.74ms] +(pass) re-indexing reports a safe failure for 503 and retries the same saved document [311.48ms] +(pass) re-indexing reports a safe failure for network and retries the same saved document [166.94ms] +(pass) re-indexing ignores a late success after a selection change [182.56ms] +(pass) re-indexing ignores a late failure after a selection change [487.10ms] +(pass) re-indexing ignores a late success after a search change [363.19ms] +(pass) re-indexing ignores a late failure after a search change [364.57ms] +(pass) re-indexing ignores a late success after a page change [391.20ms] +(pass) re-indexing ignores a late failure after a page change [233.10ms] +(pass) re-indexing ignores a late success after a tab change [254.66ms] +(pass) re-indexing ignores a late failure after a tab change [216.53ms] + +tests/retrieval.test.tsx: +(pass) retrieval waits for a non-blank question and submits trimmed optional scope [23.02ms] +(pass) retrieval omits blank scope, preserves rank and raw distances, and shows an unset cutoff [113.70ms] +(pass) retrieval disables inputs and duplicate submissions while loading [104.85ms] +(pass) retrieval shows an empty result and a zero distance cutoff [120.37ms] +(pass) retrieval replaces a failed request with a successful retry [142.64ms] +(pass) retrieval clears old results when the question or channel changes [175.60ms] +(pass) retrieval aborts on leaving the tab and ignores late responses after reopening [19.01ms] +(pass) retrieval renders chunk and metadata markup as text [82.60ms] + +tests/conversations.test.tsx: +(pass) loads only on opening the tab and paginates summaries and chronological turns independently [572.55ms] +(pass) shows loading, an empty page and a list error with a working retry [36.27ms] +(pass) retries missing conversation details without discarding the list [69.31ms] +(pass) ignores stale detail responses after selecting another conversation [33.89ms] +(pass) ignores stale errors after leaving and reopening the tab [9.73ms] +(pass) renders stored markup as text and supports missing metadata [33.06ms] +(pass) encodes conversation IDs in detail request paths [1.63ms] + + 35 pass + 0 fail + 261 expect() calls +Ran 35 tests across 4 files. [12.02s] diff --git a/.tmp/proof/document-delete-install.txt b/.tmp/proof/document-delete-install.txt new file mode 100644 index 0000000..2b30978 --- /dev/null +++ b/.tmp/proof/document-delete-install.txt @@ -0,0 +1,182 @@ +[install-runtime] $ bun install --frozen-lockfile --ignore-scripts +[install-backend] $ uv sync +[install-frontend] $ bun install +[install-frontend] bun install v1.3.5 (1e86cebd) +[install-runtime] bun install v1.3.5 (1e86cebd) +[install-backend] Using CPython 3.13.13 +[install-backend] Creating virtual environment at: .venv +[install-runtime] +[install-runtime] + @earendil-works/chord@1.3.0 +[install-runtime] + @earendil-works/pi-ai@1.3.0 +[install-runtime] + @earendil-works/pi-durable@1.3.0 +[install-runtime] +[install-runtime] 91 packages installed [1283.00ms] +[install-runtime] Finished in 1.50s +[install-frontend] +[install-frontend] + @tailwindcss/postcss@4.1.18 +[install-frontend] + @testing-library/react@16.3.3 +[install-frontend] + @types/bun@1.4.4 +[install-frontend] + eslint@9.39.2 +[install-frontend] + eslint-config-next@16.1.1 +[install-frontend] + happy-dom@21.0.4 +[install-frontend] + tailwindcss@4.1.18 +[install-frontend] + @types/node@25.0.3 +[install-frontend] + @types/react@19.2.7 +[install-frontend] + @types/react-dom@19.2.3 +[install-frontend] + axios@1.13.2 +[install-frontend] + next@16.1.1 +[install-frontend] + react@19.2.3 +[install-frontend] + react-dom@19.2.3 +[install-frontend] + swr@2.3.8 +[install-frontend] + typescript@5.9.3 +[install-frontend] +[install-frontend] 382 packages installed [2.27s] +[install-frontend] Finished in 2.47s +[install-backend] Resolved 143 packages in 5.27s +[install-backend] warning: `numpy==2.4.0` is yanked (reason: "Backward compatibility bug") +[install-backend] Building wingman @ file:///Users/johnny/.paseo/worktrees/0x03bguv/happy-whale/backend +[install-backend] Built wingman @ file:///Users/johnny/.paseo/worktrees/0x03bguv/happy-whale/backend +[install-backend] Prepared 1 package in 8.56s +[install-backend] Installed 140 packages in 3.06s +[install-backend] + aiohappyeyeballs==2.6.1 +[install-backend] + aiohttp==3.13.2 +[install-backend] + aiosignal==1.4.0 +[install-backend] + alembic==1.17.2 +[install-backend] + annotated-doc==0.0.4 +[install-backend] + annotated-types==0.7.0 +[install-backend] + anyio==4.12.0 +[install-backend] + asgiref==3.11.0 +[install-backend] + attrs==25.4.0 +[install-backend] + backoff==2.2.1 +[install-backend] + bcrypt==5.0.0 +[install-backend] + build==1.3.0 +[install-backend] + cachetools==6.2.4 +[install-backend] + certifi==2025.11.12 +[install-backend] + charset-normalizer==3.4.4 +[install-backend] + chroma-hnswlib==0.7.6 +[install-backend] + chromadb==0.6.3 +[install-backend] + click==8.3.1 +[install-backend] + coloredlogs==15.0.1 +[install-backend] + dataclasses-json==0.6.7 +[install-backend] + distro==1.9.0 +[install-backend] + durationpy==0.10 +[install-backend] + fastapi==0.128.0 +[install-backend] + filelock==3.20.1 +[install-backend] + flatbuffers==25.12.19 +[install-backend] + frozenlist==1.8.0 +[install-backend] + fsspec==2025.12.0 +[install-backend] + google-auth==2.45.0 +[install-backend] + googleapis-common-protos==1.72.0 +[install-backend] + grpcio==1.76.0 +[install-backend] + h11==0.16.0 +[install-backend] + hf-xet==1.2.0 +[install-backend] + httpcore==1.0.9 +[install-backend] + httptools==0.7.1 +[install-backend] + httpx==0.28.1 +[install-backend] + httpx-sse==0.4.3 +[install-backend] + huggingface-hub==0.36.0 +[install-backend] + humanfriendly==10.0 +[install-backend] + idna==3.11 +[install-backend] + importlib-metadata==8.7.1 +[install-backend] + importlib-resources==6.5.2 +[install-backend] + iniconfig==2.3.0 +[install-backend] + jiter==0.12.0 +[install-backend] + jsonpatch==1.33 +[install-backend] + jsonpointer==3.0.0 +[install-backend] + kubernetes==34.1.0 +[install-backend] + langchain==1.2.0 +[install-backend] + langchain-classic==1.0.1 +[install-backend] + langchain-community==0.4.1 +[install-backend] + langchain-core==1.2.5 +[install-backend] + langchain-openai==1.1.6 +[install-backend] + langchain-text-splitters==1.1.0 +[install-backend] + langgraph==1.0.5 +[install-backend] + langgraph-checkpoint==3.0.1 +[install-backend] + langgraph-prebuilt==1.0.5 +[install-backend] + langgraph-sdk==0.3.1 +[install-backend] + langsmith==0.5.2 +[install-backend] + lxml==6.0.2 +[install-backend] + mako==1.3.10 +[install-backend] + markdown-it-py==4.0.0 +[install-backend] + markupsafe==3.0.3 +[install-backend] + marshmallow==3.26.2 +[install-backend] + mdurl==0.1.2 +[install-backend] + mmh3==5.2.0 +[install-backend] + mpmath==1.3.0 +[install-backend] + multidict==6.7.0 +[install-backend] + mypy-extensions==1.1.0 +[install-backend] + numpy==2.4.0 +[install-backend] + oauthlib==3.3.1 +[install-backend] + onnxruntime==1.23.2 +[install-backend] + openai==2.14.0 +[install-backend] + opentelemetry-api==1.39.1 +[install-backend] + opentelemetry-exporter-otlp-proto-common==1.39.1 +[install-backend] + opentelemetry-exporter-otlp-proto-grpc==1.39.1 +[install-backend] + opentelemetry-instrumentation==0.60b1 +[install-backend] + opentelemetry-instrumentation-asgi==0.60b1 +[install-backend] + opentelemetry-instrumentation-fastapi==0.60b1 +[install-backend] + opentelemetry-proto==1.39.1 +[install-backend] + opentelemetry-sdk==1.39.1 +[install-backend] + opentelemetry-semantic-conventions==0.60b1 +[install-backend] + opentelemetry-util-http==0.60b1 +[install-backend] + orjson==3.11.5 +[install-backend] + ormsgpack==1.12.1 +[install-backend] + overrides==7.7.0 +[install-backend] + packaging==25.0 +[install-backend] + pluggy==1.6.0 +[install-backend] + posthog==7.4.2 +[install-backend] + propcache==0.4.1 +[install-backend] + protobuf==6.33.2 +[install-backend] + psycopg2-binary==2.9.11 +[install-backend] + pyasn1==0.6.1 +[install-backend] + pyasn1-modules==0.4.2 +[install-backend] + pydantic==2.12.5 +[install-backend] + pydantic-core==2.41.5 +[install-backend] + pydantic-settings==2.12.0 +[install-backend] + pygments==2.19.2 +[install-backend] + pypdf==6.5.0 +[install-backend] + pypika==0.48.9 +[install-backend] + pyproject-hooks==1.2.0 +[install-backend] + pytest==9.0.2 +[install-backend] + pytest-asyncio==1.3.0 +[install-backend] + python-dateutil==2.9.0.post0 +[install-backend] + python-docx==1.2.0 +[install-backend] + python-dotenv==1.2.1 +[install-backend] + pyyaml==6.0.3 +[install-backend] + regex==2025.11.3 +[install-backend] + requests==2.32.5 +[install-backend] + requests-oauthlib==2.0.0 +[install-backend] + requests-toolbelt==1.0.0 +[install-backend] + rich==14.2.0 +[install-backend] + rsa==4.9.1 +[install-backend] + shellingham==1.5.4 +[install-backend] + six==1.17.0 +[install-backend] + slack-bolt==1.27.0 +[install-backend] + slack-sdk==3.42.0 +[install-backend] + sniffio==1.3.1 +[install-backend] + sqlalchemy==2.0.45 +[install-backend] + starlette==0.50.0 +[install-backend] + sympy==1.14.0 +[install-backend] + tenacity==9.1.2 +[install-backend] + tiktoken==0.12.0 +[install-backend] + tokenizers==0.22.1 +[install-backend] + tqdm==4.67.1 +[install-backend] + typer==0.21.0 +[install-backend] + typing-extensions==4.15.0 +[install-backend] + typing-inspect==0.9.0 +[install-backend] + typing-inspection==0.4.2 +[install-backend] + urllib3==2.3.0 +[install-backend] + uuid-utils==0.12.0 +[install-backend] + uvicorn==0.40.0 +[install-backend] + uvloop==0.22.1 +[install-backend] + watchfiles==1.1.1 +[install-backend] + websocket-client==1.9.0 +[install-backend] + websockets==15.0.1 +[install-backend] + wingman==1.1.0 (from file:///Users/johnny/.paseo/worktrees/0x03bguv/happy-whale/backend) +[install-backend] + wrapt==1.17.3 +[install-backend] + xxhash==3.6.0 +[install-backend] + yarl==1.22.0 +[install-backend] + zipp==3.23.0 +[install-backend] + zstandard==0.25.0 +[install-backend] Finished in 19.42s +Finished in 19.56s diff --git a/.tmp/proof/document-delete-runtime-tests.txt b/.tmp/proof/document-delete-runtime-tests.txt new file mode 100644 index 0000000..0b01e60 --- /dev/null +++ b/.tmp/proof/document-delete-runtime-tests.txt @@ -0,0 +1,22 @@ +[test-runtime] $ node --test +✔ real Pi SQLite storage preserves answers, deduplicates retries, and retains conversation history (272.500208ms) +✔ outbox resumes after restart without regenerating answer; retry admits only one job (29.441208ms) +Warning: Detected unsettled top-level await at file:///Users/johnny/.paseo/worktrees/0x03bguv/happy-whale/runtime/fixtures/interrupted.mjs:12 +await answerJob(JSON.parse(process.argv[3]), { +^ + + + +✔ a process killed during generation resumes the admitted Pi submission (1054.132792ms) +✔ pinned operator answer is delivered without calling the model (2.001625ms) +✔ model failure sends a persisted Slack failure notification (1.075541ms) +✔ runtime starts with openai catalog and protects job routes (1814.20425ms) +✔ runtime starts with mimo catalog and protects job routes (1053.630542ms) +ℹ tests 7 +ℹ suites 0 +ℹ pass 7 +ℹ fail 0 +ℹ cancelled 0 +ℹ skipped 0 +ℹ todo 0 +ℹ duration_ms 3132.643833 diff --git a/.tmp/proof/document-delete-sitecustomize.py b/.tmp/proof/document-delete-sitecustomize.py new file mode 100644 index 0000000..d1ad2bc --- /dev/null +++ b/.tmp/proof/document-delete-sitecustomize.py @@ -0,0 +1,55 @@ +"""Local proof process only: deny Slack and use fixture Chroma embeddings.""" +from pathlib import Path +from slack_sdk import WebClient +from slack_bolt.adapter.socket_mode import SocketModeHandler + + +def blocked(*args, **kwargs): + raise AssertionError("Live Slack calls and Socket Mode are forbidden in this proof process") + + +WebClient.auth_test = lambda *args, **kwargs: { + "ok": True, "bot_id": "BTEST", "user_id": "UTEST", "team_id": "TTEST", +} +WebClient.api_call = blocked +SocketModeHandler.start = blocked + +import chromadb +from chromadb.config import Settings as ChromaSettings +from chromadb.telemetry.product.posthog import Posthog +from langchain_community.vectorstores import Chroma +from langchain_core.embeddings import Embeddings +from app.vector_store import vector_store + +Posthog.capture = lambda *args, **kwargs: None +proof_dir = Path(__file__).resolve().parent + + +class FixedEmbeddings(Embeddings): + def embed_documents(self, texts): + # A marker file injects a recoverable provider failure for the transcript. + if (proof_dir / "fail-embedding").exists(): + raise RuntimeError("Fixture embedding outage") + return [[float(len("Reset VPN via IT portal.") - len(text) + 1), 1.0] for text in texts] + + def embed_query(self, text): + return [0.0, 1.0] + + +vector_store.vector_store = Chroma( + client=chromadb.PersistentClient( + path=str(proof_dir / "chroma"), settings=ChromaSettings(anonymized_telemetry=False), + ), + collection_name="document-delete-proof", embedding_function=FixedEmbeddings(), +) +vector_store._initialized = True + +# Allow a repeatable deletion outage without changing the application. +original_delete = vector_store.vector_store.delete + +def fixture_delete(*args, **kwargs): + if (proof_dir / "fail-delete").exists(): + raise RuntimeError("Fixture Chroma deletion outage") + return original_delete(*args, **kwargs) + +vector_store.vector_store.delete = fixture_delete diff --git a/backend/app/main.py b/backend/app/main.py index 62aa9be..49c311f 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -354,6 +354,28 @@ async def index_saved_document(document_id: int, db: Session = Depends(get_db)): return {"id": doc.id, "message": "Document indexed successfully"} +@app.delete("/api/documents/{document_id}") +def delete_document(document_id: int, db: Session = Depends(get_db)): + """Remove owned vector chunks before deleting the saved record.""" + try: + doc = db.query(Document).filter(Document.id == document_id).first() + if doc is None: + raise HTTPException(status_code=404, detail="Document not found") + vector_store.delete_document(document_id) + db.delete(doc) + db.commit() + except HTTPException: + raise + except Exception: + db.rollback() + logger.exception("Deleting saved document %s failed", document_id) + raise HTTPException(status_code=503, detail={ + "message": "Document deletion is unavailable", + "document_id": document_id, + }) + return {"id": document_id, "message": "Document deleted successfully"} + + @app.get("/api/messages", response_model=List[MessageResponse]) async def list_messages( limit: int = 100, diff --git a/backend/app/vector_store.py b/backend/app/vector_store.py index 0c3d382..6caac82 100644 --- a/backend/app/vector_store.py +++ b/backend/app/vector_store.py @@ -90,6 +90,17 @@ def replace_document(self, document_id: int, texts: List[str], obsolete = sorted(set(previous["ids"]) - set(ids)) if obsolete: self.vector_store.delete(ids=obsolete) + + def delete_document(self, document_id: int): + """Remove only chunks explicitly owned by a saved document. + + Deleting an empty set is safe to retry after a database failure. + Titles and sources cannot identify ownership of historical chunks. + """ + self._ensure_initialized() + if self.vector_store is None: + raise RuntimeError("Vector store not initialized") + self.vector_store.delete(where={"document_id": document_id}) def similarity_search(self, query: str, k: int = None, *, channel_id: str = None) -> List[Dict[str, Any]]: diff --git a/backend/tests/test_document_deletion.py b/backend/tests/test_document_deletion.py new file mode 100644 index 0000000..66a90e4 --- /dev/null +++ b/backend/tests/test_document_deletion.py @@ -0,0 +1,134 @@ +"""Document removal with SQLite, local Chroma, and no external services.""" +import json +from unittest.mock import Mock, patch + +import pytest +from sqlalchemy.orm import Session + +from app.config import settings +from app.database import Document +from app.vector_store import VectorStore +from tests.test_document_indexing import ( + CONTENT, QUESTION, create_document, document_api, +) + + +def test_delete_removes_only_owned_chunks_with_retrieval_transcript(document_api, monkeypatch): + client, _, vector = document_api + monkeypatch.setattr(settings, "CHUNK_SIZE", 8) + monkeypatch.setattr(settings, "RETRIEVAL_TOP_K", 20) + document_id = create_document(client).json()["id"] + other_id = create_document(client).json()["id"] # Identical title, source and content. + legacy_ids = vector.add_documents([CONTENT], [{"title": "VPN guide", "source": "api"}]) + slack_ids = vector.add_documents([CONTENT], [{"source": "slack", "channel_id": "CTEST"}]) + before = vector.similarity_search(QUESTION) + preserved_ids = [f"document:{other_id}:{i}" for i in range(3)] + legacy_ids + slack_ids + preserved = vector.vector_store.get( + ids=preserved_ids, include=["documents", "metadatas", "embeddings"], + ) + assert len(before) == 8 + assert len([item for item in before if item["metadata"].get("document_id") == document_id]) == 3 + + response = client.delete(f"/api/documents/{document_id}") + assert response.status_code == 200 + assert response.json() == {"id": document_id, "message": "Document deleted successfully"} + after = vector.similarity_search(QUESTION) + assert len(after) == 5 + assert all(item["metadata"].get("document_id") != document_id for item in after) + assert {item["distance"] for item in before} == {1.0, 289.0} + assert {item["distance"] for item in after} == {1.0, 289.0} + remaining = vector.vector_store.get(include=["documents", "metadatas", "embeddings"]) + assert remaining["ids"] == preserved["ids"] + assert remaining["documents"] == preserved["documents"] + assert remaining["metadatas"] == preserved["metadatas"] + assert remaining["embeddings"].tolist() == preserved["embeddings"].tolist() + assert client.get(f"/api/documents/{document_id}").status_code == 404 + assert client.post(f"/api/documents/{document_id}/index").status_code == 404 + assert [item["id"] for item in client.get("/api/documents").json()["items"]] == [other_id] + assert client.delete(f"/api/documents/{document_id}").status_code == 404 + print(json.dumps({ + "query": QUESTION, "deleted_document_id": document_id, "top_k": 20, + "before_delete": before, "after_delete": after, + "note": "Fixed-vector squared L2 distances demonstrate ownership removal, not production relevance.", + }, indent=2)) + + +@pytest.mark.parametrize("document_id,status", [(999, 404), (-1, 404), ("invalid", 422), ("1.5", 422)]) +def test_missing_or_invalid_delete_does_not_initialise_vector_store(document_api, monkeypatch, document_id, status): + client, _, vector = document_api + initialise = Mock(side_effect=AssertionError("Missing document must not access Chroma")) + monkeypatch.setattr(vector, "_ensure_initialized", initialise) + response = client.delete(f"/api/documents/{document_id}") + assert response.status_code == status + if status == 404: + assert response.json() == {"detail": "Document not found"} + initialise.assert_not_called() + + +def test_delete_unindexed_legacy_record_needs_no_valid_content_or_embeddings(document_api): + client, sessions, vector = document_api + with sessions() as db: + doc = Document(title=None, content=None, source=None) + db.add(doc) + db.commit() + document_id = doc.id + with patch.object(vector.vector_store._embedding_function, "embed_documents", + side_effect=AssertionError("Deletion must not embed")), \ + patch.object(vector.vector_store._embedding_function, "embed_query", + side_effect=AssertionError("Deletion must not embed")): + assert client.delete(f"/api/documents/{document_id}").status_code == 200 + assert client.get("/api/documents").json()["total"] == 0 + assert vector.vector_store.get()["ids"] == [] + + +@pytest.mark.parametrize("stage", ["initialise", "delete", "lost-acknowledgement"]) +def test_vector_delete_failure_retains_saved_record_and_allows_retry(document_api, stage): + client, _, vector = document_api + document_id = create_document(client).json()["id"] + saved = client.get(f"/api/documents/{document_id}").json() + original_delete = vector.vector_store.delete + + def fail_after_deleting(*args, **kwargs): + original_delete(*args, **kwargs) + raise RuntimeError("Private Chroma credentials") + + target, method = (vector, "_ensure_initialized") if stage == "initialise" else (vector.vector_store, "delete") + failure = fail_after_deleting if stage == "lost-acknowledgement" else RuntimeError("Private Chroma credentials") + with patch.object(target, method, side_effect=failure): + response = client.delete(f"/api/documents/{document_id}") + assert response.status_code == 503 + assert response.json() == {"detail": { + "message": "Document deletion is unavailable", "document_id": document_id, + }} + assert "Private" not in response.text + assert client.get(f"/api/documents/{document_id}").json() == saved + expected = [] if stage == "lost-acknowledgement" else [CONTENT] + assert vector.vector_store.get()["documents"] == expected + assert client.delete(f"/api/documents/{document_id}").status_code == 200 + assert vector.vector_store.get()["ids"] == [] + assert client.get(f"/api/documents/{document_id}").status_code == 404 + + +@pytest.mark.parametrize("method", ["delete", "commit"]) +def test_database_delete_failure_rolls_back_saved_record_and_can_retry(document_api, method): + client, _, vector = document_api + document_id = create_document(client).json()["id"] + saved = client.get(f"/api/documents/{document_id}").json() + with patch.object(Session, method, side_effect=RuntimeError("Private database credentials")): + response = client.delete(f"/api/documents/{document_id}") + assert response.status_code == 503 + assert response.json() == {"detail": { + "message": "Document deletion is unavailable", "document_id": document_id, + }} + assert "Private" not in response.text + assert client.get(f"/api/documents/{document_id}").json() == saved + assert vector.vector_store.get()["ids"] == [] # Separate stores are not atomic. + assert client.delete(f"/api/documents/{document_id}").status_code == 200 + assert client.get(f"/api/documents/{document_id}").status_code == 404 + + +def test_delete_still_requires_an_initialised_adapter(monkeypatch): + vector = VectorStore() + monkeypatch.setattr(vector, "_ensure_initialized", lambda: None) + with pytest.raises(RuntimeError, match="Vector store not initialized"): + vector.delete_document(1) diff --git a/backend/tests/test_document_indexing.py b/backend/tests/test_document_indexing.py index 03e7122..9c0403f 100644 --- a/backend/tests/test_document_indexing.py +++ b/backend/tests/test_document_indexing.py @@ -69,6 +69,7 @@ def get_test_db(): ) vector._initialized = True monkeypatch.setattr(rag_module, "vector_store", vector) + monkeypatch.setattr("app.main.vector_store", vector) blocked = Mock(side_effect=AssertionError("Document indexing must not contact Slack or generate")) monkeypatch.setattr("slack_sdk.WebClient.api_call", blocked) monkeypatch.setattr("slack_bolt.adapter.socket_mode.SocketModeHandler.start", blocked) diff --git a/docs/retrieval.md b/docs/retrieval.md index 0f11321..1fa6ff1 100644 --- a/docs/retrieval.md +++ b/docs/retrieval.md @@ -132,6 +132,43 @@ the other management endpoints. The offline tests use temporary local Chroma and fixed embeddings; the recovery transcript is included in the backend gate output when run with `PYTEST_ADDOPTS=-rP`. +## Delete a saved document + +`DELETE /api/documents/{document_id}` removes the document's owned Chroma chunks, +then its saved database record. Success returns HTTP 200 with `id` and +`message`. The record disappears from document lists and detail reads. Deleting +the same ID again returns HTTP 404, as does re-indexing it. A missing record +returns HTTP 404 without accessing Chroma; a non-integer ID returns HTTP 422. +This API action has no dashboard button yet. + +```sh +curl -sS -X DELETE http://localhost:8000/api/documents/1 +``` + +Only chunks with matching numeric `document_id` metadata are removed. Other +documents, including those with identical titles and sources, Slack chunks, and +historical chunks without an owner are preserved. Legacy unowned chunks can +therefore remain searchable after deletion. Rebuild them from their original +sources to remove them safely. Documents that were saved but never indexed can +also be deleted, including legacy records with invalid content. + +Failures return HTTP 503 with `detail.message` and `detail.document_id` without +exposing provider or database details. Vector deletion runs first; on failure, +the database record is retained for retry. If database removal then fails, the +database transaction is rolled back, but removed chunks cannot be restored +automatically. Retry the same DELETE to finish removal. A lost acknowledgement +can mean a deletion completed even though the caller saw an error; a subsequent +404 means the saved record is already absent. These two stores do not form an +atomic transaction. + +Avoid overlapping deletion with indexing of the same document. Existing index +requests can still write chunks after deletion; this API does not coordinate +concurrent workers or implement tombstones. It does not remove content from Pi +history or previous answers. Keep this destructive management endpoint behind +trusted access controls, like the existing unauthenticated document endpoints. +Deletion makes no embedding, model or Slack requests. Chroma must be available +and the shared vector store must be configured, even for an unindexed record. + ## Saved Slack threads Slack thread indexing uses a stable chunk ID built from the channel ID and diff --git a/mise.toml b/mise.toml index a353d8f..48884ee 100644 --- a/mise.toml +++ b/mise.toml @@ -51,7 +51,7 @@ run = "docker compose ps" [tasks.test-backend] description = "Run backend tests" dir = "backend" -run = "uv run pytest tests/test_file_extraction_units.py tests/test_logging_config.py tests/test_logging.py tests/test_agent_runtime.py tests/test_rules.py tests/test_conversations.py tests/test_documents.py tests/test_retrieval.py tests/test_thread_indexing.py tests/test_retrieval_preview.py tests/test_document_indexing.py -v" +run = "uv run pytest tests/test_file_extraction_units.py tests/test_logging_config.py tests/test_logging.py tests/test_agent_runtime.py tests/test_rules.py tests/test_conversations.py tests/test_documents.py tests/test_retrieval.py tests/test_thread_indexing.py tests/test_retrieval_preview.py tests/test_document_indexing.py tests/test_document_deletion.py -v" [tasks.migrate] description = "Run database migrations (upgrade to latest)"