Repository navigation
Open group config in the user's configured editor #5250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import Foundation | ||
| import Testing | ||
|
|
||
| #if canImport(cmux_DEV) | ||
| @testable import cmux_DEV | ||
| #elseif canImport(cmux) | ||
| @testable import cmux | ||
| #endif | ||
|
|
||
| /// Behavioral coverage for the editor-command resolver shared by every | ||
| /// cmux config-file opener (the workspace-group "Edit Group Configuration" | ||
| /// action, the "Open Cmux Settings File" action, and the Settings config | ||
| /// window). Verifies that a configured `preferredEditorCommand` is honored | ||
| /// and that an unset/blank value falls back to `nil` (the OS-default path). | ||
| @Suite struct PreferredEditorSettingsTests { | ||
| private func makeDefaults() -> UserDefaults { | ||
| let suiteName = "cmux-preferred-editor-tests-\(UUID().uuidString)" | ||
| let defaults = UserDefaults(suiteName: suiteName)! | ||
| defaults.removePersistentDomain(forName: suiteName) | ||
| return defaults | ||
| } | ||
|
|
||
| @Test func returnsNilWhenUnset() { | ||
| let defaults = makeDefaults() | ||
| #expect(PreferredEditorSettings.resolvedCommand(defaults: defaults) == nil) | ||
| } | ||
|
|
||
| @Test func returnsNilForEmptyOrWhitespaceCommand() { | ||
| for raw in ["", " ", "\n\t "] { | ||
| let defaults = makeDefaults() | ||
| defaults.set(raw, forKey: PreferredEditorSettings.key) | ||
| #expect( | ||
| PreferredEditorSettings.resolvedCommand(defaults: defaults) == nil, | ||
| "blank command \(raw.debugDescription) should fall back to OS default" | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @Test func returnsConfiguredCommandWhenSet() { | ||
| let defaults = makeDefaults() | ||
| defaults.set("code", forKey: PreferredEditorSettings.key) | ||
| #expect(PreferredEditorSettings.resolvedCommand(defaults: defaults) == "code") | ||
| } | ||
|
|
||
| @Test func trimsSurroundingWhitespaceFromConfiguredCommand() { | ||
| let defaults = makeDefaults() | ||
| defaults.set(" code -w \n", forKey: PreferredEditorSettings.key) | ||
| #expect(PreferredEditorSettings.resolvedCommand(defaults: defaults) == "code -w") | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import Foundation | ||
| import Testing | ||
|
|
||
| #if canImport(cmux_DEV) | ||
| @testable import cmux_DEV | ||
| #elseif canImport(cmux) | ||
| @testable import cmux | ||
| #endif | ||
|
|
||
| /// Regression coverage for the workspace-group "Edit Group Configuration…" | ||
| /// action. The opener must route the cmux config file through the same | ||
| /// editor-resolving path the rest of the app uses (so `preferredEditorCommand` | ||
| /// is honored) rather than handing it to `NSWorkspace.shared.open`, which | ||
| /// routes to the OS default `.json` handler and ignores the cmux setting. | ||
| /// | ||
| /// Before the fix the opener called `NSWorkspace.shared.open(configURL)` | ||
| /// directly, so the injected opener was never invoked and this test fails. | ||
| @Suite struct SidebarWorkspaceGroupConfigOpenerTests { | ||
| @Test func routesConfigFileThroughInjectedOpener() throws { | ||
| let home = FileManager.default.temporaryDirectory | ||
| .appendingPathComponent("cmux-group-config-\(UUID().uuidString)", isDirectory: true) | ||
| defer { try? FileManager.default.removeItem(at: home) } | ||
|
|
||
| var opened: [URL] = [] | ||
| SidebarWorkspaceGroupConfigOpener.openCmuxConfigInEditor(home: home) { opened.append($0) } | ||
|
|
||
| #expect(opened.count == 1) | ||
| let url = try #require(opened.first) | ||
| #expect(url.lastPathComponent == "cmux.json") | ||
| // Resolved beneath the injected home, under .config/cmux. | ||
| #expect(url.path.hasPrefix(home.path)) | ||
| #expect(url.deletingLastPathComponent().lastPathComponent == "cmux") | ||
|
|
||
| // The opener materializes an empty config when none exists, scoped to | ||
| // the injected home (no real-filesystem side effects). | ||
| #expect(FileManager.default.fileExists(atPath: url.path)) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.