Skip to content

refactor(desktop): one Tauri transport, shared command logic - #1257

Merged
NewtTheWolf merged 5 commits into
feat/web-slimfrom
refactor/desktop-command-modules
Oct 22, 2026
Merged

NewtTheWolf merged 5 commits into
feat/web-slimfrom
refactor/desktop-command-modules

Conversation

@NewtTheWolf

@NewtTheWolf NewtTheWolf commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #1255 (targets feat/web-slim). Goal: app and web run the same logic, and Tauri lives in one place instead of behind cfg attributes all over the crate.

Five commits, kept apart on purpose (.rules/rust.md rule 6):

  1. Route duplicated commands through the application layer (behaviour)
  2. Move all Tauri code into transport::desktop (structure only)
  3. e2e: list_databases against real Postgres/MySQL
  4. Remove the 15 commands the frontend never calls
  5. AGENTS.md: a notice at the top plus a "Backend layout" section, so contributors and their agents see the new structure. It sits outside the GitNexus-managed block, so re-indexing keeps it.

1. Desktop and web share the logic

Before, about 90 desktop commands had their own copy of logic the web RPC already got from application/. The biggest were connection save/update/duplicate/delete/test at 140 to 240 lines each. Those commands now call application/ too. The desktop app manages one Arc<ApplicationState>; its fields became Arcs, so the per-field Tauri state and the application layer share the same caches.

Desktop behaviour the application layer was missing moved there first, so the desktop app loses nothing and the web gains it:

  • Deleting a connection also removes its query history.
  • Deleting a group cleans up secrets, plugin secrets, icon and history of every connection in it. Neither side did this before.
  • AWS IAM connections:
    • they never fall back to a stored password;
    • testing one without a token fails with the actionable message;
    • duplicating one does not copy the token.
  • A URI the file marks as stored in the keychain but that is missing fails the connect with "Stored connection URI is unavailable in the OS keychain" instead of a driver error.
  • SSH secrets are only kept while the tunnel is enabled. An empty passphrase field keeps the stored passphrase.
  • Test connection:
    • an unknown connection id is treated as an ad-hoc connection;
    • the dbConnect progress step shows host:port.

Web parity gaps fixed on the way:

  • list_databases had no RPC route. The connection dialog could not load the database list in the browser. It now has a route with the same authorization rules as test_connection.
  • Editing a URI-passthrough connection in the browser failed with "Connection URI is required". The browser never receives the stored URI. The dialog now treats a keychain-only URI as present, and the input shows "Stored in the OS keychain…".
  • create_sqlite_database moved from the RPC handler into application/, so both transports use the same code.

Smaller fixes:

  • Theme package install from a path: the archive is read inside the cancellable install again, as its doc comment promises. This also fixes server-path installs on the web.
  • run_connections_backup returns the same object on both transports. The string branch in BackupTab and in the contract is gone.
  • Notebooks use the runtime paths.
  • kubectl calls no longer block the async runtime on desktop.
  • QueryHistoryState is removed; it was an empty marker type.

2. One Tauri transport

src-tauri/src/transport/
├── desktop/   ← every Tauri command, run(), windows, updater
└── web/
  • transport/desktop/<module>.rs mirrors the module the code came from.
  • Commands the web RPC also calls stay plain functions; transport/desktop holds a one-line #[tauri::command] wrapper for each.
  • run() moved from lib.rs unchanged. It still registers all 308 commands, and the generated inventory confirms the list is unchanged. After commit 4 it registers 293.
  • The askpass bridge stores the app's RuntimeEvents instead of a Tauri AppHandle, so askpass has no cfg left.
  • Outside transport/desktop, the only desktop gates are the transport::desktop declaration, async_rt and the run() dispatch in lib.rs.

The rule for new code is in .rules/rust.md (rule 7). CI enforces it with a grep: no tauri:: or tauri_plugin outside transport/desktop. A Tauri-only change therefore can't break the server build unnoticed.

Intentional differences that stay

Command Desktop Web
get_connection_by_id returns the stored secrets so the edit dialog can show them redacted; omitted fields keep the stored value on save
save_connection_icon, blob/SQL/explain file commands, imports/exports host paths from native dialogs upload/download tokens or the server file-browser roots
get_connections also runs the legacy embedded-SSH migration not needed: web never had that data
windows, updater, devtools, ChatGPT sign-in, deep links desktop only not applicable

