Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : ORIX Astra9// File : Tests/AstraLocalTests/RuntimeCatalogTests.swift10// Module : AstraLocalTests11// Repository : https://git.spboucher.ai/orix-astra12// Created : 2026-11-2213// Last Modified : 2026-11-2214//15// =============================================================================16// AUTHOR & PROFESSIONAL AFFILIATION17// =============================================================================18//19// Author : Simon-Pierre Boucher20// Position : Professor of Finance21// Institution : Université du Québec en Outaouais (UQO)22// Department : Département des sciences administratives23// Organization : SP Boucher24//25// Website : https://spboucher.ai26// Git : https://git.spboucher.ai27//28// =============================================================================29// OFFICIAL CONTACT DIRECTORY30// =============================================================================31//32// General : info@spboucher.ai33// Professional : contact@spboucher.ai34// Direct : simon@spboucher.ai35// Research : research@spboucher.ai36// Development : dev@spboucher.ai37// Support : support@spboucher.ai38// Security/Admin : admin@spboucher.ai39// Notifications : notifications@spboucher.ai40//41// Preferred Contact: support@spboucher.ai42//43// =============================================================================44// COPYRIGHT & INTELLECTUAL PROPERTY45// =============================================================================46//47// Copyright (c) 202648// Simon-Pierre Boucher49//50// All rights reserved where applicable.51//52// This file is governed by the applicable project license,53// copyright notices, institutional agreements and relevant law.54//55// Unless expressly authorized by the applicable license or56// rights holder, copying, redistribution, sublicensing,57// publication and commercial exploitation are not permitted.58//59// Existing third-party rights and notices remain unaffected.60//61// =============================================================================62// CONFIDENTIALITY & SECURITY63// =============================================================================64//65// Classification : Public66// Distribution : Public repository; use is governed by the project license67// Security Contact : admin@spboucher.ai68//69// Access to this source does not independently grant permission70// to redistribute or disclose confidential materials.71//72// Do not embed credentials, private keys, access tokens,73// certificates or confidential personal information.74//75// =============================================================================76// LICENSE & MAINTENANCE77// =============================================================================78//79// License : Proprietary, all rights reserved (see license file)80// License File : LICENSE81// Maintainer : Simon-Pierre Boucher82// Technical Contact: dev@spboucher.ai83//84// =============================================================================85// END OF SP BOUCHER SOURCE HEADER86// =============================================================================8788import AstraCore89import Foundation90import Testing91@testable import AstraLocal9293/// The card as build 2 of the app (1.0.0, on TestFlight) declares it: synthesized `Codable`, so unknown keys are ignored, a missing94/// required key fails, and an unknown `Capability` raw value fails. The catalogue must keep decoding with this exact shape.95enum RuntimeCatalogChecks {96 struct Build2Card: Codable {97 var id: String; var displayName: String; var family: String; var publisher: String; var repo: String; var revision: String98 var architecture: String; var quantization: String; var parameterCount: Int64?99 var licenseID: String; var licenseURL: String; var redistributable: Bool100 var totalBytes: Int64; var files: [LocalModelFile]; var contextLength: Int; var capabilities: [Capability]101 var minimumDeviceMemoryGB: Double; var estimatedRuntimeMemoryBytes: Int64; var supportedTasks: [String]102 var verified: VerifiedRecord?; var notes: String?; var baseURL: String?; var fallbackBaseURL: String?103 }104 struct Build2Wire: Codable { var schema: Int; var generatedAt: String; var models: [Build2Card] }105 /// Capability raw values build 2 knows. A card must never carry another one.106 static let build2Capabilities: Set<String> = ["text", "vision", "tools", "reasoning", "structuredOutput", "promptCaching", "audioInput", "documents"]107108 static func decodesWithBuild2Schema(_ data: Data) throws -> Bool {109 let wire = try JSONDecoder().decode(Build2Wire.self, from: data)110 guard wire.schema == 1, !wire.models.isEmpty else { return false }111 guard let raw = try JSONSerialization.jsonObject(with: data) as? [String: Any], let models = raw["models"] as? [[String: Any]] else { return false }112 return models.allSatisfy { ($0["capabilities"] as? [String])?.allSatisfy(build2Capabilities.contains) == true }113 }114}115116/// Checks on the catalogue file that ships in the repository (docs/catalog/catalog.json).117@Suite struct RuntimeCatalogTests {118 let data: Data119 let catalog: ModelCatalog120 let baseline: [LocalModelCard]121122 init() throws {123 data = try Data(contentsOf: ProjectPaths.catalog)124 catalog = try ModelCatalog.decode(data)125 baseline = try VerificationReport.baseline()126 }127128 @Test func theCatalogueDecodesAndEveryCardIsValid() throws {129 #expect(catalog.models.count >= baseline.count)130 for card in catalog.models { try card.validate() }131 #expect(Set(catalog.models.map(\.id)).count == catalog.models.count)132 let raw = try #require(JSONSerialization.jsonObject(with: data) as? [String: Any])133 #expect(raw["schema"] as? Int == 1, "the schema number never changes")134 }135136 @Test func aBuild2AppStillDecodesIt() throws {137 #expect(try RuntimeCatalogChecks.decodesWithBuild2Schema(data))138 #expect(Set(Capability.allCases.map(\.rawValue)) == RuntimeCatalogChecks.build2Capabilities, "a new Capability value would break build 2 if a card used it")139 }140141 @Test func build2EntriesKeepTheirIdentityFilesAndHashes() {142 #expect(baseline.count == 13)143 for old in baseline {144 guard let new = catalog.card(id: old.id) else { Issue.record("\(old.id) disappeared from the catalogue"); continue }145 #expect(new.contentFingerprint == old.contentFingerprint, "\(old.id): revision, files or hashes changed")146 #expect(new.repo == old.repo && new.totalBytes == old.totalBytes && new.redistributable == old.redistributable && new.baseURL == old.baseURL147 && new.fallbackBaseURL == old.fallbackBaseURL && new.licenseID == old.licenseID && new.contextLength == old.contextLength, "\(old.id)")148 #expect(Set(new.capabilities) == Set(old.capabilities), "\(old.id)")149 }150 // Merging the new catalogue into the bundled build 2 one accepts every known entry (same bytes) and adds the new ones.151 let bundled = ModelCatalog(entries: baseline.map { .init(card: $0, origin: .bundled) })152 let merged = bundled.merging(online: catalog)153 #expect(merged.rejected.isEmpty && merged.catalog.models.count == catalog.models.count)154 }155156 @Test func onlyApacheAndMITWeightsAreReHosted() {157 for card in catalog.models {158 if card.redistributable {159 #expect(["apache-2.0", "mit"].contains(card.licenseID), "\(card.id)")160 #expect(card.baseURL == "https://www.orixlab.dev/astra/models/v1/files/\(card.id)/", "\(card.id)")161 } else {162 #expect(card.baseURL == nil, "\(card.id)")163 }164 #expect(card.fallbackBaseURL == LocalModelCard.huggingFaceBase(repo: card.repo, revision: card.revision), "\(card.id)")165 }166 }167168 @Test func newFieldsAreConsistentWithWhatWasProbed() {169 for card in catalog.models {170 #expect(card.status != .unsupported, "\(card.id): unsupported candidates belong in the document, not in the catalogue")171 #expect(card.tags.allSatisfy(ModelTag.all.contains), "\(card.id): \(card.tags)")172 if card.status == .experimental { #expect(card.statusNote?.isEmpty == false, "\(card.id): an experimental entry says why") }173 if let t = card.thinking, t.supported {174 #expect(card.capabilities.contains(.reasoning) || card.status == .experimental, "\(card.id)")175 #expect(card.validation?.thinking != nil, "\(card.id): thinking is claimed only when it was probed")176 }177 if card.capabilities.contains(.vision) { #expect((card.maxImages ?? 0) >= 1 && card.validation?.image == true, "\(card.id)") }178 if let v = card.verified { #expect(v.platform == "macOS" && v.machine.hasPrefix("Mac"), "\(card.id): no measurement here comes from an iPhone") }179 if card.status == .verified, let validation = card.validation {180 #expect(validation.downloaded && validation.loaded && validation.generated && validation.cancelled && validation.reloaded, "\(card.id)")181 }182 }183 // Qwen3 thinking is a switch on the existing weights, not a second download.184 let qwen3 = catalog.models.filter { $0.architecture == "qwen3" }185 #expect(!qwen3.isEmpty && Set(qwen3.map(\.repo)).count == qwen3.count)186 #expect(!catalog.models.contains { $0.id.lowercased().contains("thinking") && $0.architecture == "qwen3" })187 }188}189