Files
kilocode/packages/kilo-vscode/tests/unit/abort.test.ts
T

48 lines
1.3 KiB
TypeScript

import { describe, expect, it } from "bun:test"
import type { KiloClient } from "@kilocode/sdk/v2/client"
import { abortSession } from "../../src/kilo-provider/abort"
function client(calls: unknown[], fail = false) {
return {
session: {
abort: async (params: unknown, opts: unknown) => {
calls.push({ type: "abort", params, opts })
if (fail) throw new Error("abort failed")
return { data: true }
},
},
} as unknown as KiloClient
}
describe("abortSession", () => {
it("calls session.abort with the session id and directory", async () => {
const calls: unknown[] = []
await abortSession({ client: client(calls), sessionID: "session_1", dir: "/repo" })
expect(calls).toEqual([
{
type: "abort",
params: { sessionID: "session_1", directory: "/repo" },
opts: { throwOnError: true },
},
])
})
it("rejects when the abort request fails", async () => {
const calls: unknown[] = []
await expect(abortSession({ client: client(calls, true), sessionID: "session_1", dir: "/repo" })).rejects.toThrow(
"abort failed",
)
expect(calls).toEqual([
{
type: "abort",
params: { sessionID: "session_1", directory: "/repo" },
opts: { throwOnError: true },
},
])
})
})