Buckets:
localhost1978/localhost / LOCALHOST1978 /SSK_DocGen /Tests /SSK_DocGenTests /ObsidianGraphEncapsulationTests.swift
| import Foundation | |
| import Testing | |
| @testable import SSK_DocGen | |
| @testable import SSK_Orchestrator | |
| @testable import SSK_Abstractions | |
| @testable import SSK_Foundation | |
| @testable import SSK_Providers | |
| ("Obsidian Knowledge Graph Encapsulation") | |
| struct ObsidianGraphEncapsulationTests { | |
| private func createTestWorkspace() throws -> (root: URL, vault: URL, workspace: URL) { | |
| let root = FileManager.default.temporaryDirectory | |
| .appendingPathComponent("SSKObsidianTest-\(UUID().uuidString)", isDirectory: true) | |
| let workspace = root.appendingPathComponent("workspace", isDirectory: true) | |
| let vault = root.appendingPathComponent("vault", isDirectory: true) | |
| let moduleDir = workspace.appendingPathComponent("Modules/TestCore", isDirectory: true) | |
| try FileManager.default.createDirectory(at: moduleDir, withIntermediateDirectories: true) | |
| try FileManager.default.createDirectory(at: vault, withIntermediateDirectories: true) | |
| let sourceCode = """ | |
| import Foundation | |
| import SSK_Abstractions | |
| /// A test service for off-grid operations. | |
| public struct SurvivalService { | |
| public let id: String | |
| public init(id: String) { self.id = id } | |
| public func execute() -> Bool { return true } | |
| } | |
| """ | |
| try sourceCode.write(to: moduleDir.appendingPathComponent("SurvivalService.swift"), atomically: true, encoding: .utf8) | |
| return (root, vault, workspace) | |
| } | |
| private actor MockIdentitySettlementCoordinator: IdentitySettlementCoordinating { | |
| var identityService: any IdentityServiceProviding = ZKIdentityService() | |
| var lastVerifiedClaims: IdentityClaimsPayload? = nil | |
| func archiveIdentityService() throws -> any IdentityManaging { | |
| throw IdentitySettlementError.archiveSigningUnavailable | |
| } | |
| func assertDeviceBinding(sessionURI: SSKURI) async throws { | |
| // Bypass | |
| } | |
| func conductIdentityPhase(sessionURI: SSKURI, psi: Double, claims: ZKClaims) async throws -> BilateralSettlementZKProof { | |
| return BilateralSettlementZKProof(age: 25, stateSignature: "mock_sig", jurisdiction: "US-CA") | |
| } | |
| } | |
| ("Graph encapsulation generates Obsidian Markdown files and knowledge_graph.json") | |
| @available(macOS 27.0, iOS 27.0, *) | |
| func testObsidianGraphEncapsulation() async throws { | |
| let paths = try createTestWorkspace() | |
| defer { try? FileManager.default.removeItem(at: paths.root) } | |
| let mockCoordinator = MockIdentitySettlementCoordinator() | |
| let aggregatorManager = AggregatorManager( | |
| settlementCoordinator: mockCoordinator | |
| ) | |
| let storage = await aggregatorManager.storageCoordinator | |
| try await storage.mountSecureEnclave(volume: paths.vault) | |
| // Seed persisted relational entities into storage coordinator | |
| let testEntity = SemanticAppEntity( | |
| sskURI: SSKURI( | |
| authority: .spec(standardID: SSKURI.StandardIdentifier(rawValue: "survival")), | |
| domain: .identity, | |
| subdomain: "node", | |
| pathComponents: [SSKURI.PathComponent(rawValue: "PrimaryNode")] | |
| ), | |
| type: .custom, | |
| semanticPrimitives: [.survival, .identity, .security], | |
| metadata: [ | |
| "name": AnyCodable("PrimaryNode"), | |
| "docComment": AnyCodable("Core survival beacon node"), | |
| "operationalStatus": AnyCodable("Active") | |
| ], | |
| logicalTimestamp: 1001, | |
| relationshipMap: ["ssk://spec:survival/identity/node/BackupNode"], | |
| triples: [ | |
| SemanticTriple(subject: "PrimaryNode", predicate: "protects", object: "VaultVolume") | |
| ] | |
| ) | |
| try await storage.saveEntity(testEntity) | |
| // Seed in-memory graph claims | |
| try await storage.appendToGraph( | |
| entities: [ | |
| Entity( | |
| id: "PrimaryNode", | |
| type: "Node", | |
| label: "Primary Node", | |
| description: "Root mesh anchor" | |
| ) | |
| ], | |
| relationships: [ | |
| Relationship( | |
| id: "rel-1", | |
| source: "PrimaryNode", | |
| target: "VaultVolume", | |
| type: "guards", | |
| description: "Guards vault" | |
| ) | |
| ], | |
| claims: [ | |
| Claim( | |
| id: "claim-alpha", | |
| statement: "Node integrity verified", | |
| source: "PrimaryNode", | |
| confidence: 0.99, | |
| verified: true | |
| ) | |
| ] | |
| ) | |
| let report = try await SSK_DocGen.runGenerateDocs( | |
| workspaceURL: paths.workspace, | |
| vaultURL: paths.vault, | |
| clean: false, | |
| settlementCoordinator: mockCoordinator | |
| ) | |
| #expect(report.filesProcessed >= 1) | |
| #expect(report.artifactsWritten > 0) | |
| // Verify required artifacts exist in the published vault | |
| let ledgerRoot = paths.vault.appendingPathComponent("ledger", isDirectory: true) | |
| let doccIndexURL = ledgerRoot.appendingPathComponent("docc_index.json") | |
| let graphURL = ledgerRoot.appendingPathComponent("graph.json") | |
| let knowledgeGraphURL = ledgerRoot.appendingPathComponent("knowledge_graph.json") | |
| let masterIndexURL = ledgerRoot.appendingPathComponent("DocC_Index.md") | |
| #expect(FileManager.default.fileExists(atPath: doccIndexURL.path)) | |
| #expect(FileManager.default.fileExists(atPath: graphURL.path)) | |
| #expect(FileManager.default.fileExists(atPath: knowledgeGraphURL.path)) | |
| #expect(FileManager.default.fileExists(atPath: masterIndexURL.path)) | |
| // Verify knowledge_graph.json structure | |
| let kgData = try Data(contentsOf: knowledgeGraphURL) | |
| let kgJSON = try JSONSerialization.jsonObject(with: kgData) as? [String: Any] | |
| #expect(kgJSON != nil) | |
| let nodes = kgJSON?["nodes"] as? [[String: Any]] | |
| let edges = kgJSON?["edges"] as? [[String: Any]] | |
| let claims = kgJSON?["claims"] as? [[String: Any]] | |
| #expect(nodes != nil && nodes!.count > 0) | |
| #expect(edges != nil && edges!.count > 0) | |
| #expect(claims != nil && claims!.count > 0) | |
| // Verify DocC_Index.md is formatted for Obsidian (YAML frontmatter, wikilinks, mermaid) | |
| let indexMD = try String(contentsOf: masterIndexURL, encoding: .utf8) | |
| #expect(indexMD.hasPrefix("---\n")) | |
| #expect(indexMD.contains("type: \"moc\"")) | |
| #expect(indexMD.contains("[[")) | |
| #expect(indexMD.contains("```mermaid")) | |
| #expect(indexMD.contains("## Semantic Primitives Hub")) | |
| // Verify entities and primitives directories in ledger vault | |
| let primitivesDir = ledgerRoot.appendingPathComponent("primitives", isDirectory: true) | |
| let entitiesDir = ledgerRoot.appendingPathComponent("entities", isDirectory: true) | |
| let claimsDir = ledgerRoot.appendingPathComponent("claims", isDirectory: true) | |
| let doccDir = ledgerRoot.appendingPathComponent("docc", isDirectory: true) | |
| let filesDir = ledgerRoot.appendingPathComponent("files", isDirectory: true) | |
| #expect(FileManager.default.fileExists(atPath: primitivesDir.path)) | |
| #expect(FileManager.default.fileExists(atPath: entitiesDir.path)) | |
| #expect(FileManager.default.fileExists(atPath: claimsDir.path)) | |
| #expect(FileManager.default.fileExists(atPath: doccDir.path)) | |
| #expect(FileManager.default.fileExists(atPath: filesDir.path)) | |
| // Inspect one of the primitive markdown files | |
| let primitiveFiles = try FileManager.default.contentsOfDirectory(atPath: primitivesDir.path) | |
| #expect(!primitiveFiles.isEmpty) | |
| let primFile = primitivesDir.appendingPathComponent(primitiveFiles.first!) | |
| let primContent = try String(contentsOf: primFile, encoding: .utf8) | |
| #expect(primContent.hasPrefix("---\n")) | |
| #expect(primContent.contains("type: \"semantic-primitive\"")) | |
| #expect(primContent.contains("tags:")) | |
| // Inspect one of the entity markdown files | |
| let entityFiles = try FileManager.default.contentsOfDirectory(atPath: entitiesDir.path) | |
| #expect(!entityFiles.isEmpty) | |
| let entityFile = entitiesDir.appendingPathComponent(entityFiles.first!) | |
| let entityContent = try String(contentsOf: entityFile, encoding: .utf8) | |
| #expect(entityContent.hasPrefix("---\n")) | |
| #expect(entityContent.contains("tags:")) | |
| #expect(entityContent.contains("## Metadata")) | |
| #expect(entityContent.contains("## Semantic Primitives")) | |
| } | |
| } | |
Xet Storage Details
- Size:
- 8.84 kB
- Xet hash:
- 038ac87628494f9a9e45d7ee2aa5e2ded6642250c23397dc71bb18f86f5fc7df
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.