Skip to content

Commit 7edf797

Browse files
committed
Parse args sent through evaluation function
Previously they'd go in still stringified so we didn't get a chance to convert buffer objects back to buffers, for example, making things like `fs.write` write `[object Object]` to files.
1 parent fe10780 commit 7edf797

4 files changed

Lines changed: 20 additions & 10 deletions

File tree

packages/ide/test/fs.test.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const fs = require("../src/fill/fs") as typeof import("fs");
1111

1212
describe("fs", () => {
1313
let i = 0;
14-
const coderDir = path.join(os.tmpdir(), "coder");
14+
const coderDir = path.join(os.tmpdir(), "coder", "fs");
1515
const testFile = path.join(__dirname, "fs.test.ts");
1616
const tmpFile = (): string => path.join(coderDir, `${i++}`);
1717
const createTmpFile = async (): Promise<string> => {
@@ -22,6 +22,13 @@ describe("fs", () => {
2222
};
2323

2424
beforeAll(async () => {
25+
try {
26+
await util.promisify(nativeFs.mkdir)(path.dirname(coderDir));
27+
} catch (error) {
28+
if (error.code !== "EEXIST") {
29+
throw error;
30+
}
31+
}
2532
await util.promisify(rimraf)(coderDir);
2633
await util.promisify(nativeFs.mkdir)(coderDir);
2734
});
@@ -332,7 +339,7 @@ describe("fs", () => {
332339
describe("mkdtemp", () => {
333340
it("should create temp dir", async () => {
334341
await expect(util.promisify(fs.mkdtemp)(coderDir + "/"))
335-
.resolves.toMatch(/^\/tmp\/coder\/[a-zA-Z0-9]{6}/);
342+
.resolves.toMatch(/^\/tmp\/coder\/fs\/[a-zA-Z0-9]{6}/);
336343
});
337344
});
338345

packages/ide/test/net.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,17 @@ const net = require("../src/fill/net") as typeof import("net");
1212

1313
describe("net", () => {
1414
let i = 0;
15-
const coderDir = path.join(os.tmpdir(), "coder");
15+
const coderDir = path.join(os.tmpdir(), "coder", "net");
1616
const tmpFile = (): string => path.join(coderDir, `socket.${i++}`);
1717

1818
beforeAll(async () => {
19+
try {
20+
await util.promisify(fs.mkdir)(path.dirname(coderDir));
21+
} catch (error) {
22+
if (error.code !== "EEXIST") {
23+
throw error;
24+
}
25+
}
1926
await util.promisify(rimraf)(coderDir);
2027
await util.promisify(fs.mkdir)(coderDir);
2128
});

packages/protocol/src/browser/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { logger, field } from "@coder/logger";
44
import { ReadWriteConnection, InitData, OperatingSystem, SharedProcessData } from "../common/connection";
55
import { Disposer, stringify, parse } from "../common/util";
66
import { NewEvalMessage, ServerMessage, EvalDoneMessage, EvalFailedMessage, ClientMessage, WorkingInitMessage, EvalEventMessage } from "../proto";
7-
import { ActiveEval } from "./command";
7+
import { ActiveEval } from "./evaluate";
88

99
/**
1010
* Client accepts an arbitrary connection intended to communicate with the Server.

packages/protocol/src/node/evaluate.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ export interface ActiveEvaluation {
1212

1313
declare var __non_webpack_require__: typeof require;
1414
export const evaluate = (connection: SendableConnection, message: NewEvalMessage, onDispose: () => void): ActiveEvaluation | void => {
15-
const argStr: string[] = [];
16-
message.getArgsList().forEach((value) => {
17-
argStr.push(value);
18-
});
19-
2015
/**
2116
* Send the response and call onDispose.
2217
*/
@@ -94,11 +89,12 @@ export const evaluate = (connection: SendableConnection, message: NewEvalMessage
9489
process: {
9590
env: process.env,
9691
},
92+
args: message.getArgsList().map(parse),
9793
};
9894

9995
let value: any; // tslint:disable-line no-any
10096
try {
101-
const code = `(${message.getFunction()})(${eventEmitter ? "eventEmitter, " : ""}${argStr.join(",")});`;
97+
const code = `(${message.getFunction()})(${eventEmitter ? "eventEmitter, " : ""}...args);`;
10298
value = vm.runInNewContext(code, sandbox, {
10399
// If the code takes longer than this to return, it is killed and throws.
104100
timeout: message.getTimeout() || 15000,

0 commit comments

Comments
 (0)