Skip to content

armgit / peach

Public Imported from GitHub
0

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

fix(diagnostics): 仅显示当前周的研究上传状态

longmeidao315a76004baf
diff --git a/docs/DIAGNOSTICS.md b/docs/DIAGNOSTICS.md
index e56af88f7..d216e384f 100644
--- a/docs/DIAGNOSTICS.md
+++ b/docs/DIAGNOSTICS.md
@@ -104,7 +104,7 @@
后台只有在有效同意和独立接收端同时存在时才读取明细并初始化 SDK。快照须至少包含一部公共编号作品或一个偏好分组;没有可分析内容时记为 `waiting-data`,每小时重新检查,不占周传输机会。收集、压缩或入队前失败可以重新准备。每机每 UTC 自然周最多通过一次最终发送门槛,跨进程使用同一文件锁预约;重新选择同意不重置周限次。实际发送后无论明确失败还是结果未知,本周均不再发送,不补传历史快照。空快照不会进入研究样本,分析结果须披露这个筛选口径。
-`state/library-sharing-attempt.json` 区分 `waiting-data`、`queued`、`accepted`、`failed`、`unknown` 与 `blocked`,`attempted` 表示是否已通过最终发送门槛。`accepted` 仅证明取得 HTTP 2xx;未取得 HTTP 回执、网络中断和历史无回执记录均不解释为接收成功。旧字段版本、旧 UTC 周与旧同意版本的队列不能发送;旧尝试回执不能覆盖新尝试。
+`state/library-sharing-attempt.json` 区分 `waiting-data`、`queued`、`accepted`、`failed`、`unknown` 与 `blocked`,`attempted` 表示是否已通过最终发送门槛。设置 API 的 `last_attempt` 只提供当前 UTC 周的回执,跨周不改写原记录。`accepted` 仅证明取得 HTTP 2xx;未取得 HTTP 回执、网络中断和历史无回执记录均不解释为接收成功。旧字段版本、旧 UTC 周与旧同意版本的队列不能发送;旧尝试回执不能覆盖新尝试。
原始 JSON 上限 100 MiB,gzip 附件上限 18 MiB;任一超限均整份拒绝,不发送截断数据。gzip 头不含源文件名和生成时间。传输只接受固定用途事件、固定文件名附件与字段白名单,后台真正发送前复查同意版本。关闭让排队记录失效,已发送数据无法经本机开关撤回。
diff --git a/src/peach/library_sharing.py b/src/peach/library_sharing.py
index 966967ce9..6ba640e5b 100644
--- a/src/peach/library_sharing.py
+++ b/src/peach/library_sharing.py
@@ -90,7 +90,7 @@ def snapshot(config):
attempt = {**attempt, "status": "unknown", "attempted": True}
return {"enabled": bool(consent(config)), "available": bool(target()),
"schema": SCHEMA, "fields": FIELDS, "notice": NOTICE,
- "last_attempt": attempt if attempt.get("schema") == SCHEMA else {}}
+ "last_attempt": attempt if attempt.get("schema") == SCHEMA and attempt.get("period") == _period() else {}}
def collect(contract):
diff --git a/tests/test_library_sharing.py b/tests/test_library_sharing.py
index f7163ad8c..0e85597d3 100644
--- a/tests/test_library_sharing.py
+++ b/tests/test_library_sharing.py
@@ -437,6 +437,18 @@ class LibrarySharingTests(unittest.TestCase):
self.service.attempt()
collect.assert_not_called()
+ def test_settings_snapshot_only_exposes_the_current_week_without_changing_receipts(self):
+ self.enable()
+ for status in ('failed', 'unknown', 'waiting-data', 'accepted'):
+ with self.subTest(status=status):
+ state = {'schema': sharing.SCHEMA, 'period': sharing._period(),
+ 'status': status, 'attempted': True}
+ sharing._state_path(self.config).write_text(json.dumps(state))
+ self.assertEqual(sharing.snapshot(self.config)['last_attempt'], state)
+ with mock.patch.object(sharing, '_period', return_value='2099-W01'):
+ self.assertEqual(sharing.snapshot(self.config)['last_attempt'], {})
+ self.assertEqual(self.attempt_state(), state)
+
def test_concurrent_services_allow_only_one_network_reservation(self):
self.add_work()
self.enable()