feat: v2
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { runExec, type ExecSessionOpener } from "../../command/exec";
|
||||
import type { ExecApiSession, ExecOutputFrame } from "../../lib/exec-api";
|
||||
|
||||
function fakeSession(...frames: ExecOutputFrame[]): ExecApiSession {
|
||||
return {
|
||||
sendStdin() {},
|
||||
resize() {},
|
||||
close() {},
|
||||
async *[Symbol.asyncIterator]() {
|
||||
yield* frames;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
describe("exec API command runner", () => {
|
||||
test("opens the authenticated workspace endpoint and returns remote status", async () => {
|
||||
let call: Parameters<ExecSessionOpener> | undefined;
|
||||
const opener: ExecSessionOpener = async (...args) => {
|
||||
call = args;
|
||||
return fakeSession({ type: "exit", exitCode: 23 });
|
||||
};
|
||||
const controller = new AbortController();
|
||||
const result = await runExec(
|
||||
"shop/demo",
|
||||
"api",
|
||||
["sh", "-c", "exit 23"],
|
||||
controller.signal,
|
||||
opener,
|
||||
);
|
||||
|
||||
expect(result).toBe(23);
|
||||
expect(call?.[0]).toBe("shop/demo");
|
||||
expect(call?.[1]).toMatchObject({
|
||||
deployment: "api",
|
||||
command: ["sh", "-c", "exit 23"],
|
||||
tty: false,
|
||||
});
|
||||
expect(call?.[2]).toBe(controller.signal);
|
||||
});
|
||||
|
||||
test("validates required arguments before opening a connection", async () => {
|
||||
let calls = 0;
|
||||
const opener: ExecSessionOpener = async () => {
|
||||
calls += 1;
|
||||
return fakeSession();
|
||||
};
|
||||
const signal = new AbortController().signal;
|
||||
await expect(runExec("shop", "", ["sh"], signal, opener)).rejects.toThrow(
|
||||
"Deployment name",
|
||||
);
|
||||
await expect(runExec("shop", "api", [], signal, opener)).rejects.toThrow(
|
||||
"Command is required",
|
||||
);
|
||||
expect(calls).toBe(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user