- Created `CONCEPTS.md` to track coverage of blueprint structures - Added 5 new PoCs: CFG, Constitution, Frontmatter, Mutation, and Orphan Branch - Registered all 15 experiments in `lab.ts` runner - Ensured zero-dependency Deno execution for tests Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: mrteye <1945243+mrteye@users.noreply.github.com>
76 lines
2.2 KiB
TypeScript
76 lines
2.2 KiB
TypeScript
import {
|
|
assert,
|
|
assertEquals,
|
|
} from "https://deno.land/std@0.224.0/testing/asserts.ts";
|
|
import { extract } from "https://deno.land/std@0.224.0/front_matter/yaml.ts";
|
|
|
|
/**
|
|
* Proof of Concept: Declarative Frontmatter (YAML UUIDs)
|
|
*
|
|
* Demonstrates extracting UUIDv7 (mocked) from Markdown frontmatter
|
|
* to uniquely identify and trace artifacts within the repository.
|
|
*/
|
|
|
|
const mockMarkdownFile = `---
|
|
id: 018f6c3a-1234-7890-abcd-ef0123456789
|
|
type: requirements-doc
|
|
title: Authentication Specs
|
|
legacy_slug: 2024-0512.1.auth.specs
|
|
---
|
|
# Authentication Specs
|
|
This document outlines the authentication specs.
|
|
`;
|
|
|
|
const mockMissingIdMarkdown = `---
|
|
type: draft
|
|
title: Work in Progress
|
|
---
|
|
# WIP
|
|
Just starting this document.
|
|
`;
|
|
|
|
function parseArtifact(content: string) {
|
|
try {
|
|
const { attrs, body } = extract(content);
|
|
return { frontmatter: attrs as Record<string, unknown>, body };
|
|
} catch (_e) {
|
|
throw new Error("Failed to parse YAML frontmatter");
|
|
}
|
|
}
|
|
|
|
function validateArtifactId(frontmatter: Record<string, unknown>): boolean {
|
|
// Simplistic UUIDv7 regex validation mock
|
|
const uuidRegex =
|
|
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
const id = frontmatter.id;
|
|
|
|
if (!id || typeof id !== "string") return false;
|
|
return uuidRegex.test(id);
|
|
}
|
|
|
|
if (import.meta.main) {
|
|
console.log("Running Declarative Frontmatter PoC tests...");
|
|
|
|
try {
|
|
// 1. Valid Document
|
|
const validDoc = parseArtifact(mockMarkdownFile);
|
|
assertEquals(validDoc.frontmatter.title, "Authentication Specs");
|
|
const isValid = validateArtifactId(validDoc.frontmatter);
|
|
assert(isValid, "Expected valid UUID in frontmatter");
|
|
console.log(`✅ Validated Artifact ID: ${validDoc.frontmatter.id}`);
|
|
|
|
// 2. Invalid/Missing ID Document
|
|
const invalidDoc = parseArtifact(mockMissingIdMarkdown);
|
|
const isInvalid = validateArtifactId(invalidDoc.frontmatter);
|
|
assert(!isInvalid, "Expected validation to fail for missing ID");
|
|
console.log(
|
|
`✅ Correctly rejected document missing strict UUIDv7 identifier.`,
|
|
);
|
|
|
|
console.log("✅ Declarative Frontmatter PoC successful.");
|
|
} catch (err) {
|
|
console.error("❌ Declarative Frontmatter PoC failed:", err);
|
|
Deno.exit(1);
|
|
}
|
|
}
|