Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
21 changes: 14 additions & 7 deletions apps/server/src/project/ProjectSetupScriptRunner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ describe("ProjectSetupScriptRunner", () => {
const { writes } = yield* setup({
shell: "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
});
expect(yield* Queue.take(writes)).toContain("$global:LASTEXITCODE");
const submitted = yield* Queue.take(writes);
expect(submitted).toContain("$global:LASTEXITCODE");
expect(submitted).not.toContain("\x1b[200~");
}),
);

Expand Down Expand Up @@ -186,9 +188,11 @@ describe("ProjectSetupScriptRunner", () => {

it.effect("types into a quiet shell that has no line editor", () =>
Effect.gen(function* () {
const { writes } = yield* setup();
const { writes } = yield* setup({ command: "printf '%s\\n' 'setup-ready'\n".repeat(120) });
yield* TestClock.adjust("3 seconds");
expect(yield* Queue.take(writes)).toContain("vp i");
const submitted = yield* Queue.take(writes);
expect(submitted).toContain("setup-ready");
expect(submitted).not.toContain("\x1b[200~");
}),
);

Expand Down Expand Up @@ -248,6 +252,7 @@ const runObservedSetup = Effect.fnUntraced(function* (command: string) {
const { writes, outputLines, emit, completion } = yield* setup({ command });
yield* emit({ ...event, type: "output", data: "\x1b[?2004h" });
const submitted = yield* Queue.take(writes);
const shellInput = submitted.replace("\x1b[200~", "").replace("\x1b[201~", "");
const cwd = yield* HostProcess.WorkingDirectory;
const env = yield* HostProcess.Environment;

Expand All @@ -258,7 +263,7 @@ const runObservedSetup = Effect.fnUntraced(function* (command: string) {
const handle = yield* spawner.spawn(
ChildProcess.make(
"/bin/bash",
["--noprofile", "--norc", "-c", submitted.replaceAll("\r", "\n")],
["--noprofile", "--norc", "-c", shellInput.replaceAll("\r", "\n")],
{
cwd,
env: { PATH: env.PATH },
Expand All @@ -279,6 +284,7 @@ const runObservedSetup = Effect.fnUntraced(function* (command: string) {
yield* emit({ ...event, type: "closed" });
return {
submitted,
shellInput,
lines: yield* Queue.clear(outputLines),
exitCode: (yield* completion).exitCode,
};
Expand Down Expand Up @@ -324,9 +330,10 @@ describe.skipIf(HostProcess.Platform.defaultValue() === "win32")("POSIX setup co
assert.deepEqual(result.lines, expected);
assert.equal(result.exitCode, 0);
assert.equal(result.submitted.at(-1), "\r");
assert.notInclude(result.submitted, "\n");
// The runner can write before the shell switches the terminal out of canonical mode.
for (const line of result.submitted.slice(0, -1).split("\r")) {
assert.isTrue(result.submitted.startsWith(" \x1b[200~"));
assert.isTrue(result.submitted.endsWith("\x1b[201~\r"));
assert.notInclude(result.submitted.slice(0, -1), "\r");
for (const line of result.shellInput.slice(0, -1).split("\n")) {
assert.isBelow(utf8.encode(line).byteLength, 1_024);
}
}),
Expand Down
9 changes: 7 additions & 2 deletions apps/server/src/project/ProjectSetupScriptRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ export const make = Effect.gen(function* () {
const seen = activity;
yield* Effect.sleep(SHELL_QUIET_FALLBACK);
if (activity !== seen) continue;
if (!busy) return "ready" as const;
if (!busy) return "quiet" as const;
yield* input.onStartupPrompt;
}
});
Expand Down Expand Up @@ -590,7 +590,12 @@ export const make = Effect.gen(function* () {
: terminalManager.write({
threadId: input.threadId,
terminalId,
data: projectScriptTerminalInput(commandLine),
// macOS zsh garbles long typed-ahead multiline input; a live line editor takes it as one paste.
data: projectScriptTerminalInput(
shell === "ready" && completionShell === "posix" && commandLine.includes("\r")
? `\x1b[200~${commandLine.replaceAll("\r", "\n")}\x1b[201~`
: commandLine,
),
}),
),
Effect.catchCause((cause) =>
Expand Down
Loading