Skip to content

Commit e37d49c

Browse files
committed
Don't clear files in the state on execution start
1 parent 004093a commit e37d49c

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

src/frontend/state/InputOutput.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ export class InputOutput extends State {
232232
this.output = [];
233233
this.prompt = "";
234234
this.awaitingInput = false;
235-
this.files = [];
236235
this.activeEditorTab = CODE_TAB;
237236
}
238237
}

test/__tests__/state/Files.test.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Papyros } from "../../../src/frontend/state/Papyros";
22
import { expect, it, describe } from "vitest";
33
import { ProgrammingLanguage } from "../../../src/ProgrammingLanguage";
4-
import { waitForFiles, waitForPapyrosReady, waitForInputReady, waitForOutput } from "../../helpers";
4+
import { waitForFiles, waitForPapyrosReady, waitForInputReady, waitForOutput, waitForAwaitingInput } from "../../helpers";
55
import { isValidFileName } from "../../../src/util/Util";
66

77
describe("isValidFileName", () => {
@@ -117,6 +117,29 @@ raise ValueError("intentional error")
117117
expect(papyros.io.files[0].content).toBe("before crash");
118118
});
119119

120+
it("files from previous run persist while awaiting input in next run", async () => {
121+
const papyros = new Papyros();
122+
await papyros.launch();
123+
papyros.runner.programmingLanguage = ProgrammingLanguage.Python;
124+
papyros.runner.code = `open("persist.txt", "w").write("hello")`;
125+
await waitForInputReady();
126+
await papyros.runner.start();
127+
await waitForFiles(papyros, 1);
128+
expect(papyros.io.files.length).toBe(1);
129+
expect(papyros.io.files[0].name).toBe("persist.txt");
130+
131+
papyros.runner.code = `x = input("name?")`;
132+
void papyros.runner.start();
133+
await waitForAwaitingInput(papyros);
134+
expect(papyros.io.files.length).toBe(1);
135+
expect(papyros.io.files[0].name).toBe("persist.txt");
136+
137+
papyros.io.provideInput("test");
138+
await waitForPapyrosReady(papyros);
139+
expect(papyros.io.files.length).toBe(1);
140+
expect(papyros.io.files[0].name).toBe("persist.txt");
141+
});
142+
120143
it("updateFileContent updates the in-memory content of an existing file", async () => {
121144
const papyros = new Papyros();
122145
await papyros.launch();

0 commit comments

Comments
 (0)