summaryrefslogtreecommitdiff
path: root/plugins/code-modernization
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/code-modernization')
-rw-r--r--plugins/code-modernization/assets/report-template.html8
-rw-r--r--plugins/code-modernization/scripts/build_report.py31
-rw-r--r--plugins/code-modernization/scripts/tests/test_report_next.py43
3 files changed, 82 insertions, 0 deletions
diff --git a/plugins/code-modernization/assets/report-template.html b/plugins/code-modernization/assets/report-template.html
index b7d5a07a..0f632a17 100644
--- a/plugins/code-modernization/assets/report-template.html
+++ b/plugins/code-modernization/assets/report-template.html
@@ -60,6 +60,9 @@ figure{margin:16px 0}figcaption{font:.8125rem ui-monospace,Menlo,Consolas,monosp
details{margin:6px 0}summary{cursor:pointer;color:var(--link)}.diff{background:var(--bad-bg);color:var(--bad);font-weight:700}.hash{font:.75rem ui-monospace,Menlo,Consolas,monospace;overflow-wrap:anywhere}
@media (max-width:860px){.layout{display:block}#nav{position:static;margin-bottom:12px}#navlist{display:none}#navsel{display:block}#found{margin:6px 0 0}.sec{padding:14px}.tools{justify-content:stretch}input{max-width:none}}
@media print{:root{color-scheme:light;--bg:#fff;--surface:#fff;--text:#000;--muted:#333;--line:#999;--link:#000;--code:#f0f0f0}.top,#nav,.tools,.tool{display:none}.sec[hidden]{display:block!important}.sec,.glance{border:0;padding:0;break-inside:auto}.card,figure,tr{break-inside:avoid}body{font-size:11pt}.layout{display:block}}
+.next{display:flex;flex-wrap:wrap;gap:8px 12px;align-items:center;margin:0 0 12px}.next .chip{font-size:.875rem;user-select:all}.next .why{color:var(--muted);font-size:.875rem}.copy{font:inherit;font-size:.8125rem;border:1px solid var(--line);background:var(--surface);color:var(--text);border-radius:6px;padding:2px 10px;cursor:pointer}.copy:hover{border-color:var(--link)}@media print{.copy{display:none}}
+/* keep short words and pills whole in table cells (long paths still break inside code) */
+td,th{overflow-wrap:break-word}td code,td .hash{overflow-wrap:anywhere}.badge,.chip{white-space:nowrap}
</style>
</head>
<body>
@@ -264,6 +267,11 @@ function renderGlance() {
kids.push(h('div', {class: 'banner ' + (eq.state === 'green' ? 'ok' : 'bad'), role: 'status'}, [(eq.state === 'green' ? '✓ ' : '✗ ') + eq.headline].concat(
(eq.problems || []).slice(0, 3).map(function (p) { return h('p', null, [p]); }), [h('p', null, [h('a', {href: '#sec-equivalence'}, ['See the case table'])])])));
}
+ if (g.next && g.next.command) {
+ var copy = h('button', {type: 'button', class: 'copy', 'aria-label': 'Copy the command'}, ['Copy']);
+ copy.addEventListener('click', function () { try { navigator.clipboard.writeText(g.next.command).then(function () { copy.textContent = 'Copied'; }, function () { copy.textContent = 'Select and copy'; }); } catch (e) { copy.textContent = 'Select and copy'; } });
+ kids.push(h('p', {class: 'next'}, [h('strong', null, ['Next step']), h('code', {class: 'chip mono'}, [g.next.command]), copy, h('span', {class: 'why'}, [g.next.why || ''])]));
+ }
kids.push(h('ul', {class: 'chips', 'aria-label': 'Workflow steps'}, (g.steps || []).map(function (st) { return chip(st.label + (st.done ? ': done' : ': not yet'), st.done ? 'ok' : ''); })));
if (g.track) s.push(stat('Track it looks like', g.track.label, g.track.why));
if (g.topology) s.push(stat('Map', fmt(g.topology.modules) + ' modules', fmt(g.topology.loc) + ' lines' + ((g.topology.languages || []).length ? ' · ' + g.topology.languages.join(', ') : '')));
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()