SPB Git

Repository Public

Fixtures.swift 6.7 KB 139 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : MacLustr Command Center (MCC)9// File             : packages/swift-core/Tests/MCCCoreTests/Support/Fixtures.swift10// Module           : MCCCoreTests11// Repository       : https://git.spboucher.ai/maclustr-command-center12// Project Website  : https://clustr.spboucher.ai13// Created          : 2026-11-1814// Last Modified    : 2026-11-1815//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: admin@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 Foundation89@testable import MCCCore9091enum Fixture {92    static let userID = "0199aaaa-0000-7000-8000-0000000000a1"93    static let sessionID = "0199aaaa-0000-7000-8000-0000000000b1"94    static let deviceID = "0199aaaa-0000-7000-8000-0000000000c1"95    static let nodeID = "0199aaaa-0000-7000-8000-0000000000d1"9697    static func json(_ text: String) -> JSONValue { try! JSONValue.parse(Data(text.utf8)) }9899    static var user: String {100        #"{"id":"\#(userID)","handle":"spb","display_name":"Simon-Pierre","role":"owner","locale":"fr","disabled":false,"created_at":"2026-11-18T20:00:00.123456789Z"}"#101    }102    static var session: String {103        #"{"id":"\#(sessionID)","kind":"bearer","device_id":"\#(deviceID)","current":true,"created_at":"2026-11-18T20:00:00Z","last_seen_at":"2026-11-18T20:00:00Z","authenticated_at":"2026-11-18T20:00:00Z","step_up_valid_until":"2026-11-18T20:05:00Z","idle_expires_at":"2026-12-18T20:00:00Z","absolute_expires_at":"2026-12-18T20:00:00Z"}"#104    }105    static func me(permissions: [String] = ["cluster.read", "nodes.read"]) -> JSONValue {106        json(#"{"user":\#(user),"permissions":[\#(permissions.map { "\"\($0)\"" }.joined(separator: ","))],"session":\#(session)}"#)107    }108    static func tokenPair(access: String, refresh: String) -> JSONValue {109        json(#"{"access_token":"\#(access)","access_expires_at":"\#(iso(600))","refresh_token":"\#(refresh)","refresh_expires_at":"\#(iso(86400))"}"#)110    }111    static func node(alias: String = "M4M64a", freshness: String = "fresh") -> String {112        #"{"id":"\#(nodeID)","alias":"\#(alias)","kind":"mac","hostname":"m4m64a.local","site":"lan","role":"compute","environment":"prod","tags":["studio"],"registered_via":"agent","maintenance":false,"maintenance_reason":"","created_at":"2026-11-18T20:00:00Z","freshness":"\#(freshness)","cpu_cores":16,"mem_bytes":68719476736}"#113    }114    static func nodeList(_ nodes: [String]) -> JSONValue { json(#"{"items":[\#(nodes.joined(separator: ","))]}"#) }115116    static func tokens(access: String = "access-1", refresh: String = "refresh-1", expiresIn: TimeInterval = 600) -> SessionTokens {117        SessionTokens(accessToken: access, accessExpiresAt: Date().addingTimeInterval(expiresIn), refreshToken: refresh,118                      refreshExpiresAt: Date().addingTimeInterval(86_400))119    }120121    /// A secure store already holding a session for `server`.122    static func signedInStore(for server: StubServer, access: String = "access-1", refresh: String = "refresh-1", expiresIn: TimeInterval = 600) -> InMemorySecureStore {123        let store = InMemorySecureStore()124        let s = SessionStore(store: store, baseURL: server.origin)125        try! s.save(tokens(access: access, refresh: refresh, expiresIn: expiresIn))126        try! s.saveDeviceID(deviceID)127        return store128    }129}130131/// Thread-safe counter / box for stub handlers.132final class Box<T: Sendable>: @unchecked Sendable {133    private let lock = NSLock()134    private var v: T135    init(_ v: T) { self.v = v }136    var value: T { get { lock.withLock { v } } set { lock.withLock { v = newValue } } }137    @discardableResult func update<R>(_ f: (inout T) -> R) -> R { lock.withLock { f(&v) } }138}139
Files main
Menu

Theme