mirror of
https://github.com/luckyyzh/pi-agent-integrated.git
synced 2026-10-03 02:59:35 +00:00
53 lines
1.5 KiB
JavaScript
53 lines
1.5 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { createRequire } from "node:module";
|
|
import test from "node:test";
|
|
|
|
const require = createRequire(import.meta.url);
|
|
const { parseLaunchOptions } = require("../bin/pi-web-options.js");
|
|
|
|
test("opens the browser by default", () => {
|
|
assert.deepEqual(parseLaunchOptions([], {}), {
|
|
port: "30141",
|
|
hostname: "127.0.0.1",
|
|
openBrowser: true,
|
|
});
|
|
});
|
|
|
|
test("supports the no-open CLI option", () => {
|
|
assert.equal(parseLaunchOptions(["--no-open"], {}).openBrowser, false);
|
|
});
|
|
|
|
test("supports truthy PI_WEB_NO_OPEN values", () => {
|
|
for (const value of ["1", "true", "TRUE", "yes", "on"]) {
|
|
assert.equal(parseLaunchOptions([], { PI_WEB_NO_OPEN: value }).openBrowser, false);
|
|
}
|
|
});
|
|
|
|
test("does not disable browser opening for false PI_WEB_NO_OPEN values", () => {
|
|
for (const value of ["0", "false", "off", ""]) {
|
|
assert.equal(parseLaunchOptions([], { PI_WEB_NO_OPEN: value }).openBrowser, true);
|
|
}
|
|
});
|
|
|
|
test("preserves port and hostname options", () => {
|
|
assert.deepEqual(
|
|
parseLaunchOptions(["-p", "8080", "-H", "0.0.0.0"], {}),
|
|
{
|
|
port: "8080",
|
|
hostname: "0.0.0.0",
|
|
openBrowser: true,
|
|
},
|
|
);
|
|
});
|
|
|
|
test("supports PI_WEB_HOSTNAME without trusting the ambient system HOSTNAME", () => {
|
|
assert.equal(
|
|
parseLaunchOptions([], { HOSTNAME: "container-id" }).hostname,
|
|
"127.0.0.1",
|
|
);
|
|
assert.equal(
|
|
parseLaunchOptions([], { PI_WEB_HOSTNAME: "0.0.0.0" }).hostname,
|
|
"0.0.0.0",
|
|
);
|
|
});
|