Skip to content

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

Merged
liangshuo-1 merged 2 commits into
mainfrom
feat/root-interactive-upgrade
Jul 1, 2026
Merged

feat: interactive upgrade prompt for bare lark-cli#1498
liangshuo-1 merged 2 commits 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? [y/N]” prompt for bare CLI runs (no subcommand/flags) when a newer version is available in interactive terminal sessions.
  • Bug Fixes

    • Improved terminal detection so upgrade prompting triggers only when the primary output is truly a TTY.
  • Tests

    • Expanded coverage for upgrade dispatching and prompt-wrapping behavior.
    • Added unit tests for terminal-flag behavior in non-terminal and pipe-based I/O.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d2e6f497-10bb-484f-92d2-2d98a09d8f66

📥 Commits

Reviewing files that changed from the base of the PR and between b0dfca5 and d6a676e.

📒 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)
  • cmd/build.go
  • internal/cmdutil/iostreams_test.go
  • cmd/root_upgrade_test.go
  • internal/cmdutil/iostreams.go
  • cmd/root_upgrade.go

📝 Walkthrough

Walkthrough

Adds an interactive upgrade prompt for bare lark-cli invocations in interactive terminals. IOStreams now tracks OutIsTerminal, the root command gains prompt and dispatch logic, and buildInternal wires the wrapper into root command construction.

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 to IOStreams, updates terminal detection for input/output/error streams, and adds tests covering non-file and pipe-backed streams.
Root upgrade prompt core logic
cmd/root_upgrade.go, cmd/root_upgrade_test.go
Adds bare-invocation detection, yes/no parsing, cached-version prompting, update dispatch, and tests for prompting, dispatch, and nil-guard behavior.
Wiring upgrade prompt into root command builder
cmd/build.go
Wraps the root command with the new upgrade prompt during command assembly.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

  • larksuite/cli#371: Both PRs change command construction and IO/terminal handling around buildInternal and IOStreams.

Suggested reviewers: liangshuo-1

🚥 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 is concise and accurately summarizes the main change: adding an interactive upgrade prompt for bare lark-cli invocations.
Description check ✅ Passed The description matches the required template and includes summary, changes, test plan, and related issues with concrete details.
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/root-interactive-upgrade

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 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@d6a676e107565b435ee0ef37db3e9ec0902640ec

🧩 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 74.48%. Comparing base (ec6fdc9) to head (d6a676e).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1498      +/-   ##
==========================================
+ Coverage   74.47%   74.48%   +0.01%     
==========================================
  Files         849      850       +1     
  Lines       86631    86669      +38     
==========================================
+ Hits        64517    64555      +38     
  Misses      17172    17172              
  Partials     4942     4942              

☔ 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
@dc-bytedance
dc-bytedance force-pushed the feat/root-interactive-upgrade branch from 3e5a172 to 876c35c Compare June 17, 2026 08:41
dc-bytedance and others added 2 commits July 1, 2026 14:21
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
The test builds a Factory literal without going through NewDefault, so it
never runs workspace detection and would otherwise inherit whatever value a
prior test left in the process-global core.currentWorkspace. A leaked
non-local workspace makes statePath() resolve to a subdir under
LARKSUITE_CLI_CONFIG_DIR, so the written update-state.json is not found and
the wantPrompt cases fail. Pin CurrentWorkspace to Local with restore,
matching cmd/config/bind_test.go and cmd/auth/list_test.go.
@liangshuo-1
liangshuo-1 force-pushed the feat/root-interactive-upgrade branch from b0dfca5 to d6a676e Compare July 1, 2026 06:23
@liangshuo-1
liangshuo-1 merged commit bdffffb into main Jul 1, 2026
37 checks passed
@liangshuo-1
liangshuo-1 deleted the feat/root-interactive-upgrade branch July 1, 2026 07:07
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.

2 participants