sync: 鍚屾灞€鍩熺綉鏈€鏂颁唬鐮?(source master @ b69568e4)

This commit is contained in:
gozeros committed 2026-10-21 14:51:31 +08:00
1 parent 4f7f07504a
commit 8bc8b0e082
1651 files changed
+278599 -11416

No files matched your search

@@ -8,7 +8,9 @@ from pathlib import Path
from types import SimpleNamespace
import pytest
from fastapi import HTTPException
from app.gateway.document_rewrite_diagnostics import build_document_rewrite_diagnostic
from app.gateway.routers.writing import (
_REFERENCE_MAX_CHARS,
RewriteRequest,
@@ -19,6 +21,59 @@ from app.gateway.routers.writing import (
)
def test_document_rewrite_diagnostic_is_copyable_and_redacts_secrets():
try:
raise RuntimeError("upstream rejected api_key=secret-value and Bearer abc.def")
except RuntimeError as exc:
diagnostic = build_document_rewrite_diagnostic(
job_id="job-1",
stage="generation",
error_code="RuntimeError",
message=str(exc),
exc=exc,
)
assert diagnostic["jobId"] == "job-1"
assert diagnostic["exceptionType"] == "RuntimeError"
assert "secret-value" not in diagnostic["message"]
assert "abc.def" not in diagnostic["message"]
assert "[REDACTED]" in diagnostic["message"]
assert any("test_writing_rewrite_prompt.py" in line for line in diagnostic["traceTail"])
@pytest.mark.asyncio
async def test_durable_rewrite_start_returns_structured_diagnostic(monkeypatch):
from app.gateway.routers import writing
async def broken_path(*_args):
raise OSError("docker volume is read-only")
async def current_user(*_args):
return "user-a"
monkeypatch.setattr(writing, "aresolve_thread_virtual_path", broken_path)
monkeypatch.setattr(writing, "get_current_user", current_user)
request = SimpleNamespace(
_deerflow_test_bypass_auth=True,
app=SimpleNamespace(state=SimpleNamespace()),
)
body = writing.DocumentRewriteRequest(
threadId="thread-a",
path="/mnt/user-data/report.md",
instruction="统一表达风格",
)
with pytest.raises(HTTPException) as captured:
await writing.start_durable_document_rewrite_job(body=body, request=request)
assert captured.value.status_code == 500
assert captured.value.detail["message"] == "docker volume is read-only"
diagnostic = captured.value.detail["diagnostic"]
assert diagnostic["stage"] == "start"
assert diagnostic["errorCode"] == "OSError"
assert diagnostic["exceptionType"] == "OSError"
def _req(**kwargs) -> RewriteRequest:
base = {
"selection": SelectionInfo(**{"from": 0, "to": 4, "text": "原始文字"}),