syntaxai/tdd.md · main · e2e / commit-view.spec.ts
// E2E: SAMA-native commit view at /GIT/:owner/:repo/commit/:sha
//
// The screenshot in this PR was taken against the same SHA the user
// paired in their request — 526fa16... is the most recent meta-edit
// of the blog post that committed itself via the CMS.
import { test, expect } from "@playwright/test";
import * as fs from "fs";
import * as path from "path";
const SCREENSHOT_DIR = "test-results/commit-view";
const SHA = "526fa16faa56ab82c8f69a143829361365dcc98d";
const SHORT = SHA.slice(0, 7);
test.beforeAll(() => {
fs.mkdirSync(SCREENSHOT_DIR, { recursive: true });
});
test.describe("/GIT/:owner/:repo/commit/:sha", () => {
test("renders commit subject + author + parent + diff", async ({ page }) => {
const res = await page.goto(`/GIT/syntaxai/tdd.md/commit/${SHA}`);
expect(res?.status()).toBe(200);
// Subject + body block
await expect(page.locator(".commit-subject")).toContainText(/edit content\/blog\/sama-meets-git-cms\.md via web/);
// Metadata block has author, date, parent, full SHA
const meta = page.locator(".commit-meta");
await expect(meta).toContainText("syntaxai");
await expect(meta).toContainText(SHA);
// At least one file pane with the right path
const fileHeader = page.locator(".commit-file-header").first();
await expect(fileHeader).toBeVisible();
await expect(fileHeader).toContainText(/content\/blog\/sama-meets-git-cms\.md/);
// At least one added line and one removed line — every meta edit
// adds an HTML comment and that's at minimum one + line.
await expect(page.locator(".commit-line-added").first()).toBeVisible();
// Footer link to raw .diff (still on tdd.md)
const rawLink = page.locator('a[href$=".diff"]').first();
await expect(rawLink).toBeVisible();
await page.screenshot({
path: path.join(SCREENSHOT_DIR, `1-commit-${SHORT}.png`),
fullPage: true,
});
});
test(".diff suffix returns raw unified-diff text (Bun-native, served from tdd.md)", async ({ request }) => {
const res = await request.get(`/GIT/syntaxai/tdd.md/commit/${SHA}.diff`);
expect(res.status()).toBe(200);
expect(res.headers()["content-type"]).toMatch(/text\/plain/);
const body = await res.text();
expect(body).toContain("diff --git");
expect(body).toContain("content/blog/sama-meets-git-cms.md");
});
test("invalid SHA shape 404s", async ({ request }) => {
const res = await request.get(`/GIT/syntaxai/tdd.md/commit/not-a-sha`);
expect(res.status()).toBe(404);
});
test("non-existent commit 404s with our own not-found page", async ({ request }) => {
const res = await request.get(`/GIT/syntaxai/tdd.md/commit/0000000000000000000000000000000000000000`);
expect(res.status()).toBe(404);
});
});