Skip to content

fix(tui): show effective cost currency context in config view#1902

Open
LING71671 wants to merge 2 commits into
Hmbown:mainfrom
LING71671:fix/config-effective-cost-currency
Open

fix(tui): show effective cost currency context in config view#1902
LING71671 wants to merge 2 commits into
Hmbown:mainfrom
LING71671:fix/config-effective-cost-currency

Conversation

@LING71671
Copy link
Copy Markdown
Contributor

@LING71671 LING71671 commented May 21, 2026

Closes #1901.\n\n## Summary\n- keep the native /config cost_currency row anchored to the saved setting value\n- show the effective runtime currency alongside the saved value when locale fallback changes the display currency, e.g. usd (effective cny) for zh-Hans\n- include the effective display value in config filtering and add a regression test for zh-Hans + saved usd\n\n## Verification\n- cargo fmt --all\n- cargo test -p deepseek-tui --bin deepseek-tui config_view_cost_currency_shows_saved_and_effective_runtime_currency\n- cargo test -p deepseek-tui --bin deepseek-tui config_view_filter_matches_group_and_rows\n- git diff --check\n- cargo build

Greptile Summary

This PR fixes the /config view to correctly show the effective runtime currency alongside the saved setting value when a locale-based fallback causes a mismatch (e.g., saved usd but zh-Hans locale activates cny).

  • Adds an effective_cost_currency snapshot to ConfigView (populated from app.cost_currency at construction, always refreshed when the view is rebuilt after a save), and a row_display_value helper that compares canonicalized CostCurrency variants via from_setting on both sides before showing any annotation — correctly treating all aliases (yuan, rmb, ¥, $) as equivalent to their canonical currency.
  • Updates row_matches_filter to search the display value (so filtering on \"cny\" matches a saved \"usd\" row when zh-Hans locale is active), and adds a cost_currency hint string to the hints map.
  • Adds four regression tests with a mutex-guarded ConfigSettingsEnvGuard that safely isolates env-var state across parallel test runs.

Confidence Score: 5/5

Safe to merge — the change is narrowly scoped to display logic in the config view and does not touch any data persistence or runtime state paths.

The previous reviewer concern about alias comparison has been fully addressed: both the saved value and the effective value are now parsed through CostCurrency::from_setting before comparison, so aliases like yuan or rmb correctly match their canonical variant and produce no false annotation. The effective_cost_currency snapshot is always fresh because ConfigView is rebuilt via new_for_app immediately after every ConfigUpdated event.

No files require special attention.

Important Files Changed

Filename Overview
crates/tui/src/tui/views/mod.rs Adds effective_cost_currency snapshot to ConfigView, a row_display_value helper that compares canonicalized CostCurrency variants (not raw strings) to avoid false annotations, updates filter logic to search the display value, adds a hint string for cost_currency, and adds four regression tests with a safe mutex-guarded env guard.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[ConfigView::new_for_app] --> B[snapshot effective_cost_currency
from app.cost_currency]
    B --> C[ConfigView ready]
    C --> D{row_display_value called}
    D -->|key != cost_currency
or scope != Saved| E[return row.value]
    D -->|key == cost_currency
AND scope == Saved| F[from_setting on saved value
returns Option]
    F --> G[from_setting on effective
returns Option]
    G --> H{variants equal?}
    H -->|yes| E
    H -->|no| I[return annotated string]
    C --> J{ConfigUpdated persisted}
    J --> K[set_config_value updates app.cost_currency]
    K --> L[ConfigView rebuilt with fresh snapshot]
Loading

Reviews (2): Last reviewed commit: "fix(config): normalize cost currency dis..." | Re-trigger Greptile

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request modifies the ConfigView to display the effective runtime cost_currency from the application state rather than the saved configuration value. It also adds a ConfigSettingsEnvGuard test utility and a test case to verify this behavior. The review feedback indicates that displaying runtime values in a ConfigScope::Saved row is misleading and breaks UI conventions, as it hides the actual persisted setting and may lead users to believe their changes weren't saved. It is suggested to revert this change to maintain consistency.

Comment thread crates/tui/src/tui/views/mod.rs Outdated
section: ConfigSection::Display,
key: "cost_currency".to_string(),
value: settings.cost_currency.clone(),
value: cost_currency_config_value(app),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This change breaks the convention in ConfigView where rows with ConfigScope::Saved display values directly from settings, while ConfigScope::Session rows display runtime values from app.

By showing the effective runtime value (app.cost_currency) in a Saved row, the UI incorrectly implies that the displayed value is what is persisted in the configuration file. This is particularly confusing when locale-based overrides are active (e.g., zh-Hans forcing cny even if usd is saved). If a user attempts to edit this value to usd, the UI will continue to show cny after saving, making it appear as if the change failed or was not persisted.

Consider showing the actual saved value from settings here to maintain UI consistency and predictability for the 'Saved' scope.

                value: settings.cost_currency.clone(),

@LING71671 LING71671 force-pushed the fix/config-effective-cost-currency branch from f9c744d to d394b1e Compare May 21, 2026 11:44
@LING71671 LING71671 changed the title fix(tui): show effective cost currency in config view fix(tui): show effective cost currency context in config view May 21, 2026
@LING71671
Copy link
Copy Markdown
Contributor Author

Updated after Gemini's review: the cost_currency row now keeps the saved setting value as the editable value and only shows the effective runtime currency as display context when it differs, for example usd (effective cny) under zh-Hans. This preserves the SAVED-row convention while still making the locale-driven CNY display visible in native /config.

@Hmbown
Copy link
Copy Markdown
Owner

Hmbown commented May 27, 2026

Independent review (Devin):

Solid fix — the original gemini feedback was addressed well. The row_display_value approach correctly separates the saved value (used for edits) from the display string, so round-trip edits still persist what the user typed.

Currency scope: USD/CNY only. Rates are hardcoded in pricing.rs; no live exchange-rate fetch. The effective-currency override is purely locale-driven ("usd" + zh-Hans → Cny in app.rs:1696).

Bug: alias normalization mismatch. Saved values rmb, yuan, or ¥ are all valid and accepted by CostCurrency::from_setting, but row_display_value compares row.value != self.effective_cost_currency as raw strings. A user with cost_currency = "rmb" on zh-Hans would see rmb (effective cny) even though they already mean CNY — false alarm. Suggest normalizing row.value through CostCurrency::from_setting before the comparison.

Test gap: Only the ("usd", zh-Hans) → Cny path is exercised. No test for: aliases matching effective currency (should be silent), saved=cny matching effective=cny (should be silent), or non-zh-Hans locale.

v0.8.48 conflict (#2256 in flight): One conflict in the test imports — HEAD adds use std::fs at the same line where this PR adds use std::ffi::OsString. Trivial two-line merge; no logic conflict.

Filter behavior: row_display_value now feeds the filter path too (line 843), so typing cny in /config search will match the effective-currency annotation. That seems useful, just calling it out.

The core UX fix is right and worth landing once the alias comparison is tightened.

@LING71671 LING71671 force-pushed the fix/config-effective-cost-currency branch from d394b1e to df63a18 Compare May 27, 2026 13:43
@LING71671
Copy link
Copy Markdown
Contributor Author

Rebased this PR onto current upstream/main (head df63a18a) after the CodeWhale rename/mainline drift. The behavior is still scoped to native /config: the editable cost_currency row keeps the saved value, and only the displayed context/filter text includes the effective runtime currency when it differs, e.g. usd (effective cny) for zh-Hans.

Verification:

  • cargo fmt --all --check
  • git diff --check upstream/main...HEAD
  • cargo test -p codewhale-tui --bin codewhale-tui config_view_cost_currency_shows_saved_and_effective_runtime_currency --all-features
  • cargo test -p codewhale-tui --bin codewhale-tui config_view --all-features
  • cargo clippy -p codewhale-tui --all-targets --all-features (passes with existing schema_migration dead_code warnings plus current main warnings in commands/config.rs and runtime_log.rs)

Comment thread crates/tui/src/tui/views/mod.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Native /config shows saved USD while zh-Hans UI displays CNY costs

2 participants