Skip to content

feat(mail): expose draft priority in --inspect projection#779

Merged
xzcong0820 merged 1 commit into
larksuite:mainfrom
xzcong0820:harness/01kqenandss7ynchapf94ck9d
May 19, 2026
Merged

feat(mail): expose draft priority in --inspect projection#779
xzcong0820 merged 1 commit into
larksuite:mainfrom
xzcong0820:harness/01kqenandss7ynchapf94ck9d

Conversation

@xzcong0820
Copy link
Copy Markdown
Collaborator

@xzcong0820 xzcong0820 commented May 8, 2026

Generated by the harness-coding skill.

  • Task ID: 01KQENANDSS7YNCGHAPF94CK9D-13
  • Branch: harness/01kqenandss7ynchapf94ck9d
  • Target: main

Add a Priority field to DraftProjection populated from X-Cli-Priority (CLI/OAPI primary) → X-Priority (RFC fallback for IMAP-回灌 historical drafts), with case-insensitive lookup via the existing headerValue helper. When neither header is present, the projection emits 'normal' — absence of a priority header is the standard email convention for normal priority, symmetric with how mail clients interpret untagged messages.

Append one notes entry to buildDraftEditPatchTemplate documenting the --set-priority flag and the X-Cli-Priority translation contract.

The write-side (--set-priority flag, parsePriority helper, translation branch in mail_draft_edit.go, EML header target) is unchanged — already shipped on master.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 8, 2026

📝 Walkthrough

Walkthrough

Adds DraftProjection.Priority and logic to parse and normalize priority from headers (prefer X-Cli-Priority, fallback X-Priority), assigns it in Project(), adds tests, and updates CLI inspect/template output.

Changes

Mail draft priority projection

Layer / File(s) Summary
Data contract: Priority field
shortcuts/mail/draft/model.go
DraftProjection gains exported Priority field serialized as priority.
Priority parsing and normalization
shortcuts/mail/draft/projection.go
parsePriorityFromHeaders reads X-Cli-Priority first then X-Priority; mapPriorityValue normalizes numeric/text variants to high, normal, low, or unknown.
Projection assignment
shortcuts/mail/draft/projection.go
Project() assigns the parsed/normalized priority to proj.Priority before returning.
Tests and CLI/docs
shortcuts/mail/draft/projection_test.go, shortcuts/mail/mail_draft_edit.go
New tests cover precedence, fallback, normalization, and edge cases. +draft-edit --inspect prints priority: when defined; patch template notes document --set-priority header mappings.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • larksuite/cli#538: Implements compose/edit helpers and CLI flags that set and normalize X-Cli-Priority, complementing this PR's priority parsing and projection.

Suggested labels

domain/mail, size/M

Suggested reviewers

  • chanthuang
  • infeng

Poem

"I hop through headers, sniff and see,
X-Cli-Priority first for me,
maps to high, normal, or low,
tests cheer loud as values flow,
drafts now wear their flags with glee." 🐇📬

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 31.25% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The PR description is auto-generated and lacks the required template structure with Summary, Changes, Test Plan, and Related Issues sections. Reformat the description to follow the template with clear Summary, Changes list, Test Plan checklist (unit tests, manual verification), and Related Issues sections.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding a Priority field to the DraftProjection that is exposed in the --inspect output.
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 May 8, 2026
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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
shortcuts/mail/mail_draft_edit.go (1)

251-295: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

priority is missing from the human-readable --inspect text output.

The JSON envelope will include priority (it's part of DraftProjection), but the text-mode callback never prints it. Since the PR goal is to expose priority in --inspect, text-format users won't see it at all.

🐛 Proposed fix
 		if len(projection.Warnings) > 0 {
 			fmt.Fprintf(w, "warnings: %s\n", sanitizeForTerminal(strings.Join(projection.Warnings, "; ")))
 		}
+		if projection.Priority != "" && projection.Priority != "unknown" {
+			fmt.Fprintf(w, "priority: %s\n", sanitizeForTerminal(projection.Priority))
+		}
 	})
