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/build_report.py31
-rw-r--r--plugins/code-modernization/scripts/tests/test_report_next.py43
2 files changed, 74 insertions, 0 deletions
diff --git a/plugins/code-modernization/scripts/build_report.py b/plugins/code-modernization/scripts/build_report.py
index 06e97b44..c86c6298 100644
--- a/plugins/code-modernization/scripts/build_report.py
+++ b/plugins/code-modernization/scripts/build_report.py
@@ -480,6 +480,36 @@ def load_mermaid(src):
return ""
+def next_step(system, done, glance):
+ """The one command to run next, from which artifacts exist. The status command decides it the same way and also
+ reads the brief's phases; this page only knows what is on disk."""
+ def go(command, why):
+ return {"command": "/code-modernization:%s %s" % (command, system), "why": why}
+ if not done["preflight"]:
+ return go("modernize-preflight", "checks the environment and records where the code lives")
+ if not done["assess"]:
+ return go("modernize-assess", "says what you are dealing with and recommends a pattern")
+ if not done["map"]:
+ return go("modernize-map", "draws the structure of the system")
+ if not done["rules"]:
+ return go("modernize-extract-rules", "mines the business rules, each with a citation")
+ rules = glance.get("rules") or {}
+ if not done["brief"] and rules.get("defects") and not rules.get("reviews"):
+ return go("modernize-review", "a person confirms or corrects the rules that look wrong")
+ if not done["brief"]:
+ return go("modernize-brief", "writes the plan a person approves")
+ if not done["build"]:
+ return go("modernize-status", "names the first build command from the approved plan")
+ proof = glance.get("proof")
+ if not proof:
+ return go("modernize-verify", "re-checks what was built and gives each module a verdict")
+ if proof.get("verdict") != "PROVEN":
+ return go("modernize-verify", "the last check was %s: fix what its reasons name, then run it again" % str(proof.get("verdict"))[:20])
+ if not done["harden"]:
+ return go("modernize-harden", "scans the legacy system for security problems")
+ return go("modernize-status", "says whether modules or phases are left")
+
+
def build(system, workspace, out=None):
"""-> (html, section count, output path), or None when nothing was found."""
src = Source(workspace, system)
@@ -559,6 +589,7 @@ def build(system, workspace, out=None):
done = {"preflight": "PREFLIGHT.md" in docs, "assess": "ASSESSMENT.md" in docs, "rules": "BUSINESS_RULES.md" in docs, "brief": "MODERNIZATION_BRIEF.md" in docs,
"map": topo is not None or has_map or any(f["name"] != "ARCHITECTURE.mmd" for f in figures), "build": any(nonempty_dir(p) for p in mods), "harden": "SECURITY_FINDINGS.md" in docs}
glance["steps"] = [{"key": k, "label": label, "done": bool(done[k])} for k, label in STEPS]
+ glance["next"] = next_step(system, done, glance)
tracks = {"rewrite": [mods[0]], "same-stack uplift": [a("DELTA_CATALOG.md"), a("PLAYBOOK.md"), mods[1]], "reimagine": [a("AI_NATIVE_SPEC.md"), a("REIMAGINED_ARCHITECTURE.md"), mods[2]]}
ranked = sorted(((newest(p), k) for k, p in tracks.items() if newest(p)), reverse=True)
glance["track"] = {"label": ranked[0][1], "why": "newest artifact: " + os.path.relpath(ranked[0][0][1], workspace).replace(os.sep, "/")} if ranked else None
diff --git a/plugins/code-modernization/scripts/tests/test_report_next.py b/plugins/code-modernization/scripts/tests/test_report_next.py
new file mode 100644
index 00000000..e73536ba
--- /dev/null
+++ b/plugins/code-modernization/scripts/tests/test_report_next.py
@@ -0,0 +1,43 @@
+"""Tests for the report's next-step decision (scripts/build_report.py next_step)."""
+import os
+import sys
+import unittest
+
+HERE = os.path.dirname(os.path.abspath(__file__))
+sys.path.insert(0, os.path.join(os.path.dirname(HERE)))
+import build_report as br # noqa: E402
+
+ALL = dict(preflight=True, assess=True, map=True, rules=True, brief=True, build=True, harden=True)
+
+
+class NextStep(unittest.TestCase):
+ def cmd(self, done, glance=None):
+ return br.next_step("sys", dict(ALL, **done), glance or {})["command"]
+
+ def test_the_path_in_order(self):
+ order = ["preflight", "assess", "map", "rules"]
+ for i, key in enumerate(order):
+ done = {k: False for k in order[i:]}
+ done.update(brief=False, build=False, harden=False)
+ self.assertTrue(self.cmd(done).startswith("/code-modernization:modernize-" + ["preflight", "assess", "map", "extract-rules"][i]))
+
+ def test_flagged_rules_go_to_review_once_and_then_on(self):
+ flagged = {"rules": {"defects": 2}}
+ self.assertIn("modernize-review", self.cmd({"brief": False}, flagged))
+ reviewed = {"rules": {"defects": 2, "reviews": {"confirmed": 1}}}
+ self.assertIn("modernize-brief", self.cmd({"brief": False}, reviewed))
+
+ def test_a_build_is_verified_before_anything_else(self):
+ self.assertIn("modernize-verify", self.cmd({"harden": False}))
+ self.assertIn("modernize-verify", self.cmd({"harden": False}, {"proof": {"verdict": "NOT PROVEN"}}))
+ self.assertIn("modernize-harden", self.cmd({"harden": False}, {"proof": {"verdict": "PROVEN"}}))
+
+ def test_everything_done_points_at_status_and_text_is_bounded(self):
+ step = br.next_step("s", ALL, {"proof": {"verdict": "PROVEN"}})
+ self.assertIn("modernize-status", step["command"])
+ hostile = br.next_step("s", ALL, {"proof": {"verdict": "X" * 5000}})
+ self.assertLess(len(hostile["why"]), 200)
+
+
+if __name__ == "__main__":
+ unittest.main()