Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions tests/test_workspace_artifact.py
Original file line number Diff line number Diff line change
@@ -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)"]
2 changes: 1 addition & 1 deletion workflow/hooks/workspace_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down