Skip to content

feat: interactive upgrade prompt for bare lark-cli#1498

Open
dc-bytedance wants to merge 1 commit into
mainfrom
feat/root-interactive-upgrade
Open

feat: interactive upgrade prompt for bare lark-cli#1498
dc-bytedance wants to merge 1 commit into
mainfrom
feat/root-interactive-upgrade

Conversation

@dc-bytedance

@dc-bytedance dc-bytedance commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Summary

lark-cli already detects new versions, but the upgrade info is only surfaced via the JSON _notice.update field, which is consumed by AI agents — a human typing commands in a terminal never sees it. This PR adds an interactive upgrade prompt for the bare lark-cli invocation (no subcommand): when a newer version is cached and the session is a real interactive terminal, it asks Upgrade now? [y/N] on stderr — y runs the existing lark-cli update, n/Enter/EOF skips — then prints the usual help. Only the bare root command triggers it; all other commands, lark-cli update itself, and the JSON _notice channel are unchanged.

Changes

  • Add cmd/root_upgrade.go: offerRootUpgrade (three-stream TTY gate + cached-version check + [y/N] prompt), runRootUpgrade (reuses the registered update subcommand's RunE), readYes, isBareRootInvocation, and installRootUpgradePrompt
  • Add OutIsTerminal to cmdutil.IOStreams and reuse the existing StderrIsTerminal in internal/cmdutil/iostreams.go; the interactive gate requires stdin && stdout && stderr to all be a TTY
  • Wire installRootUpgradePrompt(f, rootCmd) after the unknown-subcommand guard in cmd/build.go
  • Reuse existing detection/throttle via update.CheckCached; internal/update/update.go is unchanged — no new persisted state
  • Add unit tests cmd/root_upgrade_test.go and internal/cmdutil/iostreams_test.go

Test Plan

  • make unit-test passed
  • validate passed (build / vet / unit / integration / convention guard / security)
  • skipped: sandbox E2E required a one-time device-code OAuth after recreating the container for the correct mount; the same assertions (non-TTY never prompts, JSON _notice unchanged, piped y not consumed) are covered by acceptance-reviewer against a real release binary and by host-level E2E. skillave N/A (no shortcut/skill/meta change)
  • acceptance-reviewer passed (5/5 cases, real release binary)
  • manual verification: bare lark-cli (non-TTY, cached newer version) prints help, exits 0, no Upgrade now? line; update-state.json byte-identical before/after (no state written); JSON _notice.update unchanged on subcommands

Related Issues

N/A

Summary by CodeRabbit

Release Notes

  • New Features
    • Added an interactive “Upgrade now?” prompt for bare CLI invocations (no subcommand/flags) when running in an interactive terminal and a newer version is available.
  • Bug Fixes
    • Improved terminal/TTY detection so upgrade prompts only appear when appropriate output streams are interactive.
  • Tests
    • Added coverage for upgrade dispatch to the registered update command and for prompt installation behavior when the wrapped command has no handler.
    • Added terminal detection unit tests.

@coderabbitai

coderabbitai Bot commented Jun 17, 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: ade5e37a-e1f7-4c42-a2aa-c8a3b57f2897

📥 Commits

Reviewing files that changed from the base of the PR and between 3e5a172 and 876c35c.

📒 Files selected for processing (5)
  • cmd/build.go
  • cmd/root_upgrade.go
  • cmd/root_upgrade_test.go
  • internal/cmdutil/iostreams.go
  • internal/cmdutil/iostreams_test.go
🚧 Files skipped from review as they are similar to previous changes (5)
  • internal/cmdutil/iostreams_test.go
  • cmd/root_upgrade_test.go
  • cmd/build.go
  • internal/cmdutil/iostreams.go
  • cmd/root_upgrade.go

📝 Walkthrough

Walkthrough

Adds an interactive upgrade prompt to the bare lark-cli root invocation. A new OutIsTerminal field is added to IOStreams and computed via a shared terminal-detection helper. The cmd/root_upgrade.go file implements bare-invocation detection, stdin parsing, conditional upgrade prompting using cached version state, and a RunE wrapper. buildInternal wires the prompt in via installRootUpgradePrompt. Comprehensive tests cover all terminal state combinations, cache presence, environment-variable opt-out, and edge cases.

Changes

Root Interactive Upgrade Prompt

Layer / File(s) Summary
IOStreams OutIsTerminal field and terminal detection
internal/cmdutil/iostreams.go, internal/cmdutil/iostreams_test.go
Adds OutIsTerminal bool to IOStreams, refactors NewIOStreams to compute all three terminal booleans (IsTerminal, OutIsTerminal, StderrIsTerminal) via a shared fileIsTerminal helper that safely handles non-file readers/writers, and adds tests for non-file and pipe-based streams.
Root upgrade prompt implementation and tests
cmd/root_upgrade.go, cmd/root_upgrade_test.go
Implements runRootUpgrade (find-and-run update subcommand), isBareRootInvocation (empty args with no flag tokens), readYes (parse y/yes from stdin), and offerRootUpgrade (check all three TTY flags, query cached version, print prompt to stderr, run upgrade on affirmative). Tests cover terminal combinations, cache presence/absence, opt-out via LARKSUITE_CLI_NO_UPDATE_NOTIFIER, update dispatch routing, and nil guard behavior.
Wiring into root command builder
cmd/build.go
buildInternal calls installRootUpgradePrompt after the unknown-subcommand guard to wrap the root command's RunE, ensuring the upgrade prompt runs only for bare invocations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • larksuite/cli#371: Both PRs modify command construction/wiring and IO/terminal detection—this PR adds an interactive root-upgrade prompt via buildInternal and extends IOStreams terminal flags, while the related PR refactors buildInternal/Execute into Build with injectable IO.

Suggested reviewers

  • liangshuo-1

Poem

🐇 Hop hop, a prompt appears at the gate,
"A newer version awaits — upgrade, don't wait!"
Type y and the rabbit fetches it quick,
Or press N to skip with a flick.
Bare CLI never looked so polite! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 53.33% 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 directly and concisely summarizes the main change: adding an interactive upgrade prompt for bare lark-cli invocations.
Description check ✅ Passed The description comprehensively covers all required sections from the template: Summary explains motivation, Changes lists all modifications, and Test Plan documents verification results with passing tests and manual checks.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/root-interactive-upgrade

Warning

Review ran into problems

🔥 Problems

Stopped waiting for pipeline failures after 30000ms. One of your pipelines takes longer than our 30000ms fetch window to run, so review may not consider pipeline-failure results for inline comments if any failures occurred after the fetch window. Increase the timeout if you want to wait longer or run a @coderabbit review after the pipeline has finished.


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 the size/L Large or sensitive change across domains or core paths label Jun 17, 2026
@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add larksuite/cli#feat/root-interactive-upgrade -y -g

@dc-bytedance dc-bytedance force-pushed the feat/root-interactive-upgrade branch from c3d6bea to d08f6b1 Compare June 17, 2026 08:06

@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)
cmd/root_upgrade_test.go (1)

