SPB Git

Repository Public

RecordedTranscriptTests.swift 6.9 KB 149 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : ORIX Astra9// File             : Tests/AstraProvidersTests/RecordedTranscriptTests.swift10// Module           : AstraProvidersTests11// Repository       : https://git.spboucher.ai/orix-astra12// Created          : 2026-11-2113// Last Modified    : 2026-11-2114//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 AstraProviders9293/// Replays the transcripts captured from the live smoke tests on 2026-11-21 (`ASTRA_RECORD_DIR`; 2026-11-22 for Mistral,94/// DeepSeek, Moonshot and Cerebras), sanitised of response ids, encrypted reasoning and signatures. These are the bytes each95/// adapter actually received. DeepInfra has no recording: no valid key was available, so nothing could be captured.96@Suite("Recorded live transcripts")97struct RecordedTranscriptTests {98    static let recorded = Adapter.allCases.filter { $0 != .deepInfra }99    static func file(_ adapter: Adapter, _ label: String) -> String {100        let name = [Adapter.openAI: "openai", .anthropic: "anthropic", .openRouter: "openrouter", .xAI: "xai", .google: "gemini", .custom: "custom",101                    .mistral: "mistral", .deepSeek: "deepseek", .moonshot: "moonshot", .cerebras: "cerebras"][adapter]!102        return "recorded_\(name)_\(label).sse"103    }104105    @Test(arguments: RecordedTranscriptTests.recorded)106    func text(adapter: Adapter) async {107        let c = await collect(adapter.make(FixtureTransport(.sse(Self.file(adapter, "text")))).stream(adapter.request))108        expectWellFormed(c)109        #expect(c.text.contains("ASTRA-OK"))110        #expect(c.starts.first?.reportedModel == Live.model[adapter] ?? "maclustr-qwen3")111        #expect(c.completions == [.endOfTurn])112        #expect((c.outcome.usage?.inputTokens ?? 0) > 0)113        #expect((c.outcome.usage?.outputTokens ?? 0) > 0)114    }115116    /// The second leg of the tool round trip: the answer written from the tool result.117    @Test(arguments: RecordedTranscriptTests.recorded)118    func answerAfterToolResult(adapter: Adapter) async {119        let c = await collect(adapter.make(FixtureTransport(.sse(Self.file(adapter, "tool")))).stream(adapter.request))120        expectWellFormed(c)121        #expect(c.text.contains("18"))122        #expect(c.outcome.toolCalls.isEmpty)123        #expect(c.completions == [.endOfTurn])124    }125126    @Test(arguments: [Adapter.openAI, .anthropic, .xAI, .google, .openRouter, .mistral, .deepSeek, .moonshot, .cerebras])127    func reasoning(adapter: Adapter) async {128        let c = await collect(adapter.make(FixtureTransport(.sse(Self.file(adapter, "reasoning")))).stream(adapter.request))129        expectWellFormed(c)130        #expect(c.text.contains("23"))131        #expect((c.outcome.usage?.reasoningTokens ?? 0) > 0)132        #expect(!c.reasoning.contains("ENCRYPTED"))133        #expect(!c.reasoning.contains("SIGNATURE"))134        if adapter != .google { #expect(!c.reasoning.isEmpty) }     // Gemini returned no summary for this prompt135    }136137    @Test func fixturesContainNoCredentials() throws {138        let directory = Fixtures.url("")139        let files = try FileManager.default.contentsOfDirectory(at: directory, includingPropertiesForKeys: nil)140        #expect(files.count > 60)141        for file in files {142            let text = try String(contentsOf: file, encoding: .utf8)143            // Redaction would change the text if anything shaped like a key or an Authorization header were in it.144            let allowed = ["openrouter_key.json", "openrouter_key_limited.json"]      // contain the masked label "sk-or-v1-fix...ture"145            if !allowed.contains(file.lastPathComponent) { #expect(Redactor.redact(text) == text, "\(file.lastPathComponent) contains something shaped like a credential") }146        }147    }148}149
Files main
Menu

Theme