mirror of
https://github.com/luckyyzh/pi-agent-integrated.git
synced 2026-10-03 02:59:35 +00:00
52 lines
1.5 KiB
JavaScript
52 lines
1.5 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import React from "react";
|
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
import { createJiti } from "jiti";
|
|
|
|
const jiti = createJiti(import.meta.url, {
|
|
jsx: { runtime: "automatic" },
|
|
tsconfigPaths: true,
|
|
});
|
|
const { MessageView } = await jiti.import("./MessageView.tsx");
|
|
const { I18nProvider } = await jiti.import("../hooks/useI18n.tsx");
|
|
|
|
function renderMessage(message) {
|
|
return renderToStaticMarkup(
|
|
React.createElement(
|
|
I18nProvider,
|
|
null,
|
|
React.createElement(MessageView, { message }),
|
|
),
|
|
);
|
|
}
|
|
|
|
test("renders a provider error when the assistant message has no content", () => {
|
|
const html = renderMessage({
|
|
role: "assistant",
|
|
provider: "openai",
|
|
model: "gpt-test",
|
|
content: [],
|
|
stopReason: "error",
|
|
errorMessage: "OpenAI API error (403): <html>request forbidden</html>",
|
|
});
|
|
|
|
assert.match(html, /role="alert"/);
|
|
assert.match(html, /Error: OpenAI API error \(403\)/);
|
|
assert.match(html, /<html>request forbidden<\/html>/);
|
|
});
|
|
|
|
test("renders partial assistant content before the provider error", () => {
|
|
const html = renderMessage({
|
|
role: "assistant",
|
|
provider: "openai",
|
|
model: "gpt-test",
|
|
content: [{ type: "text", text: "Partial response" }],
|
|
stopReason: "error",
|
|
errorMessage: "Connection closed",
|
|
});
|
|
|
|
assert.match(html, /Partial response/);
|
|
assert.match(html, /Error: Connection closed/);
|
|
});
|