hap-cli 0.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hap_cli/README.md +194 -0
- hap_cli/README_CN.md +601 -0
- hap_cli/__init__.py +3 -0
- hap_cli/commands/__init__.py +1 -0
- hap_cli/commands/ai_cmd.py +224 -0
- hap_cli/commands/app_cmd.py +308 -0
- hap_cli/commands/calendar_cmd.py +138 -0
- hap_cli/commands/chat_cmd.py +101 -0
- hap_cli/commands/config_cmd.py +169 -0
- hap_cli/commands/contact_cmd.py +125 -0
- hap_cli/commands/department_cmd.py +168 -0
- hap_cli/commands/group_cmd.py +128 -0
- hap_cli/commands/instance_cmd.py +310 -0
- hap_cli/commands/node_cmd.py +538 -0
- hap_cli/commands/optionset_cmd.py +99 -0
- hap_cli/commands/page_cmd.py +102 -0
- hap_cli/commands/plugin_cmd.py +133 -0
- hap_cli/commands/post_cmd.py +155 -0
- hap_cli/commands/record_cmd.py +228 -0
- hap_cli/commands/role_cmd.py +221 -0
- hap_cli/commands/workflow_cmd.py +284 -0
- hap_cli/commands/worksheet_cmd.py +342 -0
- hap_cli/context.py +43 -0
- hap_cli/core/__init__.py +1 -0
- hap_cli/core/ai.py +133 -0
- hap_cli/core/app.py +307 -0
- hap_cli/core/auth.py +219 -0
- hap_cli/core/calendar_mod.py +114 -0
- hap_cli/core/chat.py +73 -0
- hap_cli/core/contact.py +85 -0
- hap_cli/core/department.py +131 -0
- hap_cli/core/flow_node.py +1001 -0
- hap_cli/core/group.py +99 -0
- hap_cli/core/instance.py +572 -0
- hap_cli/core/optionset.py +112 -0
- hap_cli/core/page.py +138 -0
- hap_cli/core/plugin.py +87 -0
- hap_cli/core/post.py +118 -0
- hap_cli/core/record.py +268 -0
- hap_cli/core/role.py +227 -0
- hap_cli/core/session.py +348 -0
- hap_cli/core/workflow.py +556 -0
- hap_cli/core/worksheet.py +403 -0
- hap_cli/hap_cli.py +105 -0
- hap_cli/skills/SKILL.md +383 -0
- hap_cli/skills/__init__.py +0 -0
- hap_cli/tests/__init__.py +1 -0
- hap_cli/tests/test_core.py +1824 -0
- hap_cli/tests/test_full_e2e.py +136 -0
- hap_cli/tests/test_integration.py +805 -0
- hap_cli/utils/__init__.py +1 -0
- hap_cli/utils/formatting.py +111 -0
- hap_cli/utils/options.py +10 -0
- hap_cli-0.5.0.dist-info/METADATA +223 -0
- hap_cli-0.5.0.dist-info/RECORD +58 -0
- hap_cli-0.5.0.dist-info/WHEEL +5 -0
- hap_cli-0.5.0.dist-info/entry_points.txt +2 -0
- hap_cli-0.5.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"""E2E subprocess tests for hap-cli harness."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import shutil
|
|
6
|
+
import subprocess
|
|
7
|
+
import tempfile
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
import pytest
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _resolve_cli(name="hap"):
|
|
14
|
+
"""Resolve CLI binary path.
|
|
15
|
+
|
|
16
|
+
Checks:
|
|
17
|
+
1. CLI_ANYTHING_FORCE_INSTALLED env var - use PATH lookup
|
|
18
|
+
2. shutil.which for installed binary
|
|
19
|
+
3. Fallback to python -m invocation
|
|
20
|
+
"""
|
|
21
|
+
if os.environ.get("CLI_ANYTHING_FORCE_INSTALLED"):
|
|
22
|
+
path = shutil.which(name)
|
|
23
|
+
if path:
|
|
24
|
+
return [path]
|
|
25
|
+
raise FileNotFoundError(f"{name} not found in PATH")
|
|
26
|
+
|
|
27
|
+
path = shutil.which(name)
|
|
28
|
+
if path:
|
|
29
|
+
return [path]
|
|
30
|
+
|
|
31
|
+
# Fallback: run as module
|
|
32
|
+
return ["python3", "-m", "hap_cli.hap_cli"]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class TestCLISubprocess:
|
|
36
|
+
"""Test CLI via subprocess calls."""
|
|
37
|
+
|
|
38
|
+
@pytest.fixture(autouse=True)
|
|
39
|
+
def setup(self, tmp_path):
|
|
40
|
+
self.cli = _resolve_cli()
|
|
41
|
+
self.env = os.environ.copy()
|
|
42
|
+
# Use temp config dir to avoid polluting real config
|
|
43
|
+
self.config_dir = tmp_path / ".hap-cli"
|
|
44
|
+
self.config_dir.mkdir()
|
|
45
|
+
self.env["HOME"] = str(tmp_path)
|
|
46
|
+
|
|
47
|
+
def _run(self, args, **kwargs):
|
|
48
|
+
"""Run CLI command and return CompletedProcess."""
|
|
49
|
+
return subprocess.run(
|
|
50
|
+
self.cli + args,
|
|
51
|
+
capture_output=True,
|
|
52
|
+
text=True,
|
|
53
|
+
env=self.env,
|
|
54
|
+
timeout=30,
|
|
55
|
+
**kwargs,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
def test_help_returns_zero(self):
|
|
59
|
+
result = self._run(["--help"])
|
|
60
|
+
assert result.returncode == 0
|
|
61
|
+
assert "MingDAO HAP" in result.stdout
|
|
62
|
+
|
|
63
|
+
def test_all_subcommands_have_help(self):
|
|
64
|
+
for cmd in ["config", "app", "worksheet", "record", "workflow", "role", "node", "instance"]:
|
|
65
|
+
result = self._run([cmd, "--help"])
|
|
66
|
+
assert result.returncode == 0, f"{cmd} --help failed: {result.stderr}"
|
|
67
|
+
|
|
68
|
+
def test_workflow_subcommands_in_help(self):
|
|
69
|
+
result = self._run(["workflow", "--help"])
|
|
70
|
+
assert result.returncode == 0
|
|
71
|
+
for sub in ["create", "delete", "publish", "rollback", "trigger", "config-get"]:
|
|
72
|
+
assert sub in result.stdout, f"Missing workflow subcommand: {sub}"
|
|
73
|
+
|
|
74
|
+
def test_node_subcommands_in_help(self):
|
|
75
|
+
result = self._run(["node", "--help"])
|
|
76
|
+
assert result.returncode == 0
|
|
77
|
+
for sub in ["add", "delete", "save", "test-code", "test-webhook", "test-ai",
|
|
78
|
+
"save-action", "save-search", "save-get-more", "controls", "types"]:
|
|
79
|
+
assert sub in result.stdout, f"Missing node subcommand: {sub}"
|
|
80
|
+
|
|
81
|
+
def test_instance_subcommands_in_help(self):
|
|
82
|
+
result = self._run(["instance", "--help"])
|
|
83
|
+
assert result.returncode == 0
|
|
84
|
+
for sub in ["approve", "reject", "forward", "todo", "batch", "terminate"]:
|
|
85
|
+
assert sub in result.stdout, f"Missing instance subcommand: {sub}"
|
|
86
|
+
|
|
87
|
+
def test_config_subcommands_in_help(self):
|
|
88
|
+
result = self._run(["config", "--help"])
|
|
89
|
+
assert result.returncode == 0
|
|
90
|
+
for sub in ["set", "show", "login", "logout", "whoami"]:
|
|
91
|
+
assert sub in result.stdout, f"Missing config subcommand: {sub}"
|
|
92
|
+
|
|
93
|
+
def test_config_set_and_show(self):
|
|
94
|
+
result = self._run([
|
|
95
|
+
"config", "set",
|
|
96
|
+
"--server", "https://test.mingdao.com",
|
|
97
|
+
"--token", "test_token_abc",
|
|
98
|
+
])
|
|
99
|
+
assert result.returncode == 0
|
|
100
|
+
|
|
101
|
+
result = self._run(["config", "show"])
|
|
102
|
+
assert result.returncode == 0
|
|
103
|
+
assert "test.mingdao.com" in result.stdout
|
|
104
|
+
|
|
105
|
+
def test_config_show_json(self):
|
|
106
|
+
self._run([
|
|
107
|
+
"config", "set",
|
|
108
|
+
"--server", "https://test.com",
|
|
109
|
+
"--token", "tok123",
|
|
110
|
+
])
|
|
111
|
+
result = self._run(["--json", "config", "show"])
|
|
112
|
+
assert result.returncode == 0
|
|
113
|
+
data = json.loads(result.stdout)
|
|
114
|
+
assert data["server_url"] == "https://test.com"
|
|
115
|
+
assert data["configured"] is True
|
|
116
|
+
|
|
117
|
+
def test_unconfigured_session_error(self):
|
|
118
|
+
"""Operations should fail gracefully when not configured."""
|
|
119
|
+
result = self._run(["--json", "worksheet", "info", "ws_fake"])
|
|
120
|
+
assert result.returncode != 0
|
|
121
|
+
|
|
122
|
+
def test_record_list_requires_worksheet_id(self):
|
|
123
|
+
result = self._run(["record", "list"])
|
|
124
|
+
assert result.returncode != 0
|
|
125
|
+
|
|
126
|
+
def test_json_flag_position(self):
|
|
127
|
+
"""--json must come before command group."""
|
|
128
|
+
self._run([
|
|
129
|
+
"config", "set",
|
|
130
|
+
"--server", "https://t.com",
|
|
131
|
+
"--token", "tok",
|
|
132
|
+
])
|
|
133
|
+
result = self._run(["--json", "config", "show"])
|
|
134
|
+
assert result.returncode == 0
|
|
135
|
+
# Should be valid JSON
|
|
136
|
+
json.loads(result.stdout)
|