feat: added IPython-backed Python tool with streaming output and Jupyter integration
- Added IPython-backed Python tool with streaming output and image/JSON rendering. - Implemented Jupyter kernel gateway integration with WebSocket communication. - Added Python prelude with 30+ shell-like utility functions for file operations. - Migrated environment variables from PI_ to OMP_ prefix with automatic migration. - Added streaming output system with automatic spill-to-disk for large outputs. - Reorganized settings interface into behavior, tools, display, voice, status, lsp, and exa tabs.
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import { type KernelDisplayOutput, PythonKernel } from "./python-kernel";
|
||||
|
||||
const renderDisplay = (
|
||||
PythonKernel as unknown as {
|
||||
prototype: {
|
||||
renderDisplay: (content: Record<string, unknown>) => {
|
||||
text: string;
|
||||
outputs: KernelDisplayOutput[];
|
||||
};
|
||||
};
|
||||
}
|
||||
).prototype.renderDisplay;
|
||||
|
||||
describe("PythonKernel display rendering", () => {
|
||||
it("normalizes text/plain output and returns no display outputs", () => {
|
||||
const { text, outputs } = renderDisplay.call({} as PythonKernel, {
|
||||
data: { "text/plain": "hello" },
|
||||
});
|
||||
|
||||
expect(text).toBe("hello\n");
|
||||
expect(outputs).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("collects image and json display outputs without text", () => {
|
||||
const { text, outputs } = renderDisplay.call({} as PythonKernel, {
|
||||
data: { "image/png": "abc", "application/json": { foo: "bar" } },
|
||||
});
|
||||
|
||||
expect(text).toBe("");
|
||||
expect(outputs).toEqual([
|
||||
{ type: "image", data: "abc", mimeType: "image/png" },
|
||||
{ type: "json", data: { foo: "bar" } },
|
||||
]);
|
||||
});
|
||||
|
||||
it("converts text/html to markdown", () => {
|
||||
const { text, outputs } = renderDisplay.call({} as PythonKernel, {
|
||||
data: { "text/html": "<p><strong>Hello</strong></p>" },
|
||||
});
|
||||
|
||||
expect(outputs).toHaveLength(0);
|
||||
expect(text).toBe("**Hello**\n");
|
||||
});
|
||||
|
||||
it("combines text/plain with json output", () => {
|
||||
const { text, outputs } = renderDisplay.call({} as PythonKernel, {
|
||||
data: { "text/plain": "value", "application/json": { ok: true } },
|
||||
});
|
||||
|
||||
expect(text).toBe("value\n");
|
||||
expect(outputs).toEqual([{ type: "json", data: { ok: true } }]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user