flowent 0.0.1 → 0.0.4
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.
- package/README.md +19 -8
- package/backend/.python-version +1 -0
- package/backend/pyproject.toml +57 -0
- package/backend/src/flowent/__init__.py +3 -0
- package/backend/src/flowent/__pycache__/__init__.cpython-313.pyc +0 -0
- package/backend/src/flowent/__pycache__/_version.cpython-313.pyc +0 -0
- package/backend/src/flowent/__pycache__/access.cpython-313.pyc +0 -0
- package/backend/src/flowent/__pycache__/agent.cpython-313.pyc +0 -0
- package/backend/src/flowent/__pycache__/assistant_commands.cpython-313.pyc +0 -0
- package/backend/src/flowent/__pycache__/cli.cpython-313.pyc +0 -0
- package/backend/src/flowent/__pycache__/config.cpython-313.pyc +0 -0
- package/backend/src/flowent/__pycache__/events.cpython-313.pyc +0 -0
- package/backend/src/flowent/__pycache__/graph_runtime.cpython-313.pyc +0 -0
- package/backend/src/flowent/__pycache__/graph_service.cpython-313.pyc +0 -0
- package/backend/src/flowent/__pycache__/image_assets.cpython-313.pyc +0 -0
- package/backend/src/flowent/__pycache__/logging.cpython-313.pyc +0 -0
- package/backend/src/flowent/__pycache__/main.cpython-313.pyc +0 -0
- package/backend/src/flowent/__pycache__/mcp_service.cpython-313.pyc +0 -0
- package/backend/src/flowent/__pycache__/model_metadata.cpython-313.pyc +0 -0
- package/backend/src/flowent/__pycache__/network.cpython-313.pyc +0 -0
- package/backend/src/flowent/__pycache__/registry.cpython-313.pyc +0 -0
- package/backend/src/flowent/__pycache__/role_management.cpython-313.pyc +0 -0
- package/backend/src/flowent/__pycache__/runtime.cpython-313.pyc +0 -0
- package/backend/src/flowent/__pycache__/sandbox.cpython-313.pyc +0 -0
- package/backend/src/flowent/__pycache__/security.cpython-313.pyc +0 -0
- package/backend/src/flowent/__pycache__/settings.cpython-313.pyc +0 -0
- package/backend/src/flowent/__pycache__/settings_management.cpython-313.pyc +0 -0
- package/backend/src/flowent/__pycache__/state_db.cpython-313.pyc +0 -0
- package/backend/src/flowent/__pycache__/stats_service.cpython-313.pyc +0 -0
- package/backend/src/flowent/__pycache__/workspace_store.cpython-313.pyc +0 -0
- package/backend/src/flowent/_version.py +7 -0
- package/backend/src/flowent/access.py +247 -0
- package/backend/src/flowent/agent.py +2808 -0
- package/backend/src/flowent/assistant_commands.py +106 -0
- package/backend/src/flowent/channels/__init__.py +3 -0
- package/backend/src/flowent/channels/__pycache__/__init__.cpython-313.pyc +0 -0
- package/backend/src/flowent/channels/__pycache__/telegram.cpython-313.pyc +0 -0
- package/backend/src/flowent/channels/telegram.py +615 -0
- package/backend/src/flowent/cli.py +85 -0
- package/backend/src/flowent/config.py +14 -0
- package/backend/src/flowent/dev.py +3 -0
- package/backend/src/flowent/events.py +157 -0
- package/backend/src/flowent/graph_runtime.py +60 -0
- package/backend/src/flowent/graph_service.py +1346 -0
- package/backend/src/flowent/image_assets.py +356 -0
- package/backend/src/flowent/logging.py +155 -0
- package/backend/src/flowent/main.py +124 -0
- package/backend/src/flowent/mcp_service.py +1904 -0
- package/backend/src/flowent/model_metadata.py +98 -0
- package/backend/src/flowent/models/__init__.py +121 -0
- package/backend/src/flowent/models/__pycache__/__init__.cpython-313.pyc +0 -0
- package/backend/src/flowent/models/__pycache__/agent.cpython-313.pyc +0 -0
- package/backend/src/flowent/models/__pycache__/base.cpython-313.pyc +0 -0
- package/backend/src/flowent/models/__pycache__/blueprint.cpython-313.pyc +0 -0
- package/backend/src/flowent/models/__pycache__/content.cpython-313.pyc +0 -0
- package/backend/src/flowent/models/__pycache__/delta.cpython-313.pyc +0 -0
- package/backend/src/flowent/models/__pycache__/event.cpython-313.pyc +0 -0
- package/backend/src/flowent/models/__pycache__/graph.cpython-313.pyc +0 -0
- package/backend/src/flowent/models/__pycache__/history.cpython-313.pyc +0 -0
- package/backend/src/flowent/models/__pycache__/llm.cpython-313.pyc +0 -0
- package/backend/src/flowent/models/__pycache__/message.cpython-313.pyc +0 -0
- package/backend/src/flowent/models/__pycache__/tab.cpython-313.pyc +0 -0
- package/backend/src/flowent/models/__pycache__/todo.cpython-313.pyc +0 -0
- package/backend/src/flowent/models/agent.py +33 -0
- package/backend/src/flowent/models/base.py +24 -0
- package/backend/src/flowent/models/blueprint.py +176 -0
- package/backend/src/flowent/models/content.py +164 -0
- package/backend/src/flowent/models/delta.py +44 -0
- package/backend/src/flowent/models/event.py +51 -0
- package/backend/src/flowent/models/graph.py +437 -0
- package/backend/src/flowent/models/history.py +214 -0
- package/backend/src/flowent/models/llm.py +61 -0
- package/backend/src/flowent/models/message.py +27 -0
- package/backend/src/flowent/models/tab.py +48 -0
- package/backend/src/flowent/models/todo.py +10 -0
- package/backend/src/flowent/network.py +146 -0
- package/backend/src/flowent/prompts/__init__.py +67 -0
- package/backend/src/flowent/prompts/__pycache__/__init__.cpython-313.pyc +0 -0
- package/backend/src/flowent/prompts/__pycache__/common.cpython-313.pyc +0 -0
- package/backend/src/flowent/prompts/__pycache__/steward.cpython-313.pyc +0 -0
- package/backend/src/flowent/prompts/common.py +250 -0
- package/backend/src/flowent/prompts/steward.py +64 -0
- package/backend/src/flowent/providers/__init__.py +23 -0
- package/backend/src/flowent/providers/__pycache__/__init__.cpython-313.pyc +0 -0
- package/backend/src/flowent/providers/__pycache__/anthropic.cpython-313.pyc +0 -0
- package/backend/src/flowent/providers/__pycache__/base_url.cpython-313.pyc +0 -0
- package/backend/src/flowent/providers/__pycache__/configuration.cpython-313.pyc +0 -0
- package/backend/src/flowent/providers/__pycache__/content.cpython-313.pyc +0 -0
- package/backend/src/flowent/providers/__pycache__/errors.cpython-313.pyc +0 -0
- package/backend/src/flowent/providers/__pycache__/gateway.cpython-313.pyc +0 -0
- package/backend/src/flowent/providers/__pycache__/headers.cpython-313.pyc +0 -0
- package/backend/src/flowent/providers/__pycache__/management.cpython-313.pyc +0 -0
- package/backend/src/flowent/providers/__pycache__/openai.cpython-313.pyc +0 -0
- package/backend/src/flowent/providers/__pycache__/openai_responses.cpython-313.pyc +0 -0
- package/backend/src/flowent/providers/__pycache__/registry.cpython-313.pyc +0 -0
- package/backend/src/flowent/providers/__pycache__/sse.cpython-313.pyc +0 -0
- package/backend/src/flowent/providers/__pycache__/thinking.cpython-313.pyc +0 -0
- package/backend/src/flowent/providers/anthropic.py +468 -0
- package/backend/src/flowent/providers/base_url.py +60 -0
- package/backend/src/flowent/providers/configuration.py +182 -0
- package/backend/src/flowent/providers/content.py +122 -0
- package/backend/src/flowent/providers/errors.py +223 -0
- package/backend/src/flowent/providers/gateway.py +169 -0
- package/backend/src/flowent/providers/gemini.py +447 -0
- package/backend/src/flowent/providers/headers.py +20 -0
- package/backend/src/flowent/providers/management.py +96 -0
- package/backend/src/flowent/providers/ollama.py +293 -0
- package/backend/src/flowent/providers/openai.py +422 -0
- package/backend/src/flowent/providers/openai_responses.py +655 -0
- package/backend/src/flowent/providers/registry.py +144 -0
- package/backend/src/flowent/providers/sse.py +31 -0
- package/backend/src/flowent/providers/thinking.py +79 -0
- package/backend/src/flowent/registry.py +73 -0
- package/backend/src/flowent/role_management.py +255 -0
- package/backend/src/flowent/routes/__init__.py +30 -0
- package/backend/src/flowent/routes/__pycache__/__init__.cpython-313.pyc +0 -0
- package/backend/src/flowent/routes/__pycache__/access.cpython-313.pyc +0 -0
- package/backend/src/flowent/routes/__pycache__/assistant.cpython-313.pyc +0 -0
- package/backend/src/flowent/routes/__pycache__/image_assets.cpython-313.pyc +0 -0
- package/backend/src/flowent/routes/__pycache__/mcp.cpython-313.pyc +0 -0
- package/backend/src/flowent/routes/__pycache__/meta.cpython-313.pyc +0 -0
- package/backend/src/flowent/routes/__pycache__/nodes.cpython-313.pyc +0 -0
- package/backend/src/flowent/routes/__pycache__/prompts.cpython-313.pyc +0 -0
- package/backend/src/flowent/routes/__pycache__/providers_route.cpython-313.pyc +0 -0
- package/backend/src/flowent/routes/__pycache__/roles.cpython-313.pyc +0 -0
- package/backend/src/flowent/routes/__pycache__/settings.cpython-313.pyc +0 -0
- package/backend/src/flowent/routes/__pycache__/stats.cpython-313.pyc +0 -0
- package/backend/src/flowent/routes/__pycache__/tabs.cpython-313.pyc +0 -0
- package/backend/src/flowent/routes/__pycache__/ws.cpython-313.pyc +0 -0
- package/backend/src/flowent/routes/access.py +48 -0
- package/backend/src/flowent/routes/assistant.py +155 -0
- package/backend/src/flowent/routes/image_assets.py +33 -0
- package/backend/src/flowent/routes/mcp.py +125 -0
- package/backend/src/flowent/routes/meta.py +28 -0
- package/backend/src/flowent/routes/nodes.py +365 -0
- package/backend/src/flowent/routes/prompts.py +46 -0
- package/backend/src/flowent/routes/providers_route.py +364 -0
- package/backend/src/flowent/routes/roles.py +207 -0
- package/backend/src/flowent/routes/settings.py +324 -0
- package/backend/src/flowent/routes/stats.py +229 -0
- package/backend/src/flowent/routes/tabs.py +292 -0
- package/backend/src/flowent/routes/ws.py +33 -0
- package/backend/src/flowent/runtime.py +188 -0
- package/backend/src/flowent/sandbox.py +45 -0
- package/backend/src/flowent/security.py +42 -0
- package/backend/src/flowent/settings.py +2467 -0
- package/backend/src/flowent/settings_management.py +286 -0
- package/backend/src/flowent/state_db.py +120 -0
- package/backend/src/flowent/static/assets/AssistantPage-B3Xc08AS.js +1 -0
- package/backend/src/flowent/static/assets/ChannelsPage-ByLd28xk.js +1 -0
- package/backend/src/flowent/static/assets/HomePage-C0hAx9_l.js +3 -0
- package/backend/src/flowent/static/assets/McpPage-DkrYLvBv.js +7 -0
- package/backend/src/flowent/static/assets/PageScaffold-D4jO9ooX.js +1 -0
- package/backend/src/flowent/static/assets/PromptsPage-DWA7rRJd.js +1 -0
- package/backend/src/flowent/static/assets/ProvidersPage-PUWT8seJ.js +3 -0
- package/backend/src/flowent/static/assets/RolesPage-CqcclGRw.js +1 -0
- package/backend/src/flowent/static/assets/SettingsPage-8tS2cJgX.js +3 -0
- package/backend/src/flowent/static/assets/StatsPage-BX9khYzu.js +1 -0
- package/backend/src/flowent/static/assets/ToolsPage-9Tl9FdeD.js +1 -0
- package/backend/src/flowent/static/assets/WorkspaceCommandDialog-CCXxjDL8.js +1 -0
- package/backend/src/flowent/static/assets/WorkspacePanels-aMdJ7ZH7.js +1 -0
- package/backend/src/flowent/static/assets/alert-dialog-kFYVQ7oX.js +1 -0
- package/backend/src/flowent/static/assets/badge-74-3jsCg.js +1 -0
- package/backend/src/flowent/static/assets/constants-XUzFf6i1.js +1 -0
- package/backend/src/flowent/static/assets/datetime-m6_O_Ci9.js +1 -0
- package/backend/src/flowent/static/assets/dialog-BeGSweF6.js +1 -0
- package/backend/src/flowent/static/assets/elk-worker.min-C9JGDOE-.js +6312 -0
- package/backend/src/flowent/static/assets/graph-vendor-CHpVij2M.css +1 -0
- package/backend/src/flowent/static/assets/graph-vendor-DRq_-6fV.js +7 -0
- package/backend/src/flowent/static/assets/index-BHC1Vhy8.css +1 -0
- package/backend/src/flowent/static/assets/index-CL1ALZ3r.js +10 -0
- package/backend/src/flowent/static/assets/layout.worker-jMHqAFbP.js +24 -0
- package/backend/src/flowent/static/assets/markdown-vendor-DVdy_w12.js +29 -0
- package/backend/src/flowent/static/assets/modelParams-CaHd0903.js +1 -0
- package/backend/src/flowent/static/assets/react-vendor-mEs_JJxa.js +9 -0
- package/backend/src/flowent/static/assets/roles-2OLDeTc5.js +1 -0
- package/backend/src/flowent/static/assets/rolldown-runtime-BYbx6iT9.js +1 -0
- package/backend/src/flowent/static/assets/select-DL_LPeDj.js +1 -0
- package/backend/src/flowent/static/assets/shared-CMxbpLeQ.js +1 -0
- package/backend/src/flowent/static/assets/triState-DEr3NkXV.js +1 -0
- package/backend/src/flowent/static/assets/ui-vendor-Dg9NNnWX.js +51 -0
- package/backend/src/flowent/static/index.html +36 -0
- package/backend/src/flowent/stats_service.py +218 -0
- package/backend/src/flowent/tools/__init__.py +201 -0
- package/backend/src/flowent/tools/__pycache__/__init__.cpython-313.pyc +0 -0
- package/backend/src/flowent/tools/__pycache__/connect.cpython-313.pyc +0 -0
- package/backend/src/flowent/tools/__pycache__/contacts.cpython-313.pyc +0 -0
- package/backend/src/flowent/tools/__pycache__/create_agent.cpython-313.pyc +0 -0
- package/backend/src/flowent/tools/__pycache__/create_tab.cpython-313.pyc +0 -0
- package/backend/src/flowent/tools/__pycache__/delete_tab.cpython-313.pyc +0 -0
- package/backend/src/flowent/tools/__pycache__/edit.cpython-313.pyc +0 -0
- package/backend/src/flowent/tools/__pycache__/exec.cpython-313.pyc +0 -0
- package/backend/src/flowent/tools/__pycache__/fetch.cpython-313.pyc +0 -0
- package/backend/src/flowent/tools/__pycache__/idle.cpython-313.pyc +0 -0
- package/backend/src/flowent/tools/__pycache__/list_roles.cpython-313.pyc +0 -0
- package/backend/src/flowent/tools/__pycache__/list_tabs.cpython-313.pyc +0 -0
- package/backend/src/flowent/tools/__pycache__/list_tools.cpython-313.pyc +0 -0
- package/backend/src/flowent/tools/__pycache__/manage_prompts.cpython-313.pyc +0 -0
- package/backend/src/flowent/tools/__pycache__/manage_providers.cpython-313.pyc +0 -0
- package/backend/src/flowent/tools/__pycache__/manage_roles.cpython-313.pyc +0 -0
- package/backend/src/flowent/tools/__pycache__/manage_settings.cpython-313.pyc +0 -0
- package/backend/src/flowent/tools/__pycache__/mcp.cpython-313.pyc +0 -0
- package/backend/src/flowent/tools/__pycache__/read.cpython-313.pyc +0 -0
- package/backend/src/flowent/tools/__pycache__/send.cpython-313.pyc +0 -0
- package/backend/src/flowent/tools/__pycache__/set_permissions.cpython-313.pyc +0 -0
- package/backend/src/flowent/tools/__pycache__/sleep.cpython-313.pyc +0 -0
- package/backend/src/flowent/tools/__pycache__/todo.cpython-313.pyc +0 -0
- package/backend/src/flowent/tools/connect.py +156 -0
- package/backend/src/flowent/tools/contacts.py +22 -0
- package/backend/src/flowent/tools/create_agent.py +270 -0
- package/backend/src/flowent/tools/create_tab.py +59 -0
- package/backend/src/flowent/tools/delete_tab.py +39 -0
- package/backend/src/flowent/tools/edit.py +142 -0
- package/backend/src/flowent/tools/exec.py +117 -0
- package/backend/src/flowent/tools/fetch.py +85 -0
- package/backend/src/flowent/tools/idle.py +27 -0
- package/backend/src/flowent/tools/list_roles.py +50 -0
- package/backend/src/flowent/tools/list_tabs.py +96 -0
- package/backend/src/flowent/tools/list_tools.py +24 -0
- package/backend/src/flowent/tools/manage_prompts.py +102 -0
- package/backend/src/flowent/tools/manage_providers.py +220 -0
- package/backend/src/flowent/tools/manage_roles.py +275 -0
- package/backend/src/flowent/tools/manage_settings.py +346 -0
- package/backend/src/flowent/tools/mcp.py +199 -0
- package/backend/src/flowent/tools/read.py +152 -0
- package/backend/src/flowent/tools/send.py +50 -0
- package/backend/src/flowent/tools/set_permissions.py +84 -0
- package/backend/src/flowent/tools/sleep.py +41 -0
- package/backend/src/flowent/tools/todo.py +51 -0
- package/backend/src/flowent/workspace_store.py +479 -0
- package/backend/tests/__init__.py +0 -0
- package/backend/tests/__pycache__/__init__.cpython-313.pyc +0 -0
- package/backend/tests/__pycache__/conftest.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/conftest.py +6 -0
- package/backend/tests/integration/api/__pycache__/conftest.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/integration/api/__pycache__/test_access_api.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/integration/api/__pycache__/test_assistant_api.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/integration/api/__pycache__/test_frontend_mounting.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/integration/api/__pycache__/test_mcp_api.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/integration/api/__pycache__/test_meta_api.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/integration/api/__pycache__/test_nodes_api.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/integration/api/__pycache__/test_prompts_api.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/integration/api/__pycache__/test_roles_api.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/integration/api/__pycache__/test_tabs_api.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/integration/api/conftest.py +29 -0
- package/backend/tests/integration/api/test_access_api.py +182 -0
- package/backend/tests/integration/api/test_assistant_api.py +354 -0
- package/backend/tests/integration/api/test_frontend_mounting.py +61 -0
- package/backend/tests/integration/api/test_mcp_api.py +116 -0
- package/backend/tests/integration/api/test_meta_api.py +33 -0
- package/backend/tests/integration/api/test_nodes_api.py +486 -0
- package/backend/tests/integration/api/test_prompts_api.py +47 -0
- package/backend/tests/integration/api/test_roles_api.py +227 -0
- package/backend/tests/integration/api/test_tabs_api.py +501 -0
- package/backend/tests/unit/__pycache__/test_access.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/__pycache__/test_cli.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/__pycache__/test_graph_runtime.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/__pycache__/test_network.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/__pycache__/test_state_sqlite_storage.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/__pycache__/test_workspace_store.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/agent/__pycache__/test_agent_public_api.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/agent/__pycache__/test_agent_runtime.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/agent/test_agent_public_api.py +746 -0
- package/backend/tests/unit/agent/test_agent_runtime.py +2726 -0
- package/backend/tests/unit/channels/__pycache__/test_telegram_channel.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/channels/test_telegram_channel.py +552 -0
- package/backend/tests/unit/logging/__pycache__/test_logging.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/logging/test_logging.py +132 -0
- package/backend/tests/unit/prompts/__pycache__/test_prompts.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/prompts/test_prompts.py +569 -0
- package/backend/tests/unit/providers/__pycache__/test_anthropic_provider.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/providers/__pycache__/test_errors.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/providers/__pycache__/test_extract_delta_parts.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/providers/__pycache__/test_openai_provider.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/providers/__pycache__/test_openai_responses.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/providers/__pycache__/test_provider_gateway.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/providers/__pycache__/test_think_tag_parser.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/providers/test_anthropic_provider.py +185 -0
- package/backend/tests/unit/providers/test_errors.py +68 -0
- package/backend/tests/unit/providers/test_extract_delta_parts.py +22 -0
- package/backend/tests/unit/providers/test_openai_provider.py +139 -0
- package/backend/tests/unit/providers/test_openai_responses.py +402 -0
- package/backend/tests/unit/providers/test_provider_gateway.py +359 -0
- package/backend/tests/unit/providers/test_think_tag_parser.py +36 -0
- package/backend/tests/unit/routes/__pycache__/test_prompts_routes.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/routes/__pycache__/test_providers_route.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/routes/__pycache__/test_roles_routes.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/routes/__pycache__/test_settings_routes.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/routes/__pycache__/test_stats_routes.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/routes/test_prompts_routes.py +104 -0
- package/backend/tests/unit/routes/test_providers_route.py +368 -0
- package/backend/tests/unit/routes/test_roles_routes.py +426 -0
- package/backend/tests/unit/routes/test_settings_routes.py +1138 -0
- package/backend/tests/unit/routes/test_stats_routes.py +149 -0
- package/backend/tests/unit/runtime/__pycache__/test_bootstrap_runtime.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/runtime/test_bootstrap_runtime.py +1012 -0
- package/backend/tests/unit/sandbox/__pycache__/test_sandbox_tools.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/sandbox/test_sandbox_tools.py +78 -0
- package/backend/tests/unit/security/__pycache__/test_security.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/security/test_security.py +110 -0
- package/backend/tests/unit/settings/__pycache__/test_settings_roles.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/settings/test_settings_roles.py +711 -0
- package/backend/tests/unit/test_access.py +45 -0
- package/backend/tests/unit/test_cli.py +124 -0
- package/backend/tests/unit/test_graph_runtime.py +72 -0
- package/backend/tests/unit/test_network.py +51 -0
- package/backend/tests/unit/test_state_sqlite_storage.py +93 -0
- package/backend/tests/unit/test_workspace_store.py +231 -0
- package/backend/tests/unit/tools/__pycache__/test_connect_tool.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/tools/__pycache__/test_create_agent_tool.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/tools/__pycache__/test_delete_tab_tool.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/tools/__pycache__/test_edit_tool.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/tools/__pycache__/test_exec_tool.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/tools/__pycache__/test_fetch_tool.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/tools/__pycache__/test_manage_prompts_tool.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/tools/__pycache__/test_manage_providers_tool.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/tools/__pycache__/test_manage_roles_tool.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/tools/__pycache__/test_manage_settings_tool.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/tools/__pycache__/test_read_tool.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/tools/__pycache__/test_set_permissions_tool.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/tools/__pycache__/test_todo_tool.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/tools/__pycache__/test_tool_registry.cpython-313-pytest-9.0.3.pyc +0 -0
- package/backend/tests/unit/tools/test_connect_tool.py +229 -0
- package/backend/tests/unit/tools/test_create_agent_tool.py +524 -0
- package/backend/tests/unit/tools/test_delete_tab_tool.py +83 -0
- package/backend/tests/unit/tools/test_edit_tool.py +115 -0
- package/backend/tests/unit/tools/test_exec_tool.py +81 -0
- package/backend/tests/unit/tools/test_fetch_tool.py +65 -0
- package/backend/tests/unit/tools/test_manage_prompts_tool.py +117 -0
- package/backend/tests/unit/tools/test_manage_providers_tool.py +458 -0
- package/backend/tests/unit/tools/test_manage_roles_tool.py +411 -0
- package/backend/tests/unit/tools/test_manage_settings_tool.py +608 -0
- package/backend/tests/unit/tools/test_read_tool.py +33 -0
- package/backend/tests/unit/tools/test_set_permissions_tool.py +391 -0
- package/backend/tests/unit/tools/test_todo_tool.py +37 -0
- package/backend/tests/unit/tools/test_tool_registry.py +91 -0
- package/backend/uv.lock +1144 -0
- package/bin/flowent.mjs +62 -36
- package/dist/frontend/assets/AssistantPage-B3Xc08AS.js +1 -0
- package/dist/frontend/assets/ChannelsPage-ByLd28xk.js +1 -0
- package/dist/frontend/assets/HomePage-C0hAx9_l.js +3 -0
- package/dist/frontend/assets/McpPage-DkrYLvBv.js +7 -0
- package/dist/frontend/assets/PageScaffold-D4jO9ooX.js +1 -0
- package/dist/frontend/assets/PromptsPage-DWA7rRJd.js +1 -0
- package/dist/frontend/assets/ProvidersPage-PUWT8seJ.js +3 -0
- package/dist/frontend/assets/RolesPage-CqcclGRw.js +1 -0
- package/dist/frontend/assets/SettingsPage-8tS2cJgX.js +3 -0
- package/dist/frontend/assets/StatsPage-BX9khYzu.js +1 -0
- package/dist/frontend/assets/ToolsPage-9Tl9FdeD.js +1 -0
- package/dist/frontend/assets/WorkspaceCommandDialog-CCXxjDL8.js +1 -0
- package/dist/frontend/assets/WorkspacePanels-aMdJ7ZH7.js +1 -0
- package/dist/frontend/assets/alert-dialog-kFYVQ7oX.js +1 -0
- package/dist/frontend/assets/badge-74-3jsCg.js +1 -0
- package/dist/frontend/assets/constants-XUzFf6i1.js +1 -0
- package/dist/frontend/assets/datetime-m6_O_Ci9.js +1 -0
- package/dist/frontend/assets/dialog-BeGSweF6.js +1 -0
- package/dist/frontend/assets/elk-worker.min-C9JGDOE-.js +6312 -0
- package/dist/frontend/assets/graph-vendor-CHpVij2M.css +1 -0
- package/dist/frontend/assets/graph-vendor-DRq_-6fV.js +7 -0
- package/dist/frontend/assets/index-BHC1Vhy8.css +1 -0
- package/dist/frontend/assets/index-CL1ALZ3r.js +10 -0
- package/dist/frontend/assets/layout.worker-jMHqAFbP.js +24 -0
- package/dist/frontend/assets/markdown-vendor-DVdy_w12.js +29 -0
- package/dist/frontend/assets/modelParams-CaHd0903.js +1 -0
- package/dist/frontend/assets/react-vendor-mEs_JJxa.js +9 -0
- package/dist/frontend/assets/roles-2OLDeTc5.js +1 -0
- package/dist/frontend/assets/rolldown-runtime-BYbx6iT9.js +1 -0
- package/dist/frontend/assets/select-DL_LPeDj.js +1 -0
- package/dist/frontend/assets/shared-CMxbpLeQ.js +1 -0
- package/dist/frontend/assets/triState-DEr3NkXV.js +1 -0
- package/dist/frontend/assets/ui-vendor-Dg9NNnWX.js +51 -0
- package/dist/frontend/index.html +36 -0
- package/package.json +27 -41
- package/dist/.next/BUILD_ID +0 -1
- package/dist/.next/app-path-routes-manifest.json +0 -6
- package/dist/.next/build-manifest.json +0 -20
- package/dist/.next/package.json +0 -1
- package/dist/.next/prerender-manifest.json +0 -114
- package/dist/.next/required-server-files.json +0 -333
- package/dist/.next/routes-manifest.json +0 -69
- package/dist/.next/server/app/_global-error/page/app-paths-manifest.json +0 -3
- package/dist/.next/server/app/_global-error/page/build-manifest.json +0 -16
- package/dist/.next/server/app/_global-error/page/next-font-manifest.json +0 -6
- package/dist/.next/server/app/_global-error/page/react-loadable-manifest.json +0 -1
- package/dist/.next/server/app/_global-error/page/server-reference-manifest.json +0 -4
- package/dist/.next/server/app/_global-error/page.js +0 -9
- package/dist/.next/server/app/_global-error/page.js.map +0 -5
- package/dist/.next/server/app/_global-error/page.js.nft.json +0 -1
- package/dist/.next/server/app/_global-error/page_client-reference-manifest.js +0 -3
- package/dist/.next/server/app/_global-error.html +0 -1
- package/dist/.next/server/app/_global-error.meta +0 -15
- package/dist/.next/server/app/_global-error.rsc +0 -14
- package/dist/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +0 -5
- package/dist/.next/server/app/_global-error.segments/_full.segment.rsc +0 -14
- package/dist/.next/server/app/_global-error.segments/_head.segment.rsc +0 -5
- package/dist/.next/server/app/_global-error.segments/_index.segment.rsc +0 -5
- package/dist/.next/server/app/_global-error.segments/_tree.segment.rsc +0 -1
- package/dist/.next/server/app/_not-found/page/app-paths-manifest.json +0 -3
- package/dist/.next/server/app/_not-found/page/build-manifest.json +0 -16
- package/dist/.next/server/app/_not-found/page/next-font-manifest.json +0 -10
- package/dist/.next/server/app/_not-found/page/react-loadable-manifest.json +0 -1
- package/dist/.next/server/app/_not-found/page/server-reference-manifest.json +0 -4
- package/dist/.next/server/app/_not-found/page.js +0 -13
- package/dist/.next/server/app/_not-found/page.js.map +0 -5
- package/dist/.next/server/app/_not-found/page.js.nft.json +0 -1
- package/dist/.next/server/app/_not-found/page_client-reference-manifest.js +0 -3
- package/dist/.next/server/app/_not-found.html +0 -1
- package/dist/.next/server/app/_not-found.meta +0 -16
- package/dist/.next/server/app/_not-found.rsc +0 -16
- package/dist/.next/server/app/_not-found.segments/_full.segment.rsc +0 -16
- package/dist/.next/server/app/_not-found.segments/_head.segment.rsc +0 -6
- package/dist/.next/server/app/_not-found.segments/_index.segment.rsc +0 -5
- package/dist/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +0 -5
- package/dist/.next/server/app/_not-found.segments/_not-found.segment.rsc +0 -5
- package/dist/.next/server/app/_not-found.segments/_tree.segment.rsc +0 -2
- package/dist/.next/server/app/icon.svg/route/app-paths-manifest.json +0 -3
- package/dist/.next/server/app/icon.svg/route/build-manifest.json +0 -9
- package/dist/.next/server/app/icon.svg/route.js +0 -6
- package/dist/.next/server/app/icon.svg/route.js.map +0 -5
- package/dist/.next/server/app/icon.svg/route.js.nft.json +0 -1
- package/dist/.next/server/app/icon.svg.meta +0 -1
- package/dist/.next/server/app/index.html +0 -1
- package/dist/.next/server/app/index.meta +0 -14
- package/dist/.next/server/app/index.rsc +0 -15
- package/dist/.next/server/app/index.segments/__PAGE__.segment.rsc +0 -5
- package/dist/.next/server/app/index.segments/_full.segment.rsc +0 -15
- package/dist/.next/server/app/index.segments/_head.segment.rsc +0 -6
- package/dist/.next/server/app/index.segments/_index.segment.rsc +0 -5
- package/dist/.next/server/app/index.segments/_tree.segment.rsc +0 -3
- package/dist/.next/server/app/page/app-paths-manifest.json +0 -3
- package/dist/.next/server/app/page/build-manifest.json +0 -16
- package/dist/.next/server/app/page/next-font-manifest.json +0 -10
- package/dist/.next/server/app/page/react-loadable-manifest.json +0 -1
- package/dist/.next/server/app/page/server-reference-manifest.json +0 -4
- package/dist/.next/server/app/page.js +0 -14
- package/dist/.next/server/app/page.js.map +0 -5
- package/dist/.next/server/app/page.js.nft.json +0 -1
- package/dist/.next/server/app/page_client-reference-manifest.js +0 -3
- package/dist/.next/server/app-paths-manifest.json +0 -6
- package/dist/.next/server/chunks/[externals]_next_dist_0arv.vj._.js +0 -3
- package/dist/.next/server/chunks/[root-of-the-server]__0vcj1q1._.js +0 -13
- package/dist/.next/server/chunks/[turbopack]_runtime.js +0 -903
- package/dist/.next/server/chunks/_next-internal_server_app_icon_svg_route_actions_0-0ehc~.js +0 -3
- package/dist/.next/server/chunks/ssr/05w9_next_dist_0ihu0u9._.js +0 -6
- package/dist/.next/server/chunks/ssr/05w9_next_dist_client_components_12u3mib._.js +0 -3
- package/dist/.next/server/chunks/ssr/05w9_next_dist_client_components_builtin_forbidden_04fbe_..js +0 -3
- package/dist/.next/server/chunks/ssr/05w9_next_dist_client_components_builtin_global-error_0brpl_..js +0 -3
- package/dist/.next/server/chunks/ssr/05w9_next_dist_client_components_builtin_unauthorized_0~2g66g.js +0 -3
- package/dist/.next/server/chunks/ssr/05w9_next_dist_esm_build_templates_app-page_0~cyr1_.js +0 -4
- package/dist/.next/server/chunks/ssr/05w9_next_dist_esm_build_templates_app-page_1105emf.js +0 -4
- package/dist/.next/server/chunks/ssr/05w9_next_dist_esm_build_templates_app-page_11uhyqv.js +0 -4
- package/dist/.next/server/chunks/ssr/[root-of-the-server]__0.t9_75._.js +0 -33
- package/dist/.next/server/chunks/ssr/[root-of-the-server]__0c0ud_z._.js +0 -3
- package/dist/.next/server/chunks/ssr/[root-of-the-server]__0f9_8d4._.js +0 -3
- package/dist/.next/server/chunks/ssr/[root-of-the-server]__0l5ko41._.js +0 -19
- package/dist/.next/server/chunks/ssr/[root-of-the-server]__0mn6z7i._.js +0 -3
- package/dist/.next/server/chunks/ssr/[root-of-the-server]__0npxxst._.js +0 -33
- package/dist/.next/server/chunks/ssr/[root-of-the-server]__0qjhaca._.js +0 -3
- package/dist/.next/server/chunks/ssr/[root-of-the-server]__0rwgw3s._.js +0 -3
- package/dist/.next/server/chunks/ssr/[turbopack]_runtime.js +0 -903
- package/dist/.next/server/chunks/ssr/_next-internal_server_app__global-error_page_actions_0k77kol.js +0 -3
- package/dist/.next/server/chunks/ssr/_next-internal_server_app__not-found_page_actions_0eq97pa.js +0 -3
- package/dist/.next/server/chunks/ssr/_next-internal_server_app_page_actions_09-gtaw.js +0 -3
- package/dist/.next/server/chunks/ssr/node_modules__pnpm_056~6.6._.js +0 -3
- package/dist/.next/server/chunks/ssr/node_modules__pnpm_0~j0k.e._.js +0 -33
- package/dist/.next/server/functions-config-manifest.json +0 -4
- package/dist/.next/server/middleware-build-manifest.js +0 -20
- package/dist/.next/server/middleware-manifest.json +0 -6
- package/dist/.next/server/next-font-manifest.js +0 -1
- package/dist/.next/server/next-font-manifest.json +0 -13
- package/dist/.next/server/pages/404.html +0 -1
- package/dist/.next/server/pages/500.html +0 -1
- package/dist/.next/server/pages-manifest.json +0 -4
- package/dist/.next/server/prefetch-hints.json +0 -1
- package/dist/.next/server/server-reference-manifest.js +0 -1
- package/dist/.next/server/server-reference-manifest.json +0 -5
- package/dist/.next/static/SMWpxFVvkpYFxY7uuFvGB/_buildManifest.js +0 -11
- package/dist/.next/static/SMWpxFVvkpYFxY7uuFvGB/_clientMiddlewareManifest.js +0 -1
- package/dist/.next/static/SMWpxFVvkpYFxY7uuFvGB/_ssgManifest.js +0 -1
- package/dist/.next/static/chunks/01qk2~bgf76vu.js +0 -1
- package/dist/.next/static/chunks/03~yq9q893hmn.js +0 -1
- package/dist/.next/static/chunks/080queev.r2uy.js +0 -31
- package/dist/.next/static/chunks/0v3lyuj75aq50.js +0 -1
- package/dist/.next/static/chunks/10b~xdx5c-i7s.js +0 -5
- package/dist/.next/static/chunks/14gla2ascffgv.css +0 -2
- package/dist/.next/static/chunks/turbopack-0m-970~qvs7sc.js +0 -1
- package/dist/.next/static/media/7178b3e590c64307-s.11.cyxs5p-0z~.woff2 +0 -0
- package/dist/.next/static/media/8a480f0b521d4e75-s.06d3mdzz5bre_.woff2 +0 -0
- package/dist/.next/static/media/caa3a2e1cccd8315-s.p.16t1db8_9y2o~.woff2 +0 -0
- package/dist/package.json +0 -88
- package/dist/server.js +0 -38
- /package/{dist/.next/server/app/icon.svg.body → backend/src/flowent/static/favicon.svg} +0 -0
- /package/dist/{.next/static/media/icon.0.r~afrtrocz9.svg → frontend/favicon.svg} +0 -0
package/backend/tests/unit/channels/__pycache__/test_telegram_channel.cpython-313-pytest-9.0.3.pyc
ADDED
|
Binary file
|
|
@@ -0,0 +1,552 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from flowent.channels.telegram import (
|
|
6
|
+
IMAGE_INPUT_UNSUPPORTED_MESSAGE,
|
|
7
|
+
IMAGE_OUTPUT_UNSUPPORTED_MESSAGE,
|
|
8
|
+
PRIVATE_ONLY_MESSAGE,
|
|
9
|
+
TelegramChannel,
|
|
10
|
+
)
|
|
11
|
+
from flowent.models import Event, EventType
|
|
12
|
+
from flowent.settings import (
|
|
13
|
+
Settings,
|
|
14
|
+
TelegramApprovedChat,
|
|
15
|
+
TelegramPendingChat,
|
|
16
|
+
TelegramSettings,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class DummyAssistant:
|
|
21
|
+
def __init__(self) -> None:
|
|
22
|
+
self.uuid = "assistant-1"
|
|
23
|
+
self.messages: list[object] = []
|
|
24
|
+
|
|
25
|
+
def enqueue_message(self, message) -> None:
|
|
26
|
+
self.messages.append(message)
|
|
27
|
+
|
|
28
|
+
def supports_input_image(self) -> bool:
|
|
29
|
+
return True
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class _FakeTelegramResponse:
|
|
33
|
+
def __init__(self, status_code: int, payload: dict[str, object]) -> None:
|
|
34
|
+
self.status_code = status_code
|
|
35
|
+
self._payload = payload
|
|
36
|
+
|
|
37
|
+
def json(self) -> dict[str, object]:
|
|
38
|
+
return self._payload
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class _FakeAsyncSession:
|
|
42
|
+
def __init__(self, response: _FakeTelegramResponse) -> None:
|
|
43
|
+
self._response = response
|
|
44
|
+
self.requests: list[tuple[str, dict[str, object]]] = []
|
|
45
|
+
|
|
46
|
+
async def __aenter__(self) -> "_FakeAsyncSession":
|
|
47
|
+
return self
|
|
48
|
+
|
|
49
|
+
async def __aexit__(self, exc_type, exc, tb) -> bool:
|
|
50
|
+
return False
|
|
51
|
+
|
|
52
|
+
async def post(self, url: str, data: dict[str, object]):
|
|
53
|
+
self.requests.append((url, data))
|
|
54
|
+
return self._response
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def test_telegram_channel_replies_with_private_only_message_for_group_chat(
|
|
58
|
+
monkeypatch,
|
|
59
|
+
):
|
|
60
|
+
settings = Settings(telegram=TelegramSettings(bot_token="123456:ABCDE"))
|
|
61
|
+
sent_messages: list[tuple[int, str, bool]] = []
|
|
62
|
+
|
|
63
|
+
monkeypatch.setattr("flowent.channels.telegram.get_settings", lambda: settings)
|
|
64
|
+
|
|
65
|
+
channel = TelegramChannel()
|
|
66
|
+
|
|
67
|
+
async def fake_send_message(chat_id: int, text: str, *, markdown: bool) -> int:
|
|
68
|
+
sent_messages.append((chat_id, text, markdown))
|
|
69
|
+
return 1
|
|
70
|
+
|
|
71
|
+
monkeypatch.setattr(channel, "_send_message", fake_send_message)
|
|
72
|
+
|
|
73
|
+
asyncio.run(
|
|
74
|
+
channel._process_update(
|
|
75
|
+
{
|
|
76
|
+
"message": {
|
|
77
|
+
"from": {"id": 2002},
|
|
78
|
+
"chat": {"id": -3003, "type": "group"},
|
|
79
|
+
"text": "hello",
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
)
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
assert sent_messages == [(-3003, PRIVATE_ONLY_MESSAGE, False)]
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def test_telegram_channel_tracks_pending_private_chat_and_replies_with_chat_id(
|
|
89
|
+
monkeypatch,
|
|
90
|
+
):
|
|
91
|
+
settings = Settings(telegram=TelegramSettings(bot_token="123456:ABCDE"))
|
|
92
|
+
saved: list[Settings] = []
|
|
93
|
+
sent_messages: list[tuple[int, str, bool]] = []
|
|
94
|
+
|
|
95
|
+
monkeypatch.setattr("flowent.channels.telegram.get_settings", lambda: settings)
|
|
96
|
+
monkeypatch.setattr(
|
|
97
|
+
"flowent.channels.telegram.save_settings",
|
|
98
|
+
lambda current: saved.append(current),
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
channel = TelegramChannel()
|
|
102
|
+
|
|
103
|
+
async def fake_send_message(chat_id: int, text: str, *, markdown: bool) -> int:
|
|
104
|
+
sent_messages.append((chat_id, text, markdown))
|
|
105
|
+
return 1
|
|
106
|
+
|
|
107
|
+
monkeypatch.setattr(channel, "_send_message", fake_send_message)
|
|
108
|
+
|
|
109
|
+
asyncio.run(
|
|
110
|
+
channel._process_update(
|
|
111
|
+
{
|
|
112
|
+
"message": {
|
|
113
|
+
"from": {
|
|
114
|
+
"id": 2002,
|
|
115
|
+
"username": "alice",
|
|
116
|
+
"first_name": "Alice",
|
|
117
|
+
},
|
|
118
|
+
"chat": {"id": 3003, "type": "private"},
|
|
119
|
+
"text": "hello",
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
)
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
assert len(saved) == 1
|
|
126
|
+
assert settings.telegram.pending_chats == [
|
|
127
|
+
TelegramPendingChat(
|
|
128
|
+
chat_id=3003,
|
|
129
|
+
username="alice",
|
|
130
|
+
display_name="Alice",
|
|
131
|
+
first_seen_at=settings.telegram.pending_chats[0].first_seen_at,
|
|
132
|
+
last_seen_at=settings.telegram.pending_chats[0].last_seen_at,
|
|
133
|
+
)
|
|
134
|
+
]
|
|
135
|
+
assert sent_messages == [
|
|
136
|
+
(
|
|
137
|
+
3003,
|
|
138
|
+
"⏳ This chat is pending approval in Flowent.\nChat ID: `3003`",
|
|
139
|
+
True,
|
|
140
|
+
)
|
|
141
|
+
]
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def test_telegram_channel_delivers_messages_from_approved_private_chat(monkeypatch):
|
|
145
|
+
settings = Settings(
|
|
146
|
+
telegram=TelegramSettings(
|
|
147
|
+
bot_token="123456:ABCDE",
|
|
148
|
+
approved_chats=[
|
|
149
|
+
TelegramApprovedChat(
|
|
150
|
+
chat_id=4004,
|
|
151
|
+
username="alice",
|
|
152
|
+
display_name="Alice",
|
|
153
|
+
approved_at=1.0,
|
|
154
|
+
)
|
|
155
|
+
],
|
|
156
|
+
)
|
|
157
|
+
)
|
|
158
|
+
assistant = DummyAssistant()
|
|
159
|
+
|
|
160
|
+
monkeypatch.setattr("flowent.channels.telegram.get_settings", lambda: settings)
|
|
161
|
+
monkeypatch.setattr(
|
|
162
|
+
"flowent.channels.telegram.registry.get_assistant",
|
|
163
|
+
lambda: assistant,
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
channel = TelegramChannel()
|
|
167
|
+
|
|
168
|
+
asyncio.run(
|
|
169
|
+
channel._process_update(
|
|
170
|
+
{
|
|
171
|
+
"message": {
|
|
172
|
+
"from": {"id": 1001},
|
|
173
|
+
"chat": {"id": 4004, "type": "private"},
|
|
174
|
+
"text": "check status",
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
)
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
assert len(assistant.messages) == 1
|
|
181
|
+
assert assistant.messages[0].from_id == "human"
|
|
182
|
+
assert assistant.messages[0].to_id == assistant.uuid
|
|
183
|
+
assert assistant.messages[0].content == "check status"
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def test_telegram_channel_rejects_image_input_from_approved_private_chat(monkeypatch):
|
|
187
|
+
settings = Settings(
|
|
188
|
+
telegram=TelegramSettings(
|
|
189
|
+
bot_token="123456:ABCDE",
|
|
190
|
+
approved_chats=[
|
|
191
|
+
TelegramApprovedChat(
|
|
192
|
+
chat_id=4004,
|
|
193
|
+
username="alice",
|
|
194
|
+
display_name="Alice",
|
|
195
|
+
approved_at=1.0,
|
|
196
|
+
)
|
|
197
|
+
],
|
|
198
|
+
)
|
|
199
|
+
)
|
|
200
|
+
assistant = DummyAssistant()
|
|
201
|
+
sent_messages: list[tuple[int, str, bool]] = []
|
|
202
|
+
|
|
203
|
+
monkeypatch.setattr("flowent.channels.telegram.get_settings", lambda: settings)
|
|
204
|
+
monkeypatch.setattr(
|
|
205
|
+
"flowent.channels.telegram.registry.get_assistant",
|
|
206
|
+
lambda: assistant,
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
channel = TelegramChannel()
|
|
210
|
+
|
|
211
|
+
async def fake_send_message(chat_id: int, text: str, *, markdown: bool) -> int:
|
|
212
|
+
sent_messages.append((chat_id, text, markdown))
|
|
213
|
+
return 1
|
|
214
|
+
|
|
215
|
+
monkeypatch.setattr(channel, "_send_message", fake_send_message)
|
|
216
|
+
|
|
217
|
+
asyncio.run(
|
|
218
|
+
channel._process_update(
|
|
219
|
+
{
|
|
220
|
+
"message": {
|
|
221
|
+
"from": {"id": 1001},
|
|
222
|
+
"chat": {"id": 4004, "type": "private"},
|
|
223
|
+
"caption": "look at this",
|
|
224
|
+
"photo": [{"file_id": "photo-1"}],
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
)
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
assert assistant.messages == []
|
|
231
|
+
assert sent_messages == [(4004, IMAGE_INPUT_UNSUPPORTED_MESSAGE, False)]
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def test_telegram_channel_sends_typing_while_running_before_first_visible_text(
|
|
235
|
+
monkeypatch,
|
|
236
|
+
):
|
|
237
|
+
settings = Settings(
|
|
238
|
+
telegram=TelegramSettings(
|
|
239
|
+
bot_token="123456:ABCDE",
|
|
240
|
+
approved_chats=[
|
|
241
|
+
TelegramApprovedChat(
|
|
242
|
+
chat_id=4004,
|
|
243
|
+
username="alice",
|
|
244
|
+
display_name="Alice",
|
|
245
|
+
approved_at=1.0,
|
|
246
|
+
)
|
|
247
|
+
],
|
|
248
|
+
)
|
|
249
|
+
)
|
|
250
|
+
assistant = DummyAssistant()
|
|
251
|
+
sent_actions: list[tuple[int, str]] = []
|
|
252
|
+
|
|
253
|
+
monkeypatch.setattr("flowent.channels.telegram.get_settings", lambda: settings)
|
|
254
|
+
monkeypatch.setattr(
|
|
255
|
+
"flowent.channels.telegram.registry.get_assistant",
|
|
256
|
+
lambda: assistant,
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
channel = TelegramChannel()
|
|
260
|
+
|
|
261
|
+
async def fake_send_chat_action(chat_id: int, *, action: str) -> None:
|
|
262
|
+
sent_actions.append((chat_id, action))
|
|
263
|
+
|
|
264
|
+
async def fake_sleep(_: float) -> None:
|
|
265
|
+
channel._assistant_running = False
|
|
266
|
+
|
|
267
|
+
monkeypatch.setattr(channel, "_send_chat_action", fake_send_chat_action)
|
|
268
|
+
monkeypatch.setattr("flowent.channels.telegram.asyncio.sleep", fake_sleep)
|
|
269
|
+
|
|
270
|
+
async def run_test() -> None:
|
|
271
|
+
await channel._process_event(
|
|
272
|
+
Event(
|
|
273
|
+
type=EventType.NODE_STATE_CHANGED,
|
|
274
|
+
agent_id=assistant.uuid,
|
|
275
|
+
data={"new_state": "running"},
|
|
276
|
+
)
|
|
277
|
+
)
|
|
278
|
+
assert channel._typing_task is not None
|
|
279
|
+
await channel._typing_task
|
|
280
|
+
|
|
281
|
+
asyncio.run(run_test())
|
|
282
|
+
|
|
283
|
+
assert sent_actions == [(4004, "typing")]
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
def test_telegram_channel_stops_typing_after_first_visible_text(monkeypatch):
|
|
287
|
+
settings = Settings(
|
|
288
|
+
telegram=TelegramSettings(
|
|
289
|
+
bot_token="123456:ABCDE",
|
|
290
|
+
approved_chats=[
|
|
291
|
+
TelegramApprovedChat(
|
|
292
|
+
chat_id=4004,
|
|
293
|
+
username="alice",
|
|
294
|
+
display_name="Alice",
|
|
295
|
+
approved_at=1.0,
|
|
296
|
+
)
|
|
297
|
+
],
|
|
298
|
+
)
|
|
299
|
+
)
|
|
300
|
+
sent_messages: list[tuple[int, str, bool]] = []
|
|
301
|
+
sent_actions: list[tuple[int, str]] = []
|
|
302
|
+
|
|
303
|
+
monkeypatch.setattr("flowent.channels.telegram.get_settings", lambda: settings)
|
|
304
|
+
|
|
305
|
+
channel = TelegramChannel()
|
|
306
|
+
|
|
307
|
+
async def fake_send_message(chat_id: int, text: str, *, markdown: bool) -> int:
|
|
308
|
+
sent_messages.append((chat_id, text, markdown))
|
|
309
|
+
return 7
|
|
310
|
+
|
|
311
|
+
async def fake_send_chat_action(chat_id: int, *, action: str) -> None:
|
|
312
|
+
sent_actions.append((chat_id, action))
|
|
313
|
+
|
|
314
|
+
monkeypatch.setattr(channel, "_send_message", fake_send_message)
|
|
315
|
+
monkeypatch.setattr(channel, "_send_chat_action", fake_send_chat_action)
|
|
316
|
+
|
|
317
|
+
async def run_test() -> None:
|
|
318
|
+
channel._assistant_running = True
|
|
319
|
+
await channel._handle_assistant_content("hello")
|
|
320
|
+
await channel._send_typing_feedback_once()
|
|
321
|
+
|
|
322
|
+
asyncio.run(run_test())
|
|
323
|
+
|
|
324
|
+
assert sent_messages == [(4004, "hello", False)]
|
|
325
|
+
assert sent_actions == []
|
|
326
|
+
assert channel._stream_message_ids == {4004: 7}
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
def test_telegram_channel_sends_explicit_notice_for_image_output(monkeypatch):
|
|
330
|
+
settings = Settings(
|
|
331
|
+
telegram=TelegramSettings(
|
|
332
|
+
bot_token="123456:ABCDE",
|
|
333
|
+
approved_chats=[
|
|
334
|
+
TelegramApprovedChat(
|
|
335
|
+
chat_id=4004,
|
|
336
|
+
username="alice",
|
|
337
|
+
display_name="Alice",
|
|
338
|
+
approved_at=1.0,
|
|
339
|
+
)
|
|
340
|
+
],
|
|
341
|
+
)
|
|
342
|
+
)
|
|
343
|
+
assistant = DummyAssistant()
|
|
344
|
+
sent_messages: list[tuple[int, str, bool]] = []
|
|
345
|
+
|
|
346
|
+
monkeypatch.setattr("flowent.channels.telegram.get_settings", lambda: settings)
|
|
347
|
+
monkeypatch.setattr(
|
|
348
|
+
"flowent.channels.telegram.registry.get_assistant",
|
|
349
|
+
lambda: assistant,
|
|
350
|
+
)
|
|
351
|
+
|
|
352
|
+
channel = TelegramChannel()
|
|
353
|
+
|
|
354
|
+
async def fake_send_message(chat_id: int, text: str, *, markdown: bool) -> int:
|
|
355
|
+
sent_messages.append((chat_id, text, markdown))
|
|
356
|
+
return 1
|
|
357
|
+
|
|
358
|
+
monkeypatch.setattr(channel, "_send_message", fake_send_message)
|
|
359
|
+
|
|
360
|
+
asyncio.run(
|
|
361
|
+
channel._process_event(
|
|
362
|
+
Event(
|
|
363
|
+
type=EventType.HISTORY_ENTRY_ADDED,
|
|
364
|
+
agent_id=assistant.uuid,
|
|
365
|
+
data={
|
|
366
|
+
"type": "AssistantText",
|
|
367
|
+
"parts": [{"type": "image", "asset_id": "asset-1"}],
|
|
368
|
+
},
|
|
369
|
+
)
|
|
370
|
+
)
|
|
371
|
+
)
|
|
372
|
+
|
|
373
|
+
assert sent_messages == [(4004, IMAGE_OUTPUT_UNSUPPORTED_MESSAGE, False)]
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
def test_telegram_channel_ignores_tool_progress_events(monkeypatch):
|
|
377
|
+
settings = Settings(
|
|
378
|
+
telegram=TelegramSettings(
|
|
379
|
+
bot_token="123456:ABCDE",
|
|
380
|
+
approved_chats=[
|
|
381
|
+
TelegramApprovedChat(
|
|
382
|
+
chat_id=4004,
|
|
383
|
+
username="alice",
|
|
384
|
+
display_name="Alice",
|
|
385
|
+
approved_at=1.0,
|
|
386
|
+
)
|
|
387
|
+
],
|
|
388
|
+
)
|
|
389
|
+
)
|
|
390
|
+
assistant = DummyAssistant()
|
|
391
|
+
broadcast_messages: list[str] = []
|
|
392
|
+
|
|
393
|
+
monkeypatch.setattr("flowent.channels.telegram.get_settings", lambda: settings)
|
|
394
|
+
monkeypatch.setattr(
|
|
395
|
+
"flowent.channels.telegram.registry.get_assistant",
|
|
396
|
+
lambda: assistant,
|
|
397
|
+
)
|
|
398
|
+
|
|
399
|
+
channel = TelegramChannel()
|
|
400
|
+
|
|
401
|
+
async def fake_send_message(chat_id: int, text: str, *, markdown: bool) -> int:
|
|
402
|
+
broadcast_messages.append(text)
|
|
403
|
+
return 1
|
|
404
|
+
|
|
405
|
+
monkeypatch.setattr(channel, "_send_message", fake_send_message)
|
|
406
|
+
|
|
407
|
+
asyncio.run(
|
|
408
|
+
channel._process_event(
|
|
409
|
+
Event(
|
|
410
|
+
type=EventType.TOOL_CALLED,
|
|
411
|
+
agent_id=assistant.uuid,
|
|
412
|
+
data={"tool": "read"},
|
|
413
|
+
)
|
|
414
|
+
)
|
|
415
|
+
)
|
|
416
|
+
|
|
417
|
+
assert broadcast_messages == []
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
@pytest.mark.parametrize("end_state", ["idle", "error", "terminated"])
|
|
421
|
+
def test_telegram_channel_stops_without_placeholder_when_running_ends_no_content(
|
|
422
|
+
monkeypatch,
|
|
423
|
+
end_state,
|
|
424
|
+
):
|
|
425
|
+
settings = Settings(
|
|
426
|
+
telegram=TelegramSettings(
|
|
427
|
+
bot_token="123456:ABCDE",
|
|
428
|
+
approved_chats=[
|
|
429
|
+
TelegramApprovedChat(
|
|
430
|
+
chat_id=4004,
|
|
431
|
+
username="alice",
|
|
432
|
+
display_name="Alice",
|
|
433
|
+
approved_at=1.0,
|
|
434
|
+
)
|
|
435
|
+
],
|
|
436
|
+
)
|
|
437
|
+
)
|
|
438
|
+
assistant = DummyAssistant()
|
|
439
|
+
sent_messages: list[tuple[int, str, bool]] = []
|
|
440
|
+
sent_actions: list[tuple[int, str]] = []
|
|
441
|
+
|
|
442
|
+
monkeypatch.setattr("flowent.channels.telegram.get_settings", lambda: settings)
|
|
443
|
+
monkeypatch.setattr(
|
|
444
|
+
"flowent.channels.telegram.registry.get_assistant",
|
|
445
|
+
lambda: assistant,
|
|
446
|
+
)
|
|
447
|
+
|
|
448
|
+
channel = TelegramChannel()
|
|
449
|
+
|
|
450
|
+
async def fake_send_message(chat_id: int, text: str, *, markdown: bool) -> int:
|
|
451
|
+
sent_messages.append((chat_id, text, markdown))
|
|
452
|
+
return 1
|
|
453
|
+
|
|
454
|
+
async def fake_send_chat_action(chat_id: int, *, action: str) -> None:
|
|
455
|
+
sent_actions.append((chat_id, action))
|
|
456
|
+
|
|
457
|
+
async def fake_sleep(_: float) -> None:
|
|
458
|
+
await channel._process_event(
|
|
459
|
+
Event(
|
|
460
|
+
type=EventType.NODE_STATE_CHANGED,
|
|
461
|
+
agent_id=assistant.uuid,
|
|
462
|
+
data={"new_state": end_state},
|
|
463
|
+
)
|
|
464
|
+
)
|
|
465
|
+
|
|
466
|
+
monkeypatch.setattr(channel, "_send_message", fake_send_message)
|
|
467
|
+
monkeypatch.setattr(channel, "_send_chat_action", fake_send_chat_action)
|
|
468
|
+
monkeypatch.setattr("flowent.channels.telegram.asyncio.sleep", fake_sleep)
|
|
469
|
+
|
|
470
|
+
async def run_test() -> None:
|
|
471
|
+
await channel._process_event(
|
|
472
|
+
Event(
|
|
473
|
+
type=EventType.NODE_STATE_CHANGED,
|
|
474
|
+
agent_id=assistant.uuid,
|
|
475
|
+
data={"new_state": "running"},
|
|
476
|
+
)
|
|
477
|
+
)
|
|
478
|
+
assert channel._typing_task is not None
|
|
479
|
+
await channel._typing_task
|
|
480
|
+
|
|
481
|
+
asyncio.run(run_test())
|
|
482
|
+
|
|
483
|
+
assert sent_actions == [(4004, "typing")]
|
|
484
|
+
assert sent_messages == []
|
|
485
|
+
assert channel._stream_message_ids == {}
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
def test_telegram_channel_stop_cancels_typing_task_on_app_loop(monkeypatch):
|
|
489
|
+
cancelled: list[str] = []
|
|
490
|
+
|
|
491
|
+
class FakeTask:
|
|
492
|
+
def cancel(self) -> None:
|
|
493
|
+
cancelled.append("typing")
|
|
494
|
+
|
|
495
|
+
class FakeLoop:
|
|
496
|
+
def __init__(self) -> None:
|
|
497
|
+
self.calls: list[str] = []
|
|
498
|
+
|
|
499
|
+
def is_closed(self) -> bool:
|
|
500
|
+
return False
|
|
501
|
+
|
|
502
|
+
def call_soon_threadsafe(self, callback) -> None:
|
|
503
|
+
self.calls.append(callback.__name__)
|
|
504
|
+
callback()
|
|
505
|
+
|
|
506
|
+
monkeypatch.setattr(
|
|
507
|
+
"flowent.channels.telegram.event_bus.unsubscribe", lambda _: None
|
|
508
|
+
)
|
|
509
|
+
|
|
510
|
+
channel = TelegramChannel()
|
|
511
|
+
app_loop = FakeLoop()
|
|
512
|
+
polling_loop = FakeLoop()
|
|
513
|
+
channel._app_loop = app_loop
|
|
514
|
+
channel._thread_loop = polling_loop
|
|
515
|
+
channel._typing_task = FakeTask()
|
|
516
|
+
|
|
517
|
+
channel.stop()
|
|
518
|
+
|
|
519
|
+
assert app_loop.calls == ["cancel"]
|
|
520
|
+
assert polling_loop.calls == []
|
|
521
|
+
assert cancelled == ["typing"]
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
def test_telegram_channel_call_api_uses_shared_async_transport(monkeypatch):
|
|
525
|
+
settings = Settings(telegram=TelegramSettings(bot_token="123456:ABCDE"))
|
|
526
|
+
fake_session = _FakeAsyncSession(
|
|
527
|
+
_FakeTelegramResponse(200, {"ok": True, "result": {"message_id": 1}})
|
|
528
|
+
)
|
|
529
|
+
|
|
530
|
+
monkeypatch.setattr("flowent.channels.telegram.get_settings", lambda: settings)
|
|
531
|
+
monkeypatch.setattr(
|
|
532
|
+
"flowent.channels.telegram.create_async_http_session",
|
|
533
|
+
lambda timeout: fake_session,
|
|
534
|
+
)
|
|
535
|
+
|
|
536
|
+
channel = TelegramChannel()
|
|
537
|
+
|
|
538
|
+
result = asyncio.run(
|
|
539
|
+
channel._call_api(
|
|
540
|
+
"sendMessage",
|
|
541
|
+
{"chat_id": 3003, "text": "hello"},
|
|
542
|
+
parse_mode="Markdown",
|
|
543
|
+
)
|
|
544
|
+
)
|
|
545
|
+
|
|
546
|
+
assert result == {"message_id": 1}
|
|
547
|
+
assert fake_session.requests == [
|
|
548
|
+
(
|
|
549
|
+
"https://api.telegram.org/bot123456:ABCDE/sendMessage",
|
|
550
|
+
{"chat_id": 3003, "text": "hello", "parse_mode": "Markdown"},
|
|
551
|
+
)
|
|
552
|
+
]
|
|
Binary file
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import re
|
|
3
|
+
from collections.abc import Iterator
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
import pytest
|
|
7
|
+
from loguru import logger
|
|
8
|
+
|
|
9
|
+
from flowent.logging import (
|
|
10
|
+
HealthcheckAccessFilter,
|
|
11
|
+
configure_uvicorn_access_logging,
|
|
12
|
+
detect_runtime_mode,
|
|
13
|
+
setup_logging,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@pytest.fixture(autouse=True)
|
|
18
|
+
def cleanup_loguru() -> Iterator[None]:
|
|
19
|
+
yield
|
|
20
|
+
logger.remove()
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def test_detect_runtime_mode_from_fastapi_command() -> None:
|
|
24
|
+
assert detect_runtime_mode(["/venv/bin/fastapi", "dev", "app/main.py"]) == "dev"
|
|
25
|
+
assert detect_runtime_mode(["/venv/bin/fastapi", "run", "app/main.py"]) == "release"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def test_detect_runtime_mode_from_reload_flag() -> None:
|
|
29
|
+
assert detect_runtime_mode(["uvicorn", "flowent.main:app", "--reload"]) == "dev"
|
|
30
|
+
assert detect_runtime_mode(["uvicorn", "flowent.main:app"]) == "release"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def test_setup_logging_creates_timestamped_file_and_prunes_old_logs(
|
|
34
|
+
tmp_path: Path,
|
|
35
|
+
) -> None:
|
|
36
|
+
log_dir = tmp_path / "logs"
|
|
37
|
+
log_dir.mkdir()
|
|
38
|
+
for i in range(1, 12):
|
|
39
|
+
(log_dir / f"{i}.log").write_text(f"old-{i}", encoding="utf-8")
|
|
40
|
+
|
|
41
|
+
setup_logging(argv=["fastapi", "run"], runtime_dir=tmp_path)
|
|
42
|
+
|
|
43
|
+
log_files = sorted(path.name for path in log_dir.iterdir() if path.is_file())
|
|
44
|
+
assert len(log_files) == 10
|
|
45
|
+
assert "1.log" not in log_files
|
|
46
|
+
assert "2.log" not in log_files
|
|
47
|
+
assert any(
|
|
48
|
+
re.fullmatch(r"\d{4}-\d{2}-\d{2}_\d{6}_\d+\.log", path) for path in log_files
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_setup_logging_writes_source_and_agent_id_to_file(tmp_path: Path) -> None:
|
|
53
|
+
setup_logging(argv=["fastapi", "dev"], runtime_dir=tmp_path)
|
|
54
|
+
|
|
55
|
+
with logger.contextualize(agent_id="agent-123"):
|
|
56
|
+
logger.info("hello file log")
|
|
57
|
+
|
|
58
|
+
log_files = sorted((tmp_path / "logs").iterdir())
|
|
59
|
+
content = log_files[-1].read_text(encoding="utf-8")
|
|
60
|
+
|
|
61
|
+
assert "hello file log" in content
|
|
62
|
+
assert "agent:agent-123" in content
|
|
63
|
+
assert "test_setup_logging_writes_source_and_agent_id_to_file" in content
|
|
64
|
+
assert "hello file log\n\n" not in content
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def test_setup_logging_sets_console_level_from_runtime_mode(
|
|
68
|
+
capsys,
|
|
69
|
+
tmp_path: Path,
|
|
70
|
+
) -> None:
|
|
71
|
+
setup_logging(argv=["fastapi", "run"], runtime_dir=tmp_path)
|
|
72
|
+
logger.debug("hidden release debug")
|
|
73
|
+
logger.info("visible release info")
|
|
74
|
+
release_output = capsys.readouterr().err
|
|
75
|
+
|
|
76
|
+
setup_logging(argv=["fastapi", "dev"], runtime_dir=tmp_path)
|
|
77
|
+
logger.debug("visible dev debug")
|
|
78
|
+
dev_output = capsys.readouterr().err
|
|
79
|
+
|
|
80
|
+
assert "hidden release debug" not in release_output
|
|
81
|
+
assert "visible release info" in release_output
|
|
82
|
+
assert "visible release info\n\n" not in release_output
|
|
83
|
+
assert "visible dev debug" in dev_output
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def test_healthcheck_access_filter_blocks_health_endpoint() -> None:
|
|
87
|
+
access_filter = HealthcheckAccessFilter()
|
|
88
|
+
record = logging.LogRecord(
|
|
89
|
+
name="uvicorn.access",
|
|
90
|
+
level=logging.INFO,
|
|
91
|
+
pathname=__file__,
|
|
92
|
+
lineno=1,
|
|
93
|
+
msg='%s - "%s %s HTTP/%s" %d',
|
|
94
|
+
args=("127.0.0.1:12345", "GET", "/health?source=docker", "1.1", 200),
|
|
95
|
+
exc_info=None,
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
assert access_filter.filter(record) is False
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def test_healthcheck_access_filter_keeps_other_requests() -> None:
|
|
102
|
+
access_filter = HealthcheckAccessFilter()
|
|
103
|
+
record = logging.LogRecord(
|
|
104
|
+
name="uvicorn.access",
|
|
105
|
+
level=logging.INFO,
|
|
106
|
+
pathname=__file__,
|
|
107
|
+
lineno=1,
|
|
108
|
+
msg='%s - "%s %s HTTP/%s" %d',
|
|
109
|
+
args=("127.0.0.1:12345", "GET", "/api/meta", "1.1", 200),
|
|
110
|
+
exc_info=None,
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
assert access_filter.filter(record) is True
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def test_configure_uvicorn_access_logging_installs_filter_once() -> None:
|
|
117
|
+
access_logger = logging.getLogger("uvicorn.access")
|
|
118
|
+
original_filters = list(access_logger.filters)
|
|
119
|
+
access_logger.filters = [
|
|
120
|
+
f for f in access_logger.filters if not isinstance(f, HealthcheckAccessFilter)
|
|
121
|
+
]
|
|
122
|
+
|
|
123
|
+
try:
|
|
124
|
+
configure_uvicorn_access_logging()
|
|
125
|
+
configure_uvicorn_access_logging()
|
|
126
|
+
|
|
127
|
+
filters = [
|
|
128
|
+
f for f in access_logger.filters if isinstance(f, HealthcheckAccessFilter)
|
|
129
|
+
]
|
|
130
|
+
assert len(filters) == 1
|
|
131
|
+
finally:
|
|
132
|
+
access_logger.filters = original_filters
|