mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-07 01:21:37 +00:00
The iPhone Duo layout uses UIHingeInteraction, which only exists in the iOS 27.1 SDK. CI ran Xcode 16.4 (iOS 18.5 SDK) on macos-15, so the app build failed: #available is a runtime check and cannot hide a symbol the SDK lacks. ChatView's iOS 26/27 modifiers would have failed next. Both jobs now run on the xcode-27 runner image (Xcode 27.1 by default), the toolchain releases are built with. The READMEs state Xcode 27.1 as the minimum. Swift 6.4 also timed out type-checking a long `+` chain in MultipartEncoderTests, so `swift test` failed to build; the expected body is now joined from an array. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
62 lines
2.1 KiB
Swift
62 lines
2.1 KiB
Swift
import Foundation
|
|
import HapiClient
|
|
import Testing
|
|
|
|
@Suite("MultipartFormData")
|
|
struct MultipartEncoderTests {
|
|
@Test func encodesFieldsAndOneFilePart() {
|
|
var form = MultipartFormData(boundary: "B")
|
|
form.appendField(name: "provider", value: "openai")
|
|
form.appendField(name: "mode", value: "standard")
|
|
form.appendFile(
|
|
fieldName: "file",
|
|
filename: "clip.m4a",
|
|
mimeType: "audio/mp4",
|
|
data: Data([0x01, 0x02])
|
|
)
|
|
|
|
// Joined rather than `+`-chained: Swift 6.4 times out type-checking the chain.
|
|
var expected = Data(
|
|
[
|
|
"--B\r\n",
|
|
"Content-Disposition: form-data; name=\"provider\"\r\n\r\n",
|
|
"openai\r\n",
|
|
"--B\r\n",
|
|
"Content-Disposition: form-data; name=\"mode\"\r\n\r\n",
|
|
"standard\r\n",
|
|
"--B\r\n",
|
|
"Content-Disposition: form-data; name=\"file\"; filename=\"clip.m4a\"\r\n",
|
|
"Content-Type: audio/mp4\r\n\r\n",
|
|
].joined().utf8
|
|
)
|
|
expected.append(Data([0x01, 0x02]))
|
|
expected.append(Data("\r\n--B--\r\n".utf8))
|
|
|
|
#expect(form.contentType == "multipart/form-data; boundary=B")
|
|
#expect(form.encodedBody() == expected)
|
|
}
|
|
|
|
@Test func encodingDoesNotConsumeTheBuilder() {
|
|
var form = MultipartFormData(boundary: "B")
|
|
form.appendField(name: "a", value: "1")
|
|
let first = form.encodedBody()
|
|
#expect(form.encodedBody() == first)
|
|
}
|
|
|
|
@Test func sanitizesQuotesAndCRLFInHeaderValues() {
|
|
var form = MultipartFormData(boundary: "B")
|
|
form.appendFile(
|
|
fieldName: "file",
|
|
filename: "we\"ird\r\nname.m4a",
|
|
mimeType: "audio/mp4",
|
|
data: Data()
|
|
)
|
|
let body = String(decoding: form.encodedBody(), as: UTF8.self)
|
|
#expect(body.contains("filename=\"we%22irdname.m4a\""))
|
|
}
|
|
|
|
@Test func generatedBoundariesAreUnique() {
|
|
#expect(MultipartFormData.makeBoundary() != MultipartFormData.makeBoundary())
|
|
}
|
|
}
|