summaryrefslogtreecommitdiff
path: root/plugins/code-modernization/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/code-modernization/scripts')
-rw-r--r--plugins/code-modernization/scripts/render_rules.py15
-rw-r--r--plugins/code-modernization/scripts/tests/test_rules_tools.py13
2 files changed, 26 insertions, 2 deletions
diff --git a/plugins/code-modernization/scripts/render_rules.py b/plugins/code-modernization/scripts/render_rules.py
index f098a5cf..fa609332 100644
--- a/plugins/code-modernization/scripts/render_rules.py
+++ b/plugins/code-modernization/scripts/render_rules.py
@@ -36,8 +36,9 @@ def split_citation(value):
if not m:
return one_line(text, 200), ''
primary = f'{m.group(1)}:{m.group(2)}' + (f'-{m.group(3)}' if m.group(3) else '')
- rest = text[m.end():].strip(' \t;,.-\u2013\u2014`')
- return one_line(primary, 200), one_line(rest, 300)
+ rest = re.sub(r'\s*;\s*also\s+', '; ', text[m.end():], flags=re.I) # citations a consolidation appended
+ rest = re.sub(r'^[\s;,.\-\u2013\u2014`]*(?:also\s+)?', '', rest, flags=re.I)
+ return one_line(primary, 200), one_line(rest.strip(' \t;,.-\u2013\u2014`'), 300)
def block(value):
@@ -145,6 +146,16 @@ def main(argv):
doc += [f'- {one_line(f, 300)}' for f in flags]
doc.append('')
+ folded = [f for f in (result.get('foldedRules') or []) if isinstance(f, dict)]
+ if folded:
+ doc += ['## Rules folded into another', '',
+ 'These rules described the same behavior as another rule in a different place, so they were merged into it '
+ '(the kept rule lists their locations under "Also cited"):', '']
+ doc += [f"- {one_line(f.get('name'), 100)} ({one_line(f.get('source'), 100)}) into {one_line(f.get('into'), 100)}" for f in folded[:100]]
+ if len(folded) > 100:
+ doc.append(f'- … and {len(folded) - 100} more')
+ doc.append('')
+
gaps = [('never attempted (token budget or agent cap)', stats.get('skippedModules')),
('extractor returned nothing', stats.get('failedModules')),
('malformed entries, fix by hand', stats.get('droppedModules')),
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)