Skip to content

Commit 74b9fe2

Browse files
authored
feat(vercel-sandbox): fix bug with resuming sandbox during file read (#102)
Fix bug with resuming sandboxes when reading a file. I have also added an integration tests to detect if this behavior is broken in the future, as it follows a different path from the other commands (it is a stream). TL;DR: we were missing the `parseOrThrow` in this method, and `withResume()` wrapper checks for an error before resuming (we were returning the error as string)
1 parent 70e5bee commit 74b9fe2

9 files changed

Lines changed: 32 additions & 4 deletions

File tree

.changeset/pre.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"common-corners-leave",
2020
"cyan-bats-clap",
2121
"dirty-cows-talk",
22+
"easy-geckos-grab",
2223
"fair-pears-dream",
2324
"fresh-rings-rescue",
2425
"legal-rings-work",

packages/sandbox/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# sandbox
22

3+
## 3.0.0-beta.8
4+
5+
### Patch Changes
6+
7+
- Updated dependencies []:
8+
- @vercel/sandbox@2.0.0-beta.8
9+
310
## 3.0.0-beta.7
411

512
### Patch Changes

packages/sandbox/docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## `sandbox --help`
22

33
```
4-
sandbox 3.0.0-beta.7
4+
sandbox 3.0.0-beta.8
55
66
▲ sandbox [options] <command>
77

packages/sandbox/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "sandbox",
33
"description": "Command line interface for Vercel Sandbox",
4-
"version": "3.0.0-beta.7",
4+
"version": "3.0.0-beta.8",
55
"scripts": {
66
"clean": "rm -rf node_modules dist",
77
"sandbox": "ts-node ./src/sandbox.ts",

packages/vercel-sandbox/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @vercel/sandbox
22

3+
## 2.0.0-beta.8
4+
5+
### Patch Changes
6+
7+
- Fix an error with resuming while reading a file
8+
39
## 2.0.0-beta.7
410

511
### Patch Changes

packages/vercel-sandbox/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@vercel/sandbox",
3-
"version": "2.0.0-beta.7",
3+
"version": "2.0.0-beta.8",
44
"description": "Software Development Kit for Vercel Sandbox",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

packages/vercel-sandbox/src/api-client/api-client.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,10 @@ export class APIClient extends BaseClient {
518518
return null;
519519
}
520520

521+
if (!response.ok) {
522+
await parseOrThrow(z.any(), response);
523+
}
524+
521525
if (response.body === null) {
522526
return null;
523527
}

packages/vercel-sandbox/src/sandbox.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,16 @@ for (const port of ports) {
347347
expect(await result.stdout()).toContain("resumed!");
348348
});
349349

350+
it("auto-resumes a stopped session when reading a file", async () => {
351+
await sandbox.writeFiles([
352+
{ path: "persist.txt", content: Buffer.from("persisted content") },
353+
]);
354+
await sandbox.stop({ blocking: true });
355+
356+
const content = await sandbox.readFileToBuffer({ path: "persist.txt" });
357+
expect(content?.toString()).toBe("persisted content");
358+
});
359+
350360
it("raises an error when the timeout cannot be updated", async () => {
351361
try {
352362
await sandbox.extendTimeout(ms("5d"));
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// Autogenerated by inject-version.ts
2-
export const VERSION = "2.0.0-beta.7";
2+
export const VERSION = "2.0.0-beta.8";

0 commit comments

Comments
 (0)