Skip to content

Commit 71e3d32

Browse files
committed
style: ruff format + drop unused import in pipeline_install_rust
1 parent 450824b commit 71e3d32

5 files changed

Lines changed: 83 additions & 25 deletions

File tree

mcp_server/infrastructure/pipeline_discovery.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@
5757

5858
# Where the silent installer clones and builds the upstream source.
5959
# Living next to other methodology artefacts means cleanup is one rm -rf.
60-
_INSTALL_SRC_DIR = Path.home() / ".claude" / "methodology" / "src" / "automatised-pipeline"
60+
_INSTALL_SRC_DIR = (
61+
Path.home() / ".claude" / "methodology" / "src" / "automatised-pipeline"
62+
)
6163
_INSTALL_BIN_DIR = Path.home() / ".claude" / "methodology" / "bin"
6264
_INSTALL_SYMLINK = _INSTALL_BIN_DIR / "mcp-server"
6365

@@ -112,7 +114,11 @@ def ensure_pipeline_connection() -> dict:
112114
# may have rm-rf'd the install dir, deleted the symlink, or
113115
# moved the source repo. Stale entries silently break ingest;
114116
# purge them so the install path can re-run.
115-
if configured_cmd and Path(configured_cmd).exists() and os.access(configured_cmd, os.X_OK):
117+
if (
118+
configured_cmd
119+
and Path(configured_cmd).exists()
120+
and os.access(configured_cmd, os.X_OK)
121+
):
116122
return {
117123
"action": "already_configured",
118124
"path": str(path),
@@ -126,7 +132,9 @@ def ensure_pipeline_connection() -> dict:
126132
try:
127133
write_json(path, existing)
128134
except Exception as exc:
129-
logger.warning("Failed to purge stale codebase entry from %s: %s", path, exc)
135+
logger.warning(
136+
"Failed to purge stale codebase entry from %s: %s", path, exc
137+
)
130138

131139
# Auto-install path. If discovery fails, attempt a silent
132140
# git-clone + cargo build (and rustup bootstrap if cargo missing)

mcp_server/infrastructure/pipeline_install_release.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
from pathlib import Path
3737
from typing import Optional
3838

39-
_RELEASES_URL = "https://api.github.com/repos/cdeust/automatised-pipeline/releases/latest"
39+
_RELEASES_URL = (
40+
"https://api.github.com/repos/cdeust/automatised-pipeline/releases/latest"
41+
)
4042
_REQUEST_TIMEOUT = 30 # seconds
4143
_DISABLE_ENV = "CORTEX_DISABLE_PREBUILT"
4244

@@ -46,7 +48,12 @@ def _platform_tag() -> Optional[str]:
4648
sys = platform.system().lower()
4749
mach = platform.machine().lower()
4850
os_tag = {"darwin": "macos", "linux": "linux"}.get(sys)
49-
arch_tag = {"x86_64": "x86_64", "amd64": "x86_64", "arm64": "aarch64", "aarch64": "aarch64"}.get(mach)
51+
arch_tag = {
52+
"x86_64": "x86_64",
53+
"amd64": "x86_64",
54+
"arm64": "aarch64",
55+
"aarch64": "aarch64",
56+
}.get(mach)
5057
if not os_tag or not arch_tag:
5158
return None
5259
return f"{os_tag}-{arch_tag}"
@@ -88,7 +95,9 @@ def _find_assets(release: dict, tag: str) -> Optional[tuple[str, str]]:
8895
return None
8996

9097

91-
def _verify_and_extract(tar_path: str, expected_sha: str, dest_dir: str) -> Optional[str]:
98+
def _verify_and_extract(
99+
tar_path: str, expected_sha: str, dest_dir: str
100+
) -> Optional[str]:
92101
"""Verify SHA256, extract ``ai-architect-mcp`` to dest_dir, return path.
93102
94103
Refuses tar entries that escape dest_dir (path-traversal guard).
@@ -158,11 +167,17 @@ def try_install_prebuilt(symlink_dest: Path) -> dict:
158167
digest_text = sha_bytes.decode("utf-8", errors="replace").strip()
159168
expected_sha = digest_text.split()[0] if digest_text else ""
160169
if len(expected_sha) != 64:
161-
return {"action": "prebuilt_unavailable", "detail": "malformed sha256 manifest"}
170+
return {
171+
"action": "prebuilt_unavailable",
172+
"detail": "malformed sha256 manifest",
173+
}
162174

163175
binary = _verify_and_extract(str(tar_path), expected_sha, str(work))
164176
if not binary:
165-
return {"action": "prebuilt_unavailable", "detail": "hash mismatch or no binary in archive"}
177+
return {
178+
"action": "prebuilt_unavailable",
179+
"detail": "hash mismatch or no binary in archive",
180+
}
166181

167182
# Move the verified binary into the methodology bin dir under a
168183
# versioned name so subsequent fast-path installs don't clash.

mcp_server/infrastructure/pipeline_install_rust.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import os
2828
import shlex
2929
import shutil
30-
import subprocess
3130
import tempfile
3231
from pathlib import Path
3332
from typing import Optional
@@ -114,7 +113,11 @@ def install_rust_toolchain() -> dict:
114113
if not curl:
115114
return {"action": "rust_curl_missing"}
116115

117-
pin_disabled = os.environ.get(_DISABLE_HASH_PIN_ENV, "").strip() in {"0", "false", "no"}
116+
pin_disabled = os.environ.get(_DISABLE_HASH_PIN_ENV, "").strip() in {
117+
"0",
118+
"false",
119+
"no",
120+
}
118121
pinned_hash = None if pin_disabled else _read_pinned_hash()
119122

120123
if pinned_hash:
@@ -139,7 +142,16 @@ def _install_with_hash_pin(curl: str, pinned_hash: str) -> dict:
139142
tmp_path = tmp.name
140143
try:
141144
rc, tail = _run_quiet(
142-
[curl, "--proto", "=https", "--tlsv1.2", "-sSf", "-o", tmp_path, _RUSTUP_URL],
145+
[
146+
curl,
147+
"--proto",
148+
"=https",
149+
"--tlsv1.2",
150+
"-sSf",
151+
"-o",
152+
tmp_path,
153+
_RUSTUP_URL,
154+
],
143155
timeout=120,
144156
)
145157
if rc != 0:

mcp_server/infrastructure/pipeline_installer.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ def _is_ci_environment() -> bool:
7474
return any(os.environ.get(name) for name in _CI_ENV_VARS)
7575

7676

77-
def install_pipeline(force_rebuild: bool = False, git_url: Optional[str] = None) -> dict:
77+
def install_pipeline(
78+
force_rebuild: bool = False, git_url: Optional[str] = None
79+
) -> dict:
7880
"""Best-effort silent install of the upstream pipeline binary.
7981
8082
Returns audit dict with one of these actions:
@@ -109,7 +111,9 @@ def _install_locked(force_rebuild: bool, git_url: Optional[str]) -> dict:
109111
# falls through to the source-build path below.
110112
if not force_rebuild:
111113
prebuilt = try_install_prebuilt(_INSTALL_SYMLINK)
112-
if prebuilt.get("action") == "installed_prebuilt" and _binary_is_usable(_INSTALL_SYMLINK):
114+
if prebuilt.get("action") == "installed_prebuilt" and _binary_is_usable(
115+
_INSTALL_SYMLINK
116+
):
113117
return prebuilt
114118

115119
cargo = resolve_cargo()
@@ -156,7 +160,9 @@ def _install_locked(force_rebuild: bool, git_url: Optional[str]) -> dict:
156160
return _swap_symlink(binary)
157161

158162

159-
def _ensure_source(src: Path, url: str, git: str, force_rebuild: bool) -> Optional[dict]:
163+
def _ensure_source(
164+
src: Path, url: str, git: str, force_rebuild: bool
165+
) -> Optional[dict]:
160166
"""Clone or refresh the source tree. Return None on success, or
161167
a structured failure dict."""
162168
# Validate any existing checkout. A half-cloned dir leaves
@@ -166,14 +172,19 @@ def _ensure_source(src: Path, url: str, git: str, force_rebuild: bool) -> Option
166172
try:
167173
_rmtree_quiet(src)
168174
except OSError as exc:
169-
return {"action": "clone_failed", "detail": f"stale partial src cleanup: {exc}"}
175+
return {
176+
"action": "clone_failed",
177+
"detail": f"stale partial src cleanup: {exc}",
178+
}
170179

171180
if not src.exists():
172181
# Clone into a .partial sibling, atomic-rename on success.
173182
partial = src.with_name(src.name + ".partial")
174183
if partial.exists():
175184
_rmtree_quiet(partial)
176-
rc, tail = _run_quiet([git, "clone", "--depth=1", url, str(partial)], timeout=1800)
185+
rc, tail = _run_quiet(
186+
[git, "clone", "--depth=1", url, str(partial)], timeout=1800
187+
)
177188
if rc != 0 or not (partial / "Cargo.toml").is_file():
178189
_rmtree_quiet(partial)
179190
return {"action": "clone_failed", "detail": tail}

tests_py/infrastructure/test_pipeline_discovery.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,24 @@ def test_stale_codebase_entry_purged(self, tmp_path, monkeypatch):
147147
purged so the install path can re-run instead of silently
148148
breaking ingest_codebase."""
149149
config_path = tmp_path / "mcp-connections.json"
150-
config_path.write_text(json.dumps({
151-
"servers": {
152-
"codebase": {"command": "/nonexistent/mcp", "args": []},
153-
"other": {"command": "node", "args": ["/x.js"]},
154-
}
155-
}))
150+
config_path.write_text(
151+
json.dumps(
152+
{
153+
"servers": {
154+
"codebase": {"command": "/nonexistent/mcp", "args": []},
155+
"other": {"command": "node", "args": ["/x.js"]},
156+
}
157+
}
158+
)
159+
)
156160
monkeypatch.setattr(pipeline_discovery, "MCP_CONNECTIONS_PATH", config_path)
157161
# Simulate fresh discovery finding nothing (no install attempted
158162
# because we monkeypatch install_pipeline import).
159-
monkeypatch.setattr(pipeline_discovery, "discover_pipeline_command", lambda: None)
163+
monkeypatch.setattr(
164+
pipeline_discovery, "discover_pipeline_command", lambda: None
165+
)
160166
from mcp_server.infrastructure import pipeline_installer
167+
161168
monkeypatch.setattr(
162169
pipeline_installer,
163170
"install_pipeline",
@@ -321,6 +328,7 @@ def test_missing_toolchain_returns_structured_failure(self, tmp_path, monkeypatc
321328
tmp_path / "nonexistent" / "mcp-server",
322329
)
323330
from mcp_server.infrastructure import pipeline_install_rust
331+
324332
# Disable the GitHub-Releases fast-path so the missing-toolchain
325333
# branch is reachable.
326334
monkeypatch.setattr(
@@ -384,7 +392,9 @@ def test_prebuilt_unsupported_platform(self, monkeypatch):
384392
from mcp_server.infrastructure import pipeline_install_release
385393

386394
monkeypatch.delenv("CORTEX_DISABLE_PREBUILT", raising=False)
387-
monkeypatch.setattr(pipeline_install_release.platform, "system", lambda: "OpenBSD")
395+
monkeypatch.setattr(
396+
pipeline_install_release.platform, "system", lambda: "OpenBSD"
397+
)
388398
result = pipeline_install_release.try_install_prebuilt(Path("/tmp/symlink"))
389399
assert result["action"] == "prebuilt_unsupported_platform"
390400

@@ -432,7 +442,9 @@ def test_install_failure_in_ensure_does_not_crash(self, tmp_path, monkeypatch):
432442

433443
config_path = tmp_path / "mcp-connections.json"
434444
monkeypatch.setattr(pipeline_discovery, "MCP_CONNECTIONS_PATH", config_path)
435-
monkeypatch.setattr(pipeline_discovery, "discover_pipeline_command", lambda: None)
445+
monkeypatch.setattr(
446+
pipeline_discovery, "discover_pipeline_command", lambda: None
447+
)
436448
monkeypatch.setattr(
437449
pipeline_installer,
438450
"install_pipeline",

0 commit comments

Comments
 (0)