Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : SP Music9// File : Tests/AppTests/ProductionSmokeTests.swift10// Description : Read-only smoke test against production.11// Module : AppTests12// Repository : https://git.spboucher.ai/sp-music-ios13// Created : 2026-11-1714// Last Modified : 2026-11-1715//16// =============================================================================17// AUTHOR & PROFESSIONAL AFFILIATION18// =============================================================================19//20// Author : Simon-Pierre Boucher21// Position : Professor of Finance22// Institution : Université du Québec en Outaouais (UQO)23// Department : Département des sciences administratives24// Organization : SP Boucher25//26// Website : https://spboucher.ai27// Git : https://git.spboucher.ai28//29// =============================================================================30// OFFICIAL CONTACT DIRECTORY31// =============================================================================32//33// General : info@spboucher.ai34// Professional : contact@spboucher.ai35// Direct : simon@spboucher.ai36// Research : research@spboucher.ai37// Development : dev@spboucher.ai38// Support : support@spboucher.ai39// Security/Admin : admin@spboucher.ai40// Notifications : notifications@spboucher.ai41//42// Preferred Contact: support@spboucher.ai43//44// =============================================================================45// COPYRIGHT & INTELLECTUAL PROPERTY46// =============================================================================47//48// Copyright (c) 202649// Simon-Pierre Boucher50//51// All rights reserved where applicable.52//53// This file is governed by the applicable project license,54// copyright notices, institutional agreements and relevant law.55//56// Unless expressly authorized by the applicable license or57// rights holder, copying, redistribution, sublicensing,58// publication and commercial exploitation are not permitted.59//60// Existing third-party rights and notices remain unaffected.61//62// =============================================================================63// CONFIDENTIALITY & SECURITY64// =============================================================================65//66// Classification : Public67// Distribution : Public repository; use is governed by the project license68// Security Contact : admin@spboucher.ai69//70// Access to this source does not independently grant permission71// to redistribute or disclose confidential materials.72//73// Do not embed credentials, private keys, access tokens,74// certificates or confidential personal information.75//76// =============================================================================77// LICENSE & MAINTENANCE78// =============================================================================79//80// License : None specified (no license file in this repository)81// Maintainer : Simon-Pierre Boucher82// Technical Contact: dev@spboucher.ai83//84// =============================================================================85// END OF SP BOUCHER SOURCE HEADER86// =============================================================================8788import Foundation89import SPMusicCore90import Testing9192/// Read-only check against the real server and the real library (Scripts/prod-smoke.sh creates a temporary listener93/// account for it and deletes it afterwards). Nothing is written to the library; one track is downloaded to the94/// simulator and thrown away.95let prodSession = ProcessInfo.processInfo.environment["SPMUSIC_PROD_SESSION"]9697@Suite(.serialized, .enabled(if: prodSession != nil, "production smoke test not requested")) @MainActor98struct ProductionSmokeTests {99 let base = URL(string: "https://music.spboucher.ai")!100101 @Test func appSiteAssociationListsThisApp() async throws {102 let (data, resp) = try await URLSession.shared.data(from: base.appendingPathComponent(".well-known/apple-app-site-association"))103 #expect((resp as? HTTPURLResponse)?.statusCode == 200)104 let apps = ((try JSONSerialization.jsonObject(with: data) as? [String: Any])?["webcredentials"] as? [String: Any])?["apps"] as? [String]105 #expect(apps?.contains("3YM54G49SN.ai.spboucher.spmusic.ios") == true) // native passkeys are allowed for this bundle106 }107108 @Test func synchronisesStreamsAndDownloadsFromTheRealLibrary() async throws {109 let s = try await Stack(base: base, token: prodSession, online: true); defer { s.cleanup() }110 let started = Date()111 let report = try await s.sync.sync()112 let counts = await s.db.counts()113 print("NOTE: production sync — \(counts.tracks) tracks, \(counts.albums) albums, \(counts.artists) artists in \(String(format: "%.1f", Date().timeIntervalSince(started))) s (revision \(report.revision))")114 #expect(counts.tracks > 500); #expect(counts.albums > 30)115 let again = try await s.sync.sync()116 #expect(again.catalogRows == 0) // incremental: nothing to fetch the second time117 let all = await s.db.allTracks()118 #expect(all.allSatisfy { $0.file?.sha256?.count == 64 })119120 // Stream a real 24-bit FLAC over TLS through the gateway.121 let hi = try #require(all.first { $0.codec == "flac" && ($0.bitDepth ?? 16) > 16 } ?? all.first)122 s.player.play([hi])123 #expect(await s.until(30, "the real FLAC stream to play 3 s") { s.player.position >= 3 && s.player.error == nil })124 print("NOTE: streamed \(hi.formatDescription), \(Format.bytes(hi.file?.sizeBytes ?? 0)), duration \(Format.duration(s.player.duration))")125 s.player.seek(to: hi.duration * 0.6) // a seek deep into the file = HTTP Range on the real server126 #expect(await s.until(30, "playback after a deep seek") { s.player.position >= hi.duration * 0.6 + 2 })127 s.player.stop()128129 // Download the smallest real track, verify it against the server's SHA-256, play it from the device.130 let small = try #require(all.min { ($0.file?.sizeBytes ?? .max) < ($1.file?.sizeBytes ?? .max) })131 await s.downloads.pin(.track, small.id)132 try await s.settle(180)133 let local = try #require(await s.downloads.localFile(trackId: small.id))134 #expect(try FileHash.sha256(of: local.url) == small.file?.sha256)135 print("NOTE: downloaded and verified \(Format.bytes(small.file?.sizeBytes ?? 0)) (\(small.formatDescription))")136 let off = try await Stack(base: URL(string: "http://127.0.0.1:9")!, token: nil, online: false, sharing: s)137 off.player.play([small])138 #expect(await off.until(15, "the downloaded real track to play with no network") { off.player.position >= 1.5 && off.player.source?.isLocal == true })139 off.player.stop()140 await s.downloads.removeEverything()141 }142}143