Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions app/utils/local/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,41 @@
});
}

const encoder = new TextEncoder();

function byteLength(str) {
return encoder.encode(str).byteLength;
}

function waitForReady(child, expectedResponse, signal) {
// oxlint-disable-next-line promise/avoid-new
return new Promise((resolve, reject) => {
const readlineStdout = readline.createInterface({ input: child.stdout });
const readlineStderr = readline.createInterface({ input: child.stderr });

let recentOutput = "";

function recordOutput(line) {
recentOutput = `${recentOutput} ${line} \n`.slice(-MAX_ERROR_BUFFER_BYTES);
const safeLine =
byteLength(line) > MAX_ERROR_BUFFER_BYTES / 2
? line.slice(0, MAX_ERROR_BUFFER_BYTES / 2) + "…[truncated]"

Check failure on line 50 in app/utils/local/scripts.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(prefer-template)

Unexpected string concatenation.
: line;

recentOutput = `${recentOutput} ${safeLine}\n`;

while (byteLength(recentOutput) > MAX_ERROR_BUFFER_BYTES) {
const newline = recentOutput.indexOf("\n");
if (newline === -1) {
recentOutput = "";
break;
}
recentOutput = recentOutput.slice(newline + 1);
}
}

function cleanup() {
readlineStdout.removeAllListeners();
readlineStdout.close();
readlineStderr.removeAllListeners();
readlineStderr.close();
readlineStdout.removeListener("line", onLine);
readlineStderr.removeListener("line", onErrLine);
child.removeListener("error", onError);
child.removeListener("close", onClose);
if (signal) {
Expand All @@ -58,6 +77,9 @@
recordOutput(line);
if (line.includes(expectedResponse)) {
cleanup();
readlineStdout.on("line", (l) => console.log(`[${child.name}] ${l}`));

Check failure on line 80 in app/utils/local/scripts.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(id-length)

Identifier name is too short (< 3).
readlineStderr.on("line", (l) => console.log(`[${child.name}] ${l}`));

Check failure on line 81 in app/utils/local/scripts.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(id-length)

Identifier name is too short (< 3).
child.once("close", (code) => console.log(`[${child.name}] exited with code ${code}`));
resolve(child);
}
}
Expand Down
Loading