Skip to content

feat(approval): support approval event consumption#1923

Closed
LightsDancer wants to merge 1 commit into
mainfrom
feat/approval-event-consume
Closed

feat(approval): support approval event consumption#1923
LightsDancer wants to merge 1 commit into
mainfrom
feat/approval-event-consume

Conversation

@LightsDancer

@LightsDancer LightsDancer commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add support for consuming Approval instance and task status change events through lark-cli event consume, including user-auth pre-consume subscription setup, flattened output schemas, and agent-facing documentation.

Changes

  • Register approval.instance.status_changed_v4 and approval.task.status_changed_v4 EventKeys with custom flattened schemas, required user auth scopes, and console event metadata.
  • Add Approval pre-consume subscription setup that calls the instance/task subscription APIs and supports omitted, single, comma-separated, or JSON-array subscription_type values.
  • Document Approval event consumption semantics, output fields, subscription behavior, and usage examples in the lark-event skill references.
  • Add tests for EventKey registration, schema output, subscription parameter parsing, validation errors, flattened payload processing, and event list/schema visibility.

Test Plan

  • Relevant unit tests pass: go test ./cmd/event ./events/approval
  • Manual local verification confirms the lark-cli event schema / lark-cli event list flow works as expected via go run . event schema approval.instance.status_changed_v4 --json, go run . event schema approval.task.status_changed_v4 --json, and go run . event list --json.

Related Issues

  • None

Summary by CodeRabbit

  • New Features

    • Added approval v4 instance/task status-change event support (approval.instance.status_changed_v4, approval.task.status_changed_v4) with flattened JSON output.
    • Implemented subscription_type pre-registration for approval subscriptions, supporting omitted/default, comma-separated, and JSON-array inputs, with multi-relation registration behavior.
    • Expanded support for time-range filtering when querying approval instances and tasks.
  • Documentation

    • Updated and expanded Approval event consumption references, including required scopes/auth, output fields, and subscription_type usage formats.
    • Refined approval creation and task/rollback/time-range command documentation.

@CLAassistant

CLAassistant commented Jul 16, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0ba681ff-1283-484d-a065-7d1014507fcd

📥 Commits

Reviewing files that changed from the base of the PR and between 7d5e628 and 4c6aa42.

📒 Files selected for processing (13)
  • cmd/event/list_test.go
  • cmd/event/schema_test.go
  • events/approval/preconsume.go
  • events/approval/register.go
  • events/approval/register_test.go
  • events/approval/types.go
  • events/register.go
  • skills/lark-approval/references/lark-approval-initiate.md
  • skills/lark-approval/references/lark-approval-instances-initiated.md
  • skills/lark-approval/references/lark-approval-tasks-query.md
  • skills/lark-approval/references/lark-approval-tasks-rollback.md
  • skills/lark-event/SKILL.md
  • skills/lark-event/references/lark-event-approval.md
🚧 Files skipped from review as they are similar to previous changes (10)
  • cmd/event/list_test.go
  • events/register.go
  • events/approval/types.go
  • skills/lark-approval/references/lark-approval-tasks-rollback.md
  • events/approval/register.go
  • skills/lark-approval/references/lark-approval-tasks-query.md
  • events/approval/preconsume.go
  • skills/lark-event/references/lark-event-approval.md
  • events/approval/register_test.go
  • skills/lark-approval/references/lark-approval-instances-initiated.md

📝 Walkthrough

Walkthrough

Adds two Approval status-change event keys with flattened schemas, subscription pre-registration, payload processing, global registration, comprehensive tests, event-consumption documentation, and updates to Approval command references.

Changes

Approval status-change events

Layer / File(s) Summary
Event contracts and registration
events/approval/types.go, events/approval/register.go, events/register.go
Defines instance/task flattened payload types and registers both Approval event keys with schemas, handlers, parameters, scopes, and authentication metadata.
Approval subscription pre-consumption
events/approval/preconsume.go
Parses, validates, canonicalizes, and submits Approval subscription types through POST requests without returning cleanup callbacks.
Status-change payload processing
events/approval/register.go
Transforms instance and task event envelopes into flattened JSON outputs, defaults missing types, ignores nil events, and passes malformed payloads through unchanged.
Event behavior and CLI validation
events/approval/register_test.go, cmd/event/schema_test.go, cmd/event/list_test.go
Tests registration metadata, schemas, subscription requests, validation errors, payload processing, registry behavior, and CLI listing/schema output.
Approval event consumption documentation
skills/lark-event/SKILL.md, skills/lark-event/references/lark-event-approval.md
Documents the event catalog, subscription formats and lifecycle, required authorization, output fields, and consumption examples.

Approval command documentation

