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.9 KB
Raw Blame
import { test } from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";

// Split-guard for the openai-to-kiro message-helper extraction.
// The pure tool/message helpers (parseToolInput / normalizeKiroToolSchema /
// serializeToolResultContent) live in the leaf `openai-to-kiro/messageHelpers.ts`;
// the host imports them back for convertMessages. They were module-private, so the
// public export set is unchanged (no re-export needed).
const HERE = dirname(fileURLToPath(import.meta.url));
const REQ = join(HERE, "../../open-sse/translator/request");
const HOST = join(REQ, "openai-to-kiro.ts");
const LEAF = join(REQ, "openai-to-kiro/messageHelpers.ts");

test("leaf hosts the pure helpers and does not import the host", () => {
  const src = readFileSync(LEAF, "utf8");
  for (const sym of ["parseToolInput", "normalizeKiroToolSchema", "serializeToolResultContent"]) {
    assert.match(src, new RegExp(`export function ${sym}\\b`));
  }
  assert.doesNotMatch(src, /from "\.\.\/openai-to-kiro\.ts"/);
});

test("host imports the helpers back from the leaf", () => {
  const src = readFileSync(HOST, "utf8");
  assert.match(src, /from "\.\/openai-to-kiro\/messageHelpers\.ts"/);
  // buildKiroPayload stays exported on the host module.
  assert.match(src, /export function buildKiroPayload\(/);
});

test("normalizeKiroToolSchema strips empty required arrays and additionalProperties", async () => {
  const { normalizeKiroToolSchema } =
    await import("../../open-sse/translator/request/openai-to-kiro/messageHelpers.ts");
  const out = normalizeKiroToolSchema({
    type: "object",
    required: [],
    additionalProperties: false,
    properties: { a: { type: "string" } },
  });
  assert.equal("required" in out, false);
  assert.equal("additionalProperties" in out, false);
  assert.deepEqual(out.properties, { a: { type: "string" } });
});