Skip to content

feat: precheck room availability before calendar +update#1965

Merged
hugang-lark merged 1 commit into
mainfrom
feat/room_available
Jul 20, 2026
Merged

feat: precheck room availability before calendar +update#1965
hugang-lark merged 1 commit into
mainfrom
feat/room_available

Conversation

@hugang-lark

@hugang-lark hugang-lark commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

Summary

lark-cli calendar +update now runs a room-availability precheck before PATCH so agents don't PATCH an event only to end up with a room that will silently drop off (reserved, past-time, disabled, over duration, needs approval, etc.). Blocking outcomes are surfaced as a typed validation error that describes each room's status and the recovery paths the CLI actually supports.

Changes

  • Add room-availability precheck via /open-apis/calendar/v4/freebusy/room_availability_check before PATCH; surface blocked rooms with room ID + name + reason + strategy/requisition/approval details
  • Handle need_approval (all / over_duration): compare current duration against threshold; consolidate recovery guidance into a single hint that requires user confirmation before running any recovery path

Test Plan

  • Manual: lark-cli calendar +update --event-id <id> --start-time <past> returns structured failed_precondition naming the blocked room
  • Manual: lark-cli calendar +update --event-id <id> --add-room-ids <approval-room> blocks with need_approval and points at calendar event.attendees create --as user
  • Manual: --skip-room-check bypasses the precheck when the user explicitly authorizes it

Related Issues

  • None

Summary by CodeRabbit

  • New Features

    • Added meeting-room availability prechecks for calendar +update when room attendees and/or meeting times change, including dry-run previews.
    • Provides room-specific blocking messages, including “need approval” handling and contextual strategy/requisition details.
    • Falls back to the recurring master event snapshot when instance IDs aren’t found.
  • Bug Fixes

    • If the room-check API fails, the update now warns and continues (instead of blocking).
  • Documentation

    • Updated “使用规则” guidance: do not retry with room-check bypass automatically on room/approval errors; only after confirmation, and preserve the original error details.

@hugang-lark hugang-lark added the domain/calendar PR touches the calendar domain label Jul 20, 2026
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

calendar +update now pre-checks affected meeting rooms, blocks unavailable or approval-required rooms with typed errors, degrades on check failures, supports a hidden skip flag, and previews the check during dry runs. Tests cover planning, recurring events, messaging, and execution.

Changes

Calendar room availability precheck

Layer / File(s) Summary
Room check planning and API pipeline
shortcuts/calendar/calendar_room_check.go
Builds room-check plans from update inputs and event snapshots, handles recurring-event fallback, formats request times, and parses availability responses.
Blocked-room result handling
shortcuts/calendar/calendar_room_check.go
Produces room-specific strategy, requisition, and approval details, then returns typed validation errors for blocked rooms.
Calendar update integration
shortcuts/calendar/calendar_update.go, skills/lark-calendar/references/lark-calendar-update.md
Adds the hidden skip flag, precheck execution, dry-run preview output, and documented degraded execution rules.
Room-check validation coverage
shortcuts/calendar/calendar_test.go, tests/cli_e2e/calendar/calendar_update_dryrun_test.go
Tests skip conditions, request payloads, blocking, degradation, dry runs, recurring fallback, message formatting, and updated API ordering.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CalendarUpdate
  participant EventSnapshot
  participant RoomAvailabilityAPI
  participant UpdateAPI
  CalendarUpdate->>EventSnapshot: Fetch event snapshot
  EventSnapshot-->>CalendarUpdate: Return rooms, times, timezone, recurrence
  CalendarUpdate->>RoomAvailabilityAPI: Check affected rooms
  RoomAvailabilityAPI-->>CalendarUpdate: Return room availability results
  CalendarUpdate->>UpdateAPI: Apply calendar update when allowed
Loading

Possibly related PRs

  • larksuite/cli#678: Introduces the calendar update flow that this PR extends with room-availability checks.

Suggested reviewers: calendar-assistant

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: prechecking room availability before calendar updates.
Description check ✅ Passed The description includes the required Summary, Changes, Test Plan, and Related Issues sections and covers the main behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/room_available

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the size/L Large or sensitive change across domains or core paths label Jul 20, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
shortcuts/calendar/calendar_update.go (1)

295-319: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Dry-run preview omits existing rooms that will actually be checked.

