|
| 1 | +--- |
| 2 | +name: sanity-check |
| 3 | +description: Run an E2E smoke test that installs agent-os packages from npm in an isolated temp project, spawns a Pi agent session, has it write a file and read it back with cat, then verifies the result. Use when the user asks to sanity check, smoke test, or verify the release works. |
| 4 | +--- |
| 5 | + |
| 6 | +# Sanity Check |
| 7 | + |
| 8 | +## Usage |
| 9 | +- `/sanity-check` — run in a temp directory on the host |
| 10 | +- `/sanity-check docker` — run inside a `node:22` Docker container |
| 11 | +- `/sanity-check <custom instructions>` — any extra instructions (e.g. "use rc.3", "use pnpm", "test on node 20") |
| 12 | + |
| 13 | +## What it tests |
| 14 | + |
| 15 | +1. `npm install` of `@rivet-dev/agent-os-core`, `@rivet-dev/agent-os-pi`, `@rivet-dev/agent-os-common` from the public npm registry |
| 16 | +2. Boot a VM with WASM coreutils (bash, cat, sh, etc.) and the Pi SDK ACP adapter |
| 17 | +3. Create a Pi agent session with a real Anthropic API key |
| 18 | +4. Send a prompt that uses the **write tool** to create `/tmp/test.txt` with "Hello from Agent OS!" and the **bash tool** to run `cat /tmp/test.txt` |
| 19 | +5. Verify the file contents from the host side via `vm.readFile()` |
| 20 | + |
| 21 | +## Requirements |
| 22 | + |
| 23 | +- `ANTHROPIC_API_KEY` must be set in the environment. If not set, load it from `~/misc/env.txt`. |
| 24 | +- Node.js 22+ (or Docker with `node:22` image) |
| 25 | + |
| 26 | +## Steps |
| 27 | + |
| 28 | +### 1. Set up the test project |
| 29 | + |
| 30 | +Create a temp directory (e.g. `/tmp/agent-os-sanity-XXXX`) with two files: |
| 31 | + |
| 32 | +**package.json:** |
| 33 | +```json |
| 34 | +{ |
| 35 | + "name": "agent-os-sanity-check", |
| 36 | + "private": true, |
| 37 | + "type": "module", |
| 38 | + "dependencies": { |
| 39 | + "@rivet-dev/agent-os-core": "*", |
| 40 | + "@rivet-dev/agent-os-pi": "*", |
| 41 | + "@rivet-dev/agent-os-common": "*", |
| 42 | + "@mariozechner/pi-coding-agent": "^0.60.0", |
| 43 | + "@agentclientprotocol/sdk": "^0.16.1" |
| 44 | + } |
| 45 | +} |
| 46 | +``` |
| 47 | + |
| 48 | +If the user specifies a version (e.g. "use rc.3"), pin `@rivet-dev/agent-os-core` and `@rivet-dev/agent-os-pi` to that version. |
| 49 | + |
| 50 | +**test.mjs:** |
| 51 | +```js |
| 52 | +import { AgentOs } from "@rivet-dev/agent-os-core"; |
| 53 | +import common from "@rivet-dev/agent-os-common"; |
| 54 | +import pi from "@rivet-dev/agent-os-pi"; |
| 55 | + |
| 56 | +const ANTHROPIC_API_KEY = process.env.ANTHROPIC_API_KEY; |
| 57 | +if (!ANTHROPIC_API_KEY) { |
| 58 | + console.error("ANTHROPIC_API_KEY is required"); |
| 59 | + process.exit(1); |
| 60 | +} |
| 61 | + |
| 62 | +console.log("Creating VM with common + pi..."); |
| 63 | +const vm = await AgentOs.create({ software: [common, pi] }); |
| 64 | + |
| 65 | +console.log("Creating PI agent session..."); |
| 66 | +const { sessionId } = await vm.createSession("pi", { |
| 67 | + env: { ANTHROPIC_API_KEY }, |
| 68 | +}); |
| 69 | +console.log(`Session created: ${sessionId}`); |
| 70 | + |
| 71 | +vm.onSessionEvent(sessionId, (event) => { |
| 72 | + const params = event.params; |
| 73 | + if (params?.update?.sessionUpdate === "agent_message_chunk") { |
| 74 | + process.stdout.write(params.update.content?.text ?? ""); |
| 75 | + } |
| 76 | +}); |
| 77 | + |
| 78 | +console.log("\nSending prompt..."); |
| 79 | +const response = await vm.prompt( |
| 80 | + sessionId, |
| 81 | + 'Write the text "Hello from Agent OS!" to /tmp/test.txt using the write tool. Then use the bash tool to run `cat /tmp/test.txt` and tell me what it says.', |
| 82 | +); |
| 83 | +console.log(`\n\nPrompt completed: ${response.stopReason}`); |
| 84 | + |
| 85 | +console.log("\nVerifying file..."); |
| 86 | +try { |
| 87 | + const data = await vm.readFile("/tmp/test.txt"); |
| 88 | + const text = new TextDecoder().decode(data); |
| 89 | + console.log(`File contents: "${text.trim()}"`); |
| 90 | + if (text.includes("Hello from Agent OS!")) { |
| 91 | + console.log("\n✅ E2E TEST PASSED"); |
| 92 | + } else { |
| 93 | + console.log("\n❌ E2E TEST FAILED: wrong content"); |
| 94 | + process.exit(1); |
| 95 | + } |
| 96 | +} catch (err) { |
| 97 | + console.log(`\n❌ E2E TEST FAILED: ${err.message}`); |
| 98 | + process.exit(1); |
| 99 | +} |
| 100 | + |
| 101 | +vm.closeSession(sessionId); |
| 102 | +await vm.dispose(); |
| 103 | +``` |
| 104 | +
|
| 105 | +### 2. Run the test |
| 106 | +
|
| 107 | +**Default (temp dir on host):** |
| 108 | +```bash |
| 109 | +cd /tmp/agent-os-sanity-XXXX |
| 110 | +npm install |
| 111 | +node test.mjs |
| 112 | +``` |
| 113 | +
|
| 114 | +**Docker mode:** |
| 115 | +```bash |
| 116 | +docker run --rm \ |
| 117 | + -e ANTHROPIC_API_KEY="$ANTHROPIC_API_KEY" \ |
| 118 | + -v /tmp/agent-os-sanity-XXXX:/app \ |
| 119 | + -w /app \ |
| 120 | + node:22 \ |
| 121 | + bash -c "npm install && timeout 120 node test.mjs" |
| 122 | +``` |
| 123 | +
|
| 124 | +### 3. Verify results |
| 125 | +
|
| 126 | +- LLM response should stream to stdout showing the agent using write and bash tools |
| 127 | +- Final output must include `✅ E2E TEST PASSED` |
| 128 | +- If it fails, report the error and the stderr output |
| 129 | +
|
| 130 | +### 4. Clean up |
| 131 | +
|
| 132 | +Remove the temp directory after the test completes. |
| 133 | +
|
| 134 | +## Rules |
| 135 | +- Always use a fresh temp directory — never run in the repo itself. |
| 136 | +- Always install from the public npm registry — never use local links. |
| 137 | +- If Docker mode, clean up the container's node_modules via `docker run --rm` before removing the host temp dir. |
| 138 | +- Report the installed versions of `@rivet-dev/agent-os-core` and `@rivet-dev/agent-os-common` in the output. |
0 commit comments