diff --git a/tests/validate.test.affine b/tests/validate.test.affine index 2823bc6..1b8e051 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,39 +26,39 @@ import { assertEquals, assertExists, assert } 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; // ==================================================================== // UNIT: Required files exist // ==================================================================== Deno.test("unit: README.adoc exists", () => { - const stat = Deno.statSync(join(REPO_ROOT, "README.adoc")); + let stat = Deno.statSync(join(REPO_ROOT, "README.adoc")); assert(stat.isFile, "README.adoc 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"); }); Deno.test("unit: Containerfile exists", () => { - const stat = Deno.statSync(join(REPO_ROOT, "Containerfile")); + let stat = Deno.statSync(join(REPO_ROOT, "Containerfile")); assert(stat.isFile, "Containerfile must exist (not Dockerfile)"); }); Deno.test("unit: config/session-sentinel.toml exists", () => { - const stat = Deno.statSync(join(REPO_ROOT, "config", "session-sentinel.toml")); + let stat = Deno.statSync(join(REPO_ROOT, "config", "session-sentinel.toml")); assert(stat.isFile, "config/session-sentinel.toml must exist"); }); Deno.test("unit: container/manifest.toml exists", () => { - const stat = Deno.statSync(join(REPO_ROOT, "container", "manifest.toml")); + let stat = Deno.statSync(join(REPO_ROOT, "container", "manifest.toml")); assert(stat.isFile, "container/manifest.toml must exist"); }); Deno.test("unit: .well-known/security.txt exists", () => { - const stat = Deno.statSync(join(REPO_ROOT, ".well-known", "security.txt")); + let stat = Deno.statSync(join(REPO_ROOT, ".well-known", "security.txt")); assert(stat.isFile, ".well-known/security.txt must exist (RFC 9116)"); }); @@ -70,17 +67,17 @@ Deno.test("unit: .well-known/security.txt exists", () => { // ==================================================================== Deno.test("unit: config/ directory exists", () => { - const stat = Deno.statSync(join(REPO_ROOT, "config")); + let stat = Deno.statSync(join(REPO_ROOT, "config")); assert(stat.isDirectory, "config/ must be a directory"); }); Deno.test("unit: container/ directory exists", () => { - const stat = Deno.statSync(join(REPO_ROOT, "container")); + let stat = Deno.statSync(join(REPO_ROOT, "container")); assert(stat.isDirectory, "container/ must be a directory"); }); Deno.test("unit: docs/ directory exists", () => { - const stat = Deno.statSync(join(REPO_ROOT, "docs")); + let stat = Deno.statSync(join(REPO_ROOT, "docs")); assert(stat.isDirectory, "docs/ must be a directory"); }); @@ -89,17 +86,17 @@ Deno.test("unit: docs/ directory exists", () => { // ==================================================================== Deno.test("smoke: README.adoc is non-empty", () => { - const content = Deno.readTextFileSync(join(REPO_ROOT, "README.adoc")); + let content = Deno.readTextFileSync(join(REPO_ROOT, "README.adoc")); assert(content.length > 0, "README.adoc 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.length > 0, "LICENSE must not be empty"); }); Deno.test("smoke: config/session-sentinel.toml is non-empty", () => { - const content = Deno.readTextFileSync( + let content = Deno.readTextFileSync( join(REPO_ROOT, "config", "session-sentinel.toml") ); assert(content.length > 0, "session-sentinel.toml must not be empty"); @@ -115,11 +112,11 @@ Deno.test("smoke: config/session-sentinel.toml is non-empty", () => { import { parse as parseTOML } from "jsr:@std/toml@1"; /** Recursively collects all .toml file paths under a directory. */ -function collectTomlFiles(dir: string): string[] { +fn collectTomlFiles(dir: string): string[] { 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(...collectTomlFiles(fullPath)); } else if (entry.isFile && entry.name.endsWith(".toml")) { @@ -130,16 +127,16 @@ function collectTomlFiles(dir: string): string[] { } Deno.test("p2p: all TOML files parse without error", () => { - const tomlFiles = collectTomlFiles(REPO_ROOT); + let tomlFiles = collectTomlFiles(REPO_ROOT); assert(tomlFiles.length > 0, "Must have at least one TOML file to validate"); const errors: string[] = []; for (const file of tomlFiles) { try { - const content = Deno.readTextFileSync(file); + let content = Deno.readTextFileSync(file); parseTOML(content); } catch (err) { - const relPath = file.replace(REPO_ROOT, ""); + let relPath = file.replace(REPO_ROOT, ""); errors.push(`${relPath}: ${err}`); } } @@ -160,16 +157,16 @@ Deno.test("p2p: all TOML files parse without error", () => { Deno.test("e2e: session-sentinel.toml full validation chain", () => { // Stage 1: File exists (discovery) - const configPath = join(REPO_ROOT, "config", "session-sentinel.toml"); - const stat = Deno.statSync(configPath); + let configPath = join(REPO_ROOT, "config", "session-sentinel.toml"); + let stat = Deno.statSync(configPath); assert(stat.isFile, "E2E stage 1: config file must be discoverable"); // Stage 2: Content is readable (IO) - const content = Deno.readTextFileSync(configPath); + let content = Deno.readTextFileSync(configPath); assert(content.length > 0, "E2E stage 2: config file must have content"); // Stage 3: TOML parses (syntax) - const config = parseTOML(content) as Record; + let config = parseTOML(content) as Record; assertExists(config, "E2E stage 3: TOML must parse to a non-null object"); // Stage 4: Top-level sentinel section present (structure) @@ -179,7 +176,7 @@ Deno.test("e2e: session-sentinel.toml full validation chain", () => { ); // Stage 5: Required sentinel fields present (contract) - const sentinel = config.sentinel as Record; + let sentinel = config.sentinel as Record; assertExists( sentinel.scan_interval, "E2E stage 5: sentinel.scan_interval must be present" @@ -188,15 +185,15 @@ Deno.test("e2e: session-sentinel.toml full validation chain", () => { Deno.test("e2e: container manifest full validation chain", () => { // Stage 1: Discover - const manifestPath = join(REPO_ROOT, "container", "manifest.toml"); + let manifestPath = join(REPO_ROOT, "container", "manifest.toml"); assert(Deno.statSync(manifestPath).isFile, "E2E: manifest.toml must exist"); // Stage 2: Parse - const content = Deno.readTextFileSync(manifestPath); - const manifest = parseTOML(content) as Record; + let content = Deno.readTextFileSync(manifestPath); + let manifest = parseTOML(content) as Record; // Stage 3: Required metadata fields - const meta = manifest.metadata as Record; + let meta = manifest.metadata as Record; assertExists(meta, "E2E: manifest must have [metadata] section"); assertExists(meta.name, "E2E: manifest.metadata.name must be present"); assertExists(meta.version, "E2E: manifest.metadata.version must be present"); @@ -215,11 +212,11 @@ Deno.test("e2e: container manifest full validation chain", () => { // ==================================================================== Deno.test("contract: session-sentinel.toml has required sentinel fields", () => { - const content = Deno.readTextFileSync( + let content = Deno.readTextFileSync( join(REPO_ROOT, "config", "session-sentinel.toml") ); - const config = parseTOML(content) as Record; - const sentinel = config.sentinel as Record; + let config = parseTOML(content) as Record; + let sentinel = config.sentinel as Record; assertExists(sentinel, "contract: [sentinel] section must exist"); assertExists(sentinel.scan_interval, "contract: scan_interval required"); @@ -231,7 +228,7 @@ Deno.test("contract: session-sentinel.toml has required sentinel fields", () => }); Deno.test("contract: security.txt has required RFC 9116 fields", () => { - const content = Deno.readTextFileSync( + let content = Deno.readTextFileSync( join(REPO_ROOT, ".well-known", "security.txt") ); assert(content.includes("Contact:"), "contract: security.txt must have Contact field"); @@ -243,12 +240,12 @@ Deno.test("contract: security.txt has required RFC 9116 fields", () => { }); Deno.test("contract: container/manifest.toml has required security section", () => { - const content = Deno.readTextFileSync( + let content = Deno.readTextFileSync( join(REPO_ROOT, "container", "manifest.toml") ); - const manifest = parseTOML(content) as Record; + let manifest = parseTOML(content) as Record; assertExists(manifest.security, "contract: manifest must have [security] section"); - const security = manifest.security as Record; + let security = manifest.security as Record; assertExists(security.user, "contract: security.user required"); assertExists( security.no_new_privileges, @@ -264,8 +261,8 @@ Deno.test("contract: container/manifest.toml has required security section", () // ==================================================================== /** Returns true if the string appears to contain a secret pattern. */ -function containsSecretPattern(content: string): boolean { - const secretPatterns = [ +fn containsSecretPattern(content: string): boolean { + let secretPatterns = [ /(?:api_key|apikey|api-key)\s*=\s*["'][^"']{8,}["']/i, /(?:password|passwd|pwd)\s*=\s*["'][^"']{4,}["']/i, /(?:secret|token)\s*=\s*["'][a-zA-Z0-9+/]{20,}["']/i, @@ -278,7 +275,7 @@ function containsSecretPattern(content: string): boolean { } Deno.test("aspect: no hardcoded secrets in config/session-sentinel.toml", () => { - const content = Deno.readTextFileSync( + let content = Deno.readTextFileSync( join(REPO_ROOT, "config", "session-sentinel.toml") ); assert( @@ -288,10 +285,10 @@ Deno.test("aspect: no hardcoded secrets in config/session-sentinel.toml", () => }); Deno.test("aspect: no hardcoded secrets in container TOML files", () => { - const containerDir = join(REPO_ROOT, "container"); + let containerDir = join(REPO_ROOT, "container"); for (const entry of Deno.readDirSync(containerDir)) { if (!entry.name.endsWith(".toml")) continue; - const content = Deno.readTextFileSync(join(containerDir, entry.name)); + let content = Deno.readTextFileSync(join(containerDir, entry.name)); assert( !containsSecretPattern(content), `aspect: ${entry.name} must not contain hardcoded secrets` @@ -302,11 +299,11 @@ Deno.test("aspect: no hardcoded secrets in container TOML files", () => { Deno.test("aspect: no placeholder text {{REPO}} remains in critical files", () => { // manifest.toml intentionally has {{PROJECT_DESCRIPTION}} — we check // the specific fields that must be resolved: name, version, license. - const manifestContent = Deno.readTextFileSync( + let manifestContent = Deno.readTextFileSync( join(REPO_ROOT, "container", "manifest.toml") ); - const manifest = parseTOML(manifestContent) as Record; - const meta = manifest.metadata as Record; + let manifest = parseTOML(manifestContent) as Record; + let meta = manifest.metadata as Record; // These specific fields must not be placeholders assert( @@ -331,13 +328,13 @@ Deno.test("aspect: no placeholder text {{REPO}} remains in critical files", () = // ==================================================================== Deno.test("benchmark: full repo TOML scan completes within 2 seconds", () => { - const start = performance.now(); - const tomlFiles = collectTomlFiles(REPO_ROOT); + let start = performance.now(); + let tomlFiles = collectTomlFiles(REPO_ROOT); for (const file of tomlFiles) { - const content = Deno.readTextFileSync(file); + let content = Deno.readTextFileSync(file); parseTOML(content); } - const elapsed = performance.now() - start; + let elapsed = performance.now() - start; assert( elapsed < 2000, @@ -349,4 +346,3 @@ Deno.test("benchmark: full repo TOML scan completes within 2 seconds", () => { ); }); -==================================== */