repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by bugabinga
opencode/plugins/chef/test/sdk-smoke.test.ts
RawFile outline
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
// Gate the test behind the environment variable
// In bun:test, describe.skip is used directly, so we conditionally select describe or describe.skip
const describeSmokeTest = process.env.CHEF_SDK_SMOKE_TEST === "1"
? describe
: describe.skip;
describeSmokeTest("Chef Plugin SDK Smoke Test", () => {
let tempDir: string;
beforeAll(() => {
// Create a temporary directory for the test
tempDir = mkdtempSync(join(tmpdir(), "chef-smoke-test-"));
});
afterAll(() => {
// Clean up the temporary directory
rmSync(tempDir, { recursive: true, force: true });
});
test("SDK imports resolve without throwing", async () => {
// This tests that the plugin can import its dependencies
const { ChefPlugin } = await import("../chef.ts");
expect(ChefPlugin).toBeDefined();
expect(typeof ChefPlugin).toBe("function");
});
test("ChefPlugin returns tools when called with mock input", async () => {
const { ChefPlugin } = await import("../chef.ts");
const mockClient = {
session: {
create: () => Promise.resolve({ id: "test-session" }),
prompt: () =>
Promise.resolve({ data: { info: { structured_output: {} } } }),
delete: () => Promise.resolve(),
},
app: {
log: () => Promise.resolve(),
agents: () => Promise.resolve([]),
},
};
const mockInput = {
client: mockClient as any,
project: {
id: "test-project",
worktree: tempDir,
time: { created: Date.now() },
},
directory: tempDir,
worktree: tempDir,
serverUrl: new URL("http://localhost:0"),
$: {} as any,
};
const result = await ChefPlugin(mockInput);
expect(result).toBeDefined();
expect(result.tool).toBeDefined();
});
test("all 5 expected tools are present", async () => {
const { ChefPlugin } = await import("../chef.ts");
const mockClient = {
session: {
create: () => Promise.resolve({ id: "test-session" }),
prompt: () =>
Promise.resolve({ data: { info: { structured_output: {} } } }),
delete: () => Promise.resolve(),
},
app: {
log: () => Promise.resolve(),
agents: () => Promise.resolve([]),
},
};
const mockInput = {
client: mockClient as any,
project: {
id: "test-project",
worktree: tempDir,
time: { created: Date.now() },
},
directory: tempDir,
worktree: tempDir,
serverUrl: new URL("http://localhost:0"),
$: {} as any,
};
const result = await ChefPlugin(mockInput);
const expectedTools = [
"pipeline.start",
"pipeline.status",
"pipeline.continue",
"pipeline.abort",
"pipeline.list",
];
// Type assertion since we verified result.tool is defined above
const tools = result.tool!;
const actualTools = Object.keys(tools);
for (const toolName of expectedTools) {
expect(actualTools).toContain(toolName);
expect(tools[toolName]).toBeDefined();
expect(typeof tools[toolName]).toBe("object");
expect(tools[toolName].execute).toBeDefined();
expect(typeof tools[toolName].execute).toBe("function");
}
expect(actualTools).toHaveLength(expectedTools.length);
});
});