Repository Public MIT
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : SP GlassKit7// File : Tests/SPGlassRegistryTests/SchemaConsistencyTests.swift8// Module : Tests9// Repository : https://git.spboucher.ai/sp-glasskit10// Project Website : https://glass.spboucher.ai11// Created : 2026-12-0212// Last Modified : 2026-12-0213//14// Author : Simon-Pierre Boucher15// Position : Professor of Finance16// Institution : Université du Québec en Outaouais (UQO)17// Organization : SP Boucher18// Website : https://spboucher.ai19// Git : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development : dev@spboucher.ai23// Support : support@spboucher.ai24// Security/Admin : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License : MIT33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import Foundation42import Testing43@testable import SPGlassRegistry4445/// The published JSON Schemas are written by hand; these tests keep them in step with the Swift models.46@Suite("Published JSON Schemas")47struct SchemaConsistencyTests {48 static let schemaDirectory = URL(fileURLWithPath: #filePath).deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent().appendingPathComponent("Registry/schema")4950 func schema(_ name: String) throws -> [String: Any] {51 let data = try Data(contentsOf: Self.schemaDirectory.appendingPathComponent(name))52 return try #require(JSONSerialization.jsonObject(with: data) as? [String: Any])53 }5455 func keys<T: Encodable>(of value: T) throws -> Set<String> {56 Set(try #require(JSONSerialization.jsonObject(with: RegistryJSON.encode(value)) as? [String: Any]).keys)57 }5859 @Test func manifestSchemaListsExactlyTheEncodedFields() throws {60 let manifest = ComponentManifest(id: "a", name: "A", version: "1.0.0", description: "", kind: "primitive", category: "buttons", platforms: [], minimumOS: [:], dependencies: [], frameworks: [], files: [], license: "MIT", symbols: [], examples: [], accessibility: [], changelog: [])61 let schema = try schema("component.schema.json")62 let properties = Set(try #require(schema["properties"] as? [String: Any]).keys)63 #expect(properties == (try keys(of: manifest)))64 let required = Set(try #require(schema["required"] as? [String]))65 #expect(required == properties.subtracting(["category"]))66 for field in ["schemaVersion", "id", "name", "version", "description", "kind", "platforms", "minimumOS", "dependencies", "files", "sha256", "license", "symbols", "examples", "accessibility", "changelog"] {67 #expect(required.contains(field), "\(field) is mandated")68 }69 }7071 @Test func indexSchemaListsExactlyTheEncodedFields() throws {72 let index = RegistryIndex(name: "r", homepage: "h", license: "MIT", items: [], themes: [])73 let schema = try schema("registry.schema.json")74 #expect(Set(try #require(schema["properties"] as? [String: Any]).keys) == (try keys(of: index)))75 }7677 @Test("Every schema is valid JSON with an identifier", arguments: ["registry.schema.json", "component.schema.json", "theme.schema.json", "config.schema.json", "lock.schema.json"])78 func wellFormed(name: String) throws {79 let schema = try schema(name)80 #expect((schema["$id"] as? String)?.hasSuffix("/registry/schema/\(name)") == true)81 #expect(schema["additionalProperties"] as? Bool == false)82 }8384 @Test func themeSchemaExposesNoRefractionOrBlur() throws {85 let properties = try #require(try schema("theme.schema.json")["properties"] as? [String: Any])86 let glass = try #require((properties["glass"] as? [String: Any])?["properties"] as? [String: Any])87 #expect(Set(glass.keys) == ["variant", "tint"])88 }8990 @Test func pathPatternAgreesWithTheValidator() throws {91 let definition = try #require(((try schema("config.schema.json")["properties"] as? [String: Any])?["sourcesPath"] as? [String: Any])?["pattern"] as? String)92 let regex = try NSRegularExpression(pattern: definition)93 for (path, valid) in [("Sources/App/GlassKit", true), ("a/b.swift", true), ("../x", false), ("/abs", false), ("a//b", false), (".git/x", false), ("a/.x", false), ("~/x", false), ("a\\b", false)] {94 let matches = regex.firstMatch(in: path, range: NSRange(path.startIndex..., in: path)) != nil95 #expect(matches == valid, "\(path)")96 #expect(((try? RegistryPath.validate(path)) != nil) == valid, "\(path)")97 }98 }99}100