|
| 1 | +// SPDX-License-Identifier: PMPL-1.0-or-later |
| 2 | +// Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk> |
| 3 | +// |
| 4 | +// Aspect tests for universal-chat-extractor. |
| 5 | +// |
| 6 | +// Aspect tests verify cross-cutting concerns that span all modules: |
| 7 | +// security policy, accessibility of public documentation, EditorConfig |
| 8 | +// consistency, no banned file patterns, and test infrastructure health. |
| 9 | +// Run with: deno test tests/aspect_test.ts |
| 10 | + |
| 11 | +import { |
| 12 | + assertEquals, |
| 13 | + assertNotEquals, |
| 14 | + assertMatch, |
| 15 | +} from "jsr:@std/assert@^1"; |
| 16 | + |
| 17 | +const REPO_ROOT = new URL("../", import.meta.url).pathname; |
| 18 | + |
| 19 | +async function readFile(relPath: string): Promise<string | null> { |
| 20 | + return Deno.readTextFile(REPO_ROOT + relPath).catch(() => null); |
| 21 | +} |
| 22 | + |
| 23 | +async function pathExists(relPath: string): Promise<boolean> { |
| 24 | + return Deno.stat(REPO_ROOT + relPath).then(() => true).catch(() => false); |
| 25 | +} |
| 26 | + |
| 27 | +// --------------------------------------------------------------------------- |
| 28 | +// Aspect: Security policy |
| 29 | +// --------------------------------------------------------------------------- |
| 30 | + |
| 31 | +Deno.test("aspect/security: SECURITY.md exists", async () => { |
| 32 | + assertEquals(await pathExists("SECURITY.md"), true); |
| 33 | +}); |
| 34 | + |
| 35 | +Deno.test("aspect/security: SECURITY.md mentions vulnerability reporting", async () => { |
| 36 | + const content = await readFile("SECURITY.md"); |
| 37 | + assertNotEquals(content, null); |
| 38 | + const lc = content!.toLowerCase(); |
| 39 | + const hasDisclosure = |
| 40 | + lc.includes("vulnerabilit") || |
| 41 | + lc.includes("disclosure") || |
| 42 | + lc.includes("report") || |
| 43 | + lc.includes("security"); |
| 44 | + assertEquals(hasDisclosure, true, "SECURITY.md should mention security reporting"); |
| 45 | +}); |
| 46 | + |
| 47 | +Deno.test("aspect/security: .well-known/security.txt exists", async () => { |
| 48 | + assertEquals(await pathExists(".well-known/security.txt"), true); |
| 49 | +}); |
| 50 | + |
| 51 | +Deno.test("aspect/security: no .env files in repo", async () => { |
| 52 | + assertEquals(await pathExists(".env"), false, ".env must not be committed"); |
| 53 | +}); |
| 54 | + |
| 55 | +Deno.test("aspect/security: no hardcoded secret patterns in README", async () => { |
| 56 | + const content = await readFile("README.adoc"); |
| 57 | + assertNotEquals(content, null); |
| 58 | + const hasSecretLeak = /(?:api_key|password|secret|token)\s*=/i.test(content!); |
| 59 | + assertEquals(hasSecretLeak, false, "README.adoc must not contain hardcoded secrets"); |
| 60 | +}); |
| 61 | + |
| 62 | +// --------------------------------------------------------------------------- |
| 63 | +// Aspect: Code of conduct |
| 64 | +// --------------------------------------------------------------------------- |
| 65 | + |
| 66 | +Deno.test("aspect/community: CODE_OF_CONDUCT.md exists", async () => { |
| 67 | + assertEquals(await pathExists("CODE_OF_CONDUCT.md"), true); |
| 68 | +}); |
| 69 | + |
| 70 | +Deno.test("aspect/community: CODE_OF_CONDUCT.md has meaningful content", async () => { |
| 71 | + const content = await readFile("CODE_OF_CONDUCT.md"); |
| 72 | + assertNotEquals(content, null); |
| 73 | + assertEquals(content!.length > 100, true, "CODE_OF_CONDUCT.md should have meaningful content"); |
| 74 | +}); |
| 75 | + |
| 76 | +// --------------------------------------------------------------------------- |
| 77 | +// Aspect: EditorConfig consistency |
| 78 | +// --------------------------------------------------------------------------- |
| 79 | + |
| 80 | +Deno.test("aspect/formatting: .editorconfig exists", async () => { |
| 81 | + assertEquals(await pathExists(".editorconfig"), true); |
| 82 | +}); |
| 83 | + |
| 84 | +Deno.test("aspect/formatting: .editorconfig has root = true", async () => { |
| 85 | + const content = await readFile(".editorconfig"); |
| 86 | + assertNotEquals(content, null); |
| 87 | + assertMatch(content!, /root\s*=\s*true/i); |
| 88 | +}); |
| 89 | + |
| 90 | +Deno.test("aspect/formatting: .editorconfig defines indent_style", async () => { |
| 91 | + const content = await readFile(".editorconfig"); |
| 92 | + assertNotEquals(content, null); |
| 93 | + assertMatch(content!, /indent_style\s*=/); |
| 94 | +}); |
| 95 | + |
| 96 | +// --------------------------------------------------------------------------- |
| 97 | +// Aspect: No banned file patterns |
| 98 | +// --------------------------------------------------------------------------- |
| 99 | + |
| 100 | +const BANNED_FILES = [ |
| 101 | + "package.json", |
| 102 | + "package-lock.json", |
| 103 | + "yarn.lock", |
| 104 | + "bun.lockb", |
| 105 | + "node_modules", |
| 106 | + ".npmrc", |
| 107 | + "Dockerfile", // Must use Containerfile (Podman) |
| 108 | +]; |
| 109 | + |
| 110 | +for (const f of BANNED_FILES) { |
| 111 | + Deno.test(`aspect/policy: banned file must not exist — ${f}`, async () => { |
| 112 | + assertEquals(await pathExists(f), false, `Banned file/directory present: ${f}`); |
| 113 | + }); |
| 114 | +} |
| 115 | + |
| 116 | +// --------------------------------------------------------------------------- |
| 117 | +// Aspect: No TypeScript without Deno (no tsconfig.json) |
| 118 | +// --------------------------------------------------------------------------- |
| 119 | + |
| 120 | +Deno.test("aspect/language: no tsconfig.json (TS only via Deno, not tsc)", async () => { |
| 121 | + assertEquals(await pathExists("tsconfig.json"), false); |
| 122 | +}); |
| 123 | + |
| 124 | +// --------------------------------------------------------------------------- |
| 125 | +// Aspect: Documentation completeness |
| 126 | +// --------------------------------------------------------------------------- |
| 127 | + |
| 128 | +const DOCS = [ |
| 129 | + "README.adoc", |
| 130 | + "EXPLAINME.adoc", |
| 131 | + "CONTRIBUTING.md", |
| 132 | + "ROADMAP.adoc", |
| 133 | +]; |
| 134 | + |
| 135 | +for (const doc of DOCS) { |
| 136 | + Deno.test(`aspect/docs: documentation file is non-empty — ${doc}`, async () => { |
| 137 | + const content = await readFile(doc); |
| 138 | + assertNotEquals(content, null, `Doc missing: ${doc}`); |
| 139 | + assertEquals(content!.trim().length > 50, true, `Doc is too short: ${doc}`); |
| 140 | + }); |
| 141 | +} |
| 142 | + |
| 143 | +// --------------------------------------------------------------------------- |
| 144 | +// Aspect: All non-bench test files use Deno.test |
| 145 | +// --------------------------------------------------------------------------- |
| 146 | + |
| 147 | +Deno.test("aspect/tests: all non-bench .ts files in tests/ use Deno.test", async () => { |
| 148 | + const testsDir = REPO_ROOT + "tests"; |
| 149 | + for await (const entry of Deno.readDir(testsDir)) { |
| 150 | + if (entry.isFile && entry.name.endsWith(".ts") && !entry.name.includes("bench")) { |
| 151 | + const content = await Deno.readTextFile(`${testsDir}/${entry.name}`); |
| 152 | + assertMatch( |
| 153 | + content, |
| 154 | + /Deno\.test\s*\(/, |
| 155 | + `Test file ${entry.name} must contain Deno.test(`, |
| 156 | + ); |
| 157 | + } |
| 158 | + } |
| 159 | +}); |
0 commit comments