Fix Feishu sheet data writes
This commit is contained in:
@@ -130,10 +130,6 @@ class FeishuIntegrationTests(unittest.TestCase):
|
||||
'{"url":"https://mi.feishu.cn/sheets/shtcn123","spreadsheet_token":"shtcn123"}',
|
||||
{'server_name': 'feishu-mcp-pro', 'tool_name': 'sheet_ops'},
|
||||
),
|
||||
(
|
||||
'{"sheets":[{"sheet_id":"abc123","title":"Sheet1"}]}',
|
||||
{'server_name': 'feishu-mcp-pro', 'tool_name': 'sheet_ops'},
|
||||
),
|
||||
(
|
||||
'{"ok":true}',
|
||||
{'server_name': 'feishu-mcp-pro', 'tool_name': 'sheet_ops'},
|
||||
@@ -149,12 +145,12 @@ class FeishuIntegrationTests(unittest.TestCase):
|
||||
payload = response.json()
|
||||
self.assertEqual(payload['kind'], 'sheet')
|
||||
self.assertEqual(payload['url'], 'https://mi.feishu.cn/sheets/shtcn123')
|
||||
self.assertEqual(call_tool.call_count, 3)
|
||||
self.assertEqual(call_tool.call_count, 2)
|
||||
self.assertEqual(call_tool.call_args_list[0].args[0], 'sheet_ops')
|
||||
self.assertEqual(call_tool.call_args_list[0].kwargs['arguments']['action'], 'create')
|
||||
self.assertEqual(call_tool.call_args_list[2].kwargs['arguments']['action'], 'write')
|
||||
write_params = call_tool.call_args_list[2].kwargs['arguments']['params']
|
||||
self.assertEqual(write_params['range'], 'abc123!A1:B2')
|
||||
self.assertEqual(call_tool.call_args_list[1].kwargs['arguments']['action'], 'write')
|
||||
write_params = call_tool.call_args_list[1].kwargs['arguments']['params']
|
||||
self.assertEqual(write_params['range'], 'Sheet1!A1:B2')
|
||||
self.assertEqual(
|
||||
json.loads(write_params['values']),
|
||||
[['query', 'label'], ['导航到公司', 'Agent(tag="地图导航")']],
|
||||
@@ -168,6 +164,42 @@ class FeishuIntegrationTests(unittest.TestCase):
|
||||
online_docs = json.loads(map_path.read_text(encoding='utf-8'))
|
||||
self.assertEqual(online_docs['files'][str(file_path)]['kind'], 'sheet')
|
||||
|
||||
def test_create_online_doc_surfaces_feishu_sheet_write_error(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
client, state = _build_client(Path(tmp_dir))
|
||||
file_path = _write_account_file(
|
||||
state,
|
||||
'alice',
|
||||
'records.csv',
|
||||
'query,label\n导航到公司,地图导航\n',
|
||||
)
|
||||
|
||||
with patch.object(
|
||||
gui_server,
|
||||
'_feishu_status_payload',
|
||||
return_value={'logged_in': True, 'status': 'logged_in'},
|
||||
), patch.object(
|
||||
gui_server.MCPRuntime,
|
||||
'call_tool',
|
||||
side_effect=[
|
||||
(
|
||||
'{"url":"https://mi.feishu.cn/sheets/shtcn123","spreadsheet_token":"shtcn123"}',
|
||||
{'server_name': 'feishu-mcp-pro', 'tool_name': 'sheet_ops'},
|
||||
),
|
||||
(
|
||||
'{"error":"Sheet not found","code":123}',
|
||||
{'server_name': 'feishu-mcp-pro', 'tool_name': 'sheet_ops'},
|
||||
),
|
||||
],
|
||||
):
|
||||
response = client.post(
|
||||
'/api/files/online-doc',
|
||||
json={'account_id': 'alice', 'path': str(file_path)},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 400)
|
||||
self.assertIn('Sheet not found', response.json()['detail'])
|
||||
|
||||
def test_extract_first_url_ignores_wrapping_quotes(self) -> None:
|
||||
url = gui_server._extract_first_url(
|
||||
'{"url":"https://mi.feishu.cn/docx/CZIldpM3QofbbXxxAq1cEininTd"}'
|
||||
|
||||
Reference in New Issue
Block a user