Skip to content

An open-source, faster Devin alternative

TypeScript

stress tests

Brian Reardon848b1110ac1f
diff --git a/sdks/typescript/examples/test-openclaw-snapshot-stress.ts b/sdks/typescript/examples/test-openclaw-snapshot-stress.ts
new file mode 100644
index 00000000..9bfecab6
--- /dev/null
+++ b/sdks/typescript/examples/test-openclaw-snapshot-stress.ts
@@ -0,0 +1,117 @@
+/**
+ * Stress test OpenClaw snapshot builds — runs N full builds, each with a unique
+ * image (cache-busted) so every build goes through the full install flow.
+ *
+ * Usage:
+ * OPENCOMPUTER_API_KEY=... npx tsx examples/test-openclaw-snapshot-stress.ts [count]
+ *
+ * Default: 5 builds
+ */
+
+import { Image, Snapshots } from "@opencomputer/sdk/node";
+
+const API_URL = process.env.OPENCOMPUTER_API_URL || "https://app.opencomputer.dev";
+const API_KEY = process.env.OPENCOMPUTER_API_KEY;
+const COUNT = parseInt(process.argv[2] || "5", 10);
+
+if (!API_KEY) {
+ console.error("Set OPENCOMPUTER_API_KEY");
+ process.exit(1);
+}
+
+const snapshots = new Snapshots({ apiKey: API_KEY, apiUrl: API_URL });
+
+async function buildOne(i: number): Promise<{ name: string; durationMs: number; status: string }> {
+ const name = `openclaw-stress-${Date.now()}-${i}`;
+
+ // Cache-bust: unique marker file per build forces a fresh image
+ const image = Image.base()
+ .runCommands(
+ "sudo apt-get update && sudo apt-get install -y curl ca-certificates gnupg",
+ )
+ .runCommands(
+ "curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -",
+ "sudo apt-get install -y nodejs",
+ )
+ .runCommands(
+ "mkdir -p ~/npm-global",
+ "npm config set prefix ~/npm-global",
+ "npm install -g openclaw@latest",
+ "echo 'export PATH=$HOME/npm-global/bin:$PATH' | sudo tee /etc/profile.d/npm-global.sh",
+ )
+ .runCommands("mkdir -p ~/.openclaw/workspace")
+ .addFile(
+ "/home/sandbox/start-openclaw.sh",
+ `#!/bin/bash
+set -e
+export PATH=$HOME/npm-global/bin:$PATH
+[ -f ~/.openclaw/env ] && source ~/.openclaw/env
+cd ~
+nohup openclaw gateway --port 18789 > ~/.openclaw/gateway.log 2>&1 &
+for i in $(seq 1 30); do
+ if openclaw gateway status > /dev/null 2>&1; then
+ echo "OpenClaw gateway is ready"
+ exit 0
+ fi
+ sleep 1
+done
+echo "Warning: gateway did not become ready within 30s"
+exit 1
+`,
+ )
+ .runCommands("sudo chmod +x ~/start-openclaw.sh")
+ // Cache-bust: unique echo per build
+ .runCommands(`echo "build-${name}" > /tmp/build-marker`);
+
+ const t0 = Date.now();
+ const info = await snapshots.create({
+ name,
+ image,
+ onBuildLogs: (line: string) => {
+ process.stdout.write(` [${i + 1}] ${line}\n`);
+ },
+ });
+
+ return { name, durationMs: Date.now() - t0, status: info.status };
+}
+
+async function main() {
+ console.log(`OpenClaw snapshot stress test: ${COUNT} full builds`);
+ console.log(`API: ${API_URL}\n`);
+
+ const results: { name: string; durationMs: number; status: string; error?: string }[] = [];
+
+ for (let i = 0; i < COUNT; i++) {
+ console.log(`\n── Build ${i + 1}/${COUNT} ──`);
+ try {
+ const result = await buildOne(i);
+ results.push(result);
+ console.log(` ✓ ${result.name} — ${(result.durationMs / 1000).toFixed(1)}s (${result.status})`);
+ } catch (err: any) {
+ results.push({ name: `build-${i}`, durationMs: 0, status: "failed", error: err.message });
+ console.log(` ✗ FAILED: ${err.message}`);
+ }
+ }
+
+ console.log(`\n══ Results ══`);
+ const passed = results.filter((r) => r.status === "ready");
+ const failed = results.filter((r) => r.status !== "ready");
+ for (const r of results) {
+ const dur = r.durationMs ? `${(r.durationMs / 1000).toFixed(1)}s` : "—";
+ const icon = r.status === "ready" ? "✓" : "✗";
+ console.log(` ${icon} ${r.name} ${dur} ${r.error || ""}`);
+ }
+ const durations = passed.map((r) => r.durationMs / 1000);
+ if (durations.length > 0) {
+ const avg = durations.reduce((a, b) => a + b, 0) / durations.length;
+ console.log(`\n ${passed.length}/${COUNT} passed, avg ${avg.toFixed(1)}s`);
+ }
+ if (failed.length > 0) {
+ process.exit(1);
+ }
+}
+
+main().catch((err) => {
+ console.error("Fatal:", err.message);
+ process.exit(1);
+});
diff --git a/sdks/typescript/examples/test-openclaw-snapshot.ts b/sdks/typescript/examples/test-openclaw-snapshot.ts
new file mode 100644
index 00000000..02280466
--- /dev/null
+++ b/sdks/typescript/examples/test-openclaw-snapshot.ts
@@ -0,0 +1,99 @@
+/**
+ * Build a reusable OpenClaw snapshot (golden image equivalent).
+ *
+ * This creates a pre-built sandbox image with Node.js 22 and OpenClaw
+ * pre-installed. Provisioning new employees boots from this snapshot in seconds.
+ *
+ * Usage:
+ * npx tsx examples/test-openclaw-snapshot.ts
+ *
+ * Only needs to run once, or when you want to update the base OpenClaw version.
+ */
+
+import { Sandbox } from "@opencomputer/sdk";
+import { Image, Snapshots } from "@opencomputer/sdk/node";
+
+const OC_API_URL = process.env.OPENCOMPUTER_API_URL || "https://app.opencomputer.dev";
+const OC_API_KEY = process.env.OPENCOMPUTER_API_KEY;
+const OPENCLAW_SNAPSHOT = "openclaw-test-" + Date.now();
+
+async function main() {
+ const apiKey = OC_API_KEY;
+ if (!apiKey) {
+ console.error("Set OPENCOMPUTER_API_KEY");
+ process.exit(1);
+ }
+
+ console.log("Building OpenClaw snapshot...");
+ console.log("This installs Node.js 22 and OpenClaw into a reusable image.\n");
+
+ const image = Image.base()
+ .runCommands(
+ "sudo apt-get update && sudo apt-get install -y curl ca-certificates gnupg",
+ )
+ // Install Node.js 22 via NodeSource
+ .runCommands(
+ "curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -",
+ "sudo apt-get install -y nodejs",
+ )
+ // Install OpenClaw globally — npm prefix set to ~/npm-global so the
+ // 200MB package lands on the large home disk, not the small rootfs.
+ .runCommands(
+ "mkdir -p ~/npm-global",
+ "npm config set prefix ~/npm-global",
+ "npm install -g openclaw@latest",
+ "echo 'export PATH=$HOME/npm-global/bin:$PATH' | sudo tee /etc/profile.d/npm-global.sh",
+ )
+ // Create OpenClaw home directory
+ .runCommands("mkdir -p ~/.openclaw/workspace")
+ // Startup script
+ .addFile(
+ "/home/sandbox/start-openclaw.sh",
+ `#!/bin/bash
+set -e
+export PATH=$HOME/npm-global/bin:$PATH
+
+# Source environment if present (ANTHROPIC_API_KEY, etc.)
+[ -f ~/.openclaw/env ] && source ~/.openclaw/env
+
+# Start OpenClaw gateway in background
+cd ~
+nohup openclaw gateway --port 18789 > ~/.openclaw/gateway.log 2>&1 &
+
+# Wait for gateway to be ready
+for i in $(seq 1 30); do
+ if openclaw gateway status > /dev/null 2>&1; then
+ echo "OpenClaw gateway is ready"
+ exit 0
+ fi
+ sleep 1
+done
+
+echo "Warning: gateway did not become ready within 30s"
+exit 1
+`,
+ )
+ .runCommands("sudo chmod +x ~/start-openclaw.sh");
+
+ const snapshots = new Snapshots({ apiKey, apiUrl: OC_API_URL });
+
+ console.log("Creating snapshot (this may take a few minutes)...\n");
+
+ await snapshots.create({
+ name: OPENCLAW_SNAPSHOT,
+ image,
+ onBuildLogs: (line: string) => {
+ process.stdout.write(` ${line}\n`);
+ },
+ });
+
+ console.log(`\nSnapshot "${OPENCLAW_SNAPSHOT}" created successfully.`);
+ console.log(
+ "New employee sandboxes will boot from this snapshot in seconds.",
+ );
+}
+
+main().catch((err) => {
+ console.error("Failed to build snapshot:", err.message);
+ process.exit(1);
+});