File size: 3,054 Bytes
88c4c60 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | // OpenAI β Gemini / Cursor / CommandCode request translation.
import { describe, it, expect } from "vitest";
import "./registerAll.js";
import { translateRequest } from "../../open-sse/translator/index.js";
import { FORMATS } from "../../open-sse/translator/formats.js";
const O2G = (body) => translateRequest(FORMATS.OPENAI, FORMATS.GEMINI, "m", body, true, null, "gemini");
const O2C = (body) => translateRequest(FORMATS.OPENAI, FORMATS.CURSOR, "m", body, true, null, "cursor");
const O2CC = (body) => translateRequest(FORMATS.OPENAI, FORMATS.COMMANDCODE, "m", body, true, null, "commandcode");
describe("OpenAI β Gemini", () => {
// openai-to-gemini.js:92-96 β each system message overwrites systemInstruction β only last kept
// KNOWN BUG
it.fails("multiple system messages are all kept", () => {
const out = O2G({
messages: [
{ role: "system", content: "RULE_ONE" },
{ role: "system", content: "RULE_TWO" },
{ role: "user", content: "hi" },
],
});
expect(JSON.stringify(out.systemInstruction), "earlier system lost").toContain("RULE_ONE");
});
});
describe("OpenAI β Cursor", () => {
// openai-to-cursor.js:12-24 β image content fully dropped (text only)
// KNOWN BUG
it.fails("image content is preserved", () => {
const out = O2C({
messages: [{ role: "user", content: [
{ type: "text", text: "look" },
{ type: "image_url", image_url: { url: "data:image/png;base64,AAAA" } },
] }],
});
expect(JSON.stringify(out), "image dropped").toContain("AAAA");
});
// openai-to-cursor.js:179 β max_tokens hardcoded to 32000
// KNOWN BUG
it.fails("respects client max_tokens", () => {
const out = O2C({ max_tokens: 200, messages: [{ role: "user", content: "hi" }] });
expect(out.max_tokens).toBe(200);
});
});
describe("OpenAI β CommandCode", () => {
// openai-to-commandcode.js:53-57 β safeParseJson returns {} on bad JSON (args silently lost)
// KNOWN BUG
it.fails("malformed tool arguments are not silently emptied", () => {
const out = O2CC({
messages: [
{ role: "user", content: "go" },
{ role: "assistant", content: "", tool_calls: [
{ id: "c1", type: "function", function: { name: "f", arguments: "{bad" } },
] },
{ role: "tool", tool_call_id: "c1", content: "r" },
],
});
const asst = out.params.messages.find((m) => m.role === "assistant");
const call = asst.content.find((b) => b.type === "tool-call");
expect(Object.keys(call.input).length, "arguments silently dropped to {}").toBeGreaterThan(0);
});
// openai-to-commandcode.js:41-42 β image becomes "[image omitted]"
// KNOWN BUG
it.fails("image content is preserved", () => {
const out = O2CC({
messages: [{ role: "user", content: [
{ type: "text", text: "look" },
{ type: "image_url", image_url: { url: "data:image/png;base64,BBBB" } },
] }],
});
expect(JSON.stringify(out), "image omitted").toContain("BBBB");
});
});
|