import { assert, assertEquals } from "https://deno.land/std@0.224.0/testing/asserts.ts"; /** * Proof of Concept: Ontology Traceability (Gen 2) * * Demonstrates extracting JSON-LD semantic requirements from a real markdown file * and validating that code implementation connects back to the business ontology. */ async function extractJsonLD(filePath: string): Promise { const content = await Deno.readTextFile(filePath); const regex = /```json-ld\n([\s\S]*?)\n```/g; const blocks = []; let match; while ((match = regex.exec(content)) !== null) { try { blocks.push(JSON.parse(match[1])); } catch (e) { // ignore invalid json } } return blocks; } if (import.meta.main) { console.log("Running Ontology Traceability PoC (Gen 2) tests..."); try { const tempFile = await Deno.makeTempFile({ suffix: ".md" }); await Deno.writeTextFile(tempFile, ` # System Requirements This document tracks requirements. \`\`\`json-ld { "@context": "https://schema.org/", "@type": "Requirement", "identifier": "REQ-AUTH-01", "name": "User Passkey Login", "implementedBy": ["file:///src/auth/login.ts"] } \`\`\` `); const ontology = await extractJsonLD(tempFile); await Deno.remove(tempFile); assertEquals(ontology.length, 1); const req = ontology[0]; assertEquals(req.identifier, "REQ-AUTH-01"); assertEquals(req["@type"], "Requirement"); // Simulate Gatekeeper verifying traceability const isTraceable = req.implementedBy && req.implementedBy.length > 0; assert(isTraceable, "Requirement must be linked to an implementation"); console.log("✅ Ontology Traceability PoC (Gen 2) successful: JSON-LD parsed from real markdown."); } catch (err) { console.error("❌ Ontology Traceability PoC (Gen 2) failed:", err); Deno.exit(1); } }