MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / bootProcesses

Function bootProcesses

e2e/setup/boot.ts:68–161  ·  view source on GitHub ↗
(
  procs: ReadonlyArray<{
    readonly cmd: string;
    readonly args: ReadonlyArray<string>;
    readonly cwd: string;
    readonly env?: Record<string, string | undefined>;
    /** Append stdout+stderr here (long-lived boots need inspectable logs). */
    readonly logFile?: string;
  }>,
  options: { readonly label: string },
)

Source from the content-addressed store, hash-verified

66};
67
68export const bootProcesses = (
69 procs: ReadonlyArray<{
70 readonly cmd: string;
71 readonly args: ReadonlyArray<string>;
72 readonly cwd: string;
73 readonly env?: Record<string, string | undefined>;
74 /** Append stdout+stderr here (long-lived boots need inspectable logs). */
75 readonly logFile?: string;
76 }>,
77 options: { readonly label: string },
78): MonitoredBootedProcesses => {
79 const children: ChildProcess[] = [];
80 let tearingDown = false;
81 const unexpectedExits: Array<Promise<never>> = [];
82 for (const proc of procs) {
83 const log = proc.logFile ? openSync(proc.logFile, "a") : undefined;
84 const child = spawn(proc.cmd, [...proc.args], {
85 cwd: proc.cwd,
86 env: { ...process.env, ...proc.env },
87 stdio:
88 log !== undefined ? ["ignore", log, log] : process.env.E2E_VERBOSE ? "inherit" : "ignore",
89 // Own process group, so teardown can signal the whole tree — `bunx vite`
90 // is a wrapper whose actual server child would otherwise outlive the
91 // kill and squat the port into the NEXT invocation's waitForHttp.
92 detached: true,
93 });
94 if (log !== undefined) closeSync(log);
95 unexpectedExits.push(
96 new Promise<never>((_resolve, reject) => {
97 child.once("error", (cause) => {
98 if (tearingDown) return;
99 // oxlint-disable-next-line executor/no-promise-reject -- boundary: adapt the child-process error event to the startup race
100 reject(
101 new BootProcessExitError(
102 [proc.cmd, ...proc.args].join(" "),
103 child.exitCode,
104 child.signalCode,
105 `${readLogTail(proc.logFile)}\n${String(cause)}`.trim(),
106 ),
107 );
108 });
109 child.once("exit", (code, signal) => {
110 if (tearingDown) return;
111 const error = new BootProcessExitError(
112 [proc.cmd, ...proc.args].join(" "),
113 code,
114 signal,
115 readLogTail(proc.logFile),
116 );
117 console.error(`[e2e:${options.label}] ${error.message}`);
118 // oxlint-disable-next-line executor/no-promise-reject -- boundary: adapt the child-process exit event to the startup race
119 reject(error);
120 });
121 }),
122 );
123 children.push(child);
124 }
125

Callers 6

bootCloudFunction · 0.90
bootCloudflareFunction · 0.90
bootMotelFunction · 0.90
bootSelfhostFunction · 0.90
boot-stack.tsFile · 0.90

Calls 6

rejectFunction · 0.85
readLogTailFunction · 0.85
signalTreeFunction · 0.85
pushMethod · 0.80
errorMethod · 0.80
resolveFunction · 0.50

Tested by

no test coverage detected