Removed dead code

Each of these 15 registered commands was checked with rg -w across the repository: no caller in packages/, web-ui-project/, e2e/ or the plugin API. The plugin guide forbids plugins from invoking Tauri commands.

Command Why it was dead
list_all_preferences No caller.
get_theme Superseded by get_theme_catalog.
save_blob_to_file Blobs download through fetch_blob. The driver method of the same name stays.
preview_tabularis_import, apply_tabularis_import The frontend uses preview_tabularis_import_file and apply_prepared_tabularis_import.
export_connections_payload, import_connections_payload, encrypt_export_payload, decrypt_export_payload application/connection_files does the same work for the file-based flow.
open_visual_explain_window The --explain CLI path still opens the window through spawn_visual_explain_window.
open_json_viewer_window, get_json_viewer_session, complete_json_viewer_session, open_results_window, close_results_window The frontend opens these windows through WebviewWindow. Their Rust session stores were write-only, so the json_viewer and results_window modules and their ApplicationState fields went too.

That is about 740 lines.

Verified

  • Rust
    • cargo test --lib: 2135 passed. Before: 2154.
      • 20 tests of helpers that are now gone were removed.
      • 7 tests of the deleted window stores were removed.
      • 8 new tests cover the moved behaviour.
    • cargo check with default features, --features e2e-testing, --no-default-features --bin tabularis and --tests: no new warnings.
    • test:web-resilience passes.
  • Frontend
    • pnpm test: 7082 passed.
    • These checks pass: typecheck, lint, web:inventory, web:boundaries, web:packaging, web:docs, web:manual-parity, test:web-contract.
    • New test: the modal saves a keychain-only URI connection. It fails without the fix.
  • Web e2e
    • Chromium and Firefox: 10/10 against real SQLite/Postgres/MySQL and an external plugin, including the new list_databases check.
    • WebKit could not run locally because system libraries are missing; CI covers it.
  • Desktop smoke: the bundled debug app was started with an isolated profile and a seeded SQLite connection, and ran for 30 s.
    • Setup, schedulers and the frontend's startup commands ran.
    • There was no panic.
    • Every State<T> a command asks for is managed in run().
  • Docker: the image builds with --no-default-features, docker/smoke-test.sh passes 8/8, and the image size is unchanged.
  • GitNexus: detect_changes rates both refactor commits "critical". That reflects the number of moved and rerouted symbols. Tauri commands are called by name from the frontend, so the graph does not see those edges.

…layer

Desktop commands that had their own copy of logic the web RPC already gets
from `application/` now call the application layer, so both transports
behave the same. The desktop app manages one `Arc<ApplicationState>`; its
fields are `Arc`s so the per-field Tauri state shares the same instances.

Desktop behaviour the application layer lacked moved into it first:
- deleting a connection also removes its query history; a cascading group
  delete now cleans up secrets, plugin secrets, icons and history of every
  connection in the group (neither side did that before)
- AWS IAM connections never fall back to a stored password, testing one
  without a token fails with the actionable message, and duplicates do not
  copy the token
- a URI marked as stored in the keychain but missing fails a connect with
  a clear message
- SSH secrets are only kept while the tunnel is enabled, and an empty
  passphrase field keeps the stored one
- an unknown connection id in a test is treated as an ad-hoc connection;
  the dbConnect step shows host:port

Web parity fixes found on the way:
- `list_databases` had no RPC route; the connection dialog failed to load
  databases in the browser
- the connection dialog treats a URI that only lives in the keychain as
  present, so editing a passthrough connection no longer fails with
  "Connection URI is required"
- `create_sqlite_database` moved from the RPC handler into the application
  layer

Also: theme package installs from a path read the archive inside the
cancellable install again, `run_connections_backup` returns the same
object on both transports, notebooks use the runtime paths, and kubectl
calls no longer block the async runtime on desktop.
Tauri commands and everything that needs an AppHandle, a window or Tauri
state now live in `src-tauri/src/transport/desktop/`, next to
`transport/web`. It is the only module behind the `desktop` feature, so the
rest of the crate no longer carries per-item `cfg(feature = "desktop")` or
`cfg_attr(..., tauri::command)` attributes.

- `transport/desktop/<module>.rs` mirrors the module the code came from;
  commands the web RPC also calls stay plain functions and get a one-line
  Tauri wrapper there
