Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix(diagnostics): 统一故障分类并修复启动时区依赖

longmeidao5a59eba617b0
diff --git a/docs/DIAGNOSTICS.md b/docs/DIAGNOSTICS.md
index cb1294d30..bc1cf85c2 100644
--- a/docs/DIAGNOSTICS.md
+++ b/docs/DIAGNOSTICS.md
@@ -2,6 +2,15 @@
本页说明异常日志、浏览器错误上报、诊断导出与可选远程诊断的边界。正常取消、缓存回退、来源未命中和任务互斥保留各自状态。
+环境与故障证据按同一套采集和分类函数产生,各输出入口按用途取字段:`reporting_identity` 提供程序、构建与主机量级,`diagnostic_exceptions` 提供异常链的结构化错误码和媒体故障类别,`diagnostic_context` 规范浏览器、播放和运行状态。输出入口不自行重新识别同一故障。
+
+| 输出 | 使用范围 |
+| --- | --- |
+| 本机日志 | 脱敏异常链、错误码、浏览器与播放现场、请求到达和响应媒体类型 |
+| 诊断 ZIP | 从本机日志和当前运行状态汇总有界证据;保留采集失败与未取得状态 |
+| 远程技术诊断 | 仅投影已声明的代码位置、构建身份、结构化错误码与固定故障类别;详细浏览器和播放现场只在本机 |
+| 版本统计、群体研究 | 复用程序和构建身份,分别遵守既有字段、开关与频率契约 |
+
桌面制品验收在临时 Peach 数据目录显式关闭版本统计与错误上传,并在首启提交中保持关闭,避免合成测试进入正式遥测。
## 反馈入口
@@ -37,13 +46,15 @@
| 浏览器 | User-Agent、客户端提示中的品牌、完整版本、平台版本与架构、语言、时区、安全上下文、联网状态、Cookie 与本地存储可用性、视口、像素比、触控点、逻辑核数、浏览器提供的内存档位和可读取的 WebGL 图形厂商与渲染器;详细客户端提示最多等待一秒,受限或不支持时保留原因 |
| 播放能力 | 原生 `canPlayType()` 和 MSE 对 H.264、HEVC、AV1、VP9、AAC、AC-3、Opus 的能力声明;MediaSource 和 MediaCapabilities 是否存在。能力声明不能证明具体媒体已成功解码 |
| 播放失败 | 原生错误码与原因、网络和就绪状态、播放位置、时长、尺寸、缓冲区、播放设置、源协议、同源状态,以及最近八次媒体请求的状态、耗时与字节数 |
-| 服务端播放 | 媒体请求到达记录、Range、播放方案、已缓存的编码与像素格式、时长、文件世代及硬件策略和已有探测结果;诊断不另读媒体或触发转码 |
+| 服务端播放 | 媒体请求到达记录、Range、播放方案、文件响应实际声明的媒体类型、已缓存的编码与像素格式、时长、文件世代及硬件策略和已有探测结果;诊断不另读媒体或触发转码 |
| 检查与任务 | 数据库及迁移详细状态、访问保护、端口状态、近期失败任务编号与时间、脱敏挂载状态、来源健康状态及既有处理、更新和交付回执 |
浏览器和播放上下文只写本机日志,不进入远程上报入口。分享包不包含账号、Cookie、凭据、完整媒体地址、URL 查询串、媒体名称或馆藏清单。记录有字段白名单和大小上限;日志按既有尾部上限导出,汇总最多八份浏览器快照和二十条播放记录。没有完成的请求不会出现在 Resource Timing 中,应结合服务端到达记录判断。工具不可用、存储读取失败、能力 API 不支持与尚未探测分别保留状态或原因。
同一份浏览器环境每分钟记录一次,环境快照独立于每分钟二十条错误的预算;频繁刷新不会占用错误记录名额。显式下载保留当前客户端的快照。
+访问日志保留已知媒体路由、API 路由、HTTP 版本与响应状态码;URL 查询串整体移除,未知路径继续隐藏。`206` 只表示范围响应已发出,不能证明浏览器完成了解码。
+
## 可选远程诊断
安装器、首次设置和设置页「应用与维护」提供「发送版本统计与错误诊断(推荐)」单个选项,默认勾选,同时控制版本统计与错误诊断,可取消勾选或在设置页关闭。静默安装保留已有选择。选项保存在本机 `state/remote-reporting.json`;没有记录时两项默认开启,已保存的关闭选择持续生效,损坏或只开启一项的记录均不发送。不写 ledger。缺少接收端时页面明确提示不会发送,仍可保存选择。
@@ -56,6 +67,10 @@
| 媒体工具 | 退出码,以及确定匹配的 AV1 解码器缺失、非法媒体、权限、磁盘空间或未知解码器类别;stderr 与媒体名称留在本机 |
| 浏览器错误 | 白名单异常类型、Peach 正式脚本的行列位置与公开构建映射 ID;没有可定位堆栈的错误与扩展脚本不发送 |
+SQLite 错误复用本机与远程的结构化错误码;能够确定时附缺表、缺列、锁定、只读、损坏或无法打开的固定类别,不发送表名、列名或 SQL。媒体故障在路径脱敏前提取固定类别,子进程异常本身携带的 stderr 也参与分类。系统不支持文件夹对话框时保留本机状态;支持的平台上对话框启动失败仍进入技术诊断。
+
+远程事件数表示接收端存储的上报批次,`occurrence_count` 表示该批代表的发生次数。每日预算、关闭上传、断网和筛选会造成观测缺失;未收到事件不能解释为没有故障。版本统计每日一次且不含安装标识,不能当作独立用户数、日活或故障率分母。错误事件附带的是服务主机环境,不能据此推断访问页面的客户端系统或浏览器。研究快照与版本统计均是普通事件,仍占用接收平台的事件配额;分项目不隔离组织配额。
+
事件的 `purpose` 区分 `version-statistics`、`technical-diagnostics` 与独立研究通道的 `population-research`。故障视图使用 `level:error purpose:technical-diagnostics`,生产故障可再加 `environment:production`。没有用途标签的历史事件须单独审阅,不按缺失字段推断来源。启动统计是普通 info 事件,应排除在故障视图与告警条件之外。
`environment` 只接受 `production`、`development`、`test`;独立包与普通源码部署默认 `production`,Git 隔离工作树默认 `development`,可用 `PEACH_REPORTING_ENVIRONMENT` 明确指定。`runtime` 为 `packaged` 或 `source`;`dist` 使用构建提交号,不发送本机目录、主机名或自由文本标识。标准测试入口关闭本进程遥测,并向子进程传递 `PEACH_REPORTING_TEST_MODE=1`,在最终 HTTP 请求边界阻止两条通道真实外发;内存接收端仍可验证最终载荷。
diff --git a/docs/REUSE.md b/docs/REUSE.md
index 05a4d5775..3ba4f92d6 100644
--- a/docs/REUSE.md
+++ b/docs/REUSE.md
@@ -169,6 +169,10 @@ DMM / MGS 的只读商品号识别复用 `code_key`、`release_code_from_text`
## STRM 与挂载来源
+诊断输出共用 `reporting_identity` 的环境身份和 `diagnostic_exceptions` 的有限错误分类。媒体 stderr 在通用路径脱敏前归类,SQLite 使用结构化错误码与固定原因类别;本机日志、支持包和远程投影按各自字段契约消费,不引入另一套错误监控 SDK。访问日志只放行固定技术路由与协议状态,查询串整体移除;其余路径继续复用通用脱敏。
+
+任务恢复复用固定版 APScheduler 3.11.3(MIT)和标准库 `datetime.timezone.utc`,与现有关注调度器使用同一时区选择方式。一秒间隔检查不依赖本地 IANA 时区数据库;隔离回归令系统时区读取抛错,仍能创建调度器并注册任务。未新增依赖。
+
响应头策略复用 Starlette 1.8.0(BSD-3-Clause,项目已有固定依赖)的 `MutableHeaders` 与官方 [ASGI 中间件模式](https://www.starlette.io/middleware/#pure-asgi-middleware),只在 `http.response.start` 阶段设置缓存、安全及机器人策略。文件响应继续使用同一 `receive` 的断连消息,真实异常直接传播,不维护异常文本匹配或统一忽略网络错误的分支。整片转码继续复用 FFmpeg 和现有回退链,Peach 只保留有界本机证据与隐私投影,无新增依赖。
本机诊断继续复用项目的脱敏日志与 ZIP 导出,浏览器使用标准 `canPlayType()`、MSE、Resource Timing 和有界的 [UA Client Hints](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorUAData/getHighEntropyValues),服务端复用 Python 3.14 标准库的依赖元数据、磁盘余量、系统信息以及现有媒体探测缓存。字段白名单和本机证据汇总属于 Peach 的诊断边界;浏览器监控 SDK 会扩大依赖与采集范围,不承担这条本机导出链路。依赖沿用 Video.js 10.1.0 与现有 FFmpeg,不增加运行时依赖,不为导出执行媒体读取或硬件压力探测。能力声明与真实播放的区别按 [MDN `canPlayType()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/canPlayType) 和 [Video.js 媒体来源契约](https://videojs.org/docs/framework/html/guides/media-sources)核对,隔离回归覆盖无视频请求、编码能力缺失、错误状态、脱敏和仅本机写入。
diff --git a/frontend/e2e/follow-feed.test.ts b/frontend/e2e/follow-feed.test.ts
index efd61d1c3..e64a47f45 100644
--- a/frontend/e2e/follow-feed.test.ts
+++ b/frontend/e2e/follow-feed.test.ts
@@ -8,7 +8,7 @@ import { after, before, describe, it } from 'node:test';
import type { Browser, Page } from 'playwright-core';
import { FIRST, MORE, openFollowFeed } from './follow-fixture.ts';
-import { launch, layout, VIEWPORTS } from './harness.ts';
+import { launch, layout, settle, VIEWPORTS } from './harness.ts';
const DESKTOP = VIEWPORTS.find((viewport) => !viewport.mobile)!;
const MOBILE = VIEWPORTS.find((viewport) => viewport.mobile)!;
@@ -90,7 +90,8 @@ describe('关注页岛', () => {
} }));
await page.route((url) => url.pathname === '/api/items', (route) =>
route.fulfill({ json: { items: [], total: 0, has_more: false } }));
- await page.reload({ waitUntil: 'networkidle' });
+ await page.reload({ waitUntil: 'load' });
+ await settle(page);
assert.equal(await page.getByRole('searchbox', { name: '搜索创作者' }).count(), 0);
const author = page.locator('[data-follow-authors] a[data-follow-author="name:kou"]');
assert.equal(await author.count(), 1);
@@ -218,7 +219,8 @@ describe('关注页岛', () => {
});
await page.route((url) => url.pathname === '/api/follow' && !url.searchParams.has('item'),
(route) => route.fulfill({ json: payload }));
- await page.reload({ waitUntil: 'networkidle' });
+ await page.reload({ waitUntil: 'load' });
+ await settle(page);
return opened;
};
@@ -488,7 +490,8 @@ describe('关注页岛', () => {
(route) => route.fulfill({ json: payload }));
// 只读服务拒绝尺寸回写时,当前卡片仍使用浏览器取得的尺寸。
await page.route('**/api/follow/image-dims', (route) => route.fulfill({ status: 409, json: { ok: false } }));
- await page.reload({ waitUntil: 'networkidle' });
+ await page.reload({ waitUntil: 'load' });
+ await settle(page);
const image = page.locator('[data-follow-wall] [data-media-pic] > img').first();
await image.waitFor();
await image.evaluate(async (node: HTMLImageElement) => { await node.decode() });
diff --git a/frontend/src/browser-diagnostics.ts b/frontend/src/browser-diagnostics.ts
index 35a90ed64..4938400dc 100644
--- a/frontend/src/browser-diagnostics.ts
+++ b/frontend/src/browser-diagnostics.ts
@@ -24,9 +24,7 @@ export async function detailedBrowserDiagnostics() {
try {
const result = await Promise.race([data.getHighEntropyValues(['fullVersionList', 'architecture', 'bitness', 'platformVersion', 'wow64']),
new Promise<null>(resolve => { timer = setTimeout(() => resolve(null), 1000) })]);
- hints = result ? { status: result.fullVersionList ? 'available' : 'restricted',
- fullVersionList: result.fullVersionList, architecture: result.architecture, bitness: result.bitness,
- platformVersion: result.platformVersion, wow64: result.wow64 } : { status: 'timeout' };
+ hints = result ? { ...result, status: result.fullVersionList ? 'available' : 'restricted' } : { status: 'timeout' };
} catch { hints = { status: 'unavailable' } }
finally { if (timer) clearTimeout(timer) }
})();
diff --git a/src/peach/diagnostic_context.py b/src/peach/diagnostic_context.py
index 68f3a9030..43c292cd7 100644
--- a/src/peach/diagnostic_context.py
+++ b/src/peach/diagnostic_context.py
@@ -164,7 +164,7 @@ def archived_context(archive):
browsers.append({'at': row.get('at'), **context})
if isinstance(row.get('playback'), dict):
media.append({'at': row.get('at'), 'stage': 'browser', **playback(row['playback'])})
- if row.get('stage') in ('playback-request', 'playback-plan'):
+ if row.get('stage') in ('playback-request', 'playback-plan', 'playback-source'):
media.append(row)
return {'recent_browsers': sorted(browsers, key=lambda row: str(row.get('at') or ''))[-8:],
'recent_playback': sorted(media, key=lambda row: str(row.get('at') or ''))[-20:]}
diff --git a/src/peach/diagnostic_exceptions.py b/src/peach/diagnostic_exceptions.py
index c59e05d63..97f0b68de 100644
--- a/src/peach/diagnostic_exceptions.py
+++ b/src/peach/diagnostic_exceptions.py
@@ -3,6 +3,51 @@ from pathlib import Path
import re
FRAME_MODULES = {"peach", "asyncio", "anyio", "starlette", "httpx", "sqlite3", "urllib3"}
+MEDIA_MARKERS = (("Your platform doesn't support hardware accelerated AV1 decoding", 'av1_decoder_unavailable'),
+ ('Unknown decoder', 'decoder_unavailable'), ('Invalid data found', 'invalid_media'),
+ ('Permission denied', 'permission_denied'), ('No space left', 'disk_full'),
+ ('No such file or directory', 'missing_media'))
+
+
+def media_details(error, fields, codes):
+ """媒体原始错误在脱敏前归类,输出只包含固定类别和退出码。"""
+ detail = getattr(error, 'diagnostics', {}) if error is not None else {}
+ detail = detail if isinstance(detail, dict) else {}
+ if type(detail.get('returncode')) is int:
+ codes['returncode'] = detail['returncode']
+ known = {category for _, category in MEDIA_MARKERS} | {'ffmpeg_error', 'no_frame'}
+ category = detail.get('failure_category')
+ if isinstance(category, str) and category in known:
+ return category
+ raw = '\n'.join(value.decode('utf-8', 'replace') if isinstance(value, bytes) else str(value or '')
+ for value in (fields.get('stderr'), detail.get('stderr'), getattr(error, 'stderr', '')))
+ for marker, category in MEDIA_MARKERS:
+ if marker in raw:
+ return category
+ reason = detail.get('reason', fields.get('reason'))
+ return reason if isinstance(reason, str) and reason in {'ffmpeg_error', 'no_frame'} else ''
+
+
+def structured_codes(error):
+ """本机与远程共用有限错误码,数据库名称和查询内容不进入类别。"""
+ codes = {}
+ for key in ('errno', 'winerror', 'returncode', 'sqlite_errorcode'):
+ value = getattr(error, key, None)
+ if type(value) is int:
+ codes[key] = str(value)
+ name = getattr(error, 'sqlite_errorname', '')
+ if isinstance(name, str) and re.fullmatch(r'SQLITE_[A-Z_]{1,50}', name):
+ codes['sqlite_errorname'] = name
+ text = str(error).casefold()
+ for prefix, category in (('no such table:', 'missing_table'), ('no such column:', 'missing_column'),
+ ('database is locked', 'locked'), ('database table is locked', 'locked'),
+ ('attempt to write a readonly database', 'readonly'),
+ ('database disk image is malformed', 'malformed'),
+ ('unable to open database file', 'cannot_open')):
+ if text.startswith(prefix):
+ codes['sqlite_failure'] = category
+ break
+ return codes
def project(error, http_status):
@@ -13,13 +58,7 @@ def project(error, http_status):
visited.add(id(current))
name = type(current).__name__
chain.append(name)
- for key in ("errno", "winerror", "returncode", "sqlite_errorcode"):
- value = getattr(current, key, None)
- if type(value) is int:
- codes[key] = str(value)
- sqlite_name = getattr(current, "sqlite_errorname", "")
- if isinstance(sqlite_name, str) and re.fullmatch(r"SQLITE_[A-Z_]{1,50}", sqlite_name):
- codes["sqlite_errorname"] = sqlite_name
+ codes.update(structured_codes(current))
if (status := http_status(current)) is not None:
codes["status_code"] = str(status)
frames = []
diff --git a/src/peach/error_reporting.py b/src/peach/error_reporting.py
index ee3fa5e8a..b1106557f 100644
--- a/src/peach/error_reporting.py
+++ b/src/peach/error_reporting.py
@@ -121,6 +121,7 @@ def system_facts() -> dict:
def exception_facts(error: BaseException) -> dict:
+ from .diagnostic_exceptions import structured_codes
frames = []
seen = set()
current = error
@@ -130,6 +131,7 @@ def exception_facts(error: BaseException) -> dict:
chain.append({"type": type(current).__name__, "message": redact(str(current))[:4000],
"winerror": getattr(current, "winerror", None), "errno": getattr(current, "errno", None),
"operation": getattr(current, "peach_operation", None),
+ "codes": structured_codes(current),
"context": getattr(current, "peach_context", None)})
for frame in traceback.extract_tb(current.__traceback__)[-40:]:
frames.append({"file": Path(frame.filename).name, "line": frame.lineno, "function": frame.name})
@@ -171,8 +173,8 @@ def subprocess_failure(stage: str, *, tool: str, error: BaseException | None = N
"""媒体子进程仅保留工具名、错误码和有界错误输出,不记录完整命令。"""
raw = stderr or getattr(error, 'stderr', b'') or b''
text = raw.decode('utf-8', 'replace') if isinstance(raw, bytes) else str(raw)
- from .remote_reporting import _media_details
- reason = _media_details(error, {'stderr': text}, {})
+ from .diagnostic_exceptions import media_details
+ reason = media_details(error, {'stderr': text}, {})
return event(stage, error, tool=Path(tool).name, returncode=returncode,
stderr=text[-4000:], local_fields={'reason_code': reason or 'unclassified'}, **fields)
diff --git a/src/peach/folder_picker.py b/src/peach/folder_picker.py
index 57e0b2998..f098763c2 100644
--- a/src/peach/folder_picker.py
+++ b/src/peach/folder_picker.py
@@ -28,6 +28,10 @@ class PickerUnavailable(RuntimeError):
"""这台机器上没有可用的文件夹对话框,或者对话框没能打开。"""
+class PickerUnsupported(PickerUnavailable):
+ """当前平台不提供系统文件夹对话框。"""
+
+
class PickerBusy(RuntimeError):
"""已经有一个对话框开着:系统对话框是模态的,第二个只会藏在第一个后面。"""
@@ -165,7 +169,7 @@ def command(initial: str | None, platform: str = sys.platform) -> tuple[list[str
if initial and os.path.isdir(initial):
script += f' default location POSIX file "{_applescript_string(initial)}"'
return ["osascript", "-e", f"POSIX path of ({script})"], {}
- raise PickerUnavailable("这个系统上没有可用的文件夹对话框")
+ raise PickerUnsupported("这个系统上没有可用的文件夹对话框")
def pick_folder(initial: str | None = None, *, platform: str = sys.platform,
diff --git a/src/peach/library_processing.py b/src/peach/library_processing.py
index 0884b793d..2c37c89a7 100644
--- a/src/peach/library_processing.py
+++ b/src/peach/library_processing.py
@@ -1988,7 +1988,9 @@ class _PreviewCaptureError(ValueError):
def __init__(self, diagnostics):
from .error_reporting import scrub
- self.diagnostics = scrub(diagnostics)
+ from .diagnostic_exceptions import media_details
+ category = media_details(None, diagnostics, {})
+ self.diagnostics = {**scrub(diagnostics), 'failure_category': category or 'unclassified'}
message = {
'timeout': '视频抽帧超时,可重试;反馈问题请导出诊断报告',
'ffmpeg_error': 'FFmpeg 抽帧失败,反馈问题请导出诊断报告',
diff --git a/src/peach/remote_reporting.py b/src/peach/remote_reporting.py
index eb18e8428..cce79cb60 100644
--- a/src/peach/remote_reporting.py
+++ b/src/peach/remote_reporting.py
@@ -16,6 +16,7 @@ from pathlib import Path
from urllib.parse import urlsplit
from .reporting_identity import event_metadata, machine_facts
+from .diagnostic_exceptions import media_details
FIELDS = {
"usage": "Peach 版本、分发方式(Windows/macOS 应用、Docker、wheel 或源码)、操作系统类型与版本、CPU 架构与核数、内存档位、Python 版本、运行环境与公开构建编号;每天最多一次,不含安装标识。",
@@ -290,27 +291,19 @@ def _exception_details(error):
return project(error, _http_status)
-def _media_details(error, fields, codes):
- detail = getattr(error, "diagnostics", {}) if error is not None else {}
- detail = detail if isinstance(detail, dict) else {}
- if type(detail.get("returncode")) is int:
- codes["returncode"] = detail["returncode"]
- raw = str(fields.get("stderr", "")) + str(detail.get("stderr", ""))
- for marker, code in (("Your platform doesn't support hardware accelerated AV1 decoding", "av1_decoder_unavailable"),
- ("Unknown decoder", "decoder_unavailable"),
- ("Invalid data found", "invalid_media"), ("Permission denied", "permission_denied"),
- ("No space left", "disk_full"), ("No such file or directory", "missing_media")):
- if marker in raw:
- return code
- return ""
-
-
def _media_failure(stage, error):
return stage in MEDIA_STAGES or any(cls.__module__ == 'peach.transcodes'
and cls.__name__ == 'TranscodeUnavailable' for cls in type(error).__mro__)
def _expected_failure(stage, error, fields):
+ current, visited = error, set()
+ while current is not None and id(current) not in visited and len(visited) < 8:
+ visited.add(id(current))
+ if any((cls.__module__, cls.__name__) == ('peach.folder_picker', 'PickerUnsupported')
+ for cls in type(current).__mro__):
+ return True
+ current = current.__cause__ or (None if current.__suppress_context__ else current.__context__)
if stage == "logging" and fields.get("level", "ERROR") not in {"ERROR", "CRITICAL"}:
return True
if stage == "browser" and fields.get("error_name") == "AbortError":
@@ -394,7 +387,7 @@ def _technical_projection(stage, error, fields):
codes[key] = fields[key]
reason = ""
if media_stage:
- reason = _media_details(error, fields, codes)
+ reason = media_details(error, fields, codes)
if reason in {"invalid_media", "permission_denied", "disk_full", "missing_media"}:
return
if not reason and not codes and error is None:
diff --git a/src/peach/routes_media.py b/src/peach/routes_media.py
index 86b20c641..5b59ae646 100644
--- a/src/peach/routes_media.py
+++ b/src/peach/routes_media.py
@@ -282,6 +282,8 @@ def stream(request: Request, id: int, session: str = "", args: dict[str, str] =
if transcoded:
response.headers["X-Peach-Transcoded"] = "1"
response.headers["Cache-Control"] = "no-store"
+ local_event('playback-source', asset_id=id, mime_type=response.headers.get('content-type', ''),
+ transcoded=transcoded, session_present=bool(session))
return response
diff --git a/src/peach/support_bundle.py b/src/peach/support_bundle.py
index a92449057..54d287dcf 100644
--- a/src/peach/support_bundle.py
+++ b/src/peach/support_bundle.py
@@ -5,6 +5,7 @@ import io
import argparse
import json
import os
+import re
import zipfile
from datetime import datetime, timezone
from pathlib import Path
@@ -20,6 +21,19 @@ STATE_NAMES = ('library-processing.json', 'runtime-prepare.json', 'standalone-up
#: 发现页封面逐番号处理结果的份数上限;每份只有几十字节,排查缺封面靠它们。
COVER_ATTEMPT_LIMIT = 500
TAIL_BYTES = 96 * 1024
+ACCESS_REQUEST = re.compile(r'^(.*?"(?:GET|HEAD|POST|PUT|PATCH|DELETE|OPTIONS) )([^"\s]+)( HTTP/\d(?:\.\d)?" \d{3}[^\r\n]*)$')
+MEDIA_ROUTE = re.compile(r'/(?:stream|follow-stream|preview-stream|stream/hls/\d+/(?:index\.m3u8|\d+\.ts))')
+
+
+def _access_log(line: str) -> str:
+ """访问日志只保留技术路由、HTTP 版本与状态码,查询串整体移除。"""
+ match = ACCESS_REQUEST.fullmatch(line)
+ if not match:
+ return error_reporting.redact(line)
+ prefix, target, suffix = match.groups()
+ path = target.split('?', 1)[0].split('#', 1)[0]
+ route = path if MEDIA_ROUTE.fullmatch(path) or re.fullmatch(r'/api/[a-zA-Z0-9_/{}/:-]{1,180}', path) or path == '/healthz' else '<path>'
+ return error_reporting.redact(prefix) + route + error_reporting.redact(suffix)
def _processing_log(text: str) -> str:
@@ -55,7 +69,7 @@ def redact_log(text: str) -> str:
try:
value = json.loads(line)
except ValueError:
- lines.append(error_reporting.redact(line))
+ lines.append(_access_log(line))
else:
lines.append(json.dumps(error_reporting.scrub(value), ensure_ascii=False))
return "\n".join(lines) + ("\n" if text.endswith("\n") else "")
diff --git a/src/peach/web_job_recovery.py b/src/peach/web_job_recovery.py
index e8b032ee2..a2ad0c990 100644
--- a/src/peach/web_job_recovery.py
+++ b/src/peach/web_job_recovery.py
@@ -1,4 +1,5 @@
"""Web 组合入口为可恢复任务装配领域处理器。"""
+from datetime import timezone
from .job_recovery import resume
from .web_library_processing import w_library_processing
from .web_scraping import w_scraping_cover, w_scraping_amane_rebuild
@@ -41,7 +42,7 @@ class RecoveryService:
def __init__(self, contract, *, available):
self.contract = contract
self.available = available
- self.scheduler = BackgroundScheduler()
+ self.scheduler = BackgroundScheduler(timezone=timezone.utc)
def start(self):
if self.available and not self.scheduler.running:
diff --git a/tests/test_error_reporting.py b/tests/test_error_reporting.py
index 69aa5ade3..9e0197183 100644
--- a/tests/test_error_reporting.py
+++ b/tests/test_error_reporting.py
@@ -17,6 +17,18 @@ ROOT = Path(__file__).resolve().parents[1]
class ErrorReportingTests(unittest.TestCase):
+ def test_access_export_keeps_media_response_evidence_and_removes_queries(self):
+ for target in ('/stream?id=9&session=private-session', '/follow-stream?ticket=private-ticket',
+ '/api/stream-plan?id=9&t=private-token', '/stream/hls/9/index.m3u8?token=private-token'):
+ with self.subTest(target=target):
+ exported = support_bundle.redact_log(f'INFO: 192.168.1.2:3456 - "GET {target} HTTP/1.1" 206 Partial Content\n')
+ self.assertIn(f'GET {target.split("?")[0]} HTTP/1.1" 206 Partial Content', exported)
+ for private in ('192.168.1.2', 'private-', '?', 'session=', 'ticket='):
+ self.assertNotIn(private, exported)
+ exported = support_bundle.redact_log('INFO: "GET /home/private/movie.mp4?token=secret HTTP/1.1" 404 Not Found\n')
+ self.assertIn('GET <path> HTTP/1.1" 404 Not Found', exported)
+ self.assertNotIn('private', exported)
+
def setUp(self):
self.temp = tempfile.TemporaryDirectory()
self.addCleanup(self.temp.cleanup)
diff --git a/tests/test_remote_reporting.py b/tests/test_remote_reporting.py
index e746b5b4b..726b5d2cb 100644
--- a/tests/test_remote_reporting.py
+++ b/tests/test_remote_reporting.py
@@ -325,6 +325,22 @@ class RemoteReportingTests(unittest.TestCase):
self.assertEqual(send.call_args.args[1]['exception']['values'][0]['stacktrace']['frames'],
[{'filename': 'peach-app.js', 'abs_path': 'app:///peach-app.js', 'lineno': 12, 'colno': 34}])
+ def test_unsupported_folder_picker_is_local_and_dialog_failures_are_reported(self):
+ from peach.folder_picker import command, PickerUnavailable
+ from fastapi import HTTPException
+ try:
+ command(None, platform='linux')
+ except PickerUnavailable as cause:
+ unsupported = HTTPException(501, 'private')
+ unsupported.__cause__ = cause
+ with mock.patch.object(reporting, 'send') as send:
+ reporting.capture('http-request', unsupported, status_code=501, route='api/pick-folder')
+ send.assert_not_called()
+ failed = HTTPException(501, 'private')
+ failed.__cause__ = PickerUnavailable('private')
+ reporting.capture('http-request', failed, status_code=501, route='api/pick-folder')
+ send.assert_called_once()
+
def test_control_and_source_states_keep_local_records_without_remote_events(self):
import asyncio
from concurrent.futures import CancelledError
diff --git a/tests/test_reporting_fault_fixes.py b/tests/test_reporting_fault_fixes.py
index 1ad374d8e..f30545e65 100644
--- a/tests/test_reporting_fault_fixes.py
+++ b/tests/test_reporting_fault_fixes.py
@@ -16,6 +16,16 @@ from peach.transcodes import TranscodeService, TranscodeUnavailable
class FaultFixTests(unittest.TestCase):
+ def test_recovery_scheduler_works_without_local_timezone_data(self):
+ from datetime import timezone
+ from zoneinfo import ZoneInfoNotFoundError
+ from peach.web_job_recovery import RecoveryService
+ with mock.patch('apscheduler.schedulers.base.get_localzone', side_effect=ZoneInfoNotFoundError('synthetic')):
+ service = RecoveryService(mock.Mock(), available=True)
+ self.assertEqual(service.scheduler.timezone, timezone.utc)
+ service.scheduler.add_job(service.tick, 'interval', seconds=1)
+ self.assertEqual(len(service.scheduler.get_jobs()), 1)
+
def test_early_disconnect_returns_without_a_server_exception(self):
async def exercise(path):
async def inner(scope, receive, send):
diff --git a/tests/test_reporting_projection.py b/tests/test_reporting_projection.py
index dcbbaf395..bb2180cf1 100644
--- a/tests/test_reporting_projection.py
+++ b/tests/test_reporting_projection.py
@@ -7,6 +7,21 @@ from peach import diagnostic_browser, diagnostic_exceptions, remote_reporting
class ReportingProjectionTests(unittest.TestCase):
+ def test_media_categories_survive_preview_scrubbing_and_read_subprocess_stderr(self):
+ import subprocess
+ from peach.library_processing import _PreviewCaptureError
+ error = _PreviewCaptureError({'reason': 'ffmpeg_error', 'returncode': 1,
+ 'stderr': '/private/media/movie.mp4: Invalid data found when processing input'})
+ self.assertEqual(error.diagnostics['failure_category'], 'invalid_media')
+ self.assertNotIn('private', json.dumps(error.diagnostics))
+ with mock.patch.object(remote_reporting, 'send') as send:
+ remote_reporting.capture('library-preview', error)
+ send.assert_not_called()
+ failed = subprocess.CalledProcessError(1, 'ffprobe', stderr=b'Unknown decoder private-decoder')
+ remote_reporting.capture('media-probe', failed)
+ self.assertEqual(send.call_args.args[1]['tags']['media_failure'], 'decoder_unavailable')
+ self.assertNotIn('private', json.dumps(send.call_args.args[1]))
+
def test_python_chain_has_separate_frames_and_sqlite_error_identity(self):
code = compile('def fail():\n import sqlite3\n connection = sqlite3.connect(":memory:")\n'
' try:\n connection.execute("SELECT private_column")\n'
@@ -21,9 +36,23 @@ class ReportingProjectionTests(unittest.TestCase):
self.assertEqual(chain, ['RuntimeError', 'OperationalError'])
self.assertEqual([value['type'] for value in values], ['OperationalError', 'RuntimeError'])
self.assertEqual(codes['sqlite_errorname'], 'SQLITE_ERROR')
+ self.assertEqual(codes['sqlite_failure'], 'missing_column')
self.assertTrue(all(value['stacktrace']['frames'] for value in values))
self.assertNotIn('private', json.dumps(values))
+ def test_sqlite_categories_are_shared_with_local_evidence_without_query_names(self):
+ import sqlite3
+ from peach import error_reporting
+ with sqlite3.connect(':memory:') as connection:
+ try:
+ connection.execute('SELECT * FROM private_table')
+ except sqlite3.OperationalError as error:
+ codes = diagnostic_exceptions.structured_codes(error)
+ local = error_reporting.exception_facts(error)
+ self.assertEqual(codes['sqlite_failure'], 'missing_table')
+ self.assertEqual(local['exception'][0]['codes'], codes)
+ self.assertNotIn('private', json.dumps(codes))
+
def test_framework_frames_and_nested_peach_modules_are_locatable(self):
namespace = {'__name__': 'starlette.middleware.base'}
exec(compile('def fail():\n raise RuntimeError("private request")\n',
diff --git a/web/dist/peach-pages.js b/web/dist/peach-pages.js
index d64b06137..53645f370 100644
--- a/web/dist/peach-pages.js
+++ b/web/dist/peach-pages.js
@@ -2,7 +2,7 @@
(function() {
try {
var e = typeof window < "u" ? window : typeof global < "u" ? global : typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : {}, t = new e.Error().stack;
- t && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[t] = "0a93752e-4280-4eac-abf6-4113044e3a89", e._sentryDebugIdIdentifier = "sentry-dbid-0a93752e-4280-4eac-abf6-4113044e3a89");
+ t && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[t] = "0fb74f82-3237-4738-985c-ee5234b69319", e._sentryDebugIdIdentifier = "sentry-dbid-0fb74f82-3237-4738-985c-ee5234b69319");
} catch {}
})();
var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescriptor, r = Object.getOwnPropertyNames, i = Object.getPrototypeOf, a = Object.prototype.hasOwnProperty, o = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), s = (e, i, o, s) => {
@@ -49,12 +49,8 @@ async function g() {
t = setTimeout(() => e(null), 1e3);
})]);
m = n ? {
- status: n.fullVersionList ? "available" : "restricted",
- fullVersionList: n.fullVersionList,
- architecture: n.architecture,
- bitness: n.bitness,
- platformVersion: n.platformVersion,
- wow64: n.wow64
+ ...n,
+ status: n.fullVersionList ? "available" : "restricted"
} : { status: "timeout" };
} catch {
m = { status: "unavailable" };
@@ -21737,4 +21733,4 @@ var r_ = document.getElementById("peach-page"), i_ = r_ ? n_[r_.dataset.page ??
r_ && i_ && (0, M.createRoot)(r_).render(/* @__PURE__ */ (0, z.jsx)(i_, { data: { ...r_.dataset } }));
//#endregion
-//# debugId=0a93752e-4280-4eac-abf6-4113044e3a89
\ No newline at end of file
+//# debugId=0fb74f82-3237-4738-985c-ee5234b69319
\ No newline at end of file