openpod

An opencode plugin that spins up a dedicated virtual machine for each session to isolate agent work.
git clone https://unitehenry.com/git/openpod.git
Log | Files | Refs | README

commit d02221090838767d7538a432a8354c922cb9a7fa
parent 7c12c94bb90f3de1c5869e0149092aed056b309c
Author: Henry Unite <unitehenry@gmail.com>
Date:   Sun, 25 Oct 2026 01:28:12 +0000

test(shell): add unit tests for wrap.ts using vitest

- Create shell/wrap.test.ts
- Import actual init() from context (no mocks for now)
- 6 test cases covering passthrough, wrapping, first-segment logic, nested dirs, quote escaping
- Add scripts/test wrapper (consistent with typecheck/lint/format)
- Update scripts/install to also pull in vitest as dev dep
- Tests pass via npm test and ./scripts/test

Diffstat:
Mscripts/install | 1+
Ascripts/test | 9+++++++++
Ashell/wrap.test.ts | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 78 insertions(+), 0 deletions(-)

diff --git a/scripts/install b/scripts/install @@ -6,3 +6,4 @@ script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" "$script_dir/node" --version >/dev/null npm install @opencode/plugin +npm install --save-dev vitest diff --git a/scripts/test b/scripts/test @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Ensure Node.js v24 is available +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +"$script_dir/node" --version >/dev/null + +npx vitest run "$@" +\ No newline at end of file diff --git a/shell/wrap.test.ts b/shell/wrap.test.ts @@ -0,0 +1,68 @@ +import { describe, it, expect, beforeAll } from "vitest"; +import * as path from "node:path"; + +import type { OpenpodContext } from "../context"; +import { init } from "../context"; +import { wrap } from "./wrap"; + +describe("wrap", () => { + let ctx: OpenpodContext; + + beforeAll(async () => { + ctx = await init(); + }); + + it("returns original command when cwd is outside openpodRoot", () => { + const command = "echo hello"; + const result = wrap(ctx, "/tmp/some/random/dir", command); + expect(result).toBe(command); + }); + + it("returns original command when cwd is exactly openpodRoot", () => { + const command = "ls"; + const result = wrap(ctx, ctx.openpodRoot, command); + expect(result).toBe(command); + }); + + it("wraps command using first directory segment as lima name", () => { + const session = "my-session-abc"; + const cwd = path.join(ctx.openpodRoot, session); + const command = "npm run dev"; + const result = wrap(ctx, cwd, command); + + expect(result).toBe( + `limactl shell --preserve-env --workdir='${cwd}' ${session} bash -c '${command}'`, + ); + }); + + it("uses only the first segment even for nested directories", () => { + const session = "sess-xyz"; + const cwd = path.join(ctx.openpodRoot, session, "src", "app"); + const command = "cat package.json"; + const result = wrap(ctx, cwd, command); + + expect(result).toBe( + `limactl shell --preserve-env --workdir='${cwd}' ${session} bash -c '${command}'`, + ); + }); + + it("escapes single quotes in cwd and command", () => { + const session = "sess'with'quotes"; + const cwd = path.join(ctx.openpodRoot, session, "sub'dir"); + const command = "echo 'hello world'"; + const result = wrap(ctx, cwd, command); + + const escapedCwd = cwd.replace(/'/g, "'\\''"); + const escapedCmd = command.replace(/'/g, "'\\''"); + const expected = `limactl shell --preserve-env --workdir='${escapedCwd}' ${session} bash -c '${escapedCmd}'`; + + expect(result).toBe(expected); + }); + + it("returns original command for paths that would escape the tree", () => { + const command = "pwd"; + const outside = path.join(ctx.openpodRoot, "..", "escape"); + const result = wrap(ctx, outside, command); + expect(result).toBe(command); + }); +});