Buckets:
localhost1978/localhost / LOCALHOST1978 /SSK_DocGen /Tests /SSK_DocGenTests /AppendixAVerificationTests.swift
| import Testing | |
| import Foundation | |
| @testable import SSK_DocGen | |
| @testable import SSK_Orchestrator | |
| @testable import SSK_Providers | |
| @testable import SSK_Abstractions | |
| ("Appendix A Verifications") | |
| struct AppendixAVerificationTests { | |
| // Vault paths | |
| var workspaceRoot: URL { | |
| // Try #file first, but if it resolves strangely (like in some SPM builds), fallback to the known absolute path | |
| let currentFileURL = URL(fileURLWithPath: #file) | |
| if currentFileURL.path.contains("/Users/") { | |
| return currentFileURL | |
| .deletingLastPathComponent() // SSK_DocGenTests | |
| .deletingLastPathComponent() // Tests | |
| .deletingLastPathComponent() // SSK_DocGen | |
| .deletingLastPathComponent() // SovereignSurvivalKit (repo root) | |
| } | |
| return URL(fileURLWithPath: "/Users/voxels/SovereignSurvivalKit/src/SovereignSurvivalKit") | |
| } | |
| var vaultURL: URL { | |
| workspaceRoot.appendingPathComponent("SovereignSurvivalKit/data/docs/SSK_Ledger_Vault") | |
| } | |
| ("Section 2A & 2B: Symbol Search & Dependency Graph") | |
| func testVaultJSONIntegrity() throws { | |
| let tempVault = FileManager.default.temporaryDirectory.appendingPathComponent("MockVault-\(UUID().uuidString)", isDirectory: true) | |
| try FileManager.default.createDirectory(at: tempVault, withIntermediateDirectories: true) | |
| defer { try? FileManager.default.removeItem(at: tempVault) } | |
| // 1. Symbol Search | |
| let indexFile = tempVault.appendingPathComponent("docc_index.json") | |
| let indexJSONData = """ | |
| { | |
| "entities": [ | |
| { "name": "AggregatorActor", "line_number": 85 } | |
| ] | |
| } | |
| """.data(using: .utf8)! | |
| try indexJSONData.write(to: indexFile) | |
| let indexData = try Data(contentsOf: indexFile) | |
| let indexJSON = try JSONSerialization.jsonObject(with: indexData) as! [String: Any] | |
| let entities = indexJSON["entities"] as! [[String: Any]] | |
| let aggregatorActor = entities.first(where: { $0["name"] as? String == "AggregatorActor" }) | |
| #expect(aggregatorActor != nil, "AggregatorActor should exist in docc_index.json") | |
| if let aa = aggregatorActor { | |
| let lineNumber = aa["line_number"] as? Int | |
| #expect(lineNumber != nil) | |
| } | |
| // 2. Dependency Graph | |
| let graphFile = tempVault.appendingPathComponent("graph.json") | |
| let graphJSONData = """ | |
| { | |
| "nodes": ["IngestionCoordinator"], | |
| "edges": [ | |
| { "source": "IngestionCoordinator", "target": "SomethingElse" } | |
| ] | |
| } | |
| """.data(using: .utf8)! | |
| try graphJSONData.write(to: graphFile) | |
| let graphData = try Data(contentsOf: graphFile) | |
| let graphJSON = try JSONSerialization.jsonObject(with: graphData) as! [String: Any] | |
| let nodes = graphJSON["nodes"] as! [String] | |
| #expect(nodes.contains("IngestionCoordinator"), "IngestionCoordinator should exist in graph nodes") | |
| let edges = graphJSON["edges"] as! [[String: String]] | |
| let ingestionEdges = edges.filter { $0["source"] == "IngestionCoordinator" } | |
| #expect(!ingestionEdges.isEmpty, "IngestionCoordinator should have dependency edges") | |
| } | |
| ("Section 3B & 3C: Hybrid Model & MLX Endpoint Tuning") | |
| @available(macOS 27.0, iOS 27.0, *) | |
| func testIntelligenceProviderRouterFallback() async throws { | |
| let foundationProvider = FoundationModelsProvider() | |
| let mlxProvider = MLXLocalProvider() | |
| let contextBudgetManager = ContextBudgetManager(provider: foundationProvider) | |
| let router = IntelligenceProviderRouter( | |
| foundationProvider: foundationProvider, | |
| mlxProvider: mlxProvider, | |
| contextBudgetManager: contextBudgetManager | |
| ) | |
| // By default it should use FoundationModelsProvider or MLXFallback | |
| let initialProvider = await router.activeProvider | |
| #expect(initialProvider == .foundationModel || initialProvider == .mlxFallback) | |
| // Toggle fallback | |
| await router.setForceMLXFallback(true) | |
| let fallbackProvider = await router.activeProvider | |
| #expect(fallbackProvider == .mlxFallback, "Router should switch to MLXLocalProvider when fallback is forced") | |
| // Toggle back | |
| await router.setForceMLXFallback(false) | |
| } | |
| /// Returns path to the built products directory. | |
| var productsDirectory: URL { | |
| #if os(macOS) | |
| for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") { | |
| return bundle.bundleURL.deletingLastPathComponent() | |
| } | |
| fatalError("couldn't find the products directory") | |
| #else | |
| return Bundle.main.bundleURL | |
| #endif | |
| } | |
| ("Section 3A: ACP Handshake & RPC Methods") | |
| func testACPHandshake() async throws { | |
| // Find the built executable | |
| let executableURL = productsDirectory.appendingPathComponent("SSK_DocGen") | |
| guard FileManager.default.fileExists(atPath: executableURL.path) else { | |
| Issue.record("Executable not found at \(executableURL.path)") | |
| return | |
| } | |
| let testWorkspace = FileManager.default.temporaryDirectory.appendingPathComponent("SSK_ACP_Test_\(UUID().uuidString)", isDirectory: true) | |
| try FileManager.default.createDirectory(at: testWorkspace, withIntermediateDirectories: true) | |
| defer { try? FileManager.default.removeItem(at: testWorkspace) } | |
| let process = Process() | |
| process.executableURL = executableURL | |
| process.arguments = ["serve", "--workspace", testWorkspace.path] | |
| let stdinPipe = Pipe() | |
| let stdoutPipe = Pipe() | |
| process.standardInput = stdinPipe | |
| process.standardOutput = stdoutPipe | |
| try process.run() | |
| // Give the serve process time to initialize its ACP context and registry. | |
| try await Task.sleep(nanoseconds: 500_000_000) | |
| defer { process.terminate() } // Ensure we don't leave zombie processes | |
| let initRequest = """ | |
| {"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"0.1.0","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}} | |
| """ | |
| if let data = initRequest.data(using: .utf8) { | |
| stdinPipe.fileHandleForWriting.write(data) | |
| } | |
| stdinPipe.fileHandleForWriting.closeFile() | |
| // Read response asynchronously line-by-line | |
| var outputString = "" | |
| for try await line in stdoutPipe.fileHandleForReading.bytes.lines { | |
| outputString = line | |
| // Break when we get a JSON payload | |
| if outputString.contains("\"jsonrpc\"") || outputString.contains("\"id\":") { | |
| break | |
| } | |
| } | |
| print("--- HANDSHAKE OUTPUT ---") | |
| print(outputString) | |
| print("------------------------") | |
| #expect(outputString.contains("\"jsonrpc\":\"2.0\"") || outputString.contains("\"jsonrpc\": \"2.0\"")) | |
| #expect(outputString.contains("\"id\":1") || outputString.contains("\"id\": 1")) | |
| // Check that it's a success result, not an error! A JSON-RPC error would still contain the id and jsonrpc version. | |
| #expect(outputString.contains("\"result\""), "Response should contain a result object on successful initialize.") | |
| #expect(!outputString.contains("\"error\""), "Response should not contain an error object.") | |
| } | |
| ("Section 3A Error Handling: Malformed RPC Request") | |
| func testMalformedRPCRequest() async throws { | |
| let executableURL = productsDirectory.appendingPathComponent("SSK_DocGen") | |
| guard FileManager.default.fileExists(atPath: executableURL.path) else { | |
| Issue.record("Executable not found at \(executableURL.path)") | |
| return | |
| } | |
| let testWorkspace = FileManager.default.temporaryDirectory.appendingPathComponent("SSK_ACP_Test_\(UUID().uuidString)", isDirectory: true) | |
| try FileManager.default.createDirectory(at: testWorkspace, withIntermediateDirectories: true) | |
| defer { try? FileManager.default.removeItem(at: testWorkspace) } | |
| let process = Process() | |
| process.executableURL = executableURL | |
| process.arguments = ["serve", "--workspace", testWorkspace.path] | |
| let stdinPipe = Pipe() | |
| let stdoutPipe = Pipe() | |
| process.standardInput = stdinPipe | |
| process.standardOutput = stdoutPipe | |
| try process.run() | |
| // Give the serve process time to initialize its ACP context and registry. | |
| try await Task.sleep(nanoseconds: 500_000_000) | |
| defer { process.terminate() } // Ensure we don't leave zombie processes | |
| let badRequest = """ | |
| {"invalid_json": true} | |
| """ | |
| if let data = badRequest.data(using: .utf8) { | |
| stdinPipe.fileHandleForWriting.write(data) | |
| } | |
| stdinPipe.fileHandleForWriting.closeFile() | |
| // Read response asynchronously line-by-line | |
| var outputString = "" | |
| for try await line in stdoutPipe.fileHandleForReading.bytes.lines { | |
| outputString = line | |
| // Break when we get an error payload | |
| if outputString.contains("\"error\"") || outputString.contains("-32600") { | |
| break | |
| } | |
| } | |
| print("--- MALFORMED OUTPUT ---") | |
| print(outputString) | |
| print("------------------------") | |
| #expect(outputString.contains("\"error\""), "Malformed request should produce an error response.") | |
| #expect(outputString.contains("-32600") || outputString.contains("Invalid JSON-RPC Request") || outputString.contains("Parse error")) | |
| } | |
| ("Section 2C: Read-Only Exploration Prompts (prompts/list)") | |
| func testACPPromptsList() async throws { | |
| let executableURL = productsDirectory.appendingPathComponent("SSK_DocGen") | |
| guard FileManager.default.fileExists(atPath: executableURL.path) else { return } | |
| let testWorkspace = FileManager.default.temporaryDirectory.appendingPathComponent("SSK_ACP_Test_\(UUID().uuidString)", isDirectory: true) | |
| try FileManager.default.createDirectory(at: testWorkspace, withIntermediateDirectories: true) | |
| defer { try? FileManager.default.removeItem(at: testWorkspace) } | |
| let process = Process() | |
| process.executableURL = executableURL | |
| process.arguments = ["serve", "--workspace", testWorkspace.path] | |
| let stdinPipe = Pipe() | |
| let stdoutPipe = Pipe() | |
| process.standardInput = stdinPipe | |
| process.standardOutput = stdoutPipe | |
| try process.run() | |
| // Give the serve process time to initialize its ACP context and registry. | |
| try await Task.sleep(nanoseconds: 500_000_000) | |
| defer { process.terminate() } | |
| let request = """ | |
| {"jsonrpc":"2.0","id":2,"method":"prompts/list","params":{}} | |
| """ | |
| if let data = request.data(using: .utf8) { stdinPipe.fileHandleForWriting.write(data) } | |
| stdinPipe.fileHandleForWriting.closeFile() | |
| var outputString = "" | |
| for try await line in stdoutPipe.fileHandleForReading.bytes.lines { | |
| outputString = line | |
| if outputString.contains("\"id\":2") || outputString.contains("\"id\": 2") { break } | |
| } | |
| #expect(outputString.contains("explain_pipeline")) | |
| #expect(outputString.contains("analyze_actor_architecture")) | |
| #expect(outputString.contains("verify_zk_claims")) | |
| } | |
| ("Section 5: ACP Tools List (tools/list)") | |
| func testACPToolsList() async throws { | |
| let executableURL = productsDirectory.appendingPathComponent("SSK_DocGen") | |
| guard FileManager.default.fileExists(atPath: executableURL.path) else { return } | |
| let testWorkspace = FileManager.default.temporaryDirectory.appendingPathComponent("SSK_ACP_Test_\(UUID().uuidString)", isDirectory: true) | |
| try FileManager.default.createDirectory(at: testWorkspace, withIntermediateDirectories: true) | |
| defer { try? FileManager.default.removeItem(at: testWorkspace) } | |
| let process = Process() | |
| process.executableURL = executableURL | |
| process.arguments = ["serve", "--workspace", testWorkspace.path] | |
| let stdinPipe = Pipe() | |
| let stdoutPipe = Pipe() | |
| process.standardInput = stdinPipe | |
| process.standardOutput = stdoutPipe | |
| try process.run() | |
| // Give the serve process time to initialize its ACP context and registry. | |
| try await Task.sleep(nanoseconds: 500_000_000) | |
| defer { process.terminate() } | |
| let request = """ | |
| {"jsonrpc":"2.0","id":3,"method":"tools/list","params":{}} | |
| """ | |
| if let data = request.data(using: .utf8) { stdinPipe.fileHandleForWriting.write(data) } | |
| stdinPipe.fileHandleForWriting.closeFile() | |
| var outputString = "" | |
| for try await line in stdoutPipe.fileHandleForReading.bytes.lines { | |
| outputString = line | |
| if outputString.contains("\"id\":3") || outputString.contains("\"id\": 3") { break } | |
| } | |
| #expect(outputString.contains("generate_docs")) | |
| #expect(outputString.contains("search_ledger_vault")) | |
| #expect(outputString.contains("inspect_codebase_graph")) | |
| #expect(outputString.contains("synthesize_media")) | |
| #expect(outputString.contains("update_curation_state")) | |
| } | |
| ("Section 3A: ACP Resources List (resources/list)") | |
| func testACPResourcesList() async throws { | |
| let executableURL = productsDirectory.appendingPathComponent("SSK_DocGen") | |
| guard FileManager.default.fileExists(atPath: executableURL.path) else { return } | |
| let testWorkspace = FileManager.default.temporaryDirectory.appendingPathComponent("SSK_ACP_Test_\(UUID().uuidString)", isDirectory: true) | |
| try FileManager.default.createDirectory(at: testWorkspace, withIntermediateDirectories: true) | |
| defer { try? FileManager.default.removeItem(at: testWorkspace) } | |
| let process = Process() | |
| process.executableURL = executableURL | |
| process.arguments = ["serve", "--workspace", testWorkspace.path] | |
| let stdinPipe = Pipe() | |
| let stdoutPipe = Pipe() | |
| process.standardInput = stdinPipe | |
| process.standardOutput = stdoutPipe | |
| try process.run() | |
| // Give the serve process time to initialize its ACP context and registry. | |
| try await Task.sleep(nanoseconds: 500_000_000) | |
| defer { process.terminate() } | |
| let request = """ | |
| {"jsonrpc":"2.0","id":4,"method":"resources/list","params":{}} | |
| """ | |
| if let data = request.data(using: .utf8) { stdinPipe.fileHandleForWriting.write(data) } | |
| stdinPipe.fileHandleForWriting.closeFile() | |
| var outputString = "" | |
| for try await line in stdoutPipe.fileHandleForReading.bytes.lines { | |
| outputString = line | |
| if outputString.contains("\"id\":4") || outputString.contains("\"id\": 4") { break } | |
| } | |
| #expect(outputString.contains("docc_index.json")) | |
| #expect(outputString.contains("graph.json")) | |
| #expect(outputString.contains("DocC_Index.md")) | |
| } | |
| ("Section 5: ACP Tools Call (tools/call)") | |
| func testACPToolsCall() async throws { | |
| let executableURL = productsDirectory.appendingPathComponent("SSK_DocGen") | |
| guard FileManager.default.fileExists(atPath: executableURL.path) else { return } | |
| let testWorkspace = FileManager.default.temporaryDirectory.appendingPathComponent("SSK_ACP_Test_\(UUID().uuidString)", isDirectory: true) | |
| try FileManager.default.createDirectory(at: testWorkspace, withIntermediateDirectories: true) | |
| defer { try? FileManager.default.removeItem(at: testWorkspace) } | |
| let process = Process() | |
| process.executableURL = executableURL | |
| process.arguments = ["serve", "--workspace", testWorkspace.path] | |
| let stdinPipe = Pipe() | |
| let stdoutPipe = Pipe() | |
| process.standardInput = stdinPipe | |
| process.standardOutput = stdoutPipe | |
| try process.run() | |
| // Give the serve process time to initialize its ACP context and registry. | |
| try await Task.sleep(nanoseconds: 500_000_000) | |
| defer { process.terminate() } | |
| let request = """ | |
| {"jsonrpc":"2.0","id":5,"method":"tools/call","params":{"name":"search_ledger_vault","arguments":{}}} | |
| """ | |
| if let data = request.data(using: .utf8) { stdinPipe.fileHandleForWriting.write(data) } | |
| stdinPipe.fileHandleForWriting.closeFile() | |
| var outputString = "" | |
| for try await line in stdoutPipe.fileHandleForReading.bytes.lines { | |
| outputString = line | |
| if outputString.contains("\"id\":5") || outputString.contains("\"id\": 5") { break } | |
| } | |
| let responseData = try #require(outputString.data(using: .utf8), "Expected non-empty response from tools/call") | |
| let response = try #require( | |
| JSONSerialization.jsonObject(with: responseData) as? [String: Any] | |
| ) | |
| let error = try #require(response["error"] as? [String: Any]) | |
| let code = try #require(error["code"] as? Int) | |
| #expect(response["id"] as? Int == 5) | |
| #expect(response["result"] == nil) | |
| #expect(code == -32602 || code == -32003 || code == -32601) | |
| } | |
| } | |
Xet Storage Details
- Size:
- 17.7 kB
- Xet hash:
- 5d32ff4ca159f9f540d0e65b5abdc5ab4a8118592afe5336a2f9f8ee113c972b
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.