skills: route create_event/next_event through the bridge
Both skills spoke CalDAV directly and declared the account as flat contract vars (nextcloud_url/username/app_password/default_calendar). Bootstrap now stores the account under bridges.nextcloud and only the derived nextcloud_bridge_url/_token reach ctx.config, so the runner asked for the URL and credentials on first fire. Call the bridge instead, like create_task: - create_event: GET /calendars -> SemIf choice -> POST /calendars/events - next_event: GET /calendars -> SemIf choice -> GET /calendars/events The bridge gains two small affordances so the skills keep their behavior: - GET /calendars also returns the configured default calendar name - GET /calendars/events expands recurrences server-side when given a window
This commit is contained in:
1 parent
ace251a829
commit
1a1d28dffd
9 files changed
+486
-748
No files matched your search
+12
-7
@@ -9,10 +9,10 @@ token-guarded localhost JSON API, so a body only reads `nextcloud_bridge_url` an
|
||||
|
||||
There is no service daemon: Nextcloud is plain HTTPS, so the bridge is stdlib-only
|
||||
(`urllib` + `xml.etree`) and starts instantly. The connection comes from
|
||||
`bridges.nextcloud` (url/username/app_password/default_calendar/default_addressbook),
|
||||
falling back to the top-level `nextcloud_url`/`nextcloud_username`/
|
||||
`nextcloud_app_password`/`nextcloud_default_calendar` values the nextcloud pack's skills
|
||||
already use, so the same account is configured in one place.
|
||||
`bridges.nextcloud` (url/username/app_password/default_calendar/default_addressbook);
|
||||
`from_config` also accepts the top-level `nextcloud_url`/`nextcloud_username`/
|
||||
`nextcloud_app_password`/`nextcloud_default_calendar` values as a fallback for a
|
||||
hand-edited config, so the same account is configured in one place.
|
||||
|
||||
The actual DAV/OCS work lives in `nextcloud_client.py`; the routes here validate
|
||||
input and map a real failure (`NextcloudError`) to a 502 rather than a fabricated
|
||||
@@ -101,7 +101,8 @@ class NextcloudBridge(BridgeService):
|
||||
"POST /files/copy {\"path\", \"destination\", \"overwrite\"?: bool} "
|
||||
"-> 200 {\"ok\": true, \"path\", \"destination\"}",
|
||||
"GET /calendars -> 200 {\"calendars\": [{name, label, description, "
|
||||
"color, ctag, components}]} — components lists the CalDAV component "
|
||||
"color, ctag, components}], \"default\": \"<configured default "
|
||||
"calendar name, or empty>\"} — 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 "
|
||||
@@ -110,7 +111,8 @@ class NextcloudBridge(BridgeService):
|
||||
"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 "
|
||||
"optional (ISO 8601); without them every event is returned",
|
||||
"optional (ISO 8601); with both given, recurring events are expanded "
|
||||
"server-side across the window; without them every event is returned",
|
||||
"POST /calendars/events {\"calendar\"?, \"uid\"?, \"summary\", "
|
||||
"\"start\", \"end\"?, \"all_day\"?, \"location\"?, \"description\"?, "
|
||||
"\"rrule\"?, \"overwrite\"?} -> 200 {\"ok\": true, \"uid\", "
|
||||
@@ -286,7 +288,10 @@ class NextcloudBridge(BridgeService):
|
||||
)
|
||||
}
|
||||
if path == "/calendars":
|
||||
return 200, {"calendars": self.client.list_calendars()}
|
||||
return 200, {
|
||||
"calendars": self.client.list_calendars(),
|
||||
"default": self.default_calendar,
|
||||
}
|
||||
if path == "/tasklists":
|
||||
return 200, {"tasklists": self._task_lists()}
|
||||
if path == "/calendars/events":
|
||||
|
||||
@@ -504,11 +504,21 @@ def _calendar_query_body(component: str, start: str = "", end: str = "") -> byte
|
||||
if end:
|
||||
attrs += f' end="{_stamp(_parse_dt(end))}"'
|
||||
time_range = f"<c:time-range{attrs}/>"
|
||||
# With a bounded window, ask the server to expand recurrences into their
|
||||
# instances (matching a `next event` read); `<c:expand>` needs both bounds.
|
||||
calendar_data = "<c:calendar-data/>"
|
||||
if start and end:
|
||||
calendar_data = (
|
||||
"<c:calendar-data>"
|
||||
f'<c:expand start="{_stamp(_parse_dt(start))}" '
|
||||
f'end="{_stamp(_parse_dt(end))}"/>'
|
||||
"</c:calendar-data>"
|
||||
)
|
||||
return (
|
||||
'<?xml version="1.0"?>'
|
||||
'<c:calendar-query xmlns:d="DAV:" '
|
||||
'xmlns:c="urn:ietf:params:xml:ns:caldav">'
|
||||
"<d:prop><d:getetag/><c:calendar-data/></d:prop>"
|
||||
f"<d:prop><d:getetag/>{calendar_data}</d:prop>"
|
||||
"<c:filter><c:comp-filter name=\"VCALENDAR\">"
|
||||
f'<c:comp-filter name="{component}">{time_range}</c:comp-filter>'
|
||||
"</c:comp-filter></c:filter></c:calendar-query>"
|
||||
|
||||
@@ -596,6 +596,26 @@ def test_all_day_event_parses(nextcloud):
|
||||
assert event["start"] == "2026-07-04"
|
||||
|
||||
|
||||
def test_list_events_expands_recurrences_when_window_given(nextcloud):
|
||||
fake, base = nextcloud
|
||||
make_client(base).list_events(
|
||||
"personal", "2026-03-01T00:00:00Z", "2026-04-01T00:00:00Z"
|
||||
)
|
||||
report = [call for call in fake.calls if call[0] == "REPORT"][-1]
|
||||
body = report[3].decode("utf-8")
|
||||
assert "<c:expand" in body, body
|
||||
assert "c:time-range" in body, body
|
||||
|
||||
|
||||
def test_list_events_without_a_window_does_not_expand(nextcloud):
|
||||
fake, base = nextcloud
|
||||
make_client(base).list_events("personal")
|
||||
report = [call for call in fake.calls if call[0] == "REPORT"][-1]
|
||||
body = report[3].decode("utf-8")
|
||||
assert "<c:expand" not in body, body
|
||||
assert "<c:calendar-data/>" in body, body
|
||||
|
||||
|
||||
def test_create_event_sends_if_none_match(nextcloud):
|
||||
fake, base = nextcloud
|
||||
make_client(base).create_event("personal", "u3", "X", "2026-03-01T12:00:00Z")
|
||||
@@ -786,6 +806,16 @@ def test_bridge_lists_files(nextcloud):
|
||||
assert [entry["name"] for entry in payload["entries"]] == ["readme.txt"]
|
||||
|
||||
|
||||
def test_bridge_lists_calendars_with_default(nextcloud):
|
||||
_fake, base = nextcloud
|
||||
status, payload = bridge_for(base, default_calendar="personal").handle_get(
|
||||
"/calendars", {}
|
||||
)
|
||||
assert status == 200
|
||||
assert payload["default"] == "personal"
|
||||
assert [c["name"] for c in payload["calendars"]] == ["personal"]
|
||||
|
||||
|
||||
def test_bridge_create_event(nextcloud):
|
||||
_fake, base = nextcloud
|
||||
status, payload = bridge_for(base, default_calendar="personal").handle_post(
|
||||
|
||||
Reference in new issue
Block a user