test_router_scripts.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import pathlib
  2. import unittest
  3. PROJECT_ROOT = pathlib.Path(__file__).resolve().parent.parent
  4. class TestRouterScriptsBugsAndContracts(unittest.TestCase):
  5. """测试并锁定路由器 BusyBox 脚本中的文件原子性与选优漏洞,并纠正旧报告虚假报警"""
  6. def test_p1_router_local_update_atomic_file_write(self):
  7. """[P1/P2 修复验证] 验证 router_local_update.sh 采用 .tmp.$$ + mv -f 原子替换写入文件"""
  8. script_path = PROJECT_ROOT / "scripts" / "router_local_update.sh"
  9. content = script_path.read_text()
  10. self.assertIn("atomic_write_file()", content)
  11. self.assertIn(".tmp.$$", content)
  12. self.assertIn('atomic_write_file "$CURRENT_JSON_PATH"', content)
  13. def test_p2_router_local_update_filters_zero_speed(self):
  14. """[P2 修复验证] 验证 router_local_update.sh 在开启测速时优先挑选 download_speed > 0 的候选行"""
  15. script_path = PROJECT_ROOT / "scripts" / "router_local_update.sh"
  16. content = script_path.read_text()
  17. self.assertIn("speed = trim($6) + 0", content)
  18. self.assertIn("speed > 0", content)
  19. def test_recheck_correction_router_cfst_params_already_supported(self):
  20. """[复核纠偏] 验证初审报告关于 'router_local_update.sh 缺少 -dt/-dn/-dd 参数' 系虚假误报"""
  21. script_path = PROJECT_ROOT / "scripts" / "router_local_update.sh"
  22. content = script_path.read_text()
  23. # 验证源码中实际已存在这些参数映射
  24. self.assertIn('CFST_DOWNLOAD_COUNT', content)
  25. self.assertIn('-dn "$CFST_DOWNLOAD_COUNT"', content)
  26. self.assertIn('CFST_DOWNLOAD_TIME', content)
  27. self.assertIn('-dt "$CFST_DOWNLOAD_TIME"', content)
  28. self.assertIn('CFST_DISABLE_DOWNLOAD', content)
  29. self.assertIn('-dd', content)
  30. if __name__ == "__main__":
  31. unittest.main()