room_ids is set to newRooms only, but on a time/rrule change with no newly added rooms, resolveRoomCheckPlan also checks the event's existing rooms. The preview then shows an empty/partial room_ids, which can mislead agents parsing the dry-run output. Consider a placeholder mirroring the timezone convention.

♻️ Optional: signal inherited existing rooms in the preview
 			previewBody := map[string]interface{}{
 				"calendar_id":    displayCalendarID,
 				"event_id":       eventID,
 				"room_ids":       newRooms,
 				"start_timezone": "<inherited from event>",
 			}
+			if len(newRooms) == 0 && (timeChanged || rruleChanged) {
+				previewBody["room_ids"] = "<existing event rooms inherited from event>"
+			}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@shortcuts/calendar/calendar_update.go` around lines 295 - 319, Update the
dry-run preview built in the room-check block so previewBody["room_ids"] also
signals the event’s existing rooms when timeChanged or rruleChanged causes them
to be checked, while preserving explicit newRooms. Use a clear
inherited-existing-rooms placeholder consistent with the existing "<inherited
from event>" timezone convention, and keep the actual room-check planning
behavior unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@shortcuts/calendar/calendar_update.go`:
- Around line 295-319: Update the dry-run preview built in the room-check block
so previewBody["room_ids"] also signals the event’s existing rooms when
timeChanged or rruleChanged causes them to be checked, while preserving explicit
newRooms. Use a clear inherited-existing-rooms placeholder consistent with the
existing "<inherited from event>" timezone convention, and keep the actual
room-check planning behavior unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 01c2ab41-39a9-4320-a648-9267ba65a0d3

📥 Commits

Reviewing files that changed from the base of the PR and between 79adf89 and da58256.

📒 Files selected for processing (4)
  • shortcuts/calendar/calendar_room_check.go
  • shortcuts/calendar/calendar_test.go
  • shortcuts/calendar/calendar_update.go
  • skills/lark-calendar/references/lark-calendar-update.md

@github-actions

github-actions Bot commented Jul 20, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@e822dcdb5a4c6cb3f17e9d83857c434689e484a9

🧩 Skill update

npx skills add larksuite/cli#feat/room_available -y -g

@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.63781% with 85 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.01%. Comparing base (79adf89) to head (e822dcd).

Files with missing lines Patch % Lines
shortcuts/calendar/calendar_room_check.go 79.33% 51 Missing and 30 partials ⚠️
shortcuts/calendar/calendar_update.go 91.48% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1965      +/-   ##
==========================================
+ Coverage   74.98%   75.01%   +0.02%     
==========================================
  Files         896      897       +1     
  Lines       94403    94841     +438     
==========================================
+ Hits        70789    71142     +353     
- Misses      18198    18251      +53     
- Partials     5416     5448      +32     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hugang-lark
hugang-lark force-pushed the feat/room_available branch from da58256 to e822dcd Compare July 20, 2026 09:56

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/cli_e2e/calendar/calendar_update_dryrun_test.go`:
- Line 46: The calendar dry-run E2E test currently validates only room_ids;
extend its assertions to cover calendar_id, event_id, start_time, end_time, and
start_timezone in the full room-check payload. Add a separate end-to-end test in
the calendar CLI E2E tests that invokes the update flow with --skip-room-check
and verifies the bypass behavior and expected output.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7eadeb5a-375e-4187-8a71-dedfb8b00f3b

📥 Commits

Reviewing files that changed from the base of the PR and between da58256 and e822dcd.

📒 Files selected for processing (5)
  • shortcuts/calendar/calendar_room_check.go
  • shortcuts/calendar/calendar_test.go
  • shortcuts/calendar/calendar_update.go
  • skills/lark-calendar/references/lark-calendar-update.md
  • tests/cli_e2e/calendar/calendar_update_dryrun_test.go
🚧 Files skipped from review as they are similar to previous changes (4)
  • skills/lark-calendar/references/lark-calendar-update.md
  • shortcuts/calendar/calendar_room_check.go
  • shortcuts/calendar/calendar_update.go
  • shortcuts/calendar/calendar_test.go

Comment thread tests/cli_e2e/calendar/calendar_update_dryrun_test.go
@hugang-lark
hugang-lark merged commit fb57e17 into main Jul 20, 2026
32 of 44 checks passed
@hugang-lark
hugang-lark deleted the feat/room_available branch July 20, 2026 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain/calendar PR touches the calendar domain size/L Large or sensitive change across domains or core paths

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants