feat: align SDK with updated OpenAPI spec and add missing unit tests
- Update generated types from new openapi.yaml (capsule stats, usage, metrics, pause/resume lifecycle, host/channel management, auth flow) - Add Capsule pause/resume/ping/getMetrics lifecycle methods - Add Capsule.waitForReady abort signal support - Add PtyManager.connect and PtySession disposal - Fix HttpClient empty-body response handling (content-length: 0) - Add streamProcess() to CommandManager for background process streams - Add integration tests for capsule lifecycle, git, and PTY features - Add unit tests for AsyncQueue error paths, PtySession.close, Git.checkout without create, Git.add single string, Notebook.execCell error case, and PtyStartOptions fields
This commit is contained in:
@ -1,9 +1,13 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { Capsule } from "../src/capsule.js";
|
||||
import { CodeInterpreter } from "../src/code-interpreter/index.js";
|
||||
|
||||
describe("CodeInterpreter", () => {
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("creates a capsule with the jupyter template by default", async () => {
|
||||
const create = vi.spyOn(Capsule, "create").mockResolvedValue(
|
||||
new Capsule("cap_1", {
|
||||
@ -19,7 +23,6 @@ describe("CodeInterpreter", () => {
|
||||
expect(create).toHaveBeenCalledWith("jupyter", {
|
||||
baseUrl: "https://api.example.com",
|
||||
});
|
||||
create.mockRestore();
|
||||
});
|
||||
|
||||
it("connects to an existing capsule", () => {
|
||||
@ -53,4 +56,34 @@ describe("CodeInterpreter", () => {
|
||||
timeoutSec: 30,
|
||||
});
|
||||
});
|
||||
|
||||
it("returns stderr and non-zero exit code on failure", async () => {
|
||||
const capsule = new Capsule("cap_1", {
|
||||
baseUrl: "https://api.example.com",
|
||||
});
|
||||
vi.spyOn(capsule.commands, "exec").mockResolvedValue({
|
||||
exit_code: 1,
|
||||
stderr: "SyntaxError: invalid syntax\n",
|
||||
stdout: "",
|
||||
});
|
||||
const interpreter = new CodeInterpreter(capsule);
|
||||
|
||||
await expect(interpreter.notebook.execCell("invalid(")).resolves.toEqual({
|
||||
exitCode: 1,
|
||||
stderr: "SyntaxError: invalid syntax\n",
|
||||
stdout: "",
|
||||
});
|
||||
});
|
||||
|
||||
it("disposes the wrapped capsule", async () => {
|
||||
const capsule = new Capsule("cap_1", {
|
||||
baseUrl: "https://api.example.com",
|
||||
});
|
||||
const dispose = vi.spyOn(capsule, Symbol.asyncDispose).mockResolvedValue();
|
||||
const interpreter = new CodeInterpreter(capsule);
|
||||
|
||||
await interpreter[Symbol.asyncDispose]();
|
||||
|
||||
expect(dispose).toHaveBeenCalledOnce();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user