101-108: ⚡ Quick win

Use cmdutil.TestFactory(t, config) instead of manual cmdutil.Factory construction in tests.

At Line 101 and Line 131, direct &cmdutil.Factory{...} setup can drift from shared defaults and test harness behavior.

As per coding guidelines, **/*_test.go: “Use cmdutil.TestFactory(t, config) for test factories.”

Also applies to: 131-133

🤖 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 `@cmd/root_upgrade_test.go` around lines 101 - 108, Replace the manual
construction of cmdutil.Factory using &cmdutil.Factory{IOStreams:
&cmdutil.IOStreams{...}} at both locations (around line 101 and line 131) with
the cmdutil.TestFactory(t, config) helper function instead. This ensures the
test factories use shared defaults and test harness behavior consistently across
all tests, preventing drift from the intended test setup patterns.

Source: Coding guidelines

🤖 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 `@cmd/root_upgrade_test.go`:
- Around line 101-108: Replace the manual construction of cmdutil.Factory using
&cmdutil.Factory{IOStreams: &cmdutil.IOStreams{...}} at both locations (around
line 101 and line 131) with the cmdutil.TestFactory(t, config) helper function
instead. This ensures the test factories use shared defaults and test harness
behavior consistently across all tests, preventing drift from the intended test
setup patterns.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5846f316-39d0-45df-a89a-7006e14656d2

📥 Commits

Reviewing files that changed from the base of the PR and between 7eeb111 and c3d6bea.

📒 Files selected for processing (5)
  • cmd/build.go
  • cmd/root_upgrade.go
  • cmd/root_upgrade_test.go
  • internal/cmdutil/iostreams.go
  • internal/cmdutil/iostreams_test.go

@dc-bytedance dc-bytedance force-pushed the feat/root-interactive-upgrade branch from d08f6b1 to 3e5a172 Compare June 17, 2026 08:14
@codecov

codecov Bot commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.49%. Comparing base (7eeb111) to head (876c35c).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1498      +/-   ##
==========================================
+ Coverage   73.43%   73.49%   +0.05%     
==========================================
  Files         753      783      +30     
  Lines       70182    74593    +4411     
==========================================
+ Hits        51540    54822    +3282     
- Misses      14829    15674     +845     
- Partials     3813     4097     +284     

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

@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 `@cmd/root_upgrade.go`:
- Around line 22-26: Add test cases to cover the uncovered behavior branches
introduced in this PR. First, create a test for the runRootUpgrade function that
verifies the dispatch logic correctly finds and executes the "update" command
when it exists with a valid RunE function. Second, add a test case for the inner
== nil guard condition at line 82 to ensure the code handles the nil scenario
correctly. These tests should explicitly verify the expected behavior of each
branch to satisfy the requirement that every behavior change needs an
accompanying test.
🪄 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: 77eb891f-2862-473b-9c1d-5c78b671496e

📥 Commits

Reviewing files that changed from the base of the PR and between c3d6bea and 3e5a172.

📒 Files selected for processing (5)
  • cmd/build.go
  • cmd/root_upgrade.go
  • cmd/root_upgrade_test.go
  • internal/cmdutil/iostreams.go
  • internal/cmdutil/iostreams_test.go
🚧 Files skipped from review as they are similar to previous changes (4)
  • cmd/build.go
  • internal/cmdutil/iostreams.go
  • cmd/root_upgrade_test.go
  • internal/cmdutil/iostreams_test.go

Comment thread cmd/root_upgrade.go
When a newer version is cached and stdin, stdout and stderr are all a
TTY, bare `lark-cli` (no subcommand) prompts `Upgrade now? [y/N]` on
stderr: `y` runs the existing `lark-cli update`, `n`/Enter/EOF skips,
then the usual help prints. Only the bare root command triggers it;
other commands, `lark-cli update`, and the JSON `_notice` channel are
unchanged. Detection and throttle reuse update.CheckCached, with no
new persisted state.

- add cmd/root_upgrade.go (offerRootUpgrade, runRootUpgrade, readYes,
  isBareRootInvocation, installRootUpgradePrompt)
- add OutIsTerminal to cmdutil.IOStreams; reuse existing StderrIsTerminal
- wire installRootUpgradePrompt into cmd/build.go
- add unit tests for the prompt logic and the new IOStreams fields
@dc-bytedance dc-bytedance force-pushed the feat/root-interactive-upgrade branch from 3e5a172 to 876c35c Compare June 17, 2026 08:41
@github-actions

Copy link
Copy Markdown

PR Quality Summary

The semantic review system could not produce a fully trusted result. This is not reported as a code defect.

System status

  • semantic review degraded: semantic review request too large (endpoint=https[:]//ark.cn-beijing.volces.com/api/plan/v3/chat/completions model=deepseek-v4-pro response_format=none attempt=1/3 bytes=140923 limit=65536) — Action: inspect deterministic quality-gate diagnostics

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature size/L Large or sensitive change across domains or core paths

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant