Skip to content
Merged
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
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ jobs:
- name: check
run: deno check

- name: run tests
env:
DENO_DEPLOY_TOKEN: ${{ secrets.DENO_DEPLOY_TOKEN }}
DENO_DEPLOY_CLI_SPECIFIER: file://${{ github.workspace }}/main.ts
run: deno test --allow-all

jsr:
runs-on: ubuntu-latest
permissions:
Expand Down
4 changes: 3 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@cfa/gitignore-parser": "jsr:@cfa/gitignore-parser@^0.1.4",
"@cliffy/command": "jsr:@cliffy/command@^1.0.0-rc.8",
"@deno/sandbox": "jsr:@deno/sandbox@^0.5.0",
"@std/assert": "jsr:@std/assert@^1.0.16",
"@std/async": "jsr:@std/async@^1.0.15",
"@std/cli": "jsr:@std/cli@1.0.22",
"@std/dotenv": "jsr:@std/dotenv@^0.225.5",
Expand All @@ -37,7 +38,8 @@
"superjson": "npm:superjson@^2.2.2",
"@deno/framework-detect": "jsr:@deno/framework-detect@^0",
"temporal-polyfill": "npm:temporal-polyfill@^0.3.0",
"prompts": "npm:prompts@2.4.2"
"prompts": "npm:prompts@2.4.2",
"dax": "jsr:@david/dax@^0.44.2"
},
"exclude": [
"astro-demo"
Expand Down
69 changes: 68 additions & 1 deletion deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

157 changes: 157 additions & 0 deletions sandbox.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import { $ } from "dax";
import { assert, assertEquals } from "@std/assert";

if (!Deno.env.get("DENO_DEPLOY_TOKEN")) {
console.error("DENO_DEPLOY_TOKEN environment variable is required.");
Deno.exit(1);
}

const sandbox = async (...args: string[]) => {
console.log(`deno sandbox ${args.join(" ")}`);
return (await $.raw`deno sandbox ${args.join(" ")}`.text()).trim();
};

Deno.test("sandbox create", async () => {
const sandboxId = await sandbox(
"create",
"--quiet",
"--lifetime",
"60s",
"echo",
"test",
);
await sandbox("kill", sandboxId);
});

Deno.test("sandbox exec", async () => {
const sandboxId = await sandbox("create", "--quiet", "--lifetime", "60s");

const res = await sandbox("exec", sandboxId, "echo", "'exec test'");
assertEquals(res, "exec test");

await sandbox("kill", sandboxId);
});

Deno.test("sandbox copy", async () => {
const sandboxId = await sandbox("create", "--quiet", "--lifetime", "60s");

await Deno.writeTextFile("test.txt", "test content");

await sandbox("copy", "test.txt", `${sandboxId}:/tmp/test.txt`);

await sandbox("copy", `${sandboxId}:/tmp/test.txt`, "./downloaded.txt");
const downloadedContent = await Deno.readTextFile("./downloaded.txt");
assertEquals(downloadedContent, "test content");

await Deno.remove("test.txt");
await Deno.remove("downloaded.txt");

await sandbox("kill", sandboxId);
});

Deno.test("sandbox extend", async () => {
const sandboxId = await sandbox(
"create",
"--quiet",
"--lifetime",
"60s",
"sleep",
"10",
);

await sandbox("extend", sandboxId, "120s");

await sandbox("kill", sandboxId);
});

Deno.test("sandbox exec with complex commands", async () => {
const sandboxId = await sandbox("create", "--quiet", "--lifetime", "60s");

const result = await sandbox("exec", sandboxId, "'echo hello && echo world'");
assert(result.includes("hello"));
assert(result.includes("world"));

await sandbox("kill", sandboxId);
});

Deno.test("sandbox copy directory structure", async () => {
const sandboxId = await sandbox("create", "--quiet", "--lifetime", "60s");

await Deno.mkdir("testdir", { recursive: true });
await Deno.writeTextFile("testdir/file1.txt", "content1");
await Deno.writeTextFile("testdir/file2.txt", "content2");

await sandbox("exec", sandboxId, "'mkdir -p /tmp/testdir'");
await sandbox(
"copy",
"testdir/file1.txt",
`${sandboxId}:/tmp/testdir/file1.txt`,
);
await sandbox(
"copy",
"testdir/file2.txt",
`${sandboxId}:/tmp/testdir/file2.txt`,
);

const result = await sandbox("exec", sandboxId, "ls", "/tmp/testdir");
assert(result.includes("file1.txt"));
assert(result.includes("file2.txt"));

await Deno.remove("testdir", { recursive: true });
await sandbox("kill", sandboxId);
});

Deno.test("volumes create", async () => {
const volumeName = `test-vol-${crypto.randomUUID()}`.slice(0, 32);

const volumeId = await sandbox(
"volumes",
"create",
volumeName,
"--capacity",
"1gb",
"--region",
"ord",
);

await sandbox("volumes", "delete", volumeId);
});

Deno.test("sandbox with volume mount", async () => {
const volumeName = `test-vol-${crypto.randomUUID()}`.slice(0, 32);

const volumeId = await sandbox(
"volumes",
"create",
volumeName,
"--capacity",
"1gb",
"--region",
"ord",
);

const sandboxId = await sandbox(
"create",
"--quiet",
"--lifetime",
"60s",
"--volume",
`${volumeId}:/data/dataset`,
);

await sandbox(
"exec",
sandboxId,
"\"echo 'volume test' > /data/dataset/test.txt\"",
);
const result = await sandbox(
"exec",
sandboxId,
"cat",
"/data/dataset/test.txt",
);
assertEquals(result, "volume test");

await sandbox("kill", sandboxId);
await sandbox("volumes", "delete", volumeId);
});
Loading