From a883903b66c710a815e8d62fd5b19e5c2ba290fb Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Tue, 14 Jul 2026 17:52:35 +0800 Subject: [PATCH] style(host-agent): format Console task submission files --- apps/device-host-agent/host_agent/web/app.py | 8 ++------ apps/device-host-agent/tests/test_history.py | 12 ++++-------- apps/device-host-agent/tests/test_web_app.py | 17 ++++++++--------- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/apps/device-host-agent/host_agent/web/app.py b/apps/device-host-agent/host_agent/web/app.py index af71d3a..6c8f078 100644 --- a/apps/device-host-agent/host_agent/web/app.py +++ b/apps/device-host-agent/host_agent/web/app.py @@ -492,9 +492,7 @@ def create_console_app( "title": "Tasks", "session": session, "csrf_token": session.csrf_token, - "tasks": metadata_store.list_tasks() - if metadata_store is not None - else [], + "tasks": metadata_store.list_tasks() if metadata_store is not None else [], "metadata_store_missing": metadata_store is None, "devices": devices, "automatic_device_value": AUTOMATIC_DEVICE_VALUE, @@ -603,9 +601,7 @@ def create_console_app( ) try: - response = await submit_self_task( - goal=goal, device_id=explicit_device_id - ) + response = await submit_self_task(goal=goal, device_id=explicit_device_id) except HostAgentAPIError as exc: context = _tasks_list_context( session, diff --git a/apps/device-host-agent/tests/test_history.py b/apps/device-host-agent/tests/test_history.py index 8be57f1..6b1e4e3 100644 --- a/apps/device-host-agent/tests/test_history.py +++ b/apps/device-host-agent/tests/test_history.py @@ -93,17 +93,14 @@ def test_history_store_records_task_submission_without_device(tmp_path) -> None: entries = store.list_recent() - assert entries[0]["summary"] == ( - "task submitted: task-cloud-2 (automatic device)" - ) + assert entries[0]["summary"] == ("task submitted: task-cloud-2 (automatic device)") assert entries[0]["detail"] == {"task_id": "task-cloud-2"} def test_history_store_task_submission_redacts_goal_and_secrets(tmp_path) -> None: store = ConsoleHistoryStore(tmp_path / "history.sqlite3") secret_goal = ( - "rotate secret-XYZ-abcdef-very-secret " - "cookie=session-abc; lease=lease-stale" + "rotate secret-XYZ-abcdef-very-secret cookie=session-abc; lease=lease-stale" ) store.record_task_submission(task_id="task-cloud-3", device_id="device-cloud-a") @@ -111,8 +108,7 @@ def test_history_store_task_submission_redacts_goal_and_secrets(tmp_path) -> Non entries = store.list_recent() rendered = "\n".join( - repr(entry["summary"]) + " " + json.dumps(entry["detail"]) - for entry in entries + repr(entry["summary"]) + " " + json.dumps(entry["detail"]) for entry in entries ) assert secret_goal not in rendered @@ -135,4 +131,4 @@ def test_history_store_task_submissions_prune_beyond_limit(tmp_path) -> None: "task-4", "task-3", "task-2", - ] \ No newline at end of file + ] diff --git a/apps/device-host-agent/tests/test_web_app.py b/apps/device-host-agent/tests/test_web_app.py index 70e3f36..3927225 100644 --- a/apps/device-host-agent/tests/test_web_app.py +++ b/apps/device-host-agent/tests/test_web_app.py @@ -49,9 +49,7 @@ def _build_client( session_manager = SessionManager(ttl_seconds=3600.0) metadata_store: TaskMetadataStore | None = None if include_metadata_store: - metadata_store = TaskMetadataStore( - db_path=tmp_path / "task_metadata.sqlite3" - ) + metadata_store = TaskMetadataStore(db_path=tmp_path / "task_metadata.sqlite3") app = create_console_app( config=config, @@ -373,7 +371,11 @@ def _make_submission_recorder( def asyncio_run(coro): import asyncio - return asyncio.get_event_loop().run_until_complete(coro) if asyncio.get_event_loop().is_running() else asyncio.run(coro) + return ( + asyncio.get_event_loop().run_until_complete(coro) + if asyncio.get_event_loop().is_running() + else asyncio.run(coro) + ) def test_tasks_page_renders_submission_form_with_device_options(tmp_path) -> None: @@ -444,8 +446,7 @@ def test_authenticated_explicit_device_submission_uses_runtime_id(tmp_path) -> N assert response.status_code == 303 assert ( - response.headers["location"] - == "/tasks?submitted=1&task_id=task-cloud-explicit" + response.headers["location"] == "/tasks?submitted=1&task_id=task-cloud-explicit" ) assert captured == {"goal": "open mail", "device_id": "device-cloud-a"} @@ -577,9 +578,7 @@ def test_cloud_definitive_rejection_renders_safe_error_without_calling_history( tmp_path, ) -> None: submit, captured = _make_submission_recorder( - raise_api_error=HostAgentAPIError( - 403, "Host self-submission is disabled" - ), + raise_api_error=HostAgentAPIError(403, "Host self-submission is disabled"), ) client, context = _build_client(tmp_path, submit_self_task=submit) context["manager"].register_device(