Add FORTRESS_* config
This commit is contained in:
@@ -114,4 +114,43 @@ describe("loadConfig", () => {
|
||||
it("leaves google undefined when no GOOGLE_* vars are set", () => {
|
||||
expect(loadConfig(base, "/p").google).toBeUndefined();
|
||||
});
|
||||
|
||||
it("leaves fortress undefined unless FORTRESS_ENABLED is truthy", () => {
|
||||
expect(loadConfig(base, "/p").fortress).toBeUndefined();
|
||||
expect(loadConfig({ ...base, FORTRESS_ENABLED: "false" }, "/p").fortress).toBeUndefined();
|
||||
});
|
||||
|
||||
it("enables fortress with defaults", () => {
|
||||
expect(loadConfig({ ...base, FORTRESS_ENABLED: "true" }, "/p").fortress).toEqual({
|
||||
enabled: true,
|
||||
command: ["tilion-mcp"],
|
||||
headless: true,
|
||||
env: {},
|
||||
});
|
||||
});
|
||||
|
||||
it("reads FORTRESS_COMMAND, FORTRESS_HEADLESS, and non-blank pass-through vars", () => {
|
||||
const cfg = loadConfig(
|
||||
{
|
||||
...base,
|
||||
FORTRESS_ENABLED: "1",
|
||||
FORTRESS_COMMAND: 'python -m "tilion.mcp"',
|
||||
FORTRESS_HEADLESS: "false",
|
||||
TILION_PROXY: "http://u:p@h:1",
|
||||
TILION_REGION: " ",
|
||||
CAPTCHA_API_KEY: "k",
|
||||
},
|
||||
"/p",
|
||||
);
|
||||
expect(cfg.fortress).toEqual({
|
||||
enabled: true,
|
||||
command: ["python", "-m", "tilion.mcp"],
|
||||
headless: false,
|
||||
env: { TILION_PROXY: "http://u:p@h:1", CAPTCHA_API_KEY: "k" },
|
||||
});
|
||||
});
|
||||
|
||||
it("falls back to tilion-mcp when FORTRESS_COMMAND is blank", () => {
|
||||
expect(loadConfig({ ...base, FORTRESS_ENABLED: "1", FORTRESS_COMMAND: " " }, "/p").fortress?.command).toEqual(["tilion-mcp"]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -13,6 +13,7 @@ export interface Config {
|
||||
logLevel: LogLevel;
|
||||
google?: GoogleConfig;
|
||||
playwright?: PlaywrightConfig;
|
||||
fortress?: FortressConfig;
|
||||
}
|
||||
|
||||
export interface GoogleConfig {
|
||||
@@ -28,6 +29,16 @@ export interface PlaywrightConfig {
|
||||
extraArgs: string[];
|
||||
}
|
||||
|
||||
export interface FortressConfig {
|
||||
enabled: true;
|
||||
command: string[];
|
||||
headless: boolean;
|
||||
// Fortress's own env vars, passed to the tilion-mcp subprocess when set.
|
||||
env: Record<string, string>;
|
||||
}
|
||||
|
||||
const FORTRESS_PASSTHROUGH = ["TILION_PROXY", "TILION_REGION", "CAPTCHA_API_KEY"] as const;
|
||||
|
||||
export class ConfigError extends Error {}
|
||||
|
||||
const LOG_LEVELS: LogLevel[] = ["debug", "info", "warn", "error"];
|
||||
@@ -76,6 +87,21 @@ export function loadConfig(env: NodeJS.ProcessEnv = process.env, cwd: string = p
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const fortressCommand = parseArgsString(env.FORTRESS_COMMAND);
|
||||
const fortress: FortressConfig | undefined = parseBool(env.FORTRESS_ENABLED)
|
||||
? {
|
||||
enabled: true,
|
||||
command: fortressCommand.length ? fortressCommand : ["tilion-mcp"],
|
||||
headless: parseBool(env.FORTRESS_HEADLESS, true),
|
||||
env: Object.fromEntries(
|
||||
FORTRESS_PASSTHROUGH.flatMap((k) => {
|
||||
const v = blankToUndefined(env[k]);
|
||||
return v ? [[k, v]] : [];
|
||||
}),
|
||||
),
|
||||
}
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
telegramBotToken,
|
||||
telegramOwnerId,
|
||||
@@ -88,6 +114,7 @@ export function loadConfig(env: NodeJS.ProcessEnv = process.env, cwd: string = p
|
||||
logLevel,
|
||||
google,
|
||||
playwright,
|
||||
fortress,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -111,7 +138,7 @@ function parseBool(value: string | undefined, defaultValue = false): boolean {
|
||||
}
|
||||
|
||||
// Split a shell-style argument string on whitespace, honoring single and double
|
||||
// quotes. Used for PLAYWRIGHT_EXTRA_ARGS so values like --device 'iPhone 15'
|
||||
// quotes. Used for PLAYWRIGHT_EXTRA_ARGS and FORTRESS_COMMAND so values like --device 'iPhone 15'
|
||||
// arrive as two argv entries instead of three.
|
||||
function parseArgsString(value: string | undefined): string[] {
|
||||
const s = value?.trim();
|
||||
|
||||
Reference in New Issue
Block a user