diff --git a/tests/validate.test.affine b/tests/validate.test.affine index 98424d6..310024d 100644 --- a/tests/validate.test.affine +++ b/tests/validate.test.affine @@ -1,11 +1,8 @@ // SPDX-License-Identifier: MPL-2.0 -// Ported via Harvard Engine mechanical processor +// Ported via Harvard Engine (Semantic pass) module validate.test; -// TODO: Complete semantic implementation - -/* === ORIGINAL TYPESCRIPT CONTEXT === // SPDX-License-Identifier: MPL-2.0 // Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) // @@ -29,27 +26,27 @@ import { assert, assertExists } from "jsr:@std/assert@1"; import { join } from "jsr:@std/path@1"; // Repository root — resolved relative to this test file's location. -const REPO_ROOT = new URL("../", import.meta.url).pathname; +let REPO_ROOT = new URL("../", import.meta.url).pathname; // The canonical PDF filename (the primary artefact of this repo). -const PDF_NAME = "Tropical Resource Typing For Protocols.pdf"; +let PDF_NAME = "Tropical Resource Typing For Protocols.pdf"; // ==================================================================== // UNIT: Required files exist // ==================================================================== Deno.test("unit: PDF artefact exists", () => { - const stat = Deno.statSync(join(REPO_ROOT, PDF_NAME)); + let stat = Deno.statSync(join(REPO_ROOT, PDF_NAME)); assert(stat.isFile, `${PDF_NAME} must be a regular file`); }); Deno.test("unit: README.md exists", () => { - const stat = Deno.statSync(join(REPO_ROOT, "README.md")); + let stat = Deno.statSync(join(REPO_ROOT, "README.md")); assert(stat.isFile, "README.md must be a regular file"); }); Deno.test("unit: LICENSE exists", () => { - const stat = Deno.statSync(join(REPO_ROOT, "LICENSE")); + let stat = Deno.statSync(join(REPO_ROOT, "LICENSE")); assert(stat.isFile, "LICENSE must be a regular file"); }); @@ -58,7 +55,7 @@ Deno.test("unit: LICENSE exists", () => { // ==================================================================== Deno.test("smoke: PDF has non-zero size", () => { - const stat = Deno.statSync(join(REPO_ROOT, PDF_NAME)); + let stat = Deno.statSync(join(REPO_ROOT, PDF_NAME)); assert( (stat.size ?? 0) > 0, `${PDF_NAME} must have non-zero file size` @@ -66,7 +63,7 @@ Deno.test("smoke: PDF has non-zero size", () => { }); Deno.test("smoke: PDF is larger than 1KB (not a stub)", () => { - const stat = Deno.statSync(join(REPO_ROOT, PDF_NAME)); + let stat = Deno.statSync(join(REPO_ROOT, PDF_NAME)); assert( (stat.size ?? 0) > 1024, `${PDF_NAME} must be larger than 1KB — smaller files are likely stubs` @@ -74,12 +71,12 @@ Deno.test("smoke: PDF is larger than 1KB (not a stub)", () => { }); Deno.test("smoke: README.md is non-empty", () => { - const content = Deno.readTextFileSync(join(REPO_ROOT, "README.md")); + let content = Deno.readTextFileSync(join(REPO_ROOT, "README.md")); assert(content.trim().length > 0, "README.md must not be empty"); }); Deno.test("smoke: LICENSE is non-empty", () => { - const content = Deno.readTextFileSync(join(REPO_ROOT, "LICENSE")); + let content = Deno.readTextFileSync(join(REPO_ROOT, "LICENSE")); assert(content.trim().length > 0, "LICENSE must not be empty"); }); @@ -91,16 +88,16 @@ Deno.test("smoke: LICENSE is non-empty", () => { // ==================================================================== /** Returns all non-binary files under a directory. */ -function collectTextFiles(dir: string): string[] { - const binaryExtensions = new Set([".pdf", ".png", ".jpg", ".jpeg", ".gif", ".ico", ".woff", ".woff2"]); +fn collectTextFiles(dir: string): string[] { + let binaryExtensions = new Set([".pdf", ".png", ".jpg", ".jpeg", ".gif", ".ico", ".woff", ".woff2"]); const results: string[] = []; for (const entry of Deno.readDirSync(dir)) { if (entry.name.startsWith(".git")) continue; - const fullPath = join(dir, entry.name); + let fullPath = join(dir, entry.name); if (entry.isDirectory) { results.push(...collectTextFiles(fullPath)); } else if (entry.isFile) { - const ext = entry.name.includes(".") ? `.${entry.name.split(".").pop()}` : ""; + let ext = entry.name.includes(".") ? `.${entry.name.split(".").pop()}` : ""; if (!binaryExtensions.has(ext.toLowerCase())) { results.push(fullPath); } @@ -110,7 +107,7 @@ function collectTextFiles(dir: string): string[] { } Deno.test("p2p: all text files are valid UTF-8", () => { - const textFiles = collectTextFiles(REPO_ROOT); + let textFiles = collectTextFiles(REPO_ROOT); const errors: string[] = []; for (const file of textFiles) { try { @@ -127,9 +124,9 @@ Deno.test("p2p: all text files are valid UTF-8", () => { Deno.test("p2p: PDF has correct PDF magic bytes (%PDF-)", () => { // The first 5 bytes of every valid PDF file must be '%PDF-'. - const pdfPath = join(REPO_ROOT, PDF_NAME); - const bytes = Deno.readFileSync(pdfPath); - const magic = new TextDecoder("ascii").decode(bytes.slice(0, 5)); + let pdfPath = join(REPO_ROOT, PDF_NAME); + let bytes = Deno.readFileSync(pdfPath); + let magic = new TextDecoder("ascii").decode(bytes.slice(0, 5)); assert( magic === "%PDF-", `${PDF_NAME} must start with '%PDF-' (PDF magic bytes), got: '${magic}'` @@ -142,11 +139,11 @@ Deno.test("p2p: PDF has correct PDF magic bytes (%PDF-)", () => { Deno.test("e2e: README mentions 'Tropical Resource Typing' (no broken rename)", () => { // Stage 1: Discover - const readmePath = join(REPO_ROOT, "README.md"); + let readmePath = join(REPO_ROOT, "README.md"); assert(Deno.statSync(readmePath).isFile, "E2E stage 1: README.md must exist"); // Stage 2: Read - const content = Deno.readTextFileSync(readmePath); + let content = Deno.readTextFileSync(readmePath); assert(content.length > 0, "E2E stage 2: README.md must be readable and non-empty"); // Stage 3: Content check — README must reference the project topic @@ -162,16 +159,16 @@ Deno.test("e2e: README mentions 'Tropical Resource Typing' (no broken rename)", Deno.test("e2e: PDF full chain — exist → size → magic bytes", () => { // Stage 1: File exists - const pdfPath = join(REPO_ROOT, PDF_NAME); + let pdfPath = join(REPO_ROOT, PDF_NAME); assert(Deno.statSync(pdfPath).isFile, "E2E stage 1: PDF must exist"); // Stage 2: Size > 0 - const stat = Deno.statSync(pdfPath); + let stat = Deno.statSync(pdfPath); assert((stat.size ?? 0) > 0, "E2E stage 2: PDF size must be > 0"); // Stage 3: Magic bytes - const bytes = Deno.readFileSync(pdfPath); - const magic = new TextDecoder("ascii").decode(bytes.slice(0, 5)); + let bytes = Deno.readFileSync(pdfPath); + let magic = new TextDecoder("ascii").decode(bytes.slice(0, 5)); assert(magic === "%PDF-", `E2E stage 3: PDF must start with '%PDF-', got '${magic}'`); // Stage 4: File size cross-check (stat size matches read bytes) @@ -182,9 +179,9 @@ Deno.test("e2e: PDF full chain — exist → size → magic bytes", () => { }); Deno.test("e2e: LICENSE chain — exist → readable → non-empty", () => { - const licensePath = join(REPO_ROOT, "LICENSE"); + let licensePath = join(REPO_ROOT, "LICENSE"); assert(Deno.statSync(licensePath).isFile, "E2E: LICENSE must exist"); - const content = Deno.readTextFileSync(licensePath); + let content = Deno.readTextFileSync(licensePath); assert(content.length > 100, "E2E: LICENSE must have substantial content"); }); @@ -193,9 +190,9 @@ Deno.test("e2e: LICENSE chain — exist → readable → non-empty", () => { // ==================================================================== Deno.test("contract: README.md contains a heading", () => { - const content = Deno.readTextFileSync(join(REPO_ROOT, "README.md")); + let content = Deno.readTextFileSync(join(REPO_ROOT, "README.md")); // A heading is either a line starting with '#' (ATX) or underlined (setext). - const hasHeading = + let hasHeading = content.split("\n").some((line) => line.startsWith("#")) || content.includes("===") || content.includes("---"); @@ -206,8 +203,8 @@ Deno.test("contract: README.md contains a heading", () => { }); Deno.test("contract: LICENSE references a recognised license", () => { - const content = Deno.readTextFileSync(join(REPO_ROOT, "LICENSE")); - const recognisedLicenses = [ + let content = Deno.readTextFileSync(join(REPO_ROOT, "LICENSE")); + let recognisedLicenses = [ "Mozilla Public License", "MPL", "Palimpsest", @@ -216,7 +213,7 @@ Deno.test("contract: LICENSE references a recognised license", () => { "Apache License", "GNU General Public License", ]; - const mentions = recognisedLicenses.some((lic) => content.includes(lic)); + let mentions = recognisedLicenses.some((lic) => content.includes(lic)); assert( mentions, "contract: LICENSE must reference a recognised license identifier" @@ -228,8 +225,8 @@ Deno.test("contract: LICENSE references a recognised license", () => { // ==================================================================== Deno.test("aspect: README.md does not contain template placeholders", () => { - const content = Deno.readTextFileSync(join(REPO_ROOT, "README.md")); - const placeholderPatterns = ["{{REPO}}", "{{OWNER}}", "{{FORGE}}", "YOUR_REPO_NAME"]; + let content = Deno.readTextFileSync(join(REPO_ROOT, "README.md")); + let placeholderPatterns = ["{{REPO}}", "{{OWNER}}", "{{FORGE}}", "YOUR_REPO_NAME"]; for (const placeholder of placeholderPatterns) { assert( !content.includes(placeholder), @@ -241,7 +238,7 @@ Deno.test("aspect: README.md does not contain template placeholders", () => { Deno.test("aspect: PDF filename matches repo topic", () => { // The PDF filename must contain project-relevant terms. // This catches cases where a template PDF was not renamed. - const pdfName = PDF_NAME.toLowerCase(); + let pdfName = PDF_NAME.toLowerCase(); assert( pdfName.includes("tropical") || pdfName.includes("resource") || pdfName.includes("typing"), `aspect: PDF filename '${PDF_NAME}' should contain project-relevant terms` @@ -253,8 +250,8 @@ Deno.test("aspect: PDF filename matches repo topic", () => { // ==================================================================== Deno.test("benchmark: full repo text-file scan completes within 1 second", () => { - const start = performance.now(); - const textFiles = collectTextFiles(REPO_ROOT); + let start = performance.now(); + let textFiles = collectTextFiles(REPO_ROOT); for (const file of textFiles) { try { Deno.readTextFileSync(file); @@ -262,7 +259,7 @@ Deno.test("benchmark: full repo text-file scan completes within 1 second", () => // Binary files (that slipped through) are silently skipped. } } - const elapsed = performance.now() - start; + let elapsed = performance.now() - start; assert( elapsed < 1000, @@ -273,4 +270,3 @@ Deno.test("benchmark: full repo text-file scan completes within 1 second", () => ); }); -==================================== */