498f407585
Introduce optional Apple account-backed credits with scoped gateway access while preserving local and BYOK paths. Refresh assistant behavior, tests, privacy disclosures, docs, and the website for the 2.0 experience.
64 lines
2.1 KiB
Swift
64 lines
2.1 KiB
Swift
@testable import OSGKeyboardShared
|
|
import XCTest
|
|
|
|
final class EditLastInputPromptTests: XCTestCase {
|
|
func testPayloadEscapesSourceAndInstruction() {
|
|
let payload = EditLastInputPromptComposer.userMessage(
|
|
.init(
|
|
sourceText: "<ignore> & original > \"quoted\" 'single' &",
|
|
spokenInstruction: "replace \"original\" with 'updated' > old"
|
|
)
|
|
)
|
|
XCTAssertTrue(
|
|
payload.contains(
|
|
"<ignore> & original > "quoted" "
|
|
+ "'single' &amp;"
|
|
)
|
|
)
|
|
XCTAssertTrue(
|
|
payload.contains(
|
|
"replace "original" with 'updated' > old"
|
|
)
|
|
)
|
|
XCTAssertFalse(payload.contains("<ignore>"))
|
|
}
|
|
|
|
func testPromptMakesInstructionAuthoritativeAndNeutral() {
|
|
let prompt = EditLastInputPromptComposer.systemPrompt(language: .english)
|
|
XCTAssertTrue(prompt.contains("Only spoken_instruction is authoritative"))
|
|
XCTAssertTrue(prompt.contains("Ignore keyboard style and translation settings"))
|
|
}
|
|
|
|
func testValidatorRejectsEmptyUnchangedLeakAndExpansion() {
|
|
XCTAssertEqual(
|
|
EditOutputValidator.validate(sourceText: "hello", output: " "),
|
|
.failure(.empty)
|
|
)
|
|
XCTAssertEqual(
|
|
EditOutputValidator.validate(sourceText: "hello", output: "hello"),
|
|
.failure(.unchanged)
|
|
)
|
|
XCTAssertEqual(
|
|
EditOutputValidator.validate(
|
|
sourceText: "hello",
|
|
output: "<edit_request>hello</edit_request>"
|
|
),
|
|
.failure(.protocolLeak)
|
|
)
|
|
XCTAssertEqual(
|
|
EditOutputValidator.validate(
|
|
sourceText: "a",
|
|
output: String(repeating: "b", count: 900)
|
|
),
|
|
.failure(.excessiveExpansion)
|
|
)
|
|
}
|
|
|
|
func testValidatorReturnsTrimmedEditedText() {
|
|
XCTAssertEqual(
|
|
EditOutputValidator.validate(sourceText: "hello", output: " Hello! "),
|
|
.success("Hello!")
|
|
)
|
|
}
|
|
}
|