Files
blog/test/development-standards.test.js

113 lines
4.6 KiB
JavaScript

import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
const agentsMdPath = path.resolve("AGENTS.md");
const rulesMdPath = path.resolve(".agents/rules/blog-system.md");
test("Development Standards: AGENTS.md enforces test-first, adversarial testing, and verification gates", () => {
assert.ok(fs.existsSync(agentsMdPath), "AGENTS.md must exist in root");
const content = fs.readFileSync(agentsMdPath, "utf-8");
// 1. Must enforce writing tests BEFORE modifying functional/production code
assert.match(
content,
/before\s+(?:writing\s+or\s+)?modifying\s+(?:any\s+)?(?:functional|production)\s+code/i,
"AGENTS.md must explicitly mandate that tests are written before modifying functional/production code"
);
// 2. Must mandate adversarial testing
assert.match(
content,
/adversarial\s+test(?:ing|s)/i,
"AGENTS.md must mandate adversarial testing"
);
// 3. Must mandate that all tests pass before presenting final output
assert.match(
content,
/pass\s+before\s+presenting\s+(?:the\s+)?final\s+output/i,
"AGENTS.md must mandate that test cases pass before presenting final output"
);
});
test("Development Standards: .agents/rules/blog-system.md enforces test-first, adversarial testing, and verification gates", () => {
assert.ok(fs.existsSync(rulesMdPath), ".agents/rules/blog-system.md must exist");
const content = fs.readFileSync(rulesMdPath, "utf-8");
// 1. Must enforce writing tests BEFORE modifying functional/production code
assert.match(
content,
/before\s+(?:writing\s+or\s+)?modifying\s+(?:any\s+)?(?:functional|production)\s+code/i,
"blog-system.md must explicitly mandate that tests are written before modifying functional/production code"
);
// 2. Must mandate adversarial testing
assert.match(
content,
/adversarial\s+test(?:ing|s)/i,
"blog-system.md must mandate adversarial testing"
);
// 3. Must mandate that all tests pass before presenting final output
assert.match(
content,
/pass\s+before\s+presenting\s+(?:the\s+)?final\s+output/i,
"blog-system.md must mandate that test cases pass before presenting final output"
);
});
test("Development Standards: Adversarial checks against vague or permissive testing language", () => {
const files = [agentsMdPath, rulesMdPath];
for (const filePath of files) {
const content = fs.readFileSync(filePath, "utf-8");
const relPath = path.relative(process.cwd(), filePath);
// Adversarial: ensure no permissive "or alongside implementing" loophole exists
assert.doesNotMatch(
content,
/or\s+alongside\s+implementing/i,
`Violation in ${relPath}: Permissive loophole "or alongside implementing" must not exist; tests must strictly precede functional code`
);
}
});
test("Development Standards: README.md and skills reference TDD, adversarial testing, and verification", () => {
const readmePath = path.resolve("README.md");
assert.ok(fs.existsSync(readmePath), "README.md must exist");
const readmeContent = fs.readFileSync(readmePath, "utf-8");
assert.match(
readmeContent,
/written\s+before\s+(?:writing\s+or\s+)?modifying\s+(?:any\s+)?functional\s+code/i,
"README.md must document writing tests before modifying functional code"
);
assert.match(
readmeContent,
/adversarial\s+test(?:ing|s)/i,
"README.md must document mandatory adversarial testing"
);
assert.match(
readmeContent,
/pass\s+before\s+presenting\s+(?:the\s+)?final\s+output/i,
"README.md must document that tests must pass before presenting final output"
);
// Check eleventy-tiling-blog skill
const eleventySkillPath = path.resolve(".agents/skills/eleventy-tiling-blog/SKILL.md");
assert.ok(fs.existsSync(eleventySkillPath), "eleventy-tiling-blog SKILL.md must exist");
const eleventySkill = fs.readFileSync(eleventySkillPath, "utf-8");
assert.match(eleventySkill, /adversarial/i, "eleventy-tiling-blog SKILL.md must mention adversarial testing");
assert.match(eleventySkill, /before\s+modifying\s+functional/i, "eleventy-tiling-blog SKILL.md must mandate tests before modifying functional code");
// Check obsidian-sync skill
const obsidianSkillPath = path.resolve(".agents/skills/obsidian-sync/SKILL.md");
assert.ok(fs.existsSync(obsidianSkillPath), "obsidian-sync SKILL.md must exist");
const obsidianSkill = fs.readFileSync(obsidianSkillPath, "utf-8");
assert.match(obsidianSkill, /adversarial/i, "obsidian-sync SKILL.md must mention adversarial testing");
assert.match(obsidianSkill, /before[*\s`_]+modifying/i, "obsidian-sync SKILL.md must mandate tests before modifying functional code");
});