ReMe/integrations/dsh/client.test.mjs
jinliyl f5ec230fef
feat: add DSH memory integration and organize extensions (#461)
* feat: add DSH memory integration and organize extensions

* fix: support newer DSH release candidates

* fix: address DSH integration review feedback

* fix: handle DSH cross-day retry edge cases
2026-08-20 15:31:51 +08:00

55 lines
1.9 KiB
JavaScript

import assert from "node:assert/strict";
import test from "node:test";
import { ReMeClient } from "./dist/client.js";
test("calls ReMe jobs with their native request and response envelopes", async () => {
const calls = [];
const originalFetch = globalThis.fetch;
globalThis.fetch = async (url, init) => {
calls.push({ url, body: JSON.parse(init.body) });
return new Response(JSON.stringify({ success: true, answer: "memory result", metadata: {} }), {
status: 200,
headers: { "Content-Type": "application/json" },
});
};
try {
const client = new ReMeClient({
endpoint: "http://127.0.0.1:2333",
requestTimeoutMs: 1000,
backgroundTimeoutMs: 1000,
apiKey: "",
});
const result = await client.search("deployment", { limit: 5, minScore: 0 });
assert.equal(result.ok, true);
assert.equal(result.answer, "memory result");
assert.deepEqual(calls, [{
url: "http://127.0.0.1:2333/search",
body: { query: "deployment", limit: 5, min_score: 0 },
}]);
} finally {
globalThis.fetch = originalFetch;
}
});
test("combines caller cancellation with the request timeout", async () => {
const originalFetch = globalThis.fetch;
globalThis.fetch = async (_url, init) => new Promise((_resolve, reject) => {
init.signal.addEventListener("abort", () => reject(init.signal.reason), { once: true });
});
try {
const client = new ReMeClient({
endpoint: "http://127.0.0.1:2333",
requestTimeoutMs: 1000,
backgroundTimeoutMs: 1000,
apiKey: "",
});
const controller = new AbortController();
const request = client.search("deployment", { signal: controller.signal });
controller.abort(new Error("turn cancelled"));
const result = await request;
assert.equal(result.ok, false);
assert.match(result.error, /turn cancelled/);
} finally {
globalThis.fetch = originalFetch;
}
});