Skip to content

[TW-4883] Mirror default grant writes through PersistDefaultGrant#68

Merged
qasim-nylas merged 3 commits intomainfrom
feature/TW-4883-tui-default-grant-mirror
Apr 30, 2026
Merged

[TW-4883] Mirror default grant writes through PersistDefaultGrant#68
qasim-nylas merged 3 commits intomainfrom
feature/TW-4883-tui-default-grant-mirror

Conversation

@qasim-nylas
Copy link
Copy Markdown
Collaborator

Summary

  • Route setup, login, and TUI default-grant writes through PersistDefaultGrant so grants.json and config.yaml stay in sync.
  • Preserve existing default-grant behavior on login while defensively mirroring stale config.yaml values.
  • Add regressions for single-grant sync persistence failures and TUI account switching.

Test Plan

  • go test ./internal/app/auth ./internal/cli/setup ./internal/tui -count=1
  • go test ./... -short
  • git diff --check origin/main...HEAD

SwitchGrant now routes through PersistDefaultGrant so it matches every
other write path (auth switch, Air UI, login auto-default, setup
wizard). Previously the TUI was the only path writing only to
grants.json, leaving config.yaml's default_grant stale until the next
non-TUI switch — which made `auth status` and Air/UI config endpoints
display the previous default after a TUI-side switch.

Adds a ConfigStore field to tui.Config; PersistDefaultGrant handles
nil ConfigStore so demo mode keeps working.
The TUI mirror fix (9137b0e) closed one gap; this audit found five more
write paths that updated only one of grants.json / config.yaml and relied
on a follow-up call to mirror the other side. Replace each pair with a
single PersistDefaultGrant call so every mutation is atomic with rollback.

  - Login / autoSwitchDefault / syncConfigWithGrantStore now persist via
    PersistDefaultGrant instead of SetDefaultGrant + manual config.Save.
  - setup.SyncGrants and setup.PromptDefaultGrant take a ConfigStore and
    persist the chosen default to both stores in one call.
  - nylas init's updateConfigGrants and nylas auth config's manual
    cfg.DefaultGrant assignment are removed — the persistence now lives
    inside SyncGrants / PromptDefaultGrant.
  - PersistDefaultGrant also clears the legacy in-memory cfg.Grants slice
    so the prior invariant (config.yaml never carries the grant list) is
    preserved end-to-end.
@qasim-nylas qasim-nylas requested a review from AaronDDM April 30, 2026 21:40
@qasim-nylas qasim-nylas merged commit 6b4fd76 into main Apr 30, 2026
6 checks passed
@qasim-nylas qasim-nylas deleted the feature/TW-4883-tui-default-grant-mirror branch April 30, 2026 21:45
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.

2 participants