Skip to content

armgit / peach

Public Imported from GitHub
0

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

fix(test): 校验分片结束码与完成报告

longmeidaod03183c9a7dd
diff --git a/docs/TESTING.md b/docs/TESTING.md
index 6f27dccfb..e3bb727d7 100644
--- a/docs/TESTING.md
+++ b/docs/TESTING.md
@@ -212,7 +212,7 @@ macOS Release 使用 `macos-15`(Apple Silicon)和 `macos-15-intel`(Intel
`auto` 扫描同环境的有效记录,按测试文件合并 24 小时内、未受输入差异影响的成功结果;记录数量没有固定搜索上限。每项保留原通过时间,最新的失败或未完成状态阻止旧成功结果恢复。缺少、损坏、过期或未来时间的证明不计入覆盖;单份损坏记录不影响其他候选。`-Fresh` 与显式 `full` 始终实际执行请求范围。
-正式父运行在开始时原子保存待验证状态,每个分片完成后立即保存检查点。失败批次仍保留成功文件、成功补充用例及其时间;整文件状态不覆盖已取得的单项结果。共享输入变化和 `Fresh` 同时作用于文件及其补充用例。快速门槛失败时,其余文件保持未完成。进程中断后,下一次 `auto` 在所需范围内补齐缺少的文件,串行与并行使用相同结果模型。分片报告必须完整且格式有效;异常退出不能签发该片的整体成功。分片写出完成报告后仍未退出的进程,等待 15 秒后回收该片的进程树,不给尚在执行的测试设置额外时限。
+正式父运行在开始时原子保存待验证状态,每个分片完成后立即保存检查点。失败批次仍保留成功文件、成功补充用例及其时间;整文件状态不覆盖已取得的单项结果。共享输入变化和 `Fresh` 同时作用于文件及其补充用例。快速门槛失败时,其余文件保持未完成。进程中断后,下一次 `auto` 在所需范围内补齐缺少的文件,串行与并行使用相同结果模型。分片报告必须完整且格式有效,结束码须与报告一致;异常退出不能产生该片的成功证明。分片写出完成报告后仍未退出的进程,等待 15 秒后回收该片的进程树,不给尚在执行的测试设置额外时限。
浏览器与 Vitest 容器内按外部测试文件保存完成结果,只有逐条输出不能证明整个文件完成。恢复计划绑定当前输入快照、完整文件集合及每个省略项的成功时间。Python 容器用例自身也必须有成功证明,才能连同其外部文件一起省略;容器的后置检查失败仍需补测。选择参数只在对应容器用例执行期间启用,普通 Python 用例不继承这些参数;失败或退出时恢复环境。外部选择仅由正式父运行生成,`Focus` 和独立 CI 分片不签发正式记录。
diff --git a/scripts/test_resume.py b/scripts/test_resume.py
index afe9ff820..bdac7b0fd 100644
--- a/scripts/test_resume.py
+++ b/scripts/test_resume.py
@@ -215,7 +215,7 @@ def report_units(assigned, report: dict, *, clean_exit: bool, external=None, cas
result[unit] = {'outcome': 'pass', 'at': stamp}
elif module not in grouped:
result[module] = {'outcome': 'unknown', 'at': stamp}
- if ((report.get('success') and not clean_exit) or report.get('count', 0) <= 0
+ if (not clean_exit or report.get('count', 0) <= 0
or unattributed_failure(assigned, report, cases)):
result = {name: {**row, 'outcome': 'unknown'} if row['outcome'] == 'pass' else row
for name, row in result.items()}
diff --git a/scripts/test_runner.py b/scripts/test_runner.py
index 82add997b..284e5ab33 100644
--- a/scripts/test_runner.py
+++ b/scripts/test_runner.py
@@ -920,7 +920,7 @@ def run_shards(scopes: tuple[str, ...], *, jobs: int, shard_count: int,
if checkpoint is not None:
assigned = plan[index] if plan is not None else sorted({path.name for scope in scopes
for path in selected_files(scope)})[index::shard_count]
- complete = checkpoint(assigned, report, process.returncode == 0)
+ complete = checkpoint(assigned, report, process.returncode == (0 if report.get('success') else 1))
ok = ok and complete
passed = passed and ok
count += int(report.get("count", 0))
@@ -1114,7 +1114,7 @@ def run_serial_suite(scopes, chosen, original, progress, label):
if progress is not None:
complete = progress.checkpoint([path.name for path in chosen], {
'success': passed, 'count': result.testsRun, 'files': result.files, 'results': rows,
- 'complete': True}, passed)
+ 'complete': True}, True)
passed = passed and complete
return passed, result.testsRun, result.timings
diff --git a/tests/test_test_evidence.py b/tests/test_test_evidence.py
index b5b7ad75f..305356495 100644
--- a/tests/test_test_evidence.py
+++ b/tests/test_test_evidence.py
@@ -37,6 +37,24 @@ def fixture_process(command, root, env):
class ParallelShardTests(unittest.TestCase):
+ def test_checkpoint_exit_status_must_match_the_report(self):
+ def exercise(success, code):
+ observed = []
+ def spawn(command, **kwargs):
+ report = Path(command[command.index('--timings') + 1])
+ report.write_text(json.dumps({'complete': True, 'success': success, 'count': 1, 'timings': []}), encoding='utf8')
+ return mock.Mock(returncode=code, poll=lambda: code)
+ def checkpoint(assigned, report, normal):
+ observed.append(normal)
+ return True
+ with redirect_stdout(io.StringIO()):
+ runner.run_shards(('checks',), jobs=1, shard_count=1, plan=[['test_a.py']],
+ spawn=spawn, checkpoint=checkpoint)
+ return observed
+ for success, code, expected in ((False, 1, True), (False, 15, False), (True, 1, False), (True, 0, True)):
+ with self.subTest(success=success, code=code):
+ self.assertEqual(exercise(success, code), [expected])
+
def test_imported_verification_code_belongs_to_this_workspace(self):
self.assertEqual(Path(runner.__file__).resolve().parents[1], Path(__file__).resolve().parents[1])
self.assertEqual(Path(evidence.__file__).resolve().parents[1], Path(__file__).resolve().parents[1])
@@ -344,6 +362,14 @@ class ReceiptTests(ReceiptFixture, unittest.TestCase):
units = test_resume.report_units(['test_catalog.py'], report, clean_exit=False)
self.assertEqual(units['test_catalog.py']['outcome'], 'unknown')
+ def test_abnormal_exit_does_not_preserve_positive_rows_in_a_failed_report(self):
+ report = {'success': False, 'count': 2, 'results': [
+ {'id': 'test_catalog.Suite.test_value', 'outcome': 'pass'},
+ {'id': 'test_web.Suite.test_value', 'outcome': 'fail'}]}
+ units = test_resume.report_units(['test_catalog.py', 'test_web.py'], report, clean_exit=False)
+ self.assertEqual(test_resume.passed_units(units), set())
+ self.assertEqual(units['test_web.py']['outcome'], 'fail')
+
class CheckpointTests(ReceiptFixture, unittest.TestCase):
def setUp(self):
@@ -549,6 +575,23 @@ class CheckpointTests(ReceiptFixture, unittest.TestCase):
self.assertTrue(progress.complete())
self.assertNotIn('test_extra.py', progress.units)
+ def test_serial_failure_preserves_the_successful_file(self):
+ progress = self.progress()
+ progress.start()
+ def exercise(case):
+ if type(case).__module__ == 'test_web':
+ case.fail('fixture')
+ suite = unittest.TestSuite(type('Suite', (unittest.TestCase,),
+ {'__module__': name.removesuffix('.py'), 'test_value': exercise})('test_value')
+ for name in ('test_catalog.py', 'test_web.py'))
+ chosen = set(self.mapping['full'])
+ with mock.patch.object(runner, 'build_suite', return_value=suite), \
+ mock.patch.object(runner, 'save_file_seconds'), mock.patch.object(runner.test_history, 'append'), \
+ redirect_stdout(io.StringIO()), redirect_stderr(io.StringIO()):
+ self.assertFalse(runner.run_serial_suite(('full',), chosen, chosen, progress, 'fixture')[0])
+ self.assertEqual(progress.units['test_catalog.py']['outcome'], 'pass')
+ self.assertEqual(progress.units['test_web.py']['outcome'], 'fail')
+
class ShardReportTests(unittest.TestCase):
def test_malformed_reports_are_failures(self):