diff --git a/mac/VibeTunnel/Utilities/CLIInstaller.swift b/mac/VibeTunnel/Utilities/CLIInstaller.swift index e5e8dce0..0b9a34f8 100644 --- a/mac/VibeTunnel/Utilities/CLIInstaller.swift +++ b/mac/VibeTunnel/Utilities/CLIInstaller.swift @@ -27,28 +27,40 @@ final class CLIInstaller { // MARK: - Properties private let logger = Logger(subsystem: "sh.vibetunnel.vibetunnel", category: "CLIInstaller") + private let binDirectory: String + + private var vtTargetPath: String { + URL(fileURLWithPath: binDirectory).appendingPathComponent("vt").path + } var isInstalled = false var isInstalling = false var lastError: String? + // MARK: - Initialization + + /// Creates a CLI installer + /// - Parameters: + /// - binDirectory: Directory for installation (defaults to /usr/local/bin) + init(binDirectory: String = "/usr/local/bin") { + self.binDirectory = binDirectory + } + // MARK: - Public Interface /// Checks if the CLI tool is installed func checkInstallationStatus() { Task { @MainActor in - let vtPath = "/usr/local/bin/vt" - // Check if vt script exists and is configured correctly var isCorrectlyInstalled = false - if FileManager.default.fileExists(atPath: vtPath) { + if FileManager.default.fileExists(atPath: vtTargetPath) { // Check if it contains the correct app path reference - if let content = try? String(contentsOfFile: vtPath, encoding: .utf8) { + if let content = try? String(contentsOfFile: vtTargetPath, encoding: .utf8) { // Verify it's our wrapper script with all expected components isCorrectlyInstalled = content.contains("VibeTunnel CLI wrapper") && content.contains("$TRY_PATH/Contents/Resources/vibetunnel") && - content.contains("exec \"$VIBETUNNEL_BIN\" fwd \"$@\"") + content.contains("exec \"$VIBETUNNEL_BIN\" fwd") } } @@ -117,9 +129,6 @@ final class CLIInstaller { return } - let vtTargetPath = "/usr/local/bin/vt" - let binDirectory = "/usr/local/bin" - // Create the installation script let script = """ #!/bin/bash diff --git a/mac/VibeTunnelTests/CLIInstallerTests.swift b/mac/VibeTunnelTests/CLIInstallerTests.swift index 72a8a749..84d8ad22 100644 --- a/mac/VibeTunnelTests/CLIInstallerTests.swift +++ b/mac/VibeTunnelTests/CLIInstallerTests.swift @@ -416,4 +416,34 @@ struct CLIInstallerTests { await installer.install() #expect(installer.isInstalled) } + + // MARK: - PR #153 Regression Test + + @Test("Script with TITLE_MODE_ARGS detected correctly", .tags(.regression)) + func scriptWithTitleModeArgsDetection() async throws { + let script = """ + #!/bin/bash + # VibeTunnel CLI wrapper + for TRY_PATH in "/Applications/VibeTunnel.app" "$HOME/Applications/VibeTunnel.app"; do + if [ -d "$TRY_PATH" ] && [ -f "$TRY_PATH/Contents/Resources/vibetunnel" ]; then + APP_PATH="$TRY_PATH" + break + fi + done + VIBETUNNEL_BIN="$APP_PATH/Contents/Resources/vibetunnel" + TITLE_MODE_ARGS="--title-mode dynamic" + exec "$VIBETUNNEL_BIN" fwd $TITLE_MODE_ARGS "$@" + """ + + let vtPath = tempDirectory.appendingPathComponent("vt").path + try script.write(toFile: vtPath, atomically: true, encoding: .utf8) + + let installer = CLIInstaller(binDirectory: tempDirectory.path) + installer.checkInstallationStatus() + + // Wait for the async Task in checkInstallationStatus to complete + try await Task.sleep(for: .milliseconds(100)) + + #expect(installer.isInstalled) + } }