feat(cli): add unified user operations entrypoint
Add scripts/obsidian-wiki-ops.py as the repo-local command surface for common wiki, Kingdee, timer, daily update, and MCP operations. Route the existing business and MCP shell wrappers through the unified entrypoint for compatibility, and update docs to recommend the single command path. Validation: python3 -m unittest discover -v; python3 -m compileall obsidian_wiki tests scripts; git diff --check.
This commit is contained in:
@@ -14,6 +14,14 @@ import manage_business_sync
|
||||
|
||||
|
||||
class BusinessSyncServiceTests(unittest.TestCase):
|
||||
def test_shell_entrypoint_delegates_to_unified_user_ops_entrypoint(self):
|
||||
entrypoint = SCRIPTS_DIR / "business_sync_service.sh"
|
||||
|
||||
self.assertTrue(entrypoint.is_file())
|
||||
self.assertTrue(os.access(entrypoint, os.X_OK))
|
||||
content = entrypoint.read_text(encoding="utf-8")
|
||||
self.assertIn('exec python3 "$SCRIPT_DIR/obsidian-wiki-ops.py" timer "$@"', content)
|
||||
|
||||
def test_render_service_and_timer_units_for_incremental_sync(self):
|
||||
service = manage_business_sync.render_service_unit(
|
||||
project_root=Path("/opt/obsidian-wiki"),
|
||||
|
||||
@@ -15,7 +15,7 @@ import manage_mcp_service
|
||||
|
||||
|
||||
class McpServiceConfigTests(unittest.TestCase):
|
||||
def test_service_commands_use_one_shell_entrypoint(self):
|
||||
def test_service_commands_delegate_to_unified_user_ops_entrypoint(self):
|
||||
entrypoint = SCRIPTS_DIR / "mcp_service.sh"
|
||||
legacy_wrappers = [
|
||||
"new_mcp_service_token.sh",
|
||||
@@ -28,9 +28,9 @@ class McpServiceConfigTests(unittest.TestCase):
|
||||
self.assertTrue(entrypoint.is_file())
|
||||
self.assertTrue(os.access(entrypoint, os.X_OK))
|
||||
content = entrypoint.read_text(encoding="utf-8")
|
||||
self.assertIn('exec python3 "$SCRIPT_DIR/manage_mcp_service.py" "$@"', content)
|
||||
self.assertIn('exec python3 "$SCRIPT_DIR/obsidian-wiki-ops.py" mcp "$@"', content)
|
||||
for wrapper in legacy_wrappers:
|
||||
self.assertFalse((SCRIPTS_DIR / wrapper).exists(), f"{wrapper} should be folded into mcp_service.sh")
|
||||
self.assertFalse((SCRIPTS_DIR / wrapper).exists(), f"{wrapper} should be folded into obsidian-wiki-ops.py")
|
||||
|
||||
def test_render_service_unit_uses_http_transport_without_embedding_token(self):
|
||||
unit = manage_mcp_service.render_service_unit(
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
import importlib.util
|
||||
import io
|
||||
import sys
|
||||
import unittest
|
||||
from contextlib import redirect_stdout
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
SCRIPT_PATH = Path(__file__).resolve().parent.parent / "scripts" / "obsidian-wiki-ops.py"
|
||||
|
||||
|
||||
def load_user_ops():
|
||||
spec = importlib.util.spec_from_file_location("obsidian_wiki_user_ops", SCRIPT_PATH)
|
||||
if spec is None or spec.loader is None:
|
||||
raise ImportError(f"cannot import {SCRIPT_PATH}")
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
sys.modules[spec.name] = module
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
class UserOpsTests(unittest.TestCase):
|
||||
def test_kingdee_sync_forwards_to_business_cli(self):
|
||||
user_ops = load_user_ops()
|
||||
|
||||
with patch.object(user_ops, "obsidian_cli_main", return_value=0) as cli_main:
|
||||
status = user_ops.main(["kingdee", "sync", "--vault", "/data/vault", "--incremental"])
|
||||
|
||||
self.assertEqual(status, 0)
|
||||
cli_main.assert_called_once_with(
|
||||
["business", "sync", "kingdee", "--vault", "/data/vault", "--incremental"]
|
||||
)
|
||||
|
||||
def test_timer_install_alias_installs_and_starts_business_timer(self):
|
||||
user_ops = load_user_ops()
|
||||
|
||||
with patch.object(user_ops.manage_business_sync, "main", return_value=0) as timer_main:
|
||||
status = user_ops.main(["timer", "install", "--vault", "/data/vault"])
|
||||
|
||||
self.assertEqual(status, 0)
|
||||
timer_main.assert_called_once_with(["start", "--vault", "/data/vault"])
|
||||
|
||||
def test_mcp_commands_forward_to_mcp_service_manager(self):
|
||||
user_ops = load_user_ops()
|
||||
|
||||
with patch.object(user_ops.manage_mcp_service, "main", return_value=0) as mcp_main:
|
||||
status = user_ops.main(["mcp", "start", "--enable-query"])
|
||||
|
||||
self.assertEqual(status, 0)
|
||||
mcp_main.assert_called_once_with(["start", "--enable-query"])
|
||||
|
||||
def test_help_lists_common_user_operations(self):
|
||||
user_ops = load_user_ops()
|
||||
output = io.StringIO()
|
||||
|
||||
with redirect_stdout(output):
|
||||
status = user_ops.main(["help"])
|
||||
|
||||
self.assertEqual(status, 0)
|
||||
text = output.getvalue()
|
||||
self.assertIn("kingdee sync", text)
|
||||
self.assertIn("timer install", text)
|
||||
self.assertIn("mcp start", text)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user