SPB Git

Repository Public MIT

RecordedTranscriptTests.swift 6.5 KB 146 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`), sanitised of94/// response ids, encrypted reasoning and signatures. These are the bytes each adapter actually received.95@Suite("Recorded live transcripts")96struct RecordedTranscriptTests {97    static func file(_ adapter: Adapter, _ label: String) -> String {98        let name = [Adapter.openAI: "openai", .anthropic: "anthropic", .openRouter: "openrouter", .xAI: "xai", .google: "gemini", .custom: "custom"][adapter]!99        return "recorded_\(name)_\(label).sse"100    }101102    @Test(arguments: Adapter.allCases)103    func text(adapter: Adapter) async {104        let c = await collect(adapter.make(FixtureTransport(.sse(Self.file(adapter, "text")))).stream(adapter.request))105        expectWellFormed(c)106        #expect(c.text.contains("ASTRA-OK"))107        #expect(c.starts.first?.reportedModel == Live.model[adapter] ?? "maclustr-qwen3")108        #expect(c.completions == [.endOfTurn])109        #expect((c.outcome.usage?.inputTokens ?? 0) > 0)110        #expect((c.outcome.usage?.outputTokens ?? 0) > 0)111    }112113    /// The second leg of the tool round trip: the answer written from the tool result.114    @Test(arguments: Adapter.allCases)115    func answerAfterToolResult(adapter: Adapter) async {116        let c = await collect(adapter.make(FixtureTransport(.sse(Self.file(adapter, "tool")))).stream(adapter.request))117        expectWellFormed(c)118        #expect(c.text.contains("18"))119        #expect(c.outcome.toolCalls.isEmpty)120        #expect(c.completions == [.endOfTurn])121    }122123    @Test(arguments: [Adapter.openAI, .anthropic, .xAI, .google, .openRouter])124    func reasoning(adapter: Adapter) async {125        let c = await collect(adapter.make(FixtureTransport(.sse(Self.file(adapter, "reasoning")))).stream(adapter.request))126        expectWellFormed(c)127        #expect(c.text.contains("23"))128        #expect((c.outcome.usage?.reasoningTokens ?? 0) > 0)129        #expect(!c.reasoning.contains("ENCRYPTED"))130        #expect(!c.reasoning.contains("SIGNATURE"))131        if adapter != .google { #expect(!c.reasoning.isEmpty) }     // Gemini returned no summary for this prompt132    }133134    @Test func fixturesContainNoCredentials() throws {135        let directory = Fixtures.url("")136        let files = try FileManager.default.contentsOfDirectory(at: directory, includingPropertiesForKeys: nil)137        #expect(files.count > 60)138        for file in files {139            let text = try String(contentsOf: file, encoding: .utf8)140            // Redaction would change the text if anything shaped like a key or an Authorization header were in it.141            let allowed = ["openrouter_key.json", "openrouter_key_limited.json"]      // contain the masked label "sk-or-v1-fix...ture"142            if !allowed.contains(file.lastPathComponent) { #expect(Redactor.redact(text) == text, "\(file.lastPathComponent) contains something shaped like a credential") }143        }144    }145}146
Files main
Menu

Theme