Skip to content

feat(mail): preserve mailbox context in +triage output for public mailboxes#1238

Merged
xukuncx merged 1 commit into
larksuite:mainfrom
xukuncx:feat/889956e
Jun 4, 2026
Merged

feat(mail): preserve mailbox context in +triage output for public mailboxes#1238
xukuncx merged 1 commit into
larksuite:mainfrom
xukuncx:feat/889956e

Conversation

@xukuncx
Copy link
Copy Markdown
Collaborator

@xukuncx xukuncx commented Jun 3, 2026

Generated by the harness-coding skill.

  • Branch: feat/889956e
  • Target: main

Sprints

ID Title Status Commit
S1 Synthesize transport contract for larksuite/cli passed 98173ae
S2 Preserve mailbox context in mail +triage output for public mailbox scenarios passed 2296886

Source specs

  • Requirement: 线上日志显示,公共邮箱场景下 mail +triage 能通过 BatchGetUserMailboxMessage 成功读取 metadata,但后续 AI 调用 mail +message 时没有携带原始 mailbox,导致请求变成 /user_mailboxes/me/messages/{message_id},最终 data-access 按个人邮箱查不到对应邮件。目标:让 AI 从 mail +triage 输出中直接拿到后续读取详情所需的 mailbox_id。

This MR was created autonomously. Quality gates were enforced by the repo's own pre-commit hooks.

Summary by CodeRabbit

  • New Features

    • mail +triage now includes mailbox_id in JSON/data responses; table output shows a mailbox_id column only for non-default mailboxes. Pagination hints and post-result tips include --mailbox when applicable.
  • Documentation

    • Updated docs and examples for mailbox_id, pagination tokens, table behavior, and next-page/tip wording.
  • Tests

    • Added unit, table, and end-to-end dry-run tests validating mailbox_id preservation across formats, empty/batch cases, and pagination/request chaining.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 3, 2026

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The PR injects mailbox_id into each mail triage message and the top-level JSON/data response, conditionally shows mailbox_id in table rows when mailbox != me, updates next-page and tip hints to include --mailbox when appropriate, adds tests that assert these behaviors, and updates the docs accordingly.

Changes

Mail triage mailbox context

Layer / File(s) Summary
Core mailbox ID injection into messages
shortcuts/mail/mail_triage.go
Injects mailbox_id into each message before output formatting and includes it in the top-level JSON/data response payload.
Conditional table column and pagination hints
shortcuts/mail/mail_triage.go
Table rows include a mailbox_id column only when the resolved mailbox is not me; next-page hint and final tip conditionally append --mailbox <value> when mailbox is not me.
Documentation updates
skills/lark-mail/references/lark-mail-triage.md
Adds top-level mailbox_id to JSON/data examples, clarifies mailbox_id/has_more/page_token semantics and token prefixes, and updates table pagination examples to show --mailbox inclusion for shared mailboxes.
Mailbox ID preservation tests
shortcuts/mail/mail_triage_test.go, tests/cli_e2e/mail/mail_triage_dryrun_test.go
Adds HTTP-mocked unit tests verifying mailbox_id is present at the response root and on each message for list/search and empty-result cases; adds batch-metadata-mismatch test; adds table-output assertions for mailbox_id column and stderr hints; adds e2e dry-run test validating the generated request chain and test env helper.

Sequence Diagram(s)

(omitted — change is localized and does not introduce a multi-component sequential flow requiring visualization)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • larksuite/cli#301: Modifies shortcuts/mail/mail_triage.go pagination and hint logic, overlapping areas affected by mailbox-id and pagination changes.

Suggested reviewers

  • chanthuang
  • infeng

Poem

🐇 A rabbit's note on mailbox context:

Messages carry where they came from,
A mailbox ID to guide them home,
Table rows and JSON echo the trace,
Hints keep paging tied to the right place.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description does not follow the required template structure. It is missing the Summary, Changes, Test Plan, and Related Issues sections specified in the template. Restructure the description to include Summary, Changes (bullet list), Test Plan (with checkboxes), and Related Issues sections as specified in the repository template.
Docstring Coverage ⚠️ Warning Docstring coverage is 7.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: preserving mailbox context in mail +triage output for public mailboxes, which is the core objective of the PR.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@github-actions github-actions Bot added domain/mail PR touches the mail domain size/M Single-domain feat or fix with limited business impact labels Jun 3, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 3, 2026

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add xukuncx/cli#feat/889956e -y -g

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.83%. Comparing base (98173ae) to head (0a59ebf).
⚠️ Report is 15 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1238      +/-   ##
==========================================
+ Coverage   69.19%   69.83%   +0.64%     
==========================================
  Files         637      666      +29     
  Lines       59753    64423    +4670     
