79 lines
3.3 KiB
Swift
79 lines
3.3 KiB
Swift
import MusicAssistantCore
|
|
import XCTest
|
|
|
|
final class SongGenerationContextTests: XCTestCase {
|
|
func testContextIncludesOnlySelectedInstrumentsWithArrangementDetails() {
|
|
let project = SongProject(
|
|
title: "Instrument Context",
|
|
idea: "Use selected instruments in generation",
|
|
sections: [
|
|
SongSection(id: "intro", type: .intro, title: "Opening"),
|
|
SongSection(id: "chorus", type: .chorus, title: "Final Chorus", order: 1)
|
|
],
|
|
instruments: [
|
|
InstrumentTrack(
|
|
instrumentId: "oud",
|
|
selected: true,
|
|
variant: "Arabic Oud",
|
|
playingStyle: "tremolo",
|
|
role: "lead motif",
|
|
autoArrangementEnabled: true,
|
|
placements: [
|
|
InstrumentPlacement(
|
|
sectionId: "intro",
|
|
startTime: 0,
|
|
endTime: 12,
|
|
direction: "solo opening"
|
|
)
|
|
]
|
|
),
|
|
InstrumentTrack(
|
|
instrumentId: "violin",
|
|
selected: false,
|
|
variant: "Violin",
|
|
role: "deselected counterline"
|
|
)
|
|
]
|
|
)
|
|
|
|
let context = SongGenerationContext(project: project)
|
|
|
|
XCTAssertTrue(context.hasSelectedInstruments)
|
|
XCTAssertEqual(context.selectedInstruments.map(\.instrumentId), ["oud"])
|
|
XCTAssertEqual(context.selectedInstruments.first?.displayName, "Arabic Oud")
|
|
XCTAssertEqual(context.selectedInstruments.first?.playingStyle, "tremolo")
|
|
XCTAssertEqual(context.selectedInstruments.first?.role, "lead motif")
|
|
XCTAssertEqual(context.selectedInstruments.first?.autoArrangementEnabled, true)
|
|
XCTAssertEqual(context.selectedInstruments.first?.placements.first?.sectionTitle, "Opening")
|
|
XCTAssertEqual(context.selectedInstruments.first?.placements.first?.sectionType, .intro)
|
|
XCTAssertEqual(
|
|
context.sunoStyleInstrumentPhrase,
|
|
"Arabic Oud (lead motif, tremolo, Opening 0s-12s solo opening)"
|
|
)
|
|
}
|
|
|
|
func testAIRequestsCarrySongGenerationContextFromProjects() {
|
|
let project = SongProject(
|
|
title: "Context Request",
|
|
idea: "Carry selected instruments",
|
|
instruments: [
|
|
InstrumentTrack(instrumentId: "qanun", selected: true, variant: "Qanun"),
|
|
InstrumentTrack(instrumentId: "piano", selected: false, variant: "Piano")
|
|
]
|
|
)
|
|
|
|
let generationRequest = SongProjectGenerationRequest(
|
|
context: AIRequestContext(userInstruction: "Generate."),
|
|
seedProject: project
|
|
)
|
|
let updateRequest = SongProjectUpdateRequest(
|
|
context: AIRequestContext(userInstruction: "Arrange."),
|
|
project: project,
|
|
allowedScopes: [.arrangement]
|
|
)
|
|
|
|
XCTAssertEqual(generationRequest.songGenerationContext.selectedInstruments.map(\.instrumentId), ["qanun"])
|
|
XCTAssertEqual(updateRequest.songGenerationContext.selectedInstruments.map(\.displayName), ["Qanun"])
|
|
}
|
|
}
|