From 997a01ccfaf2776495cdc80e148f49f422d273f6 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Wed, 4 Nov 2026 11:17:37 +0100 Subject: [PATCH] fix(kvb-org-operator): list only runnable rows in the bash block Legacy register rows carry a prose title and no directory. They stay in the table but no longer land in the copy-paste bash block as if they were commands; with no runnable row the block is omitted. Co-Authored-By: Claude Opus 5.5 --- skills/kvb-org-operator/scripts/operator.py | 13 +++++++------ tests/test_operator.py | 13 +++++++++++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/skills/kvb-org-operator/scripts/operator.py b/skills/kvb-org-operator/scripts/operator.py index 5f5e74c..1cb389a 100755 --- a/skills/kvb-org-operator/scripts/operator.py +++ b/skills/kvb-org-operator/scripts/operator.py @@ -226,14 +226,15 @@ def cmd_list(rasci: ModuleType, args: argparse.Namespace) -> int: for number, row in enumerate(listed, 1): values = (number, row["directory"] or "-", row["command"] or "-", row["why"] or "-", row["check"]) print("| " + " | ".join(cell(v) for v in values) + " |") - print() - print("```bash") - for row in listed: - if row["directory"]: + # Trip-wire: legacy rows carry a prose title and no directory; only rows recorded by `add` are commands. + runnable = [row for row in listed if row["directory"] and row["command"]] + if runnable: + print() + print("```bash") + for row in runnable: print(f"cd {shlex.quote(row['directory'])}") - if row["command"]: print(row["command"]) - print("```") + print("```") return 0 diff --git a/tests/test_operator.py b/tests/test_operator.py index a6510db..a4de7cd 100644 --- a/tests/test_operator.py +++ b/tests/test_operator.py @@ -194,8 +194,17 @@ class TestOperator(unittest.TestCase): self.assertEqual(result.returncode, 0, result.stderr) self.assertEqual( self._out("list"), - [HEADER, "|---|---|---|---|---|", "| 1 | - | sudo reboot | - | manual |", "", "```bash", - "sudo reboot", "```"], + [HEADER, "|---|---|---|---|---|", "| 1 | - | sudo reboot | - | manual |"], + ) + + def test_bash_block_skips_legacy_rows_without_directory(self): + result = self._run("set", "operator/legacy", "--title", "Rotate leaked credentials", "--status", "queued", + script=RASCI) + self.assertEqual(result.returncode, 0, result.stderr) + self._add("reboot", self.base, "sudo reboot", "kernel", "manual") + self.assertEqual( + self._out("list")[-4:], + ["```bash", f"cd {self.base}", "sudo reboot", "```"], ) def test_invalid_input_exits_2(self):