🤖 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_draft_edit.go` around lines 251 - 295, The human-readable
inspect output in the runtime.OutFormat callback for draft inspection is missing
the DraftProjection priority field; update the callback in mail_draft_edit.go
(inside the runtime.OutFormat anonymous func) to print projection.Priority (use
the same sanitizeForTerminal + fmt.Fprintf pattern as other fields), e.g. add a
conditional that emits "priority: <value>\n" when projection.Priority is
non-empty so text-mode --inspect matches the JSON envelope.
🧹 Nitpick comments (2)
shortcuts/mail/draft/projection.go (1)

177-188: 💤 Low value

"normal" string form is not mapped — returns "unknown" for non-CLI writers.

The CLI write-side removes X-Cli-Priority for --set-priority normal, so this path won't be hit by CLI-authored drafts. However, an external OAPI client that writes X-Cli-Priority: normal (or X-Priority: normal) would incorrectly project to "unknown" instead of "normal". Consider adding the alias if the backend PriorityValueToType vocabulary includes it.

🛡️ Proposed fix
 	switch strings.ToLower(strings.TrimSpace(raw)) {
 	case "1", "high", "1 (highest)":
 		return "high"
-	case "3":
+	case "3", "normal":
 		return "normal"
 	case "5", "low", "5 (lowest)":
 		return "low"
🤖 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/draft/projection.go` around lines 177 - 188, mapPriorityValue
currently maps several textual/numeric inputs to internal priority types but
omits the plain "normal" token, causing external OAPI/HTTP writers sending
X-Cli-Priority: normal or X-Priority: normal to be projected as "unknown";
update mapPriorityValue to treat "normal" (case-insensitive, trimmed) as the
same as "3" by adding "normal" to the switch case that returns "normal" so it
aligns with the backend PriorityValueToType vocabulary and existing CLI
behavior.
shortcuts/mail/draft/model.go (1)

169-169: 💤 Low value

omitempty is a no-op here — consider dropping it for clarity.

parsePriorityFromHeaders always returns a non-empty string (minimum "unknown"), so omitempty never suppresses the field. The PR description says the goal is "a stable read-side surface"; removing omitempty makes that guarantee self-documenting in the struct tag.

