Merge branch 'feat/project-write-upload'

# Conflicts:
#	README.md
#	nocobase_crm_mcp/server.py
#	scripts/manage_mcp_service.py
#	tests/test_mcp_service.py
#	tests/test_nb_client.py
#	tests/test_server.py
This commit is contained in:
nac
2026-07-13 03:00:21 +00:00
17 changed files with 1569 additions and 15 deletions
+71
View File
@@ -99,6 +99,77 @@ class NbClientTests(unittest.TestCase):
self.assertEqual(calls[0]["cmd"][0], "/opt/node/bin/nb")
self.assertEqual(calls[0]["env"]["PATH"], "/opt/node/bin:/usr/bin")
def test_create_record_uses_values_and_whitelist(self) -> None:
commands: list[list[str]] = []
def runner(cmd, **kwargs):
commands.append(cmd)
return subprocess.CompletedProcess(cmd, 0, stdout='{"data":{"id":7}}', stderr="")
client = NbClient(env_name="nb-mcp", runner=runner)
client.create_record("t_projects", {"f_project_name": "EV inverter"}, ["f_project_name"])
self.assertEqual(commands[0][:4], ["nb", "api", "resource", "create"])
self.assertEqual(
json.loads(commands[0][commands[0].index("--values") + 1]),
{"f_project_name": "EV inverter"},
)
self.assertEqual(commands[0][commands[0].index("--whitelist") + 1], "f_project_name")
def test_update_record_uses_filter_by_tk(self) -> None:
commands: list[list[str]] = []
def runner(cmd, **kwargs):
commands.append(cmd)
return subprocess.CompletedProcess(cmd, 0, stdout='{"data":{"id":7}}', stderr="")
client = NbClient(env_name="nb-mcp", runner=runner)
client.update_record("t_projects", 7, {"client_ID": 3}, ["client_ID"])
self.assertEqual(commands[0][:4], ["nb", "api", "resource", "update"])
self.assertEqual(commands[0][commands[0].index("--filter-by-tk") + 1], "7")
def test_record_writes_reject_empty_values_without_running_command(self) -> None:
commands: list[list[str]] = []
def runner(cmd, **kwargs):
commands.append(cmd)
return subprocess.CompletedProcess(cmd, 0, stdout='{"data":{}}', stderr="")
client = NbClient(env_name="nb-mcp", runner=runner)
with self.assertRaises(ValueError):
client.create_record("t_projects", {}, ["f_project_name"])
with self.assertRaises(ValueError):
client.update_record("t_projects", 7, {}, ["f_project_name"])
self.assertEqual(commands, [])
def test_record_writes_reject_nested_values_without_running_command(self) -> None:
commands: list[list[str]] = []
def runner(cmd, **kwargs):
commands.append(cmd)
return subprocess.CompletedProcess(cmd, 0, stdout='{"data":{}}', stderr="")
client = NbClient(env_name="nb-mcp", runner=runner)
nested_values = [
{"client": {"id": 3}},
{"client_ids": [3]},
{"client_ids": {3}},
{"client_ids": (3,)},
]
for values in nested_values:
with self.subTest(operation="create", values=values):
with self.assertRaises(ValueError):
client.create_record("t_projects", values, list(values))
with self.subTest(operation="update", values=values):
with self.assertRaises(ValueError):
client.update_record("t_projects", 7, values, list(values))
self.assertEqual(commands, [])
def test_list_collection_fields_uses_data_modeling_command(self) -> None:
commands: list[list[str]] = []