fix(ci): master Test workflow green on Python 3.12 and ubuntu-26.04
🧪 Test / 🧪 Lock + lint (push) Waiting to run
🧪 Test / 🧪 Lock + lint (push) Waiting to run
- 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 <noreply@anthropic.com>
This commit is contained in:
1 parent
d3bc54f401
commit
888ebb40af
8 files changed
+71
-25
No files matched your search
@@ -25,7 +25,7 @@ jobs:
|
|||||||
- name: 📦 Install lint tools
|
- name: 📦 Install lint tools
|
||||||
run: |
|
run: |
|
||||||
python -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
pip install --group lint
|
pip install --group lint --group test
|
||||||
pip install --requirement orchestrator/requirements.txt
|
pip install --requirement orchestrator/requirements.txt
|
||||||
sudo apt-get update && sudo apt-get install -y shellcheck
|
sudo apt-get update && sudo apt-get install -y shellcheck
|
||||||
npm install -g markdownlint-cli2
|
npm install -g markdownlint-cli2
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ jobs:
|
|||||||
- name: 📦 Install lint tools
|
- name: 📦 Install lint tools
|
||||||
run: |
|
run: |
|
||||||
python -m pip install --upgrade pip
|
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
|
sudo apt-get update && sudo apt-get install -y shellcheck
|
||||||
npm install -g markdownlint-cli2
|
npm install -g markdownlint-cli2
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
[dependency-groups]
|
[dependency-groups]
|
||||||
lint = ["ruff==0.17.3"]
|
lint = ["ruff==0.17.3"]
|
||||||
|
test = ["PyYAML==6.0.3"]
|
||||||
|
|
||||||
[tool.ruff]
|
[tool.ruff]
|
||||||
target-version = "py312"
|
target-version = "py312"
|
||||||
@@ -53,7 +53,8 @@ Args:
|
|||||||
answer, is skipped with the reason and stays open (unready()).
|
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 /
|
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
|
[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
|
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
|
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,
|
is not cancelled. y runs the command in its directory,
|
||||||
@@ -207,6 +208,9 @@ INDENT = " "
|
|||||||
LABEL = 11
|
LABEL = 11
|
||||||
OUTPUT = " "
|
OUTPUT = " "
|
||||||
QUEUE_COLUMNS = ("position", "id", "status", "task", "eta_min")
|
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:
|
def fail(message: str) -> None:
|
||||||
@@ -542,11 +546,15 @@ def git_tree(directory: str) -> bool:
|
|||||||
|
|
||||||
def filtered(directory: str) -> bool:
|
def filtered(directory: str) -> bool:
|
||||||
try:
|
try:
|
||||||
return subprocess.run(
|
found = subprocess.run(
|
||||||
[*GIT, "config", "--get-regexp", r"^filter\."], cwd=directory, env=git_env(), capture_output=True, check=False
|
[*GIT, "config", "--show-scope", "--name-only", "--get-regexp", r"^filter\."],
|
||||||
).returncode == 0
|
cwd=directory, env=git_env(), capture_output=True, text=True, check=False,
|
||||||
|
)
|
||||||
except OSError:
|
except OSError:
|
||||||
return False
|
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]]:
|
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():
|
if not sys.stdin.isatty():
|
||||||
return read(prompt)
|
return read(prompt)
|
||||||
mode = termios.tcgetattr(sys.stdin.fileno())
|
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:
|
try:
|
||||||
return read(prompt)
|
return read(prompt)
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
import unittest
|
import unittest
|
||||||
|
from pathlib import Path
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
from hub_support import ASK, HUB, REPO_ROOT
|
from hub_support import ASK, HUB, REPO_ROOT
|
||||||
from kvb_orchestrator import scores
|
from kvb_orchestrator import scores
|
||||||
from test_hub_match import MatchCase, git, merge_repo, move_head
|
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"]
|
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"
|
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())
|
status, _, body = self.call("GET", "/api/runner/previews", None, self.client())
|
||||||
self.assertEqual(status, 200, body)
|
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.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}")
|
card = self.card(f"review:{review}")
|
||||||
self.assertEqual([(entry["path"], entry["status"], entry["additions"]) for entry in card["files"]], [("app.py", "M", 1)])
|
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"])
|
self.assertIn("+added = 2", card["files"][0]["patch"])
|
||||||
|
|||||||
+34
-2
@@ -3,6 +3,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import http.server
|
import http.server
|
||||||
|
import importlib.util
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import pty
|
import pty
|
||||||
@@ -21,6 +22,9 @@ from pathlib import Path
|
|||||||
|
|
||||||
REPO_ROOT = Path(__file__).resolve().parents[1]
|
REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||||
OPERATOR = REPO_ROOT / "skills" / "kvb-org-operator" / "scripts" / "operator.py"
|
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"
|
RASCI = REPO_ROOT / "skills" / "kvb-org-rasci" / "scripts" / "rasci.py"
|
||||||
HEADER = "| # | Directory | Command | Why | Check |"
|
HEADER = "| # | Directory | Command | Why | Check |"
|
||||||
RUNNER = ["", "Every step with preview and yes/skip:", "```bash", f"python3 {OPERATOR} run", "```"]
|
RUNNER = ["", "Every step with preview and yes/skip:", "```bash", f"python3 {OPERATOR} run", "```"]
|
||||||
@@ -138,7 +142,7 @@ class TestOperator(unittest.TestCase):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _iutf8(leader: int) -> bool:
|
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]]:
|
def _terminal(self, args: list[str], steps: list[tuple[bytes, bytes | signal.Signals]]) -> tuple[int, str, list[bool]]:
|
||||||
"""Args:
|
"""Args:
|
||||||
@@ -155,7 +159,7 @@ class TestOperator(unittest.TestCase):
|
|||||||
leader, follower = pty.openpty()
|
leader, follower = pty.openpty()
|
||||||
self.addCleanup(os.close, leader)
|
self.addCleanup(os.close, leader)
|
||||||
mode = termios.tcgetattr(follower)
|
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:
|
try:
|
||||||
child = subprocess.Popen(
|
child = subprocess.Popen(
|
||||||
[sys.executable, str(OPERATOR), *args], stdin=follower, stdout=follower, stderr=follower,
|
[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.assertNotIn("?? 2", result.stdout)
|
||||||
self.assertFalse(marker.exists())
|
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):
|
def test_list_and_preview_never_fetch_a_missing_object(self):
|
||||||
marker = self.base / "fetched"
|
marker = self.base / "fetched"
|
||||||
repo = self._repo("lazy", upstream=True)
|
repo = self._repo("lazy", upstream=True)
|
||||||
|
|||||||
@@ -425,11 +425,9 @@ class TestSupervise(unittest.TestCase):
|
|||||||
group.assert_not_called()
|
group.assert_not_called()
|
||||||
|
|
||||||
def test_a_tree_running_a_container_client_never_fires_and_says_so_once(self):
|
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 = 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)))
|
result, _, err = self.supervised(self.start(CLIENT, str(docker)))
|
||||||
self.assertEqual(result, (0, None))
|
self.assertEqual(result, (0, None))
|
||||||
self.assertEqual(err.count("the command runs docker,"), 1)
|
self.assertEqual(err.count("the command runs docker,"), 1)
|
||||||
|
|||||||
+11
-11
@@ -109,14 +109,20 @@ class TestRadio(unittest.TestCase):
|
|||||||
def _pidfile(self, sid: str) -> Path:
|
def _pidfile(self, sid: str) -> Path:
|
||||||
return self.root / "radio-listen" / f"{sid}.pid"
|
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(
|
proc = subprocess.Popen(
|
||||||
[sys.executable, "-c", LISTENER, str(RADIO)],
|
[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)
|
self.addCleanup(self._stop, proc)
|
||||||
proc.stdin.write(json.dumps({"session_id": sid}))
|
return proc
|
||||||
proc.stdin.close()
|
|
||||||
|
def _listen(self, sid: str) -> subprocess.Popen:
|
||||||
|
proc = self._spawn(sid)
|
||||||
deadline = time.monotonic() + 10
|
deadline = time.monotonic() + 10
|
||||||
while time.monotonic() < deadline and proc.poll() is None:
|
while time.monotonic() < deadline and proc.poll() is None:
|
||||||
pidfile = self._pidfile(sid)
|
pidfile = self._pidfile(sid)
|
||||||
@@ -607,13 +613,7 @@ class TestRadio(unittest.TestCase):
|
|||||||
_, victims = self._victims()
|
_, victims = self._victims()
|
||||||
self.root.mkdir()
|
self.root.mkdir()
|
||||||
(self.root / "radio-listen").symlink_to(victims)
|
(self.root / "radio-listen").symlink_to(victims)
|
||||||
proc = subprocess.Popen(
|
proc = self._spawn("s2")
|
||||||
[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()
|
|
||||||
try:
|
try:
|
||||||
code = proc.wait(timeout=10)
|
code = proc.wait(timeout=10)
|
||||||
except subprocess.TimeoutExpired:
|
except subprocess.TimeoutExpired:
|
||||||
|
|||||||
Reference in new issue
Block a user