From 888ebb40af7b79f04d583fd2ef5637898eacbce0 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Wed, 25 Nov 2026 09:20:36 +0000 Subject: [PATCH] fix(ci): master Test workflow green on Python 3.12 and ubuntu-26.04 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - CI installs PyYAML (new dependency group test) so the staged-diff secret rules load; the Update workflow also installs the orchestrator requirements - operator.py: termios.IUTF8 falls back to 0o40000 on Python 3.12, where the terminal prompt crashed with AttributeError - operator.py: the run preview trusts filters of the system and global git config (git-lfs on runner images) and stays off for repo or command filters, and when git cannot name a filter's scope - test_radio feeds the listener its stdin through an own pipe, since 3.12 communicate() flushes a closed proc.stdin - test_hub_match_content gives the runner a MEDUSA rules home instead of the host's - test_queue_hung uses a script named docker, since a multicall sleep refuses that name ๐ŸŽฏ Fix: 93 % ๐Ÿ’ฅ Break: 3 % ๐Ÿ’ธ Tokens: โ€“ โฑ๏ธ Velocity: โ€“ ๐Ÿ›ก๏ธ Security: 100 % ๐Ÿ† Score: 90 ๐Ÿšฆ Gate: โœ… 90/5, tokens and velocity <= 100, security 100 % Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 --- .github/workflows/test.yml | 2 +- .github/workflows/update.yml | 3 +- pyproject.toml | 1 + skills/kvb-org-operator/scripts/operator.py | 18 ++++++++--- tests/test_hub_match_content.py | 8 ++++- tests/test_operator.py | 36 +++++++++++++++++++-- tests/test_queue_hung.py | 6 ++-- tests/test_radio.py | 22 ++++++------- 8 files changed, 71 insertions(+), 25 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e108aee..85a7acf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,7 +25,7 @@ jobs: - name: ๐Ÿ“ฆ Install lint tools run: | python -m pip install --upgrade pip - pip install --group lint + pip install --group lint --group test pip install --requirement orchestrator/requirements.txt sudo apt-get update && sudo apt-get install -y shellcheck npm install -g markdownlint-cli2 diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index 2c4a526..611b1fb 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -30,7 +30,8 @@ jobs: - name: ๐Ÿ“ฆ Install lint tools run: | python -m pip install --upgrade pip - pip install --group lint + pip install --group lint --group test + pip install --requirement orchestrator/requirements.txt sudo apt-get update && sudo apt-get install -y shellcheck npm install -g markdownlint-cli2 diff --git a/pyproject.toml b/pyproject.toml index d87d29a..4bff647 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,6 @@ [dependency-groups] lint = ["ruff==0.17.3"] +test = ["PyYAML==6.0.3"] [tool.ruff] target-version = "py312" diff --git a/skills/kvb-org-operator/scripts/operator.py b/skills/kvb-org-operator/scripts/operator.py index d6c57b2..314a258 100755 --- a/skills/kvb-org-operator/scripts/operator.py +++ b/skills/kvb-org-operator/scripts/operator.py @@ -53,7 +53,8 @@ Args: answer, is skipped with the reason and stays open (unready()). Otherwise a preview of what the command changes, its output indented, and asks [y]es / [s]kip / [c]ancel / [d]iff / [q]uit; d shows the full diff. A repo - whose git config names filter commands gets no preview. c asks for a + whose git config names filter commands outside the system and global + config gets no preview. c asks for a reason (empty: back to the question), sets the row as shown stopped with it and sends it as a message; a row changed since it was shown is not cancelled. y runs the command in its directory, @@ -207,6 +208,9 @@ INDENT = " " LABEL = 11 OUTPUT = " " QUEUE_COLUMNS = ("position", "id", "status", "task", "eta_min") +IUTF8 = getattr(termios, "IUTF8", 0o40000) +TRUSTED_SCOPES = frozenset({"system", "global"}) +CONFIG_ANSWERS = (0, 1) def fail(message: str) -> None: @@ -542,11 +546,15 @@ def git_tree(directory: str) -> bool: def filtered(directory: str) -> bool: try: - return subprocess.run( - [*GIT, "config", "--get-regexp", r"^filter\."], cwd=directory, env=git_env(), capture_output=True, check=False - ).returncode == 0 + found = subprocess.run( + [*GIT, "config", "--show-scope", "--name-only", "--get-regexp", r"^filter\."], + cwd=directory, env=git_env(), capture_output=True, text=True, check=False, + ) except OSError: return False + if found.returncode not in CONFIG_ANSWERS: + return True + return any(line.partition("\t")[0] not in TRUSTED_SCOPES for line in found.stdout.splitlines()) def evidence(check: str, directory: str, full: bool) -> list[tuple[list[str], str]]: @@ -606,7 +614,7 @@ def whole_characters(read: Callable[[str], str | None]) -> Callable[[str], str | if not sys.stdin.isatty(): return read(prompt) mode = termios.tcgetattr(sys.stdin.fileno()) - termios.tcsetattr(sys.stdin.fileno(), termios.TCSANOW, [mode[0] | termios.IUTF8, *mode[1:]]) + termios.tcsetattr(sys.stdin.fileno(), termios.TCSANOW, [mode[0] | IUTF8, *mode[1:]]) try: return read(prompt) finally: diff --git a/tests/test_hub_match_content.py b/tests/test_hub_match_content.py index d16df37..595e8d2 100644 --- a/tests/test_hub_match_content.py +++ b/tests/test_hub_match_content.py @@ -1,14 +1,17 @@ from __future__ import annotations import json +import os import re import time import unittest +from pathlib import Path from unittest import mock from hub_support import ASK, HUB, REPO_ROOT from kvb_orchestrator import scores from test_hub_match import MatchCase, git, merge_repo, move_head +from test_hub_operator_tasks import rules_dir, staged_diff ORDER = ["fix", "break", "tokens", "velocity", "security", "legal", "architecture", "score"] FULL = "๐ŸŽฏ Fix: 95 % ยท ๐Ÿ’ฅ Break: 3 % ยท ๐Ÿ’ธ Tokens: 100 % ยท โฑ๏ธ Velocity: 100 % ยท ๐Ÿ›ก๏ธ Security: 99 ยท โš–๏ธ Legal: 98 ยท ๐Ÿ›๏ธ Architecture: 97 ยท ๐Ÿ† Score: 96" @@ -34,7 +37,10 @@ class TestMergeDiff(MatchCase): status, _, body = self.call("GET", "/api/runner/previews", None, self.client()) self.assertEqual(status, 200, body) self.assertEqual([(row["id"], row["worktree"], row["tree"], row["head"]) for row in json.loads(body)["reviews"]], [(review, str(self.repo), tree, None)]) - self.run_runner(register=False) + home = self.outside / "medusa-home" + rules_dir(home / staged_diff.RULES_HOME.relative_to(Path.home()) / Path(staged_diff.RULES_TAIL.replace("*", "")).parent) + with mock.patch.dict(os.environ, {"HOME": str(home), "XDG_CACHE_HOME": str(home / ".cache")}): + self.run_runner(register=False) card = self.card(f"review:{review}") self.assertEqual([(entry["path"], entry["status"], entry["additions"]) for entry in card["files"]], [("app.py", "M", 1)]) self.assertIn("+added = 2", card["files"][0]["patch"]) diff --git a/tests/test_operator.py b/tests/test_operator.py index 101ca26..5dc83a7 100644 --- a/tests/test_operator.py +++ b/tests/test_operator.py @@ -3,6 +3,7 @@ from __future__ import annotations import http.server +import importlib.util import json import os import pty @@ -21,6 +22,9 @@ from pathlib import Path REPO_ROOT = Path(__file__).resolve().parents[1] OPERATOR = REPO_ROOT / "skills" / "kvb-org-operator" / "scripts" / "operator.py" +OPERATOR_SPEC = importlib.util.spec_from_file_location("kvb_operator_for_terminal", OPERATOR) +operator_script = importlib.util.module_from_spec(OPERATOR_SPEC) +OPERATOR_SPEC.loader.exec_module(operator_script) RASCI = REPO_ROOT / "skills" / "kvb-org-rasci" / "scripts" / "rasci.py" HEADER = "| # | Directory | Command | Why | Check |" RUNNER = ["", "Every step with preview and yes/skip:", "```bash", f"python3 {OPERATOR} run", "```"] @@ -138,7 +142,7 @@ class TestOperator(unittest.TestCase): @staticmethod def _iutf8(leader: int) -> bool: - return bool(termios.tcgetattr(leader)[0] & termios.IUTF8) + return bool(termios.tcgetattr(leader)[0] & operator_script.IUTF8) def _terminal(self, args: list[str], steps: list[tuple[bytes, bytes | signal.Signals]]) -> tuple[int, str, list[bool]]: """Args: @@ -155,7 +159,7 @@ class TestOperator(unittest.TestCase): leader, follower = pty.openpty() self.addCleanup(os.close, leader) mode = termios.tcgetattr(follower) - termios.tcsetattr(follower, termios.TCSANOW, [mode[0] & ~termios.IUTF8, *mode[1:]]) + termios.tcsetattr(follower, termios.TCSANOW, [mode[0] & ~operator_script.IUTF8, *mode[1:]]) try: child = subprocess.Popen( [sys.executable, str(OPERATOR), *args], stdin=follower, stdout=follower, stderr=follower, @@ -670,6 +674,34 @@ class TestOperator(unittest.TestCase): self.assertNotIn("?? 2", result.stdout) self.assertFalse(marker.exists()) + def test_run_preview_trusts_a_filter_of_the_system_and_the_global_config(self): + system = self.base / "gitconfig" + system.write_text('[filter "lfs"]\n\tclean = cat\n', encoding="utf-8") + (self.home / ".gitconfig").write_text('[filter "own"]\n\tclean = cat\n', encoding="utf-8") + self.env["GIT_CONFIG_SYSTEM"] = str(system) + repo = self._repo("lfs", upstream=False) + (repo / "one").write_text("changed", encoding="utf-8") + self._add("lfs", repo, "true", "r", "manual") + result = self._feed("s\n") + self.assertEqual(result.returncode, 0, result.stderr) + self.assertIn(" M one", result.stdout) + self.assertNotIn("(nothing to compare)", result.stdout) + + def test_run_preview_stays_off_when_git_cannot_name_the_scope_of_a_filter(self): + marker = self.base / "ran" + git = self.bin / "git" + git.write_text(f'#!/bin/sh\ncase " $* " in *" --show-scope "*) exit 129;; esac\nexec {shutil.which("git")} "$@"\n', encoding="utf-8") + git.chmod(0o755) + repo = self._repo("old", upstream=False) + self._git(repo, "config", "filter.x.clean", f"touch {marker}") + (repo / ".gitattributes").write_text("* filter=x\n", encoding="utf-8") + (repo / "one").write_text("changed", encoding="utf-8") + self._add("old", repo, "true", "r", "manual") + result = self._feed("s\n") + self.assertEqual(result.returncode, 0, result.stderr) + self.assertIn("(nothing to compare)", result.stdout) + self.assertFalse(marker.exists()) + def test_list_and_preview_never_fetch_a_missing_object(self): marker = self.base / "fetched" repo = self._repo("lazy", upstream=True) diff --git a/tests/test_queue_hung.py b/tests/test_queue_hung.py index 42af7ab..3b29df2 100644 --- a/tests/test_queue_hung.py +++ b/tests/test_queue_hung.py @@ -425,11 +425,9 @@ class TestSupervise(unittest.TestCase): group.assert_not_called() def test_a_tree_running_a_container_client_never_fires_and_says_so_once(self): - sleep = shutil.which("sleep") - if sleep is None: - self.skipTest("no sleep binary on PATH") docker = self.scratch() / "docker" - docker.symlink_to(sleep) + docker.write_text(f"#!{sys.executable}\nimport sys, time\ntime.sleep(float(sys.argv[1]))\n", encoding="utf-8") + docker.chmod(0o755) result, _, err = self.supervised(self.start(CLIENT, str(docker))) self.assertEqual(result, (0, None)) self.assertEqual(err.count("the command runs docker,"), 1) diff --git a/tests/test_radio.py b/tests/test_radio.py index a9320bf..f9c15b1 100644 --- a/tests/test_radio.py +++ b/tests/test_radio.py @@ -109,14 +109,20 @@ class TestRadio(unittest.TestCase): def _pidfile(self, sid: str) -> Path: return self.root / "radio-listen" / f"{sid}.pid" - def _listen(self, sid: str) -> subprocess.Popen: + def _spawn(self, sid: str) -> subprocess.Popen: + reader, writer = os.pipe() + os.write(writer, json.dumps({"session_id": sid}).encode()) + os.close(writer) proc = subprocess.Popen( [sys.executable, "-c", LISTENER, str(RADIO)], - stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, env=self._env(None), + stdin=reader, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, env=self._env(None), ) + os.close(reader) self.addCleanup(self._stop, proc) - proc.stdin.write(json.dumps({"session_id": sid})) - proc.stdin.close() + return proc + + def _listen(self, sid: str) -> subprocess.Popen: + proc = self._spawn(sid) deadline = time.monotonic() + 10 while time.monotonic() < deadline and proc.poll() is None: pidfile = self._pidfile(sid) @@ -607,13 +613,7 @@ class TestRadio(unittest.TestCase): _, victims = self._victims() self.root.mkdir() (self.root / "radio-listen").symlink_to(victims) - proc = subprocess.Popen( - [sys.executable, "-c", LISTENER, str(RADIO)], - stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, env=self._env(None), - ) - self.addCleanup(self._stop, proc) - proc.stdin.write(json.dumps({"session_id": "s2"})) - proc.stdin.close() + proc = self._spawn("s2") try: code = proc.wait(timeout=10) except subprocess.TimeoutExpired: