answer42 0.12.0__tar.gz → 0.13.0__tar.gz

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.
Files changed (70) hide show
  1. {answer42-0.12.0 → answer42-0.13.0}/PKG-INFO +1 -1
  2. {answer42-0.12.0 → answer42-0.13.0}/pyproject.toml +1 -1
  3. {answer42-0.12.0 → answer42-0.13.0}/src/cf/DataProcessors/MCPTestManager/Forms//320/244/320/276/321/200/320/274/320/260/Ext/Form/Module.bsl +118 -1
  4. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/assets/MCPTestClient.cf +0 -0
  5. answer42-0.13.0/src/mcp_1c/assets/MCPTestManager.cf +0 -0
  6. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/protocol.py +1 -1
  7. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/server.py +87 -6
  8. answer42-0.12.0/src/mcp_1c/assets/MCPTestManager.cf +0 -0
  9. {answer42-0.12.0 → answer42-0.13.0}/.gitignore +0 -0
  10. {answer42-0.12.0 → answer42-0.13.0}/LICENSE +0 -0
  11. {answer42-0.12.0 → answer42-0.13.0}/README.md +0 -0
  12. {answer42-0.12.0 → answer42-0.13.0}/credentials.example.json +0 -0
  13. {answer42-0.12.0 → answer42-0.13.0}/docs/agent-installation.md +0 -0
  14. {answer42-0.12.0 → answer42-0.13.0}/docs/architecture.md +0 -0
  15. {answer42-0.12.0 → answer42-0.13.0}/docs/assets/answer42-logo.png +0 -0
  16. {answer42-0.12.0 → answer42-0.13.0}/docs/assets/platform42-logo.svg +0 -0
  17. {answer42-0.12.0 → answer42-0.13.0}/docs/installation.md +0 -0
  18. {answer42-0.12.0 → answer42-0.13.0}/scripts/build_cf.py +0 -0
  19. {answer42-0.12.0 → answer42-0.13.0}/scripts/e2e_http_smoke.py +0 -0
  20. {answer42-0.12.0 → answer42-0.13.0}/scripts/e2e_stable.py +0 -0
  21. {answer42-0.12.0 → answer42-0.13.0}/scripts/openclaw_mcp_autoreload.py +0 -0
  22. {answer42-0.12.0 → answer42-0.13.0}/scripts/rag_cli.py +0 -0
  23. {answer42-0.12.0 → answer42-0.13.0}/scripts/read_webclient_start_info.py +0 -0
  24. {answer42-0.12.0 → answer42-0.13.0}/src/cf/ConfigDumpInfo.xml +0 -0
  25. {answer42-0.12.0 → answer42-0.13.0}/src/cf/Configuration.xml +0 -0
  26. {answer42-0.12.0 → answer42-0.13.0}/src/cf/DataProcessors/MCPTestManager/Ext/ObjectModule.bsl +0 -0
  27. {answer42-0.12.0 → answer42-0.13.0}/src/cf/DataProcessors/MCPTestManager/Forms//320/244/320/276/321/200/320/274/320/260/Ext/Form.xml" +0 -0
  28. {answer42-0.12.0 → answer42-0.13.0}/src/cf/DataProcessors/MCPTestManager/Forms//320/244/320/276/321/200/320/274/320/260.xml" +0 -0
  29. {answer42-0.12.0 → answer42-0.13.0}/src/cf/DataProcessors/MCPTestManager.xml +0 -0
  30. {answer42-0.12.0 → answer42-0.13.0}/src/cf/Ext/ManagedApplicationModule.bsl +0 -0
  31. {answer42-0.12.0 → answer42-0.13.0}/src/cf/Languages//320/240/321/203/321/201/321/201/320/272/320/270/320/271.xml" +0 -0
  32. {answer42-0.12.0 → answer42-0.13.0}/src/client_cf/Catalogs//320/237/320/241_/320/222/320/273/320/260/320/264/320/265/320/273/320/265/321/206.xml" +0 -0
  33. {answer42-0.12.0 → answer42-0.13.0}/src/client_cf/Catalogs//320/237/320/241_/320/241/320/277/321/200/320/260/320/262/320/276/321/207/320/275/320/270/320/2721.xml" +0 -0
  34. {answer42-0.12.0 → answer42-0.13.0}/src/client_cf/ConfigDumpInfo.xml +0 -0
  35. {answer42-0.12.0 → answer42-0.13.0}/src/client_cf/Configuration.xml +0 -0
  36. {answer42-0.12.0 → answer42-0.13.0}/src/client_cf/Languages//320/240/321/203/321/201/321/201/320/272/320/270/320/271.xml" +0 -0
  37. {answer42-0.12.0 → answer42-0.13.0}/src/client_cf/Reports//320/237/320/241_/320/241/320/277/320/270/321/201/320/276/320/272/320/255/320/273/320/265/320/274/320/265/320/275/321/202/320/276/320/262/Ext/ManagerModule.bsl" +0 -0
  38. {answer42-0.12.0 → answer42-0.13.0}/src/client_cf/Reports//320/237/320/241_/320/241/320/277/320/270/321/201/320/276/320/272/320/255/320/273/320/265/320/274/320/265/320/275/321/202/320/276/320/262/Ext/ObjectModule.bsl" +0 -0
  39. {answer42-0.12.0 → answer42-0.13.0}/src/client_cf/Reports//320/237/320/241_/320/241/320/277/320/270/321/201/320/276/320/272/320/255/320/273/320/265/320/274/320/265/320/275/321/202/320/276/320/262/Templates//320/236/321/201/320/275/320/276/320/262/320/275/320/260/321/217/320/241/321/205/320/265/320/274/320/260/320/232/320/276/320/274/320/277/320/276/320/275/320/276/320/262/320/272/320/270/320/224/320/260/320/275/320/275/321/213/321/205/Ext/Template.xml" +0 -0
  40. {answer42-0.12.0 → answer42-0.13.0}/src/client_cf/Reports//320/237/320/241_/320/241/320/277/320/270/321/201/320/276/320/272/320/255/320/273/320/265/320/274/320/265/320/275/321/202/320/276/320/262/Templates//320/236/321/201/320/275/320/276/320/262/320/275/320/260/321/217/320/241/321/205/320/265/320/274/320/260/320/232/320/276/320/274/320/277/320/276/320/275/320/276/320/262/320/272/320/270/320/224/320/260/320/275/320/275/321/213/321/205.xml" +0 -0
  41. {answer42-0.12.0 → answer42-0.13.0}/src/client_cf/Reports//320/237/320/241_/320/241/320/277/320/270/321/201/320/276/320/272/320/255/320/273/320/265/320/274/320/265/320/275/321/202/320/276/320/262.xml" +0 -0
  42. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/__init__.py +0 -0
  43. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/assets/__init__.py +0 -0
  44. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/auth.py +0 -0
  45. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/bridge.py +0 -0
  46. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/browser_agent.py +0 -0
  47. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/credentials.py +0 -0
  48. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/credentials_cli.py +0 -0
  49. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/html_agent.py +0 -0
  50. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/os_support.py +0 -0
  51. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/platform.py +0 -0
  52. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/rag/__init__.py +0 -0
  53. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/rag/detect.py +0 -0
  54. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/rag/dump.py +0 -0
  55. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/rag/model.py +0 -0
  56. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/rag/parsers.py +0 -0
  57. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/rag/service.py +0 -0
  58. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/rag/store.py +0 -0
  59. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/rag/summary_backend.py +0 -0
  60. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/rag/summary_vector.py +0 -0
  61. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/recorder.py +0 -0
  62. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/release_helper.py +0 -0
  63. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/runtime.py +0 -0
  64. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/skill_installer.py +0 -0
  65. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/tool_groups.py +0 -0
  66. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/version_proxy.py +0 -0
  67. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/webclient_probe.py +0 -0
  68. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/webkit_patch.py +0 -0
  69. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/win_desktop.py +0 -0
  70. {answer42-0.12.0 → answer42-0.13.0}/src/mcp_1c/window_control.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: answer42
3
- Version: 0.12.0
3
+ Version: 0.13.0
4
4
  Summary: Answer42 — The Answer to Life, Universe, and 1C — UI Driver. MCP-powered 1C:Enterprise UI automation: click, fill, navigate, test, and introspect managed forms through the test-client API
5
5
  Author: Marvin (AI Assistant), 42Clouds, and contributors
6
6
  Author-email: "Kosolapov Stanislav (proDOOMman)" <prodoomman@gmail.com>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "answer42"
3
- version = "0.12.0"
3
+ version = "0.13.0"
4
4
  description = "Answer42 — The Answer to Life, Universe, and 1C — UI Driver. MCP-powered 1C:Enterprise UI automation: click, fill, navigate, test, and introspect managed forms through the test-client API"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -371,7 +371,7 @@
371
371
 
372
372
  &НаКлиенте
373
373
  Функция ВерсияПротоколаМенеджераMCP()
374
- Возврат "2026.11.16.1";
374
+ Возврат "2026.12.02.1";
375
375
  КонецФункции
376
376
 
377
377
  &НаКлиенте
@@ -405,6 +405,9 @@
405
405
  ИначеЕсли Метод = "disconnect_test_client" Тогда
406
406
  Лог("ВыполнитьКоманду: disconnect_test_client");
407
407
  Возврат ОтключитьКлиентТестирования();
408
+ ИначеЕсли Метод = "close_test_client" Тогда
409
+ Лог("ВыполнитьКоманду: close_test_client");
410
+ Возврат ЗакрытьКлиентТестированияMCP();
408
411
  ИначеЕсли Метод = "active_window" Тогда
409
412
  Возврат АктивноеОкноКакСтруктуру();
410
413
  ИначеЕсли Метод = "active_window_summary" Тогда
@@ -11497,6 +11500,120 @@
11497
11500
  КонецПопытки;
11498
11501
  КонецФункции
11499
11502
 
11503
+ // Штатное завершение клиента тестирования средствами 1С: закрывается главное окно
11504
+ // приложения (ТестируемоеОкноКлиентскогоПриложения), как крестиком окна.
11505
+ // - Вопрос "Завершить работу с программой?" подтверждается кнопкой "Да".
11506
+ // - Вопрос о несохраненных данных ("Данные были изменены. Все изменения будут потеряны.")
11507
+ // не подтверждается: клиент остается открытым, текст и кнопки возвращаются агенту.
11508
+ // Процесс клиента здесь не убивается: что делать, если клиент не завершился, решает вызывающая сторона.
11509
+ &НаКлиенте
11510
+ Функция ЗакрытьКлиентТестированияMCP()
11511
+ Результат = Новый Структура("attempted,reason,exit_confirmed,window_title", Ложь, "", Ложь, "");
11512
+ Если ТестируемоеПриложение = Неопределено Тогда
11513
+ Результат.reason = "not_connected";
11514
+ Возврат Результат;
11515
+ КонецЕсли;
11516
+ ОкноГлавное = ГлавноеОкноТестируемогоПриложенияMCP();
11517
+ Если ОкноГлавное = Неопределено Тогда
11518
+ Результат.reason = "no_window";
11519
+ Возврат Результат;
11520
+ КонецЕсли;
11521
+ Результат.window_title = БезопасноеСвойство(ОкноГлавное, "Заголовок", "");
11522
+ Результат.attempted = Истина;
11523
+ Попытка
11524
+ ОкноГлавное.Закрыть();
11525
+ Исключение
11526
+ // Клиент мог завершиться, не успев ответить: решает проверка процесса на стороне Python.
11527
+ Результат.Вставить("close_error", ПодробноеПредставлениеОшибки(ИнформацияОбОшибке()));
11528
+ Результат.reason = "close_call_failed";
11529
+ Возврат Результат;
11530
+ КонецПопытки;
11531
+
11532
+ Для НомерШага = 1 По 5 Цикл
11533
+ Попытка
11534
+ Диалог = ДиалогВопросаКлиентаMCP();
11535
+ Исключение
11536
+ // Связь с клиентом оборвалась: после подтверждения выхода это нормальное завершение.
11537
+ Результат.reason = ?(Результат.exit_confirmed, "exit_confirmed", "connection_lost");
11538
+ Возврат Результат;
11539
+ КонецПопытки;
11540
+ Если Диалог = Неопределено Тогда
11541
+ Результат.reason = ?(Результат.exit_confirmed, "exit_confirmed", "no_dialog");
11542
+ Возврат Результат;
11543
+ КонецЕсли;
11544
+ Результат.Вставить("dialog_title", Диалог.title);
11545
+ Результат.Вставить("dialog_text", Диалог.text);
11546
+ Результат.Вставить("dialog_buttons", Диалог.buttons);
11547
+ ТекстДиалога = НРег(Диалог.title + " " + Диалог.text);
11548
+ Если СтрНайти(ТекстДиалога, "изменен") > 0 Или СтрНайти(ТекстДиалога, "потеряны") > 0
11549
+ Или СтрНайти(ТекстДиалога, "не сохран") > 0 Или СтрНайти(ТекстДиалога, "сохранить") > 0 Тогда
11550
+ Результат.reason = "unsaved_changes";
11551
+ Возврат Результат;
11552
+ КонецЕсли;
11553
+ Если СтрНайти(ТекстДиалога, "заверш") = 0 Или СтрНайти(ТекстДиалога, "работ") = 0 Тогда
11554
+ Результат.reason = "unexpected_dialog";
11555
+ Возврат Результат;
11556
+ КонецЕсли;
11557
+ КнопкаДа = Неопределено;
11558
+ Для Каждого КнопкаДиалога Из Диалог.button_objects Цикл
11559
+ ЗаголовокКнопки = НРег(СокрЛП(БезопасныйЗаголовок(КнопкаДиалога)));
11560
+ Если ЗаголовокКнопки = "да" Или ЗаголовокКнопки = "yes" Тогда
11561
+ КнопкаДа = КнопкаДиалога;
11562
+ Прервать;
11563
+ КонецЕсли;
11564
+ КонецЦикла;
11565
+ Если КнопкаДа = Неопределено Тогда
11566
+ Результат.reason = "unexpected_dialog";
11567
+ Возврат Результат;
11568
+ КонецЕсли;
11569
+ Результат.exit_confirmed = Истина;
11570
+ Результат.Вставить("clicked_button", БезопасныйЗаголовок(КнопкаДа));
11571
+ Попытка
11572
+ КнопкаДа.Нажать();
11573
+ Исключение
11574
+ // Клиент завершился прямо при нажатии: ответ не успел вернуться.
11575
+ Результат.reason = "exit_confirmed";
11576
+ Возврат Результат;
11577
+ КонецПопытки;
11578
+ КонецЦикла;
11579
+ Результат.reason = "dialog_loop_limit";
11580
+ Возврат Результат;
11581
+ КонецФункции
11582
+
11583
+ &НаКлиенте
11584
+ Функция ГлавноеОкноТестируемогоПриложенияMCP()
11585
+ ВсеОкна = ОкнаТестируемогоПриложения();
11586
+ Для Каждого ТекущееОкно Из ВсеОкна Цикл
11587
+ Если БезопасноеСвойство(ТекущееОкно, "Основное", БезопасноеСвойство(ТекущееОкно, "ГлавноеОкно", Ложь)) = Истина Тогда
11588
+ Возврат ТекущееОкно;
11589
+ КонецЕсли;
11590
+ КонецЦикла;
11591
+ Если ВсеОкна.Количество() > 0 Тогда
11592
+ Возврат ВсеОкна[0];
11593
+ КонецЕсли;
11594
+ Возврат Неопределено;
11595
+ КонецФункции
11596
+
11597
+ // Активное окно как вопрос клиента (текст и кнопки) или Неопределено, если окно не содержит кнопок.
11598
+ // Исключение значит, что связь с клиентом потеряна.
11599
+ &НаКлиенте
11600
+ Функция ДиалогВопросаКлиентаMCP()
11601
+ ОкноДиалога = ТестируемоеПриложение.ПолучитьАктивноеОкно();
11602
+ ТекстыДиалога = Новый Массив;
11603
+ НайтиТекстыОкнаРекурсивно(ОкноДиалога, ТекстыДиалога, 0);
11604
+ КнопкиДиалога = Новый Массив;
11605
+ НайтиКнопкиРекурсивно(ОкноДиалога, КнопкиДиалога, 0);
11606
+ Если КнопкиДиалога.Количество() = 0 Тогда
11607
+ Возврат Неопределено;
11608
+ КонецЕсли;
11609
+ ОписаниеКнопок = Новый Массив;
11610
+ Для Каждого КнопкаДиалога Из КнопкиДиалога Цикл
11611
+ ОписаниеКнопок.Добавить(Новый Структура("name,title", БезопасноеСвойство(КнопкаДиалога, "Имя", ""), БезопасныйЗаголовок(КнопкаДиалога)));
11612
+ КонецЦикла;
11613
+ Возврат Новый Структура("title,text,buttons,button_objects", БезопасноеСвойство(ОкноДиалога, "Заголовок", ""),
11614
+ СтрСоединить(ТекстыДиалога, Символы.ПС), ОписаниеКнопок, КнопкиДиалога);
11615
+ КонецФункции
11616
+
11500
11617
  &НаКлиенте
11501
11618
  Функция ПроверитьСостояниеКлиентаПослеШага(ЗаголовокОкнаДоКоманды = "", ИмяФормыОкнаДоКоманды = "")
11502
11619
  Результат = Новый Структура;
@@ -3,7 +3,7 @@ from __future__ import annotations
3
3
  from dataclasses import dataclass
4
4
  from typing import Any
5
5
 
6
- MANAGER_PROTOCOL_VERSION = "2026.11.16.1"
6
+ MANAGER_PROTOCOL_VERSION = "2026.12.02.1"
7
7
 
8
8
 
9
9
  @dataclass(slots=True)
@@ -1422,7 +1422,7 @@ async def _idle_watch_session(session_id: str) -> None:
1422
1422
  if time.monotonic() - sess.last_activity_monotonic >= timeout:
1423
1423
  logging.info("Session %s idle for %ss; stopping", session_id, timeout)
1424
1424
  try:
1425
- await _stop_session_impl(session_id, clean_data=False)
1425
+ await _stop_session_impl(session_id, clean_data=False, force=True)
1426
1426
  except Exception as exc:
1427
1427
  logging.warning("idle stop_session failed for %s: %s", session_id, exc)
1428
1428
  return
@@ -6184,12 +6184,85 @@ async def _start_html_agent(sess: SessionState, mode: str = "") -> None:
6184
6184
  sess.html_agent = inspector
6185
6185
 
6186
6186
 
6187
- async def _stop_session_impl(session_id: str = DEFAULT_SESSION, clean_data: bool = False) -> dict[str, Any]:
6187
+ _STOP_CLOSE_TIMEOUT = float(os.getenv("ONEC_MCP_STOP_CLOSE_TIMEOUT", "30"))
6188
+ _STOP_EXIT_WAIT = float(os.getenv("ONEC_MCP_STOP_EXIT_WAIT", "15"))
6189
+
6190
+
6191
+ def _test_client_pid_for_stop(sess: SessionState) -> int:
6192
+ if sess.test_client_process is not None:
6193
+ return int(sess.test_client_process.pid)
6194
+ return int(sess.test_client_pid or 0)
6195
+
6196
+
6197
+ def _test_client_running(sess: SessionState) -> bool:
6198
+ if sess.test_client_process is not None:
6199
+ return sess.test_client_process.poll() is None
6200
+ return _pid_is_running(int(sess.test_client_pid or 0))
6201
+
6202
+
6203
+ async def _wait_test_client_exit(sess: SessionState, timeout: float) -> bool:
6204
+ deadline = time.monotonic() + max(0.0, timeout)
6205
+ while _test_client_running(sess):
6206
+ if time.monotonic() >= deadline:
6207
+ return False
6208
+ await asyncio.sleep(0.2)
6209
+ return True
6210
+
6211
+
6212
+ async def _close_test_client(sess: SessionState, force: bool) -> dict[str, Any]:
6213
+ """Ask the test client to exit through 1C itself (close its main window) and report how it ended.
6214
+
6215
+ `method` is one of: not_started, already_exited, graceful, graceful_after_exit_confirmation,
6216
+ killed_after_close_attempt (force and the client stayed alive), blocked (no force and the client is still
6217
+ running: `reason` says why, an unsaved-data question is passed to the agent in `dialog_*`).
6218
+ The process is never killed here; the caller kills it for forced stops.
6219
+ """
6220
+ pid = _test_client_pid_for_stop(sess)
6221
+ info: dict[str, Any] = {"client_pid": pid or None, "forced": bool(force)}
6222
+ if not pid:
6223
+ return {**info, "method": "not_started"}
6224
+ if not _test_client_running(sess):
6225
+ return {**info, "method": "already_exited"}
6226
+ try:
6227
+ close = await sess.bridge.call("close_test_client", {}, timeout=_STOP_CLOSE_TIMEOUT)
6228
+ if not isinstance(close, dict):
6229
+ close = {"attempted": True, "reason": "unexpected_response", "raw": close}
6230
+ except Exception as exc:
6231
+ close = {"attempted": False, "reason": "close_unavailable",
6232
+ "error": _compact_error_text(str(exc).strip()) or type(exc).__name__}
6233
+ reason = str(close.get("reason") or "")
6234
+ # An open question keeps the client alive, there is nothing to wait for.
6235
+ waits_for_exit = reason not in {"unsaved_changes", "unexpected_dialog", "not_connected", "no_window"}
6236
+ exited = await _wait_test_client_exit(sess, _STOP_EXIT_WAIT if waits_for_exit else 0.0)
6237
+ for key in ("window_title", "exit_confirmed", "clicked_button", "dialog_title", "dialog_text", "dialog_buttons", "error", "close_error"):
6238
+ if key in close:
6239
+ info[key] = close[key]
6240
+ info["close_reason"] = reason
6241
+ if exited:
6242
+ method = "graceful_after_exit_confirmation" if close.get("exit_confirmed") else "graceful"
6243
+ return {**info, "method": method}
6244
+ if force:
6245
+ return {**info, "method": "killed_after_close_attempt"}
6246
+ if reason == "unsaved_changes":
6247
+ info["hint"] = (
6248
+ "1C asks about unsaved data, the client is still running. Save or discard it via the UI "
6249
+ "(save_form, click_button) and call stop_session again, or call stop_session(force=true) to kill the client."
6250
+ )
6251
+ else:
6252
+ info["hint"] = "The client did not exit by itself; call stop_session(force=true) to kill it."
6253
+ return {**info, "method": "blocked", "reason": reason if reason == "unsaved_changes" else "client_still_running"}
6254
+
6255
+
6256
+ async def _stop_session_impl(session_id: str = DEFAULT_SESSION, clean_data: bool = False, force: bool = False) -> dict[str, Any]:
6188
6257
  try:
