Validate compiled Suno output
This commit is contained in:
@@ -0,0 +1,29 @@
|
|||||||
|
import Foundation
|
||||||
|
|
||||||
|
public protocol SunoOutputValidating: Sendable {
|
||||||
|
func validate(_ output: CompiledSunoOutput) throws
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum SunoOutputValidationError: Error, Equatable, LocalizedError, Sendable {
|
||||||
|
case missingContent
|
||||||
|
|
||||||
|
public var errorDescription: String? {
|
||||||
|
switch self {
|
||||||
|
case .missingContent:
|
||||||
|
return "Add lyrics or a style prompt before sending the song to Suno."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct CompiledSunoOutputValidator: SunoOutputValidating {
|
||||||
|
public init() {}
|
||||||
|
|
||||||
|
public func validate(_ output: CompiledSunoOutput) throws {
|
||||||
|
let lyrics = output.lyricsText.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
|
let style = output.stylePrompt.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
|
|
||||||
|
guard !lyrics.isEmpty || !style.isEmpty else {
|
||||||
|
throw SunoOutputValidationError.missingContent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import MusicAssistantCore
|
||||||
|
import XCTest
|
||||||
|
|
||||||
|
final class SunoOutputValidationTests: XCTestCase {
|
||||||
|
func testValidatorRejectsOutputWithoutSunoContent() {
|
||||||
|
let output = CompiledSunoOutput(lyricsText: " \n ", stylePrompt: "\t")
|
||||||
|
|
||||||
|
XCTAssertThrowsError(try CompiledSunoOutputValidator().validate(output)) { error in
|
||||||
|
XCTAssertEqual(error as? SunoOutputValidationError, .missingContent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testValidatorAllowsLyricsOrAStylePrompt() throws {
|
||||||
|
let validator = CompiledSunoOutputValidator()
|
||||||
|
|
||||||
|
XCTAssertNoThrow(try validator.validate(CompiledSunoOutput(lyricsText: "Lyrics", stylePrompt: "")))
|
||||||
|
XCTAssertNoThrow(try validator.validate(CompiledSunoOutput(lyricsText: "", stylePrompt: "Cinematic folk")))
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -102,7 +102,7 @@ requirement is missing and blocks implementation, record it in
|
|||||||
appropriate.
|
appropriate.
|
||||||
- [x] Generate style prompt from genre blend, instrumentation, vocals,
|
- [x] Generate style prompt from genre blend, instrumentation, vocals,
|
||||||
tempo, harmony, emotion and production instructions.
|
tempo, harmony, emotion and production instructions.
|
||||||
- [ ] Validate output before handoff.
|
- [x] Validate output before handoff.
|
||||||
- [ ] Keep compiler independent from UI and OpenAI client.
|
- [ ] Keep compiler independent from UI and OpenAI client.
|
||||||
|
|
||||||
## Phase 8 --- Suno Handoff
|
## Phase 8 --- Suno Handoff
|
||||||
|
|||||||
Reference in New Issue
Block a user