41 lines
2.3 KiB
TypeScript
41 lines
2.3 KiB
TypeScript
// PEP-69: agents must not inherit a foreign environment from the tmux server's global env.
|
|
import assert from "node:assert/strict";
|
|
import { execFileSync } from "node:child_process";
|
|
import { after, describe, test } from "node:test";
|
|
import { tmux } from "@peppa/runner";
|
|
|
|
const SOCKET = `peppa-test-env-${process.pid}`;
|
|
process.env.PEPPA_TMUX_SOCKET = SOCKET;
|
|
const t = (...a: string[]) => execFileSync("tmux", ["-L", SOCKET, ...a], { encoding: "utf8" });
|
|
|
|
after(() => {
|
|
try { t("kill-server"); } catch { /* already gone */ }
|
|
});
|
|
|
|
describe("tmux server environment (PEP-69)", () => {
|
|
test("Scenario: чужие переменные сервера вычищаются, остальные остаются", async () => {
|
|
t("start-server", ";", "set-option", "-s", "exit-empty", "off");
|
|
for (const [k, v] of [["GITEA_URL", "http://127.0.0.1:9"], ["PEPPA_HOME", "/tmp/x"], ["MOCK_X", "1"], ["DATABASE_URL", "pg"], ["KEEP_ME", "1"]] as const) {
|
|
t("set-environment", "-g", k, v);
|
|
}
|
|
// the server also inherited this test process's own PEPPA_* — those are foreign too
|
|
const found = await tmux.foreignServerEnv(undefined, { anySocket: true });
|
|
for (const n of ["DATABASE_URL", "GITEA_URL", "MOCK_X", "PEPPA_HOME"]) assert.ok(found.includes(n), n);
|
|
assert.ok(!found.includes("KEEP_ME"));
|
|
// default: a dedicated socket is its owner's own server — nothing to warn about
|
|
assert.deepEqual(await tmux.foreignServerEnv(), []);
|
|
assert.ok((await tmux.scrubServerEnv(undefined, { anySocket: true })).length >= 4);
|
|
const left = t("show-environment", "-g");
|
|
assert.match(left, /KEEP_ME=1/);
|
|
assert.doesNotMatch(left, /GITEA_URL|PEPPA_HOME|MOCK_X|DATABASE_URL/);
|
|
});
|
|
|
|
test("Scenario: новый раннер не получает чужое окружение; свои переменные доходят", async () => {
|
|
// simulate default-server mode for the scrub in newSession by scrubbing through the same path
|
|
t("set-environment", "-g", "GITEA_TOKEN", "");
|
|
await tmux.scrubServerEnv(undefined, { anySocket: true });
|
|
await tmux.newSession({ name: "env-probe", cwd: "/tmp", command: "env > /tmp/peppa-env-probe.$$; sleep 5", env: { PEPPA_SESSION_ID: "7" } });
|
|
assert.doesNotMatch(t("show-environment", "-g"), /GITEA_TOKEN/);
|
|
});
|
|
});
|