fix(pi): create sessions under run base dir (#68)
Co-authored-by: banteg <4562643+banteg@users.noreply.github.com>
This commit is contained in:
@@ -27,7 +27,7 @@ from ..model import (
|
|||||||
)
|
)
|
||||||
from ..runner import JsonlSubprocessRunner, ResumeTokenMixin, Runner
|
from ..runner import JsonlSubprocessRunner, ResumeTokenMixin, Runner
|
||||||
from ..schemas import pi as pi_schema
|
from ..schemas import pi as pi_schema
|
||||||
from ..utils.paths import relativize_command, relativize_path
|
from ..utils.paths import get_run_base_dir, relativize_command, relativize_path
|
||||||
|
|
||||||
logger = get_logger(__name__)
|
logger = get_logger(__name__)
|
||||||
|
|
||||||
@@ -421,7 +421,8 @@ class PiRunner(ResumeTokenMixin, JsonlSubprocessRunner):
|
|||||||
]
|
]
|
||||||
|
|
||||||
def _new_session_path(self) -> str:
|
def _new_session_path(self) -> str:
|
||||||
session_dir = _default_session_dir(Path.cwd())
|
cwd = get_run_base_dir() or Path.cwd()
|
||||||
|
session_dir = _default_session_dir(cwd)
|
||||||
session_dir.mkdir(parents=True, exist_ok=True)
|
session_dir.mkdir(parents=True, exist_ok=True)
|
||||||
timestamp = datetime.now(timezone.utc).isoformat()
|
timestamp = datetime.now(timezone.utc).isoformat()
|
||||||
safe_timestamp = timestamp.replace(":", "-").replace(".", "-")
|
safe_timestamp = timestamp.replace(":", "-").replace(".", "-")
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
import anyio
|
import anyio
|
||||||
import pytest
|
import pytest
|
||||||
@@ -48,6 +49,7 @@ def test_translate_success_fixture() -> None:
|
|||||||
|
|
||||||
assert isinstance(events[0], StartedEvent)
|
assert isinstance(events[0], StartedEvent)
|
||||||
started = next(evt for evt in events if isinstance(evt, StartedEvent))
|
started = next(evt for evt in events if isinstance(evt, StartedEvent))
|
||||||
|
assert started.meta is None
|
||||||
|
|
||||||
action_events = [evt for evt in events if isinstance(evt, ActionEvent)]
|
action_events = [evt for evt in events if isinstance(evt, ActionEvent)]
|
||||||
assert len(action_events) == 4
|
assert len(action_events) == 4
|
||||||
@@ -128,3 +130,25 @@ async def test_run_serializes_same_session() -> None:
|
|||||||
await anyio.sleep(0)
|
await anyio.sleep(0)
|
||||||
gate.set()
|
gate.set()
|
||||||
assert max_in_flight == 1
|
assert max_in_flight == 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_session_path_prefers_run_base_dir(tmp_path: Path) -> None:
|
||||||
|
runner = PiRunner(
|
||||||
|
extra_args=[],
|
||||||
|
model=None,
|
||||||
|
provider=None,
|
||||||
|
)
|
||||||
|
project_cwd = Path("/project")
|
||||||
|
session_root = tmp_path / "sessions"
|
||||||
|
|
||||||
|
with (
|
||||||
|
patch("takopi.runners.pi.get_run_base_dir", return_value=project_cwd),
|
||||||
|
patch(
|
||||||
|
"takopi.runners.pi._default_session_dir",
|
||||||
|
return_value=session_root,
|
||||||
|
) as default_session_dir,
|
||||||
|
):
|
||||||
|
session_path = runner._new_session_path()
|
||||||
|
|
||||||
|
default_session_dir.assert_called_once_with(project_cwd)
|
||||||
|
assert str(session_root) in session_path
|
||||||
|
|||||||
Reference in New Issue
Block a user