Layer / File(s) Summary
Approval command reference updates
skills/lark-approval/references/lark-approval-initiate.md, skills/lark-approval/references/lark-approval-instances-initiated.md, skills/lark-approval/references/lark-approval-tasks-query.md, skills/lark-approval/references/lark-approval-tasks-rollback.md
Updates form requirements, adds instance/task time filters, documents task identifiers, and adds START rollback guidance and examples.

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

Sequence Diagram(s)

sequenceDiagram
  participant Consumer
  participant approvalSubscriptionPreConsume
  participant ApprovalAPI
  participant EventProcessor
  Consumer->>approvalSubscriptionPreConsume: provide subscription_type
  approvalSubscriptionPreConsume->>ApprovalAPI: POST subscription registrations
  ApprovalAPI-->>Consumer: deliver Approval status-change event
  Consumer->>EventProcessor: pass raw event payload
  EventProcessor-->>Consumer: return flattened JSON output
Loading

Possibly related PRs

Suggested reviewers: liangshuo-1

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: adding Approval event consumption support.
Description check ✅ Passed The description follows the template and includes summary, changes, test plan, and related issues with sufficient detail.
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/approval-event-consume

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 commented Jul 16, 2026

Copy link
Copy Markdown

PR Quality Summary

CI did not complete successfully. Use the failed check links below to decide whether this PR needs a code change or a rerun.

Failed checks

@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add larksuite/cli#feat/approval-event-consume -y -g

@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: 4

🤖 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 `@cmd/event/schema_test.go`:
- Line 172: Before the cmdutil.TestFactory call in the relevant schema test, set
LARKSUITE_CLI_CONFIG_DIR to t.TempDir() so the test uses an isolated temporary
CLI configuration directory.

In `@events/approval/preconsume.go`:
- Line 15: Update approvalSubscriptionPreConsume to accept a configuration
struct with named fields for eventType and subscribePath instead of two string
parameters, then update its callers to initialize the fields explicitly and
preserve the existing request behavior.
- Around line 27-31: Update the subscription registration loop in the preconsume
flow to handle partial success when a later CallAPI request fails: either
compensate already-created subscriptions using an idempotent cleanup path, or
return a typed, structured error containing the successful and failed
subscription types plus actionable retry guidance. Preserve successful
registrations, avoid discarding write outcomes, and add coverage for failure on
the second relation.

In `@events/approval/register_test.go`:
- Around line 150-175: Replace loose map-based schema parsing with typed
projection structs in events/approval/register_test.go lines 150-175, covering
formats, enums, and nested user properties; update assertEnumContains in
events/approval/register_test.go lines 181-191 to accept []string. In
cmd/event/schema_test.go lines 178-210, decode command output into typed structs
for params, scopes, auth types, and resolved schema properties, with no new
map[string]interface{} parsing.
🪄 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: b737246e-257b-44d0-9477-448d5e4e49e6

📥 Commits

Reviewing files that changed from the base of the PR and between 7081960 and 17b63dd.

📒 Files selected for processing (13)
  • cmd/event/list_test.go
  • cmd/event/schema_test.go
  • events/approval/preconsume.go
  • events/approval/register.go
  • events/approval/register_test.go
  • events/approval/types.go
  • events/register.go
  • skills/lark-approval/references/lark-approval-initiate.md
  • skills/lark-approval/references/lark-approval-instances-initiated.md
  • skills/lark-approval/references/lark-approval-tasks-query.md
  • skills/lark-approval/references/lark-approval-tasks-rollback.md
  • skills/lark-event/SKILL.md
  • skills/lark-event/references/lark-event-approval.md

Comment thread cmd/event/schema_test.go
Comment thread events/approval/preconsume.go Outdated
Comment thread events/approval/preconsume.go
Comment thread events/approval/register_test.go Outdated
@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.70507% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.99%. Comparing base (7081960) to head (4c6aa42).

Files with missing lines Patch % Lines
events/approval/preconsume.go 89.36% 6 Missing and 4 partials ⚠️
events/approval/register.go 93.44% 4 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1923      +/-   ##
==========================================
+ Coverage   74.96%   74.99%   +0.03%     
==========================================
  Files         892      894       +2     
  Lines       94058    94275     +217     
==========================================
+ Hits        70506    70705     +199     
- Misses      18139    18149      +10     
- Partials     5413     5421       +8     

☔ 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.

@LightsDancer
LightsDancer force-pushed the feat/approval-event-consume branch from 17b63dd to 7d5e628 Compare July 16, 2026 20:09
Register approval.instance.status_changed_v4 and approval.task.status_changed_v4 with custom flattened schemas and user-auth pre-consume subscription setup.

Handle approval subscription_type as optional multi-value pre-registration metadata: omitted values register both involved and managed relations, explicit values can be single, comma-separated, or JSON array, and consumers do not unsubscribe on exit.

Report partial approval subscription registration failures with registered and failed relation context while preserving the underlying typed error classification.

Document approval event output fields and subscription semantics, and refresh approval skill references from API metadata.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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