diff options
| author | Morgan Lunt <morganl@anthropic.com> | 2026-09-24 20:29:13 -0700 |
|---|---|---|
| committer | Morgan Lunt <morganl@anthropic.com> | 2026-09-24 20:29:13 -0700 |
| commit | e662d6d338a7abb1a03ba97e1a47fb98d669c81f (patch) | |
| tree | 3f3cc3b70c97348002a570820b6a144f56773baf /plugins/code-modernization/scripts/tests | |
| parent | f33999b153851d927a103e0f4b6032ed53a94aad (diff) | |
code-modernization: keep one citation per rule when rendering business rules
The extractor is told to cite a single file range per rule, but on a large
Perl codebase it kept returning two or three files and a sentence of
explanation in the source field, which the report and the pane cannot
resolve to a line. The renderer now takes the first path:line-range as the
rule's citation and puts anything after it on an "Also cited" line.
Diffstat (limited to 'plugins/code-modernization/scripts/tests')
| -rw-r--r-- | plugins/code-modernization/scripts/tests/test_rules_tools.py | 15 |
1 files changed, 15 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 632b2250..59d9a30b 100644 --- a/plugins/code-modernization/scripts/tests/test_rules_tools.py +++ b/plugins/code-modernization/scripts/tests/test_rules_tools.py @@ -159,6 +159,21 @@ class RenderTests(unittest.TestCase): dto = open(os.path.join(ws, 'analysis/s/DATA_OBJECTS.md'), encoding='utf-8').read() self.assertIn('## Account', dto) + def test_a_rule_keeps_one_citation_and_the_rest_moves_to_also_cited(self): + sources = ['wwwroot/a.pl:100-120 (aggregation); family table at lib/b.pm:31-40', + 'lib/x.pm:966,1018,1238 (order lists)', 'no citation here', 'c.cbl:7'] + result = {'confirmedRules': [ + {'name': f'R{i}', 'category': 'Policy', 'priority': 'P1', 'source': src, 'plainEnglish': 'x', + 'given': 'g', 'when': 'w', 'then': 't', 'confidence': 'High'} for i, src in enumerate(sources)]} + 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() + cites = re.findall(r'^\*\*Source:\*\* `([^`]*)`', text, re.M) + self.assertEqual(sorted(cites), sorted(['wwwroot/a.pl:100-120', 'lib/x.pm:966', 'no citation here', 'c.cbl:7'])) + self.assertIn('**Also cited:** (aggregation); family table at lib/b.pm:31-40', text) + self.assertEqual(text.count('**Also cited:**'), 2) + def test_unreadable_result_is_an_error(self): with tempfile.TemporaryDirectory() as ws: self.assertEqual(run('render_rules.py', 's', '--workspace', ws).returncode, 1) |
