feat(asset): 清理被截断的结尾图片引用,修复整单 502
仓库首次入库(此前仅存在于本地工作区与测试服构建产物中,未上传)。 改动(src/knowledge_adapter/asset_content_processor.py): - 新增 _TRUNCATED_TRAILING_MARKDOWN_RESOURCE_IMAGE 规则,清除 chunk 末尾被截断的  - 回归测试 tests/test_asset_content_processor.py:: test_truncated_trailing_markdown_resource_image_is_removed 验证证据: - 测试服 120.76.217.51,镜像 knowledge-adapter-service:reviewed-test-aeab4b5fca2d (release aeab4b5fca2d8661):KB d015d05c-25c8-4d63-b2ab-e8590d3c2dfb 5 个查询全部 http=200、records=5、残留 resource:// = 0;KB b9dacd62 无退化;容器日志无 error/exception - 本地:pytest 141 项全通过、ruff 全通过 - 该文件与 258c31e0fe07fd08 源码的差异经逐文件 md5 比对,为唯一变更文件
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python3
|
||||
import hashlib
|
||||
import json
|
||||
import subprocess
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
|
||||
query_script = open("/tmp/query_active_asset_id.py", "rb").read()
|
||||
result = subprocess.run(
|
||||
["docker", "exec", "-i", "knowledge-adapter-adapter-1", "python", "-"],
|
||||
input=query_script,
|
||||
capture_output=True,
|
||||
check=True,
|
||||
)
|
||||
asset_id = result.stdout.decode().strip()
|
||||
if not asset_id:
|
||||
raise SystemExit("no active asset mapping")
|
||||
path = "/i/" + asset_id
|
||||
|
||||
|
||||
class NoRedirect(urllib.request.HTTPRedirectHandler):
|
||||
def redirect_request(self, *args: object, **kwargs: object) -> None:
|
||||
return None
|
||||
|
||||
|
||||
def request(follow: bool) -> tuple[int, dict[str, str], bytes]:
|
||||
req = urllib.request.Request(
|
||||
"http://127.0.0.1" + path,
|
||||
headers={"Host": "weknora-api-test.dobot.cn"},
|
||||
)
|
||||
opener = (
|
||||
urllib.request.build_opener()
|
||||
if follow
|
||||
else urllib.request.build_opener(NoRedirect())
|
||||
)
|
||||
try:
|
||||
with opener.open(req, timeout=30) as response:
|
||||
return response.status, dict(response.headers.items()), response.read(20_000_000)
|
||||
except urllib.error.HTTPError as exc:
|
||||
return exc.code, dict(exc.headers.items()), exc.read(1000)
|
||||
|
||||
|
||||
status, headers, _ = request(False)
|
||||
location = headers.get("Location", "")
|
||||
report: dict[str, object] = {
|
||||
"active_mapping_found": True,
|
||||
"redirect_status": status,
|
||||
"cache_control": headers.get("Cache-Control"),
|
||||
"referrer_policy": headers.get("Referrer-Policy"),
|
||||
"location_https": location.startswith("https://"),
|
||||
"location_not_logged": True,
|
||||
}
|
||||
if status != 302 or not location.startswith("https://"):
|
||||
raise SystemExit(json.dumps(report))
|
||||
status, _, body = request(True)
|
||||
report["follow"] = {
|
||||
"status": status,
|
||||
"bytes": len(body),
|
||||
"sha256_prefix": hashlib.sha256(body).hexdigest()[:12],
|
||||
}
|
||||
print(json.dumps(report))
|
||||
Reference in New Issue
Block a user