Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 37 additions & 41 deletions tests/validate.test.affine
Original file line number Diff line number Diff line change
@@ -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) <j.d.a.jewell@open.ac.uk>
//
Expand All @@ -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");
});

Expand All @@ -58,28 +55,28 @@ 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`
);
});

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`
);
});

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");
});

Expand All @@ -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);
}
Expand All @@ -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 {
Expand All @@ -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}'`
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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");
});

Expand All @@ -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("---");
Expand All @@ -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",
Expand All @@ -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"
Expand All @@ -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),
Expand All @@ -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`
Expand All @@ -253,16 +250,16 @@ 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);
} catch {
// Binary files (that slipped through) are silently skipped.
}
}
const elapsed = performance.now() - start;
let elapsed = performance.now() - start;

assert(
elapsed < 1000,
Expand All @@ -273,4 +270,3 @@ Deno.test("benchmark: full repo text-file scan completes within 1 second", () =>
);
});

==================================== */
Loading