From b5f919daa77fc64dc527b68c44a556e4ac2eb142 Mon Sep 17 00:00:00 2001 From: nan Date: Tue, 1 Sep 2026 13:37:38 +0800 Subject: [PATCH] fix: correct workspace truncation warning --- tests/test_workspace_artifact.py | 23 +++++++++++++++++++++++ workflow/hooks/workspace_artifact.py | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 tests/test_workspace_artifact.py diff --git a/tests/test_workspace_artifact.py b/tests/test_workspace_artifact.py new file mode 100644 index 0000000000..45b5abfde3 --- /dev/null +++ b/tests/test_workspace_artifact.py @@ -0,0 +1,23 @@ +import logging + +from utils.attachments import AttachmentStore +from workflow.hooks.workspace_artifact import WorkspaceArtifactHook + + +def test_snapshot_logs_counts_when_scan_is_truncated(tmp_path, caplog): + workspace = tmp_path / "workspace" + workspace.mkdir() + (workspace / "artifact.txt").write_text("payload", encoding="utf-8") + + hook = WorkspaceArtifactHook( + attachment_store=AttachmentStore(tmp_path / "attachments"), + emit_callback=lambda _: None, + max_files_scanned=1, + ) + + with caplog.at_level(logging.WARNING, logger=hook.logger.name): + snapshot, truncated = hook._snapshot(workspace) + + assert truncated is True + assert set(snapshot) == {"artifact.txt"} + assert caplog.messages == ["Workspace scan truncated (files=1 total_bytes=7)"] diff --git a/workflow/hooks/workspace_artifact.py b/workflow/hooks/workspace_artifact.py index a04daf662c..1f16cc7c80 100755 --- a/workflow/hooks/workspace_artifact.py +++ b/workflow/hooks/workspace_artifact.py @@ -204,7 +204,7 @@ def _snapshot(self, workspace: Path) -> Tuple[Dict[str, _FileSignature], bool]: entries[str(rel_path)] = _FileSignature(sha256=sha256, size=stat.st_size) if file_count >= self.max_files_scanned or total_bytes >= self.max_bytes_scanned: self.logger.warning( - "Workspace scan truncated (files=%s total_bytes=%s) for session %s", + "Workspace scan truncated (files=%s total_bytes=%s)", file_count, total_bytes, )