Buckets:
localhost1978/localhost / LOCALHOST1978 /Modules /SSK_Abstractions /Tests /SSK_AbstractionsTests /AudioIngestionContractsTests.swift
| import XCTest | |
| @testable import SSK_Abstractions | |
| final class AudioIngestionContractsTests: XCTestCase { | |
| func testAudioACPCommandShapesAndRoundTrip() throws { | |
| let start = AudioACPCommandRequest( | |
| method: .ingestAudio, | |
| ingestionRequest: makeRequest() | |
| ) | |
| XCTAssertNoThrow(try start.validate()) | |
| let status = AudioACPCommandRequest( | |
| method: .getAudioIngestion, | |
| jobID: AudioIngestionJobID() | |
| ) | |
| XCTAssertNoThrow(try status.validate()) | |
| let decoded = try JSONDecoder().decode( | |
| AudioACPCommandRequest.self, | |
| from: JSONEncoder().encode(status) | |
| ) | |
| XCTAssertEqual(decoded, status) | |
| } | |
| func testAudioACPCommandRejectsMixedArguments() throws { | |
| let request = AudioACPCommandRequest( | |
| method: .ingestAudio, | |
| ingestionRequest: makeRequest(), | |
| jobID: AudioIngestionJobID() | |
| ) | |
| XCTAssertThrowsError(try request.validate()) { error in | |
| XCTAssertEqual(error as? AudioACPContractError, .unexpectedJobID) | |
| } | |
| let missingJob = AudioACPCommandRequest(method: .cancelAudioIngestion) | |
| XCTAssertThrowsError(try missingJob.validate()) { error in | |
| XCTAssertEqual(error as? AudioACPContractError, .missingJobID) | |
| } | |
| } | |
| func testRequestRoundTripAndValidation() throws { | |
| let request = AudioIngestionRequest( | |
| clientRequestID: UUID(uuidString: "A13B1E73-16E3-4650-B399-66CDDD06589A")!, | |
| source: .securityScopedBookmark( | |
| data: Data([0x01, 0x02, 0x03]), | |
| displayName: "fixture.wav", | |
| contentTypeIdentifier: "com.microsoft.waveform-audio" | |
| ), | |
| mode: .incrementalFile, | |
| outputPolicy: .demo, | |
| presentationPolicy: .fullArtifactSummary, | |
| sharingPolicy: .finderReveal | |
| ) | |
| try request.validate() | |
| let encoded = try JSONEncoder().encode(request) | |
| let decoded = try JSONDecoder().decode(AudioIngestionRequest.self, from: encoded) | |
| XCTAssertEqual(decoded, request) | |
| } | |
| func testRequestRejectsUnknownSchemaAndEmptyBookmark() { | |
| let unknownSchema = AudioIngestionRequest( | |
| schemaVersion: 99, | |
| source: .securityScopedBookmark( | |
| data: Data([0x01]), | |
| displayName: "fixture.wav", | |
| contentTypeIdentifier: "com.microsoft.waveform-audio" | |
| ), | |
| mode: .postProduction | |
| ) | |
| XCTAssertThrowsError(try unknownSchema.validate()) { error in | |
| XCTAssertEqual(error as? AudioIngestionContractError, .unsupportedSchemaVersion(99)) | |
| } | |
| let emptyBookmark = AudioIngestionRequest( | |
| source: .securityScopedBookmark( | |
| data: Data(), | |
| displayName: "fixture.wav", | |
| contentTypeIdentifier: "com.microsoft.waveform-audio" | |
| ), | |
| mode: .postProduction | |
| ) | |
| XCTAssertThrowsError(try emptyBookmark.validate()) { error in | |
| XCTAssertEqual(error as? AudioIngestionContractError, .emptySecurityScopedBookmark) | |
| } | |
| } | |
| func testStateMachineAllowsCanonicalPath() throws { | |
| let start = AudioIngestionJobRecord( | |
| clientRequestID: UUID(), | |
| sourceContentHash: "source-hash" | |
| ) | |
| let authorizing = try start.transitioning(to: .authorizing) | |
| let waiting = try authorizing.transitioning(to: .waitingForModel) | |
| let analyzing = try waiting.transitioning(to: .analyzing) | |
| let persisting = try analyzing.transitioning(to: .persisting) | |
| let ready = try persisting.transitioning(to: .ready) | |
| let indexing = try ready.transitioning(to: .indexing) | |
| let sharing = try indexing.transitioning(to: .sharing) | |
| let completed = try sharing.transitioning(to: .completed) | |
| XCTAssertEqual(completed.state, .completed) | |
| XCTAssertTrue(completed.state.isTerminal) | |
| } | |
| func testStateMachineRejectsImpossibleAndTerminalTransitions() throws { | |
| let start = AudioIngestionJobRecord( | |
| clientRequestID: UUID(), | |
| sourceContentHash: "source-hash" | |
| ) | |
| XCTAssertThrowsError(try start.transitioning(to: .completed)) { error in | |
| XCTAssertEqual( | |
| error as? AudioIngestionContractError, | |
| .invalidStateTransition(from: .accepted, to: .completed) | |
| ) | |
| } | |
| let cancelled = try start.transitioning(to: .cancelled) | |
| XCTAssertThrowsError(try cancelled.transitioning(to: .authorizing)) | |
| } | |
| func testProgressAndWidgetModelsEnforceBounds() { | |
| let jobID = AudioIngestionJobID() | |
| let progress = AudioIngestionProgress( | |
| jobID: jobID, | |
| state: .analyzing, | |
| sourceName: "fixture.wav", | |
| fractionCompleted: 4, | |
| processedFrameCount: -1, | |
| artifactCount: -5, | |
| message: "Analyzing" | |
| ) | |
| XCTAssertEqual(progress.fractionCompleted, 1) | |
| XCTAssertEqual(progress.processedFrameCount, 0) | |
| XCTAssertEqual(progress.artifactCount, 0) | |
| let points = (0..<300).map { AudioChartPoint(time: Double($0), value: Double($0)) } | |
| + [AudioChartPoint(time: .nan, value: 1)] | |
| let series = (0..<5).map { | |
| AudioChartSeries(id: "series-\($0)", title: "Series \($0)", unit: "gap", points: points) | |
| } | |
| let summaries = (0..<15).map { | |
| AudioTelemetrySummary(id: "summary-\($0)", title: "Summary \($0)", gap: 0, tau: 0) | |
| } | |
| let model = AudioIngestionWidgetModel( | |
| jobID: jobID, | |
| title: "Fixture", | |
| sourceName: "fixture.wav", | |
| state: .analyzing, | |
| phaseMessage: "Analyzing", | |
| fractionCompleted: -1, | |
| chartSeries: series, | |
| telemetrySummaries: summaries | |
| ) | |
| XCTAssertEqual(model.fractionCompleted, 0) | |
| XCTAssertEqual(model.chartSeries.count, AudioIngestionWidgetModel.maximumSeriesCount) | |
| XCTAssertTrue(model.chartSeries.allSatisfy { | |
| $0.points.count == AudioIngestionWidgetModel.maximumPointsPerSeries | |
| }) | |
| XCTAssertEqual( | |
| model.telemetrySummaries.count, | |
| AudioIngestionWidgetModel.maximumTelemetrySummaryCount | |
| ) | |
| } | |
| func testManifestReadyValidation() throws { | |
| let jobID = AudioIngestionJobID() | |
| let sessionURI = makeURI(subdomain: "session") | |
| let artifacts = AudioArtifactManifest.requiredReadyArtifactKinds.map { kind in | |
| AudioArtifactReference( | |
| kind: kind, | |
| uri: makeURI(subdomain: kind.rawValue), | |
| contentHash: "hash-\(kind.rawValue)", | |
| byteCount: 1 | |
| ) | |
| } | |
| let manifest = AudioArtifactManifest( | |
| jobID: jobID, | |
| sessionURI: sessionURI, | |
| sourceContentHash: "source-hash", | |
| pipelineVersion: "1", | |
| modelRevision: "htdemucs", | |
| cacheKey: "cache-key", | |
| artifacts: artifacts, | |
| retentionClass: "default" | |
| ) | |
| XCTAssertNoThrow(try manifest.validateForReady()) | |
| XCTAssertTrue(manifest.missingRequiredArtifactKinds.isEmpty) | |
| let incomplete = AudioArtifactManifest( | |
| jobID: jobID, | |
| sessionURI: sessionURI, | |
| sourceContentHash: "source-hash", | |
| pipelineVersion: "1", | |
| modelRevision: "htdemucs", | |
| cacheKey: "cache-key", | |
| artifacts: [], | |
| retentionClass: "default" | |
| ) | |
| XCTAssertThrowsError(try incomplete.validateForReady()) | |
| XCTAssertEqual( | |
| incomplete.missingRequiredArtifactKinds, | |
| AudioArtifactManifest.requiredReadyArtifactKinds | |
| ) | |
| } | |
| private func makeURI(subdomain: String) -> SSKURI { | |
| SSKURI( | |
| authority: .cas(hash: SSKURI.ContentHash(rawValue: "test-hash")), | |
| domain: .media, | |
| subdomain: SSKURI.Subdomain(rawValue: subdomain) | |
| ) | |
| } | |
| private func makeRequest() -> AudioIngestionRequest { | |
| AudioIngestionRequest( | |
| source: .securityScopedBookmark( | |
| data: Data([1, 2, 3]), | |
| displayName: "fixture.wav", | |
| contentTypeIdentifier: "com.microsoft.waveform-audio" | |
| ), | |
| mode: .postProduction | |
| ) | |
| } | |
| } | |
Xet Storage Details
- Size:
- 8.52 kB
- Xet hash:
- 5f531e80bc7905690254615da7b3660cf076a434e662616a8d343f3686006713
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.