Compare commits
2
Commits
228886f7cd
...
912417792f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
912417792f | ||
|
|
0005d8f7ee |
No files matched your search
@@ -833,9 +833,12 @@ CLI, unit tests (24) + integration tests (2).
|
||||
resumes, resolves the target calendar with a SemIf choice over the owned
|
||||
calendars — a strong winner is used, otherwise the configured default);
|
||||
`calendar.next_event` is the read counterpart (Nextcloud CalDAV, recurring
|
||||
events expanded server-side); `simplex.next_message` (read via the forwarding
|
||||
bridge) and `simplex.connect_link` (show/create the forwarding bot's contact
|
||||
link) are the messenger seeds; `time.now`, `time.date`, `time.set_timer`, and
|
||||
events expanded server-side); `productivity_management.create_nextcloud_task`
|
||||
adds a task to a Nextcloud task list through the Nextcloud bridge (`GET
|
||||
/tasklists` for a VTODO-capable target, `POST /tasks` to create it, the LLM
|
||||
bridge to phrase the summary/description); `simplex.next_message` (read via the
|
||||
forwarding bridge) and `simplex.connect_link` (show/create the forwarding bot's
|
||||
contact link) are the messenger seeds; `time.now`, `time.date`, `time.set_timer`, and
|
||||
`time.set_alarm` are the local time utilities (`compute` transport, empty
|
||||
contract) — they read the host clock and schedule on `ctx.timers`. Local time
|
||||
is the top-level `timezone` config value (an IANA name such as
|
||||
@@ -1314,9 +1317,11 @@ CLI, unit tests (24) + integration tests (2).
|
||||
`nextcloud_bridge_token`); the `BridgeInfo` declares only those two config vars.
|
||||
Routes (reads `GET`, mutations `POST`): files (`/files`, `/files/stat`,
|
||||
`/files/read` text-or-base64, `/files/search`, `/files/write|mkdir|delete|move|copy`),
|
||||
calendars (`/calendars`, `/calendars/events` list, `POST /calendars/events` +
|
||||
`/update` + `/delete`), tasks (`/tasks` list, `POST /tasks` + `/update` +
|
||||
`/complete` + `/delete`), contacts (`/addressbooks`, `/contacts` list/search,
|
||||
calendars (`/calendars` with each collection's `supported-calendar-component-set`
|
||||
as `components`, `/tasklists` for VTODO-capable task lists, `/calendars/events`
|
||||
list, `POST /calendars/events` + `/update` + `/delete`), tasks (`/tasks` list,
|
||||
`POST /tasks` + `/update` + `/complete` + `/delete`; task routes only target a
|
||||
VTODO-capable calendar and reject an event-only one), contacts (`/addressbooks`, `/contacts` list/search,
|
||||
`POST /contacts` + `/update` + `/delete`), notes (`/notes`, `/notes/get`,
|
||||
`POST /notes` + `/update` + `/delete`), and `/user` + `/capabilities` (OCS).
|
||||
A missing connection is `503`; a real failure (`NextcloudError` — transport,
|
||||
|
||||
+2
-1
@@ -149,7 +149,7 @@
|
||||
"token": ""
|
||||
},
|
||||
"nextcloud": {
|
||||
"_comment": "Nextcloud bridge: files (WebDAV), calendar events and tasks (CalDAV), contacts (CardDAV), and Notes (the Notes app) over one uniform local JSON API, so skill bodies never speak the native DAV/OCS protocols. It has no service daemon (Nextcloud is plain HTTPS) and runs inside the same `semif-bridge` process as the other enabled bridges. The connection is configured HERE (url/username/app_password); when a value is blank the bridge falls back to the top-level nextcloud_url/nextcloud_username/nextcloud_app_password/nextcloud_default_calendar the calendar seeds already use, so the account is configured once. `app_password` is a Nextcloud app password (Settings > Security > Devices & sessions), not the account password. `default_calendar`/`default_addressbook` are used when a request names none and the account has several. `verify_tls` false skips certificate verification (self-signed hosts). Skills call it at http://host:port (derived from this block; no top-level duplicate). Binds localhost only; an optional `token` is required in the X-Semif-Token header when set.",
|
||||
"_comment": "Nextcloud bridge: files (WebDAV), calendar events and tasks (CalDAV), contacts (CardDAV), and Notes (the Notes app) over one uniform local JSON API, so skill bodies never speak the native DAV/OCS protocols. It has no service daemon (Nextcloud is plain HTTPS) and runs inside the same `semif-bridge` process as the other enabled bridges. The connection is configured HERE (url/username/app_password); when a value is blank the bridge falls back to the top-level nextcloud_url/nextcloud_username/nextcloud_app_password/nextcloud_default_calendar the calendar seeds already use, so the account is configured once. `app_password` is a Nextcloud app password (Settings > Security > Devices & sessions), not the account password. `default_calendar`/`default_task_calendar`/`default_addressbook` are used when a request names none and the account has several; task operations only ever target a VTODO-capable task list (GET /tasklists), never an event-only calendar. `verify_tls` false skips certificate verification (self-signed hosts). Skills call it at http://host:port (derived from this block; no top-level duplicate). Binds localhost only; an optional `token` is required in the X-Semif-Token header when set.",
|
||||
"enabled": true,
|
||||
"host": "127.0.0.1",
|
||||
"port": 5230,
|
||||
@@ -158,6 +158,7 @@
|
||||
"username": "",
|
||||
"app_password": "",
|
||||
"default_calendar": "",
|
||||
"default_task_calendar": "",
|
||||
"default_addressbook": "",
|
||||
"verify_tls": true,
|
||||
"timeout": 30
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"nextcloud_bridge_url": "Base URL of the local Nextcloud bridge, e.g. http://127.0.0.1:5230 (no trailing slash needed); used to list task lists and create the task.",
|
||||
"nextcloud_bridge_token": "Shared secret for the Nextcloud bridge, if one is configured; sent as the X-Semif-Token header. Leave blank when the bridge requires no auth.",
|
||||
"llm_bridge_url": "Base URL of the local LLM bridge, e.g. http://127.0.0.1:5229 (no trailing slash needed); used to phrase the task title and description.",
|
||||
"llm_bridge_token": "Shared secret for the LLM bridge, if one is configured; sent as the X-Semif-Token header. Leave blank when the bridge requires no auth."
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"description": "Add a single task to a Nextcloud task list from a request such as \"add a task to eat more hot dogs\"."
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
"""Add a single task to a Nextcloud task list.
|
||||
|
||||
Real integration: the Nextcloud bridge over HTTP, which fronts the user's
|
||||
Nextcloud (CalDAV VTODO). The bridge URL/token and the LLM bridge URL/token are
|
||||
operational values supplied through `ctx.config` (declared in CONTRACT); the task
|
||||
summary and description are derived from `request.text`.
|
||||
|
||||
`GET /tasklists` returns only VTODO-capable task lists (the bridge excludes
|
||||
event-only calendars and Nextcloud Deck boards), so a task can never be written
|
||||
to a collection that rejects it. When the account has several task lists the
|
||||
target is resolved by a single SemIf choice over them; otherwise the sole list is
|
||||
used. The task is created for real with `POST /tasks` and the real outcome is
|
||||
reported — a failure is never dressed up as success.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
|
||||
from semif_agent.decisions import DecisionRequest, Option
|
||||
from semif_agent.skills import ActionResult
|
||||
|
||||
INTEGRATION = {
|
||||
"service": "nextcloud",
|
||||
"transport": "http",
|
||||
"config_vars": [
|
||||
"nextcloud_bridge_url",
|
||||
"nextcloud_bridge_token",
|
||||
"llm_bridge_url",
|
||||
"llm_bridge_token",
|
||||
],
|
||||
}
|
||||
|
||||
CONTRACT = {
|
||||
"nextcloud_bridge_url": "Base URL of the local Nextcloud bridge, e.g. http://127.0.0.1:5230 (no trailing slash needed); used to list task lists and create the task.",
|
||||
"nextcloud_bridge_token": "Shared secret for the Nextcloud bridge, if one is configured; sent as the X-Semif-Token header. Leave blank when the bridge requires no auth.",
|
||||
"llm_bridge_url": "Base URL of the local LLM bridge, e.g. http://127.0.0.1:5229 (no trailing slash needed); used to phrase the task title and description.",
|
||||
"llm_bridge_token": "Shared secret for the LLM bridge, if one is configured; sent as the X-Semif-Token header. Leave blank when the bridge requires no auth.",
|
||||
}
|
||||
|
||||
|
||||
def _headers(token):
|
||||
"""Build request headers, sending the bridge token only when one is set."""
|
||||
headers = {"Content-Type": "application/json"}
|
||||
if token:
|
||||
headers["X-Semif-Token"] = token
|
||||
return headers
|
||||
|
||||
|
||||
def _call(method, url, headers, payload=None, timeout=25):
|
||||
"""Perform one HTTP call, returning (status, decoded_json_or_error_dict)."""
|
||||
data = json.dumps(payload).encode("utf-8") if payload is not None else None
|
||||
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||
try:
|
||||
with urllib.request.urlopen(req, timeout=timeout) as response:
|
||||
body = response.read().decode("utf-8")
|
||||
return response.status, (json.loads(body) if body else {})
|
||||
except urllib.error.HTTPError as exc:
|
||||
try:
|
||||
detail = json.loads(exc.read().decode("utf-8"))
|
||||
except Exception:
|
||||
detail = {"error": str(exc)}
|
||||
return exc.code, detail
|
||||
except (urllib.error.URLError, ValueError) as exc:
|
||||
return None, {"error": str(exc)}
|
||||
|
||||
|
||||
def _parse_json_object(text):
|
||||
"""Pull the first JSON object out of a model reply, or return None."""
|
||||
if not text:
|
||||
return None
|
||||
start = text.find("{")
|
||||
end = text.rfind("}")
|
||||
if start == -1 or end <= start:
|
||||
return None
|
||||
try:
|
||||
data = json.loads(text[start : end + 1])
|
||||
except ValueError:
|
||||
return None
|
||||
return data if isinstance(data, dict) else None
|
||||
|
||||
|
||||
def _extract_task(ctx, request):
|
||||
"""Ask the LLM bridge for (summary, description) of the task; else an error."""
|
||||
llm_url = str(ctx.config.get("llm_bridge_url", "") or "").rstrip("/")
|
||||
headers = _headers(ctx.config.get("llm_bridge_token", ""))
|
||||
messages = [
|
||||
{
|
||||
"role": "system",
|
||||
"content": (
|
||||
"You turn a user's request into a single to-do task. Reply with "
|
||||
'only a JSON object: {"summary": "<short task title>", '
|
||||
'"description": "<extra detail, or an empty string>"}.'
|
||||
),
|
||||
},
|
||||
{"role": "user", "content": request.text or ""},
|
||||
]
|
||||
status, payload = _call(
|
||||
"POST",
|
||||
f"{llm_url}/chat",
|
||||
headers,
|
||||
{"messages": messages, "max_tokens": 200},
|
||||
)
|
||||
if status != 200:
|
||||
return (
|
||||
None,
|
||||
None,
|
||||
f"could not phrase the task via the LLM bridge at {llm_url}: "
|
||||
f"status {status}, {payload.get('error', payload)}",
|
||||
)
|
||||
data = _parse_json_object(payload.get("text") or "")
|
||||
if not data or not str(data.get("summary") or "").strip():
|
||||
return (
|
||||
None,
|
||||
None,
|
||||
f"LLM bridge at {llm_url} returned no usable task text: "
|
||||
f"{payload.get('text')!r}",
|
||||
)
|
||||
return (
|
||||
str(data["summary"]).strip(),
|
||||
str(data.get("description") or "").strip(),
|
||||
None,
|
||||
)
|
||||
|
||||
|
||||
def act(ctx, request) -> ActionResult:
|
||||
"""Add one task to the chosen Nextcloud task list and report the result."""
|
||||
decisions = []
|
||||
base_url = str(ctx.config.get("nextcloud_bridge_url", "") or "").rstrip("/")
|
||||
nc_headers = _headers(ctx.config.get("nextcloud_bridge_token", ""))
|
||||
|
||||
# 1. Phrase the task from the request via the LLM bridge.
|
||||
summary, description, llm_error = _extract_task(ctx, request)
|
||||
if llm_error:
|
||||
return ActionResult(
|
||||
action_log=llm_error,
|
||||
new_state=request.text,
|
||||
decisions=decisions,
|
||||
)
|
||||
|
||||
# 2. Find the task list to write to (the bridge returns only VTODO-capable
|
||||
# task lists, so an event-only calendar can never be chosen).
|
||||
status, payload = _call("GET", f"{base_url}/tasklists", nc_headers)
|
||||
if status != 200:
|
||||
return ActionResult(
|
||||
action_log=(
|
||||
f"could not list Nextcloud task lists from {base_url}: "
|
||||
f"status {status}, {payload.get('error', payload)}"
|
||||
),
|
||||
new_state=request.text,
|
||||
decisions=decisions,
|
||||
)
|
||||
task_lists = [c for c in (payload.get("tasklists") or []) if c.get("name")]
|
||||
if not task_lists:
|
||||
return ActionResult(
|
||||
action_log="no Nextcloud task lists are available to add a task to",
|
||||
new_state=request.text,
|
||||
decisions=decisions,
|
||||
)
|
||||
|
||||
if len(task_lists) == 1:
|
||||
target = task_lists[0]["name"]
|
||||
else:
|
||||
decision = DecisionRequest(
|
||||
state=request.text,
|
||||
question="Which Nextcloud task list should the new task be added to?",
|
||||
options=[
|
||||
Option(c["name"], c.get("label") or c["name"]) for c in task_lists
|
||||
],
|
||||
)
|
||||
result = ctx.engine.call(decision)
|
||||
decisions.append((decision, result))
|
||||
target = result.selected
|
||||
target_label = next(
|
||||
(c.get("label") or c["name"] for c in task_lists if c["name"] == target),
|
||||
target,
|
||||
)
|
||||
|
||||
# 3. Create the task for real through the bridge.
|
||||
status, payload = _call(
|
||||
"POST",
|
||||
f"{base_url}/tasks",
|
||||
nc_headers,
|
||||
{"calendar": target, "summary": summary, "description": description},
|
||||
)
|
||||
if status != 200 or not payload.get("ok"):
|
||||
return ActionResult(
|
||||
action_log=(
|
||||
f"failed to add task \"{summary}\" to Nextcloud task list "
|
||||
f"\"{target_label}\": status {status}, {payload.get('error', payload)}"
|
||||
),
|
||||
new_state=request.text,
|
||||
decisions=decisions,
|
||||
)
|
||||
|
||||
uid = payload.get("uid", "")
|
||||
calendar = payload.get("calendar", target)
|
||||
report = (
|
||||
f'added task "{summary}" to Nextcloud task list "{target_label}" '
|
||||
f"(calendar={calendar}, uid={uid})"
|
||||
)
|
||||
return ActionResult(action_log=report, new_state=report, decisions=decisions)
|
||||
@@ -0,0 +1,345 @@
|
||||
"""Hermetic mechanics test for productivity_management.create_nextcloud_task.
|
||||
|
||||
Run from this folder: `python skill.test.py`. No external network: a loopback
|
||||
http.server plays the Nextcloud bridge (`GET /tasklists`, `POST /tasks`) and the
|
||||
LLM bridge's `POST /chat`. This proves the body phrases the task through the LLM
|
||||
bridge, picks a task list (the sole one, or a SemIf choice when there are
|
||||
several), creates the task through the bridge, and fails honestly when the LLM
|
||||
bridge or the Nextcloud bridge errors. It does NOT prove the live integration —
|
||||
only a real run against the user's Nextcloud does.
|
||||
"""
|
||||
|
||||
import json
|
||||
import socket
|
||||
import threading
|
||||
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
||||
|
||||
from semif_agent.decisions import Request
|
||||
from semif_agent.skills import ActionContext
|
||||
|
||||
import skill
|
||||
|
||||
|
||||
def make_handler(routes, seen):
|
||||
"""Build a request handler that records every request and replays `routes`."""
|
||||
|
||||
class Handler(BaseHTTPRequestHandler):
|
||||
def _respond(self):
|
||||
length = int(self.headers.get("Content-Length") or 0)
|
||||
raw = self.rfile.read(length) if length else b""
|
||||
try:
|
||||
body = json.loads(raw.decode("utf-8")) if raw else None
|
||||
except ValueError:
|
||||
body = raw.decode("utf-8", "replace")
|
||||
seen.append(
|
||||
{
|
||||
"method": self.command,
|
||||
"path": self.path,
|
||||
"headers": {k.lower(): v for k, v in self.headers.items()},
|
||||
"body": body,
|
||||
}
|
||||
)
|
||||
key = (self.command, self.path.split("?")[0])
|
||||
status, payload = routes.get(key, (404, {"error": "no route"}))
|
||||
data = json.dumps(payload).encode("utf-8")
|
||||
self.send_response(status)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.send_header("Content-Length", str(len(data)))
|
||||
self.end_headers()
|
||||
self.wfile.write(data)
|
||||
|
||||
do_GET = _respond
|
||||
do_POST = _respond
|
||||
|
||||
def log_message(self, *args):
|
||||
pass
|
||||
|
||||
return Handler
|
||||
|
||||
|
||||
def start_server(routes):
|
||||
seen = []
|
||||
server = ThreadingHTTPServer(("127.0.0.1", 0), make_handler(routes, seen))
|
||||
threading.Thread(target=server.serve_forever, daemon=True).start()
|
||||
url = "http://127.0.0.1:%d" % server.server_address[1]
|
||||
return server, seen, url
|
||||
|
||||
|
||||
def stop(server):
|
||||
server.shutdown()
|
||||
server.server_close()
|
||||
|
||||
|
||||
def closed_port_url():
|
||||
sock = socket.socket()
|
||||
sock.bind(("127.0.0.1", 0))
|
||||
port = sock.getsockname()[1]
|
||||
sock.close()
|
||||
return "http://127.0.0.1:%d" % port
|
||||
|
||||
|
||||
class FakeResult:
|
||||
"""Minimal stand-in for a DecisionResult: the body only reads `.selected`."""
|
||||
|
||||
def __init__(self, selected):
|
||||
self.selected = selected
|
||||
|
||||
|
||||
class FakeEngine:
|
||||
"""Test-only decision engine; records the requests the body asked for."""
|
||||
|
||||
def __init__(self, choice=None):
|
||||
self.choice = choice
|
||||
self.calls = []
|
||||
|
||||
def call(self, decision):
|
||||
self.calls.append(decision)
|
||||
return FakeResult(self.choice)
|
||||
|
||||
|
||||
def test_happy_path_single_task_list():
|
||||
llm_routes = {
|
||||
("POST", "/chat"): (
|
||||
200,
|
||||
{
|
||||
"text": '{"summary": "Eat hot dogs", '
|
||||
'"description": "Buy and eat hot dogs"}'
|
||||
},
|
||||
)
|
||||
}
|
||||
nc_routes = {
|
||||
("GET", "/tasklists"): (
|
||||
200,
|
||||
{"tasklists": [{"name": "tasks", "label": "Tasks"}]},
|
||||
),
|
||||
("POST", "/tasks"): (
|
||||
200,
|
||||
{"ok": True, "uid": "uid-1", "calendar": "tasks"},
|
||||
),
|
||||
}
|
||||
llm_server, llm_seen, llm_url = start_server(llm_routes)
|
||||
nc_server, nc_seen, nc_url = start_server(nc_routes)
|
||||
try:
|
||||
engine = FakeEngine()
|
||||
ctx = ActionContext(
|
||||
engine=engine,
|
||||
config={
|
||||
"nextcloud_bridge_url": nc_url,
|
||||
"nextcloud_bridge_token": "nc-secret",
|
||||
"llm_bridge_url": llm_url,
|
||||
"llm_bridge_token": "llm-secret",
|
||||
},
|
||||
)
|
||||
request = Request("Add a task in next cloud for eating hot dogs.")
|
||||
result = skill.act(ctx, request)
|
||||
|
||||
assert not engine.calls, "a single task list must not need a decision"
|
||||
assert "Eat hot dogs" in result.action_log, result.action_log
|
||||
assert "Tasks" in result.action_log, result.action_log
|
||||
assert "uid-1" in result.action_log, result.action_log
|
||||
|
||||
assert len(llm_seen) == 1, llm_seen
|
||||
chat = llm_seen[0]
|
||||
assert chat["method"] == "POST", chat
|
||||
assert chat["path"] == "/chat", chat
|
||||
assert chat["headers"].get("x-semif-token") == "llm-secret", chat["headers"]
|
||||
assert chat["body"]["messages"][1]["content"] == request.text, chat["body"]
|
||||
assert "summary" in chat["body"]["messages"][0]["content"], chat["body"]
|
||||
|
||||
assert [r["path"] for r in nc_seen] == ["/tasklists", "/tasks"], nc_seen
|
||||
listing = nc_seen[0]
|
||||
assert listing["method"] == "GET", listing
|
||||
assert listing["headers"].get("x-semif-token") == "nc-secret", listing["headers"]
|
||||
create = nc_seen[1]
|
||||
assert create["method"] == "POST", create
|
||||
assert create["headers"].get("x-semif-token") == "nc-secret", create["headers"]
|
||||
assert create["body"] == {
|
||||
"calendar": "tasks",
|
||||
"summary": "Eat hot dogs",
|
||||
"description": "Buy and eat hot dogs",
|
||||
}, create["body"]
|
||||
print("happy path:", result.action_log)
|
||||
finally:
|
||||
stop(llm_server)
|
||||
stop(nc_server)
|
||||
|
||||
|
||||
def test_multiple_task_lists_asks_and_omits_token_header():
|
||||
llm_routes = {
|
||||
("POST", "/chat"): (200, {"text": '{"summary": "Eat hot dogs"}'})
|
||||
}
|
||||
nc_routes = {
|
||||
("GET", "/tasklists"): (
|
||||
200,
|
||||
{
|
||||
"tasklists": [
|
||||
{"name": "tasks", "label": "Tasks"},
|
||||
{"name": "work", "label": "Work"},
|
||||
]
|
||||
},
|
||||
),
|
||||
("POST", "/tasks"): (200, {"ok": True, "uid": "uid-2", "calendar": "work"}),
|
||||
}
|
||||
llm_server, llm_seen, llm_url = start_server(llm_routes)
|
||||
nc_server, nc_seen, nc_url = start_server(nc_routes)
|
||||
try:
|
||||
engine = FakeEngine(choice="work")
|
||||
ctx = ActionContext(
|
||||
engine=engine,
|
||||
config={
|
||||
"nextcloud_bridge_url": nc_url,
|
||||
"nextcloud_bridge_token": "",
|
||||
"llm_bridge_url": llm_url,
|
||||
"llm_bridge_token": "",
|
||||
},
|
||||
)
|
||||
result = skill.act(
|
||||
ctx, Request("Add a task in next cloud for eating hot dogs.")
|
||||
)
|
||||
|
||||
assert len(engine.calls) == 1, "two task lists must trigger one decision"
|
||||
decision = engine.calls[0]
|
||||
assert [o.id for o in decision.options] == ["tasks", "work"], decision.options
|
||||
assert result.decisions, "the decision must be recorded on the result"
|
||||
|
||||
assert "x-semif-token" not in llm_seen[0]["headers"], llm_seen[0]["headers"]
|
||||
create = nc_seen[-1]
|
||||
assert create["path"] == "/tasks", create
|
||||
assert create["body"]["calendar"] == "work", create["body"]
|
||||
assert create["body"]["description"] == "", create["body"]
|
||||
assert "x-semif-token" not in create["headers"], create["headers"]
|
||||
assert "Work" in result.action_log, result.action_log
|
||||
print("decision path:", result.action_log)
|
||||
finally:
|
||||
stop(llm_server)
|
||||
stop(nc_server)
|
||||
|
||||
|
||||
def test_llm_bridge_failure_leaves_nextcloud_untouched():
|
||||
llm_routes = {("POST", "/chat"): (502, {"error": "model down"})}
|
||||
nc_routes = {
|
||||
("GET", "/tasklists"): (200, {"tasklists": [{"name": "tasks"}]})
|
||||
}
|
||||
llm_server, _llm_seen, llm_url = start_server(llm_routes)
|
||||
nc_server, nc_seen, nc_url = start_server(nc_routes)
|
||||
try:
|
||||
ctx = ActionContext(
|
||||
engine=FakeEngine(),
|
||||
config={
|
||||
"nextcloud_bridge_url": nc_url,
|
||||
"llm_bridge_url": llm_url,
|
||||
},
|
||||
)
|
||||
result = skill.act(ctx, Request("Add a task in next cloud for hot dogs."))
|
||||
assert "could not phrase the task" in result.action_log, result.action_log
|
||||
assert "model down" in result.action_log, result.action_log
|
||||
assert nc_seen == [], "Nextcloud must not be touched when phrasing fails"
|
||||
print("llm failure:", result.action_log)
|
||||
finally:
|
||||
stop(llm_server)
|
||||
stop(nc_server)
|
||||
|
||||
|
||||
def test_llm_reply_without_task_text():
|
||||
llm_routes = {("POST", "/chat"): (200, {"text": "I cannot help with that."})}
|
||||
nc_routes = {
|
||||
("GET", "/tasklists"): (200, {"tasklists": [{"name": "tasks"}]})
|
||||
}
|
||||
llm_server, _llm_seen, llm_url = start_server(llm_routes)
|
||||
nc_server, nc_seen, nc_url = start_server(nc_routes)
|
||||
try:
|
||||
ctx = ActionContext(
|
||||
engine=FakeEngine(),
|
||||
config={"nextcloud_bridge_url": nc_url, "llm_bridge_url": llm_url},
|
||||
)
|
||||
result = skill.act(ctx, Request("do something vague"))
|
||||
assert "no usable task text" in result.action_log, result.action_log
|
||||
assert nc_seen == [], "Nextcloud must not be touched without a task title"
|
||||
print("unusable llm reply:", result.action_log)
|
||||
finally:
|
||||
stop(llm_server)
|
||||
stop(nc_server)
|
||||
|
||||
|
||||
def test_no_task_lists_available():
|
||||
llm_routes = {
|
||||
("POST", "/chat"): (200, {"text": '{"summary": "Eat hot dogs"}'})
|
||||
}
|
||||
nc_routes = {("GET", "/tasklists"): (200, {"tasklists": []})}
|
||||
llm_server, _llm_seen, llm_url = start_server(llm_routes)
|
||||
nc_server, nc_seen, nc_url = start_server(nc_routes)
|
||||
try:
|
||||
ctx = ActionContext(
|
||||
engine=FakeEngine(),
|
||||
config={"nextcloud_bridge_url": nc_url, "llm_bridge_url": llm_url},
|
||||
)
|
||||
result = skill.act(ctx, Request("Add a task in next cloud for hot dogs."))
|
||||
assert "no Nextcloud task lists" in result.action_log, result.action_log
|
||||
assert [r["path"] for r in nc_seen] == ["/tasklists"], nc_seen
|
||||
print("no task lists:", result.action_log)
|
||||
finally:
|
||||
stop(llm_server)
|
||||
stop(nc_server)
|
||||
|
||||
|
||||
def test_unreachable_nextcloud_bridge():
|
||||
llm_routes = {
|
||||
("POST", "/chat"): (200, {"text": '{"summary": "Eat hot dogs"}'})
|
||||
}
|
||||
llm_server, _llm_seen, llm_url = start_server(llm_routes)
|
||||
try:
|
||||
ctx = ActionContext(
|
||||
engine=FakeEngine(),
|
||||
config={
|
||||
"nextcloud_bridge_url": closed_port_url(),
|
||||
"llm_bridge_url": llm_url,
|
||||
},
|
||||
)
|
||||
result = skill.act(ctx, Request("Add a task in next cloud for hot dogs."))
|
||||
assert "could not list Nextcloud task lists" in result.action_log, result.action_log
|
||||
print("unreachable nextcloud:", result.action_log)
|
||||
finally:
|
||||
stop(llm_server)
|
||||
|
||||
|
||||
def test_task_creation_failure_is_reported():
|
||||
llm_routes = {
|
||||
("POST", "/chat"): (200, {"text": '{"summary": "Eat hot dogs"}'})
|
||||
}
|
||||
nc_routes = {
|
||||
("GET", "/tasklists"): (
|
||||
200,
|
||||
{"tasklists": [{"name": "tasks", "label": "Tasks"}]},
|
||||
),
|
||||
("POST", "/tasks"): (502, {"error": "CalDAV rejected the VTODO"}),
|
||||
}
|
||||
llm_server, _llm_seen, llm_url = start_server(llm_routes)
|
||||
nc_server, nc_seen, nc_url = start_server(nc_routes)
|
||||
try:
|
||||
ctx = ActionContext(
|
||||
engine=FakeEngine(),
|
||||
config={"nextcloud_bridge_url": nc_url, "llm_bridge_url": llm_url},
|
||||
)
|
||||
result = skill.act(ctx, Request("Add a task in next cloud for hot dogs."))
|
||||
assert "failed to add task" in result.action_log, result.action_log
|
||||
assert "CalDAV rejected the VTODO" in result.action_log, result.action_log
|
||||
assert [r["path"] for r in nc_seen] == ["/tasklists", "/tasks"], nc_seen
|
||||
print("creation failure:", result.action_log)
|
||||
finally:
|
||||
stop(llm_server)
|
||||
stop(nc_server)
|
||||
|
||||
|
||||
def main():
|
||||
test_happy_path_single_task_list()
|
||||
test_multiple_task_lists_asks_and_omits_token_header()
|
||||
test_llm_bridge_failure_leaves_nextcloud_untouched()
|
||||
test_llm_reply_without_task_text()
|
||||
test_no_task_lists_available()
|
||||
test_unreachable_nextcloud_bridge()
|
||||
test_task_creation_failure_is_reported()
|
||||
print("ok")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -26,6 +26,45 @@ import uuid
|
||||
from .base import BridgeInfo, BridgeService
|
||||
from .nextcloud_client import DEFAULT_TIMEOUT, NextcloudClient, NextcloudError
|
||||
|
||||
#: Nextcloud Deck backs each board with a VTODO-only calendar named like this.
|
||||
_DECK_PREFIX = "app-generated--deck--"
|
||||
|
||||
_COMPONENT_KINDS = {
|
||||
"VTODO": "task list",
|
||||
"VEVENT": "event calendar",
|
||||
"VJOURNAL": "journal",
|
||||
}
|
||||
|
||||
|
||||
def _supports(calendar: dict, component: str) -> bool:
|
||||
"""Whether a calendar accepts `component`; unknown (empty) means allow."""
|
||||
components = calendar.get("components") or []
|
||||
return not components or component in components
|
||||
|
||||
|
||||
def _is_deck_board(calendar: dict) -> bool:
|
||||
return str(calendar.get("name") or "").startswith(_DECK_PREFIX)
|
||||
|
||||
|
||||
def _component_kind(component: str) -> str:
|
||||
return _COMPONENT_KINDS.get(component, "calendar of that kind")
|
||||
|
||||
|
||||
def _join_components(calendar: dict) -> str:
|
||||
components = calendar.get("components") or []
|
||||
return ", ".join(components) if components else "an unknown component set"
|
||||
|
||||
|
||||
def _task_list_hint(calendars: list[dict]) -> str:
|
||||
names = [
|
||||
c["name"]
|
||||
for c in calendars
|
||||
if _supports(c, "VTODO") and not _is_deck_board(c)
|
||||
]
|
||||
if names:
|
||||
return "task lists: " + ", ".join(names)
|
||||
return "no VTODO-capable task lists are available"
|
||||
|
||||
|
||||
class NextcloudBridge(BridgeService):
|
||||
name = "nextcloud"
|
||||
@@ -62,7 +101,12 @@ class NextcloudBridge(BridgeService):
|
||||
"POST /files/copy {\"path\", \"destination\", \"overwrite\"?: bool} "
|
||||
"-> 200 {\"ok\": true, \"path\", \"destination\"}",
|
||||
"GET /calendars -> 200 {\"calendars\": [{name, label, description, "
|
||||
"color, ctag}]}",
|
||||
"color, ctag, components}]} — components lists the CalDAV component "
|
||||
"types each collection accepts (VEVENT, VTODO, VJOURNAL)",
|
||||
"GET /tasklists -> 200 {\"tasklists\": [{name, label, description, "
|
||||
"color, ctag, components}]} — the user's task lists (calendars that "
|
||||
"accept VTODO), excluding Nextcloud Deck boards; use this to pick a "
|
||||
"target for POST /tasks",
|
||||
"GET /calendars/events?calendar=<name>&start=<iso>&end=<iso> -> 200 "
|
||||
"{\"calendar\", \"events\": [{uid, summary, start, end, all_day, "
|
||||
"location, description, rrule, status, href, etag}]} — start/end "
|
||||
@@ -79,10 +123,12 @@ class NextcloudBridge(BridgeService):
|
||||
"{\"ok\": true, \"uid\", \"calendar\"}",
|
||||
"GET /tasks?calendar=<name> -> 200 {\"calendar\", \"tasks\": [{uid, "
|
||||
"summary, due, status, percent_complete, priority, description, href, "
|
||||
"etag}]} — CalDAV VTODO",
|
||||
"etag}]} — CalDAV VTODO; calendar must be a VTODO-capable task list "
|
||||
"(see GET /tasklists), defaulting to the configured task calendar",
|
||||
"POST /tasks {\"calendar\"?, \"uid\"?, \"summary\", \"due\"?, "
|
||||
"\"priority\"?, \"description\"?} -> 200 {\"ok\": true, \"uid\", "
|
||||
"\"calendar\", \"etag\"}",
|
||||
"\"calendar\", \"etag\"} — calendar must be a VTODO-capable task list "
|
||||
"(see GET /tasklists); an event-only calendar is rejected with 400",
|
||||
"POST /tasks/update {\"calendar\"?, \"uid\", \"summary\"?, \"due\"?, "
|
||||
"\"priority\"?, \"description\"?, \"status\"?, \"percent_complete\"?} "
|
||||
"-> 200 {ok, uid}",
|
||||
@@ -148,6 +194,7 @@ class NextcloudBridge(BridgeService):
|
||||
self.username = str(pick("username")).strip()
|
||||
self.app_password = str(pick("app_password"))
|
||||
self.default_calendar = str(pick("default_calendar")).strip()
|
||||
self.default_task_calendar = str(pick("default_task_calendar")).strip()
|
||||
self.default_addressbook = str(pick("default_addressbook")).strip()
|
||||
self.verify_tls = bool(cfg.get("verify_tls", fb.get("verify_tls", True)))
|
||||
self.timeout = float(cfg.get("timeout", DEFAULT_TIMEOUT))
|
||||
@@ -222,6 +269,8 @@ class NextcloudBridge(BridgeService):
|
||||
}
|
||||
if path == "/calendars":
|
||||
return 200, {"calendars": self.client.list_calendars()}
|
||||
if path == "/tasklists":
|
||||
return 200, {"tasklists": self._task_lists()}
|
||||
if path == "/calendars/events":
|
||||
calendar = self._resolve_calendar(self._q(query, "calendar"))
|
||||
return 200, {
|
||||
@@ -233,7 +282,7 @@ class NextcloudBridge(BridgeService):
|
||||
),
|
||||
}
|
||||
if path == "/tasks":
|
||||
calendar = self._resolve_calendar(self._q(query, "calendar"))
|
||||
calendar = self._resolve_calendar(self._q(query, "calendar"), "VTODO")
|
||||
return 200, {"calendar": calendar, "tasks": self.client.list_tasks(calendar)}
|
||||
if path == "/addressbooks":
|
||||
return 200, {"addressbooks": self.client.list_addressbooks()}
|
||||
@@ -287,10 +336,10 @@ class NextcloudBridge(BridgeService):
|
||||
if path == "/tasks/update":
|
||||
return 200, self._update_task(payload)
|
||||
if path == "/tasks/complete":
|
||||
calendar = self._resolve_calendar(self._optional_str(payload, "calendar"))
|
||||
calendar = self._resolve_calendar(self._optional_str(payload, "calendar"), "VTODO")
|
||||
return 200, self.client.complete_task(calendar, self._required(payload, "uid"))
|
||||
if path == "/tasks/delete":
|
||||
calendar = self._resolve_calendar(self._optional_str(payload, "calendar"))
|
||||
calendar = self._resolve_calendar(self._optional_str(payload, "calendar"), "VTODO")
|
||||
return 200, self.client.delete_object(calendar, self._required(payload, "uid"))
|
||||
if path == "/contacts":
|
||||
return 200, self._create_contact(payload)
|
||||
@@ -348,7 +397,7 @@ class NextcloudBridge(BridgeService):
|
||||
return self.client.update_event(calendar, uid, **changes)
|
||||
|
||||
def _create_task(self, payload: dict) -> dict:
|
||||
calendar = self._resolve_calendar(self._optional_str(payload, "calendar"))
|
||||
calendar = self._resolve_calendar(self._optional_str(payload, "calendar"), "VTODO")
|
||||
uid = self._optional_str(payload, "uid") or uuid.uuid4().hex
|
||||
return self.client.create_task(
|
||||
calendar,
|
||||
@@ -360,7 +409,7 @@ class NextcloudBridge(BridgeService):
|
||||
)
|
||||
|
||||
def _update_task(self, payload: dict) -> dict:
|
||||
calendar = self._resolve_calendar(self._optional_str(payload, "calendar"))
|
||||
calendar = self._resolve_calendar(self._optional_str(payload, "calendar"), "VTODO")
|
||||
uid = self._required(payload, "uid")
|
||||
changes = {
|
||||
key: payload[key]
|
||||
@@ -410,17 +459,71 @@ class NextcloudBridge(BridgeService):
|
||||
|
||||
# ---- default resolution ----
|
||||
|
||||
def _resolve_calendar(self, name) -> str:
|
||||
name = str(name or self.default_calendar or "").strip()
|
||||
if name:
|
||||
return name
|
||||
def _resolve_calendar(self, name, component: str | None = None) -> str:
|
||||
"""Resolve a calendar name, honoring the CalDAV component it must accept.
|
||||
|
||||
An explicit name is validated when the collection's component set is
|
||||
known: asking a task operation to write to an event-only calendar is a
|
||||
real error (a `VTODO` PUT there is rejected), not a silent redirect. With
|
||||
no name, a task operation falls back to the configured task calendar, then
|
||||
the event default when it also accepts VTODO, then the sole user task
|
||||
list. `component=None` (events, files) keeps the historical behavior.
|
||||
"""
|
||||
requested = str(name or "").strip()
|
||||
if requested:
|
||||
if component:
|
||||
calendars = self.client.list_calendars()
|
||||
match = next((c for c in calendars if c.get("name") == requested), None)
|
||||
if match is not None and not _supports(match, component):
|
||||
raise ValueError(
|
||||
f"{requested!r} is not a {_component_kind(component)} "
|
||||
f"(it accepts {_join_components(match)}); "
|
||||
f"{_task_list_hint(calendars)}"
|
||||
)
|
||||
return requested
|
||||
|
||||
# The configured defaults, most specific first. For a task operation the
|
||||
# event default is still consulted when it also accepts VTODO.
|
||||
defaults = [self.default_task_calendar] if component == "VTODO" else []
|
||||
defaults.append(self.default_calendar)
|
||||
calendars = None
|
||||
for default in defaults:
|
||||
if not default:
|
||||
continue
|
||||
if not component:
|
||||
return default
|
||||
if calendars is None:
|
||||
calendars = self.client.list_calendars()
|
||||
match = next((c for c in calendars if c.get("name") == default), None)
|
||||
if match is None or _supports(match, component):
|
||||
return default
|
||||
|
||||
if calendars is None:
|
||||
calendars = self.client.list_calendars()
|
||||
if component:
|
||||
calendars = [c for c in calendars if _supports(c, component)]
|
||||
if component == "VTODO":
|
||||
calendars = [c for c in calendars if not _is_deck_board(c)]
|
||||
if len(calendars) == 1:
|
||||
return calendars[0]["name"]
|
||||
raise ValueError(
|
||||
"calendar is required (name one in the request, or set "
|
||||
"bridges.nextcloud.default_calendar)"
|
||||
f"calendar is required (name one in the request, or set "
|
||||
f"bridges.nextcloud.default_calendar"
|
||||
+ (
|
||||
" / default_task_calendar"
|
||||
if component == "VTODO"
|
||||
else ""
|
||||
)
|
||||
+ ")"
|
||||
)
|
||||
|
||||
def _task_lists(self) -> list[dict]:
|
||||
"""The user's task lists: VTODO-capable calendars, minus Deck boards."""
|
||||
return [
|
||||
calendar
|
||||
for calendar in self.client.list_calendars()
|
||||
if _supports(calendar, "VTODO") and not _is_deck_board(calendar)
|
||||
]
|
||||
|
||||
def _resolve_addressbook(self, name) -> str:
|
||||
name = str(name or self.default_addressbook or "").strip()
|
||||
|
||||
@@ -57,6 +57,23 @@ def _int(value, default=None):
|
||||
return default
|
||||
|
||||
|
||||
def _component_set(prop) -> list[str]:
|
||||
"""The component types a calendar accepts (`VEVENT`/`VTODO`/`VJOURNAL`).
|
||||
|
||||
Parsed from the CalDAV `supported-calendar-component-set` property. An empty
|
||||
list means the server did not advertise it (unknown), not "accepts nothing".
|
||||
"""
|
||||
node = prop.find(f"{{{CALDAV}}}supported-calendar-component-set")
|
||||
if node is None:
|
||||
return []
|
||||
names = []
|
||||
for comp in node.findall(f"{{{CALDAV}}}comp"):
|
||||
name = (comp.get("name") or "").strip().upper()
|
||||
if name:
|
||||
names.append(name)
|
||||
return names
|
||||
|
||||
|
||||
def _norm_path(path) -> str:
|
||||
"""A user-facing DAV path: always leading `/`, no trailing slash (root `/`)."""
|
||||
text = "/" + str(path or "").strip("/")
|
||||
@@ -457,6 +474,7 @@ _CALENDAR_PROPFIND = (
|
||||
'<d:propfind xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav" '
|
||||
'xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns">'
|
||||
"<d:prop><d:resourcetype/><d:displayname/><c:calendar-description/>"
|
||||
"<c:supported-calendar-component-set/>"
|
||||
"<c:getctag/><oc:getctag/><nc:calendar-color/><oc:calendar-color/></d:prop>"
|
||||
"</d:propfind>"
|
||||
).encode("utf-8")
|
||||
@@ -860,6 +878,7 @@ class NextcloudClient:
|
||||
ctag = _text(prop.find(f"{{{CALDAV}}}getctag")) or _text(
|
||||
prop.find(f"{{{OC}}}getctag")
|
||||
)
|
||||
components = _component_set(prop)
|
||||
calendars.append(
|
||||
{
|
||||
"name": name,
|
||||
@@ -867,6 +886,7 @@ class NextcloudClient:
|
||||
"description": _text(prop.find(f"{{{CALDAV}}}calendar-description")),
|
||||
"color": color,
|
||||
"ctag": ctag,
|
||||
"components": components,
|
||||
}
|
||||
)
|
||||
calendars.sort(key=lambda calendar: calendar["name"].lower())
|
||||
|
||||
@@ -124,6 +124,7 @@ def build_bridge(
|
||||
"username": config.get("nextcloud_username"),
|
||||
"app_password": config.get("nextcloud_app_password"),
|
||||
"default_calendar": config.get("nextcloud_default_calendar"),
|
||||
"default_task_calendar": config.get("nextcloud_default_task_calendar"),
|
||||
"default_addressbook": config.get("nextcloud_default_addressbook"),
|
||||
},
|
||||
)
|
||||
|
||||
@@ -668,6 +668,10 @@ CATEGORY_DESCRIPTIONS: dict[str, str] = {
|
||||
"Time and date utilities: telling the current time or date, setting "
|
||||
"countdown timers, and setting alarms."
|
||||
),
|
||||
"productivity_management": (
|
||||
"Personal productivity: creating and managing the user's to-do tasks "
|
||||
"and task lists."
|
||||
),
|
||||
"housekeeping": (
|
||||
"Agent self-maintenance: deleting, reconfiguring, regenerating, and "
|
||||
"cancelling the agent's own skills."
|
||||
|
||||
@@ -48,7 +48,9 @@ class FakeNextcloud:
|
||||
"/Documents/readme.txt": {"type": "file", "content": b"hello world"},
|
||||
"/image.png": {"type": "file", "content": b"\x89PNG\x00\xff"},
|
||||
}
|
||||
self.calendars = {"personal": {"label": "Personal", "objects": {}}}
|
||||
self.calendars = {
|
||||
"personal": {"label": "Personal", "components": ["VEVENT"], "objects": {}}
|
||||
}
|
||||
self.addressbooks = {"contacts": {"label": "Contacts", "cards": {}}}
|
||||
self.notes = {}
|
||||
self._next_note_id = 1
|
||||
@@ -257,12 +259,16 @@ class FakeNextcloud:
|
||||
)
|
||||
]
|
||||
for name, calendar in self.calendars.items():
|
||||
components = calendar.get("components") or ["VEVENT"]
|
||||
comp_xml = "".join(f'<c:comp name="{c}"/>' for c in components)
|
||||
responses.append(
|
||||
self._response(
|
||||
f"/remote.php/dav/calendars/{USER}/{name}/",
|
||||
"<d:resourcetype><d:collection/><c:calendar/></d:resourcetype>"
|
||||
f"<d:displayname>{calendar['label']}</d:displayname>"
|
||||
"<c:calendar-description>desc</c:calendar-description>"
|
||||
f"<c:supported-calendar-component-set>{comp_xml}"
|
||||
"</c:supported-calendar-component-set>"
|
||||
'<nc:calendar-color>#ff0000</nc:calendar-color>'
|
||||
"<c:getctag>ctag-1</c:getctag>",
|
||||
)
|
||||
@@ -546,6 +552,7 @@ def test_list_calendars(nextcloud):
|
||||
"description": "desc",
|
||||
"color": "#ff0000",
|
||||
"ctag": "ctag-1",
|
||||
"components": ["VEVENT"],
|
||||
}
|
||||
]
|
||||
|
||||
@@ -809,6 +816,83 @@ def test_bridge_uses_only_calendar_when_unset(nextcloud):
|
||||
assert status == 200 and payload["calendar"] == "personal"
|
||||
|
||||
|
||||
# ---- bridge: task-list resolution ----
|
||||
|
||||
|
||||
def test_bridge_tasklists_exclude_event_calendars_and_deck(nextcloud):
|
||||
fake, base = nextcloud
|
||||
fake.calendars["tasks"] = {"label": "Tasks", "components": ["VTODO"], "objects": {}}
|
||||
fake.calendars["app-generated--deck--board-1"] = {
|
||||
"label": "Deck: Board",
|
||||
"components": ["VTODO"],
|
||||
"objects": {},
|
||||
}
|
||||
status, payload = bridge_for(base).handle_get("/tasklists", {})
|
||||
assert status == 200
|
||||
assert [c["name"] for c in payload["tasklists"]] == ["tasks"]
|
||||
|
||||
|
||||
def test_bridge_create_task_uses_default_task_calendar(nextcloud):
|
||||
fake, base = nextcloud
|
||||
fake.calendars["tasks"] = {"label": "Tasks", "components": ["VTODO"], "objects": {}}
|
||||
status, payload = bridge_for(base, default_task_calendar="tasks").handle_post(
|
||||
"/tasks", {"summary": "Buy milk"}
|
||||
)
|
||||
assert status == 200
|
||||
assert payload["ok"] is True and payload["calendar"] == "tasks"
|
||||
|
||||
|
||||
def test_bridge_create_task_resolves_sole_task_list(nextcloud):
|
||||
fake, base = nextcloud
|
||||
fake.calendars["tasks"] = {"label": "Tasks", "components": ["VTODO"], "objects": {}}
|
||||
# default_calendar points at an event-only calendar; a task must skip it.
|
||||
status, payload = bridge_for(base, default_calendar="personal").handle_post(
|
||||
"/tasks", {"summary": "Buy milk"}
|
||||
)
|
||||
assert status == 200 and payload["calendar"] == "tasks"
|
||||
|
||||
|
||||
def test_bridge_task_default_must_accept_vtodo(nextcloud):
|
||||
fake, base = nextcloud
|
||||
fake.calendars["tasks"] = {"label": "Tasks", "components": ["VTODO"], "objects": {}}
|
||||
status, payload = bridge_for(base, default_task_calendar="personal").handle_post(
|
||||
"/tasks", {"summary": "Buy milk"}
|
||||
)
|
||||
assert status == 200 and payload["calendar"] == "tasks"
|
||||
|
||||
|
||||
def test_bridge_task_prefers_vtodo_capable_default_calendar(nextcloud):
|
||||
fake, base = nextcloud
|
||||
fake.calendars["morgan"] = {
|
||||
"label": "Morgan",
|
||||
"components": ["VEVENT", "VTODO"],
|
||||
"objects": {},
|
||||
}
|
||||
fake.calendars["other"] = {"label": "Other", "components": ["VTODO"], "objects": {}}
|
||||
status, payload = bridge_for(base, default_calendar="morgan").handle_post(
|
||||
"/tasks", {"summary": "Buy milk"}
|
||||
)
|
||||
assert status == 200 and payload["calendar"] == "morgan"
|
||||
|
||||
|
||||
def test_bridge_create_task_rejects_event_calendar(nextcloud):
|
||||
_fake, base = nextcloud
|
||||
status, payload = bridge_for(base).handle_post(
|
||||
"/tasks", {"calendar": "personal", "summary": "Buy milk"}
|
||||
)
|
||||
assert status == 400
|
||||
assert "not a task list" in payload["error"]
|
||||
|
||||
|
||||
def test_bridge_task_requires_calendar_when_ambiguous(nextcloud):
|
||||
fake, base = nextcloud
|
||||
fake.calendars["tasks-a"] = {"label": "Tasks A", "components": ["VTODO"], "objects": {}}
|
||||
fake.calendars["tasks-b"] = {"label": "Tasks B", "components": ["VTODO"], "objects": {}}
|
||||
status, payload = bridge_for(base).handle_post("/tasks", {"summary": "Buy milk"})
|
||||
assert status == 400
|
||||
assert "calendar is required" in payload["error"]
|
||||
|
||||
|
||||
def test_bridge_maps_nextcloud_error_to_502(nextcloud):
|
||||
_fake, base = nextcloud
|
||||
status, payload = bridge_for(base).handle_get("/files/read", {"path": ["/missing.txt"]})
|
||||
|
||||
@@ -38,6 +38,7 @@ def test_expected_seeds_exist():
|
||||
assert "time.date" in ids
|
||||
assert "time.set_timer" in ids
|
||||
assert "time.set_alarm" in ids
|
||||
assert "productivity_management.create_nextcloud_task" in ids
|
||||
|
||||
|
||||
@pytest.mark.parametrize("seed", SEED_DIRS, ids=[seed_id(s) for s in SEED_DIRS])
|
||||
|
||||
Reference in new issue
Block a user