From e4601dbbcbce5606c0757db56661bd45734ea1a3 Mon Sep 17 00:00:00 2001 From: venus Date: Sun, 13 Sep 2026 01:16:20 -0500 Subject: [PATCH] feat: adopt strict TDD framework and add adversarial test suite - Update AGENTS.md and .agents/rules/blog-system.md with strict TDD mandate - Extract Eleventy custom filters into modular src/_filters/index.js for unit testing - Add npm test script using Node.js native test runner (node:test) - Create test/site-config.test.js for environment validation and fatal error assertions - Create test/filters.test.js for adversarial filter edge cases (dates, limits, reading time, headings) - Create test/frontmatter-schema.test.js enforcing post metadata contracts - Create test/design-rules.test.js enforcing strict anti-patterns (no glassmorphism, no shadows, max 4px radius) - Create test/build-integrity.test.js checking static output, zero 404 links, and TOC anchor targets --- .agents/rules/blog-system.md | 15 +++++ AGENTS.md | 10 +++ eleventy.config.js | 57 ++--------------- package.json | 1 + src/_data/site.js | 30 ++++----- src/_filters/index.js | 74 ++++++++++++++++++++++ test/build-integrity.test.js | 83 +++++++++++++++++++++++++ test/design-rules.test.js | 86 +++++++++++++++++++++++++ test/filters.test.js | 107 ++++++++++++++++++++++++++++++++ test/frontmatter-schema.test.js | 71 +++++++++++++++++++++ test/site-config.test.js | 64 +++++++++++++++++++ 11 files changed, 532 insertions(+), 66 deletions(-) create mode 100644 src/_filters/index.js create mode 100644 test/build-integrity.test.js create mode 100644 test/design-rules.test.js create mode 100644 test/filters.test.js create mode 100644 test/frontmatter-schema.test.js create mode 100644 test/site-config.test.js diff --git a/.agents/rules/blog-system.md b/.agents/rules/blog-system.md index 42af3e9..c7e16dd 100644 --- a/.agents/rules/blog-system.md +++ b/.agents/rules/blog-system.md @@ -54,3 +54,18 @@ - Wikilinks `[[slug]]` or `[[slug|Label]]` must be transformed into standard web URLs (`/posts/slug/`). - Callout blocks (`> [!NOTE]`, `> [!WARNING]`, etc.) must render as terminal-style alert callouts. - Images must be processed into `src/assets/images/posts/` and linked via standard `` or Markdown image syntax. + +--- + +## 5. Test-Driven Development (TDD) & Adversarial Verification +1. **Red-Green-Refactor Lifecycle:** + - Write tests in `test/*.test.js` using Node's native test runner (`node:test`, `node:assert/strict`). + - Test inputs before implementing filters, data loaders, or template macros. +2. **Adversarial Test Coverage Required:** + - **Data & Configuration:** Test that missing required environment variables (e.g. `SITE_DOMAIN`) throw fatal errors. + - **Filters:** Test edge cases: empty strings, undefined values, single-word inputs, massive word counts, non-date objects. + - **Content Schemas:** Validate all Markdown files in `src/posts/` against frontmatter schemas. + - **Design Spec Compliance:** Automate regex/AST assertions on `src/assets/css/` ensuring zero violations of the "Do Not Use" list (`backdrop-filter`, `box-shadow`, `text-shadow`, gradients, floaty transitions). + - **Link & Anchor Integrity:** Verify that every compiled page has zero broken internal links and that all Table of Contents anchor links resolve to valid heading IDs. +3. **Execution Invariant:** + - Always run `npm test` before committing. All tests must pass cleanly with 0 failures. diff --git a/AGENTS.md b/AGENTS.md index d945b50..317c787 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -30,6 +30,16 @@ Every component, style, and layout change must strictly adhere to [`sample-desig - **Interactivity:** Instant binary hover state transitions (no 300ms easing); high-contrast 1px/2px focus outlines for keyboard navigation. - **Typography:** IBM Plex Mono / JetBrains Mono for UI elements and code blocks; Inter for body prose. +### 1.4 Strict Test-Driven Development (TDD) & Adversarial Verification Mandate +- **Test-First Development:** For all new features, custom filters, template helpers, frontmatter schemas, or configuration changes, write automated tests asserting expected behaviors and edge cases *before* or alongside implementing the code. +- **Adversarial Mindset:** Actively design tests to break assumptions: + - Missing environment variables (e.g. unset `SITE_DOMAIN` must throw). + - Malformed frontmatter (missing titles, invalid dates, empty tags). + - Edge-case inputs to filters (empty strings, giant numbers, special characters). + - Design rule violations (asserting 0 instances of `backdrop-filter`, `box-shadow`, gradients, or floaty animations). + - Broken internal links and missing anchor tags in generated HTML. +- **Verification Gate:** Every code change must be verified by running `npm test`. No feature or commit is considered complete unless 100% of the test suite passes. + --- ## 2. Code Modularity & Isolation Guidelines diff --git a/eleventy.config.js b/eleventy.config.js index d8fa67d..2afa0cd 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -1,7 +1,7 @@ import syntaxHighlight from "@11ty/eleventy-plugin-syntaxhighlight"; import markdownIt from "markdown-it"; import markdownItAnchor from "markdown-it-anchor"; -import { DateTime } from "luxon"; +import { filters } from "./src/_filters/index.js"; export default function (eleventyConfig) { // 1. Static Asset Passthrough Copy @@ -32,57 +32,10 @@ export default function (eleventyConfig) { eleventyConfig.setLibrary("md", markdownLib); - // 4. Custom Filters - // Format readable dates: SEP 12, 2026 - eleventyConfig.addFilter("postDate", (dateObj) => { - if (!dateObj) return ""; - return DateTime.fromJSDate(new Date(dateObj), { zone: "utc" }) - .toFormat("LLL dd, yyyy") - .toUpperCase(); - }); - - // ISO date format for