Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

1.4 KB
Raw Blame
import test from "node:test";
import assert from "node:assert/strict";
import { translateRequest } from "../../open-sse/translator/index.ts";
import { FORMATS } from "../../open-sse/translator/formats.ts";

test("#13948: mid-array system message keeps its chronological position after claude->openai translation for a strict provider", () => {
  const body = {
    model: "mimo-v2.5",
    system: [{ type: "text", text: "You are a coding assistant." }],
    messages: [
      { role: "user", content: "hi" },
      { role: "system", content: "deferred tools list" },
      { role: "user", content: "go" },
    ],
  };

  const result = translateRequest(
    FORMATS.CLAUDE,
    FORMATS.OPENAI,
    "mimo-v2.5",
    body,
    false,
    null,
    "xiaomi-mimo"
  );

  const outMessages = result.messages as Array<{ role: string; content: string }>;
  const offender = outMessages.find((m) => m.content === "deferred tools list");
  assert.ok(offender, "the mid-array system instruction must not be dropped");

  const hiIndex = outMessages.findIndex((m) => m.content === "hi");
  const offenderIndex = outMessages.findIndex((m) => m.content === "deferred tools list");
  const goIndex = outMessages.findIndex((m) => m.content === "go");

  assert.ok(
    hiIndex < offenderIndex,
    `"hi" (index ${hiIndex}) must come before the deferred instruction (index ${offenderIndex})`
  );
  assert.ok(offenderIndex < goIndex, 'the deferred instruction must still precede "go"');
});