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.5 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 huggingchat executor JSONL-stream extraction.
// The pure JSONL->OpenAI-SSE translation lives in huggingchat/jsonlStream.ts
// (consumes a passed-in ReadableStream; no host state/fetch/auth). Host imports it back.
const HERE = dirname(fileURLToPath(import.meta.url));
const EXE = join(HERE, "../../open-sse/executors");
const HOST = join(EXE, "huggingchat.ts");
const LEAF = join(EXE, "huggingchat/jsonlStream.ts");

test("leaf hosts the jsonl translators and does not import the host", () => {
  const src = readFileSync(LEAF, "utf8");
  assert.match(src, /export async function\* streamJsonlToOpenAi\b/);
  assert.match(src, /export async function readJsonlResponse\b/);
  assert.match(src, /export function (sseChunk|parseJsonlLine)\b/);
  assert.doesNotMatch(src, /from "\.\.\/huggingchat\.ts"/);
});

test("host imports the jsonl translators back from the leaf", () => {
  const host = readFileSync(HOST, "utf8");
  assert.match(host, /from "\.\/huggingchat\/jsonlStream\.ts"/);
});

test("parseJsonlLine parses a jsonl data line", async () => {
  const { parseJsonlLine } = await import("../../open-sse/executors/huggingchat/jsonlStream.ts");
  assert.equal(typeof parseJsonlLine, "function");
  assert.doesNotThrow(() => parseJsonlLine("not json"));
});