Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Sources/LucaCore/Core/Installer/Installer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,7 @@ public struct Installer {

private func installExecutable(tool: Tool, downloadedFile: URL, installationDestination: URL) throws {
try fileManager.createDirectory(at: installationDestination, withIntermediateDirectories: true)
let binaryName: String = {
if let binaryName = tool.desiredBinaryName { return binaryName }
return tool.name
}()
let binaryName = tool.effectiveBinaryPath
let destinationFile = installationDestination
.appending(components: binaryName)
try fileManager.moveItem(at: downloadedFile, to: destinationFile)
Expand Down
53 changes: 53 additions & 0 deletions Tests/Core/InstallerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,59 @@ struct InstallerTests {
#expect(fileManager.fileExists(atPath: symLinkPath.path))
}

/// Regression test: when a direct-binary tool has `binaryPath` set but no `desiredBinaryName`
/// (e.g. `name: "FirebaseCLI"`, `binaryPath: "firebase"`), the binary must be stored under
/// the `binaryPath` name so that `isToolInstalled` can find it and avoids re-downloading
/// on every run.
@Test
func test_install_executableWithBinaryPath_storesBinaryUnderBinaryPathName() async throws {
let fileManager = FileManagerWrapperMock()
let toolName = "FirebaseCLI"
let binaryPathName = "firebase"
let version = "14.12.1"

let executableData = Data([0x7F, 0x45, 0x4C, 0x46,
0x02, 0x01, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x02, 0x00, 0xB7, 0x00])

let installer = Installer(
fileManager: fileManager,
ignoreArchitectureCheck: true,
quiet: true,
printer: PrinterMock(),
downloader: DownloaderMock(result: .tempFile(executableData))
)

let installationType = InstallationType.individualInline(
name: toolName,
version: version,
url: URL(string: "https://example.com/firebase-tools-macos")!,
binaryPath: binaryPathName,
desiredBinaryName: nil,
checksum: nil,
algorithm: nil
)

try await installer.install(installationType: installationType)

// Binary must be stored as "firebase", not "FirebaseCLI"
let binaryPath = fileManager.toolsFolder.appending(components: toolName, version, binaryPathName)
#expect(fileManager.fileExists(atPath: binaryPath.path))

// Symlink must be named "firebase"
let symLinkPath = fileManager.symlinksFolder.appending(component: binaryPathName)
#expect(fileManager.fileExists(atPath: symLinkPath.path))

// isToolInstalled checks versionFolder/binaryPath — must find it, avoiding re-download
let wrongPath = fileManager.toolsFolder.appending(components: toolName, version, toolName)
#expect(!fileManager.fileExists(atPath: wrongPath.path), "Binary must NOT be stored under tool name")

// Second install must not throw (isToolInstalled returns true, skips download)
try await installer.install(installationType: installationType)
#expect(fileManager.fileExists(atPath: binaryPath.path))
}

@Test
func test_install_unknownFileType_throws() async throws {
let fileManager = FileManagerWrapperMock()
Expand Down
Loading