From e11e3841b48ed6296ff66f1d00696b3cacea5622 Mon Sep 17 00:00:00 2001 From: Zamil Majdy Date: Thu, 16 Apr 2026 05:31:40 +0700 Subject: [PATCH] fix(backend/copilot): sanitize OSError path in write log, patch config in mode-check tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - _write_cli_session_to_disk: log basename + e.strerror instead of raw OSError to avoid exposing host directory paths in warning logs - TestRestoreCliSessionModeCheck: patch config.claude_agent_use_resume=True so tests are not silently skipped when CLAUDE_AGENT_USE_RESUME=false in env - baseline/transcript_integration_test.py: fix stale docstring (restore_cli_session → download_transcript) --- .../baseline/transcript_integration_test.py | 2 +- .../backend/backend/copilot/sdk/service.py | 7 +++++- .../copilot/sdk/service_helpers_test.py | 22 ++++++++++++++----- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/autogpt_platform/backend/backend/copilot/baseline/transcript_integration_test.py b/autogpt_platform/backend/backend/copilot/baseline/transcript_integration_test.py index a886487bcc..da698d3840 100644 --- a/autogpt_platform/backend/backend/copilot/baseline/transcript_integration_test.py +++ b/autogpt_platform/backend/backend/copilot/baseline/transcript_integration_test.py @@ -2,7 +2,7 @@ Exercises the real helpers in ``baseline/service.py`` that restore, validate, load, append to, backfill, and upload the CLI session. -Storage is mocked via ``restore_cli_session`` / ``upload_cli_session`` +Storage is mocked via ``download_transcript`` / ``upload_transcript`` patches; no network access is required. """ diff --git a/autogpt_platform/backend/backend/copilot/sdk/service.py b/autogpt_platform/backend/backend/copilot/sdk/service.py index ba6e2291bb..a9a0a23886 100644 --- a/autogpt_platform/backend/backend/copilot/sdk/service.py +++ b/autogpt_platform/backend/backend/copilot/sdk/service.py @@ -883,7 +883,12 @@ def _write_cli_session_to_disk( ) return True except OSError as e: - logger.warning("%s Failed to write CLI session file: %s", log_prefix, e) + logger.warning( + "%s Failed to write CLI session file %s: %s", + log_prefix, + os.path.basename(session_file), + e.strerror or str(e), + ) return False diff --git a/autogpt_platform/backend/backend/copilot/sdk/service_helpers_test.py b/autogpt_platform/backend/backend/copilot/sdk/service_helpers_test.py index 71444d9715..4d93d3a9e2 100644 --- a/autogpt_platform/backend/backend/copilot/sdk/service_helpers_test.py +++ b/autogpt_platform/backend/backend/copilot/sdk/service_helpers_test.py @@ -660,10 +660,15 @@ class TestRestoreCliSessionModeCheck: mode="baseline", ) + import backend.copilot.sdk.service as _svc_mod + download_mock = AsyncMock(return_value=baseline_restore) - with patch( - "backend.copilot.sdk.service.download_transcript", - new=download_mock, + with ( + patch( + "backend.copilot.sdk.service.download_transcript", + new=download_mock, + ), + patch.object(_svc_mod.config, "claude_agent_use_resume", True), ): result = await _restore_cli_session_for_turn( user_id="user-1", @@ -738,9 +743,14 @@ class TestRestoreCliSessionModeCheck: mode="sdk", ) - with patch( - "backend.copilot.sdk.service.download_transcript", - new=AsyncMock(return_value=sdk_restore), + import backend.copilot.sdk.service as _svc_mod + + with ( + patch( + "backend.copilot.sdk.service.download_transcript", + new=AsyncMock(return_value=sdk_restore), + ), + patch.object(_svc_mod.config, "claude_agent_use_resume", True), ): result = await _restore_cli_session_for_turn( user_id="user-1",