refactor(host): inject platform and environment instead of reading them ambiently (#549)

This commit is contained in:
morluto
2026-10-05 17:39:26 +08:00
committed by GitHub
parent 69a45e0bbc
commit 5b59b87726
3 changed files with 90 additions and 7 deletions
+14 -3
View File
@@ -7,9 +7,20 @@ import {
} from "./domain/errors.js";
import type { JsonValue } from "./domain/jsonValue.js";
/** Load the configured passive browser authority and provider for one CLI operation. */
export const browserContext = async (operation: string) => {
const config = parseConfig(process.env);
/**
* Load the configured passive browser authority and provider for one CLI
* operation.
*
* `environment` defaults to the process environment so CLI callers stay
* unchanged, but every caller may supply the environment explicitly. That is
* what makes configuration-driven behaviour testable without mutating
* `process.env` for the duration of a test.
*/
export const browserContext = async (
operation: string,
environment: Readonly<Record<string, string | undefined>> = process.env,
) => {
const config = parseConfig(environment);
if (!config.ok)
return { ok: false as const, error: browserCliError(config.error) };
const policy = config.value.browserObservationPolicy;