6189
6258
  sess = await _ensure_restored_session(session_id)
6190
- _SESSIONS.pop(session_id, None)
6191
6259
  except ValueError:
6192
6260
  return {"stopped": False, "reason": f"session {session_id!r} not found"}
6261
+ client_exit = await _close_test_client(sess, force)
6262
+ if client_exit["method"] == "blocked":
6263
+ return {"stopped": False, "session_id": session_id, "reason": client_exit["reason"], "client_exit": client_exit,
6264
+ "hint": client_exit.get("hint", "")}
6265
+ _SESSIONS.pop(session_id, None)
6193
6266
  stopped: list[str] = []
6194
6267
  if sess.html_agent is not None:
6195
6268
  await sess.html_agent.stop()
@@ -6242,16 +6315,24 @@ async def _stop_session_impl(session_id: str = DEFAULT_SESSION, clean_data: bool
6242
6315
  _trim_session_data_dir(sess.data_dir)
6243
6316
  stopped.append("data_dir_caches")
6244
6317
  _persist_sessions()
6245
- return {"stopped": True, "session_id": session_id, "components": stopped}
6318
+ return {"stopped": True, "session_id": session_id, "components": stopped, "client_exit": client_exit}
6246
6319
 
6247
6320
 
6248
6321
  @mcp.tool()
6249
6322
  async def stop_session(
6250
6323
  session_id: Annotated[str, "Session to tear down"] = DEFAULT_SESSION,
6251
6324
  clean_data: Annotated[bool, "Remove the session data directory"] = False,
6325
+ force: Annotated[bool, "Kill the test client if it does not exit by itself after the close attempt"] = False,
6252
6326
  ) -> dict[str, Any]:
6253
- """Tear down a session: disconnect test-client, stop test-manager, ibsrv, Xvfb and bridge."""
6254
- return await _stop_session_impl(session_id=session_id, clean_data=clean_data)
6327
+ """Tear down a session: close the test client through 1C, stop test-manager, ibsrv, Xvfb and bridge.
6328
+
6329
+ The client's main window is closed first and the «Завершить работу?» question is answered «Да». If 1C
6330
+ reports unsaved data (or the client does not exit), the session stays alive and the reply has
6331
+ `stopped: false` with `client_exit` (reason, dialog text and buttons); with `force: true` the client is
6332
+ killed after the close attempt. `client_exit.method` tells how the client ended: graceful,
6333
+ graceful_after_exit_confirmation, already_exited, not_started or killed_after_close_attempt.
6334
+ """
6335
+ return await _stop_session_impl(session_id=session_id, clean_data=clean_data, force=force)
6255
6336
 
6256
6337
 
6257
6338
  def launch_manager(
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes