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

93 lines
5.1 KiB
JavaScript

import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
const skillDir = path.resolve(".agents/skills/standards-verification");
const skillPath = path.join(skillDir, "SKILL.md");
const standardsDocPath = path.resolve(".agents/standards.md");
const skillStandardsRefPath = path.join(skillDir, "references/standards.md");
test("Standards Verification Skill: Directory, SKILL.md, and standards document exist", () => {
assert.ok(fs.existsSync(skillDir), ".agents/skills/standards-verification directory must exist");
assert.ok(fs.existsSync(skillPath), "SKILL.md must exist in standards-verification skill");
assert.ok(fs.existsSync(standardsDocPath), "Dedicated standards document .agents/standards.md must exist");
assert.ok(fs.existsSync(skillStandardsRefPath), "Skill references/standards.md must exist");
});
test("Standards Verification Skill: SKILL.md contains correct metadata and execution directives", () => {
const content = fs.readFileSync(skillPath, "utf-8");
// 1. YAML frontmatter name and description
assert.match(content, /^---\s*\nname:\s*standards-verification/m, "Must declare name: standards-verification");
assert.match(content, /description:\s*>-?[\s\S]*?---/, "Must define description in frontmatter");
// 2. Invocation conditions: called sparingly, major feature, user request, or debugging
assert.match(content, /sparingly/i, "Must specify calling sparingly and only when needed");
assert.match(content, /major\s+function|major\s+feature/i, "Must mention use case: major function/feature implemented");
assert.match(content, /user(?:\s+\w+)?\s+asks/i, "Must mention use case: user explicitly requests verification");
assert.match(content, /debug(?:ging)?/i, "Must mention use case: debugging code issues");
// 3. Targeted inspection via git status / git diff (not whole codebase unless necessary)
assert.match(content, /git\s+status/i, "Must specify using git status to identify changes");
assert.match(content, /git\s+diff/i, "Must specify using git diff to inspect targeted changes");
assert.match(content, /not\s+(?:the\s+)?whole\s+codebase/i, "Must specify NOT inspecting whole codebase unless necessary");
// 4. Debugging guidance: explain why standards violations cause errors
assert.match(content, /(?:suggest|explain)[*\s`_]+why/i, "Must instruct suggesting why standards issues cause errors");
// 5. External standards document reference
assert.match(content, /standards\.md/i, "Must refer to standards.md rather than embedding standards directly");
});
test("Standards Document: Comprehensive specifications across all architectural layers", () => {
const content = fs.readFileSync(standardsDocPath, "utf-8");
// 1. Design & CSS Anti-Patterns
assert.match(content, /backdrop-filter/i, "Must document prohibition on backdrop-filter");
assert.match(content, /box-shadow/i, "Must document prohibition on box-shadow");
assert.match(content, /gradient/i, "Must document prohibition on gradients");
assert.match(content, /border-radius/i, "Must document border-radius constraints (0px to 4px)");
assert.match(content, /instant/i, "Must document instant binary transitions");
// 2. Templating & Eleventy
assert.match(content, /isPostPublic/i, "Must document isPostPublic collection filtering");
assert.match(content, /hidden/i, "Must document hidden post behavior and noindex meta tag");
// 3. Frontmatter & Content Contract
assert.match(content, /title/i, "Must document title requirement");
assert.match(content, /date|created/i, "Must document date requirement");
assert.match(content, /tags/i, "Must document tags requirement");
assert.match(content, /excerpt/i, "Must document excerpt requirement");
// 4. Server & Security Invariants
assert.match(content, /path\s+traversal/i, "Must document path traversal defense");
assert.match(content, /healthz/i, "Must document healthcheck endpoint");
assert.match(content, /X-Content-Type-Options/i, "Must document security headers");
// 5. Strict TDD & Verification Invariants
assert.match(content, /before\s+(?:writing\s+or\s+)?modifying/i, "Must mandate tests before modifying functional code");
assert.match(content, /adversarial/i, "Must mandate adversarial testing");
assert.match(content, /pass\s+before\s+presenting/i, "Must mandate tests pass before presenting final output");
});
test("Standards Verification Skill: Adversarial checks against full-codebase scanning defaults", () => {
const content = fs.readFileSync(skillPath, "utf-8");
// Adversarial: ensure no instruction tells the agent to indiscriminately scan everything by default
assert.doesNotMatch(
content,
/always\s+scan\s+(?:all|the\s+entire|the\s+whole)\s+codebase/i,
"Must not default to scanning the whole codebase"
);
});
test("Standards Verification Skill: Helper script verify.js exists and executes safely", () => {
const scriptPath = path.join(skillDir, "scripts/verify.js");
assert.ok(fs.existsSync(scriptPath), "scripts/verify.js must exist");
const content = fs.readFileSync(scriptPath, "utf-8");
assert.match(content, /git\s+status/i, "Script must inspect git status");
});