- `run()` moved from lib.rs with the handler list unchanged (308 commands)
- the askpass bridge keeps the app's `RuntimeEvents` instead of a Tauri
  `AppHandle`
- helpers the desktop code needs became `pub(crate)`

No behaviour changes. `.rules/rust.md` documents the boundary and CI fails
when Tauri shows up outside `transport/desktop`.
@kilo-code-bot

kilo-code-bot Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Notes

  • Reviewed the three commits (route to application layer, move Tauri into transport::desktop, e2e list_databases). The PR description's claims matched the code where I checked them.
  • list_databases RPC is registered in the web dispatcher and covered by the same policy checks as test_connection: authorize, authorize_saved_access and authorize_saved_credentials.
  • CreateSqliteDatabase stays LocalAdmin-gated through RpcCommand::CreateSqliteDatabase metadata.
  • Moved desktop behaviour is present in application/connections.rs: keychain-unavailable fallback, IAM token handling, SSH secret toggling, keychain-URI-missing error, and group/connection deletion cleanup including query history.
  • The CI grep guard ("no tauri:: / tauri_plugin outside transport/desktop") returns nothing on the current tree.
  • lib.rs run() and the invoke-handler registration were carried over into transport/desktop/mod.rs. The askpass bridge now uses RuntimeEvents instead of an AppHandle.
  • The frontend keychain-only URI handling in NewConnectionModal.tsx is consistent with the clear/import paths.

Assumptions and gaps

  • I did not execute code. Cargo, pnpm and e2e results are taken from the PR description, not re-run.
  • Desktop get_connections now returns redacted connections through the application layer. The PR table lists get_connection_by_id as the desktop exception, and the edit dialog loads secrets through it, so I did not flag this.
Files Reviewed (118 files)
  • src-tauri/src/application/connections.rs, connections_tests.rs, themes.rs
  • src-tauri/src/transport/web/rpc.rs, rpc_connection_policy.rs, rpc_tests.rs
  • src-tauri/src/transport/desktop/** (moved Tauri commands, mod.rs, commands.rs)
  • src-tauri/src/runtime/state.rs, runtime/tests.rs, lib.rs, askpass/mod.rs
  • src-tauri/src/theme_commands.rs, theme_packages/commands.rs, notebooks.rs, ai_commands.rs, backup/mod.rs, query_history.rs, sqlite_database.rs
  • packages/web-ui/src/components/modals/NewConnectionModal.tsx, settings/BackupTab.tsx, api/contract.ts, locale files, NewConnectionModal.test.tsx
  • web-ui-project/e2e/tests/web-ui-matrix.spec.ts, scripts/generate-web-ui-api-inventory.mjs, docs
  • .github/workflows/ci.yml, .rules/rust.md

Reviewed by claude-sonnet-5.5 · Input: 320 · Output: 10.3K · Cached: 3.5M

Review guidance: REVIEW.md from base branch feat/web-slim

None of these 15 registered commands has a caller in the frontend,
the e2e suites or the plugin API (plugins must not invoke Tauri commands):
list_all_preferences, get_theme, save_blob_to_file,
preview_tabularis_import, apply_tabularis_import,
export_connections_payload, import_connections_payload,
encrypt_export_payload, decrypt_export_payload,
open_visual_explain_window, open_json_viewer_window,
get_json_viewer_session, complete_json_viewer_session,
open_results_window and close_results_window.

The JSON viewer and results windows are opened from the frontend, so their
Rust session stores (`json_viewer`, `results_window`) were write-only and
go too. The driver method `save_blob_to_file` stays; only the command that
wrapped it is gone.
Points contributors and their agents at transport/desktop for Tauri code and lists what in-flight branches need to change when they rebase.
@NewtTheWolf
NewtTheWolf merged commit 61d1d05 into feat/web-slim Oct 22, 2026
3 of 4 checks passed
@NewtTheWolf

Copy link
Copy Markdown
Collaborator Author

Folded into #1255: feat/web-slim was fast-forwarded to this branch, so GitHub marks this PR as merged. Review continues in #1255, which now carries both parts (the Tauri-free image and the shared app/web implementation).

@NewtTheWolf
NewtTheWolf deleted the refactor/desktop-command-modules branch October 22, 2026 16:02
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.

1 participant