From dde2beb1dba2c750464d6a57ef30d8e983fea674 Mon Sep 17 00:00:00 2001 From: Chanda Mulenga Date: Thu, 27 Aug 2026 15:39:21 +0200 Subject: [PATCH] fix: keep agent-core install script from joining fiif Swift multiline strings drop the last newline. The fd shim then starts with if, so ash sees fiif and rejects the script. --- .../Sources/DorydKit/MachineRecipeProvisioner.swift | 4 +++- .../DorydKitTests/MachineRecipeProvisionerTests.swift | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/dory-core-swift/Sources/DorydKit/MachineRecipeProvisioner.swift b/dory-core-swift/Sources/DorydKit/MachineRecipeProvisioner.swift index d9431bc4..1271a716 100644 --- a/dory-core-swift/Sources/DorydKit/MachineRecipeProvisioner.swift +++ b/dory-core-swift/Sources/DorydKit/MachineRecipeProvisioner.swift @@ -32,6 +32,8 @@ public enum MachineRecipeProvisioner { } private static func packageInstallScript(alpine: String, debian: String) -> String { + // Swift multiline strings drop the newline before the closing delimiter. + // A later `if` must start on a new line so ash does not see `fiif`. """ if command -v apk >/dev/null 2>&1; then apk add --no-cache \(alpine) @@ -44,7 +46,7 @@ public enum MachineRecipeProvisioner { echo "Dory recipes support Alpine apk and Debian apt guests" >&2 exit 69 fi - """ + """ + "\n" } public static func recipe(id rawID: String) throws -> Recipe { diff --git a/dory-core-swift/Tests/DorydKitTests/MachineRecipeProvisionerTests.swift b/dory-core-swift/Tests/DorydKitTests/MachineRecipeProvisionerTests.swift index 7a4609b1..40fac9cc 100644 --- a/dory-core-swift/Tests/DorydKitTests/MachineRecipeProvisionerTests.swift +++ b/dory-core-swift/Tests/DorydKitTests/MachineRecipeProvisionerTests.swift @@ -32,6 +32,13 @@ final class MachineRecipeProvisionerTests: XCTestCase { } } + func testAgentCoreInstallScriptDoesNotJoinFiIntoTheFdShim() throws { + let script = try MachineRecipeProvisioner.recipe(id: "agent-core").installScript + XCTAssertFalse(script.contains("fiif"), script) + XCTAssertTrue(script.contains("fi\nif ! command -v fd"), script) + XCTAssertTrue(script.contains("exit 69\nfi\n"), script) + } + func testRequiredProvisioningStageRejectsNonzeroExitWithStderr() { let result = DoryExecResult( exitCode: 17,