==========================================
+ Hits        41345    44991    +3646     
- Misses      15067    15812     +745     
- Partials     3341     3620     +279     

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

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Jun 3, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
shortcuts/mail/mail_triage_test.go (1)

2274-2303: 💤 Low value

Consider explicitly verifying that stdout does not contain mailbox_id.

The test name and comment indicate that table format with empty results should not output mailbox_id. The test currently checks that stderr contains "No messages found" but does not explicitly verify that stdout is empty or lacks mailbox_id.

While the implementation returns early without printing to stdout (making this implicitly correct), an explicit assertion would make the test's intent clearer.

📝 Suggested enhancement
 	errOut := stderr.String()
 	if !strings.Contains(errOut, "No messages found") {
 		t.Fatalf("expected 'No messages found' in stderr for empty table result, got stdout:\n%s\nstderr:\n%s", stdout.String(), errOut)
 	}
+	out := stdout.String()
+	if strings.Contains(out, "mailbox_id") {
+		t.Fatalf("table output for empty results should not contain 'mailbox_id', got:\n%s", out)
+	}
 }
🤖 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/mail/mail_triage_test.go` around lines 2274 - 2303, The test
TestMailTriageTableEmptyResultNoMailboxID should explicitly assert that stdout
does not contain a mailbox_id to match its intent; after the existing stderr
assertion, add an assertion checking stdout.String() either equals "" or does
not contain "mailbox_id" (e.g., fail the test if
strings.Contains(stdout.String(), "mailbox_id")), referencing stdout and the
test name so the check is colocated with the current stderr verification.
🤖 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/mail/mail_triage_test.go`:
- Around line 2274-2303: The test TestMailTriageTableEmptyResultNoMailboxID
should explicitly assert that stdout does not contain a mailbox_id to match its
intent; after the existing stderr assertion, add an assertion checking
stdout.String() either equals "" or does not contain "mailbox_id" (e.g., fail
the test if strings.Contains(stdout.String(), "mailbox_id")), referencing stdout
and the test name so the check is colocated with the current stderr
verification.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1b62e78c-5f63-440b-8ef9-9507076eea29

📥 Commits

Reviewing files that changed from the base of the PR and between 11b4d60 and 3575a09.

📒 Files selected for processing (1)
  • shortcuts/mail/mail_triage_test.go

@xukuncx xukuncx force-pushed the feat/889956e branch 3 times, most recently from bd4936c to 5e4ddf3 Compare June 4, 2026 06:54
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

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/mail/mail_triage_dryrun_test.go`:
- Line 37: The assertion expects an unescaped mailbox ID but mailboxPath() uses
url.PathEscape, so update the test to compare against the URL-encoded mailbox
string (or construct the expected URL using url.PathEscape) rather than the raw
"postmaster@larksuite.com"; adjust both assertions that check api.0.url (the
line at require.Equal and the similar one at line 42) to use the escaped mailbox
(e.g., call url.PathEscape or otherwise percent-encode the mailbox) so the
expected value matches the dry-run 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: 88265f2e-06ba-48f7-898e-5271f7caaec0

📥 Commits

Reviewing files that changed from the base of the PR and between 3575a09 and bd4936c.

📒 Files selected for processing (2)
  • shortcuts/mail/mail_triage_test.go
  • tests/cli_e2e/mail/mail_triage_dryrun_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • shortcuts/mail/mail_triage_test.go

Comment thread tests/cli_e2e/mail/mail_triage_dryrun_test.go Outdated
…lboxes

When triaging a public/shared mailbox, downstream AI consumers (e.g.
mail +message) need the mailbox_id to construct correct API paths.
Previously the triage output only included message_id, causing
/user_mailboxes/me/messages/{id} lookups that fail for public mailboxes.

- Add mailbox_id field to every normalized message in structured output
- Add mailbox_id to top-level JSON/data output envelope
- Add mailbox_id to table rows when mailbox is not "me"
- Update stderr next-step tip to include --mailbox for non-me mailboxes
- Update next-page hint to include --mailbox for non-me mailboxes
- Add unit tests covering list, search, and public mailbox paths
- Update triage skill docs to show mailbox_id in output examples
Copy link
Copy Markdown
Collaborator

@chanthuang chanthuang left a comment

Choose a reason for hiding this comment

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

LGTM. Fix preserves mailbox context from mail +triage output for public/shared mailboxes, and the added tests/docs look solid.

@xukuncx xukuncx merged commit a82a486 into larksuite:main Jun 4, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain/mail PR touches the mail domain size/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants