summaryrefslogtreecommitdiff
path: root/plugins/code-modernization/scripts/tests
diff options
context:
space:
mode:
authorMorgan Lunt <morganl@anthropic.com>2026-09-24 21:22:06 -0700
committerMorgan Lunt <morganl@anthropic.com>2026-09-24 21:22:06 -0700
commitff833bd7231262a8521ab3728c5625dc6c4f4a1d (patch)
treed12e70b6407f666e787fae7217362011f892f459 /plugins/code-modernization/scripts/tests
parentf45794fa4831636e7ae55f8081769c8ebf3f58c6 (diff)
code-modernization: make rule consolidation auditable and injection-safe
Follow-ups from review of the consolidation pass: - The agent is a restricted type with the same read-only wording as its siblings, and every field on its numbered list is a single bounded line, so a rule name containing a newline cannot fake another entry. - A group with any number out of range or not an integer is rejected whole instead of being coerced into a different merge. - A merge keeps the most conservative review state: the highest priority, the lowest confidence, and every suspected defect and SME question of the folded rules. - Every folded rule is returned with the rule it went into, and the rules document lists them under "Rules folded into another", so nothing disappears untraceably. Extra citations show as "Also cited" without the joining word.
Diffstat (limited to 'plugins/code-modernization/scripts/tests')
-rw-r--r--plugins/code-modernization/scripts/tests/test_rules_tools.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/plugins/code-modernization/scripts/tests/test_rules_tools.py b/plugins/code-modernization/scripts/tests/test_rules_tools.py
index 59d9a30b..33cfd279 100644
--- a/plugins/code-modernization/scripts/tests/test_rules_tools.py
+++ b/plugins/code-modernization/scripts/tests/test_rules_tools.py
@@ -174,6 +174,19 @@ class RenderTests(unittest.TestCase):
self.assertIn('**Also cited:** (aggregation); family table at lib/b.pm:31-40', text)
self.assertEqual(text.count('**Also cited:**'), 2)
+ def test_folded_rules_are_listed_so_nothing_disappears_untraceably(self):
+ result = {'confirmedRules': [{'name': 'Twiddle table', 'category': 'Calculation', 'priority': 'P0', 'source': 'a.c:1-2 ; also b.c:3-4',
+ 'plainEnglish': 'x', 'given': 'g', 'when': 'w', 'then': 't', 'confidence': 'Low'}],
+ 'foldedRules': [{'name': 'Twiddle factors', 'source': 'b.c:3-4', 'into': 'Twiddle table'}, 'junk', {'name': 'X\n# fake heading', 'source': 's', 'into': 'i'}]}
+ with tempfile.TemporaryDirectory() as ws:
+ write(ws, 'analysis/s/rules_result.json', json.dumps(result))
+ self.assertEqual(run('render_rules.py', 's', '--workspace', ws).returncode, 0)
+ text = open(os.path.join(ws, 'analysis/s/BUSINESS_RULES.md'), encoding='utf-8').read()
+ self.assertIn('## Rules folded into another', text)
+ self.assertIn('- Twiddle factors (b.c:3-4) into Twiddle table', text)
+ self.assertIn('**Also cited:** b.c:3-4', text)
+ self.assertNotIn('\n# fake heading', text)
+
def test_unreadable_result_is_an_error(self):
with tempfile.TemporaryDirectory() as ws:
self.assertEqual(run('render_rules.py', 's', '--workspace', ws).returncode, 1)