Skip to content

fix(config): propagate Lang across credential boundary; respect CurrentApp in priorLang#1157

Merged
liangshuo-1 merged 1 commit into
mainfrom
fix/cliconfig-lang-credential-boundary
May 28, 2026
Merged

fix(config): propagate Lang across credential boundary; respect CurrentApp in priorLang#1157
liangshuo-1 merged 1 commit into
mainfrom
fix/cliconfig-lang-credential-boundary

Conversation

@liangshuo-1
Copy link
Copy Markdown
Collaborator

@liangshuo-1 liangshuo-1 commented May 28, 2026

Follow-up to #1132 (now merged as 3b77055). Addresses two issues caught in cross-boundary review that the existing tests missed because they constructed RuntimeContext / CliConfig directly, bypassing the credential edge where the bugs live.

P1 — Lang dropped at credential boundary (blocker)

credential.Account had no Lang field, so AccountFromCliConfig / ToCliConfig silently dropped cfg.Lang. The production Factory builds CliConfig via acct.ToCliConfig() (factory_default.go Phase 3):

disk -> ResolveConfigFromMulti -> cfg.Lang = "ja_jp"   ✓
     -> AccountFromCliConfig    -> Account (no Lang)   ✗ dropped
     -> ToCliConfig             -> cfg.Lang = ""        ✗
     -> RuntimeContext.Lang()   -> ""
     -> mail signature etc.     -> falls back to zh_cn

The shortcut tests passed because they built &RuntimeContext{Config: &CliConfig{Lang: ...}} directly — bypassing the edge where the bug sits.

Fix: add Lang i18n.Lang to Account; copy in both AccountFromCliConfig and ToCliConfig.

Regression test: TestFullChain_LangSurvivesProductionPath walks the real production path SaveMultiAppConfig -> DefaultAccountProvider.ResolveAccount -> ToCliConfig and asserts Lang survives — forces future field additions to undergo the same audit.

P2 — priorLang ignored CurrentApp in multi-profile workspaces

cmd/config/bind.go:387 scanned multi.Apps and returned the first non-empty Lang. If a workspace had multiple named profiles (from profile add) and the active one was not Apps[0], a re-bind without --lang silently inherited the wrong profile's preference.

Fix: read multi.CurrentAppConfig("").Lang instead.

Regression tests:

  • TestPriorLang_RespectsCurrentAppCurrentApp wins over Apps[0]
  • TestPriorLang_FallsBackToFirstAppWhenCurrentUnset — bind-written single-app shape still works
  • TestPriorLang_MalformedReturnsEmpty — unparseable bytes branch

Test plan

  • go build ./...
  • go vet on impacted packages
  • go test on internal/credential, internal/cmdutil, internal/i18n, internal/core, cmd/config, cmd/auth, cmd/profile, shortcuts/common, shortcuts/mail — all green
  • 4 new tests (TestFullChain_LangSurvivesProductionPath, 3× TestPriorLang_*) — all green

Summary by CodeRabbit

  • Bug Fixes

    • Language selection now correctly respects the active app profile, preventing unintended language inheritance from other profiles.
    • Language configuration is properly maintained through the credential resolution process.
  • Tests

    • Added unit test coverage for language configuration handling in various scenarios.
    • Added integration test verifying language persistence in production credential flows.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 98d5f405-7961-4f4d-9486-2050295b2ccf

📥 Commits

Reviewing files that changed from the base of the PR and between 893555a and 0df7855.

📒 Files selected for processing (5)
  • cmd/config/bind.go
  • cmd/config/bind_test.go
  • internal/credential/integration_test.go
  • internal/credential/types.go
  • internal/credential/types_test.go

📝 Walkthrough

Walkthrough

This PR refines language preference handling in the CLI: fixes the priorLang helper to respect multi-profile configuration correctly, adds language field propagation through credential account types, and validates the end-to-end preservation of language settings with an integration test.

Changes

Language Preference Type System

Layer / File(s) Summary
Fix priorLang multi-profile logic
cmd/config/bind.go, cmd/config/bind_test.go
priorLang now uses MultiAppConfig.CurrentAppConfig("") to extract stored language, avoiding incorrect fallback to the first app when multiple named profiles exist. Three unit tests validate correct behavior for the CurrentApp field, legacy multi-app fallback, and malformed config handling.
Language propagation through credential Account
internal/credential/types.go, internal/credential/types_test.go
Account struct adds a Lang i18n.Lang field with bidirectional conversion: AccountFromCliConfig copies config language into the account, and ToCliConfig copies it back. Unit tests verify language is preserved in both directions during round-trip conversion.
Integration test for language survival
internal/credential/integration_test.go
New integration test persists a multi-app config with non-default language (Japanese), resolves an account through the production credential path, and validates that both the account and derived CLI config preserve the configured language.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • larksuite/cli#1132: Both PRs modify the cmd/config/bind.go language "priorLang" logic used to preserve/derive the previously persisted Lang on re-bind (and add/update cmd/config/bind_test.go coverage around that behavior).

Suggested reviewers

  • GeekyMax

Poem

🐰 A language now flows through account walls,

No profile confusion when binding calls,

From config to credential, the path is clear,

Japanese preferences persist here!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the two main fixes: propagating Lang across the credential boundary and respecting CurrentApp in priorLang for multi-profile workspaces.
Description check ✅ Passed The description fully covers motivation, root causes, fixes, and test plan with clear examples; all required template sections are present and substantive.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 fix/cliconfig-lang-credential-boundary

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/L Large or sensitive change across domains or core paths labels May 28, 2026
…ntApp in priorLang

Two issues caught in review of #1132 that the existing tests missed because
they constructed RuntimeContext/CliConfig directly, bypassing the credential
edge where the bug lives.

P1 — Lang dropped at credential boundary
  credential.Account had no Lang field, so AccountFromCliConfig and
  ToCliConfig silently dropped cfg.Lang. The production Factory builds
  CliConfig via acct.ToCliConfig() (factory_default.go Phase 3), which
  meant RuntimeContext.Lang() always returned "" in production and
  shortcuts/mail/mail_signature.go always fell back to zh_cn — defeating
  the whole point of persisting --lang.

  Fix: add Lang i18n.Lang to Account and copy it in both directions.

  Regression test: TestFullChain_LangSurvivesProductionPath walks the
  real path (SaveMultiAppConfig -> DefaultAccountProvider.ResolveAccount
  -> ToCliConfig) and asserts Lang survives, so any future field added
  to CliConfig forces the same audit.

P2 — priorLang ignored CurrentApp in multi-profile workspaces
  priorLang scanned all Apps and returned the first non-empty Lang. If a
  user had multiple profiles and the active one disagreed with Apps[0],
  a re-bind without --lang would silently inherit the wrong profile's
  preference.

  Fix: read multi.CurrentAppConfig("").Lang instead.

  Regression tests cover CurrentApp wins over Apps[0], single-app
  fallback, and malformed bytes.

Change-Id: If7a276605f84f398cec329c2c942b471b4c32749
@liangshuo-1 liangshuo-1 force-pushed the fix/cliconfig-lang-credential-boundary branch from 21316de to 0df7855 Compare May 28, 2026 12:15
@github-actions github-actions Bot removed the domain/mail PR touches the mail domain label May 28, 2026
@github-actions
Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add larksuite/cli#fix/cliconfig-lang-credential-boundary -y -g

@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.74%. Comparing base (893555a) to head (0df7855).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1157   +/-   ##
=======================================
  Coverage   68.74%   68.74%           
=======================================
  Files         627      627           
  Lines       58579    58580    +1     
=======================================
+ Hits        40269    40273    +4     
+ Misses      15018    15016    -2     
+ Partials     3292     3291    -1     

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

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

Actionable comments posted: 0

@liangshuo-1 liangshuo-1 merged commit ce2abff into main May 28, 2026
22 checks passed
@liangshuo-1 liangshuo-1 deleted the fix/cliconfig-lang-credential-boundary branch May 28, 2026 12:53
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