xbp 10.14.2

XBP is a zero-config build pack that can also interact with proxies, kafka, sockets, synthetic monitors.
Documentation
import importlib.util
import pathlib
import subprocess
import sys
import unittest
from unittest.mock import patch


MODULE_PATH = pathlib.Path(__file__).parent / "xbp_mcp_server.py"
spec = importlib.util.spec_from_file_location("xbp_mcp_server", MODULE_PATH)
module = importlib.util.module_from_spec(spec)
assert spec is not None and spec.loader is not None
sys.modules[spec.name] = module
spec.loader.exec_module(module)


class XbpMcpServerTests(unittest.TestCase):
    def test_args_version_supports_target_and_git_flag(self):
        args = module._args_version({"target": "tokio=1.45.0", "git": True})
        self.assertEqual(args, ["version", "tokio=1.45.0", "--git"])

    def test_args_secrets_push_includes_optional_flags(self):
        args = module._args_secrets_push(
            {"repo": "owner/repo", "file": ".env", "force": True}
        )
        self.assertEqual(
            args,
            ["secrets", "--repo", "owner/repo", "push", "--file", ".env", "--force"],
        )

    def test_args_raw_requires_string_array(self):
        with self.assertRaises(ValueError):
            module._args_raw({"args": ["ports", 123]})

    def test_tools_include_version_tool(self):
        tool_names = {tool.name for tool in module.TOOLS}
        self.assertIn("xbp_version", tool_names)

    @patch("subprocess.run")
    def test_run_xbp_success_includes_debug_flag(self, mock_run):
        mock_run.return_value = subprocess.CompletedProcess(
            args=["xbp", "version"],
            returncode=0,
            stdout="ok",
            stderr="",
        )

        result = module._run_xbp(["version"], {"debug": True})

        self.assertTrue(result["ok"])
        self.assertEqual(result["exit_code"], 0)
        self.assertEqual(result["command"][0:2], ["xbp", "--debug"])

    @patch("subprocess.run", side_effect=FileNotFoundError)
    def test_run_xbp_file_not_found(self, _mock_run):
        result = module._run_xbp(["version"], {})
        self.assertFalse(result["ok"])
        self.assertEqual(result["exit_code"], 127)
        self.assertIn("not found", result["stderr"])

    @patch("subprocess.run")
    def test_run_xbp_timeout(self, mock_run):
        mock_run.side_effect = subprocess.TimeoutExpired(cmd=["xbp"], timeout=1)

        result = module._run_xbp(["version"], {"timeout_seconds": 1})

        self.assertFalse(result["ok"])
        self.assertEqual(result["exit_code"], 124)
        self.assertIn("timed out", result["stderr"])


if __name__ == "__main__":
    unittest.main()