From 1f7fd87f970ef076b870a9986b6441620c66d23b Mon Sep 17 00:00:00 2001 From: 69049ed6x <69049ed6x@users.noreply.github.com> Date: Sat, 7 Mar 2026 14:04:23 +0800 Subject: [PATCH] test: cover invalid factor rule payload --- tests/test_factor_rules.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test_factor_rules.py b/tests/test_factor_rules.py index 344a6a35..08d869c4 100644 --- a/tests/test_factor_rules.py +++ b/tests/test_factor_rules.py @@ -111,6 +111,18 @@ class FactorRulesPathTests(unittest.TestCase): with self.assertRaises(ValueError): load_factor_rules({"project_dir": str(project_dir)}) + def test_invalid_top_level_payload_returns_empty_rules(self): + with tempfile.TemporaryDirectory() as tmpdir: + project_dir = Path(tmpdir) + examples_dir = project_dir / "examples" + examples_dir.mkdir() + rule_path = examples_dir / "factor_rules.json" + rule_path.write_text(json.dumps("unexpected-string"), encoding="utf-8") + + rules, loaded_path = load_factor_rules({"project_dir": str(project_dir)}) + self.assertEqual(rules, []) + self.assertEqual(Path(loaded_path), rule_path.resolve()) + def test_summarize_factor_rules_counts_biases(self): summary = summarize_factor_rules( [