Skip to content

refactor: phase 3 tail — migrate 7 ViewModels and 2 coordinators to AppServices#1120

Merged
datlechin merged 10 commits intomainfrom
refactor/phase3-tail
May 8, 2026
Merged

refactor: phase 3 tail — migrate 7 ViewModels and 2 coordinators to AppServices#1120
datlechin merged 10 commits intomainfrom
refactor/phase3-tail

Conversation

@datlechin
Copy link
Copy Markdown
Member

Summary

Phase 3 tail. 7 ViewModels and 2 coordinators migrated to AppServices DI per the recipe in /tmp/audit/phase3-migration-pattern.md. Pattern proven by PR #1117 QuickSwitcherViewModel exemplar. Mechanical, no behavior change.

Migrated (commit order)

  1. ServerDashboardViewModel (4 .shared refs)
  2. FavoritesSidebarViewModel (1 ref kept; others single-VM, left direct)
  3. AIChatViewModel + 4 extensions (7 services)
  4. ERDiagramViewModel (1 ref; ERDiagramPositionStorage left direct)
  5. DatabaseSwitcherViewModel (2 services)
  6. WelcomeViewModel (2 services)
  7. FeedbackViewModel (added FeedbackAPIClient to AppServices)
  8. ConnectionFormCoordinator (4 services)
  9. MainContentCoordinator main file (4 services)

Container changes

AppServices grew by 1 service (FeedbackAPIClient). Followed the "don't over-eagerly containerize" rule: services accessed only by one VM stay as direct .shared rather than bloating the container. Pure single-touch singletons left as is: ToolApprovalCenter, AIKeyStorage, ChatToolRegistry, ERDiagramPositionStorage, GroupStorage, AppSettingsStorage, LinkedFolderWatcher, WelcomeRouter, WindowOpener, TabRouter, WindowLifecycleMonitor, SchemaProviderRegistry, ConnectionDataCache, WindowManager, PluginMetadataRegistry.

Out of scope

MainContentCoordinator's 35 extension files (Views/Main/Extensions/MainContentCoordinator+*.swift) NOT touched. Those access services via the main coordinator. Phase 4 territory; would explode this PR.

Test plan

  • Build clean (verified via xcodebuild Debug)
  • swiftlint clean on all touched files
  • Open server dashboard, confirm metrics load
  • Open ER diagram, confirm graph builds
  • AI chat: send a message, confirm streaming + tool calls work
  • Quick switcher (Cmd+K), DB switcher (Cmd+Shift+K)
  • Welcome window: import/export connections, group operations
  • Feedback window: submit feedback
  • Connection form: save / test / open existing
  • Open a query tab, run a query (MainContentCoordinator path)

Pattern doc

/tmp/audit/phase3-migration-pattern.md unchanged — the recipe held for every migration. No pattern bending needed.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 18719e253c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

do {
if !password.isEmpty && !promptForPassword {
ConnectionStorage.shared.savePassword(password, for: testConn.id)
services.connectionStorage.savePassword(password, for: testConn.id)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid retaining the form during connection tests

Because services is an instance property, referencing it unqualified inside this [weak self] task makes the closure strongly capture the coordinator before any weak self check. If the user closes the connection form while a slow test is running, the coordinator stays alive and the task can still save temporary secrets and later update or present errors for a dismissed form; capture services explicitly before creating the task (or in the capture list) to preserve the weak-self behavior.

Useful? React with 👍 / 👎.

@datlechin datlechin merged commit 2175c94 into main May 8, 2026
2 checks passed
@datlechin datlechin deleted the refactor/phase3-tail branch May 8, 2026 10:52
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