peppa/packages/testkit/test/live-checkout.test.ts

28 lines
1.3 KiB
TypeScript

// PEP-172: no agent works in the directory Peppa FACTORY itself runs from (the live copy).
import assert from "node:assert/strict";
import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { describe, test } from "node:test";
import { runner } from "./helpers.ts";
describe("PEP-172: копия живого сайта — не для агентов", () => {
test("каталог, из которого работает Peppa FACTORY, узнаётся (PEPPA_ROOT, через символьные ссылки тоже)", () => {
const live = mkdtempSync(join(tmpdir(), "mock-live-"));
const other = mkdtempSync(join(tmpdir(), "mock-ws-"));
const prev = process.env.PEPPA_ROOT;
process.env.PEPPA_ROOT = live;
try {
assert.equal(runner.isLiveCheckout(live), true);
assert.equal(runner.isLiveCheckout(`${live}/`), true);
assert.equal(runner.isLiveCheckout(other), false);
assert.equal(runner.isLiveCheckout(join(other, "missing")), false);
} finally {
if (prev === undefined) delete process.env.PEPPA_ROOT;
else process.env.PEPPA_ROOT = prev;
rmSync(live, { recursive: true, force: true });
rmSync(other, { recursive: true, force: true });
}
});
});