mirror of
https://github.com/langgenius/dify.git
synced 2026-05-09 12:59:18 +08:00
fix: Using CONSOLE_API_URL to generate an image preview URL causes the image preview to fail on the chunks details page of the knowledge base.
This commit is contained in:
parent
ea71990388
commit
d7f99d6458
@ -12,7 +12,9 @@ This test suite covers:
|
||||
import json
|
||||
import pickle
|
||||
from datetime import UTC, datetime
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import Mock, patch
|
||||
from urllib.parse import parse_qs, urlparse
|
||||
from uuid import uuid4
|
||||
|
||||
from core.rag.index_processor.constant.index_type import IndexTechniqueType
|
||||
@ -676,6 +678,51 @@ class TestDocumentSegmentIndexing:
|
||||
# Assert
|
||||
assert segment.hit_count == 5
|
||||
|
||||
def test_document_segment_attachments_prefers_files_url_for_source_url(self, monkeypatch):
|
||||
"""Test attachment source URLs use FILES_URL before falling back to CONSOLE_API_URL."""
|
||||
# Arrange
|
||||
segment = DocumentSegment(
|
||||
tenant_id="tenant-1",
|
||||
dataset_id="dataset-1",
|
||||
document_id="document-1",
|
||||
position=1,
|
||||
content="Test",
|
||||
word_count=1,
|
||||
tokens=2,
|
||||
created_by="user-1",
|
||||
)
|
||||
segment.id = "segment-1"
|
||||
attachment = SimpleNamespace(
|
||||
id="upload-1",
|
||||
name="image.png",
|
||||
size=128,
|
||||
extension="png",
|
||||
mime_type="image/png",
|
||||
)
|
||||
|
||||
monkeypatch.setattr("models.dataset.time.time", lambda: 1700000000)
|
||||
monkeypatch.setattr("models.dataset.os.urandom", lambda _: b"\x01" * 16)
|
||||
monkeypatch.setattr("models.dataset.dify_config.SECRET_KEY", "unit-secret")
|
||||
monkeypatch.setattr("models.dataset.dify_config.FILES_URL", "https://files.example.com")
|
||||
monkeypatch.setattr("models.dataset.dify_config.CONSOLE_API_URL", "https://console.example.com")
|
||||
|
||||
with patch("models.dataset.db") as mock_db:
|
||||
mock_db.session.execute.return_value.all.return_value = [(Mock(), attachment)]
|
||||
|
||||
# Act
|
||||
attachments = segment.attachments
|
||||
|
||||
# Assert
|
||||
assert len(attachments) == 1
|
||||
source_url = attachments[0]["source_url"]
|
||||
parsed = urlparse(source_url)
|
||||
query = parse_qs(parsed.query)
|
||||
assert parsed.netloc == "files.example.com"
|
||||
assert parsed.path == "/files/upload-1/image-preview"
|
||||
assert query["timestamp"] == ["1700000000"]
|
||||
assert query["nonce"] == ["01010101010101010101010101010101"]
|
||||
assert query["sign"][0]
|
||||
|
||||
def test_document_segment_error_tracking(self):
|
||||
"""Test document segment error tracking."""
|
||||
# Arrange
|
||||
|
||||
Loading…
Reference in New Issue
Block a user