Files
cowork-local/tests/unit/test_execution_workspace.py
f9f6bc01fd
CI / test (push) Canceled after 0s
Feature/delta team/epic r04 (#7)
## Summary

epic r04 - begin refactor

## Change Type

- [x] Cowork feature
- [ ] Bug fix
- [ ] Core AI contribution
- [ ] Test / hardening
- [ ] Performance
- [ ] Documentation

## Related Work

Cowork Task:

Core Repo: http://34.143.229.138/gitea-admin/fsg-ai-core-assets

Core AI Issue:

Core Task:

Related PR:

## Scope

What is intentionally included?

What is intentionally NOT included?

## Validation

- [ ] Unit tests
- [ ] Integration tests
- [ ] Manual verification
- [ ] Regression check

Commands / evidence:

## Security Impact

Permission / credential / network / customer data impact:

## Compatibility

- [ ] No breaking change
- [ ] Breaking change documented

## Reviewer Notes

Anything Cowork reviewers should pay attention to.

---------

Co-authored-by: Anh Tran Nguyen Minh <anhtnm1@fpt.com>
Co-authored-by: Huong Le Thi Thien <huongltt35@fpt.com>
Co-authored-by: Nam Pham Dinh Thanh <nampdt@fpt.com>
Co-authored-by: Vu Dam Tuan <vudt15@fpt.com>
Co-authored-by: Hiep Ha Van <hiephv3@fpt.com>
Co-authored-by: Lam Hoang Van <lamhv7@fpt.com>
Reviewed-on: #7
Co-authored-by: Duy Le Huu <duylh19@fpt.com>
2026-08-31 05:15:13 +00:00

52 lines
2.0 KiB
Python

"""EPIC R06-T03: ExecutionWorkspace names the output-dir/scratch-dir split
that already exists in ``core/chat_agent.py`` (``.scratch`` under the
workspace root) without changing where anything lands."""
from __future__ import annotations
from cowork_local.domain.workspaces import WorkspaceSession
from cowork_local.infrastructure.filesystem.execution_workspace import ExecutionWorkspace
def test_output_dir_is_the_workspace_root_itself(tmp_path):
session = WorkspaceSession.unscoped(tmp_path)
workspace = ExecutionWorkspace(session, turn_id="turn-1")
assert workspace.output_dir == tmp_path
def test_scratch_dir_matches_the_existing_flat_convention(tmp_path):
"""core/chat_agent.py::_cleanup_cowork_intermediates operates on
``output_dir / ".scratch"`` with no per-turn subfolder — this must agree,
or cleanup_scratch() would target a directory nothing ever wrote to."""
session = WorkspaceSession.unscoped(tmp_path)
workspace = ExecutionWorkspace(session, turn_id="turn-1")
assert workspace.scratch_dir == tmp_path / ".scratch"
def test_ensure_dirs_creates_both_folders(tmp_path):
session = WorkspaceSession.unscoped(tmp_path / "root")
workspace = ExecutionWorkspace(session, turn_id="t")
workspace.ensure_dirs()
assert workspace.output_dir.is_dir()
assert workspace.scratch_dir.is_dir()
def test_cleanup_scratch_removes_it_and_leaves_output_dir_alone(tmp_path):
session = WorkspaceSession.unscoped(tmp_path)
workspace = ExecutionWorkspace(session, turn_id="t")
workspace.ensure_dirs()
(workspace.scratch_dir / "helper.py").write_text("print(1)", encoding="utf-8")
(workspace.output_dir / "deliverable.txt").write_text("done", encoding="utf-8")
workspace.cleanup_scratch()
assert not workspace.scratch_dir.exists()
assert (workspace.output_dir / "deliverable.txt").exists()
def test_cleanup_scratch_is_a_no_op_when_never_created(tmp_path):
workspace = ExecutionWorkspace(WorkspaceSession.unscoped(tmp_path), turn_id="t")
workspace.cleanup_scratch() # must not raise