PIPE: Add pipe support for passing data into and out of terminal commands (#2395)

This commit is contained in:
Michael Ficocelli
2026-02-22 12:18:23 -07:00
committed by GitHub
parent 4a22e16058
commit 92b8b58588
68 changed files with 2430 additions and 480 deletions

View File

@@ -14,6 +14,7 @@ import { WorkerScript } from "../../../src/Netscript/WorkerScript";
import { NetscriptFunctions } from "../../../src/NetscriptFunctions";
import type { PositiveInteger } from "../../../src/types";
import { ErrorState } from "../../../src/ErrorHandling/ErrorState";
import { getTerminalStdIO } from "../../../src/Terminal/StdIO/RedirectIO";
fixDoImportIssue();
@@ -36,7 +37,7 @@ async function expectErrorWhenRunningScript(
for (const script of scripts) {
Player.getHomeComputer().writeToScriptFile(script.filePath, script.code);
}
runScript(testScriptPath, [], Player.getHomeComputer());
runScript(testScriptPath, [], Player.getHomeComputer(), getTerminalStdIO());
const workerScript = workerScripts.get(1);
if (!workerScript) {
throw new Error(`Invalid worker script`);
@@ -145,7 +146,7 @@ describe("runScript and runScriptFromScript", () => {
ns.print(server.hostname);
}`,
);
runScript(testScriptPath, [], Player.getHomeComputer());
runScript(testScriptPath, [], Player.getHomeComputer(), getTerminalStdIO());
const workerScript = workerScripts.get(1);
if (!workerScript) {
throw new Error(`Invalid worker script`);
@@ -160,7 +161,7 @@ describe("runScript and runScriptFromScript", () => {
});
describe("Failure", () => {
test("Script does not exist", () => {
runScript(testScriptPath, [], Player.getHomeComputer());
runScript(testScriptPath, [], Player.getHomeComputer(), getTerminalStdIO());
expect((Terminal.outputHistory[1] as { text: string }).text).toContain(
`Script ${testScriptPath} does not exist on home`,
);
@@ -172,7 +173,7 @@ describe("runScript and runScriptFromScript", () => {
`export async function main(ns) {
}`,
);
runScript(testScriptPath, [], server);
runScript(testScriptPath, [], server, getTerminalStdIO());
expect((Terminal.outputHistory[1] as { text: string }).text).toContain(
`You do not have root access on ${server.hostname}`,
);
@@ -184,7 +185,7 @@ describe("runScript and runScriptFromScript", () => {
{
}`,
);
runScript(testScriptPath, [], Player.getHomeComputer());
runScript(testScriptPath, [], Player.getHomeComputer(), getTerminalStdIO());
expect((Terminal.outputHistory[1] as { text: string }).text).toContain(
`Cannot calculate RAM usage of ${testScriptPath}`,
);
@@ -196,7 +197,7 @@ describe("runScript and runScriptFromScript", () => {
ns.ramOverride(1024);
}`,
);
runScript(testScriptPath, [], Player.getHomeComputer());
runScript(testScriptPath, [], Player.getHomeComputer(), getTerminalStdIO());
expect((Terminal.outputHistory[1] as { text: string }).text).toContain("This script requires 1.02TB of RAM");
});
test("Thrown error in main function", async () => {