Skip to content
Closed
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
78 changes: 78 additions & 0 deletions tests/tools/test_cronjob_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,84 @@ def test_update_normalizes_list_form_deliver(self):
stored = get_job(created["job_id"])
assert stored["deliver"] == "telegram"

def test_update_attach_to_session_persists_and_is_visible(self):
"""An attach-only update must persist and be observable via the tool."""
from cron.jobs import get_job

created = json.loads(
cronjob(action="create", prompt="x", schedule="every 1h")
)

updated = json.loads(
cronjob(
action="update",
job_id=created["job_id"],
attach_to_session=True,
)
)

assert updated["success"] is True
assert updated["job"]["attach_to_session"] is True
stored = get_job(created["job_id"])
assert stored is not None
assert stored["attach_to_session"] is True

listing = json.loads(cronjob(action="list"))
listed = next(
job for job in listing["jobs"] if job["job_id"] == created["job_id"]
)
assert listed["attach_to_session"] is True

updated = json.loads(
cronjob(
action="update",
job_id=created["job_id"],
attach_to_session=False,
)
)

assert updated["success"] is True
assert updated["job"]["attach_to_session"] is False
stored = get_job(created["job_id"])
assert stored is not None
assert stored["attach_to_session"] is False

listing = json.loads(cronjob(action="list"))
listed = next(
job for job in listing["jobs"] if job["job_id"] == created["job_id"]
)
assert listed["attach_to_session"] is False

@pytest.mark.parametrize("attach_to_session", [True, False])
def test_handler_forwards_attach_to_session(self, attach_to_session):
"""The registered handler must forward both boolean override values."""
from tools.registry import registry

created_raw = registry.dispatch(
"cronjob",
{
"action": "create",
"prompt": "x",
"schedule": "every 1h",
},
)
assert isinstance(created_raw, str)
created = json.loads(created_raw)

updated_raw = registry.dispatch(
"cronjob",
{
"action": "update",
"job_id": created["job_id"],
"attach_to_session": attach_to_session,
},
)
assert isinstance(updated_raw, str)
updated = json.loads(updated_raw)

assert updated["success"] is True
assert updated["job"]["attach_to_session"] is attach_to_session


# =========================================================================
# Agent-facing surface: per-job model pins are user-owned
Expand Down
3 changes: 3 additions & 0 deletions tools/cronjob_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,8 @@ def _format_job(job: Dict[str, Any]) -> Dict[str, Any]:
result["enabled_toolsets"] = job["enabled_toolsets"]
if job.get("workdir"):
result["workdir"] = job["workdir"]
if isinstance(job.get("attach_to_session"), bool):
result["attach_to_session"] = job["attach_to_session"]
stored_refs = job.get("context_from") or []
if isinstance(stored_refs, str):
stored_refs = [stored_refs]
Expand Down Expand Up @@ -1909,6 +1911,7 @@ def check_cronjob_requirements() -> bool:
enabled_toolsets=args.get("enabled_toolsets"),
workdir=args.get("workdir"),
no_agent=args.get("no_agent"),
attach_to_session=args.get("attach_to_session"),
monitor_script=args.get("monitor_script"),
monitor_url=args.get("monitor_url"),
task_id=kw.get("task_id"),
Expand Down