-	Priority                string                   `json:"priority,omitempty"`
+	Priority                string                   `json:"priority"`
🤖 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/draft/model.go` at line 169, The JSON tag on the Priority
field currently uses `omitempty` even though parsePriorityFromHeaders always
returns a non-empty string (at least "unknown"), so `omitempty` is misleading;
update the struct field `Priority` in shortcuts/mail/draft/model.go to remove
`,omitempty` from its `json:"priority,omitempty"` tag (make it
`json:"priority"`) so the read-side surface is stable and self-documenting, and
keep parsePriorityFromHeaders 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.

Outside diff comments:
In `@shortcuts/mail/mail_draft_edit.go`:
- Around line 251-295: The human-readable inspect output in the
runtime.OutFormat callback for draft inspection is missing the DraftProjection
priority field; update the callback in mail_draft_edit.go (inside the
runtime.OutFormat anonymous func) to print projection.Priority (use the same
sanitizeForTerminal + fmt.Fprintf pattern as other fields), e.g. add a
conditional that emits "priority: <value>\n" when projection.Priority is
non-empty so text-mode --inspect matches the JSON envelope.

---

Nitpick comments:
In `@shortcuts/mail/draft/model.go`:
- Line 169: The JSON tag on the Priority field currently uses `omitempty` even
though parsePriorityFromHeaders always returns a non-empty string (at least
"unknown"), so `omitempty` is misleading; update the struct field `Priority` in
shortcuts/mail/draft/model.go to remove `,omitempty` from its
`json:"priority,omitempty"` tag (make it `json:"priority"`) so the read-side
surface is stable and self-documenting, and keep parsePriorityFromHeaders
behavior unchanged.

In `@shortcuts/mail/draft/projection.go`:
- Around line 177-188: mapPriorityValue currently maps several textual/numeric
inputs to internal priority types but omits the plain "normal" token, causing
external OAPI/HTTP writers sending X-Cli-Priority: normal or X-Priority: normal
to be projected as "unknown"; update mapPriorityValue to treat "normal"
(case-insensitive, trimmed) as the same as "3" by adding "normal" to the switch
case that returns "normal" so it aligns with the backend PriorityValueToType
vocabulary and existing CLI behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: af93c6af-c710-4b94-a7fe-0a8fbe7cd07e

📥 Commits

Reviewing files that changed from the base of the PR and between 9075788 and d760b19.

📒 Files selected for processing (4)
  • shortcuts/mail/draft/model.go
  • shortcuts/mail/draft/projection.go
  • shortcuts/mail/draft/projection_test.go
  • shortcuts/mail/mail_draft_edit.go

@codecov
Copy link
Copy Markdown

codecov Bot commented May 8, 2026

Codecov Report

❌ Patch coverage is 85.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.94%. Comparing base (7c68639) to head (f2ea65e).
⚠️ Report is 70 commits behind head on main.

Files with missing lines Patch % Lines
shortcuts/mail/mail_draft_edit.go 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #779      +/-   ##
==========================================
+ Coverage   65.40%   66.94%   +1.54%     
==========================================
  Files         508      568      +60     
  Lines       46795    52990    +6195     
==========================================
+ Hits        30605    35475    +4870     
- Misses      13548    14584    +1036     
- Partials     2642     2931     +289     

☔ View full report in Codecov by Sentry.
📢 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.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 8, 2026

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add xzcong0820/larksuite-cli#harness/01kqenandss7ynchapf94ck9d -y -g

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.

Found one issue that should be addressed before merge:

mapPriorityValue only maps normal priority when the raw header is exactly 3, but this PR explicitly supports the X-Priority fallback for historical/imported drafts and already accepts Outlook-style strings for high/low (1 (Highest), 5 (Lowest)). The normal counterparts (Normal, 3 (Normal)) currently project as unknown, so a draft with an explicit normal priority loses that signal while high/low do not. Please include normal and 3 (normal) in the mapping and add a regression test for the fallback/header string form.

@xzcong0820 xzcong0820 force-pushed the harness/01kqenandss7ynchapf94ck9d branch 2 times, most recently from 83614de to 34fd79f Compare May 15, 2026 08:04
Comment thread shortcuts/mail/draft/projection.go
…t --set-priority

Add a Priority field to DraftProjection populated from the EML header pair
X-Cli-Priority (CLI/OAPI primary) → X-Priority (RFC fallback for IMAP-回灌
historical drafts), with case-insensitive lookup via the existing
headerValue helper and a local mapping table aligned with the backend
gopkg/mail_priority.PriorityValueToType vocabulary. When neither header is
present (the symmetric read of --set-priority normal=remove_header) the
projection emits "unknown" so agents have a stable read-side surface.

Append one notes entry to buildDraftEditPatchTemplate documenting the
--set-priority flag and the X-Cli-Priority translation contract.

The write-side (--set-priority flag, parsePriority helper, translation
branch in mail_draft_edit.go, EML header target) is unchanged — already
shipped on master.

sprint: S4
@xzcong0820 xzcong0820 force-pushed the harness/01kqenandss7ynchapf94ck9d branch from 34fd79f to f2ea65e Compare May 19, 2026 03:50
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 `@shortcuts/mail/draft/projection_test.go`:
- Around line 219-233: The test TestProjectPriorityBothAbsentNormal and its
assertion are out of sync with the PR contract: when both headers are absent
Project(snapshot) should set proj.Priority to "unknown". Rename the test and/or
comment to reflect "both absent => unknown" and change the assertion in
TestProjectPriorityBothAbsentNormal (which calls Project(snapshot) and checks
proj.Priority) to expect "unknown" instead of "normal".
🪄 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: 3dd71fab-cdca-4d37-bcfc-56d334ef59ff

📥 Commits

Reviewing files that changed from the base of the PR and between 34fd79f and f2ea65e.

📒 Files selected for processing (4)
  • shortcuts/mail/draft/model.go
  • shortcuts/mail/draft/projection.go
  • shortcuts/mail/draft/projection_test.go
  • shortcuts/mail/mail_draft_edit.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • shortcuts/mail/draft/projection.go
  • shortcuts/mail/mail_draft_edit.go

Comment thread shortcuts/mail/draft/projection_test.go
@xzcong0820 xzcong0820 merged commit e511404 into larksuite:main May 19, 2026
19 checks passed
@liangshuo-1 liangshuo-1 mentioned this pull request May 19, 2026
2 tasks
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.

2 participants