ai-chatbot/tests/scripts/postbuild-cleanup.test.mjs
Codex 9155682238 chore(repo): make the recovered production baseline portable
Record source and release ownership, keep source line endings consistent,
and exclude local build/config backups from version control.

Restore default Next type paths, normalize CI checks across line endings,
and use portable Playwright and postbuild entry points on Windows/Linux.
Align the stale timeout fixture with the existing production timeout policy.

Application runtime files remain identical to production-snapshot-48-20261030.
Production build and focused regressions passed; pre-existing full-repository
lint findings remain documented instead of relaxing lint rules.
2026-10-30 16:19:08 +08:00

46 lines
1.9 KiB
JavaScript

import assert from "node:assert/strict";
import { spawnSync } from "node:child_process";
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { isAbsolute, join, relative, resolve } from "node:path";
import { test } from "node:test";
const workspace = process.cwd();
const script = resolve("scripts/postbuild-cleanup.mjs");
test("postbuild removes nested public maps and preserves runtime assets", async () => {
const qa = resolve(".qa");
await mkdir(qa, { recursive: true });
const directory = await mkdtemp(join(qa, "postbuild-cleanup-"));
const nested = join(directory, "static", "chunks");
try {
await mkdir(nested, { recursive: true });
await writeFile(join(nested, "runtime.js"), "runtime");
await writeFile(join(nested, "runtime.js.map"), "source map");
await writeFile(join(nested, "notes.txt"), "keep");
const result = spawnSync(process.execPath, [script], {
cwd: workspace,
env: { ...process.env, NEXT_DIST_DIR: relative(workspace, directory) },
encoding: "utf8",
});
assert.equal(result.status, 0, result.stderr);
assert.match(result.stdout, /Removed 1 public source map files/);
assert.equal(await readFile(join(nested, "runtime.js"), "utf8"), "runtime");
assert.equal(await readFile(join(nested, "notes.txt"), "utf8"), "keep");
await assert.rejects(readFile(join(nested, "runtime.js.map")), { code: "ENOENT" });
} finally {
const location = relative(qa, directory);
assert.ok(location.startsWith("postbuild-cleanup-") && !isAbsolute(location) && !location.includes(".."));
await rm(directory, { recursive: true, force: true });
}
});
test("postbuild refuses a build directory outside the workspace", () => {
const result = spawnSync(process.execPath, [script], {
cwd: workspace,
env: { ...process.env, NEXT_DIST_DIR: ".." },
encoding: "utf8",
});
assert.notEqual(result.status, 0);
assert.match(result.stderr, /inside the workspace/);
});