From 79cc6aeb818779a63a5f066f51d3c219f9323c99 Mon Sep 17 00:00:00 2001 From: Guruprasad Kulkarni Date: Sun, 15 Nov 2026 07:55:47 +0100 Subject: [PATCH] chore: isolate the planned cms/ directory from the blog Exclude cms/ from tsc, ESLint and Tailwind source scanning, add a fail-safe blog-changes filter job in front of the test job, and derive the four count-coupled test expectations from src/content/posts. Claude-Session: https://claude.ai/code/session_01426xQEC2VhQSZVe7cBXuz5 --- .github/workflows/test.yml | 26 ++++++++++++++++ .gitignore | 2 ++ CHANGELOG.md | 24 +++++++++++++++ e2e/posts.spec.ts | 9 ++++-- e2e/tags.spec.ts | 5 +-- e2e/url-preservation.spec.ts | 5 +-- eslint.config.js | 3 ++ src/styles/global.css | 1 + tests/AGENTS.md | 1 + tests/build.test.ts | 3 +- tests/helpers/published-posts.test.ts | 14 +++++++++ tests/helpers/published-posts.ts | 44 +++++++++++++++++++++++++++ tsconfig.json | 3 +- 13 files changed, 132 insertions(+), 8 deletions(-) create mode 100644 tests/helpers/published-posts.test.ts create mode 100644 tests/helpers/published-posts.ts diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 873e535..40bd243 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,33 @@ concurrency: cancel-in-progress: true jobs: + blog-changes: + runs-on: ubuntu-latest + outputs: + blog: ${{ steps.filter.outputs.blog }} + steps: + - uses: actions/checkout@v7 + with: + fetch-depth: 0 + + - name: Detect changes outside the CMS + id: filter + env: + BASE: ${{ github.event.pull_request.base.sha || github.event.before }} + run: | + if [ -z "$BASE" ] || [ "$BASE" = "0000000000000000000000000000000000000000" ] || ! git cat-file -e "$BASE^{commit}" 2>/dev/null; then + echo "blog=true" >> "$GITHUB_OUTPUT" + exit 0 + fi + if git diff --name-only "$BASE" "$GITHUB_SHA" | grep -qvE '^(cms/|\.github/workflows/cms\.yml$)'; then + echo "blog=true" >> "$GITHUB_OUTPUT" + else + echo "blog=false" >> "$GITHUB_OUTPUT" + fi + test: + needs: blog-changes + if: ${{ !cancelled() && (needs.blog-changes.result != 'success' || needs.blog-changes.outputs.blog == 'true') }} runs-on: ubuntu-latest steps: diff --git a/.gitignore b/.gitignore index fad6799..ccaefe6 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,5 @@ pnpm-debug.log* # openidea notes .openidea/ +.dev.vars +.trash/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d32e34..2392cf8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,27 @@ +## 2026-11-15 07:58 + +| Check | Status | Details | +|-------|--------|---------| +| Lint | ✓ PASS | 0 errors | +| Build | ✓ PASS | 27 pages built, 5 pages indexed (Pagefind) | +| Unit Tests | ✓ PASS | 75 tests passed | +| E2E Tests | ✓ PASS | 96 tests passed | +| Lighthouse | ✓ PASS | 99.8% performance (avg) | + +### Lighthouse Performance (local build) + +| Page | Scores (3 runs) | +|------|-----------------| +| / (index) | 100%, 100%, 100% | +| /about | 99%, 99%, 99% | +| /posts | 100%, 100%, 100% | +| /archives (soft 404, not linked) | 100%, 100%, 100% | +| /404 | 100%, 100%, 100% | + +**Diagnostics:** None. Live site not measured. A stub `cms/src/x.tsx` changed the Tailwind CSS hash until `@source not "../../cms"` was added; hashes then matched the baseline. A temporary sixth post with a new tag passed build, unit and e2e. + +Changes: Isolate the planned `cms/` directory from the blog (tsconfig, ESLint, Tailwind source, `blog-changes` CI filter); derive the post, tag and RSS counts in four tests from `src/content/posts` via `tests/helpers/published-posts.ts`. + ## 2026-11-15 00:32 | Check | Status | Details | diff --git a/e2e/posts.spec.ts b/e2e/posts.spec.ts index f4be01a..dc1657f 100644 --- a/e2e/posts.spec.ts +++ b/e2e/posts.spec.ts @@ -1,14 +1,19 @@ import { test, expect } from "@playwright/test"; +import { published } from "../tests/helpers/published-posts"; test.describe("Posts Page", () => { test("listing shows perPage (3) posts", async ({ page }) => { await page.goto("/posts/"); - await expect(page.locator("#main-content ul > li")).toHaveCount(3); + await expect(page.locator("#main-content ul > li")).toHaveCount( + Math.min(3, published.length) + ); }); test("listing paginates to /posts/2/", async ({ page }) => { await page.goto("/posts/2/"); - await expect(page.locator("#main-content ul > li")).toHaveCount(2); + await expect(page.locator("#main-content ul > li")).toHaveCount( + Math.min(3, published.length - 3) + ); }); test("can navigate to individual post", async ({ page }) => { diff --git a/e2e/tags.spec.ts b/e2e/tags.spec.ts index 000ca4f..3f9c833 100644 --- a/e2e/tags.spec.ts +++ b/e2e/tags.spec.ts @@ -1,4 +1,5 @@ import { test, expect } from "@playwright/test"; +import { tags } from "../tests/helpers/published-posts"; test.describe("Tags Page", () => { test("loads tags page", async ({ page }) => { @@ -6,10 +7,10 @@ test.describe("Tags Page", () => { await expect(page).toHaveTitle("Tags | Developer Musings"); }); - test("lists all 14 tags", async ({ page }) => { + test("lists all published tags", async ({ page }) => { await page.goto("/tags/"); await expect(page.locator('#main-content a[href^="/tags/"]')).toHaveCount( - 14 + tags.length ); }); diff --git a/e2e/url-preservation.spec.ts b/e2e/url-preservation.spec.ts index b60116b..d6873a9 100644 --- a/e2e/url-preservation.spec.ts +++ b/e2e/url-preservation.spec.ts @@ -34,13 +34,14 @@ test.describe("URL preservation", () => { const links = [...xml.matchAll(/.*?([^<]+)<\/link>/gs)].map( m => m[1] ); - expect(links).toEqual([ + const OLD = [ "https://blog.kulkarni.cloud/posts/some-interesting-features-in-github-actions/", "https://blog.kulkarni.cloud/posts/gradle-tricks/", "https://blog.kulkarni.cloud/posts/tmux-how-i-use-it/", "https://blog.kulkarni.cloud/posts/followup-latest-version-of-the-tools-using-asdf/", "https://blog.kulkarni.cloud/posts/on-the-topic-of-tools-their-versions-and-automated-installations/", - ]); + ]; + expect(links.filter(l => OLD.includes(l))).toEqual(OLD); }); test("old ampersand-less slug is not served", async ({ request }) => { diff --git a/eslint.config.js b/eslint.config.js index 1ce06d7..67b78ec 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -61,6 +61,9 @@ export default [ ".husky/", ".vscode/", "public/", + "cms/", + ".claude/", + ".trash/", ], }, ]; diff --git a/src/styles/global.css b/src/styles/global.css index f4396bd..956e0ad 100644 --- a/src/styles/global.css +++ b/src/styles/global.css @@ -1,4 +1,5 @@ @import "tailwindcss"; +@source not "../../cms"; @import "./theme.css"; @import "./typography.css"; @import "rehype-callouts/theme/obsidian"; diff --git a/tests/AGENTS.md b/tests/AGENTS.md index 771fb28..b54b8f6 100644 --- a/tests/AGENTS.md +++ b/tests/AGENTS.md @@ -16,6 +16,7 @@ Unit tests need no network: offline, the Google font provider in `astro.config.t ## Subdirectories | Directory | Purpose | |-----------|---------| +| `helpers/` | `published-posts.ts` reads `../src/content/posts` and exports `published` and `tags`; the count-coupled tests derive expected values from it | | `utils/` | Tests for `src/utils/` (see `utils/AGENTS.md`) | | `functions/` | `turnstile.test.ts`: session cookie signing, public-path list and middleware branches of `../functions/` | diff --git a/tests/build.test.ts b/tests/build.test.ts index 39d1d5a..43811ee 100644 --- a/tests/build.test.ts +++ b/tests/build.test.ts @@ -1,6 +1,7 @@ import { describe, it, expect, beforeAll } from "vitest"; import { existsSync, readdirSync, readFileSync } from "fs"; import { join } from "path"; +import { published } from "./helpers/published-posts"; const distDir = join(process.cwd(), "dist"); @@ -69,7 +70,7 @@ describe("Build Output", () => { const pngs = readdirSync(postsDir) .map(d => join(postsDir, d, "index.png")) .filter(existsSync); - expect(pngs).toHaveLength(5); + expect(pngs).toHaveLength(published.filter(p => !p.ogImage).length); for (const png of pngs) { expect(readFileSync(png).subarray(0, 8)).toEqual( Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]) diff --git a/tests/helpers/published-posts.test.ts b/tests/helpers/published-posts.test.ts new file mode 100644 index 0000000..1ab98a2 --- /dev/null +++ b/tests/helpers/published-posts.test.ts @@ -0,0 +1,14 @@ +import { describe, it, expect } from "vitest"; +import { published, tags } from "./published-posts"; + +describe("published-posts helper", () => { + it("lists published posts", () => { + expect(published.length).toBeGreaterThanOrEqual(5); + expect(published.every(post => !post.draft)).toBe(true); + }); + + it("lists unique slugified tags", () => { + expect(tags).toContain("gradle"); + expect(new Set(tags).size).toBe(tags.length); + }); +}); diff --git a/tests/helpers/published-posts.ts b/tests/helpers/published-posts.ts new file mode 100644 index 0000000..b0e7e65 --- /dev/null +++ b/tests/helpers/published-posts.ts @@ -0,0 +1,44 @@ +import { readdirSync, readFileSync } from "node:fs"; +import { join } from "node:path"; +import { parseYaml } from "@astrojs/internal-helpers/yaml"; +import dayjs from "dayjs"; +import timezone from "dayjs/plugin/timezone.js"; +import utc from "dayjs/plugin/utc.js"; +import config from "../../astro-paper.config"; +import { slugifyStr } from "../../src/utils/slugify"; + +dayjs.extend(utc); +dayjs.extend(timezone); + +const postsDir = join(import.meta.dirname, "../../src/content/posts"); + +interface PostData { + draft?: boolean; + pubDatetime: string | Date; + timezone?: string; + tags?: string[]; + ogImage?: unknown; +} + +function readPosts(): PostData[] { + return readdirSync(postsDir) + .filter(name => /^[^_].*\.mdx?$/.test(name)) + .map(name => { + const source = readFileSync(join(postsDir, name), "utf8"); + const match = /^---\r?\n([\s\S]*?)\r?\n---/.exec(source); + return parseYaml(match?.[1] ?? "") as PostData; + }); +} + +export const published = readPosts().filter(post => { + if (post.draft) return false; + const tz = post.timezone || config.site.timezone || "UTC"; + const publishDay = dayjs(post.pubDatetime).tz(tz).startOf("day"); + return !publishDay.isAfter(dayjs().tz(tz).startOf("day")); +}); + +export const tags = [ + ...new Set( + published.flatMap(post => (post.tags ?? ["others"]).map(slugifyStr)) + ), +]; diff --git a/tsconfig.json b/tsconfig.json index 4d02f37..a86e015 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,7 +7,8 @@ "old-posts", ".lighthouseci", "playwright-report", - "test-results" + "test-results", + "cms" ], "compilerOptions": { "paths": {