//===----------------------------------------------------------------------===// // Copyright © 2026 Apple Inc. and the container project authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. //===----------------------------------------------------------------------===// import ContainerAPIClient import ContainerPersistence import ContainerizationArchive import Foundation import Testing /// Tests for `container system kernel set`. Each test modifies the global default /// kernel binary, so the suite must run fully serialised. @Suite(.serialized) struct TestCLIKernelSetSerial { private let remoteTar = ContainerSystemConfig().kernel.url private let defaultBinaryPath = ContainerSystemConfig().kernel.binaryPath private let defaultDigest = KernelConfig.defaultDigest /// Kernel release string parsed from the binary filename. /// /// The binary path is conventionally `vmlinux-{release}` — but Kata's distribution /// appends a `-{buildNumber}` suffix to the file (e.g. `vmlinux-6.18.15-186`) /// while `uname -r` in the guest only reports the upstream release (`6.18.15`). /// We strip a trailing `-N` where N is all digits to match what the guest reports, /// while preserving non-numeric suffixes like `-rc1` or `-rt` that ARE part of the /// upstream release string. private var expectedKernelRelease: String { let filename = URL(fileURLWithPath: defaultBinaryPath).lastPathComponent let prefix = "vmlinux-" let raw = filename.hasPrefix(prefix) ? String(filename.dropFirst(prefix.count)) : filename if let dashIdx = raw.lastIndex(of: "-"), raw[raw.index(after: dashIdx)...].allSatisfy({ $0.isNumber }) { return String(raw[..