2026-10-05 20:16:44 +08:00
|
|
|
import { delimiter } from "node:path";
|
|
|
|
|
|
2026-07-23 07:08:47 +00:00
|
|
|
import type { ProcessScenario } from "../domain/processCapture.js";
|
|
|
|
|
import type { LoopbackReplay } from "./LoopbackReplay.js";
|
|
|
|
|
import type { CommandShimReplay } from "./CommandShimReplay.js";
|
|
|
|
|
|
|
|
|
|
interface ProcessCaptureEnvironmentOptions {
|
|
|
|
|
readonly scenario: ProcessScenario;
|
|
|
|
|
readonly replay: LoopbackReplay;
|
|
|
|
|
readonly shimReplay: CommandShimReplay;
|
|
|
|
|
readonly runId: string;
|
2026-10-05 20:16:44 +08:00
|
|
|
readonly hostEnvironment: Readonly<Record<string, string | undefined>>;
|
2026-07-23 07:08:47 +00:00
|
|
|
}
|
|
|
|
|
|
2026-10-05 20:16:44 +08:00
|
|
|
/** Build the inherited environment with scenario overrides and replay instrumentation. */
|
2026-07-23 07:08:47 +00:00
|
|
|
export const makeProcessCaptureEnvironment = (
|
|
|
|
|
options: ProcessCaptureEnvironmentOptions,
|
|
|
|
|
): Record<string, string> => {
|
2026-10-05 20:16:44 +08:00
|
|
|
const { scenario, replay, shimReplay, runId, hostEnvironment } = options;
|
2026-07-23 07:08:47 +00:00
|
|
|
const environment: Record<string, string> = {
|
2026-10-05 20:16:44 +08:00
|
|
|
...Object.fromEntries(
|
|
|
|
|
Object.entries(hostEnvironment).filter(
|
|
|
|
|
(entry): entry is [string, string] => entry[1] !== undefined,
|
|
|
|
|
),
|
|
|
|
|
),
|
2026-07-23 07:08:47 +00:00
|
|
|
...scenario.environment,
|
2026-10-05 20:16:44 +08:00
|
|
|
TERM: scenario.environment.TERM ?? hostEnvironment.TERM ?? "xterm-256color",
|
2026-07-23 07:08:47 +00:00
|
|
|
REA_PROCESS_RUN_ID: runId,
|
|
|
|
|
};
|
|
|
|
|
environment.REA_REPLAY_HTTP_URL = replay.httpUrl;
|
|
|
|
|
environment.REA_REPLAY_WEBSOCKET_URL = replay.websocketUrl;
|
|
|
|
|
environment.REA_SHIM_LEDGER_URL = shimReplay.url;
|
2026-10-05 20:16:44 +08:00
|
|
|
// Shims are instrumentation; all remaining executable lookup uses host PATH.
|
2026-07-23 07:08:47 +00:00
|
|
|
environment.PATH = [shimReplay.binPath, environment.PATH ?? ""]
|
|
|
|
|
.filter((part) => part.length > 0)
|
2026-10-05 20:16:44 +08:00
|
|
|
.join(delimiter);
|
2026-07-23 07:08:47 +00:00
|
|
|
return environment;
|
|
|
|
|
};
|