Skip to content

Open-source, local-first AI agent for real work.

2.0 KB
Raw Blame
import { readdirSync, readFileSync } from "node:fs";
import { resolve } from "node:path";
import { describe, expect, it } from "vitest";

const appRoot = resolve(import.meta.dirname, "..");
const repoRoot = resolve(appRoot, "../..");

function activeIgnoreRules(contents: string): string[] {
	return contents
		.split(/\r?\n/u)
		.map((line) => line.trim())
		.filter((line) => line.length > 0 && !line.startsWith("#"));
}

describe("Vercel deployment contract", () => {
	it("keeps the public documentation content in the upload", () => {
		const rules = activeIgnoreRules(readFileSync(resolve(repoRoot, ".vercelignore"), "utf8"));

		expect(rules).toContain("/docs");
		expect(rules).not.toContain("docs");
	});

	it("does not require Git history after .git has been excluded", () => {
		const config = JSON.parse(readFileSync(resolve(appRoot, "vercel.json"), "utf8")) as {
			ignoreCommand?: string;
		};

		expect(config.ignoreCommand).toBeUndefined();
	});

	it("keeps documentation pages prerendered instead of rendering per request", () => {
		// Per-request rendering runs a function for every page view and exhausted the
		// hosting quota once; the language must come from the route, not request headers.
		const pagesRoot = resolve(appRoot, "app/[lang]");
		const sources = readdirSync(pagesRoot, { recursive: true, encoding: "utf8" })
			.filter((file) => file.endsWith(".tsx"))
			.map((file) => ({ file, contents: readFileSync(resolve(pagesRoot, file), "utf8") }));

		expect(sources.length).toBeGreaterThan(0);
		for (const { file, contents } of sources) {
			expect(contents, file).not.toMatch(/from "next\/headers"/u);
			expect(contents, file).not.toMatch(/force-dynamic/u);
		}
	});

	it("disables automatic prefetch for documentation sidebar links", () => {
		const layout = readFileSync(resolve(appRoot, "app/[lang]/(docs)/layout.tsx"), "utf8");
		const sidebarOptions = layout.match(/\bsidebar\s*=\s*\{\{(.*?)\}\}/su)?.[1];

		expect(sidebarOptions).toMatch(/\bprefetch\s*:\s*false\b/u);
	});
});