## Summary Chinese in a deck came out as boxes (or as nothing) in the preview panel, the delivery thumbnail, the template gallery, and the pages the model renders to check its own work. LibreOffice reports success and the PDF is well formed, so nothing flagged it. Why, per platform: - **Linux**: apt's `libreoffice` brings no CJK face. - **macOS**: the system already ships Han faces (Songti, STHeiti, Hiragino Sans GB, PingFang). Since 26.8 the macOS build renders headless through a bundled fontconfig (`--enable-headless --without-system-fontconfig` in `distro-configs/LibreOfficeMacOSX.conf`) that looks for `/usr/local/etc/fonts/fonts.conf`, which an Apple Silicon Mac does not have; without it that fontconfig lists 0 fonts, and a face in `~/Library/Fonts` or a per-user fontconfig file is ignored. That is why installing a font on a Mac never helped, and why the Macs that worked had a CJK face copied into `LibreOffice.app` by hand. openai/codex#32968 reports the same symptom from Codex's own headless-only LibreOfficeDev build, whose fontconfig carries a `/@..._OOO/etc/fonts` prefix; the cask build looks in `/usr/local/etc/fonts`, so that thread's workaround is not the one needed here. What the PR does (the net diff; earlier commits on the branch tried render-time detection, environment injection and then an installer-written fontconfig file, and the later commits replace them): 1. **Linux font.** The LibreOffice offer installs `libreoffice fonts-noto-cjk`. Where that did not run and `fc-list :lang=zh` is empty, a pinned Noto Sans SC (size and sha256 checked before it is put in place) goes into `~/.local/share/fonts` and `fc-cache` is rerun. 2. **macOS: the Mac's own faces, linked into LibreOffice's profile.** LibreOffice always reads the `user/fonts` folder of the profile it runs with. `office.link_han_faces(profile)` links Songti, STHeiti, Hiragino Sans GB and PingFang (found under `AssetsV2` each time, so a link a macOS update left dangling is replaced) into `profile/user/fonts`. `office.to_pdf` does it for its throwaway profile (preview panel, delivery thumbnail, template covers, ppt engine), the design engine for its two profiles, and `ExecTool` for LibreOffice's default profile, which the model's own `soffice --convert-to` uses. No download, no password, nothing written outside the user's home, and it reaches users who upgrade without rerunning `install.sh`. 3. **LibreOffice on a Mac without Homebrew.** This used to be a warning and no preview at all. The installer now fetches the release dmg (26.8.0, sha256 pinned per arch, from the stable directory and then the archive), mounts it read-only, copies `LibreOffice.app` into `/Applications` or `~/Applications`, never over an existing app, and writes a two-line `~/.local/bin/soffice` launcher the way the cask does. A failed `brew install` falls back to it too. 4. **Finding it.** `office.find_soffice` falls back to the launcher inside `LibreOffice.app` in either Applications folder when nothing is on PATH; the design engine now asks the same resolver. 5. **Stale renders.** The pdf-preview and deck-template cover cache keys mix in `office.RENDER_GENERATION` (3), which retires every picture drawn before this change. The Linux font step also clears both caches whenever it installs a face. Removed relative to earlier revisions: `raven/utils/fonts.py` (`render_env`, `han_face`, `can_draw_han`, `host_han_faces`, `install_hint`; several were never called), the exec-environment wrapping, the ppt-engine face lookup, and the installer's sudo-written `/usr/local/etc/fonts/fonts.conf`. Known limits: - A `soffice` run with a profile raven did not prepare (a caller passing its own `-env:UserInstallation`) gets no faces on a Mac. - A `deck.pdf` rendered beside a deck before the fix is still preferred by the viewer until the deck is re-rendered or touched. - Verified on macOS 15.7.1 arm64, and by review on macOS 26.5 arm64 (LibreOffice 26.8.0.3 from the cask); macOS 14 and Intel Macs have not been run. ## Type - [x] Fix - [ ] Feature - [ ] Docs - [ ] CI / tooling - [ ] Refactor - [ ] Other ## Verification macOS 15.7.1 arm64, LibreOffice 26.8.0.3 run from the stock dmg (no CJK face in its bundle), fontconfig handed an empty configuration (so no `fonts.conf` of any kind), HOME pointed at an empty directory: - `main`: the model's own `soffice --convert-to` (default profile, after building an `ExecTool`), `pdf_preview.pdf_for` / `png_for`, the ppt engine's `to_pdf` and the design engine's `LibreOfficeBackend` each embedded only Carlito and LinuxLibertineG (`pdffonts`). - This branch: the same four paths each embedded PingFangSC, STHeitiSC and STSongti-SC; the default profile held links to the five faces. - No-Homebrew path, with PATH stripped of `/opt/homebrew`, an empty HOME and a read-only Applications folder: the step downloaded the dmg, matched its digest, installed into `~/Applications` (`codesign --verify --deep --strict` valid, `spctl --assess` accepted) and wrote the launcher; a second run downloaded nothing. - Linux (container with every CJK face hidden): the font step downloaded Noto Sans SC and the render embedded NotoSansSC; a second run did nothing. - `uv run --frozen --all-extras pytest -q tests/test_utils_office.py tests/test_install_script.py tests/test_design_engine_rendering_office.py tests/test_rpc_deck_templates.py tests/test_shell_background.py tests/test_ppt_engine_render_service.py`: 142 passed, 1 skipped. - `uv run --frozen lint-imports`: 10 kept, 0 broken. `ruff check` / `ruff format --check` on the changed files: clean. `shellcheck -s sh install.sh`: no new findings. `scripts/check_source_language.py`: pass. - [x] Relevant tests pass locally - [x] Relevant lint / type checks pass locally - [ ] User-facing docs or screenshots are updated when needed (no docs describe this step) ## Risk - [x] Security impact considered: the dmg and the font are checked against pinned sha256 digests before use; the macOS change only creates symlinks under LibreOffice profiles in the user's home, never replaces a real file there, and runs no privileged command. - [x] Backward compatibility considered: Linux hosts that already have a CJK face are untouched; on a Mac, a profile that already holds its own fonts keeps them. The cache-key bump costs one re-render. - [x] Rollback path is clear for risky changes: deleting the links in `~/Library/Application Support/LibreOffice/4/user/fonts` returns LibreOffice to its previous behaviour; reverting the PR restores the old installer. User-visible: a Mac without Homebrew downloads about 300 MB of LibreOffice once; nothing asks for a password. ## Related Issues N/A --------- Co-authored-by: litong <litong02@shanda.com> Co-authored-by: Claude (claude-opus-4-6) <noreply@anthropic.com> Co-authored-by: KT <74288668+0xKT@users.noreply.github.com>
433 lines
16 KiB
Python
433 lines
16 KiB
Python
"""AgentLoop binds a per-session working directory for the duration of a turn."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from raven.agent import workdir as workdir_mod
|
|
from raven.agent.loop import AgentLoop
|
|
from raven.agent.loop.bundles import EngineWiring, SubagentWiring, TurnPolicy
|
|
from raven.agent.workdir import WorkdirPolicy, WorkdirResolver
|
|
from raven.contracts.llm_provider import LLMResponse
|
|
from raven.session.manager import SessionManager
|
|
from raven.spine.message import ChatType, Source
|
|
from raven.spine.turn import Origin, TurnRequest
|
|
|
|
|
|
class _FakeChatProvider:
|
|
"""Minimal provider: only used to construct an AgentLoop, never invoked."""
|
|
|
|
def get_default_model(self) -> str:
|
|
return "stub-model"
|
|
|
|
|
|
class _FakeReplyProvider:
|
|
"""Non-streaming provider returning one final reply with no tool calls."""
|
|
|
|
def __init__(self, response: LLMResponse) -> None:
|
|
self._response = response
|
|
|
|
async def chat_with_retry(self, **kwargs) -> LLMResponse:
|
|
return self._response
|
|
|
|
def get_default_model(self) -> str:
|
|
return "fake/model"
|
|
|
|
|
|
def _stub_edges(loop: AgentLoop) -> None:
|
|
"""No-op the sandbox executor bring-up so a turn runs without a VM.
|
|
|
|
``_connect_mcp`` needs no stub: it is already a no-op with no
|
|
``mcp_servers`` configured (the constructor default used here). Same
|
|
shape as the executor stub used in the run/emit turn tests.
|
|
"""
|
|
|
|
async def _noop() -> None:
|
|
return None
|
|
|
|
loop._start_executor = _noop
|
|
|
|
|
|
def _req(text: str) -> TurnRequest:
|
|
return TurnRequest(
|
|
origin=Origin.USER,
|
|
source=Source(channel="web", chat_id="abc", sender_id="u", chat_type=ChatType.DM),
|
|
text=text,
|
|
)
|
|
|
|
|
|
def _resolver(tmp_path: Path) -> WorkdirResolver:
|
|
return WorkdirResolver(
|
|
WorkdirPolicy.PER_CHANNEL,
|
|
agent_home=tmp_path,
|
|
session_root=tmp_path / "chanwork",
|
|
)
|
|
|
|
|
|
def test_session_workdir_uses_the_resolver(tmp_path: Path) -> None:
|
|
loop = AgentLoop(
|
|
provider=_FakeChatProvider(), workspace=tmp_path, subagents=SubagentWiring(workdir_resolver=_resolver(tmp_path))
|
|
)
|
|
|
|
assert loop.session_workdir("web:abc") == tmp_path / "chanwork" / "web"
|
|
|
|
|
|
def test_session_workdir_falls_back_to_the_workspace(tmp_path: Path) -> None:
|
|
"""No resolver means the pre-split behaviour: one directory for everything."""
|
|
loop = AgentLoop(provider=_FakeChatProvider(), workspace=tmp_path)
|
|
|
|
assert loop.session_workdir("web:abc") == tmp_path
|
|
|
|
|
|
class _EmitCollector:
|
|
def __init__(self) -> None:
|
|
self.events: list = []
|
|
|
|
async def __call__(self, ev) -> None:
|
|
self.events.append(ev)
|
|
|
|
|
|
def _drain() -> list:
|
|
return []
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_turn_binds_the_session_workdir(tmp_path: Path) -> None:
|
|
"""A turn runs with the binding active and releases it afterwards."""
|
|
seen: list[Path | None] = []
|
|
loop = AgentLoop(
|
|
provider=_FakeReplyProvider(LLMResponse(content="ok", finish_reason="stop")),
|
|
workspace=tmp_path,
|
|
subagents=SubagentWiring(workdir_resolver=_resolver(tmp_path)),
|
|
)
|
|
_stub_edges(loop)
|
|
|
|
original = loop._set_tool_context
|
|
|
|
def _spy(*args, **kwargs):
|
|
seen.append(workdir_mod.current())
|
|
return original(*args, **kwargs)
|
|
|
|
loop._set_tool_context = _spy
|
|
await loop.run_turn(_req("hi"), _EmitCollector(), _drain, stream=False)
|
|
|
|
assert seen == [tmp_path / "chanwork" / "web"]
|
|
assert workdir_mod.current() is None
|
|
|
|
|
|
def _checkpoint_loop(tmp_path: Path, provider) -> AgentLoop:
|
|
from raven.config.raven import RuntimeConfig
|
|
|
|
runtime = RuntimeConfig()
|
|
runtime.checkpoint.policy = "always"
|
|
return AgentLoop(
|
|
provider=provider,
|
|
workspace=tmp_path,
|
|
subagents=SubagentWiring(workdir_resolver=_resolver(tmp_path)),
|
|
engine=EngineWiring(runtime_config=runtime),
|
|
policy=TurnPolicy(interactive=True),
|
|
)
|
|
|
|
|
|
def test_checkpoints_are_per_working_directory(tmp_path: Path) -> None:
|
|
"""One shadow git repo per working directory, cached on that directory.
|
|
|
|
Under per-channel working directories two chats on one channel share a
|
|
directory, so they legitimately share its repo; another channel is another
|
|
directory and must get its own. Keying the cache on the directory rather
|
|
than on the session key is what makes both true at once.
|
|
"""
|
|
loop = _checkpoint_loop(tmp_path, _FakeChatProvider())
|
|
|
|
with workdir_mod.bind(loop.session_workdir("web:one")):
|
|
first = loop._turn_checkpoint()
|
|
again = loop._turn_checkpoint()
|
|
with workdir_mod.bind(loop.session_workdir("web:two")):
|
|
same_channel = loop._turn_checkpoint()
|
|
with workdir_mod.bind(loop.session_workdir("qq:one")):
|
|
other_channel = loop._turn_checkpoint()
|
|
|
|
assert first is again
|
|
assert first is same_channel
|
|
assert first is not other_channel
|
|
assert first._workspace == tmp_path / "chanwork" / "web"
|
|
assert other_channel._workspace == tmp_path / "chanwork" / "qq"
|
|
|
|
|
|
class _WritingProvider:
|
|
"""Leaves an edit in the bound working directory, then replies.
|
|
|
|
Stands in for the turn's tool calls: the checkpoint only commits when the
|
|
turn actually changed something, so the oracle below needs a real edit.
|
|
"""
|
|
|
|
def __init__(self, filename: str) -> None:
|
|
self._filename = filename
|
|
|
|
async def chat_with_retry(self, **kwargs) -> LLMResponse:
|
|
(workdir_mod.current() / self._filename).write_text("edited\n", encoding="utf-8")
|
|
return LLMResponse(content="ok", finish_reason="stop")
|
|
|
|
def get_default_model(self) -> str:
|
|
return "fake/model"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_turn_checkpoint_commits_the_session_working_directory(tmp_path: Path) -> None:
|
|
"""The per-turn snapshot must land in the directory the turn wrote to.
|
|
|
|
Regression: the checkpoint used to be keyed on the always-empty
|
|
extraction session id, so every gateway turn snapshotted the fallback
|
|
``ws/_`` while the turn's edits landed in the session's own directory.
|
|
|
|
Asserting the commit -- not just the cache entry -- is deliberate:
|
|
``_stash_recovery`` populates ``_checkpoints`` too, so a cache-only
|
|
assertion stays green even if the end-of-turn snapshot is deleted.
|
|
"""
|
|
loop = _checkpoint_loop(tmp_path, _WritingProvider("edited.txt"))
|
|
_stub_edges(loop)
|
|
|
|
await loop.run_turn(_req("hi"), _EmitCollector(), _drain, stream=False)
|
|
|
|
session_dir = tmp_path / "chanwork" / "web"
|
|
assert list(loop._checkpoints) == [session_dir]
|
|
assert not (tmp_path / "chanwork" / "_").exists()
|
|
|
|
svc = loop._checkpoints[session_dir]
|
|
assert svc._workspace == session_dir
|
|
rc, subject, _ = await svc._git("log", "-1", "--pretty=%s")
|
|
assert rc == 0, "the turn left no commit in the session's shadow repo"
|
|
assert subject.strip() == "turn web:abc [completed]"
|
|
rc, tracked, _ = await svc._git("ls-tree", "-r", "--name-only", "HEAD")
|
|
assert rc == 0
|
|
assert "edited.txt" in tracked.splitlines()
|
|
|
|
|
|
def test_sandbox_mounts_the_root_covering_every_session(tmp_path: Path, monkeypatch) -> None:
|
|
recorded: dict = {}
|
|
|
|
def _fake_build_executor(cfg, workspace, owned_ids=None, extra_volumes=(), *, sandbox_dir=None):
|
|
recorded["workspace"] = workspace
|
|
recorded["extra_volumes"] = list(extra_volumes)
|
|
|
|
class _Stub:
|
|
# Stands in for the sandbox built with this mount.
|
|
is_sandboxed = True
|
|
|
|
return _Stub()
|
|
|
|
monkeypatch.setattr("raven.agent.loop.main.build_executor", _fake_build_executor)
|
|
AgentLoop(
|
|
provider=_FakeChatProvider(), workspace=tmp_path, subagents=SubagentWiring(workdir_resolver=_resolver(tmp_path))
|
|
)
|
|
|
|
assert recorded["workspace"] == tmp_path / "chanwork"
|
|
# Per-session dirs live under ``<workspace>/ws``, a child of workspace, not
|
|
# an ancestor of it -- so the mount does not already cover agent home and
|
|
# a separate volume must keep it reachable inside the VM.
|
|
assert recorded["extra_volumes"] == [(str(tmp_path), "/agent-home", "rw")]
|
|
|
|
|
|
def test_sandbox_skips_the_home_volume_when_the_mount_already_covers_it(tmp_path: Path, monkeypatch) -> None:
|
|
"""LAUNCH_DIR policy with no override mounts the workspace itself -- no
|
|
second volume is needed since agent home and the mount are the same
|
|
directory."""
|
|
recorded: dict = {}
|
|
|
|
def _fake_build_executor(cfg, workspace, owned_ids=None, extra_volumes=(), *, sandbox_dir=None):
|
|
recorded["workspace"] = workspace
|
|
recorded["extra_volumes"] = list(extra_volumes)
|
|
|
|
class _Stub:
|
|
# Stands in for the sandbox built with this mount.
|
|
is_sandboxed = True
|
|
|
|
return _Stub()
|
|
|
|
monkeypatch.setattr("raven.agent.loop.main.build_executor", _fake_build_executor)
|
|
resolver = WorkdirResolver(WorkdirPolicy.LAUNCH_DIR, agent_home=tmp_path, launch_dir=tmp_path)
|
|
AgentLoop(provider=_FakeChatProvider(), workspace=tmp_path, subagents=SubagentWiring(workdir_resolver=resolver))
|
|
|
|
assert recorded["workspace"] == tmp_path
|
|
assert recorded["extra_volumes"] == []
|
|
|
|
|
|
def test_sandboxed_turn_refuses_a_workdir_outside_the_mount(tmp_path, monkeypatch):
|
|
"""A pinned directory outside the VM mount is a hard error, not a silent miss."""
|
|
outside = tmp_path / "outside"
|
|
outside.mkdir()
|
|
sessions = SessionManager(tmp_path / "home")
|
|
session = sessions.get_or_create("web:abc")
|
|
session.metadata["workdir"] = str(outside)
|
|
sessions.save(session)
|
|
|
|
resolver = WorkdirResolver(
|
|
WorkdirPolicy.PER_CHANNEL,
|
|
agent_home=tmp_path / "home",
|
|
session_root=tmp_path / "home" / "chanwork",
|
|
sessions=sessions,
|
|
)
|
|
loop = AgentLoop(
|
|
provider=_FakeChatProvider(), workspace=tmp_path / "home", subagents=SubagentWiring(workdir_resolver=resolver)
|
|
)
|
|
monkeypatch.setattr(type(loop._executor), "is_sandboxed", property(lambda self: True))
|
|
|
|
with pytest.raises(ValueError, match="outside the sandbox mount"):
|
|
loop.session_workdir("web:abc")
|
|
|
|
|
|
def test_sandboxed_turn_allows_an_override_reached_through_a_symlinked_ancestor(tmp_path, monkeypatch):
|
|
"""A persisted override is resolved through symlinks; ``mount_root()`` is
|
|
not. An override that is physically inside the mount must not be refused
|
|
just because it was spelled through a symlinked ancestor of agent home."""
|
|
real_home = tmp_path / "real_home"
|
|
real_home.mkdir()
|
|
link_home = tmp_path / "link_home"
|
|
link_home.symlink_to(real_home, target_is_directory=True)
|
|
|
|
sessions = SessionManager(link_home)
|
|
session = sessions.get_or_create("web:abc")
|
|
session.metadata["workdir"] = str(link_home / "chanwork" / "sub")
|
|
sessions.save(session)
|
|
|
|
resolver = WorkdirResolver(
|
|
WorkdirPolicy.PER_CHANNEL,
|
|
agent_home=link_home,
|
|
# Named explicitly, and through the symlink, so the mount root is the
|
|
# tree the override sits in -- the point of the test is that the two
|
|
# spellings of one physical directory compare equal.
|
|
session_root=link_home / "chanwork",
|
|
sessions=sessions,
|
|
)
|
|
loop = AgentLoop(
|
|
provider=_FakeChatProvider(), workspace=link_home, subagents=SubagentWiring(workdir_resolver=resolver)
|
|
)
|
|
monkeypatch.setattr(type(loop._executor), "is_sandboxed", property(lambda self: True))
|
|
|
|
resolved = loop.session_workdir("web:abc")
|
|
|
|
assert resolved == real_home / "chanwork" / "sub"
|
|
|
|
|
|
def test_mount_root_follows_an_explicit_workdir_under_per_session_policy(tmp_path) -> None:
|
|
"""An explicit ``-w`` override must win through every policy, including
|
|
PER_SESSION. ``resolve()`` already lets ``explicit_workdir`` win over the
|
|
policy default for every session; ``mount_root()`` must agree, or a
|
|
sandboxed turn is refused unconditionally once that combination becomes
|
|
reachable."""
|
|
explicit = tmp_path / "explicit"
|
|
resolver = WorkdirResolver(
|
|
WorkdirPolicy.PER_CHANNEL,
|
|
agent_home=tmp_path,
|
|
session_root=tmp_path / "chanwork",
|
|
explicit_workdir=explicit,
|
|
)
|
|
|
|
assert resolver.mount_root() == explicit
|
|
assert resolver.resolve("web:abc") == explicit
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_run_turn_refuses_a_workdir_outside_the_mount(tmp_path, monkeypatch):
|
|
"""The Step 4b guard must fire on the real turn path, not just when
|
|
``session_workdir`` is called directly."""
|
|
outside = tmp_path / "outside"
|
|
outside.mkdir()
|
|
sessions = SessionManager(tmp_path / "home")
|
|
session = sessions.get_or_create("web:abc")
|
|
session.metadata["workdir"] = str(outside)
|
|
sessions.save(session)
|
|
|
|
resolver = WorkdirResolver(
|
|
WorkdirPolicy.PER_CHANNEL,
|
|
agent_home=tmp_path / "home",
|
|
session_root=tmp_path / "home" / "chanwork",
|
|
sessions=sessions,
|
|
)
|
|
loop = AgentLoop(
|
|
provider=_FakeReplyProvider(LLMResponse(content="ok", finish_reason="stop")),
|
|
workspace=tmp_path / "home",
|
|
subagents=SubagentWiring(workdir_resolver=resolver),
|
|
)
|
|
_stub_edges(loop)
|
|
monkeypatch.setattr(type(loop._executor), "is_sandboxed", property(lambda self: True))
|
|
|
|
with pytest.raises(RuntimeError, match="Session working directory is invalid"):
|
|
await loop.run_turn(_req("hi"), _EmitCollector(), _drain, stream=False)
|
|
|
|
|
|
def test_a_multi_round_plan_works_the_session_s_directory_not_the_agent_home(tmp_path: Path) -> None:
|
|
"""A plan takes a checkout of a project and edits it for hours. Agent home
|
|
is not a project, and on a gateway neither is the directory the process was
|
|
launched from -- so the question goes through the same resolver a tool call
|
|
does."""
|
|
project = tmp_path / "chanwork" / "web"
|
|
loop = AgentLoop(
|
|
provider=_FakeChatProvider(), workspace=tmp_path, subagents=SubagentWiring(workdir_resolver=_resolver(tmp_path))
|
|
)
|
|
|
|
assert loop._stint_workspace("web:abc") == project
|
|
assert loop._stint_workspace("web:abc") != tmp_path
|
|
|
|
|
|
def test_peek_does_not_create_the_directory(tmp_path: Path) -> None:
|
|
"""Reporting where a session would work must not touch the disk."""
|
|
loop = AgentLoop(
|
|
provider=_FakeChatProvider(), workspace=tmp_path, subagents=SubagentWiring(workdir_resolver=_resolver(tmp_path))
|
|
)
|
|
|
|
peeked = loop.peek_session_workdir("web:abc")
|
|
|
|
assert peeked == tmp_path / "chanwork" / "web"
|
|
assert not peeked.exists()
|
|
assert loop.session_workdir("web:abc").is_dir()
|
|
|
|
|
|
def test_peek_does_not_refuse_a_workdir_outside_the_mount(tmp_path, monkeypatch) -> None:
|
|
"""A read reports the path; refusing belongs to the paths about to use it."""
|
|
outside = tmp_path / "outside"
|
|
outside.mkdir()
|
|
sessions = SessionManager(tmp_path / "home")
|
|
session = sessions.get_or_create("web:abc")
|
|
session.metadata["workdir"] = str(outside)
|
|
sessions.save(session)
|
|
|
|
resolver = WorkdirResolver(
|
|
WorkdirPolicy.PER_CHANNEL,
|
|
agent_home=tmp_path / "home",
|
|
session_root=tmp_path / "home" / "chanwork",
|
|
sessions=sessions,
|
|
)
|
|
loop = AgentLoop(
|
|
provider=_FakeChatProvider(), workspace=tmp_path / "home", subagents=SubagentWiring(workdir_resolver=resolver)
|
|
)
|
|
monkeypatch.setattr(type(loop._executor), "is_sandboxed", property(lambda self: True))
|
|
|
|
assert loop.peek_session_workdir("web:abc") == outside
|
|
|
|
|
|
def test_refused_workdir_is_not_created(tmp_path, monkeypatch) -> None:
|
|
"""The mount check runs before the mkdir, so a refusal leaves nothing behind."""
|
|
outside = tmp_path / "outside"
|
|
sessions = SessionManager(tmp_path / "home")
|
|
session = sessions.get_or_create("web:abc")
|
|
session.metadata["workdir"] = str(outside)
|
|
sessions.save(session)
|
|
|
|
resolver = WorkdirResolver(
|
|
WorkdirPolicy.PER_CHANNEL,
|
|
agent_home=tmp_path / "home",
|
|
session_root=tmp_path / "home" / "chanwork",
|
|
sessions=sessions,
|
|
)
|
|
loop = AgentLoop(
|
|
provider=_FakeChatProvider(), workspace=tmp_path / "home", subagents=SubagentWiring(workdir_resolver=resolver)
|
|
)
|
|
monkeypatch.setattr(type(loop._executor), "is_sandboxed", property(lambda self: True))
|
|
|
|
with pytest.raises(ValueError, match="outside the sandbox mount"):
|
|
loop.session_workdir("web:abc")
|
|
assert not outside.exists()
|