@langchain/sandbox-standard-tests 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +246 -0
- package/dist/index.cjs +5 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/sandbox-BX7bEJLz.d.cts +168 -0
- package/dist/sandbox-C1ApHibz.js +1157 -0
- package/dist/sandbox-C1ApHibz.js.map +1 -0
- package/dist/sandbox-C22TOwhI.cjs +1169 -0
- package/dist/sandbox-C22TOwhI.cjs.map +1 -0
- package/dist/sandbox-CWDp3zl_.d.ts +168 -0
- package/dist/vitest.cjs +43 -0
- package/dist/vitest.cjs.map +1 -0
- package/dist/vitest.d.cts +19 -0
- package/dist/vitest.d.ts +19 -0
- package/dist/vitest.js +41 -0
- package/dist/vitest.js.map +1 -0
- package/package.json +77 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) LangChain, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
# @langchain/sandbox-standard-tests
|
|
2
|
+
|
|
3
|
+
Shared integration test suites for [deepagents](https://github.com/langchain-ai/deepagentsjs) sandbox providers. Run a single function call and get comprehensive coverage of the `SandboxBackendProtocol` — lifecycle management, command execution, file I/O, search, and more.
|
|
4
|
+
|
|
5
|
+
The package is **framework-agnostic** — it works with any test runner that provides `describe`, `it`, `expect`, `beforeAll`, and `afterAll`. A first-class Vitest sub-export is included for convenience.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @langchain/sandbox-standard-tests
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
### With Vitest (recommended)
|
|
16
|
+
|
|
17
|
+
Import from `@langchain/sandbox-standard-tests/vitest` and the Vitest primitives are injected automatically:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { sandboxStandardTests } from "@langchain/sandbox-standard-tests/vitest";
|
|
21
|
+
import { MySandbox } from "./sandbox.js";
|
|
22
|
+
|
|
23
|
+
sandboxStandardTests({
|
|
24
|
+
name: "MySandbox",
|
|
25
|
+
skip: !process.env.MY_SANDBOX_TOKEN,
|
|
26
|
+
timeout: 120_000,
|
|
27
|
+
createSandbox: (opts) => MySandbox.create({ ...opts }),
|
|
28
|
+
closeSandbox: (sb) => sb.close(),
|
|
29
|
+
resolvePath: (name) => `/tmp/${name}`,
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### With any test runner
|
|
34
|
+
|
|
35
|
+
Import from the root entry point and pass your runner's primitives via the `runner` config property:
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { sandboxStandardTests } from "@langchain/sandbox-standard-tests";
|
|
39
|
+
import { describe, it, expect, beforeAll, afterAll } from "bun:test";
|
|
40
|
+
import { MySandbox } from "./sandbox.js";
|
|
41
|
+
|
|
42
|
+
sandboxStandardTests({
|
|
43
|
+
name: "MySandbox",
|
|
44
|
+
runner: { describe, it, expect, beforeAll, afterAll },
|
|
45
|
+
createSandbox: (opts) => MySandbox.create({ ...opts }),
|
|
46
|
+
closeSandbox: (sb) => sb.close(),
|
|
47
|
+
resolvePath: (name) => `/tmp/${name}`,
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Run with your test runner of choice:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npx vitest run sandbox.int.test.ts
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
That single `sandboxStandardTests()` call registers **11 describe blocks** covering every method on the sandbox protocol.
|
|
58
|
+
|
|
59
|
+
## Configuration
|
|
60
|
+
|
|
61
|
+
`sandboxStandardTests` accepts a `StandardTestsConfig<T>` object:
|
|
62
|
+
|
|
63
|
+
| Option | Type | Required | Description |
|
|
64
|
+
| ---------------------------- | ---------------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
65
|
+
| `name` | `string` | yes | Display name shown in the test runner (e.g. `"ModalSandbox"`). |
|
|
66
|
+
| `runner` | `TestRunner` | yes\* | Test-runner primitives (`describe`, `it`, `expect`, `beforeAll`, `afterAll`). \*Optional when importing from `/vitest`. |
|
|
67
|
+
| `createSandbox` | `(opts?) => Promise<T>` | yes | Factory that creates and returns a running sandbox. Receives an optional `{ initialFiles }` map. |
|
|
68
|
+
| `resolvePath` | `(relativePath: string) => string` | yes | Converts a relative filename (e.g. `"test-file.txt"`) to the provider-specific absolute path (e.g. `"/tmp/test-file.txt"` or `"/home/app/test-file.txt"`). |
|
|
69
|
+
| `closeSandbox` | `(sandbox: T) => Promise<void>` | no | Teardown function. If omitted the "close" lifecycle test is skipped. |
|
|
70
|
+
| `createUninitializedSandbox` | `() => T` | no | Factory for a sandbox that has **not** been started yet. Enables the two-step initialization test. |
|
|
71
|
+
| `skip` | `boolean` | no | Skip the entire suite (useful when credentials are missing). |
|
|
72
|
+
| `sequential` | `boolean` | no | Run tests sequentially instead of in parallel (useful to avoid provider concurrency limits). |
|
|
73
|
+
| `timeout` | `number` | no | Per-test timeout in ms. Defaults to `120_000` (2 min). |
|
|
74
|
+
|
|
75
|
+
### `TestRunner`
|
|
76
|
+
|
|
77
|
+
The `runner` object must provide these five primitives from your test framework:
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
interface TestRunner {
|
|
81
|
+
describe: SuiteFn;
|
|
82
|
+
it: TestFn;
|
|
83
|
+
expect: ExpectFn;
|
|
84
|
+
beforeAll: HookFn;
|
|
85
|
+
afterAll: HookFn;
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The `describe` and `it` functions may optionally expose `.skip`, `.skipIf(condition)`, and `.sequential` modifiers. When a modifier is not available the suite gracefully degrades (e.g. `describe.sequential` falls back to `describe`).
|
|
90
|
+
|
|
91
|
+
### `SandboxInstance`
|
|
92
|
+
|
|
93
|
+
Your sandbox class must implement the `SandboxInstance` interface, which extends `SandboxBackendProtocol` from `deepagents`:
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
interface SandboxInstance extends SandboxBackendProtocol {
|
|
97
|
+
readonly isRunning: boolean;
|
|
98
|
+
uploadFiles(
|
|
99
|
+
files: Array<[string, Uint8Array]>,
|
|
100
|
+
): MaybePromise<FileUploadResponse[]>;
|
|
101
|
+
downloadFiles(paths: string[]): MaybePromise<FileDownloadResponse[]>;
|
|
102
|
+
initialize?(): Promise<void>;
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
The key difference from the base protocol is that `uploadFiles` and `downloadFiles` are **required** (they are optional in `SandboxBackendProtocol`).
|
|
107
|
+
|
|
108
|
+
## What gets tested
|
|
109
|
+
|
|
110
|
+
| Suite | What it covers |
|
|
111
|
+
| --------------------- | -------------------------------------------------------------------------------------------- |
|
|
112
|
+
| **Lifecycle** | `create`, `isRunning`, `close`, two-step `initialize` |
|
|
113
|
+
| **Command execution** | `echo`, exit codes, multiline output, stderr, env vars, non-existent commands |
|
|
114
|
+
| **File operations** | `uploadFiles`, `downloadFiles`, round-trip integrity |
|
|
115
|
+
| **write()** | New files, parent directory creation, overwrite, special characters, unicode, long content |
|
|
116
|
+
| **read()** | Basic read, non-existent path, `offset`, `limit`, `offset + limit`, unicode, chunked reads |
|
|
117
|
+
| **edit()** | Single/multi occurrence, `replaceAll`, not-found handling, special chars, multiline, unicode |
|
|
118
|
+
| **lsInfo()** | Directory listing, empty dirs, hidden files, large directories, absolute paths |
|
|
119
|
+
| **grepRaw()** | Pattern search, glob filters, case sensitivity, nested directories, unicode |
|
|
120
|
+
| **globInfo()** | Wildcards, recursive patterns, extension filters, character classes, deeply nested |
|
|
121
|
+
| **Initial files** | Basic seeding, nested paths, empty files |
|
|
122
|
+
| **Integration** | End-to-end write → read → edit workflows, complex directory operations, error handling |
|
|
123
|
+
|
|
124
|
+
## Sandbox reuse strategy
|
|
125
|
+
|
|
126
|
+
To avoid spinning up too many sandbox instances (which can hit provider concurrency limits), the test suite uses a **single shared sandbox** for the majority of tests. Only two kinds of tests create temporary instances:
|
|
127
|
+
|
|
128
|
+
- **Lifecycle** tests that verify `close` and two-step initialization
|
|
129
|
+
- **Initial files** tests that require a fresh sandbox with pre-seeded content
|
|
130
|
+
|
|
131
|
+
These temporary sandboxes are torn down immediately, so the concurrent sandbox count never exceeds **2**.
|
|
132
|
+
|
|
133
|
+
## Retry helper
|
|
134
|
+
|
|
135
|
+
The package exports a `withRetry` utility for working around transient sandbox creation failures (e.g. provider concurrency limits):
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
import { withRetry } from "@langchain/sandbox-standard-tests/vitest";
|
|
139
|
+
|
|
140
|
+
const sandbox = await withRetry(
|
|
141
|
+
() => MySandbox.create({ memoryMb: 512 }),
|
|
142
|
+
5, // max attempts (default: 5)
|
|
143
|
+
15_000, // delay between attempts in ms (default: 15 000)
|
|
144
|
+
);
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Real-world examples
|
|
148
|
+
|
|
149
|
+
### Remote provider (Modal)
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
import {
|
|
153
|
+
sandboxStandardTests,
|
|
154
|
+
withRetry,
|
|
155
|
+
} from "@langchain/sandbox-standard-tests/vitest";
|
|
156
|
+
import { ModalSandbox } from "./sandbox.js";
|
|
157
|
+
|
|
158
|
+
const hasCredentials = !!(
|
|
159
|
+
process.env.MODAL_TOKEN_ID && process.env.MODAL_TOKEN_SECRET
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
sandboxStandardTests({
|
|
163
|
+
name: "ModalSandbox",
|
|
164
|
+
skip: !hasCredentials,
|
|
165
|
+
timeout: 180_000,
|
|
166
|
+
createSandbox: (opts) =>
|
|
167
|
+
ModalSandbox.create({ imageName: "alpine:3.21", ...opts }),
|
|
168
|
+
createUninitializedSandbox: () =>
|
|
169
|
+
new ModalSandbox({ imageName: "alpine:3.21" }),
|
|
170
|
+
closeSandbox: (sb) => sb.close(),
|
|
171
|
+
resolvePath: (name) => `/tmp/${name}`,
|
|
172
|
+
});
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Sequential execution (Deno Deploy)
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
import { sandboxStandardTests } from "@langchain/sandbox-standard-tests/vitest";
|
|
179
|
+
import { DenoSandbox } from "./sandbox.js";
|
|
180
|
+
|
|
181
|
+
sandboxStandardTests({
|
|
182
|
+
name: "DenoSandbox",
|
|
183
|
+
skip: !process.env.DENO_DEPLOY_TOKEN,
|
|
184
|
+
sequential: true,
|
|
185
|
+
timeout: 120_000,
|
|
186
|
+
createSandbox: (opts) => DenoSandbox.create({ memoryMb: 768, ...opts }),
|
|
187
|
+
createUninitializedSandbox: () => new DenoSandbox({ memoryMb: 768 }),
|
|
188
|
+
closeSandbox: (sb) => sb.close(),
|
|
189
|
+
resolvePath: (name) => `/home/app/${name}`,
|
|
190
|
+
});
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Local provider (Node VFS)
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
import { sandboxStandardTests } from "@langchain/sandbox-standard-tests/vitest";
|
|
197
|
+
import { VfsSandbox } from "./sandbox.js";
|
|
198
|
+
|
|
199
|
+
sandboxStandardTests({
|
|
200
|
+
name: "VfsSandbox",
|
|
201
|
+
skip: process.platform === "win32",
|
|
202
|
+
timeout: 30_000,
|
|
203
|
+
createSandbox: (opts) => VfsSandbox.create(opts),
|
|
204
|
+
closeSandbox: (sb) => sb.stop(),
|
|
205
|
+
resolvePath: (name) => name,
|
|
206
|
+
});
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Custom runner (Bun)
|
|
210
|
+
|
|
211
|
+
```ts
|
|
212
|
+
import { sandboxStandardTests } from "@langchain/sandbox-standard-tests";
|
|
213
|
+
import { describe, it, expect, beforeAll, afterAll } from "bun:test";
|
|
214
|
+
import { MySandbox } from "./sandbox.js";
|
|
215
|
+
|
|
216
|
+
sandboxStandardTests({
|
|
217
|
+
name: "MySandbox",
|
|
218
|
+
runner: { describe, it, expect, beforeAll, afterAll },
|
|
219
|
+
createSandbox: (opts) => MySandbox.create(opts),
|
|
220
|
+
closeSandbox: (sb) => sb.close(),
|
|
221
|
+
resolvePath: (name) => `/tmp/${name}`,
|
|
222
|
+
});
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Adding provider-specific tests
|
|
226
|
+
|
|
227
|
+
After calling `sandboxStandardTests`, you can add provider-specific tests in the same file using standard Vitest `describe` / `it` blocks:
|
|
228
|
+
|
|
229
|
+
```ts
|
|
230
|
+
sandboxStandardTests({
|
|
231
|
+
/* ... */
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
describe("MySandbox Provider-Specific Tests", () => {
|
|
235
|
+
it("should support custom image types", async () => {
|
|
236
|
+
const sb = await MySandbox.create({ image: "python:3.12" });
|
|
237
|
+
const result = await sb.execute("python --version");
|
|
238
|
+
expect(result.exitCode).toBe(0);
|
|
239
|
+
await sb.close();
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## License
|
|
245
|
+
|
|
246
|
+
MIT
|
package/dist/index.cjs
ADDED
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as SandboxInstance, c as TestFn, i as HookFn, l as TestRunner, n as withRetry, o as StandardTestsConfig, r as ExpectFn, s as SuiteFn, t as sandboxStandardTests } from "./sandbox-BX7bEJLz.cjs";
|
|
2
|
+
export { type ExpectFn, type HookFn, type SandboxInstance, type StandardTestsConfig, type SuiteFn, type TestFn, type TestRunner, sandboxStandardTests, withRetry };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as SandboxInstance, c as TestFn, i as HookFn, l as TestRunner, n as withRetry, o as StandardTestsConfig, r as ExpectFn, s as SuiteFn, t as sandboxStandardTests } from "./sandbox-CWDp3zl_.js";
|
|
2
|
+
export { type ExpectFn, type HookFn, type SandboxInstance, type StandardTestsConfig, type SuiteFn, type TestFn, type TestRunner, sandboxStandardTests, withRetry };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { FileDownloadResponse, FileUploadResponse, MaybePromise, SandboxBackendProtocol } from "deepagents";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
/** A `describe` / suite function accepted by the standard tests. */
|
|
5
|
+
interface SuiteFn {
|
|
6
|
+
(name: string, fn: () => void): void;
|
|
7
|
+
skip?: SuiteFn;
|
|
8
|
+
sequential?: SuiteFn;
|
|
9
|
+
skipIf?: (condition: boolean) => SuiteFn;
|
|
10
|
+
}
|
|
11
|
+
/** An `it` / test function accepted by the standard tests. */
|
|
12
|
+
interface TestFn {
|
|
13
|
+
(name: string, fn: () => void | Promise<void>, timeout?: number): void;
|
|
14
|
+
skipIf?: (condition: boolean) => TestFn;
|
|
15
|
+
}
|
|
16
|
+
/** A `beforeAll` / `afterAll` hook function. */
|
|
17
|
+
type HookFn = (fn: () => void | Promise<void>, timeout?: number) => void;
|
|
18
|
+
/**
|
|
19
|
+
* An `expect` function.
|
|
20
|
+
*
|
|
21
|
+
* The return type is intentionally `any` — every test framework exposes
|
|
22
|
+
* its own matcher API and fully typing it would couple the package to a
|
|
23
|
+
* specific runner.
|
|
24
|
+
*/
|
|
25
|
+
type ExpectFn = (value: unknown) => any;
|
|
26
|
+
/**
|
|
27
|
+
* Test-runner primitives required by the standard test suite.
|
|
28
|
+
*
|
|
29
|
+
* Pass the primitives from your test framework (Vitest, Jest, …) when
|
|
30
|
+
* importing from the root entry point. The `@langchain/sandbox-standard-tests/vitest`
|
|
31
|
+
* sub-export fills these in automatically.
|
|
32
|
+
*/
|
|
33
|
+
interface TestRunner {
|
|
34
|
+
describe: SuiteFn;
|
|
35
|
+
it: TestFn;
|
|
36
|
+
expect: ExpectFn;
|
|
37
|
+
beforeAll: HookFn;
|
|
38
|
+
afterAll: HookFn;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Interface for sandbox instances used in standard tests.
|
|
42
|
+
*
|
|
43
|
+
* Extends the canonical `SandboxBackendProtocol` from deepagents with
|
|
44
|
+
* test-specific properties (`isRunning`, `initialize`) and makes
|
|
45
|
+
* `uploadFiles`/`downloadFiles` required (they are optional in the
|
|
46
|
+
* base protocol).
|
|
47
|
+
*/
|
|
48
|
+
interface SandboxInstance extends SandboxBackendProtocol {
|
|
49
|
+
/** Whether the sandbox is currently running */
|
|
50
|
+
readonly isRunning: boolean;
|
|
51
|
+
/** Upload multiple files (required for standard tests) */
|
|
52
|
+
uploadFiles(files: Array<[string, Uint8Array]>): MaybePromise<FileUploadResponse[]>;
|
|
53
|
+
/** Download multiple files (required for standard tests) */
|
|
54
|
+
downloadFiles(paths: string[]): MaybePromise<FileDownloadResponse[]>;
|
|
55
|
+
/** Optional two-step initialization */
|
|
56
|
+
initialize?(): Promise<void>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Configuration for the standard sandbox test suite.
|
|
60
|
+
*
|
|
61
|
+
* @typeParam T - The concrete sandbox type (e.g., ModalSandbox, DenoSandbox)
|
|
62
|
+
*/
|
|
63
|
+
interface StandardTestsConfig<T extends SandboxInstance = SandboxInstance> {
|
|
64
|
+
/**
|
|
65
|
+
* Display name for the test suite (e.g., "ModalSandbox", "DenoSandbox").
|
|
66
|
+
*/
|
|
67
|
+
name: string;
|
|
68
|
+
/**
|
|
69
|
+
* Test-runner primitives (`describe`, `it`, `expect`, `beforeAll`, `afterAll`).
|
|
70
|
+
*
|
|
71
|
+
* Required when importing from the root entry point. Pre-filled when
|
|
72
|
+
* importing from `@langchain/sandbox-standard-tests/vitest`.
|
|
73
|
+
*/
|
|
74
|
+
runner: TestRunner;
|
|
75
|
+
/**
|
|
76
|
+
* Skip all tests when true (e.g., when credentials are missing).
|
|
77
|
+
*/
|
|
78
|
+
skip?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Run tests sequentially to avoid concurrency limits.
|
|
81
|
+
*/
|
|
82
|
+
sequential?: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Timeout for each test in milliseconds.
|
|
85
|
+
* @default 120_000
|
|
86
|
+
*/
|
|
87
|
+
timeout?: number;
|
|
88
|
+
/**
|
|
89
|
+
* Factory function to create a new sandbox instance.
|
|
90
|
+
*
|
|
91
|
+
* The test suite passes `initialFiles` with paths already resolved via
|
|
92
|
+
* `resolvePath`. The implementation should pass them through to the
|
|
93
|
+
* provider's create method.
|
|
94
|
+
*
|
|
95
|
+
* `initialFiles` values are always strings (not Uint8Array) in the
|
|
96
|
+
* standard tests.
|
|
97
|
+
*/
|
|
98
|
+
createSandbox: (options?: {
|
|
99
|
+
initialFiles?: Record<string, string>;
|
|
100
|
+
}) => Promise<T>;
|
|
101
|
+
/**
|
|
102
|
+
* Optional factory for creating an uninitialized sandbox for the
|
|
103
|
+
* two-step initialization test. If omitted, the test is skipped.
|
|
104
|
+
*/
|
|
105
|
+
createUninitializedSandbox?: () => T;
|
|
106
|
+
/**
|
|
107
|
+
* Close / cleanup a sandbox instance.
|
|
108
|
+
*/
|
|
109
|
+
closeSandbox?: (sandbox: T) => Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Convert a relative file path (e.g., `"test-file.txt"`) to the
|
|
112
|
+
* provider-specific absolute or working-directory path
|
|
113
|
+
* (e.g., `"/tmp/test-file.txt"` or just `"test-file.txt"`).
|
|
114
|
+
*/
|
|
115
|
+
resolvePath: (relativePath: string) => string;
|
|
116
|
+
}
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/sandbox.d.ts
|
|
119
|
+
/**
|
|
120
|
+
* Retry an async operation with a fixed delay between attempts.
|
|
121
|
+
*
|
|
122
|
+
* Useful for working around transient sandbox concurrency limits:
|
|
123
|
+
* when a provider rejects creation because the organisation has too
|
|
124
|
+
* many running sandboxes, waiting a short while and retrying usually
|
|
125
|
+
* succeeds once a previous sandbox finishes shutting down.
|
|
126
|
+
*
|
|
127
|
+
* @param fn - The async operation to attempt
|
|
128
|
+
* @param maxRetries - Maximum number of attempts (default: 3)
|
|
129
|
+
* @param delayMs - Milliseconds to wait between attempts (default: 10 000)
|
|
130
|
+
* @returns The result of the first successful attempt
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```ts
|
|
134
|
+
* const sandbox = await withRetry(() => DenoSandbox.create({ memoryMb: 768 }));
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
declare function withRetry<T>(fn: () => Promise<T>, maxRetries?: number, delayMs?: number): Promise<T>;
|
|
138
|
+
/**
|
|
139
|
+
* Run the standard sandbox integration tests against a provider.
|
|
140
|
+
*
|
|
141
|
+
* A single shared sandbox is created in `beforeAll` and reused for the
|
|
142
|
+
* majority of tests (command execution, file operations). Tests that
|
|
143
|
+
* inherently need their own sandbox (lifecycle close/init, initialFiles)
|
|
144
|
+
* create a temporary one and destroy it immediately, so the concurrent
|
|
145
|
+
* sandbox count never exceeds **2** (shared + 1 temporary).
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```ts
|
|
149
|
+
* import { sandboxStandardTests } from "@langchain/sandbox-standard-tests/vitest";
|
|
150
|
+
* import { ModalSandbox } from "./sandbox.js";
|
|
151
|
+
*
|
|
152
|
+
* sandboxStandardTests({
|
|
153
|
+
* name: "ModalSandbox",
|
|
154
|
+
* skip: !process.env.MODAL_TOKEN_ID,
|
|
155
|
+
* timeout: 180_000,
|
|
156
|
+
* createSandbox: (opts) =>
|
|
157
|
+
* ModalSandbox.create({ imageName: "alpine:3.21", ...opts }),
|
|
158
|
+
* createUninitializedSandbox: () =>
|
|
159
|
+
* new ModalSandbox({ imageName: "alpine:3.21" }),
|
|
160
|
+
* closeSandbox: (sb) => sb.close(),
|
|
161
|
+
* resolvePath: (name) => `/tmp/${name}`,
|
|
162
|
+
* });
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
declare function sandboxStandardTests<T extends SandboxInstance>(config: StandardTestsConfig<T>): void;
|
|
166
|
+
//#endregion
|
|
167
|
+
export { SandboxInstance as a, TestFn as c, HookFn as i, TestRunner as l, withRetry as n, StandardTestsConfig as o, ExpectFn as r, SuiteFn as s, sandboxStandardTests as t };
|
|
168
|
+
//# sourceMappingURL=sandbox-BX7bEJLz.d.cts.map
|