Files
OmniRoute/tests/unit/chatcore-memory-extraction.test.ts
Diego Rodrigues de Sa e Souza 305474de85 refactor(sse): split chatCore.ts pure helpers into chatCore/ modules (−561 LOC) (#4159)
Integrated into release/v3.8.29 (re-synced: kept only the chatCore split, dropped the stale-merge contamination)
2026-06-18 10:20:08 -03:00

43 lines
1.5 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import {
extractMemoryTextFromResponse,
extractMemoryTextFromRequestBody,
resolveMemoryOwnerId,
} from "../../open-sse/handlers/chatCore/memoryExtraction.ts";
test("extractMemoryTextFromResponse reads OpenAI, Claude-array and responses output_text", () => {
assert.equal(
extractMemoryTextFromResponse({ choices: [{ message: { content: " hi " } }] }),
"hi"
);
assert.equal(
extractMemoryTextFromResponse({ content: [{ type: "text", text: " a " }, { type: "image" }] }),
"a"
);
assert.equal(extractMemoryTextFromResponse({ output_text: " out " }), "out");
assert.equal(extractMemoryTextFromResponse(null), "");
});
test("extractMemoryTextFromRequestBody returns the last user message text", () => {
const body = {
messages: [
{ role: "user", content: "first" },
{ role: "assistant", content: "ignored" },
{ role: "user", content: "second" },
],
};
assert.equal(extractMemoryTextFromRequestBody(body), "second");
const inputBody = {
input: [{ role: "user", type: "message", content: [{ type: "input_text", text: "hey" }] }],
};
assert.equal(extractMemoryTextFromRequestBody(inputBody), "hey");
});
test("resolveMemoryOwnerId returns trimmed id or null", () => {
assert.equal(resolveMemoryOwnerId({ id: "key_123" }), "key_123");
assert.equal(resolveMemoryOwnerId({ id: " " }), null);
assert.equal(resolveMemoryOwnerId(null), null);
});